Skip to content

Commit 2724517

Browse files
fix(workspace-hub): validate structured API payloads
1 parent e0d2adc commit 2724517

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2026-04-12
4+
5+
- Added runtime payload validation bounds to `repos/workspace-hub/src/lib/api.ts` so `runRepoIntake`, `runWorkspaceCapabilityAction`, and `applyRepoAgentPreset` execute strict schema-shape verification before asserting TypeScript types, preventing downstream React faults on malformed payloads.
6+
37
## 2026-04-11
48

59
- Bumped the workspace baseline release to `v1.2.2` and updated `repos/workspace-hub` to `1.2.2` to capture the side-load `entry.md` packet flow, manifest `entryDocs` support, and thin-versus-deep indexed search as the new published baseline.

docs/HANDOVER.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,3 +896,15 @@ Verification status for this local slice:
896896
Pickup note:
897897

898898
- if this slice lands, update `docs/CHANGELOG.md`, `docs/README.md`, and any relevant `workspace-hub` docs summary so the public side-load contract reflects `entry.md` and the new indexed-search modes
899+
900+
### Implementation update (2026-04-12, runtime payload safety)
901+
902+
Completed in `repos/workspace-hub`:
903+
904+
1. Added strict validation constraints around core API calls fetching structured payloads (`runRepoIntake`, `runWorkspaceCapabilityAction`, and `applyRepoAgentPreset`) inside `src/lib/api.ts`.
905+
2. Verified manual object validation throws clean Errors rather than silently returning structurally corrupt data to the React UI, establishing stricter type boundaries given the environment lacks `zod`.
906+
907+
Verification status for this local slice:
908+
909+
- `pnpm --dir "repos/workspace-hub" typecheck`
910+
- `pnpm --dir "repos/workspace-hub" test`

repos/workspace-hub/src/lib/api.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ export async function runWorkspaceCapabilityAction(
174174
throw new Error(await readErrorMessage(response))
175175
}
176176

177-
return (await response.json()) as {
177+
const data = await response.json()
178+
if (!data || typeof data !== 'object' || !('ok' in data) || !('output' in data)) {
179+
throw new Error('Malformed response received from capability action endpoint')
180+
}
181+
182+
return data as {
178183
ok: boolean
179184
output: string
180185
}
@@ -325,7 +330,12 @@ export async function runRepoIntake(relativePath: string) {
325330
throw new Error(await readErrorMessage(response))
326331
}
327332

328-
return (await response.json()) as {
333+
const data = await response.json()
334+
if (!data || typeof data !== 'object' || !('ok' in data) || !('result' in data)) {
335+
throw new Error('Malformed response received from intake endpoint')
336+
}
337+
338+
return data as {
329339
ok: boolean
330340
result: RepoIntakeResult
331341
}
@@ -413,7 +423,12 @@ export async function applyRepoAgentPreset(
413423
throw new Error(await readErrorMessage(response))
414424
}
415425

416-
return (await response.json()) as {
426+
const data = await response.json()
427+
if (!data || typeof data !== 'object' || !('ok' in data) || !('result' in data)) {
428+
throw new Error('Malformed response received from agent preset endpoint')
429+
}
430+
431+
return data as {
417432
ok: true
418433
result: RepoAgentPresetResult
419434
}

0 commit comments

Comments
 (0)