Repository navigation
fix(core): parse QWEN_SERVE_MCP_CLIENT_BUDGET strictly as a decimal integer #5752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2627,6 +2627,25 @@ describe('McpClientManager — PR 14 guardrails', () => { | |
| } | ||
| }); | ||
|
|
||
| it('readBudgetFromEnv rejects non-decimal budget values (hex / scientific / float)', async () => { | ||
| const writeSpy = vi.spyOn(process.stderr, 'write').mockReturnValue(true); | ||
| try { | ||
| for (const bad of ['0x10', '1e2', '1.0']) { | ||
| process.env['QWEN_SERVE_MCP_CLIENT_BUDGET'] = bad; | ||
| const manager = mkManager({ config: configWithServers({}) }); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The stderr breadcrumb is the sole operator-facing signal for rejected values. Add an assertion after the rejection loop: const calls = writeSpy.mock.calls.map((c) => String(c[0]));
expect(calls.some(s => s.includes("'0x10'"))).toBe(true);— qwen3.7-max via Qwen Code /review |
||
| // Pre-fix Number('0x10')=16 / Number('1e2')=100 slipped through as a budget. | ||
| expect(manager.getMcpClientBudget()).toBeUndefined(); | ||
| } | ||
| // a plain decimal integer is still accepted. | ||
| process.env['QWEN_SERVE_MCP_CLIENT_BUDGET'] = '16'; | ||
| const ok = mkManager({ config: configWithServers({}) }); | ||
| expect(ok.getMcpClientBudget()).toBe(16); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The upgrade from — qwen3.7-max via Qwen Code /review |
||
| } finally { | ||
| writeSpy.mockRestore(); | ||
| delete process.env['QWEN_SERVE_MCP_CLIENT_BUDGET']; | ||
| } | ||
| }); | ||
|
|
||
| it('readResource rejects existing-but-now-disabled servers (wenshao R7 #5 line 1342)', async () => { | ||
| // Pre-fix: a server connected pre-disable and then operator- | ||
| // disabled mid-session via settings reload would still serve | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,7 +269,8 @@ export function mcpTransportOf(config: MCPServerConfig): McpTransportKind { | |
| * behavior, no enforcement. | ||
| * | ||
| * `QWEN_SERVE_MCP_CLIENT_BUDGET` — positive integer; non-numeric / | ||
| * zero / negative / NaN are silently ignored (treated as unset). | ||
| * zero / negative / NaN are rejected (treated as unset) and a | ||
| * stderr breadcrumb is written so the misconfiguration is visible. | ||
| * `QWEN_SERVE_MCP_BUDGET_MODE` — `enforce|warn|off`. Defaults to | ||
| * `warn` when a budget is set, `off` otherwise. | ||
| */ | ||
|
|
@@ -278,8 +279,12 @@ function readBudgetFromEnv(): McpBudgetConfig { | |
| const rawMode = process.env['QWEN_SERVE_MCP_BUDGET_MODE']; | ||
| let clientBudget: number | undefined; | ||
| if (rawBudget !== undefined && rawBudget !== '') { | ||
| const parsed = Number(rawBudget); | ||
| if (Number.isFinite(parsed) && Number.isInteger(parsed) && parsed > 0) { | ||
| // Parse strictly as a decimal integer: Number('0x10')=16, Number('1e2')=100 | ||
| // and Number('1.0')=1 all pass isInteger, so a loose parse would silently | ||
| // accept them. Only plain decimal digits should set a budget. | ||
| const trimmed = rawBudget.trim(); | ||
| const parsed = Number(trimmed); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The inline parsing logic ( Consider replacing the inline parse with: const budget = parsePositiveIntegerEnv('QWEN_SERVE_MCP_CLIENT_BUDGET');The stderr warning branch still works since — qwen3.7-max via Qwen Code /review |
||
| if (/^\d+$/.test(trimmed) && Number.isSafeInteger(parsed) && parsed > 0) { | ||
| clientBudget = parsed; | ||
| } else { | ||
| // operator typos | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] The
.trim()code path added at source line 284 is not tested. Consider adding whitespace-padded values:" 16 "(should be accepted as 16) and" 0x10 "(should still be rejected after trim) to the test cases.— qwen3.7-max via Qwen Code /review