Skip to content

feat(list,statusline): include untracked in HEAD± for --full and statusline - #2764

Merged
max-sixty merged 2 commits into
mainfrom
status
May 15, 2026
Merged

max-sixty merged 2 commits into
mainfrom
status

Conversation

@max-sixty

@max-sixty max-sixty commented May 15, 2026 •

Copy link
Copy Markdown
Owner

wt list --full and wt statusline now count untracked-file lines in the HEAD± working-diff segment, matching what wt step diff shows. Default wt list and the picker stay on the cheap git diff --shortstat HEAD path (tracked-only). Putting the untracked-inclusive variant behind the same --full boundary as BranchDiff / CiStatus / SummaryGenerate means the explanation stays simple — "--full includes untracked too" — with no new exception class.

Mechanism

WorkingTree::working_tree_diff_stats_with_untracked() registers untracked files in a temporary copy of the index via git add --intent-to-add ., then runs git diff --shortstat HEAD against that temp index. Same trick wt step diff uses; the worktree's real index is never touched (a unit test diffs the index bytes before/after to lock that contract in).

WorkingTreeDiffTask branches on the new flag and on the cached porcelain — when no untracked entries exist, the expensive path is skipped (the two paths are bit-equivalent for tracked-only worktrees).

Refactor

A new TempIndex helper consolidates the "copy index + stage stuff into it + run a follow-up git command" pattern that was previously open-coded in three places (wt step diff, WorkingTreeConflictsTask::write_tree_with_working_tree, and the new method above). TempIndex::git(args) returns a Cmd already wired with current_dir, log context, and GIT_INDEX_FILE, so each caller collapses to a few lines.

Wiring

A new include_untracked_in_working_diff: bool on CollectOptions flows through TaskContext to WorkingTreeDiffTask. Set from show_full in collect/mod.rs, hard-coded true in statusline.rs, hard-coded false for the picker (the only other ShowConfig::Resolved consumer, which intentionally runs the same fast bucket as default wt list).

Snapshot env scrub fix (second commit)

A pre-existing latent bug surfaced when regenerating the six --full / statusline snapshots: LLVM_PROFILE_FILE (set on every test subprocess by isolate_subprocess_env since #2730) leaked into the env block as a platform-specific tempdir path. The intended scrub at setup_snapshot_settings was using add_filter, which only substitutes on captured snapshot content — never on the YAML info/env block — so it was dead code. Replaced with add_redaction(".env.LLVM_PROFILE_FILE", ...) (and the same for CARGO_LLVM_COV*) inside add_standard_env_redactions, which is already bound by the repo rstest fixture; values now render as stable [LLVM_PROFILE_FILE] placeholders matching the existing convention for HOME / GIT_CONFIG_GLOBAL / etc.

Tests

3695 pass: one new unit test for working_tree_diff_stats_with_untracked (verifies untracked lines counted, real index byte-identical), plus snapshot updates for nine --full / statusline tests where untracked files now contribute to HEAD±.

…d statusline

`wt list --full` and `wt statusline` now count untracked-file lines in the
`HEAD±` working-diff segment, matching what `wt step diff` shows. Default
`wt list` and the picker stay on the cheap `git diff --shortstat HEAD`
path (tracked-only) — the untracked-inclusive variant joins
`BranchDiff` / `CiStatus` / `SummaryGenerate` in the same "expensive
bucket" the `--full` flag opens up, so the explanation is "`--full`
includes untracked too" with no new exception.

A new `WorkingTree::temp_index()` returning a `TempIndex` helper
consolidates the index-copy-and-stage trick previously open-coded in
`wt step diff`, `WorkingTreeConflictsTask`, and the new
`working_tree_diff_stats_with_untracked` method. `TempIndex::git()`
returns a `Cmd` already wired with `current_dir`, log context, and
`GIT_INDEX_FILE` — three call sites collapse to a few lines each, and
the real index is never mutated.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All six modified snapshots now embed a hardcoded macOS path:

LLVM_PROFILE_FILE: /var/folders/v3/8k5q0_6j3_q6gl4h8czr66sh0000gn/T/wt-test-profraw/cov-%m_%p.profraw

These tests will fail on Linux/Windows CI runners (where std::env::temp_dir() resolves to e.g. /tmp) and on any other macOS machine. None of the previously-existing --full snapshots have this line — it was introduced by re-accepting these snapshots in a coverage-flavored environment after #2730.

Root cause is in tests/common/mod.rs:1098-1100 — the filter intended to strip these vars only matches quoted YAML scalars:

settings.add_filter(r#"    CARGO_LLVM_COV: "1"\n"#, "");
settings.add_filter(r#"    CARGO_LLVM_COV_TARGET_DIR: "[^"]+"\n"#, "");
settings.add_filter(r#"    LLVM_PROFILE_FILE: "[^"]+"\n"#, "");

serde_yaml emits paths like /var/folders/.../cov-%m_%p.profraw (and /tmp/wt-test-profraw/cov-%m_%p.profraw on Linux) as plain scalars, so the "[^"]+" group never matches and the value leaks into the snapshot. This is a latent bug from #2730 that any first regeneration after that PR would surface.

Suggested fix — relax the filters to match either form, then regenerate the six affected snapshots:

settings.add_filter(r#"    CARGO_LLVM_COV: .+\n"#, "");
settings.add_filter(r#"    CARGO_LLVM_COV_TARGET_DIR: .+\n"#, "");
settings.add_filter(r#"    LLVM_PROFILE_FILE: .+\n"#, "");

Happy to push a fix commit (filter relaxation + regenerated snapshots) if you'd like — say the word.


The core refactor (TempIndex consolidating three call sites, gating the untracked-inclusive path behind working_tree_status.untracked) and the new unit test that checks the real index stays byte-identical look good to me.

Snapshots regenerated in this branch leaked
`LLVM_PROFILE_FILE: /var/folders/.../wt-test-profraw/cov-%m_%p.profraw`
into the env block — `isolate_subprocess_env` (#2730) sets the var on
every test subprocess, and `insta_cmd` records it verbatim with a
platform-specific path. The intended scrub at
`setup_snapshot_settings` was never effective: `add_filter`
substitutes only on captured snapshot content, not the YAML info/env
block where env entries live, so the regex wasn't matching anything.

Switch to `add_redaction(".env.LLVM_PROFILE_FILE", ...)` (and the same
for `CARGO_LLVM_COV*`) inside `add_standard_env_redactions`, which is
already bound by the `repo` rstest fixture for every test that uses
it. Drop the obsolete `add_filter` lines and regenerate the six
affected snapshots — values now read as stable `[LLVM_PROFILE_FILE]`
placeholders matching the convention used for HOME, GIT_CONFIG_GLOBAL,
etc.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

macOS test failure looks unrelated to this PR — test_switch_picker_switch_to_existing_worktree timed out after 30s waiting for 1 visible row but saw 2 (+ target-branch and @ main). The screen shows the picker hadn't applied its filter input yet, which reads as a PTY/timing flake. Linux and Windows both passed, and the PR doesn't touch picker code (it changes WorkingTreeDiffTask for --full/statusline and the snapshot env redactions).

run · tests/integration_tests/switch_picker.rs:528. Leaving the approval in place; happy to investigate further if it recurs.

@max-sixty
max-sixty merged commit 6174f66 into main May 15, 2026
47 of 48 checks passed
@max-sixty
max-sixty deleted the status branch May 15, 2026 20:03
max-sixty added a commit that referenced this pull request May 15, 2026
…#2768)

The `tests/CLAUDE.md` "Snapshot env drift is cosmetic" rule was too
broad. It correctly covers stable values (`""`, `C`, redacted
placeholders) but also waved through host-specific leaks. While
regenerating snapshots in #2764, a macOS `LLVM_PROFILE_FILE` tempdir
path leaked into the env block and the "cosmetic" framing nearly let it
pass review.

This splits the section into two cases: stable values stay
accept-silently; host/temp/PID/timestamp values are leaks that must be
redacted via `add_redaction(".env.VAR", "[VAR]")` in
`add_standard_env_redactions`. It also records the non-obvious gotcha
that `add_filter` never touches the `env:` block (it only substitutes on
captured snapshot content) — the actual fix mechanism applied in #2764.

Docs-only; no code or test changes.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request May 15, 2026
… row count (#2767)

The `expected_rows: Some(1)` gate (added in #2729) waits for skim's row
list to filter down after the test types its query. But skim's matcher
runs on a separate thread, and under heavy parallel macOS load the row
redraw can lag the matcher by more than the 30s timeout — even though
skim's selection cursor and preview pane have already advanced to the
matched item. The gate then panics with `saw 2`, while the test would
have selected the right item anyway: Enter acts on the cursor, not on
which rows happen to be painted. This is the flake reported on
`test_switch_picker_no_cd_prints_branch_without_switching` (local) and
`test_switch_picker_switch_to_existing_worktree` (CI on #2764).

These three `target`-selection tests don't snapshot the list panel, so
they don't need the filter applied — only the cursor on the right item.
They now gate on the preview-pane text that's emitted once skim's
selection moves to target-branch, which tracks the cursor rather than
the lagging redraw. If selection genuinely never moves, the content gate
still fails loudly, so the diagnostic value of #2729 is preserved.

Reproduced the original flake at ~2/5 with 5 parallel `cargo test
test_switch_picker -- --test-threads=20`. After the fix: 0 occurrences
of the line-528 panic across 48-run focused stress, the original 5×20
recipe, and a 16× pathological run. The `preview_panel_*` snapshot tests
share the same matcher-lag root cause but genuinely need the filter
applied (they snapshot the list); they weren't in scope here and remain
as follow-up.

Also deletes `test_switch_picker_no_cd_suppresses_directive` — a strict
subset of `test_switch_picker_no_cd_prints_branch_without_switching`
(identical setup/env/inputs, both assert exit 0 + empty cd file; the
latter additionally asserts the printed branch name). Same belief, no
coverage lost. Net diff is a reduction.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

2 participants