Skip to content

Commit 89fc0ba

Browse files
committed
fix: ensure commit-msg hook can find executable in test environments
Modified test environment setup to include dist/bin in PATH for all tests that run git commit operations. This ensures the commit-msg hook can properly locate the commit-msg executable during testing, particularly in CI environments where the package may not be installed globally. Fixes potential CI failures where the hook couldn't locate the commit-msg command. Change-Id: Ia3e82246c27ac6a8455e062ab0cd6a37277a7234 Co-developed-by: Claude <noreply@anthropic.com>
1 parent 475cafd commit 89fc0ba

2 files changed

Lines changed: 61 additions & 20 deletions

File tree

test/integration.test.ts

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ This is a new feature that adds functionality to the application.
6969
It includes several improvements and bug fixes.`;
7070
writeFileSync(messageFile, commitMessage, 'utf8');
7171

72-
// Set environment variable to trigger CoDevelopedBy
73-
const env = { ...process.env, CLAUDECODE: '1' };
72+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
73+
const env = {
74+
...process.env,
75+
CLAUDECODE: '1',
76+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
77+
};
7478

7579
// Execute the commit-msg hook directly
7680
const execResult = spawnSync(
@@ -112,8 +116,12 @@ It includes several improvements and bug fixes.`;
112116
This is a merge commit message.`;
113117
writeFileSync(messageFile, mergeCommitMessage, 'utf8');
114118

115-
// Set environment variable to trigger CoDevelopedBy
116-
const env = { ...process.env, CLAUDECODE: '1' };
119+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
120+
const env = {
121+
...process.env,
122+
CLAUDECODE: '1',
123+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
124+
};
117125

118126
// Execute the commit-msg hook directly
119127
const execResult = spawnSync(
@@ -139,8 +147,12 @@ This is a merge commit message.`;
139147
This is a fixup commit.`;
140148
writeFileSync(messageFile, fixupCommitMessage, 'utf8');
141149

142-
// Set environment variable to trigger CoDevelopedBy
143-
const env = { ...process.env, CLAUDECODE: '1' };
150+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
151+
const env = {
152+
...process.env,
153+
CLAUDECODE: '1',
154+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
155+
};
144156

145157
// Execute the commit-msg hook directly
146158
const execResult = spawnSync(
@@ -172,8 +184,12 @@ This updates an existing feature.
172184
Change-Id: ${existingChangeId}`;
173185
writeFileSync(messageFile, commitMessage, 'utf8');
174186

175-
// Set environment variable to trigger CoDevelopedBy
176-
const env = { ...process.env, CLAUDECODE: '1' };
187+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
188+
const env = {
189+
...process.env,
190+
CLAUDECODE: '1',
191+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
192+
};
177193

178194
// Execute the commit-msg hook directly
179195
const execResult = spawnSync(
@@ -213,8 +229,13 @@ Change-Id: ${existingChangeId}`;
213229
This is a really awesome feature.`;
214230
writeFileSync(messageFile, commitMessage, 'utf8');
215231

216-
// Test with GEMINI_CLI environment variable, but first unset CLAUDECODE
217-
const env = { ...process.env, CLAUDECODE: undefined, GEMINI_CLI: '1' };
232+
// Test with GEMINI_CLI environment variable, but first unset CLAUDECODE and ensure PATH includes dist/bin
233+
const env = {
234+
...process.env,
235+
CLAUDECODE: undefined,
236+
GEMINI_CLI: '1',
237+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
238+
};
218239

219240
// Execute the commit-msg hook directly
220241
const execResult = spawnSync(
@@ -436,8 +457,12 @@ This adds support for the new commit-msg.changeid configuration.`;
436457
// Set up git configuration to disable Change-Id using the new config option
437458
execSync('git config commit-msg.changeid false', { stdio: 'ignore' });
438459

439-
// Set environment variable to trigger CoDevelopedBy
440-
const env = { ...process.env, CLAUDECODE: '1' };
460+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
461+
const env = {
462+
...process.env,
463+
CLAUDECODE: '1',
464+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
465+
};
441466

442467
// Execute the commit-msg hook directly
443468
const execResult = spawnSync(
@@ -484,8 +509,12 @@ This adds support for the new commitmsg.changeid configuration.`;
484509
// Set up git configuration to disable Change-Id using the new config option
485510
execSync('git config commitmsg.changeid false', { stdio: 'ignore' });
486511

487-
// Set environment variable to trigger CoDevelopedBy
488-
const env = { ...process.env, CLAUDECODE: '1' };
512+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
513+
const env = {
514+
...process.env,
515+
CLAUDECODE: '1',
516+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
517+
};
489518

490519
// Execute the commit-msg hook directly
491520
const execResult = spawnSync(

test/merge-commit.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ describe('commit-msg merge commit handling tests with real git commits', () => {
6868
});
6969

7070
it('should process first commit in empty repository with Change-Id and Co-developed-by', () => {
71-
// Set environment variable to trigger CoDevelopedBy
72-
const env = { ...process.env, CLAUDECODE: '1' };
71+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
72+
const env = {
73+
...process.env,
74+
CLAUDECODE: '1',
75+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
76+
};
7377

7478
// Create first commit
7579
execSync('echo "Initial content" > file1.txt', { stdio: 'ignore' });
@@ -123,8 +127,12 @@ describe('commit-msg merge commit handling tests with real git commits', () => {
123127
execSync('echo "Feature content" > file2.txt', { stdio: 'ignore' });
124128
execSync('git add file2.txt', { stdio: 'ignore' });
125129

126-
// Set environment variable to trigger CoDevelopedBy
127-
const env = { ...process.env, CLAUDECODE: '1' };
130+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
131+
const env = {
132+
...process.env,
133+
CLAUDECODE: '1',
134+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
135+
};
128136

129137
// Commit on feature branch
130138
const featureCommitResult = spawnSync(
@@ -195,8 +203,12 @@ describe('commit-msg merge commit handling tests with real git commits', () => {
195203
});
196204

197205
it('should process regular commit after merge commit with Change-Id and Co-developed-by', () => {
198-
// Set environment variable to trigger CoDevelopedBy
199-
const env = { ...process.env, CLAUDECODE: '1' };
206+
// Set environment variable to trigger CoDevelopedBy and ensure PATH includes dist/bin
207+
const env = {
208+
...process.env,
209+
CLAUDECODE: '1',
210+
PATH: `${path.join(originalCwd, 'dist', 'bin')}:${process.env.PATH || ''}`,
211+
};
200212

201213
// Create a commit after the merge
202214
execSync('echo "Post-merge content" > file4.txt', { stdio: 'ignore' });

0 commit comments

Comments
 (0)