From 6f80d0de034ec9953eb6dd4347248263e1da4bcc Mon Sep 17 00:00:00 2001 From: wujunchen Date: Mon, 27 Apr 2026 15:29:29 +0800 Subject: [PATCH] test: add generation.ts cancellationNoticeKey edge case tests Tests cover all backend types (api, anthropic-api, claude-code, codex), all generation phases (queued, reading, cache-check, generating, saving), and null settings/job edge cases. Change-Id: I722fb0cf1129c7cf45dfc5bf2544577652df843d --- package.json | 2 +- tests/direct-generation.test.js | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/direct-generation.test.js diff --git a/package.json b/package.json index aa180c7..895c336 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "typecheck": "tsc --noEmit", "lint": "biome check main.ts src/", "lint:fix": "biome check --write main.ts src/", - "test": "npm run build && npm run typecheck && node tests/main.test.js && node tests/generation-job-manager.test.js && node tests/anchor.test.js && node tests/schema.test.js && node tests/cache.test.js && node tests/cards-nav.test.js && node tests/markdown.test.js && node tests/vault-batch.test.js && node tests/i18n.test.js && node tests/scroll.test.js && node tests/settings.test.js && node tests/providers.test.js && node tests/streaming.test.js && node tests/cli.test.js && node tests/direct-prompt.test.js && node tests/direct-markdown.test.js && node tests/direct-cache.test.js && node tests/direct-providers.test.js && node tests/direct-settings.test.js && node tests/direct-i18n.test.js && node tests/direct-streaming.test.js" + "test": "npm run build && npm run typecheck && node tests/main.test.js && node tests/generation-job-manager.test.js && node tests/anchor.test.js && node tests/schema.test.js && node tests/cache.test.js && node tests/cards-nav.test.js && node tests/markdown.test.js && node tests/vault-batch.test.js && node tests/i18n.test.js && node tests/scroll.test.js && node tests/settings.test.js && node tests/providers.test.js && node tests/streaming.test.js && node tests/cli.test.js && node tests/direct-prompt.test.js && node tests/direct-generation.test.js && node tests/direct-markdown.test.js && node tests/direct-cache.test.js && node tests/direct-providers.test.js && node tests/direct-settings.test.js && node tests/direct-i18n.test.js && node tests/direct-streaming.test.js" }, "devDependencies": { "@biomejs/biome": "^2.4.13", diff --git a/tests/direct-generation.test.js b/tests/direct-generation.test.js new file mode 100644 index 0000000..38a6c0a --- /dev/null +++ b/tests/direct-generation.test.js @@ -0,0 +1,74 @@ +const { assert, requireBundledModule, cleanup } = require('./direct-test-setup'); + +(async () => { + try { + const generation = await requireBundledModule('src/generation.ts'); + + // ── cancellationNoticeKey: API backend during generation ── + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'api' }, { phase: 'generating' }), + 'cancelRequestedApiInFlight', + 'API backend + generating = API in-flight notice', + ); + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'anthropic-api' }, { phase: 'generating' }), + 'cancelRequestedApiInFlight', + 'anthropic-api backend + generating = API in-flight notice', + ); + + // ── cancellationNoticeKey: CLI backends ── + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'claude-code' }, { phase: 'generating' }), + 'cancelRequested', + 'CLI backend uses simple cancel notice', + ); + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'codex' }, { phase: 'generating' }), + 'cancelRequested', + 'codex backend uses simple cancel notice', + ); + + // ── cancellationNoticeKey: non-generating phases ── + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'api' }, { phase: 'queued' }), + 'cancelRequested', + 'queued phase = simple cancel even for API', + ); + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'api' }, { phase: 'cache-check' }), + 'cancelRequested', + 'cache-check phase = simple cancel', + ); + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'api' }, { phase: 'reading' }), + 'cancelRequested', + 'reading phase = simple cancel', + ); + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'api' }, { phase: 'saving' }), + 'cancelRequested', + 'saving phase = simple cancel', + ); + + // ── cancellationNoticeKey: null/edge cases ── + assert.strictEqual( + generation.cancellationNoticeKey(null, { phase: 'generating' }), + 'cancelRequested', + 'null settings = simple cancel', + ); + assert.strictEqual( + generation.cancellationNoticeKey({ backend: 'api' }, null), + 'cancelRequested', + 'null job = simple cancel', + ); + assert.strictEqual( + generation.cancellationNoticeKey(null, null), + 'cancelRequested', + 'both null = simple cancel', + ); + + console.log('direct generation tests passed'); + } finally { + cleanup(); + } +})().catch((e) => { console.error(e); process.exit(1); });