Skip to content

test(dj): accept the sandbox fallback scratch dir - #1013

Merged
LargeModGames merged 1 commit into
mainfrom
fix/dj-scratch-test-sandbox
Nov 14, 2026
Merged

LargeModGames merged 1 commit into
mainfrom
fix/dj-scratch-test-sandbox

Conversation

@kapok-4o

@kapok-4o kapok-4o commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #1011. the_agent_scratch_dir_is_not_the_current_directory failed in the Nix sandbox at assert!(scratch.ends_with("dj-scratch")).

In the sandbox HOME cannot be created, so agent_scratch_dir uses its fallback (#478): a private dir from fresh_private_dir(temp, "spotatui-dj-scratch"), named spotatui-dj-scratch-<pid>-<nanos>-<n>. Path::ends_with compares whole components, so that name never matches dj-scratch. The code was right; the test only knew the state-dir case.

The test now checks what it guards: the scratch dir is not the current directory, it is absolute, and its last component contains dj-scratch, which holds for both the state dir and the fallback. No production code changes.

Testing

  • cargo fmt --all --check: clean
  • cargo test --locked --no-default-features --features telemetry,tui,ai-dj -- scratch: 2 passed, 0 failed
  • With HOME=/nonexistent/sandbox-home XDG_STATE_HOME= (CARGO_HOME and RUSTUP_HOME pointed at the real ones), the same test fails on main at session.rs:678 and passes with this change.

Additional notes

Not run inside a real Nix build. If it holds there, doCheck = !withAiDj; in nixpkgs' spotatui/package.nix can go.


💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • Tests
    • Updated scratch-directory validation to support both configured directories and uniquely named temporary fallback directories.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The scratch-directory test now accepts both the configured dj-scratch directory and a uniquely named temporary fallback. It checks that the selected path is absolute and that its final component contains dj-scratch.

Changes: Scratch directory test

Layer / File(s) Summary
Scratch path validation
src/infra/dj/session.rs
The test checks that the scratch path is absolute and that its final component contains dj-scratch. This replaces the exact suffix check.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Other · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 6d35c

This updates a test so the AI DJ-enabled Nix sandbox build no longer fails on the scratch-directory check. No production behavior changes, and no merge-blocking risk remains.

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 uses the conventional-commit prefix test(dj) and an imperative subject, which matches the configured title requirements. It names the sandbox fallback scratch directory, which is the main ch…
Linked Issues check Passed Issue #1011 asks that the_agent_scratch_dir_is_not_the_current_directory no longer fails in a Nix sandbox. The failing assertion was assert!(scratch.ends_with("dj-scratch")). The production code a…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes one file, src/infra/dj/session.rs, with +8/-1 lines. The only change is inside the the_agent_scratch_dir_is_not_the_current_directory test body. It…
Full details: Title check

Explanation

The title uses the conventional-commit prefix test(dj) and an imperative subject, which matches the configured title requirements. It names the sandbox fallback scratch directory, which is the main change: the scratch-directory test now accepts the sandbox fallback naming pattern as well as the configured dj-scratch directory.

Full details: Linked Issues check

Explanation

Issue #1011 asks that the_agent_scratch_dir_is_not_the_current_directory no longer fails in a Nix sandbox. The failing assertion was assert!(scratch.ends_with("dj-scratch")). The production code at head uses scratch_dir_from, which falls back to fresh_private_dir(temp, "spotatui-dj-scratch") when the state dir is unusable (#478). That fallback yields spotatui-dj-scratch-&lt;pid&gt;-&lt;nanos&gt;-&lt;n&gt;, so Path::ends_with never matches it. The diff replaces that assertion in src/infra/dj/session.rs with three checks: the path differs from the current directory (kept), the path is absolute, and its final component contains dj-scratch. Both the state-dir case and the fallback satisfy these checks. The test now passes under the sandbox condition, as the PR reports for a local HOME override. The fix is coding work in automated tests, which the issue requires. Not verified: a real Nix build, which the PR states was not run.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes one file, src/infra/dj/session.rs, with +8/-1 lines. The only change is inside the the_agent_scratch_dir_is_not_the_current_directory test body. It directly implements the #1011 objective. No production code changes. No unrelated files or hunks appear in the reviewed diff.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • 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 d36f53d and 6d35c2e.

Files selected for processing: 1

  • src/infra/dj/session.rs

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

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit 1a011d8 into main Nov 14, 2026
39 checks passed
@LargeModGames
LargeModGames deleted the fix/dj-scratch-test-sandbox branch November 14, 2026 13:29
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.

Test the_agent_scratch_dir_is_not_the_current_directory fails in Nix sandbox

2 participants