Skip to content

fix(core): actionable authoring errors, strict request fixtures and JSON 422s - #607

Merged
jimhoyd merged 7 commits into
mainfrom
claude/authoring-strictness
Sep 24, 2026
Merged

jimhoyd merged 7 commits into
mainfrom
claude/authoring-strictness

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The usability audit found errors that do not say what went wrong, where it is, or how to fix it (#581). It also found an Express-style route that validates but never matches (#583), request fixtures that accept unknown keys and so pass when they check nothing (#584), and JSON routes that answer 422 as plain text showing a single issue (#587).

Resulting behavior

#583: Express-style segments. A segment like /users/:id is now refused by validate (and by schema-only validate_yaml), with file:line. The message gives the fix: write {id} and declare it under parameters: [{name: id, in: path, required: true, schema: {type: string}}]. Colons inside a segment (/a:b) are still literal.

#584: strict request fixtures.

  • A new shipped schemas/requests.schema.json is the fixture contract. It is in the tarball through the existing schemas entry, and test:package confirms it ships.
  • Unknown keys are refused. json, expectJson, url and similar keys get a hint saying what to write instead; typos get a did-you-mean (expectBdy → expectBody). The error names the fixture and the step.
  • Malformed fixture JSON reports its line and column instead of Operation failed.
  • A failing case in urlcode test prints its method, its path as written, and failures: {check, name, expected, actual, firstDifference} for each failed assertion. Each value is cut to about 200 characters starting just before the first difference. A value captured by steps is printed as {{name}}, never the value itself. audit output is unchanged and still shows no values.
  • Zero cases: urlcode test exits nonzero once the project has an active route. A project with no active routes (bare init, the starter, urlcode-template) passes with a no-test-cases warning, because the shipped GitHub Action runs urlcode test on the bare scaffold. test:package covers that flow.
  • The fixture format is documented in docs/AI-AUTHORING.md, which docs search covers, so urlcode docs search expectBody now finds it. It is also in docs/READINESS.md, both skills and the generated starter AGENTS.md.

#581: errors say what, where and how to fix. The table rows are covered as follows:

  • Two handlers on one route give declares 2 handlers (redirect, respond); a route with none gives declares no handler; add exactly one of: ….
  • A handler typo (redirct:) gives unknown key "redirct"; did you mean "redirect"?. These route-level checks run before the schema's oneOf, which used to report them as a missing redirect.
  • redirect: {to: …} gives missing required key "url"; found unknown key "to" instead (allowed keys: url, status, query). rotes: gives did you mean "routes"?.
  • Route paths are printed unescaped (route /a/b, redirect.status), not /routes/~1a~1b.
  • Enum and const failures list the allowed values (must be one of 301, 302, 303, 307, 308). Other keywords append Ajv's schema-derived message.
  • YAML syntax errors report line and column, the parser's reason and its code. The source excerpt, which may hold a value, is dropped.
  • Schema errors in urlcode.yaml and in included files are prefixed file:line:column:. The position comes from the YAML node.
  • Missing file: Referenced project file is missing: "functions/x.mjs", now with the route named. A missing --project directory gives Project directory not found. No urlcode.yaml gives No urlcode.yaml in <dir>; run urlcode init there….
  • Every compile error names its route (Route /u/{id}: …). A placeholder error names {id} and the parameters entry to add. A static route error shows the path to write (/s/*).
  • Denied env/secret bindings name the alias and the variable, and point at urlcode permissions and --policy <file>.
  • Sandbox import errors name the module and the specifier.
  • CLI: Unknown option --prot; did you mean --port?. An option with no value (--project, docs search --policy) says to put text that starts with - after --. context --budget 100 gives the smallest workable budget.
  • A target refusal now lists the targets that support every capability the project uses.
  • Structured fields: every error event carries whichever of code, route, file, line, column, pointer and key apply. This includes errors from the config worker. Codes are listed in docs/AI-AUTHORING.md.
  • Bundle and transport errors are left to [Bug]: init --with cannot succeed on 0.5.9: bundle attestation source ref is main, not the release tag #579, as agreed.

#587 (422 part only): JSON 422s. A route with a JSON request.body.schema now always answers 422 as application/json, whatever the Accept header, and lists every issue (at most 8, capped at 4096 bytes as before). Each of the first three undeclared properties is its own additionalProperties issue. The issue names the property in property only when the name looks like an identifier (^[A-Za-z_][A-Za-z0-9_-]{0,63}$); any other name is left out. Values are still never echoed. prefersJson negotiation is removed.

Breaking change: a client that parsed the plain-text 422 now receives JSON. This is documented in docs/HTTP.md and docs/SPECIFICATION.md, in the RIM-HTTP-001 card in docs/RUNTIME-IMPLEMENTATION.md, and in examples/body-validation. docs/CLOUDFLARE.md now notes that the dated workerd run happened before this change.

Security and compatibility notes

  • The only new client-controlled text in a response is an identifier-shaped extra property name, echoed back to the client that sent it (the 422 is no-store and nosniff). The earlier rule was that no client text appears at all; this is a deliberate relaxation, requested in [Bug]: planner and recipe search steer simple JSON endpoints to function code #587. The test that used a secret-shaped key now uses extra. It asserts that a non-identifier key such as <…> is not named, and that no values appear.
  • Configuration errors echo only key names, authored paths and file names (quoted and bounded) and schema-declared values, never YAML values.
  • urlcode test failure output now includes response header and body excerpts from the author's own project. The docs say to keep secrets out of test responses that end up in CI logs.
  • The sandbox: true isolation path is unchanged; only its error wording changed.

Validation

  • npm run verify: green locally (lint, typecheck, check and check:docs, build, 785 core tests, workspace verifies).
  • npm run test:package: green (packed install, starter and cookbook smoke). schemas/requests.schema.json is in the pack.
  • New test/authoring-errors.test.ts covers every row above. Existing tests were updated where message text changed.
  • Regenerated: llms-full.txt, the plugin skill copy, and starter AGENTS.md (via renderAgentsGuide). docs:reference has no change, because urlcode.schema.json is untouched.

Closes #583
Closes #584
Closes #581
Refs #587

Every row of the #581 table is addressed; bundle/transport errors belong to #579. MCP tool errors still return a generic Operation failed validation, which is tracked in #582; the structured code/route/file/line/pointer fields on ConfigError.details are available for that fix to surface. #587's planner and recipe parts are handled in a separate PR.

🤖 Generated with Claude Code

jimhoyd and others added 4 commits September 23, 2026 17:36
… request fixtures; JSON 422s

- Reject Express-style /users/:id route segments with the {id} + parameters fix (#583).
- Validate tests/requests.json against a new shipped schemas/requests.schema.json:
  unknown keys (json, expectJson, typos) are refused with the fixture number and a hint;
  malformed JSON reports line/column; a failing case prints method, path and expected vs
  actual per assertion (shortened around the first difference, captured values redacted);
  zero cases exit nonzero once the project has an active route, and warn on a bare
  scaffold (#584).
- Configuration and CLI errors: did-you-mean for unknown keys at route level including
  handler names, explicit multiple/no-handler errors, unescaped route paths, enum/const
  values listed, YAML line/column, file:line:column prefixes (includes too), named missing
  files/projects/imports, route-named compile errors, policy-denied bindings point at
  urlcode permissions and --policy, unknown/valueless CLI options named, target refusals
  list compatible targets. Error events carry code/route/file/line/column/pointer (#581).
- Routes with a JSON request.body.schema always answer 422 as JSON listing every issue and
  name identifier-shaped undeclared properties (#587).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	llms-full.txt
#	packages/core/src/readiness.ts
The fixture schema, structured error fields and expanded docs from
#581/#583/#584 push the package over the previous 2450 KiB unpacked
budget. Raised to 2550 KiB, which also covers the pre-existing
examples/cloudflare/dist leak (gitignored build output that still
ends up in npm pack because 'examples' is listed wholesale) tracked
separately as #608.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 24, 2026 01:13
# Conflicts:
#	llms-full.txt
#	packages/core/src/capabilities.ts
jimhoyd added a commit that referenced this pull request Sep 24, 2026
…growth

Same budget #607 raised (structured error fields, fixture schema, docs
growth from several now-merged PRs; see that PR's commit for the full
justification and the examples/cloudflare/dist packaging note, #608).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit c17deec into main Sep 24, 2026
61 checks passed
@jimhoyd
jimhoyd deleted the claude/authoring-strictness branch September 24, 2026 01:53
jimhoyd added a commit that referenced this pull request Sep 24, 2026
…uard, and update stale test expectations

- router.ts: the pinned-policy binding-denial messages (#602) now combine
  with #607's grantHint wording instead of dropping the pin-specific
  explanation; the pin case takes priority since it fully explains the
  denial on its own.
- config.ts: safeFile no longer names a reference that looks like a path
  traversal attempt (a '..' segment), fixing a regression #607 introduced
  and #602 exposed (issue #610) — MCP's validate tool now surfaces the
  CLI's real error text (#582), which would otherwise turn an escaping
  function/middleware source reference into a filesystem oracle. A plain
  in-project typo is still named, matching #607's own authoring-errors
  test.
- test/dev-diagnostics.test.ts, test/mcp.test.ts: two assertions predated
  #607's route-name and file:line:column prefixes and #581's friendlier
  multiple-handlers message; updated to match the now-current, improved
  text rather than reverting the improvement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant