Skip to content

Keep the secrets_sync Tests Meaningful Under a Root Test Runner - #4281

Merged
ptr727 merged 3 commits into
developfrom
fix/4262-secrets-sync-tests-root
Nov 19, 2026
Merged

ptr727 merged 3 commits into
developfrom
fix/4262-secrets-sync-tests-root

Conversation

@ptr727

@ptr727 ptr727 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Summary

Refs #4262.

scripts/secrets_sync.py refuses root before any call. So under a root test runner almost every case in tests/test_secrets_sync.py failed at that refusal: 170 failures and 1 error in a root container.

  • Under real root, the base case patches refuse_root to a no-op rather than faking the euid. The euid stays 0, consistent with the owner of the files the runner creates, so the ownership check reads them as owned.
  • test_root_is_refused_before_any_call restores the real function and runs as root.
  • The interrupt cases' subprocess driver stubs refuse_root as it already stubs ask.
  • A shared RUNNING_AS_ROOT in tests/host_capability.py skips the one case root genuinely changes: root lists a mode-000 directory.

Verification

In python:3.13-slim, with a copy of the tree:

  • As uid 0: 163 tests OK, 1 skipped, with both interrupt cases running. On develop: 170 failures, 1 error.
  • As uid 1234: OK.
  • The root-refusal case fails as root when the real function is not restored.

On this host as a normal user: OK. No stub process survived.

Local strict review

Three passes. Round 1 replaced a faked euid, which caused 11 avoidable skips, with the refuse_root stub and a shared predicate. Round 2 moved the interrupt cases onto the same stub. Round 3 raised nothing.

Dropped findings

  • Inline euid-0 predicates in tests/test_restore_secrets.py, test_secrets_sh.py, test_install_agents.py, test_skills_install.py, test_bootstrap.py, and test_build_dist.py, consolidation on text this change did not touch. RUNNING_AS_ROOT is the primitive they can move onto.

🤖 Generated with Claude Code

ptr727 and others added 3 commits November 19, 2026 07:22
`secrets_sync.py` refuses root before any call, so under a root runner nearly every case failed at that refusal: 170 failures and 1 error in a root container. Under real root the base case now reads a non-root euid, and the root-refusal case still patches its own 0 and runs as root.

Real root also changes what no patch can model. Every file the runner writes is owned by uid 0, which the ownership check then reads as foreign, and root lists a mode-000 directory. The 12 cases that depend on either, and the interrupt cases that run the real script, skip under real root.

The patch applies only under real root. A fixed id would make every file a non-root runner with another uid creates read as foreign-owned. Verified as uid 0 (OK, 14 skipped), as uid 1234 (OK), and on this host (OK).

Closes #4262

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The local review found that faking a non-root euid caused 11 of the 12 skips. Files a root runner creates are owned by 0, which the faked euid read as foreign. Root itself caused none of them. Patching `refuse_root` leaves the euid at 0, consistent with the files' owner, so those 11 cases now run as root. The root-refusal case restores the real function and patches its own 0.

Only two kinds of case still skip under real root: the mode-000 listing, and the interrupt cases that run the real script. They read a shared `RUNNING_AS_ROOT` from `tests/host_capability.py` rather than a predicate of this file's own.

Verified as uid 0 (OK, 3 skipped), as uid 1234 (OK), and on this host (OK). The root-refusal case fails as root when the real function is not restored.

Refs #4262

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The second local review found the interrupt cases skipped under root for the same class the base case now patches. The subprocess driver already stubs `stdin_is_tty` and `ask`, and it now stubs `refuse_root` too, so both signal cases run as root. Only the mode-000 listing case still skips there.

Verified as uid 0 (OK, 1 skipped), as uid 1234 (OK), and on this host (OK). No stub process survived.

Refs #4262

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings November 19, 2026 15:33
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@ptr727

ptr727 commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 8baaa5ca21cc72abdb66186e956c9d0a38b57709, the content this pull request carries at that commit against develop, and it recorded 0 findings.

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.

🟢 Approval recommended

No active review issues remain, and the test updates account for root-specific behavior while retaining coverage of the production root refusal.

No open issues 🎉

What changed in this PR

This pull request keeps secrets_sync tests meaningful when the suite runs as root while preserving coverage for the production root refusal.

Changes:

  • Adds a shared RUNNING_AS_ROOT capability predicate.
  • Stubs refuse_root for tests exercising non-root behavior and restores the real guard for the dedicated root-refusal test.
  • Updates interrupt subprocess tests and skips the permission case where root behavior differs.
File Description
tests/​test_secrets_sync.py Makes regular, interrupt, root-refusal, and permission tests behave correctly under root.
tests/​host_capability.py Adds the shared root-detection capability used by the tests.

Review effort: Lite

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.21%. Comparing base (5d07823) to head (8baaa5c).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4281   +/-   ##
========================================
  Coverage    79.21%   79.21%           
========================================
  Files           42       42           
  Lines        15502    15502           
========================================
  Hits         12280    12280           
  Misses        3222     3222           
Flag Coverage Δ
python-3.13 79.21% <ø> (ø)

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.

@ptr727

ptr727 commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727
ptr727 merged commit d37b4e2 into develop Nov 19, 2026
14 checks passed
@ptr727
ptr727 deleted the fix/4262-secrets-sync-tests-root branch November 19, 2026 15:51
ptr727 added a commit that referenced this pull request Nov 19, 2026
…n secrets_sync Tests as Root (#4282)

## Summary

Promotes `develop` to `main`. It carries these changes:

- [#4280](#4280) makes the
carried `hub_fetch_run.py` pass every carrier's strict checker.
- **The fix.** The `urlopen` body is annotated as `bytes`, which clears
`mypy --strict`'s `no-any-return`. Every carrier holds this file at its
root and may not edit it.
- **The gate.** The hub's validate action now runs `mypy --strict` with
no config, and pyright, on the snippet, once each as Linux, macOS, and
Windows code. A `# pyright: strict` line keeps pyright strict wherever
the file is checked.
- [#4281](#4281) keeps
`tests/test_secrets_sync.py` meaningful under a root runner. Root used
to give 170 failures and 1 error. Under root the base case now stubs the
script's root refusal, the refusal case restores it, and the interrupt
driver stubs it too. Only the mode-000 listing case skips, through a
shared `RUNNING_AS_ROOT` in `tests/host_capability.py`.

Closes #4266
Closes #4262

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Tests**
* Test coverage now accounts for root-level environments, including
cases where root access changes how filesystem permissions behave.
* Root-refusal behavior remains explicitly covered, and interruption
scenarios are less affected by root restrictions.
* **Chores**
* Automated validation now checks Python types across Linux, macOS, and
Windows.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
ptr727 added a commit that referenced this pull request Nov 20, 2026
## Summary

`pr_review.py merge` could land a pull request in the gap after a hosted
reviewer was asked and before its check registered. Until the check
registers the rollup holds nothing of the review, so a head whose other
checks have passed reads ready. This adds the registration grace the
maintainer chose on #3814 and refined on #3806: option 1, anchored on
the head's push, its last check settling, and its newest review ask,
with G = 90s.

- **Settle stamp.** `check_nodes` now records when each check settled.
For a CheckRun that is `completedAt`, which the held query now reads.
For a StatusContext it is `createdAt` once the context is no longer
pending.
- **The grace.** `pr_review_hold.hosted_grace` anchors on the latest of
three things: the head's push (its earliest suite or check), its last
non-hosted check settling, and its newest trusted review ask
(`@coderabbitai review`, `@coderabbitai full review`, or `/review` from
an owner, member, or collaborator). It runs `HOSTED_GRACE` = 90 seconds
from that anchor.
- A hosted reviewer's own check, Copilot's included, is left out of the
settling, so a finished review never restarts the window.
- The grace ends early once a CodeRabbit or Qodo check that did not
conclude `SKIPPED` and that began at or after the newest ask is on the
head. From then on, that check's existing hold decides. A check older
than the ask answered an earlier request, so a re-ask still waits for
its own check. A `SKIPPED` check is CodeRabbit's "automatic reviews are
disabled" placeholder, which every head here carries about 10s after the
push.
- **wait.** On an attested head, the held poll judges the grace only
after `wait` sends its after-checks asks. Where it sent one, it reads
the pull request again, because the ask moves the anchor. The
`CHECKS_PENDING` line adds `(registration grace until: <time>)`. A
`wait` that returns `0` with no hosted check on the head prints a note.
The note says either that the grace released the merge without a hosted
check, or, on a head no local pass covers, that the grace still holds
and `merge` refuses until it ends.
- **merge.** The fresh read's `unmet` refuses an open grace as
`CHECKS_PENDING`, on a line of its own that names when the grace ends.
This is separate from the "a hosted review of the head is running" line.
- **Layout.** `pr_review.py` was at 2198 of its 2200-line ceiling,
`pr_review_checks.py` at 449 of 450, and `pr_review_side.py` at 347 of
350. So the grace, its note, and the `CHECKS_PENDING` line builder (with
`_unmet_note`) live in a new pure reader, `scripts/pr_review_hold.py`,
which has a 200-line ceiling.
- The pure helpers `side_command`, `side_asks`, `head_arrived`, and
`hosted_check` moved there from `pr_review_side.py`, which imports them
back.
- The new module is listed among the readers in the import contract
test.
  - No ceiling was raised.
- **Accepted trade-off.** The grace is judged apart from
`held_checks_open`'s stuck-check read. So on an attested head, a
`BLOCKED` merge with a required check stuck reports `30` for at most the
grace's 90 seconds before `44`. `scripts/README.md` says so in the
`wait` paragraph and on the `44` exit row.

## Measurement

Read-only reads of the 150 most recently updated merged pull requests in
this repository (#4038 to #4300):

- CodeRabbit posts a `SKIPPED` "Review skipped: automatic reviews are
disabled" check on every head, about 10s after the push (p90 30s). Its
check for an actual review appears only after an ask. 89 heads carried
such a run: 26 finished, 50 rate limited (an instant neutral), and 13
cancelled. Qodo posts no check in this repository.
- **Ask to registration:** 10 to 33s across all 89 asked runs, mostly 12
to 17s.
- **Later of push and last non-hosted check settling, to registration:**
3 to 146s on 86 heads (p50 91s, p90 133s). The other 3 were 278s, 1566s,
and 1963s, where a later `wait` sent the ask minutes after the checks
settled. That is why the anchor includes the ask.
- **The failure, measured:** 7 merges landed 1 to 6s before CodeRabbit's
run registered (#4280, #4281, #4244, #4130, #4129, #4105, #4109). Each
run was then cancelled with "Pull request is closed", and each merge
came 10 to 20s after the ask.
- **Chosen value:** `HOSTED_GRACE` = 90s, about 2.7 times the largest
measured delay from ask to registration. On a head nobody asks a hosted
reviewer to review, the fixed cost is 90s after the checks settle.

## Verification

- `python -m unittest discover -s tests`: see the CI run. Locally,
`tests/test_pr_*.py` (979 tests) and `tests/test_backlog*.py` pass, the
size ceiling test included.
- New cases in `TestRegistrationGrace` cover:
- the anchor's three sources, with an untrusted ask and a hosted
conclusion moving nothing;
  - a `SKIPPED` check versus any other hosted conclusion;
  - a StatusContext's settle stamp;
  - the open and released notes;
  - the `CHECKS_PENDING` line;
  - `merge`'s separate refusal line.
- `TestCli` cases cover the hold and its release on a held head, and the
extra read after a sent ask, which happens only when an ask was sent.
Three existing `wait` fixtures now date their head past the grace.
- ruff format, ruff check, mypy, and the prose gate are clean. The full
`unittest discover -s tests` run passed locally on the first commit
(4559 tests).

## Local review

There were three recorded `local-strict-review` passes. The first raised
seven findings and the second raised two, and both rounds' fixes are in
this branch. The third raised none. The declined findings are these:

- **Grace ignores the review policy** (`introduced`, declined). On #3814
the maintainer chose a grace that reads no reviewer configuration, with
its fixed, bounded delay accepted. A policy can also understate a
reviewer that is installed, and reading it would then drop the hold.
- **`ASK_BODIES` repeats `pr_review_policy.COMMANDS`** (`introduced`,
declined). `pr_review_policy` imports `subprocess`, which the reader
contract test forbids a pure reader to load.
- **`stamp()` repeats the formatter in `secrets_sync.py`**
(`introduced`, declined). The same reader contract rules that import
out.
- **Skill drift** (`introduced`, reported to the backlog-burndown
orchestrator, outside this pull request's files). Two skills still
describe the old refusal:
- `.agents/skills/pr-review-conduct/SKILL.md` "Merge Gate" item 2 names
only a running hosted check as a `CHECKS_PENDING` refusal.
- `.agents/skills/drive-pr/SKILL.md` step 4 `next=redrive` says a
`CHECKS_PENDING` refusal clears by `gh pr checks --watch`, which returns
at once for a grace refusal.

  The refusal line itself now names the time to run `merge` again.

Closes on promotion: #3806

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

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

Development

Successfully merging this pull request may close these issues.

2 participants