Skip to content

Stop the Regression Container by Name and Refuse Arguments First - #1308

Merged
ptr727 merged 2 commits into
developfrom
harness-signals-1305-1306
Nov 26, 2026
Merged

ptr727 merged 2 commits into
developfrom
harness-signals-1305-1306

Conversation

@ptr727

@ptr727 ptr727 commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Why

regression-test.sh adds -it to docker run when its standard input is a terminal, which is the usual sudo env ... regression-test.sh run. In TTY mode the docker CLI passes no signals to its container. So a SIGTERM sent to the harness never reached PlexCleaner, and the EXIT trap's zfs rollback could run while the container was still processing the test dataset (#1305).

The harness and integration-test.sh also refused some arguments only after host lookups or a tool lookup, so a bad argument could exit 1 with an unrelated error instead of 64 (#1306).

What

  • regression-test.sh: a RunContainer wrapper records the container name for the length of each docker run. The INT/TERM trap sends SIGTERM to that container with docker kill, then waits on the CLI, which exits once the container stops. Where no container run is active, or docker kill fails, the trap signals the child as before.
  • regression-test.sh: the tag, corpus, plugin, and REGRESSION_COVERAGE_TOOL checks run ahead of the nonroot/users lookups.
  • integration-test.sh: a dash-prefixed argument is refused in any position, and an existing WORKDIR is refused before the dotnet-coverage lookup.
  • Tests: the dataset-restore signal test runs with a pty on standard input as well as without one, using a CLI stub that ignores SIGTERM until its container is stopped. A third case covers the fallback when docker kill fails. New refusal tests cover each reordered check. Each new test fails against develop's scripts.

The comments label covers the trap's one new comment line, plus two existing comments the validation move carries along.

Verification

  • python3 -m unittest discover -s tests in RegressionTests/: 141 tests OK. ruff, mypy, shellcheck, and shfmt are clean.
  • Mutation check: replacing the fallback with an unconditional docker kill fails both kill_works=False subtests.
  • Local strict review: two frontier passes, the last recorded at 0 findings. The first pass raised one finding against the carried "Interrupts in Shell" rule, which has no case for a child that passes no signal on. That goes to the hub's per-unit tracker rather than into this change.
  • The real-host harness run on the ZFS host is still pending, and the merge waits on it.

Closes #1305
Closes #1306

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Invalid options and existing work directories are now rejected earlier with clearer errors.
    • Unknown plugin selections are refused before environment checks.
    • When a regression run is interrupted, cleanup now attempts to stop the running container and restore provisioned resources.
    • Input handling for interrupted processes is more consistent across terminal and non-terminal sessions.

ptr727 and others added 2 commits November 26, 2026 11:09
A docker CLI holding a TTY passes no SIGTERM to its container, so the
harness signal trap now stops the running container with docker kill by
name, then waits for the CLI. The EXIT trap's rollback no longer runs
under a container still processing the test dataset. The trap falls
back to signalling the CLI where no container run is active or the kill
fails.

regression-test.sh validates the tag, corpus, plugin, and coverage
arguments ahead of the nonroot and users lookups, so a bad argument is
refused with 64 on any host. integration-test.sh refuses a dash-prefixed
argument in any position, and an existing WORKDIR before the tool
lookup.

Closes #1305
Closes #1306

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 19:17
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The RegressionTests scripts now reject invalid arguments and work directories earlier. The regression harness tracks the active Docker container and attempts to stop it on signals, with tests covering TTY input, kill failures, and dataset rollback.

Changes: Regression harness behavior

Layer / File(s) Summary
Argument and work-directory validation
RegressionTests/integration-test.sh, RegressionTests/regression-test.sh, RegressionTests/tests/test_regression_harness.py, RegressionTests/tests/test_shell_scripts.py
integration-test.sh checks every argument for a leading dash and refuses an existing work directory before tool lookup. regression-test.sh performs argument and coverage-tool validation earlier. Tests verify the refusal behavior.
Container tracking and signal handling
RegressionTests/regression-test.sh, RegressionTests/tests/script_helpers.py, RegressionTests/tests/test_regression_harness.py
The harness tracks the container while Docker runs. On a signal, it attempts to send TERM to the container and falls back to signaling child processes if needed. The tests cover TTY modes, Docker kill outcomes, and dataset rollback.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Harness as regression-test.sh
  participant Docker as Docker CLI
  participant Container as Regression container
  participant ZFS
  Harness->>Docker: Send TERM to the tracked container
  Docker->>Container: Deliver TERM
  Harness->>ZFS: Roll back the provisioned dataset during cleanup
Loading

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · up to 0cdd3

The change makes the regression scripts refuse bad arguments earlier and stops the named container on interrupt before the dataset rollback. No concrete defect was found, and the new tests cover the changed behavior. The author's pending real-host ZFS run is the remaining check before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two changes that appear in the changeset: the regression container is now stopped by name on SIGINT/SIGTERM (via docker kill --signal TERM on the tracked container), and argument refus…
Linked Issues check Passed [#1305] RegressionTests/regression-test.sh sets Container to ContainerName in RunContainer for the length of each docker run. OnSignal runs docker kill --signal TERM on that container, then waits on t…
Out of Scope Changes check Passed All changes map to #1305 or #1306. The RunContainer wrapper and OnSignal fallback implement #1305. The argument reordering and the dash-prefix check implement #1306. The added tests in test_regression…
Full details: Title check

Explanation

The title names two changes that appear in the changeset: the regression container is now stopped by name on SIGINT/SIGTERM (via docker kill --signal TERM on the tracked container), and argument refusals were moved ahead of host lookups in both scripts (regression-test.sh validation moved before the root check; integration-test.sh refuses dash-prefixed arguments and existing workdirs earlier). The title is concise, specific, and matches the main objectives of PR #1308 and linked issues #1305 and #1306.

Full details: Linked Issues check

Explanation

[#1305] RegressionTests/regression-test.sh sets Container to ContainerName in RunContainer for the length of each docker run. OnSignal runs docker kill --signal TERM on that container, then waits on the child PIDs. If no container is tracked or docker kill fails, it sends SIGTERM to the child, as the issue requires. Docker run uses --rm, so a stopped container releases the PlexCleaner-RegressionTest name. Ctrl-C handling is unchanged. The PR adds signal tests for stdin with and without a pty and for the docker kill failure fallback, per the PR description. The real-host ZFS run is pending. It is a verification step, not a coding requirement, and the static code evidence does not show the container's runtime stop behavior.

[#1306] regression-test.sh now validates the Mode, Tag, Corpus, and Plugins arguments, and the REGRESSION_COVERAGE_TOOL value, before the id -u nonroot and getent group users lookups. Unknown arguments exit 64 through UnknownArgument or Refuse. integration-test.sh checks every argument for a leading dash (after --help handling), so a dash-prefixed second argument is refused with 64. It refuses an existing WORKDIR before the dotnet-coverage lookup. New refusal tests cover each reordered check.

Full details: Out of Scope Changes check

Explanation

All changes map to #1305 or #1306. The RunContainer wrapper and OnSignal fallback implement #1305. The argument reordering and the dash-prefix check implement #1306. The added tests in test_regression_harness.py, script_helpers.py (the stdin parameter), and test_shell_scripts.py support those changes. The one new comment line in the trap and the two moved comments describe the same changed code. The PR notes the 'Interrupts in Shell' rule gap is tracked elsewhere and is not changed here. No unrelated file or behavior change was found in the reviewed code.

Limit: the whole-PR diff tool was unavailable. Review used the head file contents and the supplied change summary, not a base-to-head diff. The test file changes were not read directly.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 568a6e3 and 0cdd337.

Files selected for processing: 5

  • RegressionTests/integration-test.sh
  • RegressionTests/regression-test.sh
  • RegressionTests/tests/script_helpers.py
  • RegressionTests/tests/test_regression_harness.py
  • RegressionTests/tests/test_shell_scripts.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@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

Stop the regression container before rollback and validate arguments early

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Stop the named regression container before restoring its dataset, including when Docker has a TTY.
• Refuse invalid harness and integration inputs before unrelated host or coverage-tool lookups.
• Test signal handling, kill failure, TTY mode, and early argument refusal.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: ZFS-backed regression harness execution, integration test execution.
  • This is the bounded workflow that synthesizes media, runs the image under coverage, and checks result files.
  • Its validation changes affect that end-to-end test operation, not application runtime behavior.
  • This bounded workflow provisions a disposable corpus clone, runs the image and plugins, records results, and restores the dataset.
  • The changed container lifecycle and interruption path coordinate those steps as one end-to-end operation.
Sources

RegressionTests/integration-test.sh[85-86]

if [[ -e "$work" ]]; then
    Refuse "integration-test.sh: $work exists, give a new directory"
Behavioral complexity 🔴 High 🧩 Interacting branches, Concurrent ordering

  • Before, the signal handler sent TERM to the Docker CLI child and waited.
  • After, the harness tracks a named container, attempts container termination, falls back to signaling the CLI, and clears tracking after each wrapped run.
  • The new correctness conditions are that the tracked container corresponds to the active child, fallback occurs when container termination fails, and cleanup/wait ordering still permits dataset restoration across TTY and non-TTY execution.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the changed validation behavior is wrong for a supported invocation, the integration test run can be refused or fail to start.
  • No PlexCleaner production data or external customer effect is reached.
  • Re-run with corrected arguments or a new work directory; the source revert restores the prior invocation behavior.
Sources

RegressionTests/integration-test.sh[85-86]

if [[ -e "$work" ]]; then
    Refuse "integration-test.sh: $work exists, give a new directory"
Assessed commit 0cdd337
Diagram

graph TD
  S["INT or TERM"] --> D{"Container active?"} -->|yes| K["Kill named container"] --> C{"Kill succeeded?"} -->|yes| W["Wait for child"] --> R["Restore dataset"]
  D -->|no| F["Signal child"] --> W
  C -->|no| F
Loading
High-Level Assessment

Stopping the already-named container directly addresses the TTY signal gap without removing interactive TTY support. Retaining child-process signaling as a fallback preserves behavior for other commands and Docker kill failures.

Files changed (5) +160 / -92

Bug fix (2) +62 / -50
integration-test.shRefuse options in any position and existing workdirs early +8/-6

Refuse options in any position and existing workdirs early

• Checks every argument for a dash prefix. Rejects an existing WORKDIR before looking up dotnet-coverage, so these invalid inputs produce the intended refusal status.

RegressionTests/integration-test.sh

regression-test.shStop active containers on signals and move validation ahead of host lookups +54/-44

Stop active containers on signals and move validation ahead of host lookups

• Tracks the named container around each Docker run and sends it SIGTERM on interruption, falling back to signaling the child if needed. Moves tag, corpus, plugin, and coverage-tool validation before nonroot user and group lookups.

RegressionTests/regression-test.sh

Tests (3) +98 / -42
script_helpers.pyAllow signal tests to provide terminal stdin +2/-1

Allow signal tests to provide terminal stdin

• Adds an optional stdin parameter to the shared interruption helper, retaining DEVNULL as the default.

RegressionTests/tests/script_helpers.py

test_regression_harness.pyCover early plugin refusal and container shutdown before rollback +84/-41

Cover early plugin refusal and container shutdown before rollback

• Verifies an unknown plugin is refused before host lookups. Expands dataset-restore signal tests to cover TTY and non-TTY runs and the fallback when Docker kill fails.

RegressionTests/tests/test_regression_harness.py

test_shell_scripts.pyCover integration argument refusals before tool lookup +12/-0

Cover integration argument refusals before tool lookup

• Tests rejection of a dash-prefixed WORKDIR and an existing WORKDIR when dotnet-coverage is unavailable.

RegressionTests/tests/test_shell_scripts.py

@ptr727

ptr727 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

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

@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 (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Interrupting one run stops another 🐞 Bug ≡ Correctness
Description
OnSignal treats a successful docker kill of the fixed container name as proof that it stopped
this invocation’s child, without checking which run owns that container. If another run already
holds the name, this invocation’s docker run can fail with a name conflict while its CLI is still
tracked; an interrupt at that point terminates the other run’s container instead.
Code

RegressionTests/regression-test.sh[R103-105]

+        if [[ -z "$Container" ]] || ! docker kill --signal TERM "$Container" >/dev/null 2>&1; then
+            kill -s TERM "${pids[@]}" 2>/dev/null || :
+        fi
Evidence
Every Docker run uses the same name, and RunContainer marks that name active before starting or
verifying its Docker CLI. OnSignal then kills whatever container currently has the name and skips
signalling the tracked CLI when that kill succeeds.

RegressionTests/regression-test.sh[221-236]
RegressionTests/regression-test.sh[80-87]
RegressionTests/regression-test.sh[100-106]

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 signal trap kills a globally named container without establishing that the current `docker run` created it. During a name conflict, interrupting this invocation can stop another invocation’s container.
## Fix Focus Areas
- RegressionTests/regression-test.sh[100-106]
- RegressionTests/regression-test.sh[221-236]
## Recommended Fix
Record the container ID created by each invocation, such as with a unique `docker run --cidfile` path. Have the signal handler kill only that recorded ID, fall back to signalling the tracked CLI if no ID is available, and clean up the ID file after the run.

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


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 script still performs environment-variable checks before validating positional arguments, so invalid input can trigger unrelated work and violate the required refusal-before-work contract.

1 open issue
What changed in this PR

This PR hardens the RegressionTests shell harnesses by stopping named Docker containers during terminal interrupts and expanding early argument-validation coverage. The regression script's positional validation still occurs after required-environment checks.

Changes:

  • Adds container-aware signal handling with a fallback to terminating the Docker CLI.
  • Reorders selected regression and integration argument checks before host-dependent operations.
  • Expands signal and refusal tests, including TTY and failed-container-stop scenarios.
File Description
RegressionTests/​tests/​test_shell_scripts.py Adds tests for integration argument rejection and work-directory refusal ordering.
RegressionTests/​tests/​test_regression_harness.py Adds coverage for TTY signal handling, container-stop fallback, and plugin validation ordering.
RegressionTests/​tests/​script_helpers.py Allows signal tests to provide custom standard input descriptors, including pseudo-terminals.
RegressionTests/​regression-test.sh Adds named-container signal cleanup and reorders selected positional validation, while required-environment checks still precede the positional preflight.
RegressionTests/​integration-test.sh Rejects dash-prefixed arguments in any position and checks existing work directories earlier.

Review effort: Lite

Comment thread RegressionTests/regression-test.sh Resolved
@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 performed

Review finished.

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 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

@qodo-free-for-open-source-projects please dismiss finding 1, 'Interrupting one run stops another' (RegressionTests/regression-test.sh:103-105). Disproven. The harness is single-run by design. Every run restores the one fixed dataset snapshot ($TestDataset@backup) and mounts the one fixed media path read-write, so a second concurrent run corrupts the first long before an interrupt matters. A name conflict on the fixed container name is the same unsupported state, and the maintainer starts one run at a time on their own host. Identifying a container's owner would harden against a case the harness already does not support.

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

Copy link
Copy Markdown

please dismiss finding 1, 'Interrupting one run stops another' (RegressionTests/regression-test.sh:103-105). Disproven. The harness is single-run by design. Every run restores the one fixed dataset snapshot ($TestDataset@backup) and mounts the one fixed media path read-write, so a second concurrent run corrupts the first long before an interrupt matters. A name conflict on the fixed container name is the same unsupported state, and the maintainer starts one run at a time on their own host. Identifying a container's owner would harden against a case the harness already does not support.

I couldn't dismiss finding 1 ("Interrupting one run stops another", RegressionTests/regression-test.sh:103-105). The published report lists it, but I can't match it to an active finding in this PR's findings catalog, which is currently empty. Without a stable finding ID, I can't safely close it.

Your rationale is clear: the harness assumes one run at a time, so a concurrent run corrupts the dataset before an interrupt matters. If you want me to dismiss it, please confirm that this is the finding you mean and I'll proceed. Note that only the PR author can dismiss findings.

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