Skip to content

Commit 1d36bfb

Browse files
wan9chiclaude
andcommitted
test(e2e): add IPC client e2e tests for every method
New fixture `ipc_client_test` exercises each IPC method through the JS wrapper (@voidzero-dev/vite-task-client) inside a real cached task: - ignoreInput → the ignored dir can mutate without invalidating cache - ignoreOutput → read-write overlap under an ignored dir still caches - disableCache → forces re-execution on next run - fetchEnv(tracked: true) → env change invalidates cache; same value hits The e2e harness now copies packages/vite-task-client into each staging node_modules so fixtures can `import { ... } from "@voidzero-dev/vite-task-client"` without pnpm install. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2e6028c commit 1d36bfb

12 files changed

Lines changed: 247 additions & 0 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "ipc-client-test",
3+
"private": true,
4+
"type": "module"
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { disableCache } from "@voidzero-dev/vite-task-client";
2+
import { writeFileSync, mkdirSync } from "node:fs";
3+
4+
// Produce an output, then ask the runner not to cache this execution — the
5+
// next `vt run` should re-execute the task.
6+
mkdirSync("dist", { recursive: true });
7+
writeFileSync("dist/out.txt", "ok\n");
8+
disableCache();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { fetchEnv } from "@voidzero-dev/vite-task-client";
2+
import { writeFileSync, mkdirSync } from "node:fs";
3+
4+
// fetchEnv populates process.env from the runner and — with tracked: true —
5+
// adds the env to the post-run fingerprint, so a change between runs
6+
// invalidates the cache.
7+
fetchEnv("PROBE_ENV", { tracked: true });
8+
const value = process.env.PROBE_ENV ?? "(unset)";
9+
10+
mkdirSync("dist", { recursive: true });
11+
writeFileSync("dist/out.txt", "PROBE_ENV=" + value + "\n");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ignoreInput } from "@voidzero-dev/vite-task-client";
2+
import { writeFileSync, readFileSync } from "node:fs";
3+
import { mkdirSync } from "node:fs";
4+
5+
// The task reads from `cache_like/` (which we want the runner to IGNORE as
6+
// an input), and writes to `dist/`. Without the ignore, the auto-input
7+
// fingerprint would fluctuate with cache_like/ contents even though they're
8+
// not semantic inputs.
9+
mkdirSync("cache_like", { recursive: true });
10+
writeFileSync("cache_like/stale.txt", "stale-" + Date.now() + "\n");
11+
ignoreInput("cache_like");
12+
readFileSync("cache_like/stale.txt", "utf8");
13+
14+
mkdirSync("dist", { recursive: true });
15+
writeFileSync("dist/out.txt", "ok\n");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ignoreOutput } from "@voidzero-dev/vite-task-client";
2+
import { writeFileSync, readFileSync, mkdirSync } from "node:fs";
3+
4+
// The task both reads and writes `sidecar/tmp.txt`. If the runner didn't
5+
// treat `sidecar/` as an ignored output, the read-write overlap check would
6+
// refuse to cache the task. `dist/out.txt` is the real output.
7+
mkdirSync("sidecar", { recursive: true });
8+
writeFileSync("sidecar/tmp.txt", "initial\n");
9+
readFileSync("sidecar/tmp.txt", "utf8");
10+
writeFileSync("sidecar/tmp.txt", "final\n");
11+
ignoreOutput("sidecar");
12+
13+
mkdirSync("dist", { recursive: true });
14+
writeFileSync("dist/out.txt", "ok\n");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# E2E tests for @voidzero-dev/vite-task-client. Each case exercises one IPC
2+
# method by running a Node script inside a real cached task and observing the
3+
# runner's cache behaviour.
4+
5+
# ignoreInput: the runner treats cache_like/ as non-input, so mutations to it
6+
# between runs do not invalidate the cache.
7+
[[e2e]]
8+
name = "ignore_input_keeps_cache_valid"
9+
ignore = true
10+
steps = [
11+
# First run populates the cache.
12+
["vt", "run", "ignore-input"],
13+
# Mutate the ignored directory between runs; this would invalidate the cache
14+
# if the runner had tracked it as an input.
15+
["vtt", "write-file", "cache_like/other.txt", "after"],
16+
# Second run must still be a cache hit.
17+
{ argv = ["vt", "run", "ignore-input"], comment = "cache hit: cache_like/ was ignored via ignoreInput" },
18+
]
19+
20+
# ignoreOutput: the task reads and writes sidecar/tmp.txt. If the runner
21+
# didn't honour ignoreOutput, the read-write overlap check would refuse to
22+
# cache the run ("read and wrote 'sidecar/tmp.txt'").
23+
[[e2e]]
24+
name = "ignore_output_allows_read_write_overlap"
25+
ignore = true
26+
steps = [
27+
["vt", "run", "ignore-output"],
28+
["vtt", "rm", "dist/out.txt"],
29+
# Cache hit proves ignoreOutput suppressed the overlap error.
30+
{ argv = ["vt", "run", "ignore-output"], comment = "cache hit: sidecar/ writes were ignored" },
31+
["vtt", "print-file", "dist/out.txt"],
32+
]
33+
34+
# disableCache: the tool asks the runner not to cache this run, so the next
35+
# invocation re-executes.
36+
[[e2e]]
37+
name = "disable_cache_forces_reexecution"
38+
ignore = true
39+
steps = [
40+
["vt", "run", "disable-cache"],
41+
# Second run is a cache miss (NotFound) because nothing was cached.
42+
{ argv = ["vt", "run", "disable-cache"], comment = "cache miss: tool called disableCache" },
43+
]
44+
45+
# fetchEnv (tracked: true) — the env value becomes part of the post-run
46+
# fingerprint. Same value → cache hit; different value → cache miss.
47+
[[e2e]]
48+
name = "fetch_env_tracked_invalidates_on_change"
49+
ignore = true
50+
steps = [
51+
{ argv = ["vt", "run", "fetch-env"], envs = [["PROBE_ENV", "first"]] },
52+
# Same value → cache hit.
53+
{ argv = ["vt", "run", "fetch-env"], envs = [["PROBE_ENV", "first"]], comment = "cache hit: PROBE_ENV unchanged" },
54+
# Different value → cache miss (tracked env changed).
55+
{ argv = ["vt", "run", "fetch-env"], envs = [["PROBE_ENV", "second"]], comment = "cache miss: tracked env changed" },
56+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# disable_cache_forces_reexecution
2+
3+
## `vt run disable-cache`
4+
5+
```
6+
$ node scripts/disable_cache.mjs
7+
```
8+
9+
## `vt run disable-cache`
10+
11+
cache miss: tool called disableCache
12+
13+
```
14+
$ node scripts/disable_cache.mjs
15+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# fetch_env_tracked_invalidates_on_change
2+
3+
## `PROBE_ENV=first vt run fetch-env`
4+
5+
```
6+
$ node scripts/fetch_env.mjs
7+
```
8+
9+
## `PROBE_ENV=first vt run fetch-env`
10+
11+
cache hit: PROBE_ENV unchanged
12+
13+
```
14+
$ node scripts/fetch_env.mjs ◉ cache hit, replaying
15+
16+
---
17+
vt run: cache hit.
18+
```
19+
20+
## `PROBE_ENV=second vt run fetch-env`
21+
22+
cache miss: tracked env changed
23+
24+
```
25+
$ node scripts/fetch_env.mjs ○ cache miss: tracked env 'PROBE_ENV' changed, executing
26+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ignore_input_keeps_cache_valid
2+
3+
## `vt run ignore-input`
4+
5+
```
6+
$ node scripts/ignore_input.mjs
7+
```
8+
9+
## `vtt write-file cache_like/other.txt after`
10+
11+
```
12+
```
13+
14+
## `vt run ignore-input`
15+
16+
cache hit: cache_like/ was ignored via ignoreInput
17+
18+
```
19+
$ node scripts/ignore_input.mjs ◉ cache hit, replaying
20+
21+
---
22+
vt run: cache hit.
23+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ignore_output_allows_read_write_overlap
2+
3+
## `vt run ignore-output`
4+
5+
```
6+
$ node scripts/ignore_output.mjs
7+
```
8+
9+
## `vtt rm dist/out.txt`
10+
11+
```
12+
```
13+
14+
## `vt run ignore-output`
15+
16+
cache hit: sidecar/ writes were ignored
17+
18+
```
19+
$ node scripts/ignore_output.mjs ◉ cache hit, replaying
20+
21+
---
22+
vt run: cache hit.
23+
```
24+
25+
## `vtt print-file dist/out.txt`
26+
27+
```
28+
ok
29+
```

0 commit comments

Comments
 (0)