Skip to content

Harden the derived MAJOR_RELEASE: manifest-shape guard and bounded policy-text search (follow-up to #679) - #681

Merged
brettheap merged 1 commit into
mainfrom
fix/credential-validator-major-release-hardening
Sep 5, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/credential-validator-major-release-hardening

Conversation

@brettheap

Copy link
Copy Markdown
Contributor

Lane: openxfactory-1 (openXfactory-1)

Refs #634

Follow-up to #679

#679 (merge commit 1be0cc21) landed the core fix for #634 — MAJOR_RELEASE derived from contracts/manifest.yaml instead of pinned, plus the policy cross-check test. While it was in flight, Copilot's automatic second-round review (triggered by that PR's second commit) posted three robustness findings. Two real ones were fixed and pushed as f9a854df on the original branch, but the admin merge of #679 landed on head a2459bad about three minutes before f9a854df reached the remote — a race, not a rejection — so those two fixes never made it into main. This PR is that same commit, cherry-picked onto origin/main, so they land now.

What this adds

  • _major_release() in scripts/validate-credential-contracts.py now checks that contracts/manifest.yaml parses to a mapping before calling .get() on it, raising a clear message instead of an unhelpful AttributeError if the manifest is malformed or empty.
  • The policy-parsing test helpers in tests/credential_contracts/test_major_release_matches_policy.py now bound their search to the entry each targets: _bounded_entry() stops at the next top-level bullet or section heading instead of scanning to end-of-document, and _consumer_block_target() asserts its pattern matches exactly once. Both guards exist so a future policy entry that happens to share phrasing with an existing one cannot be silently matched by mistake — the exact class of drift this test file exists to catch.

Declined finding (not carried into this PR): spec_from_file_location()'s .loader could in principle be None in the test helper. Declined because it matches the identical, unmodified pattern already used by tests/credential_contracts/test_consumer_block_phasing.py and test_requirement_ref_resolution.py; changing it only here would diverge from established convention for a test-only import helper whose path is a hardcoded literal.

No behavior change: refuse/warn logic and the messages' derived release name are unchanged from what #679 shipped — this only hardens the derivation and the guard-test against malformed input and future false matches. No OpenSpec change.

Gates

  • pytest tests/ -q -k credential — 281 passed.
  • python3 scripts/validate-credential-contracts.py . (packaged self-test) — self-test: 8 positive + 19 negative + 13 warning example(s) confirmed, 11 deprecation code(s) probed.

Codex not re-requested (already recorded ABSENT on #679 for the same usage limit). Real Copilot defects only, per the disposition above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv

Two real findings taken from the second Copilot review round:

- _major_release() now checks contracts/manifest.yaml parses to a
  mapping before calling .get() on it, raising a clear message
  instead of an unhelpful AttributeError on a malformed manifest.
- The policy-parsing test helpers now bound their search to the
  entry each targets: _bounded_entry() stops at the next top-level
  bullet or section heading instead of scanning to end-of-document,
  and _consumer_block_target() asserts its pattern matches exactly
  once. Both guards exist so a future policy entry that happens to
  share phrasing with an existing one cannot be silently matched by
  mistake — the exact class of drift this test file exists to catch.

Declined finding (spec_from_file_location()'s loader may be None):
matches the identical, unmodified pattern already used by
tests/credential_contracts/test_consumer_block_phasing.py and
test_requirement_ref_resolution.py; changing it only in the new file
would diverge from established convention for a test-only import
helper whose path is a hardcoded literal.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv
Lane: openxfactory-1
Copilot AI lite review requested due to automatic review settings September 5, 2026 14:51

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @brettheap! 👋

Your private repo does not have access to Sourcery.

Please upgrade to continue using Sourcery ✨

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are narrowly scoped, improve robustness without altering intended behavior, and the new guards are consistent with existing error handling and test intent.

Pull request overview

This PR is a follow-up hardening pass on the MAJOR_RELEASE derivation and its policy cross-check tests (originally introduced in #679 to fix #634). It improves failure modes when contracts/manifest.yaml is malformed and tightens the policy-text parsing helpers to avoid accidental matches as the policy document evolves.

Changes:

  • Add a manifest-shape guard in _major_release() to fail with a clear SystemExit message if contracts/manifest.yaml doesn’t parse as a mapping.
  • Strengthen policy parsing in test_major_release_matches_policy.py by bounding an entry scan to a single bullet/section and requiring the consumer-block pattern to match exactly once.
File summaries
File Description
scripts/validate-credential-contracts.py Adds a defensive manifest type-check to produce a clear error instead of an AttributeError when deriving MAJOR_RELEASE.
tests/credential_contracts/test_major_release_matches_policy.py Makes policy parsing more robust against future document edits by bounding entry text and asserting single-match patterns.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-1 (openXfactory-1; session 5e783e4d)

Provenance for the admin merge of #681 (follow-up to #679: the two Copilot round-2 hardening fixes that reached the branch three minutes after #679's merge — the race was the coordinator's, landing on a green monitor before the author had frozen). Word: Brett Heap, 2026-09-05 — "do both as a batch on one word". Head 496851ed (cherry-pick of f9a854d), FROZEN by the author; nine checks SUCCESS; Copilot approval recommended, 0 comments; Codex not re-requested. Self-authored PR → admin merge (standing pattern B2).

🤖 Generated with Claude Code

https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv

@brettheap
brettheap merged commit d0a5f39 into main Sep 5, 2026
10 checks passed
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.

2 participants