Skip to content

Commit a64f39c

Browse files
branchseerclaude
andcommitted
feat: reject unknown fields in vite-task.json
Add `deny_unknown_fields` to `UserRunConfig` so typos and removed fields (like `cacheScripts`) produce a clear error at load time. Task-level unknown fields were already rejected via the flatten chain to `UserCacheConfig`. Also fix 5 test fixtures still using the old `cacheScripts` field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7029286 commit a64f39c

File tree

12 files changed

+162
-36
lines changed

12 files changed

+162
-36
lines changed

crates/vite_task_graph/src/config/user.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl ResolvedGlobalCacheConfig {
177177
#[derive(Debug, Default, Deserialize)]
178178
// TS derive macro generates code using std types that clippy disallows; skip derive during linting
179179
#[cfg_attr(all(test, not(clippy)), derive(TS), ts(optional_fields, rename = "RunConfig"))]
180-
#[serde(rename_all = "camelCase")]
180+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
181181
pub struct UserRunConfig {
182182
/// Root-level cache configuration.
183183
///
@@ -454,4 +454,17 @@ mod tests {
454454
serde_json::from_value::<UserGlobalCacheConfig>(json!({ "unknown": true })).is_err()
455455
);
456456
}
457+
458+
#[test]
459+
fn test_run_config_unknown_top_level_field() {
460+
assert!(serde_json::from_value::<UserRunConfig>(json!({ "unknown": true })).is_err());
461+
}
462+
463+
#[test]
464+
fn test_task_config_unknown_field() {
465+
assert!(
466+
serde_json::from_value::<UserTaskConfig>(json!({ "command": "echo", "unknown": true }))
467+
.is_err()
468+
);
469+
}
457470
}

crates/vite_task_plan/src/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ fn plan_spawn_execution(
580580
/// re-expanding themselves when a different query reaches them (e.g.,
581581
/// `vp run build` produces a different query than the script's `vp run -r build`,
582582
/// 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.
583+
/// Like the skip rule, extra args don't affect this — only the `TaskQuery` matters.
584584
#[expect(clippy::future_not_send, reason = "PlanContext contains !Send dyn PlanRequestParser")]
585585
pub async fn plan_query_request(
586586
query: Arc<TaskQuery>,

crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-cd-no-skip/snapshots/task graph.snap

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-c
1919
"command": "cd packages/a && vp run deploy",
2020
"resolved_options": {
2121
"cwd": "<workspace>/",
22-
"cache_config": null
22+
"cache_config": {
23+
"env_config": {
24+
"fingerprinted_envs": [],
25+
"pass_through_envs": [
26+
"<default pass-through envs>"
27+
]
28+
}
29+
}
2330
}
24-
}
31+
},
32+
"source": "PackageJsonScript"
2533
},
2634
"neighbors": []
2735
},
@@ -40,9 +48,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-c
4048
"command": "echo deploying-a",
4149
"resolved_options": {
4250
"cwd": "<workspace>/packages/a",
43-
"cache_config": null
51+
"cache_config": {
52+
"env_config": {
53+
"fingerprinted_envs": [],
54+
"pass_through_envs": [
55+
"<default pass-through envs>"
56+
]
57+
}
58+
}
4459
}
45-
}
60+
},
61+
"source": "PackageJsonScript"
4662
},
4763
"neighbors": []
4864
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cacheScripts": true
2+
"cache": true
33
}

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
2828
}
2929
}
3030
}
31-
}
31+
},
32+
"source": "TaskConfig"
3233
},
3334
"neighbors": [
3435
[
@@ -52,9 +53,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
5253
"command": "echo linting",
5354
"resolved_options": {
5455
"cwd": "<workspace>/",
55-
"cache_config": null
56+
"cache_config": {
57+
"env_config": {
58+
"fingerprinted_envs": [],
59+
"pass_through_envs": [
60+
"<default pass-through envs>"
61+
]
62+
}
63+
}
5664
}
57-
}
65+
},
66+
"source": "PackageJsonScript"
5867
},
5968
"neighbors": []
6069
},
@@ -73,9 +82,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
7382
"command": "echo building-a",
7483
"resolved_options": {
7584
"cwd": "<workspace>/packages/a",
76-
"cache_config": null
85+
"cache_config": {
86+
"env_config": {
87+
"fingerprinted_envs": [],
88+
"pass_through_envs": [
89+
"<default pass-through envs>"
90+
]
91+
}
92+
}
7793
}
78-
}
94+
},
95+
"source": "PackageJsonScript"
7996
},
8097
"neighbors": []
8198
},
@@ -94,9 +111,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-d
94111
"command": "echo linting-a",
95112
"resolved_options": {
96113
"cwd": "<workspace>/packages/a",
97-
"cache_config": null
114+
"cache_config": {
115+
"env_config": {
116+
"fingerprinted_envs": [],
117+
"pass_through_envs": [
118+
"<default pass-through envs>"
119+
]
120+
}
121+
}
98122
}
99-
}
123+
},
124+
"source": "PackageJsonScript"
100125
},
101126
"neighbors": []
102127
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-depends-on-passthrough/vite-task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"cacheScripts": true,
2+
"cache": true,
33
"tasks": {
44
"build": {
55
"dependsOn": ["lint"]

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ 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": null
22+
"cache_config": {
23+
"env_config": {
24+
"fingerprinted_envs": [],
25+
"pass_through_envs": [
26+
"<default pass-through envs>"
27+
]
28+
}
29+
}
2330
}
24-
}
31+
},
32+
"source": "PackageJsonScript"
2533
},
2634
"neighbors": []
2735
},
@@ -40,9 +48,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
4048
"command": "echo building-a",
4149
"resolved_options": {
4250
"cwd": "<workspace>/packages/a",
43-
"cache_config": null
51+
"cache_config": {
52+
"env_config": {
53+
"fingerprinted_envs": [],
54+
"pass_through_envs": [
55+
"<default pass-through envs>"
56+
]
57+
}
58+
}
4459
}
45-
}
60+
},
61+
"source": "PackageJsonScript"
4662
},
4763
"neighbors": []
4864
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cacheScripts": true
2+
"cache": true
33
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-mutual-recursion/snapshots/task graph.snap

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
1919
"command": "vp run -r test",
2020
"resolved_options": {
2121
"cwd": "<workspace>/",
22-
"cache_config": null
22+
"cache_config": {
23+
"env_config": {
24+
"fingerprinted_envs": [],
25+
"pass_through_envs": [
26+
"<default pass-through envs>"
27+
]
28+
}
29+
}
2330
}
24-
}
31+
},
32+
"source": "PackageJsonScript"
2533
},
2634
"neighbors": []
2735
},
@@ -40,9 +48,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
4048
"command": "vp run -r build",
4149
"resolved_options": {
4250
"cwd": "<workspace>/",
43-
"cache_config": null
51+
"cache_config": {
52+
"env_config": {
53+
"fingerprinted_envs": [],
54+
"pass_through_envs": [
55+
"<default pass-through envs>"
56+
]
57+
}
58+
}
4459
}
45-
}
60+
},
61+
"source": "PackageJsonScript"
4662
},
4763
"neighbors": []
4864
},
@@ -61,9 +77,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
6177
"command": "echo building-a",
6278
"resolved_options": {
6379
"cwd": "<workspace>/packages/a",
64-
"cache_config": null
80+
"cache_config": {
81+
"env_config": {
82+
"fingerprinted_envs": [],
83+
"pass_through_envs": [
84+
"<default pass-through envs>"
85+
]
86+
}
87+
}
6588
}
66-
}
89+
},
90+
"source": "PackageJsonScript"
6791
},
6892
"neighbors": []
6993
},
@@ -82,9 +106,17 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/workspace-root-m
82106
"command": "echo testing-a",
83107
"resolved_options": {
84108
"cwd": "<workspace>/packages/a",
85-
"cache_config": null
109+
"cache_config": {
110+
"env_config": {
111+
"fingerprinted_envs": [],
112+
"pass_through_envs": [
113+
"<default pass-through envs>"
114+
]
115+
}
116+
}
86117
}
87-
}
118+
},
119+
"source": "PackageJsonScript"
88120
},
89121
"neighbors": []
90122
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cacheScripts": true
2+
"cache": true
33
}

0 commit comments

Comments
 (0)