From 385e830f1b7a1015c284b78d286d35d0e48b667f Mon Sep 17 00:00:00 2001 From: sykosyber Date: Mon, 12 Oct 2026 20:08:46 -0700 Subject: [PATCH] Codex: repeat query lists only on reads, and refuse an empty required list Writes and computes keep sending one JSON value for a list, as they did before #160, so no write path changes. A required query list given as [] is INPUT_INVALID instead of being left out of the request. Co-Authored-By: Claude Opus 5.5 --- src/core/capabilities/execute.ts | 6 +++++- src/core/capabilities/httpTarget.ts | 11 ++++++---- .../capabilities/listQueryParameters.test.ts | 21 ++++++++++++++++++- src/core/services/server/capabilityBroker.ts | 2 +- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/core/capabilities/execute.ts b/src/core/capabilities/execute.ts index e6058fb..796808e 100644 --- a/src/core/capabilities/execute.ts +++ b/src/core/capabilities/execute.ts @@ -180,7 +180,7 @@ function prepareRun(manifest: CapabilityManifest, args: Readonly { describe('sending a list in the query', () => { it('repeats the name once per element, in order', () => { const params = new URLSearchParams('part=old'); - setQueryParam(params, 'part', ['snippet', 'statistics']); + setQueryParam(params, 'part', ['snippet', 'statistics'], 'read'); expect(params.toString()).toBe('part=snippet&part=statistics'); }); + it('keeps sending one JSON value for anything but a read, as before', () => { + for (const effect of ['compute', 'write', 'destructive'] as const) { + const params = new URLSearchParams(); + setQueryParam(params, 'tags', ['a', 'b'], effect); + expect(params.getAll('tags')).toEqual(['["a","b"]']); + } + }); + beforeEach(() => { clearCapabilities(); capabilitySecrets.clear(); @@ -79,6 +87,17 @@ describe('sending a list in the query', () => { expect(new URL(fetchMock.mock.calls[0][0]).searchParams.getAll('part')).toEqual(['snippet']); }); + it('refuses an empty required list instead of leaving it out', async () => { + const [manifest] = compileOpenApi(spec(LIST)).manifests; + expect(installProposal(manifest).ok).toBe(true); + const fetchMock = vi.fn(); + vi.stubGlobal('fetch', fetchMock); + const result = await executeCapability(manifest.id, { part: [] }); + expect(result.error?.code).toBe('INPUT_INVALID'); + expect(result.error?.message).toContain('part needs at least one value'); + expect(fetchMock).not.toHaveBeenCalled(); + }); + it('through the broker', async () => { const [manifest] = compileOpenApi(spec(LIST), { brokerOrigins: ['https://videos.example.test'] }).manifests; const seen: PinnedRequest[] = []; diff --git a/src/core/services/server/capabilityBroker.ts b/src/core/services/server/capabilityBroker.ts index 8e480f7..626083a 100644 --- a/src/core/services/server/capabilityBroker.ts +++ b/src/core/services/server/capabilityBroker.ts @@ -316,7 +316,7 @@ function buildUrl(manifest: CapabilityManifest, input: Record): const url = target.url; for (const entry of manifest.inputs) { if (!Object.hasOwn(input, entry.name) || input[entry.name] === undefined || entry.in !== 'query') continue; - setQueryParam(url.searchParams, entry.name, input[entry.name]); + setQueryParam(url.searchParams, entry.name, input[entry.name], manifest.effect); } return url; }