Skip to content

test: clean up concurrent integration fixtures and share move scenarios - #256

Merged
kevin-orellana merged 2 commits into
mainfrom
feature/integration-helper-cleanup
Nov 3, 2026
Merged

kevin-orellana merged 2 commits into
mainfrom
feature/integration-helper-cleanup

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: A callback failure or startup wait timeout can leave an integration-test child running. A failed configured callback also leaves temporary configuration installed.

Solution: Give concurrent execution its own helper module and restore configuration before resuming the original panic. Request normal Box shutdown before forcing termination, so Box can stop and reap its workload groups. Keep timeout results failed even when cleanup exits successfully. Share repeated move-replacement setup and state checks while keeping separate Shell and Monty cases.

Trade-off: Failure cleanup allows five seconds for normal shutdown, then force-stops the direct child. If Box ignores shutdown, this fallback cannot guarantee descendant cleanup or bounded inherited-pipe draining. No production containment implementation changes.

Description

The fixture's existing public methods and production timeouts remain unchanged. Eleven new unit tests exercise failure and success paths using local subprocess fixtures.
Seven original deliberate-defect controls verified direct-child cleanup and configuration restoration. Four further tests cover separate workload groups, graceful timeout exits, and forced termination. The forced-termination test enforces its own twelve-second deadline and cleans up its fixture before failing.
These checks verify the test helper, not Box containment.

MoveReplacement shares only setup and common results. Shell retains its entry and exit-status assertions; Monty retains interpreter identity and PermissionError checks.
Both cases still assert a successful fresh move, refusal of replacement by no_deletes, and preserved file contents.
The README explains composition through small helpers and independent case reporting. Runtime extraction is a separate companion change.

Category What the tests prove Results and remaining gaps
Containment: 78 deterministic cases The cases distinguish permitted operations, required refusals, and recorded limitations across native filesystem, execution, process, network, and environment behavior. 69 passed and nine skipped on Linux. Nine cases remain declared macOS-only. Terminal observations in CN-I-11 do not prove terminal isolation; complete Linux/macOS parity is not established.
Policy: 9 deterministic cases Mediated requests follow authorization rules and retain deny-only protections. 9 passed on Linux. No authorization or denial assertion was removed.
Shell: 24 deterministic cases Shell requests produce the checked results while preserving policy refusals and request isolation. 24 passed on Linux. The move-replacement case retains its Shell-specific refusal checks.
Monty: 14 deterministic cases Python requests use the restricted interpreter and preserve its operation and policy boundaries. 14 passed on Linux. These checks concern the restricted interpreter, not native Python containment.
Telemetry: 8 deterministic cases Records preserve the checked identity, decision, destination, trace, and payload protections. 8 passed on Linux. A deployed telemetry service is outside this qualification.

The nine Linux skips are CN-D-01, CN-D-02, CN-E-04, CN-F-02, CN-F-03, CN-I-13, CN-L-01, CN-P-02, and CN-T-05.
They are actual test cases declared for macOS. Linux-specific cases test different supported boundaries; this refactor does not close the remaining platform gaps.
The Linux test-gate enforcement from #185 is unchanged. Deployment qualification remains separate.

Related Issues

Companion to runtime-restructuring PR #249 and the integration coverage work in #187.
Runtime extraction remains in PR #249; bulk renaming has been withdrawn, and PR #257 is superseded. This cleanup PR remains separate.
The unit-test owner retains Box and containment source ownership. The separate live HTTP repair owns crates/box/tests/box_telemetry.rs.

Type of Change

Other: Test harness organization. Includes a cleanup and configuration-restoration bug fix in the test helper.

Testing

Exact source. Base e4ca8b80359b2213d684de31cd6ef32e0d61478a; published head cf227b7615b31ec4682c309967e30f26d0d328f7.
The final candidate tree is be334ba4da15bde015cbca13c5c4a686aacf79d8. The follow-up patch over eb656874aca1057ecd4368d2ff2f1d89d144339e has SHA-256 7a8436c6d74c4946c5fdef4a74b179800826a3038618e2d48dc1c51cfeb9d437.
The combined check applies #249 head 49f7f1b6fb9476061d5e26e40a57df27e4712aa7 and both helper patches to that base.
The full combined integration run used tree f3d845b246b550d98dd9ee7adffbceaa07ce8bac. A subsequent watchdog-only unit-test change produced final combined tree 34a3c373f4095a4e019711389b6f5874de839aad; all eleven affected unit tests, formatting, and strict Clippy passed again. Integration case bodies and helper implementation were unchanged after the full run.
The raw verdict records box_commit: unknown; the verified trees, patch hashes, and build receipts identify its source. The base commit alone does not identify the tested patch set.

Linux environment. Amazon Linux 2023.12.20261102 as reported by /etc/os-release, AArch64, kernel 6.12.113-138.209.amzn2023.aarch64, Rust/Cargo 1.98.1.
Runs used EXPERIMENTAL_LINUX_SUPPORT=TRUE, CARGO_BUILD_JOBS=2, and the built target/debug directory first on PATH.
The alias helper was also installed beside the workspace test binaries. HOME was unchanged.

Check Result and execution boundary
Full workspace unit/bin targets 1,873 passed, zero failed, seven ignored. A nested child-test summary is excluded to avoid counting its parent scenario twice.
Full workspace integration targets Cargo reported 2,709 passed, zero failed, nine ignored. One pass returned before its live credential-daemon assertion; another omitted alias-read protection but executed its write checks. Thus 2,707 passes had neither documented omission. The successful custom box_library target emits no count and is excluded.
Workspace documentation tests 13 passed, zero failed, one ignored.
Combined deterministic integration 124 passed, nine declared macOS-only skips, zero failures/errors; 133 expected and recorded, with no integrity problems. Each of the 133 case identifiers remains separately reported.
Harness helper unit tests 104 library unit tests passed. Five case-local helper tests, ten Phase 3 component checks, and one case-note check also passed; one harness documentation example stayed ignored. These support checks are separate from the 133 integration cases. Cargo counts the nine platform-return wrappers as successful tests; the verdict records them as skips. The seven new process tests also passed seven separate deliberate-defect controls on Linux.
Build, formatting, lint, and documentation Workspace all-features build, formatting, repository Clippy gate, strict standalone-harness Clippy, and strict private rustdoc passed. The workspace gate uses the listed existing lint allowances; the changed harness passes without them.
Existing Linux execution reporter Passed and retained exactly the missing-daemon and partial alias-read diagnostics above.
Example gate Build and command passed, but zero examples executed because no scripted examples remain. The manual tutorial was not run.
Native macOS helper checks Darwin 27.2.0 ARM64. Eleven process unit tests and twelve runtime unit tests passed. One of the thirteen moved runtime functions is Linux-only and is excluded on macOS. Both candidate harnesses compiled all test targets; formatting and builds with default features disabled passed. This local check did not run the full macOS integration suite.

The full workspace is unchanged by these standalone harness edits. Its checks ran on the process candidate; source comparison confirms identical workspace sources for the runtime candidate.
The earlier combined deterministic run covered both helper implementations and the then-proposed case renames. Those renames have since been withdrawn; the cleanup implementation in this PR is unchanged. The final watchdog-only adjustment received focused validation as stated above. Earlier isolated candidate runs and native patch hashes match these source changes.
A combined formatting attempt with --all encountered the enclosing checkout's workspace discovery through test-common; formatting the changed standalone crate passed.
No source or assertion changed to bypass that setup error.

Commands, from the applicable checkout root with the environment above:

cargo build --workspace --all-features
cargo fmt --all --check
cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::too_many_arguments -A clippy::only_used_in_recursion -A clippy::await_holding_refcell_ref -A clippy::explicit_auto_deref -A clippy::chunks_exact_to_as_chunks -A dead_code -A non_snake_case
cargo test --workspace --all-features --no-fail-fast -- --show-output
python3 scripts/check-linux-test-output.py <workspace-test.log>
bash scripts/test-all.sh box-examples
cargo fmt --manifest-path test-integ/Cargo.toml --check
cargo clippy --manifest-path test-integ/Cargo.toml --all-targets --all-features -- -D warnings
RUSTDOCFLAGS='-D warnings --document-private-items' cargo doc --manifest-path test-integ/Cargo.toml --all-features --no-deps
cargo test --manifest-path test-integ/Cargo.toml --release --all-features --lib
DET_RESULTS_DIR=<fresh-results-directory> bash test-integ/run.sh --all-features

just is absent on this Linux host, so the listed Cargo commands ran its relevant gates directly.
The combined checkout used CARGO_TARGET_DIR=<primary-checkout>/test-integ/target and the primary checkout's unchanged Box binaries.
Native macOS used cargo test --manifest-path test-integ/Cargo.toml --all-features --lib process::tests -- --show-output, followed by --all-features --no-run, cargo fmt --check, and cargo build --no-default-features for the same manifest.

Review correction. The initial automated finding identified a real descendant leak when direct forced termination bypassed Box teardown. Separate Linux and macOS probes reproduced it. The follow-up now requests normal shutdown on callback failure, readiness timeout, and exit timeout. Independent macOS validation confirmed shutdown receipt, workload termination, and supervisor reaping. Deliberately removing forced termination failed through the test's own deadline.

Hosted validation. Initial CI run 41286760441 passed for the earlier head eb656874aca1057ecd4368d2ff2f1d89d144339e, using merge revision 14af67ae0a0099958f83046f8a07fae596f342ff. Linux recorded 124 passed and nine macOS-only skips; macOS recorded 121 passed and twelve Linux-only skips. Both recorded all 133 cases without failures/errors. Separate library unit counts were 100 Linux and 99 macOS; support counts were 16 and 11. Each platform ignored one documentation example. The hosted workspace Rust and native-filesystem jobs were skipped by changed-path filters.

The latest follow-up cf227b7615b31ec4682c309967e30f26d0d328f7 passed all applicable hosted checks in CI run 41287958730. The automated re-review confirmed that the cleanup finding is fixed and found no new issues. This prose assessment does not supply formal GitHub approval. The original review thread is resolved after the reviewer verified the fix on the current head. Formal approval, merge, and deployment qualification remain separate.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features).
  • If I touched Rust, I ran cargo fmt --all and the repository Clippy gate; the existing lint allowances are listed above.

Checklist

  • I have read the CONTRIBUTING document.
  • I have reviewed and understand every line of code in this PR, including generated code, and can explain why it works.
  • My change is focused and reasonably small; I split unrelated work into separate PRs.
  • I added or retained the tests needed to verify this change.
  • I updated the documentation accordingly.
  • My changes generate no new warnings.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

A callback panic or readiness timeout can leave the integration fixture child running.
A configured callback panic also leaves its temporary command installed.
Shell and Monty repeat the same move-replacement setup and state checks.

## Solution

Move concurrent execution into a private process module.
Stop and reap the owned child when execution unwinds.
Restore the baseline command before resuming the original callback panic.
Keep existing BoxFixture method names and production timeouts.
Share move-replacement setup and common assertions through MoveReplacement.
Keep separately reported cases, commands, interpreter checks, and route-specific refusals.
Document extension through helper composition and distinguish helper unit tests from integration coverage.

## Tests

Seven process helper unit tests pass on Linux and macOS.
when_the_callback_panics_then_the_child_is_stopped_and_reaped and
when_readiness_times_out_then_the_child_is_stopped_and_reaped pin child cleanup.
when_a_configured_callback_panics_then_the_baseline_command_is_restored and
when_an_environment_callback_panics_then_the_baseline_command_is_restored pin configuration restoration.
The other tests preserve early-exit, successful callback, and captured timeout results.
Each of seven deliberate helper defects fails its corresponding test; the restored tests pass.
SH-MV-REPLACE and MO-MV-REPLACE retain successful moves, replacement refusals, and final file contents.
The combined rename and both helper patches pass 124 Linux integration cases with nine declared macOS-only skips.
All 133 case records are present; 100 harness library unit tests and sixteen support checks pass.
Full workspace tests, all-features build, formatting, repository Clippy, strict harness Clippy, and strict private rustdoc pass.
Workspace output retains the missing credential-daemon and partial alias-read diagnostics.
The example gate builds successfully but executes zero examples because no scripted examples remain.
Cleanup of all descendants is not claimed. Native macOS checks cover helper units and compilation;
full macOS integration and deployment qualification are separate.
@github-actions github-actions Bot added chore Maintenance tasks, dependency updates, CI changes, refactoring with no user-facing impact Area - Shell/Monty strands-running labels Nov 1, 2026
@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 1, 2026 09:00
Comment thread test-integ/src/process.rs Resolved
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Comment

I reviewed head eb656874. The refactor keeps the old behavior, and restoring the configuration is correct. I found one problem with the cleanup fix: it ends only the direct child, with SIGKILL. That skips the box's own SIGTERM teardown of the workload's process group, so on macOS the case this PR names (a failed callback) still leaves a workload running. The inline comment has a reproduction and a small fix.

Checks that held
  • When the child exited normally or before the ready marker, try_wait/wait has already reaped it, so the Drop does nothing and cannot signal a reused PID.
  • The child is dropped during the unwind before restore_command_after writes the baseline back, so a running box never reads the restored configuration.
  • restore_command_after restores the same ["bash"] baseline that the old success path wrote.
  • In the Shell and Monty cases, MoveReplacement keeps every assertion that was removed: the fresh-move permit, FRESH=n, the no_deletes refusal on b.txt, and STATE=new,old. The route-specific checks stay in each case.
  • The rustdoc link fixes (native_python, SNAPSHOT_DEADLINE) point to items that exist.
  • test-integ has no AGENTS.md, and the PR touches no frozen surface or premise from the root AGENTS.md.

The new helper is now testable with injected timeouts, which is useful.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Approve (no new findings)

I reviewed cf227b76 against my earlier review of eb656874. The new commit fixes the one open finding: when a callback fails, the helper now stops the box with SIGTERM, a 5 s wait, then SIGKILL, so the box can end its workload's process group first. I found no new problems.

Checks that held on this head
  • Callback panic, readiness timeout, and exit timeout all go through stop(), and on each path the workload in its own group is reaped. I checked this with the 11 process:: tests and with an independent setsid busy-loop probe.
  • The 5 s grace is longer than the box's own teardown (STOP_GRACE 1 s, MCP stop_and_wait 1 s), so the forced SIGKILL runs only when teardown really hangs.
  • stop() signals only a child that try_wait reports as still unreaped, so the PID cannot belong to another process.
  • A child that exits normally or before the ready marker returns its cached status, and stop() sends no signal.
  • A timed-out run keeps rc = -1 after a clean exit on SIGTERM. No case matches the old within 45s text, and Duration's debug output still prints 45s.
  • The checks from the earlier review still hold: configuration restore order, MoveReplacement equivalence, doc links, and no frozen surface touched.

@kevin-orellana
kevin-orellana merged commit bb0d87c into main Nov 3, 2026
25 checks passed
@kevin-orellana
kevin-orellana deleted the feature/integration-helper-cleanup branch November 3, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Shell/Monty chore Maintenance tasks, dependency updates, CI changes, refactoring with no user-facing impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants