Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
| 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 | ||
| 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() | ||
| } |
| 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"), | ||
| } | ||
| } |
| 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"); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "ipc-client-test", | ||
| "private": true, | ||
| "type": "module" | ||
| } |
| 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(); |
| 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'); |
| 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'); |
| 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'); |
| 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'); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 👍 / 👎.