Skip to content

Commit cd16a68

Browse files
branchseerclaude
andcommitted
feat: add touch-file tool and E2E test for single O_RDWR open detection
Add a `touch-file` tool that opens a file with O_RDWR in a single syscall (unlike replace-file-content which uses separate read/write opens). This tests that fspy correctly detects a single O_RDWR open as both READ and WRITE for the input-modified cache skip. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1b163ee commit cd16a68

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@test/touch-pkg",
3+
"scripts": {
4+
"task": "touch-file src/data.txt"
5+
}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
original

crates/vite_task_bin/tests/e2e_snapshots/fixtures/input-read-write-not-cached/snapshots.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ steps = ["vt run -r task", "vt run -r task"]
1717
name = "verbose read-write task shows path in full summary"
1818
cwd = "packages/rw-pkg"
1919
steps = ["vt run -v task"]
20+
21+
# Single O_RDWR open (touch-file) is also detected as read-write overlap
22+
[[e2e]]
23+
name = "single O_RDWR open is not cached"
24+
cwd = "packages/touch-pkg"
25+
steps = ["vt run task", "vt run task"]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/input-read-write-not-cached/snapshots/multi task with read-write shows not cached in summary.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ expression: e2e_outputs
66
~/packages/normal-pkg$ print hello
77
hello
88

9+
~/packages/touch-pkg$ touch-file src/data.txt
10+
911
~/packages/rw-pkg$ replace-file-content src/data.txt original modified
1012

1113
---
12-
vt run: 0/2 cache hit (0%). @test/rw-pkg#task not cached because it modified its input. (Run `vt run --last-details` for full details)
14+
vt run: 0/3 cache hit (0%). @test/touch-pkg#task (and 1 more) not cached because they modified their inputs. (Run `vt run --last-details` for full details)
1315
> vt run -r task
1416
~/packages/normal-pkg$ print hellocache hit, replaying
1517
hello
1618

19+
~/packages/touch-pkg$ touch-file src/data.txt
20+
1721
~/packages/rw-pkg$ replace-file-content src/data.txt original modified
1822

1923
---
20-
vt run: 1/2 cache hit (50%), <duration> saved. @test/rw-pkg#task not cached because it modified its input. (Run `vt run --last-details` for full details)
24+
vt run: 1/3 cache hit (33%), <duration> saved. @test/touch-pkg#task (and 1 more) not cached because they modified their inputs. (Run `vt run --last-details` for full details)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
info:
5+
cwd: packages/touch-pkg
6+
---
7+
> vt run task
8+
~/packages/touch-pkg$ touch-file src/data.txt
9+
10+
---
11+
vt run: @test/touch-pkg#task not cached because it modified its input. (Run `vt run --last-details` for full details)
12+
> vt run task
13+
~/packages/touch-pkg$ touch-file src/data.txt
14+
15+
---
16+
vt run: @test/touch-pkg#task not cached because it modified its input. (Run `vt run --last-details` for full details)

packages/tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"print-env": "./src/print-env.js",
99
"print-file": "./src/print-file.ts",
1010
"read-stdin": "./src/read-stdin.js",
11-
"replace-file-content": "./src/replace-file-content.ts"
11+
"replace-file-content": "./src/replace-file-content.ts",
12+
"touch-file": "./src/touch-file.ts"
1213
},
1314
"type": "module",
1415
"dependencies": {

packages/tools/src/touch-file.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
3+
// Opens a file once in read-write mode (O_RDWR) without modifying content.
4+
// Used to test that fspy detects a single O_RDWR open as both READ and WRITE.
5+
6+
import { openSync, closeSync, constants } from 'node:fs';
7+
8+
const filename = process.argv[2];
9+
if (!filename) {
10+
console.error('Usage: touch-file <filename>');
11+
process.exit(1);
12+
}
13+
14+
const fd = openSync(filename, constants.O_RDWR);
15+
closeSync(fd);

0 commit comments

Comments
 (0)