-
Notifications
You must be signed in to change notification settings - Fork 25
feat(cache): integrate runner-aware IPC reports #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
branchseer
wants to merge
1
commit into
feat/runner-execute-refactor
from
feat/runner-cache-integration
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| mod cli; | ||
| mod collections; | ||
| mod napi_client; | ||
| pub mod session; | ||
|
|
||
| // Public exports for vite_task_bin | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //! The `vite_task_client_napi` cdylib is embedded into the `vp` binary and | ||
| //! materialized to disk on first use so tools can `require()` it at runtime. | ||
|
|
||
| use std::{env, fs, sync::LazyLock}; | ||
|
|
||
| use materialized_artifact::artifact; | ||
| use vite_path::{AbsolutePath, AbsolutePathBuf}; | ||
|
|
||
| /// Path to the materialized `vite_task_client_napi` `.node` addon. | ||
| /// | ||
| /// The file is written to a process-wide temp directory on first call and | ||
| /// reused on every subsequent call (content-addressed filename; no re-writes). | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the materialization fails on first call — this mirrors fspy's | ||
| /// `SPY_IMPL` and the same reasoning applies: if we can't write into the | ||
| /// system temp dir, the runner can't run tasks anyway. | ||
| #[must_use] | ||
| pub fn napi_client_path() -> &'static AbsolutePath { | ||
| static PATH: LazyLock<AbsolutePathBuf> = LazyLock::new(|| { | ||
| let dir = env::temp_dir().join("vite_task_client_napi"); | ||
| let _ = fs::create_dir(&dir); | ||
| let path = artifact!("vite_task_client_napi") | ||
| .materialize() | ||
| .suffix(".node") | ||
| .at(&dir) | ||
| .expect("materialize vite_task_client_napi"); | ||
| AbsolutePathBuf::new(path).expect("system temp dir yields an absolute path") | ||
| }); | ||
| PATH.as_absolute_path() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| pub fn run(args: &[String]) { | ||
| let [path, pattern] = args else { | ||
| eprintln!("Usage: vtt grep-file <path> <pattern>"); | ||
| std::process::exit(2); | ||
| }; | ||
| match std::fs::read_to_string(path) { | ||
| Ok(content) => { | ||
| if content.contains(pattern.as_str()) { | ||
| println!("{path}: found {pattern:?}"); | ||
| } else { | ||
| println!("{path}: missing {pattern:?}"); | ||
| } | ||
| } | ||
| Err(_) => println!("{path}: not found"), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| pub fn run(args: &[String]) { | ||
| for file in args { | ||
| if std::fs::metadata(file).is_ok() { | ||
| println!("{file}: exists"); | ||
| } else { | ||
| println!("{file}: missing"); | ||
| } | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
crates/vite_task_bin/tests/e2e_snapshots/fixtures/ipc_client_test/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "ipc-client-test", | ||
| "private": true, | ||
| "type": "module" | ||
| } |
8 changes: 8 additions & 0 deletions
8
crates/vite_task_bin/tests/e2e_snapshots/fixtures/ipc_client_test/scripts/disable_cache.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { disableCache } from '@voidzero-dev/vite-task-client'; | ||
| import { writeFileSync, mkdirSync } from 'node:fs'; | ||
|
|
||
| // Produce an output, then ask the runner not to cache this execution — the | ||
| // next `vt run` should re-execute the task. | ||
| mkdirSync('dist', { recursive: true }); | ||
| writeFileSync('dist/out.txt', 'ok\n'); | ||
| disableCache(); |
10 changes: 10 additions & 0 deletions
10
crates/vite_task_bin/tests/e2e_snapshots/fixtures/ipc_client_test/scripts/fetch_env.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { getEnv } from '@voidzero-dev/vite-task-client'; | ||
| import { writeFileSync, mkdirSync } from 'node:fs'; | ||
|
|
||
| // getEnv returns the env value from the runner and — with tracked: true — | ||
| // adds the env to the post-run fingerprint, so a change between runs | ||
| // invalidates the cache. | ||
| const value = getEnv('PROBE_ENV', { tracked: true }) ?? '(unset)'; | ||
|
|
||
| mkdirSync('dist', { recursive: true }); | ||
| writeFileSync('dist/out.txt', 'PROBE_ENV=' + value + '\n'); |
14 changes: 14 additions & 0 deletions
14
crates/vite_task_bin/tests/e2e_snapshots/fixtures/ipc_client_test/scripts/fetch_envs.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { getEnvs } from '@voidzero-dev/vite-task-client'; | ||
| import { writeFileSync, mkdirSync } from 'node:fs'; | ||
|
|
||
| // getEnvs asks the runner for every env matching the glob. The glob (plus | ||
| // its match-set) becomes part of the post-run fingerprint, so adding, | ||
| // removing, or changing any matching env invalidates the cache on the next | ||
| // run. The non-matching UNRELATED envs set by some test steps must not | ||
| // contribute. | ||
| const matches = getEnvs('PROBE_*', { tracked: true }); | ||
|
|
||
| mkdirSync('dist', { recursive: true }); | ||
| const sorted = Object.entries(matches).sort(([a], [b]) => a.localeCompare(b)); | ||
| const body = sorted.map(([k, v]) => `${k}=${v}`).join('\n'); | ||
| writeFileSync('dist/out.txt', body + '\n'); |
15 changes: 15 additions & 0 deletions
15
crates/vite_task_bin/tests/e2e_snapshots/fixtures/ipc_client_test/scripts/ignore_input.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { ignoreInput } from '@voidzero-dev/vite-task-client'; | ||
| import { writeFileSync, readFileSync } from 'node:fs'; | ||
| import { mkdirSync } from 'node:fs'; | ||
|
|
||
| // The task reads from `cache_like/` (which we want the runner to IGNORE as | ||
| // an input), and writes to `dist/`. Without the ignore, the auto-input | ||
| // fingerprint would fluctuate with cache_like/ contents even though they're | ||
| // not semantic inputs. | ||
| mkdirSync('cache_like', { recursive: true }); | ||
| writeFileSync('cache_like/stale.txt', 'stale-' + Date.now() + '\n'); | ||
| ignoreInput('cache_like'); | ||
| readFileSync('cache_like/stale.txt', 'utf8'); | ||
|
|
||
| mkdirSync('dist', { recursive: true }); | ||
| writeFileSync('dist/out.txt', 'ok\n'); |
14 changes: 14 additions & 0 deletions
14
crates/vite_task_bin/tests/e2e_snapshots/fixtures/ipc_client_test/scripts/ignore_output.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { ignoreOutput } from '@voidzero-dev/vite-task-client'; | ||
| import { writeFileSync, readFileSync, mkdirSync } from 'node:fs'; | ||
|
|
||
| // The task both reads and writes `sidecar/tmp.txt`. If the runner didn't | ||
| // treat `sidecar/` as an ignored output, the read-write overlap check would | ||
| // refuse to cache the task. `dist/out.txt` is the real output. | ||
| mkdirSync('sidecar', { recursive: true }); | ||
| writeFileSync('sidecar/tmp.txt', 'initial\n'); | ||
| readFileSync('sidecar/tmp.txt', 'utf8'); | ||
| writeFileSync('sidecar/tmp.txt', 'final\n'); | ||
| ignoreOutput('sidecar'); | ||
|
|
||
| mkdirSync('dist', { recursive: true }); | ||
| writeFileSync('dist/out.txt', 'ok\n'); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This captures only the runner process environment, but the actual child environment is
spawn_execution.spawn_command.all_envsplus prefix envs and runtime injections. When a task uses a command prefix or other planned env override (for exampleFOO=prod node ...while the parent hasFOO=devor noFOO),getEnv('FOO')returns the parent value/Noneinstead of what the spawned tool sees, so runner-aware tools can compute outputs from the wrong value and record the wrong post-run fingerprint.Useful? React with 👍 / 👎.