test: simplify hooks temp-dir cleanup to a one-line exit handler (#221)

#213 guarded cleanup with a flag + named function + process.once. But
fs.rmSync with force:true already no-ops on a missing path, so the guard
and the explicit end-of-file call are unnecessary. Collapse to a single
process.on('exit') handler.

Refs #204

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
DietrichGebert
2026-06-21 01:29:09 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent ee263e5708
commit 248a30b40b
+2 -8
View File
@@ -21,13 +21,8 @@ function run(script, env, input = '') {
delete process.env.CLAUDE_CONFIG_DIR;
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ponytail-hooks-'));
let cleanedTemp = false;
function cleanupTemp() {
if (cleanedTemp) return;
cleanedTemp = true;
fs.rmSync(temp, { recursive: true, force: true });
}
process.once('exit', cleanupTemp);
// Runs on normal exit and on assertion-throw exit; force makes it idempotent.
process.on('exit', () => fs.rmSync(temp, { recursive: true, force: true }));
const home = path.join(temp, 'home');
const pluginData = path.join(temp, 'plugin-data');
@@ -163,5 +158,4 @@ assert.equal(
output = JSON.parse(result.stdout);
assert.deepEqual(output, {});
cleanupTemp();
console.log('hook compatibility checks passed');