feat(graceful-handoff): 2.0 — statusLine context-percent hint [skip-docs]
Step 4 of v2.0 plan. statusLine hook reads context_window.used_percentage from stdin payload and prints display-only hint at 60% / 70%. NEVER runs git (research/03 — statusLine scripts can be cancelled mid-flight, unsafe for side effects). 9 tests cover thresholds, null payload, malformed JSON. Includes hook-helper.mjs copied from llm-security as test infrastructure.
This commit is contained in:
parent
8d4e16bf8e
commit
1efb1b3176
3 changed files with 171 additions and 0 deletions
42
plugins/graceful-handoff/tests/hooks/hook-helper.mjs
Normal file
42
plugins/graceful-handoff/tests/hooks/hook-helper.mjs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// hook-helper.mjs — Shared test helper for hook scripts.
|
||||
// Spawns a hook as a child process and feeds it JSON via stdin.
|
||||
|
||||
import { execFile } from 'node:child_process';
|
||||
|
||||
/**
|
||||
* Run a hook script by spawning `node <scriptPath>` and piping `input` to stdin.
|
||||
*
|
||||
* @param {string} scriptPath - Absolute path to the hook .mjs file
|
||||
* @param {object|string} input - JSON payload (object will be stringified)
|
||||
* @returns {Promise<{ code: number, stdout: string, stderr: string }>}
|
||||
*/
|
||||
export function runHook(scriptPath, input) {
|
||||
return runHookWithEnv(scriptPath, input, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a hook script with custom environment variables.
|
||||
*
|
||||
* @param {string} scriptPath - Absolute path to the hook .mjs file
|
||||
* @param {object|string} input - JSON payload (object will be stringified)
|
||||
* @param {Record<string, string>} envOverrides - Extra env vars to set
|
||||
* @returns {Promise<{ code: number, stdout: string, stderr: string }>}
|
||||
*/
|
||||
export function runHookWithEnv(scriptPath, input, envOverrides) {
|
||||
return new Promise((resolve) => {
|
||||
const env = { ...process.env, ...envOverrides };
|
||||
const child = execFile(
|
||||
'node',
|
||||
[scriptPath],
|
||||
{ timeout: 5000, env },
|
||||
(err, stdout, stderr) => {
|
||||
resolve({
|
||||
code: child.exitCode ?? (err && err.code === 'ERR_CHILD_PROCESS_STDIO_FINAL' ? 0 : 1),
|
||||
stdout: stdout || '',
|
||||
stderr: stderr || '',
|
||||
});
|
||||
}
|
||||
);
|
||||
child.stdin.end(typeof input === 'string' ? input : JSON.stringify(input));
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue