Repository navigation
fix(sse): remove duplicate const settings in handleChatCore (release-blocker) - #2989
Conversation
handleChatCore declared `const settings = cachedSettings ?? await
getCachedSettings()` twice in the same function scope — the consolidated
"fetch once, reuse" const near the top, plus a duplicate added alongside the
per-key stream-default-mode feature. esbuild/tsx rejected the same-scope
redeclaration ("The symbol 'settings' has already been declared"), which made
every unit test that imports chatCore fail to transform and broke the
production build.
Remove the duplicate; reuse the earlier consolidated `settings`. Add an
import-guard regression test.
There was a problem hiding this comment.
Code Review
This pull request resolves a duplicate const settings declaration in open-sse/handlers/chatCore.ts that was causing build and test failures, and adds a regression test to prevent future occurrences. Feedback on these changes suggests removing the verbose comment documenting the bug in the source code, and refactoring the new test file to use vitest instead of Node's native test runner to align with the repository's testing framework.
| 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)" | ||
| ); | ||
| }); |
There was a problem hiding this comment.
The project uses Vitest as its primary test runner (as indicated by the presence of vitest.config.ts in the repository configuration). For consistency across the test suite and proper integration with Vitest's test runner, reporters, and coverage tools, please use vitest instead of the Node.js native node:test and node:assert modules.
import { test, expect } from "vitest";
test("chatCore.ts imports without a duplicate-declaration transform error", async () => {
const mod = await import("../../open-sse/handlers/chatCore.ts");
expect(typeof mod.handleChatCore).toBe("function");
});References
- Rule 1 of the Repository Style Guide mentions
vitest.config.tsas a standard configuration file and refers to test files as 'Vitest files', indicating Vitest is the standard testing framework for the repository. (link)
| // `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. |
There was a problem hiding this comment.
Avoid committing verbose comments that document past bugs, git history, or PR context directly in the source code. This information is already captured in the git history and PR description, and keeping it in the code adds unnecessary noise and can quickly become outdated. The code is self-explanatory without this comment.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge (already merged) Files Reviewed (3 files)
Reviewed by step-3.7-flash-20260528 · 363,616 tokens |
Problem (release-blocker)
handleChatCore(open-sse/handlers/chatCore.ts) declaredconst settings = cachedSettings ?? (await getCachedSettings())twice in the same function scope — the consolidated "fetch once, reuse" const (~line 1921) plus a duplicate (~line 2154) added alongside the per-key stream-default-mode feature (commit99d673fe5).esbuild/tsx rejects the same-scope redeclaration:
This turned every unit test that imports chatCore red (e.g.
system-role-extraction,claude-passthrough-thinking-2454) and breaks the production build (a duplicate block-scopedconstis a hard JS error).Fix
Remove the duplicate declaration; reuse the earlier consolidated
settings.Verification
chatcore-imports-cleanly(new import guard): 1/1system-role-extraction: 10/10 (was red — TransformError)claude-passthrough-thinking-2454: 4/4 (was red)settingsredeclare error; lint clean.🤖 Generated with Claude Code