diff --git a/index.ts b/index.ts index 968a9ec..265bc86 100644 --- a/index.ts +++ b/index.ts @@ -147,6 +147,12 @@ export function runWorker(payload: unknown, signal: AbortSignal): Promise ({ settings: { enabled: true, reserveTokens: 16384, keepRecentTokens: 20000 }, }); const controller = new AbortController(); +const notifications = []; let branch = []; const ctx = { cwd: process.cwd(), - hasUI: false, - ui: { notify() {} }, + hasUI: true, + ui: { notify(message, level) { notifications.push({ message, level }); } }, model: { ...model }, modelRegistry: { async getApiKeyAndHeaders() { throw new Error("auth should not be needed in this test"); } }, sessionManager: { @@ -231,6 +232,16 @@ console.warn = () => {}; const workerFailureWithArchive = await before({ type: "session_before_compact", preparation: prep(nextMessages, first.compaction.summary), branchEntries: branch, customInstructions: undefined, signal: controller.signal }, ctx); console.warn = originalWarn; if (workerFailureWithArchive?.cancel !== true) throw new Error("worker failure with an existing archive did not cancel safely"); +const retainedNotice = notifications.at(-1); +if ( + retainedNotice?.level !== "error" || + !retainedNotice.message.includes("SnapCompact visual compaction failed: SnapCompact worker failed") || + !retainedNotice.message.includes("maxArchiveTokens must be positive") || + !retainedNotice.message.includes("text fallback also failed") || + !retainedNotice.message.includes("existing archive was retained") +) { + throw new Error(`worker failure notice hid the primary error: ${JSON.stringify(retainedNotice)}`); +} ctx.model = { ...model, input: ["text"], contextWindow: 20000, maxTokens: 4096 }; console.warn = () => {}; const manual = await before({ type: "session_before_compact", preparation: prep(nextMessages, first.compaction.summary), branchEntries: branch, customInstructions: "focus on tests", signal: controller.signal }, ctx);