Skip to content

Validate the Rulesets Response Before ruleset_id() Reads It (#1971) - #1988

Merged
ptr727 merged 1 commit into
developfrom
feature/auto-1971
Sep 28, 2026
Merged

ptr727 merged 1 commit into
developfrom
feature/auto-1971

Conversation

@ptr727

@ptr727 ptr727 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Summary

repo-config/configure.sh's ruleset_id() per_page guard fails open on
any non-array 2xx response from the rulesets API, not only the CR-mangled
case #1880/#1972 fixed, because the guard's own comparison failure inside
its $(...) subshell never reaches set -e (no inherit_errexit).

The defect

On a non-array response, jqr 'length' prints nothing, so the
[ "" -eq 100 ] guard fails silently rather than tripping, and the
following ids= extraction likewise falls through empty rather than
aborting. ruleset_id returns 0, which both call sites read as "not
found": the apply site would create a duplicate ruleset by name, and the
check site would misreport "not found" instead of aborting.

Fix

Validate $out is a JSON array (jq_has 'type == "array"' <<<"$out",
matching the entries guard's own pattern) before either the per_page
guard or the ids= extraction reads it, aborting with a "could not read
live ruleset state" message on failure.

Verification

  • New tests/test_configure_ruleset_id.py lifts ruleset_id()'s own
    lines and exercises it through a stubbed gh, invoked the way both real
    call sites invoke it (id="$(ruleset_id ...)"), which is what exposes
    the subshell-errexit defect.
  • Confirmed by reverting the fix: every non-array-response case then
    returns exit 0 with empty stdout (the "not found" misread), and the
    pre-existing per_page-cap, gh-failure, and duplicate-name cases stay
    passing throughout.
  • shellcheck and shfmt -d clean on repo-config/configure.sh.
  • python3 -m unittest discover -s tests (1777 tests), python3 scripts/repo_gate.py, and python3 spec/validate.py all pass.
  • A local-strict-review pass over the full diff found no blocking
    defects. It flagged one comment-wording inaccuracy (fixed) and one
    pre-existing gap in the ids= extraction for a malformed array
    element, filed separately as ruleset_id()'s ids= Extraction Still Misreads a Malformed Ruleset Array Element #1987 rather than expanding this fix's
    scope.

Closes on promotion: #1971

🤖 Generated with Claude Code

## Summary

`repo-config/configure.sh`'s `ruleset_id()` per_page guard fails open on
any non-array 2xx response from the rulesets API, not only the CR-mangled
case #1880/#1972 fixed, because the guard's own comparison failure inside
its `$(...)` subshell never reaches `set -e` (no `inherit_errexit`).

## The defect

On a non-array response, `jqr 'length'` prints nothing, so the
`[ "" -eq 100 ]` guard fails silently rather than tripping, and the
following `ids=` extraction likewise falls through empty rather than
aborting. `ruleset_id` returns 0, which both call sites read as "not
found": the apply site would create a duplicate ruleset by name, and the
check site would misreport "not found" instead of aborting.

## Fix

Validate `$out` is a JSON array (`jq_has 'type == "array"' <<<"$out"`,
matching the `entries` guard's own pattern) before either the per_page
guard or the `ids=` extraction reads it, aborting with a "could not read
live ruleset state" message on failure.

## Verification

- New `tests/test_configure_ruleset_id.py` lifts `ruleset_id()`'s own
  lines and exercises it through a stubbed `gh`, invoked the way both real
  call sites invoke it (`id="$(ruleset_id ...)"`), which is what exposes
  the subshell-errexit defect.
- Confirmed by reverting the fix: every non-array-response case then
  returns exit 0 with empty stdout (the "not found" misread), and the
  pre-existing per_page-cap, gh-failure, and duplicate-name cases stay
  passing throughout.
- `shellcheck` and `shfmt -d` clean on `repo-config/configure.sh`.
- `python3 -m unittest discover -s tests` (1777 tests), `python3
  scripts/repo_gate.py`, and `python3 spec/validate.py` all pass.

Closes on promotion: #1971

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 28, 2026 07:27
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Sep 28, 2026
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: c5588ac0-3ad4-4dec-a7d5-9c543b7d0c7b


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@9573a06). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #1988   +/-   ##
==========================================
  Coverage           ?   55.42%           
==========================================
  Files              ?       16           
  Lines              ?     7249           
  Branches           ?        0           
==========================================
  Hits               ?     4018           
  Misses             ?     3231           
  Partials           ?        0           
Flag Coverage Δ
python-3.13 55.42% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The change correctly blocks the confirmed fail-open path by type-checking the rulesets response before parsing, and the added tests cover both the new abort behavior and the preserved existing guard cases.

Review effort: Lite
Findings: None

What changed in this PR

This pull request hardens repo-config/configure.sh’s ruleset_id() lookup against malformed-but-2xx GitHub API responses by validating the response shape before parsing, and adds a targeted regression test that exercises the function via the same command-substitution call pattern used in production.

Changes:

  • Add a jq_has 'type == "array"' guard in ruleset_id() to abort on non-array responses before the length check and id extraction run.
  • Add tests/test_configure_ruleset_id.py to run lifted ruleset_id() lines with a stubbed gh, covering the non-array 2xx failure mode and preserving existing guard behaviors.
File Description
tests/​test_configure_ruleset_id.py Adds an offline unittest harness that lifts ruleset_id() and stubs gh to validate failure propagation under command substitution.
repo-config/​configure.sh Validates the rulesets API response is a JSON array before evaluating length or extracting ids, preventing false “not found” reads.

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

@ptr727
ptr727 merged commit 8c802f3 into develop Sep 28, 2026
11 checks passed
ptr727 added a commit that referenced this pull request Sep 28, 2026
… and Setup Tooling (#2000)

## Summary

Promotes develop to main, carrying the 16 pull requests merged to
develop since #1943.

- **Wait-loop guard (requirement 7):**
[#1999](#1999) credits a
comparison bound only inside a `[`, `[[`, or `test` invocation, and
[#1996](#1996) reconciles
the requirement's README count and diagram with its hook.
- **Registry:**
[#1994](#1994) and
[#1976](#1976) record
Vantage-Config's line endings and description.
- **Scripts and tooling:**
- [#1988](#1988) and
[#1972](#1972) harden
`ruleset_id()`.
- [#1974](#1974) and
[#1949](#1949) fix
`pr_review.py` `reply --match` and `wait`.
- [#1969](#1969),
[#1964](#1964),
[#1954](#1954) and
[#1951](#1951) fix
host-setup tool shadowing, shims, hook ownership and dpkg ownership
checks.
- **Gates and audit:**
- [#1980](#1980) triages a
path collision.
- [#1967](#1967) and
[#1962](#1962) tighten
sha-pin and version-literal checks.
- [#1956](#1956) keeps a
folded `if:` visible to the interface audit.

Closes #1636
Closes #1639
Closes #1948
Closes #1971
Closes #1718
Closes #1934
Closes #1877
Closes #1880
Closes #1865
Closes #1889
Closes #1966
Closes #1906
Closes #1935
Closes #1901
Closes #1905
Closes #1866
Closes #1897

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@ptr727
ptr727 deleted the feature/auto-1971 branch November 1, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants