Skip to content

fix: reject malformed HTTP error constants - #14

Merged
shivros merged 1 commit into
mainfrom
runner/COD-508-reject-malformed-http-error-constants
Sep 19, 2026
Merged

shivros merged 1 commit into
mainfrom
runner/COD-508-reject-malformed-http-error-constants

Conversation

@shivros

@shivros shivros commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes COD-508 by making typed HTTP-error const declarations strict at the real YAML loader boundary:

  • preserves an omitted const as dynamic None;
  • rejects explicit null, ~, empty YAML values, booleans, numbers, sequences, and mappings before generation;
  • retains valid required string constants and the existing public Option<String> model;
  • adds named source diagnostics for malformed declarations and source-qualified validation errors for optional string constants.

No generated fixture or public surface changed for valid definitions.

Evidence

Baseline before the fix, through hydra_core::load_api_definition, incorrectly accepted const: null as constant=None.

The new table-driven loader test derives temporary definitions from the committed HTTP-error fixture. It covers required and optional fields, omitted/dynamic behavior, escaped/empty/quoted scalar strings, all malformed YAML scalar/collection forms, named source diagnostics, and the existing required-only constant rule.

A real CLI boundary check now rejects an optional string constant before write with:

Error: validate API definition from api/operations.yaml
Caused by:
    operation status HTTP error response unavailable field error declares const but is optional; constants require required: true

Verification

cargo build --all-targets
cargo test --all-targets                 # 51 codegen + 14 Notes-surface + 6 security-scan tests
cargo test -p hydra-codegen --test codegen
cargo clippy --all-targets -- -D warnings
cargo fmt --all -- --check
(cd examples/notes && cargo run -p hydra-codegen --bin hydra-codegen -- check)
(cd examples/security-scan && cargo run -p hydra-codegen --bin hydra-codegen -- check)
git diff --check

All commands passed. The existing HTTP-error fixture's two temporary generated writes remained byte-identical, and both committed example artifact checks reported current output.

Scope

This is a bounded loader-validation correction only: no release, tag, dependency, consumer adoption, configuration, generated artifact, CLI/MCP behavior, SSE behavior, or runtime dispatch change.

@shivros

shivros commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated Review Panel

Reviewer A — GPT-5.6 Terra

APPROVE — no correctness blockers remain.

  • Confirmed the raw-YAML pass rejects every supplied non-string const before typed generation, while omission still yields dynamic None.
  • Confirmed valid escaped, empty, quoted numeric, and quoted boolean strings remain fixed required constants rather than constructor inputs.
  • Confirmed the prior review finding is resolved: optional string constants now fail through the existing required-only rule with the API-definition source path. The regression asserts source, operation, response, and field diagnostics.
  • Confirmed full local gates, deterministic fixture coverage, and both example checks are green.

Reviewer B — Gemini 3 Flash (OpenRouter)

APPROVE (minor non-blocking notes only).

  • Confirmed strict null/tilde/boolean/numeric/collection rejection, named diagnostics, and unchanged valid-constant behavior.
  • Noted the intentional two-pass loader parse used to retain raw-YAML diagnostic context while keeping direct HttpErrorField deserialization strict. This is bounded definition-load work, not a runtime-path regression.
  • Noted only optional consistency/performance refinements; no correctness, goal-alignment, or convention violation was found.

Resolution and evidence

The first Reviewer A pass identified one real issue: optional string constants lacked source-path context. It was fixed before this final dual-model confirmation by wrapping semantic definition validation in the loader's source context and adding a regression assertion. The real hydra-codegen write boundary now emits:

Error: validate API definition from api/operations.yaml
Caused by:
    operation status HTTP error response unavailable field error declares const but is optional; constants require required: true

Final verified gates:

cargo build --all-targets
cargo test --all-targets
cargo test -p hydra-codegen --test codegen
cargo clippy --all-targets -- -D warnings
cargo fmt --all -- --check
(cd examples/notes && cargo run -p hydra-codegen --bin hydra-codegen -- check)
(cd examples/security-scan && cargo run -p hydra-codegen --bin hydra-codegen -- check)
git diff --check

All passed; the full suite contains 51 codegen tests, 14 Notes-surface tests, and 6 security-scan tests. The committed HTTP-error fixture's existing two-write byte-determinism test also remained green.

@shivros
shivros marked this pull request as ready for review September 19, 2026 16:50
@shivros

shivros commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Auto-Merge Gate

Confidence: 0.93

The implementation directly satisfies COD-508: omitted const remains dynamic; every explicitly supplied non-string YAML value is rejected at load_api_definition; valid required string constants retain their existing public Option<String> semantics. The regression matrix exercises the real loader for required and optional fields and asserts named, source-qualified diagnostics.

Independent checks observed: CI Test and Creed context drift both succeeded. The PR review panel’s final disposition found no correctness blocker, and the linked Linear issue has no manual-review or do-not-auto-merge marker.

Scope limits reviewed: two files only; no release, deployment, credential, consumer, generated-artifact, or runtime dispatch change.

@shivros
shivros merged commit b36ac5f into main Sep 19, 2026
2 checks passed
@shivros
shivros deleted the runner/COD-508-reject-malformed-http-error-constants branch September 19, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant