Skip to content

fix(tests): keep __pycache__ out of a clean checkout - #899

Merged
thewrz merged 1 commit into
mainfrom
fix/issue-897
Sep 24, 2026
Merged

thewrz merged 1 commit into
mainfrom
fix/issue-897

Conversation

@thewrz

@thewrz thewrz commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

This was written agentically; verify its assertions:

Why

A green tests/run-tests.sh run left agentkit/hooks/lib/__pycache__/ behind, so agent-run.sh --cmd test reported the checkout dirty and finding-ledger.sh evidence refused to record the run.

What

.gitignore now excludes __pycache__/ and *.pyc. tests/run-tests.sh exports PYTHONDONTWRITEBYTECODE=1 as defense in depth. The actual write path was test-rewrite-runtime.sh's --prefix-fixture reinvocation, which launches python3 -I (implies -E, so it ignores PYTHONDONTWRITEBYTECODE) without -B; it now passes -B too. A new suite, tests/test-clean-tree-after-probe.sh, pins the fix: it fails on the unfixed fixture and passes after.

Testing

  • tests/run-tests.sh green
  • new test fails on origin/main, passes here
  • agent-run.sh --cmd test exits 0 with a clean tree, PYTHONDONTWRITEBYTECODE unset
  • CI green

🤖 Co-authored by Claude Fable 5.1 (plan) and Claude Sonnet 5 (implementation). Closes #897.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Python test runs now avoid creating bytecode cache files, helping keep the project directory clean.
    • Added a check to verify that running a runtime probe does not leave Python cache directories behind.

A green tests/run-tests.sh run left agentkit/hooks/lib/__pycache__/
behind because test-rewrite-runtime.sh's --prefix-fixture reinvocation
launches python3 with -I (which implies -E and so ignores
PYTHONDONTWRITEBYTECODE) but not -B, so it re-imports rewrite_runtime.py
without bytecode-write protection. .gitignore also didn't exclude
__pycache__/, so agent-run.sh --cmd test then reported the checkout
dirty and finding-ledger.sh evidence refused.

Ignore __pycache__/ and *.pyc, export PYTHONDONTWRITEBYTECODE=1 from
run-tests.sh as defense in depth, add -B to the reinvocation that was
the actual write path, and pin all of it with a new suite that fails
on the unfixed fixture and passes after.

Closes #897

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 4112a646-c57a-47e6-bbd4-1fab9828637c

📥 Commits

Reviewing files that changed from the base of the PR and between d4ba2f8 and 3a3949b.

📒 Files selected for processing (4)
  • .gitignore
  • tests/fixtures/test_rewrite_runtime.py
  • tests/run-tests.sh
  • tests/test-clean-tree-after-probe.sh

Included review availability: 9 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.


📝 Walkthrough

Walkthrough

The test runner and rewrite-runtime fixture now disable Python bytecode writes. A new shell test checks for __pycache__ directories before and after the fixture runs. .gitignore excludes Python cache directories and compiled files.

Changes

Python bytecode cleanliness

Layer / File(s) Summary
Disable and check Python cache writes
tests/run-tests.sh, tests/fixtures/test_rewrite_runtime.py, tests/test-clean-tree-after-probe.sh, .gitignore
The test runner sets PYTHONDONTWRITEBYTECODE=1, and the fixture uses Python’s -B flag. A new test checks for __pycache__ directories before and after fixture execution and verifies its exit status. .gitignore excludes __pycache__/ and *.pyc.

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3a394

No actionable merge risk remains; the new cleanliness test is included in the normal test run.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning PR #899 implements the main fixes for #897: .gitignore ignores __pycache__/ and *.pyc, tests/run-tests.sh exports PYTHONDONTWRITEBYTECODE=1, and the isolated fixture uses python3 -B. The a… Update tests/test-clean-tree-after-probe.sh to run the relevant probe coverage and assert an empty git status --porcelain after the run. Keep the focused __pycache__ assertion if it remains useful.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The reviewed changes are limited to Python bytecode exclusion, test-process bytecode prevention, the isolated fixture invocation, and regression coverage for issue #897. No unrelated change is establi…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing pycache files from leaving the test checkout dirty.
Full details: Linked Issues check

Explanation

PR #899 implements the main fixes for #897: .gitignore ignores __pycache__/ and *.pyc, tests/run-tests.sh exports PYTHONDONTWRITEBYTECODE=1, and the isolated fixture uses python3 -B. The added test runs the fixture and checks for __pycache__ under agentkit. It does not assert that git status --porcelain is empty after the probe, as required by #897, and it does not cover other checkout changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)


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

@thewrz

thewrz commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

This was written agentically; verify its assertions:

Adversarial review receipt

  • Reviewer: provider=openai; model=gpt-6-astra; effort=xhigh; mode=cross-provider (reason: n/a)
  • Launcher: adversarial-run.sh sha256=4d1fc623db1b387d5d6dc0792b56ea5fcc25bf1297a77b9aca4dab243902bd50; attempt=4ae5f6c6-c113-4200-a923-1f5c77c98d1e
  • Procedure: one-shot diff review; no contract-blind or two-pass attestation
  • Reviewer override: configured=gpt-6-astra-xhigh; operator-authorized=gpt-6-astra-xhigh
  • Counts: P1=0; P2=0; total=0
  • Reviewed head: 3a3949b
  • Diff payload: wrzonance/agent-kit:899:5fe49204b3157c9d4fac18a74f914c8f9c304286fe552acd08fcf19e373f36bb
  • Confirmed finding: none confirmed
  • Execution: performed; adjudication=recorded
  • Remediation: complete

🤖 Co-authored by Claude Fable 5.1 noreply@anthropic.com.

@thewrz

thewrz commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

This was written agentically; verify its assertions:

Review ledger

Machine-readable record of every review already performed on this PR.

{
  "version": 1,
  "pr": 899,
  "repo": "wrzonance/agent-kit",
  "reviews": [
    {
      "kind": "adversarial",
      "provider": "openai",
      "model": "gpt-6-astra",
      "effort": "xhigh",
      "mode": "cross-provider",
      "attemptId": "4ae5f6c6-c113-4200-a923-1f5c77c98d1e",
      "launcherSha256": "4d1fc623db1b387d5d6dc0792b56ea5fcc25bf1297a77b9aca4dab243902bd50",
      "procedure": "one-shot diff review; no contract-blind or two-pass attestation",
      "reviewerOverride": "configured=gpt-6-astra-xhigh; operator-authorized=gpt-6-astra-xhigh",
      "harness": "codex",
      "head_sha": "3a3949b80b17ff03815f0e39cb90551b17c61d75",
      "covered_heads": [
        "3a3949b80b17ff03815f0e39cb90551b17c61d75"
      ],
      "diff_payload": "wrzonance/agent-kit:899:5fe49204b3157c9d4fac18a74f914c8f9c304286fe552acd08fcf19e373f36bb",
      "findings": [],
      "counts": {
        "p1": 0,
        "p2": 0
      },
      "reviewed_at": "2026-09-24T04:57:28Z"
    }
  ]
}

🤖 Co-authored by Claude Fable 5.1 noreply@anthropic.com.

@thewrz

thewrz commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@thewrz
thewrz marked this pull request as ready for review September 24, 2026 05:11
@thewrz
thewrz merged commit f066e35 into main Sep 24, 2026
9 checks passed
@thewrz
thewrz deleted the fix/issue-897 branch September 24, 2026 05:11
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.

fix(tests): the probe suite writes __pycache__ into the shipped tree, so agent-run reports checkout-dirty and evidence helpers refuse

1 participant