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
This commit is contained in:
wujunchen 2026-04-27 15:29:29 +08:00
parent 0f8625874e
commit 6f80d0de03
2 changed files with 75 additions and 1 deletions

View file

@ -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",

View file

@ -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); });