Skip to content

Commit 20bf309

Browse files
branchseerclaude
andcommitted
fix(test): avoid separate mkdir cache entries in output-cache-test
On Windows, `&&`-chained commands become separate cache entries. The `vtt mkdir -p dist` sub-command's fspy-inferred input is the `dist` directory itself — when the test deletes `dist`, the next run detects `dist` was removed and reports a cache miss for that sub-command. Fix by making `vtt write-file` create parent directories automatically, then removing the `mkdir` commands from test fixtures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79f428a commit 20bf309

File tree

7 files changed

+20
-40
lines changed

7 files changed

+20
-40
lines changed

crates/vite_task_bin/src/vtt/write_file.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ pub fn run(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
22
if args.len() < 2 {
33
return Err("Usage: vtt write-file <filename> <content>".into());
44
}
5-
std::fs::write(&args[0], &args[1])?;
5+
let path = std::path::Path::new(&args[0]);
6+
if let Some(parent) = path.parent() {
7+
std::fs::create_dir_all(parent)?;
8+
}
9+
std::fs::write(path, &args[1])?;
610
Ok(())
711
}

crates/vite_task_bin/tests/e2e_snapshots/fixtures/output-cache-test/snapshots/auto output - files restored on cache hit.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,24 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run auto-output
6-
$ vtt mkdir -p dist
7-
86
$ vtt write-file dist/out.txt built
97

108
$ vtt print done
119
done
1210

1311
---
14-
vt run: 0/3 cache hit (0%). (Run `vt run --last-details` for full details)
12+
vt run: 0/2 cache hit (0%). (Run `vt run --last-details` for full details)
1513
> vtt print-file dist/out.txt
1614
built
1715
> vtt rm -rf dist
1816

1917
> vt run auto-output
20-
$ vtt mkdir -p distcache hit, replaying
21-
2218
$ vtt write-file dist/out.txt builtcache hit, replaying
2319

2420
$ vtt print donecache hit, replaying
2521
done
2622

2723
---
28-
vt run: 3/3 cache hit (100%). (Run `vt run --last-details` for full details)
24+
vt run: 2/2 cache hit (100%). (Run `vt run --last-details` for full details)
2925
> vtt print-file dist/out.txt
3026
built

crates/vite_task_bin/tests/e2e_snapshots/fixtures/output-cache-test/snapshots/auto output with non-auto input.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run auto-output-no-auto-input
6-
$ vtt mkdir -p dist
7-
86
$ vtt write-file dist/out.txt built
97

108
$ vtt print done
119
done
1210

1311
---
14-
vt run: 0/3 cache hit (0%). (Run `vt run --last-details` for full details)
12+
vt run: 0/2 cache hit (0%). (Run `vt run --last-details` for full details)
1513
> vtt rm -rf dist
1614

1715
> vt run auto-output-no-auto-input
18-
$ vtt mkdir -p distcache hit, replaying
19-
2016
$ vtt write-file dist/out.txt builtcache hit, replaying
2117

2218
$ vtt print donecache hit, replaying
2319
done
2420

2521
---
26-
vt run: 3/3 cache hit (100%). (Run `vt run --last-details` for full details)
22+
vt run: 2/2 cache hit (100%). (Run `vt run --last-details` for full details)
2723
> vtt print-file dist/out.txt
2824
built

crates/vite_task_bin/tests/e2e_snapshots/fixtures/output-cache-test/snapshots/glob output - only matched files restored.snap

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,29 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run glob-output
6-
$ vtt mkdir -p dist
7-
86
$ vtt write-file dist/out.txt built
97

10-
$ vtt mkdir -p tmp
11-
128
$ vtt write-file tmp/temp.txt temp
139

1410
$ vtt print done
1511
done
1612

1713
---
18-
vt run: 0/5 cache hit (0%). (Run `vt run --last-details` for full details)
14+
vt run: 0/3 cache hit (0%). (Run `vt run --last-details` for full details)
1915
> vtt rm -rf dist
2016

2117
> vtt rm -rf tmp
2218

2319
> vt run glob-output
24-
$ vtt mkdir -p distcache hit, replaying
25-
2620
$ vtt write-file dist/out.txt builtcache hit, replaying
2721

28-
$ vtt mkdir -p tmpcache hit, replaying
29-
3022
$ vtt write-file tmp/temp.txt tempcache hit, replaying
3123

3224
$ vtt print donecache hit, replaying
3325
done
3426

3527
---
36-
vt run: 5/5 cache hit (100%). (Run `vt run --last-details` for full details)
28+
vt run: 3/3 cache hit (100%). (Run `vt run --last-details` for full details)
3729
> vtt print-file dist/out.txt
3830
built
3931
> vtt print-file tmp/temp.txt # should fail - tmp not in output globs

crates/vite_task_bin/tests/e2e_snapshots/fixtures/output-cache-test/snapshots/negative output - excluded files not restored.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run negative-output
6-
$ vtt mkdir -p dist/cache
7-
86
$ vtt write-file dist/out.txt built
97

108
$ vtt write-file dist/cache/tmp.txt temp
@@ -13,12 +11,10 @@ $ vtt print done
1311
done
1412

1513
---
16-
vt run: 0/4 cache hit (0%). (Run `vt run --last-details` for full details)
14+
vt run: 0/3 cache hit (0%). (Run `vt run --last-details` for full details)
1715
> vtt rm -rf dist
1816

1917
> vt run negative-output
20-
$ vtt mkdir -p dist/cachecache hit, replaying
21-
2218
$ vtt write-file dist/out.txt builtcache hit, replaying
2319

2420
$ vtt write-file dist/cache/tmp.txt tempcache hit, replaying
@@ -27,7 +23,7 @@ $ vtt print done ◉ cache hit, replaying
2723
done
2824

2925
---
30-
vt run: 4/4 cache hit (100%). (Run `vt run --last-details` for full details)
26+
vt run: 3/3 cache hit (100%). (Run `vt run --last-details` for full details)
3127
> vtt print-file dist/out.txt
3228
built
3329
> vtt print-file dist/cache/tmp.txt # should fail - excluded by negative glob

crates/vite_task_bin/tests/e2e_snapshots/fixtures/output-cache-test/snapshots/output config change invalidates cache.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
55
> vt run output-config-change
6-
$ vtt mkdir -p dist
7-
86
$ vtt write-file dist/out.txt built
97

108
$ vtt print done
119
done
1210

1311
---
14-
vt run: 0/3 cache hit (0%). (Run `vt run --last-details` for full details)
12+
vt run: 0/2 cache hit (0%). (Run `vt run --last-details` for full details)
1513
> vtt replace-file-content vite-task.json REPLACE_ME dist/**
1614
1715
> vt run output-config-change # cache miss: output config changed
18-
$ vtt mkdir -p dist ○ cache miss: output configuration changed, executing
19-
2016
$ vtt write-file dist/out.txt built ○ cache miss: output configuration changed, executing
2117
2218
$ vtt print done ○ cache miss: output configuration changed, executing
2319
done
2420
2521
---
26-
vt run: 0/3 cache hit (0%). (Run `vt run --last-details` for full details)
22+
vt run: 0/2 cache hit (0%). (Run `vt run --last-details` for full details)

crates/vite_task_bin/tests/e2e_snapshots/fixtures/output-cache-test/vite-task.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"tasks": {
33
"auto-output": {
4-
"command": "vtt mkdir -p dist && vtt write-file dist/out.txt built && vtt print done",
4+
"command": "vtt write-file dist/out.txt built && vtt print done",
55
"cache": true
66
},
77
"glob-output": {
8-
"command": "vtt mkdir -p dist && vtt write-file dist/out.txt built && vtt mkdir -p tmp && vtt write-file tmp/temp.txt temp && vtt print done",
8+
"command": "vtt write-file dist/out.txt built && vtt write-file tmp/temp.txt temp && vtt print done",
99
"output": ["dist/**"],
1010
"cache": true
1111
},
1212
"auto-output-no-auto-input": {
13-
"command": "vtt mkdir -p dist && vtt write-file dist/out.txt built && vtt print done",
13+
"command": "vtt write-file dist/out.txt built && vtt print done",
1414
"input": ["src/**"],
1515
"cache": true
1616
},
1717
"negative-output": {
18-
"command": "vtt mkdir -p dist/cache && vtt write-file dist/out.txt built && vtt write-file dist/cache/tmp.txt temp && vtt print done",
18+
"command": "vtt write-file dist/out.txt built && vtt write-file dist/cache/tmp.txt temp && vtt print done",
1919
"output": [{ "auto": true }, "!dist/cache/**"],
2020
"cache": true
2121
},
2222
"output-config-change": {
23-
"command": "vtt mkdir -p dist && vtt write-file dist/out.txt built && vtt print done",
23+
"command": "vtt write-file dist/out.txt built && vtt print done",
2424
"output": ["REPLACE_ME"],
2525
"cache": true
2626
}

0 commit comments

Comments
 (0)