Skip to content

Bring the RegressionTests Python Tools Under the Interrupt Rule - #1300

Merged
ptr727 merged 6 commits into
developfrom
interrupt-rule-1293
Nov 26, 2026
Merged

ptr727 merged 6 commits into
developfrom
interrupt-rule-1293

Conversation

@ptr727

@ptr727 ptr727 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

Brings the RegressionTests Python tools under the CODESTYLE.md "Interrupts" and "Interrupts in Python" rules, which #1294 refreshed from the hub, and folds in the review items #1293 lists. #1293 stays open until the promotion carries this to main.

  • One helper: RegressionTests/synthetic/interrupts.py implements the rule once. That covers the single SIGINT/SIGTERM handler, one KeyboardInterrupt catch that names the signal and re-raises it, and a bounded child stop. It adds run_child for every subprocess, so a docker CLI receives SIGTERM, which it proxies to its container, rather than subprocess.run's SIGKILL. It also provides an atomic write beside the target. It lives under synthetic/ because the integration run mounts only that directory, and the top-level tools add it to sys.path.
  • Tools: audit_physical, catalog_corpus, check_results, locate_issue and reduce_corpus write their state files atomically and run every child through run_child. synthesize has each child write a .partial sibling, then replaces the target with it. hevc_nal.run_injector moves off its own SIGTERM-only, exit 143/130 shape.
  • Tests: mid-run signal tests cover locate_issue, reduce_corpus and synthesize. Each asserts death by the signal, one interrupt line with no traceback, the stub child stopped by SIGTERM, and nothing left behind. SyntheticDirectoryTests runs the synthetic scripts from a copy holding only synthetic/, as the integration container does.
  • Review items from Bring the RegressionTests Python Tools Under the Interrupt Rule #1293: the harness tests move to test_regression_harness.py and skip unless on Linux. They gain the wrong-mountpoint and non-clone-origin refusal cases, and Docs/ClosedCaptions.md states the TS file as the consequence it is.

Not Covered

  • audit_physical, catalog_corpus, check_results and the injectors hold only a momentary temporary file, so the rule owes them no mid-run signal test.
  • The shell scripts are untouched here. Exit status 64 for a refused argument, and the shell side of the re-raise rule, come in a later pull request.

Verification

  • ruff 0.17.6 format and check pass, and mypy passes.
  • The unittest suite runs 126 tests, OK, across three runs, with no stub left behind.
  • Local strict review: three frontier passes. The first found seven issues: the integration import break, two comment-case lines, an untested partial cleanup, leaking subtests, a fixed file mode, and a path filter that the move made moot. The second found a README omission. All are fixed, and the third found nothing.

🤖 Generated with Claude Code

ptr727 and others added 3 commits November 26, 2026 07:19
A shared interrupts.py implements CODESTYLE.md "Interrupts in Python" once:
one SIGINT/SIGTERM handler, one KeyboardInterrupt catch that names the
signal and re-raises it, a bounded child stop, run_child for every
subprocess so a docker CLI gets SIGTERM it proxies to its container, and
an atomic write beside the target. Every tool's state file and the
synthesizer's outputs go through a temporary sibling and os.replace.

Mid-run signal tests cover locate_issue, reduce_corpus and synthesize.
The harness tests move to test_regression_harness.py, skip off Linux, and
gain the wrong-mountpoint and non-clone-origin refusal cases.
Docs/ClosedCaptions.md states the TS file as the consequence it is.

Refs #1293.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
integration-test.sh mounts only RegressionTests/synthetic, so the helper
lives there and the top-level tools add that directory to sys.path. A
new test runs the synthetic scripts from a copy holding only synthetic/.
The partial-file test now covers a child that writes the partial itself,
each signal subtest cleans up its own process group, and a new target
takes the umask-masked mode write_text gave it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Nov 26, 2026
Copilot AI lite review requested due to automatic review settings November 26, 2026 15:32
@ptr727

ptr727 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

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

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Make RegressionTests Python tools interrupt-safe

🐞 Bug fix ✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Centralize signal handling and child shutdown so interrupted tools stop cleanly and die by signal.
• Write state and synthetic outputs through temporary siblings to avoid incomplete files.
• Add signal and container-layout tests; expand harness safety checks and clarify documentation.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: RegressionTests corpus analysis and validation integration.
  • The changed callers all parse, reduce, validate, locate, or audit the same regression corpus and publish artifacts consumed by subsequent RegressionTests steps; subprocess cleanup and artifact replacement are supporting hops in that bounded integration.
  • Synthetic builders and injectors create the media fixtures consumed by the same RegressionTests corpus-validation workflow; they are a separate end-to-end operation within that bounded integration, not an independent deployment or product subsystem.
Sources

RegressionTests/audit_physical.py[95-97]

    atomic_write_text(
        reduced / "catalog.json", json.dumps(collection, indent=2, ensure_ascii=False)
    )
Behavioral complexity 🔴 High 🧩 Coordinated invariants, Concurrent ordering

  • Before, each tool called subprocess.run or wrote final files directly, while entry-point interruption and cleanup were implemented independently or not at all.
  • After, shared wrappers coordinate signal receipt, child termination, temporary-file cleanup, and final replacement.
  • The new correctness conditions are that the first signal remains authoritative, children are stopped before exit, temporary artifacts are removed on every failure path, and readers see either the old or new complete artifact rather than a partial write.
Potential damage 🟡 Medium 🩹 Recoverable

  • If the changed lifecycle or publication behavior regresses, a run may leave a child process active, fail to complete, or leave stale/partial catalog, rules, or expected-result artifacts.
  • The affected corpus-validation operation can be rerun and the generated artifacts regenerated; no PlexCleaner media state or external customer data is touched.
  • Recovery requires stopping any surviving child and rerunning the affected tool; reverting code stops new failures but does not automatically remove stale artifacts or terminate already-running processes.
Sources

RegressionTests/audit_physical.py[95-97]

    atomic_write_text(
        reduced / "catalog.json", json.dumps(collection, indent=2, ensure_ascii=False)
    )
Assessed commit a14c1bb
Diagram

graph TD
  CLI["Corpus tools"] --> Helper["Interrupt helpers"] --> Child["External commands"]
  Helper --> State["Atomic state"]
  Synth["Synthesizer"] --> Helper
  Synth --> Partial["Partial fixtures"] --> Output["Final fixtures"]
Loading
High-Level Assessment

Keep the shared helper under synthetic/: it avoids duplicating signal and cleanup policy while remaining importable when the integration container mounts only that directory. Continuing with individual handlers or direct subprocess.run calls would make the interrupt contract harder to maintain.

Files changed (15) +686 / -265

Enhancement (4) +148 / -8
audit_physical.pyWrite audit catalogs atomically and handle interrupts +9/-2

Write audit catalogs atomically and handle interrupts

• Uses the shared entry-point handler and replaces direct catalog writes with atomic writes.

RegressionTests/audit_physical.py

catalog_corpus.pyProtect catalog output from interrupted writes +7/-2

Protect catalog output from interrupted writes

• Writes generated catalogs atomically and runs the CLI through the shared interrupt entry point.

RegressionTests/catalog_corpus.py

check_results.pyAtomically write expected results +6/-4

Atomically write expected results

• Makes --write replace the expected-results file atomically and adopts shared interrupt handling while preserving the main function's exit status.

RegressionTests/check_results.py

interrupts.pyAdd shared signal, child, and atomic-write helpers +126/-0

Add shared signal, child, and atomic-write helpers

• Introduces a single SIGINT/SIGTERM path that reports the first signal and re-raises it after cleanup. Adds bounded SIGTERM-then-kill child shutdown and temporary-sibling writes that preserve file modes.

RegressionTests/synthetic/interrupts.py

Bug fix (5) +76 / -62
corpus_common.pyStop shared media-tool children on interruption +9/-7

Stop shared media-tool children on interruption

• Routes mkvmerge, mkvpropedit, and clip-cutting subprocesses through the shared child runner.

RegressionTests/corpus_common.py

locate_issue.pyClean up decode children and protect rules writes +19/-12

Clean up decode children and protect rules writes

• Uses signal-aware subprocess execution, stops the streaming decode child in a finally block, and writes located rules atomically. Its CLI now reports and re-raises interrupts through the shared entry point.

RegressionTests/locate_issue.py

reduce_corpus.pyMake corpus reduction interrupt-safe +14/-15

Make corpus reduction interrupt-safe

• Runs media tools and Docker through the shared child runner so they receive SIGTERM during cleanup. Replaces direct catalog writes with atomic writes and adopts the shared entry point.

RegressionTests/reduce_corpus.py

hevc_nal.pyUnify injector interrupt and output behavior +18/-23

Unify injector interrupt and output behavior

• Replaces the injector's SIGTERM-specific handler and numeric exits with shared signal re-raising. Injector output now uses an atomic write.

RegressionTests/synthetic/hevc_nal.py

synthesize.pyPromote completed synthetic fixtures atomically +16/-5

Promote completed synthetic fixtures atomically

• Builds each fixture in an extension-preserving partial sibling, replaces the final output only when complete, and removes partials on failure or interruption. Child commands and the CLI entry point use the shared interrupt helpers.

RegressionTests/synthetic/synthesize.py

Tests (4) +458 / -193
test_help.pyKeep Python CLI tests separate from harness tests +1/-189

Keep Python CLI tests separate from harness tests

• Removes shell-harness and ZFS-provisioning tests from the Python tool help-test module; those cases move to a dedicated harness test file.

RegressionTests/tests/test_help.py

test_interrupts.pyTest signal cleanup and atomic-write guarantees +230/-0

Test signal cleanup and atomic-write guarantees

• Tests atomic replacement, mode preservation, and cleanup when replacement fails. Sends mid-run signals to locate_issue, reduce_corpus, and synthesize, and checks that synthetic scripts import from a synthetic-only copy.

RegressionTests/tests/test_interrupts.py

test_reduce_corpus.pyAdapt reduction tests to the shared child runner +4/-4

Adapt reduction tests to the shared child runner

• Mocks reduce_corpus.run_child instead of subprocess.run so existing media-probe and processing assertions cover the new call path.

RegressionTests/tests/test_reduce_corpus.py

test_regression_harness.pyIsolate Linux harness tests and expand safety checks +223/-0

Isolate Linux harness tests and expand safety checks

• Moves harness help, signal, and ZFS-provisioning tests into a Linux-gated module. Adds checks that a wrong mountpoint or non-clone dataset is refused before any destructive operation.

RegressionTests/tests/test_regression_harness.py

Documentation (2) +4 / -2
ClosedCaptions.mdClarify why caption testing uses a temporary TS file +1/-1

Clarify why caption testing uses a temporary TS file

• Explains that unreliable piping leads the tests to use a temporary TS file as standard input, rather than implying CCExtractor requires one.

Docs/ClosedCaptions.md

README.mdDocument the shared interrupt helper +3/-1

Document the shared interrupt helper

• Lists synthetic/interrupts.py and explains its placement under the directory mounted by the integration run.

RegressionTests/README.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (1) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Three tools lack a mid-run signal test 📎 Requirement gap ☼ Reliability
Description
The mid-run signal tests in ToolSignalTests cover only locate_issue, reduce_corpus and
synthesize, while audit_physical.py, catalog_corpus.py and check_results.py have none, and
the PR's Not Covered section excuses them because they hold only a momentary temporary file. The
rule requires a mid-run signal test for each of the six tools, so an interruption during those three
tools' writes or child work goes unexercised by any test.
Code

RegressionTests/tests/test_interrupts.py[R55-56]

+@unittest.skipIf(sys.platform == "win32", "Windows cannot deliver SIGINT or SIGTERM to a script")
+class ToolSignalTests(unittest.TestCase):
Evidence
The PR's own test class lists only three tool tests, and the PR description states the other three
are excluded by choice rather than by a test. The checklist requires each of the six tools to have
one.

Test mid-run interruption cleanup for every affected tool
RegressionTests/tests/test_interrupts.py[163-207]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR adds mid-run signal tests only for `locate_issue`, `reduce_corpus` and `synthesize`. The compliance rule requires a mid-run signal test for each of the six tools, including `audit_physical.py`, `catalog_corpus.py` and `check_results.py`. The PR currently excludes these three by choice.
## Fix Focus Areas
- RegressionTests/tests/test_interrupts.py[55-210]
- RegressionTests/audit_physical.py[90-100]
- RegressionTests/catalog_corpus.py[92-100]
- RegressionTests/check_results.py[341-350]
## Recommended Fix
Add a `ToolSignalTests` case for each of the three tools, following the pattern of `test_locate_issue`. Each case should hold the tool mid-run, for example by stubbing a slow child or by making the tool's input large enough to keep it running long enough to signal. It should assert the signal death status, one interrupt line with no traceback, and that nothing remains in the temporary directory. Keep the Windows skip on the class. If the tools have no child process to hold, hold a temporary path instead, as the rule's objective allows.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Building a fixture can erase another file ✓ Resolved
Description
build_target always uses the predictable sibling .partial and unlinks it in finally, even if
that path existed before the build. If a user already has that sibling file, a build can overwrite
or delete it; concurrent builds for the same output can also replace or remove each other’s partial
results.

3. Saving through a symlinked state file replaces the link ✓ Resolved
Description
atomic_write_bytes takes its mode from path.stat(), which follows a symlink, and then calls
os.replace(temp, path), which swaps out the link itself for a plain file. Say the external rules
file locate_issue --record writes to, or a catalog.json or expected-results file, is a symlink
into another checkout. Each write then cuts the link, so the real target stops getting updates and
nothing reports it. Hard links and ownership are lost the same way.

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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.

🟡 Changes recommended

The regression tests do not verify SIGTERM delivery for the locate_issue and synthesize cases, so a SIGKILL regression could still pass undetected.

1 open issue
What changed in this PR

This pull request applies shared interrupt handling and atomic-write behavior across the RegressionTests Python tooling, improving signal re-raising, child-process cleanup, and protection against partial state.

Changes:

  • Adds shared signal, child-process, and atomic-write helpers under RegressionTests/synthetic/.
  • Migrates corpus, reduction, catalog, result-checking, locating, and synthetic-generation tools to the shared helpers.
  • Expands harness, interrupt, mountpoint, clone-origin, and synthetic-directory test coverage.
  • Clarifies the related CCExtractor temporary-file behavior in the documentation.
File Description
RegressionTests/​tests/​test_regression_harness.py Separates harness tests and adds Linux-only signal, mountpoint, clone-origin, and synthetic-directory coverage.
RegressionTests/​tests/​test_reduce_corpus.py Updates reduction tests and subprocess mocks for the shared child-process runner.
RegressionTests/​tests/​test_interrupts.py Adds atomic-write, child-cleanup, signal, and synthetic-directory tests.
RegressionTests/​tests/​test_help.py Maintains help and injector-focused tests after harness coverage was extracted.
RegressionTests/​synthetic/​synthesize.py Routes media-tool processes through shared interrupt handling and promotes partial outputs atomically.
RegressionTests/​synthetic/​interrupts.py Provides shared signal handling, bounded child termination, and atomic-write primitives.
RegressionTests/​synthetic/​hevc_nal.py Applies shared interrupt handling and atomic output writes to the injector entry points.
RegressionTests/​reduce_corpus.py Uses shared child execution, atomic catalog writes, and interrupt-aware entry handling.
RegressionTests/​README.md Documents the shared interrupt helper and synthetic-directory integration layout.
RegressionTests/​locate_issue.py Adds interrupt-aware child cleanup and atomic rule-file writes.
RegressionTests/​corpus_common.py Routes media-tool subprocesses through the shared child runner.
RegressionTests/​check_results.py Makes expected-result writes atomic and uses shared interrupt-aware entry handling.
RegressionTests/​catalog_corpus.py Makes catalog generation atomic and uses shared interrupt-aware entry handling.
RegressionTests/​audit_physical.py Makes augmented catalog updates atomic and uses shared interrupt-aware entry handling.
Docs/​ClosedCaptions.md Clarifies the temporary TS-file consequence of CCExtractor input handling.

Review effort: Lite

ptr727 and others added 2 commits November 26, 2026 07:36
The atomic write resolves its target first, so a symlinked state file
keeps its link. synthesize reserves its partial sibling with mkstemp, so
it never overwrites or deletes a file it did not create. A test drives a
KeyboardInterrupt through the atomic write, the only thing
audit_physical, catalog_corpus and check_results hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One TERM-trapping stub serves all three cases, so a regression to
SIGKILL fails locate_issue and synthesize as it already failed
reduce_corpus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptr727

ptr727 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Action not completed

Head commit changed.

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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptr727

ptr727 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

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

@ptr727

ptr727 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

@qodo-free-for-open-source-projects please dismiss finding 1 ("Three tools lack a mid-run signal test"). audit_physical, catalog_corpus and check_results hold no child process and no long-lived path. The one thing each holds is the temporary file inside interrupts.atomic_write_bytes, which all three share. 2d8e98d adds test_interrupt_mid_write_keeps_the_old_content_and_leaves_no_temp, which raises KeyboardInterrupt, the exception the signal handler raises, from inside that write. It asserts the old content survives and no temporary file remains. That is the mid-run interruption of everything those tools hold. A whole-process signal test would need a hook to stop each tool inside a write that lasts microseconds.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

please dismiss finding 1 ("Three tools lack a mid-run signal test"). audit_physical, catalog_corpus and check_results hold no child process and no long-lived path. The one thing each holds is the temporary file inside interrupts.atomic_write_bytes, which all three share. 2d8e98d adds test_interrupt_mid_write_keeps_the_old_content_and_leaves_no_temp, which raises KeyboardInterrupt, the exception the signal handler raises, from inside that write. It asserts the old content survives and no temporary file remains. That is the mid-run interruption of everything those tools hold. A whole-process signal test would need a hook to stop each tool inside a write that lasts microseconds.

I couldn't dismiss finding 1 ("Three tools lack a mid-run signal test") because I can't match it to a finding ID. The findings index for this PR is empty, so I have no stable ID to pass to the dismiss action.

Your argument is substantive. test_interrupt_mid_write_keeps_the_old_content_and_leaves_no_temp covers the one thing those three tools hold, and the rule's objective allows holding a temporary path instead of a child process. If you want this closed, the usual options are:

  • Retry the dismissal once the findings index is populated for this PR. I'll match it by title and then dismiss it, with the reason "intentional" or "rejected" if you tell me which fits.
  • Dismiss it in the Qodo UI if that's available to you as the PR author.

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