diff --git a/CHANGELOG.md b/CHANGELOG.md index d9d39790c..4fc806c77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +- **Fixed** A task that `vp run` starts in another directory, as with `vp run -r`, `vp run pkg#task`, a task's `cwd` option, or a `cd` in its command, now sees `PWD` set to that directory instead of the one `vp run` was called from, so tools that check `PWD` against the working directory, such as workerd, no longer warn ([#1049](https://github.com/voidzero-dev/vite-task/issues/1049), [#1063](https://github.com/voidzero-dev/vite-task/pull/1063)). - **Changed** When automatic file-access tracking cannot record everything a task did, the "Not cached" summary line now includes the specific reason (for example, that the tracking channel ran out of capacity or that installing the seccomp filter failed for a given executable) ([#1054](https://github.com/voidzero-dev/vite-task/pull/1054), [#1056](https://github.com/voidzero-dev/vite-task/pull/1056)). - **Changed** Invalid remote cache endpoint URLs in `cache.remote.url` or `VP_REMOTE_CACHE_URL` (such as missing schemes, non-`http`/`https` schemes, or missing hosts) now fail upfront during configuration and planning instead of warning per task during execution, and `vp run --help` now documents `VP_REMOTE_CACHE`, `VP_REMOTE_CACHE_URL`, and `VP_REMOTE_CACHE_HEADER_` ([#1048](https://github.com/voidzero-dev/vite-task/pull/1048)). - **Changed** Removed `NEXT_*`, `VERCEL`, `VERCEL_*`, `USE_OUTPUT_FOR_EDGE_FUNCTIONS`, `NOW_BUILDER`, `VC_MICROFRONTENDS_CONFIG_FILE_NAME`, `GITHUB_*`, `ACTIONS_ID_TOKEN_REQUEST_URL`, `DOCKER_*`, `BUILDKIT_*`, `COMPOSE_*`, and `*_TOKEN` from the default untracked environment variables passed to cached tasks. Tasks that need any of these variables should declare them explicitly in `cache.env` or `cache.untrackedEnv` ([#1044](https://github.com/voidzero-dev/vite-task/pull/1044)). diff --git a/crates/vt_plan/src/plan.rs b/crates/vt_plan/src/plan.rs index 16abe6a6d..4838b043d 100644 --- a/crates/vt_plan/src/plan.rs +++ b/crates/vt_plan/src/plan.rs @@ -634,6 +634,18 @@ fn plan_spawn_execution( let mut spawn_envs = (**envs).clone(); let cwd = Arc::clone(&resolved_task_options.cwd); + // Keep `PWD` in line with the directory the task runs in, as a shell + // `cd` would. Otherwise a task run from another directory (`-r`, + // `pkg#task`, the `cwd` option, or a `cd` in its command) inherits the + // caller's `PWD`, and tools that check it against the real working + // directory complain. Only an inherited `PWD` is replaced, so none is + // added where the caller had none. Set before `EnvFingerprints::resolve` + // so a task that lists `PWD` in `env` fingerprints the value it sees. A + // prefix assignment (`PWD=… command`) still wins: those are applied last. + if let Some(pwd) = spawn_envs.get_mut(EnvName::from_ref(OsStr::new("PWD"))) { + *pwd = Arc::from(cwd.as_path().as_os_str()); + } + let mut resolved_cache_metadata = None; if let Some(cache_config) = &resolved_task_options.cache_config { // Resolve envs according cache configs diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/package.json b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/package.json new file mode 100644 index 000000000..be7b6dc3e --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/package.json @@ -0,0 +1,4 @@ +{ + "name": "pwd-follows-task-cwd", + "private": true +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/packages/a/package.json b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/packages/a/package.json new file mode 100644 index 000000000..44d21f1fa --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/packages/a/package.json @@ -0,0 +1,3 @@ +{ + "name": "a" +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/packages/a/vite-task.json b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/packages/a/vite-task.json new file mode 100644 index 000000000..1473912f4 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/packages/a/vite-task.json @@ -0,0 +1,21 @@ +{ + "tasks": { + "where": { + "command": "vtt print-env PWD" + }, + "where-sub": { + "command": "vtt print-env PWD", + "cwd": "sub" + }, + "where-cd": { + "command": "cd sub && vtt print-env PWD" + }, + "where-uncached": { + "command": "vtt print-env PWD", + "cache": false + }, + "where-prefix": { + "command": "PWD=/custom vtt print-env PWD" + } + } +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/pnpm-workspace.yaml b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/pnpm-workspace.yaml new file mode 100644 index 000000000..924b55f42 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - packages/* diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots.toml b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots.toml new file mode 100644 index 000000000..823860152 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots.toml @@ -0,0 +1,41 @@ +# Tests that a spawned task sees `PWD` set to the directory it runs in, not +# the directory `vt run` was called from (as after a shell `cd`). + +[fields] +key = true + +[fields.spawn_command] +cwd = true + +[fields.spawn_command.spawn_envs] +PWD = true + +[[plan]] +name = "package_task_from_workspace_root" +args = ["run", "a#where"] +env = { PWD = "/caller" } + +[[plan]] +name = "task_cwd_option" +args = ["run", "where-sub"] +cwd = "packages/a" +env = { PWD = "/caller" } + +[[plan]] +name = "cd_before_command" +args = ["run", "a#where-cd"] +env = { PWD = "/caller" } + +[[plan]] +name = "uncached_task" +args = ["run", "a#where-uncached"] +env = { PWD = "/caller" } + +[[plan]] +name = "prefix_assignment_wins" +args = ["run", "a#where-prefix"] +env = { PWD = "/caller" } + +[[plan]] +name = "pwd_not_added_when_caller_has_none" +args = ["run", "a#where"] diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_cd_before_command.jsonc b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_cd_before_command.jsonc new file mode 100644 index 000000000..4d7fd0d9b --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_cd_before_command.jsonc @@ -0,0 +1,29 @@ +// run a#where-cd +{ + "graph": [ + { + "key": [ + "/packages/a", + "where-cd" + ], + "node": { + "items": [ + { + "kind": { + "Leaf": { + "Spawn": { + "spawn_command": { + "spawn_envs": { + "PWD": "/packages/a/sub" + }, + "cwd": "/packages/a/sub" + } + } + } + } + } + ] + } + } + ] +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_package_task_from_workspace_root.jsonc b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_package_task_from_workspace_root.jsonc new file mode 100644 index 000000000..d98059923 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_package_task_from_workspace_root.jsonc @@ -0,0 +1,29 @@ +// run a#where +{ + "graph": [ + { + "key": [ + "/packages/a", + "where" + ], + "node": { + "items": [ + { + "kind": { + "Leaf": { + "Spawn": { + "spawn_command": { + "spawn_envs": { + "PWD": "/packages/a" + }, + "cwd": "/packages/a" + } + } + } + } + } + ] + } + } + ] +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_prefix_assignment_wins.jsonc b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_prefix_assignment_wins.jsonc new file mode 100644 index 000000000..29c82b3c1 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_prefix_assignment_wins.jsonc @@ -0,0 +1,29 @@ +// run a#where-prefix +{ + "graph": [ + { + "key": [ + "/packages/a", + "where-prefix" + ], + "node": { + "items": [ + { + "kind": { + "Leaf": { + "Spawn": { + "spawn_command": { + "spawn_envs": { + "PWD": "/custom" + }, + "cwd": "/packages/a" + } + } + } + } + } + ] + } + } + ] +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_pwd_not_added_when_caller_has_none.jsonc b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_pwd_not_added_when_caller_has_none.jsonc new file mode 100644 index 000000000..42aa15ff4 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_pwd_not_added_when_caller_has_none.jsonc @@ -0,0 +1,27 @@ +// run a#where +{ + "graph": [ + { + "key": [ + "/packages/a", + "where" + ], + "node": { + "items": [ + { + "kind": { + "Leaf": { + "Spawn": { + "spawn_command": { + "spawn_envs": {}, + "cwd": "/packages/a" + } + } + } + } + } + ] + } + } + ] +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_task_cwd_option.jsonc b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_task_cwd_option.jsonc new file mode 100644 index 000000000..26be11c4d --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_task_cwd_option.jsonc @@ -0,0 +1,29 @@ +// run where-sub +{ + "graph": [ + { + "key": [ + "/packages/a", + "where-sub" + ], + "node": { + "items": [ + { + "kind": { + "Leaf": { + "Spawn": { + "spawn_command": { + "spawn_envs": { + "PWD": "/packages/a/sub" + }, + "cwd": "/packages/a/sub" + } + } + } + } + } + ] + } + } + ] +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_uncached_task.jsonc b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_uncached_task.jsonc new file mode 100644 index 000000000..686acb485 --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/query_uncached_task.jsonc @@ -0,0 +1,29 @@ +// run a#where-uncached +{ + "graph": [ + { + "key": [ + "/packages/a", + "where-uncached" + ], + "node": { + "items": [ + { + "kind": { + "Leaf": { + "Spawn": { + "spawn_command": { + "spawn_envs": { + "PWD": "/packages/a" + }, + "cwd": "/packages/a" + } + } + } + } + } + ] + } + } + ] +} diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/task_graph.md b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/task_graph.md new file mode 100644 index 000000000..e0e8fb58a --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/snapshots/task_graph.md @@ -0,0 +1,193 @@ +# task graph + +```mermaid +flowchart TD + task_0["/packages/a#where"] + task_1["/packages/a#where-cd"] + task_2["/packages/a#where-prefix"] + task_3["/packages/a#where-sub"] + task_4["/packages/a#where-uncached"] +``` + +## `/packages/a#where` + +```json +{ + "task_display": { + "package_name": "a", + "task_name": "where", + "package_path": "/packages/a" + }, + "resolved_config": { + "commands": [ + "vtt print-env PWD" + ], + "resolved_options": { + "cwd": "/packages/a", + "cache_config": { + "remote_cache_allowed": true, + "env_config": { + "fingerprinted_envs": [], + "untracked_env": [ + "" + ] + }, + "input_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + }, + "output_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + } + } + } + }, + "source": "TaskConfig" +} +``` + +## `/packages/a#where-cd` + +```json +{ + "task_display": { + "package_name": "a", + "task_name": "where-cd", + "package_path": "/packages/a" + }, + "resolved_config": { + "commands": [ + "cd sub && vtt print-env PWD" + ], + "resolved_options": { + "cwd": "/packages/a", + "cache_config": { + "remote_cache_allowed": true, + "env_config": { + "fingerprinted_envs": [], + "untracked_env": [ + "" + ] + }, + "input_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + }, + "output_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + } + } + } + }, + "source": "TaskConfig" +} +``` + +## `/packages/a#where-prefix` + +```json +{ + "task_display": { + "package_name": "a", + "task_name": "where-prefix", + "package_path": "/packages/a" + }, + "resolved_config": { + "commands": [ + "PWD=/custom vtt print-env PWD" + ], + "resolved_options": { + "cwd": "/packages/a", + "cache_config": { + "remote_cache_allowed": true, + "env_config": { + "fingerprinted_envs": [], + "untracked_env": [ + "" + ] + }, + "input_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + }, + "output_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + } + } + } + }, + "source": "TaskConfig" +} +``` + +## `/packages/a#where-sub` + +```json +{ + "task_display": { + "package_name": "a", + "task_name": "where-sub", + "package_path": "/packages/a" + }, + "resolved_config": { + "commands": [ + "vtt print-env PWD" + ], + "resolved_options": { + "cwd": "/packages/a/sub", + "cache_config": { + "remote_cache_allowed": true, + "env_config": { + "fingerprinted_envs": [], + "untracked_env": [ + "" + ] + }, + "input_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + }, + "output_config": { + "includes_auto": true, + "positive_globs": [], + "negative_globs": [] + } + } + } + }, + "source": "TaskConfig" +} +``` + +## `/packages/a#where-uncached` + +```json +{ + "task_display": { + "package_name": "a", + "task_name": "where-uncached", + "package_path": "/packages/a" + }, + "resolved_config": { + "commands": [ + "vtt print-env PWD" + ], + "resolved_options": { + "cwd": "/packages/a", + "cache_config": null + } + }, + "source": "TaskConfig" +} +``` + diff --git a/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/vite-task.json b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/vite-task.json new file mode 100644 index 000000000..d548edfac --- /dev/null +++ b/crates/vt_plan/tests/plan_snapshots/fixtures/pwd_follows_task_cwd/vite-task.json @@ -0,0 +1,3 @@ +{ + "cache": true +}