mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-24 19:52:53 +08:00
fix(sdk): encode the signature hash in client.telemetry.getTool (#4772)
## Description `client.telemetry.getTool(signatureHash)` in `sdk/typescript/src/client.ts` (line 461 on `200c838c`) put its argument into the URL path unencoded. The `feedback` method (line 473) and the `toin` method (line 489) in the same file wrap theirs in `encodeURIComponent`. A value containing `/`, `?` or `#` changed which route was requested; for example `"../../v1/feedback?x=1#f"` reached a real HTTP server as `GET /v1/v1/feedback?x=1`. This PR wraps the argument in `encodeURIComponent`, the same way. Real hash values are hex digests, so they are unchanged. Closes #4769 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - `sdk/typescript/src/client.ts`: `getTool` uses `encodeURIComponent(signatureHash)`. - `sdk/typescript/test/client-expanded.test.ts`: one test, `telemetry.getTool encodes the signature hash like feedback and toin do`, with a stubbed `fetch`. ## Testing - [ ] Unit tests pass (`pytest`) - [ ] Linting passes (`ruff check .`) - [ ] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [x] Manual testing performed This is a TypeScript-only change, so the Python checks above do not apply; the SDK equivalents were run (Node v24.22.2, vitest 5.1.0, `npm ci --ignore-scripts` from the committed lockfile, Ubuntu on WSL2). ### Test Output Fail before (`client.ts` from `200c838c`, new test kept): ```text vitest run test/client-expanded.test.ts -t "telemetry.getTool" × telemetry.getTool encodes the signature hash like feedback and toin do AssertionError: expected 'http://test:8787/v1/telemetry/tools/.…' to be 'http://test:8787/v1/telemetry/tools/.…' Tests 1 failed | 34 skipped (35) ``` Pass after (this branch): ```text vitest run test/client-expanded.test.ts -t "telemetry.getTool" Tests 1 passed | 34 skipped (35) vitest run (whole sdk/typescript suite) Test Files 19 passed | 5 skipped (24) Tests 460 passed | 33 skipped (493) tsc --noEmit -> exit 0 ``` ## Real Behavior Proof - Environment: Ubuntu on WSL2, Node v24.22.2, the built package (`npm ci --ignore-scripts && npx tsup` in `sdk/typescript`) and a real `node:http` server on 127.0.0.1, not a mock. - Exact command / steps: `git checkout <branch>` (or `origin/main` for "before"); build as above; start a `node:http` server that records `req.method` and `req.url` and answers `{}`; create `new HeadroomClient({ baseUrl, fallback: false })` from `dist/index.js` and call `client.telemetry.getTool("../../v1/feedback?x=1#f")` and `client.telemetry.getTool("abc123def456")`. - Observed result: before (`200c838c`) the server saw `GET /v1/v1/feedback?x=1` and `GET /v1/telemetry/tools/abc123def456`. After (this branch) it saw `GET /v1/telemetry/tools/..%2F..%2Fv1%2Ffeedback%3Fx%3D1%23f` and `GET /v1/telemetry/tools/abc123def456`; a normal hex hash is unchanged. - Not tested: a real Headroom proxy (the server is a recorder), so how the proxy answers the encoded path is not checked. ## Runtime Rollout Safety - Rollout-managed feature(s): none; TypeScript SDK client only. - Minimum rollout channel: n/a - Stable/default behavior changed: only for a value with `/`, `?` or `#`; hex hashes request the same URL as before. - Kill switch / disable path: n/a - Unsafe override required: no - Qualification impact: none - Rollback path: revert this commit. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] I did **not** edit `CHANGELOG.md` — it is generated by release-please from my Conventional Commit PR title (a CI guard enforces this) ## Additional Notes - No documentation change. I did not add a code comment either: the one-line change follows the neighbouring `feedback` and `toin` methods. AI assistance: this change, its tests and the runs above were done with Claude (Sonnet 5.5), operated by me (HetCreep). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
99ef4eec82
commit
3c66c91eea
@@ -459,7 +459,7 @@ export class HeadroomClient implements HeadroomClientInterface {
|
||||
return deepCamelCase(await resp.json());
|
||||
},
|
||||
getTool: async (signatureHash: string): Promise<any> => {
|
||||
const resp = await this._fetch(`/v1/telemetry/tools/${signatureHash}`, { method: "GET" });
|
||||
const resp = await this._fetch(`/v1/telemetry/tools/${encodeURIComponent(signatureHash)}`, { method: "GET" });
|
||||
return deepCamelCase(await resp.json());
|
||||
},
|
||||
};
|
||||
|
||||
@@ -395,6 +395,15 @@ describe("shared HTTP transport", () => {
|
||||
expect(mockFetch.mock.calls[2][1].body).toBeUndefined();
|
||||
});
|
||||
|
||||
it("telemetry.getTool encodes the signature hash like feedback and toin do", async () => {
|
||||
mockFetch.mockResolvedValue(jsonResponse({}));
|
||||
const client = new HeadroomClient({ baseUrl: "http://test:8787" });
|
||||
await client.telemetry.getTool("../../v1/feedback?x=1#f");
|
||||
expect(mockFetch.mock.calls[0][0]).toBe(
|
||||
"http://test:8787/v1/telemetry/tools/..%2F..%2Fv1%2Ffeedback%3Fx%3D1%23f",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps proxy headers on requests without provider auth", async () => {
|
||||
mockFetch.mockResolvedValue(jsonResponse({ ok: true }));
|
||||
const client = new HeadroomClient({ baseUrl: "http://test:8787", apiKey: "hr_proxykey", stack: "cli" });
|
||||
|
||||
Reference in New Issue
Block a user