From b84dfd4c9b85467e6afbd9c91e6dc521acb27ba8 Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Sat, 11 Apr 2026 08:50:44 -0400 Subject: [PATCH] fix(tests): add before() hook to bug-1736 test to prevent hooks/dist race condition (#2099) With --test-concurrency=4, bug-1834 and bug-1924 run build-hooks.js concurrently with bug-1736. build-hooks.js creates hooks/dist/ empty first then copies files, creating a window where bug-1736 sees an empty directory, install() fails with "directory is empty", and process.exit(1) kills the test process. Added the same before() pattern used by all other install tests. Co-authored-by: Claude Sonnet 4.6 --- tests/bug-1736-local-install-commands.test.cjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/bug-1736-local-install-commands.test.cjs b/tests/bug-1736-local-install-commands.test.cjs index a42396ad9..969376435 100644 --- a/tests/bug-1736-local-install-commands.test.cjs +++ b/tests/bug-1736-local-install-commands.test.cjs @@ -12,7 +12,7 @@ process.env.GSD_TEST_MODE = '1'; -const { describe, test, beforeEach, afterEach } = require('node:test'); +const { describe, test, before, beforeEach, afterEach } = require('node:test'); const assert = require('node:assert/strict'); const fs = require('fs'); const path = require('path'); @@ -20,8 +20,22 @@ const os = require('os'); const { execFileSync } = require('child_process'); const INSTALL_SRC = path.join(__dirname, '..', 'bin', 'install.js'); +const BUILD_SCRIPT = path.join(__dirname, '..', 'scripts', 'build-hooks.js'); const { install, copyCommandsAsClaudeSkills } = require(INSTALL_SRC); +// ─── Ensure hooks/dist/ is populated before install tests ──────────────────── +// With --test-concurrency=4, other install tests (bug-1834, bug-1924) run +// build-hooks.js concurrently. That script creates hooks/dist/ empty first, +// then copies files — creating a window where this test sees an empty dir and +// install() fails with "directory is empty" → process.exit(1). + +before(() => { + execFileSync(process.execPath, [BUILD_SCRIPT], { + encoding: 'utf-8', + stdio: 'pipe', + }); +}); + // ─── #1736: local install deploys commands/gsd/ ───────────────────────────── describe('#1736: local Claude install populates .claude/commands/gsd/', () => {