Skip to content

test(box): name unit cases by condition and expected outcome - #258

Closed
kevin-orellana wants to merge 1 commit into
mainfrom
feature/box-core-unit-when-then
Closed

kevin-orellana wants to merge 1 commit into
mainfrom
feature/box-core-unit-when-then

Conversation

@kevin-orellana

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Unit tests use mixed naming styles. Their names do not consistently separate the condition from the expected result.

Solution. Give 687 existing box unit-test definitions condition/outcome names, and update their exact subprocess filters and references. The memory-read test now describes its actual parent/child relationship.

Trade-off. This produces 1,528 changed lines of mechanical review work. It adds no test coverage. Existing assertions, platform conditions, and ignored status are preserved.

Description

Use when_<condition>_then_<expected_outcome> for the existing unit-test functions. Keep their test bodies and runtime behavior intact. Reference changes include documentation and integration-test comments or diagnostics; existing integration case names and assertions remain unchanged.

Suite extraction and the HOME fixture cleanup are separate patches. This PR can target main independently of the other component's rename PR.

This is an intentionally incomplete draft, published before the remaining macOS and broader checks. It is not ready for approval or merge.

Related Issues

Related naming work: #249. This PR does not close the broader coverage effort.

Type of Change

Other (please describe): unit-test naming and reference cleanup.

Testing

Tested head: 84195459c6d11a22f040055876e94df9fc6e6d0c. Its source tree is 5bc9f01d35107ef467351dd8424da546d0d1ea29, based on e4ca8b80359b2213d684de31cd6ef32e0d61478a.

Host: Linux ARM64, Rust 1.98.1. The exact publication tree ran:

cargo test -p strands-box --lib --bins --all-features --locked -- --show-output
Check Result Scope
Library and binary unit tests 677 passed, zero failed or ignored, no reported skips Exact publication tree
Source-preservation audit All 1,130 existing definitions preserved their assertions, literal data, platform conditions, and ignored status Both prepared rename batches; approved identifier/reference changes and one corrected doc comment
Local adversarial review Four misleading descriptions corrected; no unresolved source finding Both prepared batches
Formatting Passed Prepared combined series
Clippy Passed with warnings denied and the repository's vendor allowlist Both crates, all targets and features, prepared combined series
Native macOS, full workspace, integration, examples, and live-agent checks Pending Required follow-up before review readiness

Definition counts and executed Linux test counts differ because platform conditions and shared code affect discovery. The Box alias-image test initially returned early without its helper; the helper was installed, and the exact publication run has no reported skip.

The following full-suite attestations remain unchecked. The author approved opening these drafts before completing them. Hosted checks will supply additional evidence; dispatch alone is not a pass.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works — no new behavioral test is required for these renames; the existing tests were preserved and executed
  • I have updated the documentation accordingly
  • My changes generate no new warnings — supported by the prepared-series lint run above; the full workspace attestation remains pending

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

## Problem

Box core unit tests use mixed naming styles. A test list does not consistently separate the condition from the expected result.

## Solution

Rename 687 existing unit-test definitions to when_<condition>_then_<expected_outcome>. Update exact child-process filters and references. Correct the memory-read test description to identify a parent and child.

Keep test assertions, platform conditions, and ignored status unchanged. Leave suite extraction and HOME fixture changes in separate patches.

## Tests

Linux ARM64: cargo test -p strands-box --lib --bins --all-features --locked -- --show-output. Exact publication-tree results: 677 passed, zero failures, zero ignored tests, and no reported skips.

The prepared combined tree passed formatting, both crates' all-target/all-feature Clippy checks with the repository vendor allowlist, and source-preservation checks for all 1,130 existing test definitions. Adversarial review corrected four descriptions across the two rename batches.

Native macOS and full workspace, integration, examples, and live-agent gates remain pending. The user approved draft publication before completing those gates. This commit makes no coverage-percentage claim.
@github-actions github-actions Bot added chore Maintenance tasks, dependency updates, CI changes, refactoring with no user-facing impact Area - Release labels Nov 1, 2026
@kevin-orellana
kevin-orellana marked this pull request as ready for review November 1, 2026 09:06
/// refused.**
#[test]
fn a_credential_store_is_granted_only_when_named_exactly() {
fn when_a_credential_store_is_named_exactly_then_it_can_be_granted() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important (non-blocking): This rename removes the refusal half of a credential-floor test from its name. The test still checks the refusal, but the name no longer says so.
Example: The old name a_credential_store_is_granted_only_when_named_exactly covered both arms. The body still checks both: read = ["~/.aws"] is granted, and read = ["~"] must be refused beneath every grant. The new name ..._then_it_can_be_granted names only the permissive arm. The deny arm is the security property here. crates/box/AGENTS.md:285-286 cites this test for "A prefix of a store, or a parent of one, stays refused." A reader who trusts the name could treat the ~ assertion as incidental.

The same "only when" → one-arm change happens in two other places:

  • run/contain/boundary.rs:1877 a_log_directory_gets_metadata_only_when_the_process_lists_it → when_a_process_lists_its_log_directory_then_metadata_access_is_granted. The body also checks that an unlisted directory gets no rule, and that file-read*/file-read-data/file-write-data/process-exec are never granted.
  • run/contain/boundary.rs:1941 the_disclosure_names_native_egress_only_when_it_is_selected → when_native_egress_is_selected_then_the_disclosure_names_it. The body also checks that a gateway leaf's disclosure does not mention native egress.

Suggestion: Keep both outcomes in the then_ clause. For example: when_a_credential_store_is_named_then_only_an_exact_entry_is_granted, when_a_log_directory_is_listed_then_only_metadata_is_granted, when_egress_mode_varies_then_only_native_egress_is_disclosed. Then update the AGENTS.md reference.

Comment thread crates/box/AGENTS.md
operator's filesystem. Two escapes were found in its first version, both pinned by a test that
must not be deleted:
- a **dangling symlink written through** (`a_dangling_symlink_cannot_be_written_through`). "It
- a **dangling symlink written through** (`when_a_write_targets_a_dangling_symlink_then_it_is_refused`). "It

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important (non-blocking): The list of tests that must survive in .agents/agents/feature-critic.md:150-154 no longer covers the Monty escape tests that this file cites.
Example: On main, a_dangling_symlink_cannot_be_written_through and an_intra_home_symlink_cannot_launder_a_scoped_read each named two tests: one in run/broker/python/effects.rs, which this section and docs/design/decisions.md cite as "must not be deleted", and one in tests/box_shell.rs. This PR renames only the effects.rs copies. The old names in feature-critic.md still match the box_shell.rs copies, so git grep -w reports nothing stale. But the critic's "named examples that must survive" check now guards only the Shell halves. A later change that deletes when_a_write_targets_a_dangling_symlink_then_it_is_refused would not hit that list.

A smaller issue: line 229 of this file, which the PR also edits, cites run_config.rs::when_run_selects_a_box_then_.... That test is in src/record/config/mod.rs, not tests/run_config.rs. The wrong prefix was already there before this PR, but since the line is being rewritten anyway, now is a good time to fix it.

Suggestion: Add the two new effects.rs names to the feature-critic.md list next to the old ones. Change the line-229 prefix to record::config::tests:: (or config/mod.rs::).

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Comment

The rename is mechanically sound. Mapping each old name to its new name over e4ca8b8 and diffing against this head leaves only rustfmt brace wraps and the corrected hardening.rs doc comment. Two problems remain, both about whether names and references still say what they pin. Neither blocks the merge. Unit tests on Linux and macOS were still running in CI when I reviewed. The draft status and pending macOS checks are already noted in the description.

Checked and held
  • Test bodies: unchanged apart from rustfmt brace wraps for the 22 signatures that exceed 100 columns, and the hardening.rs doc comment, which matches the fork/process_vm_readv probe.
  • Subprocess --exact filters: the effects.rs rename test and probe.rs (module_path!) both resolve to the enclosing fn.
  • Stale references: no old name remains anywhere in the tree (git grep -w). The only exceptions are names that also exist as integration or other-crate tests, covered inline.
  • New references: all 685 when_* names cited in docs and comments are defined.
  • Scope: all 685 renamed fns are #[test]/#[tokio::test]. No helper was renamed, so cfg-gated macOS callers cannot break.
  • Root AGENTS.md premise: the mcp.rs reference is updated, and no frozen surface is touched.
  • cargo fmt --all --check passes, and CI Lint passes.
  • scripts/check-linux-test-output.py does not depend on test names.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 1, 2026 09:15
auto-merge was automatically disabled November 1, 2026 09:27

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Release 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.

2 participants