-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(desktop): validate list_sessions pagination params #7162
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
76fe734
2e8746c
403c0d3
73840a1
d60feeb
eec88b0
a99b024
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||||||||
| import { describe, expect, it } from 'bun:test'; | ||||||||||||
| import { handleListSessions } from './list-sessions.ts'; | ||||||||||||
|
Comment on lines
+1
to
+2
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] This test file (and the pre-existing Consider adding a CI step that runs — qwen3.7-max via Qwen Code /review
Contributor
Author
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. Thanks, addressed. I added a full-profile CI step that runs the focused desktop regression test with |
||||||||||||
| import type { ListSessionsOptions, SessionToolContext } from '../context.ts'; | ||||||||||||
|
|
||||||||||||
| function createCtx( | ||||||||||||
| onListSessions: (options?: ListSessionsOptions) => void, | ||||||||||||
| ): SessionToolContext { | ||||||||||||
| return { | ||||||||||||
| listSessions: (options?: ListSessionsOptions) => { | ||||||||||||
| onListSessions(options); | ||||||||||||
| return { | ||||||||||||
| total: 1, | ||||||||||||
| returned: 1, | ||||||||||||
| sessions: [ | ||||||||||||
| { | ||||||||||||
| id: 'session-123', | ||||||||||||
| name: 'Example', | ||||||||||||
| labels: [], | ||||||||||||
| status: 'todo', | ||||||||||||
| createdAt: 1, | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }; | ||||||||||||
| }, | ||||||||||||
| } as unknown as SessionToolContext; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| describe('handleListSessions', () => { | ||||||||||||
| it('rejects malformed pagination values before listing sessions', async () => { | ||||||||||||
| const cases: Array<{ args: ListSessionsOptions; message: string }> = [ | ||||||||||||
| { args: { limit: 0 }, message: 'limit must be a positive integer.' }, | ||||||||||||
| { args: { limit: -1 }, message: 'limit must be a positive integer.' }, | ||||||||||||
| { args: { limit: 1.5 }, message: 'limit must be a positive integer.' }, | ||||||||||||
|
Comment on lines
+32
to
+33
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] Missing boundary tests (
Suggested change
Also consider adding a valid-boundary test: it('accepts minimum valid pagination boundaries', async () => {
const calls: Array<ListSessionsOptions | undefined> = [];
const ctx = createCtx((options) => calls.push(options));
const result = await handleListSessions(ctx, { limit: 1, offset: 0 });
expect(result.isError).toBe(false);
expect(calls).toEqual([{ limit: 1, offset: 0 }]);
});— qwen3.7-max via Qwen Code /review
Contributor
Author
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. Thanks, addressed. I added the invalid |
||||||||||||
| { | ||||||||||||
| args: { offset: -1 }, | ||||||||||||
| message: 'offset must be a non-negative integer.', | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| args: { offset: 1.5 }, | ||||||||||||
| message: 'offset must be a non-negative integer.', | ||||||||||||
| }, | ||||||||||||
| ]; | ||||||||||||
|
|
||||||||||||
| for (const { args, message } of cases) { | ||||||||||||
| const calls: Array<ListSessionsOptions | undefined> = []; | ||||||||||||
| const ctx = createCtx((options) => calls.push(options)); | ||||||||||||
|
|
||||||||||||
| const result = await handleListSessions(ctx, args); | ||||||||||||
|
|
||||||||||||
| expect(result.isError).toBe(true); | ||||||||||||
| expect(result.content[0]?.text).toContain(message); | ||||||||||||
| expect(calls).toEqual([]); | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('accepts minimum valid pagination boundaries', async () => { | ||||||||||||
| const calls: Array<ListSessionsOptions | undefined> = []; | ||||||||||||
| const ctx = createCtx((options) => calls.push(options)); | ||||||||||||
|
|
||||||||||||
| const result = await handleListSessions(ctx, { limit: 1, offset: 0 }); | ||||||||||||
|
|
||||||||||||
| expect(result.isError).toBe(false); | ||||||||||||
| expect(calls).toEqual([{ limit: 1, offset: 0 }]); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('passes valid pagination values through to the session lister', async () => { | ||||||||||||
| const calls: Array<ListSessionsOptions | undefined> = []; | ||||||||||||
| const ctx = createCtx((options) => calls.push(options)); | ||||||||||||
|
|
||||||||||||
| const result = await handleListSessions(ctx, { | ||||||||||||
| status: 'todo', | ||||||||||||
| limit: 2, | ||||||||||||
| offset: 1, | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| expect(result.isError).toBe(false); | ||||||||||||
| expect(calls).toEqual([{ status: 'todo', limit: 2, offset: 1 }]); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('preserves high integer limits for the backend clamp', async () => { | ||||||||||||
| const calls: Array<ListSessionsOptions | undefined> = []; | ||||||||||||
| const ctx = createCtx((options) => calls.push(options)); | ||||||||||||
|
|
||||||||||||
| const result = await handleListSessions(ctx, { limit: 101 }); | ||||||||||||
|
|
||||||||||||
| expect(result.isError).toBe(false); | ||||||||||||
| expect(calls).toEqual([{ limit: 101 }]); | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,19 @@ describe('session tool filtering helpers', () => { | |||||||||||||
| expect(names.includes('send_developer_feedback')).toBe(false); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it('json schema exposes list_sessions pagination controls as integers', () => { | ||||||||||||||
| const defs = getToolDefsAsJsonSchema({ includeDeveloperFeedback: false }); | ||||||||||||||
| const listSessions = defs.find(d => d.name === 'list_sessions'); | ||||||||||||||
| const properties = ( | ||||||||||||||
| listSessions?.inputSchema as | ||||||||||||||
| | { properties?: Record<string, { type?: string }> } | ||||||||||||||
| | undefined | ||||||||||||||
| )?.properties; | ||||||||||||||
|
|
||||||||||||||
| expect(properties?.limit?.type).toBe('integer'); | ||||||||||||||
| expect(properties?.offset?.type).toBe('integer'); | ||||||||||||||
|
Comment on lines
+55
to
+56
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 schema test verifies only
Suggested change
中文说明Schema 测试仅验证了 — qwen3.8-max-preview via Qwen Code /review |
||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it('all canonical session tools declare safeMode metadata', () => { | ||||||||||||||
| for (const def of SESSION_TOOL_DEFS) { | ||||||||||||||
| expect(def.safeMode === 'allow' || def.safeMode === 'block').toBe(true); | ||||||||||||||
|
|
||||||||||||||
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 CI step is named "Run desktop session-tools-core tests" but hardcodes only
list-sessions.test.ts. Thetool-defs-filtering.test.tschange made in this same PR (thetype === 'integer'schema assertion) is not covered by any CI step — Concrete cost: if a future change revertsz.number().int()toz.number(), the schema test catches it locally but CI stays green, and the regression ships undetected.中文说明
CI 步骤名为 "Run desktop session-tools-core tests",但只硬编码了
list-sessions.test.ts。本 PR 同时修改的tool-defs-filtering.test.ts(schema integer 类型断言)没有被任何 CI 步骤覆盖。具体代价:如果未来某个变更将z.number().int()回退为z.number(),schema 测试在本地能捕获,但 CI 仍为绿色,回归会不被发现地合入。— qwen3.8-max-preview via Qwen Code /review