Repository navigation
test: assert API error responses through a shared helper - #3558
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR replaces 159 repeated API error assertion pairs with a shared helper that includes the response body in failure messages. Example: An API refusal test expects 403 FORBIDDEN but receives 500 INTERNAL_ERROR.
Review scores
ProductKind: Test only · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides useful test cleanup, preserves the existing expectations, and has no actionable findings. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherIntegration and conformance tests pass parsed controller responses into the helper, which checks HTTP status and error code and produces assertion diagnostics. flowchart LR
A[Test scenario] --> B[Controller API]
B --> C[Parsed response]
C --> D[Shared error assertion]
D --> E[Test result and diagnostics]
Technical reviewBest possible solution: Retain the small shared assertion helper and its behavior-preserving caller replacements. Do we have a high-confidence way to reproduce the issue? No product bug is claimed; the pinned base assertions directly establish the repeated checks and inconsistent diagnostic messages. Is this the best way to solve the issue? The helper is a proportionate solution: it preserves strict comparisons, keeps expectations at each call site, and leaves richer assertions in place. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against eef2a181350f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 24, 2026, 8:58 PM ET / October 25, 2026, 00:58 UTC. |
Problem
Tests check API refusals with the same two lines over and over:
assert.equal(x.status, 4xx, ...)and thenassert.equal(x.body.error.code, "CODE", ...). A survey oftests/on main found 181 such pairs in 19 files (96 inocc-api.test.mjs). The failure messages differ by site: some print the body, some print only a label, and some print nothing, so a refusal that answered differently can fail without showing what came back.Change
tests/helpers/api-error.mjswithassertApiError(response, status, code, label). It assertsresponse.statusandresponse.body.error.codewith the same strictassert.equalthe call sites used. Each failure message is the response body as JSON, afterlabelwhen given.${label}: ${JSON.stringify(body)}message becomeslabel). Sites that printedx.textnow print the parsed body.configuration-controller.test.mjsandstatic-egress.test.mjs(both edited by feat(occdev): wire the OpenShell Git route into occ dev up with an installed acceptance #3045).native-admin-access.test.mjsthat feat: assign configured OpenClaw roles to Agent users #906 rewrites.credential-source-api.test.mjspairs whose status and code messages differ.deepEqual(x.body.error, {...})checks: they assert more than the helper does.Test-only. No product code, assertion values or test names change.
Verification
postgres-agent-provisioningandcredential-proxy-withdrawalran in the full postgres-platform lane on a remote test VM: the lane passed (postgres-agent-provisioning 84.5 s, credential-proxy-withdrawal 6.3 s).status + 1fails every file (occ-api 37 cases, plugin-discovery-api 9, secret-api 8, presets-controller 7, runtime-credentials-api 6, and 1-3 in each of the others).code + "_"fails the same cases.tsc --build tsconfig.json tests/tsconfig.json, ESLint and Prettier are clean.git merge-tree: none of the 17 open PRs that touch these files (feat: add Agent workload tags #115, feat: assign configured OpenClaw roles to Agent users #906, fix(ssh): accept operator-provisioned channel credentials #914, feat(iam): grant the deployer exact read of the revision a deploy admits #1605, fix(credentials): release refresh bootstrap references and preserve resend protection #1952, fix: preserve native plugin permissions across Harness selection and admission #2258, fix: prepare native admin access on the first Agent deployment #2259, fix(worker): settle initial provisioning on a superseding deploy or stop #2268, feat(plugins): let administrators approve pinned plugin releases #2398, Draft implementation: managed outbound HTTPS for dedicated Gateways #2518, fix(credentials): retain every Secret the gateway may hold during updates #2520, Propose execution-scoped Strands history policy above Credential Proxy #2533, feat(console): show the authorized native Gateway people roster #2596, feat: add Gateway managed mode to Agent deployments #2982, feat(occdev): wire the OpenShell Git route into occ dev up with an installed acceptance #3045, fix(kubernetes): preserve explicit human Gateway identities #3049, Bind OpenClaw plugin selections to Agent connections #3343) gets a new conflicted file or conflict hunk.Risks
Low. The helper asserts the same two values with the same strict equality; the messages now include the body where some sites had none. A response without
body.errorstill fails with a TypeError, as before.