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:
co-authored by
Claude Opus 4.8
parent
ee263e5708
commit
248a30b40b
+2
-8
@@ -21,13 +21,8 @@ function run(script, env, input = '') {
|
|||||||
delete process.env.CLAUDE_CONFIG_DIR;
|
delete process.env.CLAUDE_CONFIG_DIR;
|
||||||
|
|
||||||
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ponytail-hooks-'));
|
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ponytail-hooks-'));
|
||||||
let cleanedTemp = false;
|
// Runs on normal exit and on assertion-throw exit; force makes it idempotent.
|
||||||
function cleanupTemp() {
|
process.on('exit', () => fs.rmSync(temp, { recursive: true, force: true }));
|
||||||
if (cleanedTemp) return;
|
|
||||||
cleanedTemp = true;
|
|
||||||
fs.rmSync(temp, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
process.once('exit', cleanupTemp);
|
|
||||||
|
|
||||||
const home = path.join(temp, 'home');
|
const home = path.join(temp, 'home');
|
||||||
const pluginData = path.join(temp, 'plugin-data');
|
const pluginData = path.join(temp, 'plugin-data');
|
||||||
@@ -163,5 +158,4 @@ assert.equal(
|
|||||||
output = JSON.parse(result.stdout);
|
output = JSON.parse(result.stdout);
|
||||||
assert.deepEqual(output, {});
|
assert.deepEqual(output, {});
|
||||||
|
|
||||||
cleanupTemp();
|
|
||||||
console.log('hook compatibility checks passed');
|
console.log('hook compatibility checks passed');
|
||||||
|
|||||||
Reference in New Issue
Block a user