Skip to content

Commit 56e1175

Browse files
branchseerclaude
andcommitted
test: add plan cases for extra_arg and cd interaction with skip/prune rules
- Extra args don't affect skip/prune (they're in PlanOptions, not TaskQuery) - `cd` before `vp run` changes the cwd, producing a different ContainingPackage query, so the skip rule correctly does not fire Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent aa59d25 commit 56e1175

15 files changed

Lines changed: 191 additions & 106 deletions

File tree

crates/vite_task_plan/src/plan.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ async fn plan_task_as_execution_node(
203203
// Skip rule: skip if this nested query is the same as the parent expansion.
204204
// This handles workspace root tasks like `"build": "vp run -r build"` —
205205
// re-entering the same query would just re-expand the same tasks.
206+
//
207+
// The comparison is on TaskQuery only (package_query + task_name +
208+
// include_explicit_deps). Extra args live in PlanOptions, so
209+
// `vp run -r build extra_arg` still matches `vp run -r build`.
210+
// Conversely, `cd packages/a && vp run build` does NOT match a
211+
// parent `vp run build` from root because `cd` changes the cwd,
212+
// producing a different ContainingPackage in the PackageQuery.
206213
if query_plan_request.query == *context.parent_query() {
207214
continue;
208215
}
@@ -569,8 +576,11 @@ fn plan_spawn_execution(
569576
/// **Prune rule:** If the expanding task (the task whose command triggered
570577
/// this nested query) appears in the expansion result, it is pruned from the graph
571578
/// and its predecessors are wired directly to its successors. This prevents
572-
/// workspace root tasks like `"build": "vp run build"` from infinitely re-expanding
573-
/// themselves when a different query reaches them.
579+
/// workspace root tasks like `"build": "vp run -r build"` from infinitely
580+
/// re-expanding themselves when a different query reaches them (e.g.,
581+
/// `vp run build` produces a different query than the script's `vp run -r build`,
582+
/// so the skip rule doesn't fire, but the prune rule catches root in the result).
583+
/// Like the skip rule, extra args don't affect this — only the TaskQuery matters.
574584
#[expect(clippy::future_not_send, reason = "PlanContext contains !Send dyn PlanRequestParser")]
575585
pub async fn plan_query_request(
576586
query: Arc<TaskQuery>,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "test-workspace",
3+
"private": true,
4+
"scripts": {
5+
"deploy": "cd packages/a && vp run deploy"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@test/a",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"deploy": "echo deploying-a"
6+
}
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
- 'packages/*'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Tests that `cd` before `vp run` prevents the skip rule from firing.
2+
# Root deploy = `cd packages/a && vp run deploy`.
3+
#
4+
# The skip rule compares TaskQuery, which includes ContainingPackage(cwd).
5+
# After `cd packages/a`, the cwd changes, so the nested query resolves to
6+
# ContainingPackage(packages/a) — different from the parent's
7+
# ContainingPackage(root). The queries don't match and the skip rule
8+
# does NOT fire, allowing the nested expansion to proceed normally.
9+
10+
[[plan]]
11+
name = "cd changes cwd so skip rule does not fire"
12+
args = ["run", "deploy"]
13+
compact = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
3+
expression: "&compact_plan"
4+
info:
5+
args:
6+
- run
7+
- deploy
8+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-cd-no-skip
9+
---
10+
{
11+
"#deploy": {
12+
"items": [
13+
{
14+
"packages/a#deploy": []
15+
}
16+
],
17+
"neighbors": []
18+
}
19+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
3+
expression: task_graph_json
4+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-cd-no-skip
5+
---
6+
[
7+
{
8+
"key": [
9+
"<workspace>/",
10+
"deploy"
11+
],
12+
"node": {
13+
"task_display": {
14+
"package_name": "test-workspace",
15+
"task_name": "deploy",
16+
"package_path": "<workspace>/"
17+
},
18+
"resolved_config": {
19+
"command": "cd packages/a && vp run deploy",
20+
"resolved_options": {
21+
"cwd": "<workspace>/",
22+
"cache_config": null
23+
}
24+
}
25+
},
26+
"neighbors": []
27+
},
28+
{
29+
"key": [
30+
"<workspace>/packages/a",
31+
"deploy"
32+
],
33+
"node": {
34+
"task_display": {
35+
"package_name": "@test/a",
36+
"task_name": "deploy",
37+
"package_path": "<workspace>/packages/a"
38+
},
39+
"resolved_config": {
40+
"command": "echo deploying-a",
41+
"resolved_options": {
42+
"cwd": "<workspace>/packages/a",
43+
"cache_config": null
44+
}
45+
}
46+
},
47+
"neighbors": []
48+
}
49+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cacheScripts": true
3+
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-depends-on-passthrough/snapshots/task graph.snap

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
5252
"command": "echo linting",
5353
"resolved_options": {
5454
"cwd": "<workspace>/",
55-
"cache_config": {
56-
"env_config": {
57-
"fingerprinted_envs": [],
58-
"pass_through_envs": [
59-
"<default pass-through envs>"
60-
]
61-
}
62-
}
55+
"cache_config": null
6356
}
6457
}
6558
},
@@ -80,14 +73,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
8073
"command": "echo building-a",
8174
"resolved_options": {
8275
"cwd": "<workspace>/packages/a",
83-
"cache_config": {
84-
"env_config": {
85-
"fingerprinted_envs": [],
86-
"pass_through_envs": [
87-
"<default pass-through envs>"
88-
]
89-
}
90-
}
76+
"cache_config": null
9177
}
9278
}
9379
},
@@ -108,14 +94,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
10894
"command": "echo linting-a",
10995
"resolved_options": {
11096
"cwd": "<workspace>/packages/a",
111-
"cache_config": {
112-
"env_config": {
113-
"fingerprinted_envs": [],
114-
"pass_through_envs": [
115-
"<default pass-through envs>"
116-
]
117-
}
118-
}
97+
"cache_config": null
11998
}
12099
}
121100
},

crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-multi-command/snapshots/task graph.snap

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
1919
"command": "echo pre && vp run -r build",
2020
"resolved_options": {
2121
"cwd": "<workspace>/",
22-
"cache_config": {
23-
"env_config": {
24-
"fingerprinted_envs": [],
25-
"pass_through_envs": [
26-
"<default pass-through envs>"
27-
]
28-
}
29-
}
22+
"cache_config": null
3023
}
3124
}
3225
},
@@ -47,14 +40,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
4740
"command": "echo building-a",
4841
"resolved_options": {
4942
"cwd": "<workspace>/packages/a",
50-
"cache_config": {
51-
"env_config": {
52-
"fingerprinted_envs": [],
53-
"pass_through_envs": [
54-
"<default pass-through envs>"
55-
]
56-
}
57-
}
43+
"cache_config": null
5844
}
5945
}
6046
},

0 commit comments

Comments
 (0)