diff --git a/CHANGELOG.md b/CHANGELOG.md index bdaf09e4c8..e52c402baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,12 @@ ### Fixed +- **sse/chatCore:** remove a duplicate `const settings` declaration in + `handleChatCore` (introduced alongside the per-key stream-default-mode + feature). The same-scope redeclaration made esbuild/tsx fail with + "The symbol 'settings' has already been declared", which turned every unit + test that imports chatCore red and broke the production build. The earlier + consolidated `settings` const is now reused. - **db/migrations:** resolve a `077` migration version collision (`077_api_key_stream_default_mode.sql` vs `077_quota_pools.sql`) that made `getMigrationFiles()` throw and blocked `getDbInstance()` at startup (app would diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.ts index 7fa8fdf045..763e7c4721 100644 --- a/open-sse/handlers/chatCore.ts +++ b/open-sse/handlers/chatCore.ts @@ -2151,7 +2151,10 @@ export async function handleChatCore({ userAgent: streamUserAgent, streamDefaultMode: apiKeyInfo?.streamDefaultMode, }); - const settings = cachedSettings ?? (await getCachedSettings()); + // `settings` is already consolidated once near the top of handleChatCore + // (the "fetch once, reuse" const). A second `const settings` here was a + // duplicate same-scope declaration that broke the esbuild/tsx transform + // ("settings has already been declared") and the production build. Reuse it. credentials = applyCodexGlobalFastServiceTier(provider, credentials, settings, { model: requestedModel, body: body && typeof body === "object" ? (body as Record) : null, diff --git a/tests/unit/chatcore-imports-cleanly.test.ts b/tests/unit/chatcore-imports-cleanly.test.ts new file mode 100644 index 0000000000..6033e3a58c --- /dev/null +++ b/tests/unit/chatcore-imports-cleanly.test.ts @@ -0,0 +1,23 @@ +/** + * Regression guard: `open-sse/handlers/chatCore.ts` must transform/compile. + * + * `handleChatCore` declared `const settings` twice in the same function scope + * (a "fetch once, reuse" const near the top + a duplicate added by the per-key + * stream-default-mode feature). esbuild/tsx rejected it with + * "The symbol 'settings' has already been declared", which turned EVERY test + * that imports chatCore red and broke the production build. + * + * Importing the module forces the transform; if the duplicate declaration + * returns, this import throws and the test fails loudly. + */ +import test from "node:test"; +import assert from "node:assert/strict"; + +test("chatCore.ts imports without a duplicate-declaration transform error", async () => { + const mod = await import("../../open-sse/handlers/chatCore.ts"); + assert.equal( + typeof mod.handleChatCore, + "function", + "handleChatCore must be importable (no duplicate `const settings` in scope)" + ); +});