Repository navigation
fix(sdk): support relative daemon base URLs in remaining workspace file helpers #9817
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 1 commit
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 |
|---|---|---|
|
|
@@ -1798,22 +1798,21 @@ export class DaemonClient { | |
| } = {}, | ||
| clientId?: string, | ||
| ): Promise<DaemonWorkspaceFile> { | ||
| const url = new URL(`${this.baseUrl}/file`); | ||
| url.searchParams.set('path', filePath); | ||
| const query = new URLSearchParams({ path: filePath }); | ||
| if (opts.maxBytes !== undefined) { | ||
| url.searchParams.set('maxBytes', String(opts.maxBytes)); | ||
| query.set('maxBytes', String(opts.maxBytes)); | ||
| } | ||
| if (opts.line !== undefined) { | ||
| url.searchParams.set('line', String(opts.line)); | ||
| query.set('line', String(opts.line)); | ||
| } | ||
| if (opts.limit !== undefined) { | ||
| url.searchParams.set('limit', String(opts.limit)); | ||
| query.set('limit', String(opts.limit)); | ||
| } | ||
| if (opts.cursor !== undefined) { | ||
| url.searchParams.set('cursor', opts.cursor); | ||
| query.set('cursor', opts.cursor); | ||
| } | ||
| return await this.fetchWithTimeout( | ||
| url.toString(), | ||
| `${this.baseUrl}/file?${query.toString()}`, | ||
| { headers: this.headers({}, clientId) }, | ||
| async (res) => { | ||
| if (!res.ok) throw await this.failOnError(res, 'GET /file'); | ||
|
|
@@ -1845,10 +1844,9 @@ export class DaemonClient { | |
| } | ||
|
|
||
| async fileStat(filePath: string): Promise<unknown> { | ||
| const url = new URL(`${this.baseUrl}/stat`); | ||
| url.searchParams.set('path', filePath); | ||
| const query = new URLSearchParams({ path: filePath }); | ||
|
Comment on lines
1846
to
+1847
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. Agreed on the diagnosis, and I'd rather not take it in this PR — reasoning below, happy to be overruled. You're right that the duplication is what caused this: #9734 fixed one copy, six were left behind, and #9816 is the bill for that. A helper is the correct end state. Two reasons to do it separately:
The smaller 中文说明同意你的判断,但我倾向于不在本 PR 中处理——理由如下,如有异议我可以照办。 重复代码确实是根因:#9734 只修复了一处,遗留了六处,#9816 就是代价。抽取 helper 是正确的最终形态。 分开处理的两个理由:
你给出的较小的 |
||
| return await this.fetchWithTimeout( | ||
| url.toString(), | ||
| `${this.baseUrl}/stat?${query.toString()}`, | ||
| { headers: this.headers() }, | ||
| async (res) => { | ||
| if (!res.ok) throw await this.failOnError(res, 'GET /stat'); | ||
|
|
@@ -1858,10 +1856,9 @@ export class DaemonClient { | |
| } | ||
|
|
||
| async dirList(dirPath: string): Promise<unknown> { | ||
| const url = new URL(`${this.baseUrl}/list`); | ||
| url.searchParams.set('path', dirPath); | ||
| const query = new URLSearchParams({ path: dirPath }); | ||
| return await this.fetchWithTimeout( | ||
| url.toString(), | ||
| `${this.baseUrl}/list?${query.toString()}`, | ||
| { headers: this.headers() }, | ||
| async (res) => { | ||
| if (!res.ok) throw await this.failOnError(res, 'GET /list'); | ||
|
|
@@ -1875,10 +1872,9 @@ export class DaemonClient { | |
| * pick a path outside any registered workspace (e.g. "Add workspace"). | ||
| */ | ||
| async workspacePathSuggestions(prefix: string): Promise<unknown> { | ||
| const url = new URL(`${this.baseUrl}/workspace-path-suggestions`); | ||
| url.searchParams.set('prefix', prefix); | ||
| const query = new URLSearchParams({ prefix }); | ||
| return await this.fetchWithTimeout( | ||
| url.toString(), | ||
| `${this.baseUrl}/workspace-path-suggestions?${query.toString()}`, | ||
| { headers: this.headers() }, | ||
| async (res) => { | ||
| if (!res.ok) { | ||
|
|
@@ -1903,10 +1899,9 @@ export class DaemonClient { | |
| } | ||
|
|
||
| async glob(pattern: string): Promise<unknown> { | ||
| const url = new URL(`${this.baseUrl}/glob`); | ||
| url.searchParams.set('pattern', pattern); | ||
| const query = new URLSearchParams({ pattern }); | ||
| return await this.fetchWithTimeout( | ||
| url.toString(), | ||
| `${this.baseUrl}/glob?${query.toString()}`, | ||
| { headers: this.headers() }, | ||
| async (res) => { | ||
| if (!res.ok) throw await this.failOnError(res, 'GET /glob'); | ||
|
|
@@ -1970,9 +1965,8 @@ export class DaemonClient { | |
| req: DaemonWorkspaceFileUploadRequest, | ||
| clientId?: string, | ||
| ): Promise<DaemonWorkspaceFileUploadResult> { | ||
| const target = new URL(`${this.baseUrl}${uploadPath}`); | ||
| target.searchParams.set('path', req.path); | ||
| const url = target.toString(); | ||
| const query = new URLSearchParams({ path: req.path }); | ||
| const url = `${this.baseUrl}${uploadPath}?${query.toString()}`; | ||
| const headers = this.headers( | ||
| { 'Content-Type': 'application/octet-stream' }, | ||
| clientId, | ||
|
|
||
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.
Fixed in 4c7da78 — and thank you for the mutation probe, it reproduced exactly.
Baseline on this branch:
35 files, 1659/1659 passed. Deleting themaxBytesbranch fromreadWorkspaceFileleaves that identical — 35 files, 1659/1659 — so the branch really was invisible to the suite.Worth noting why it hid:
maxBytesdoes appear in two existing assertions (lines 578 and 602), but both belong toreadWorkspaceFileByteshittingGET /file/bytes. Different method, different endpoint. Of the four optional paramsreadWorkspaceFileserialises,cursoris covered at line 533 andline/limitby the new relative-base test —maxByteswas the only one nothing pinned on either base URL.The relative-base test now asserts a second call carrying it:
I kept the original
{ line: 2, limit: 3 }assertion rather than replacing it, so the omitted case still proves the branch is conditional.Re-running the same mutation with this in place now fails:
Full suite green with the branch restored: 35 files, 1659/1659.
中文说明
已在 4c7da78 中修复——感谢提供变异测试探针,本地完全复现。
本分支基线:
35 files, 1659/1659 passed。从readWorkspaceFile中删除maxBytes分支后结果完全相同——35 files、1659/1659,说明该分支确实未被测试覆盖。补充一点它为何被漏掉:
maxBytes确实出现在现有的两处断言中(第 578、602 行),但它们属于readWorkspaceFileBytes请求的GET /file/bytes——方法不同,端点也不同。readWorkspaceFile序列化的四个可选参数中,cursor由第 533 行覆盖,line/limit由新增的相对 base URL 测试覆盖,只有maxBytes在两种 base URL 下都无测试锚定。相对 base URL 的测试现在增加了一次携带该参数的调用断言,并保留了原有的
{ line: 2, limit: 3 }断言,以便同时验证该分支是条件生效的。在此改动下重跑同一变异测试会失败;恢复分支后全量测试通过:35 files、1659/1659。