Skip to content

Commit 360934a

Browse files
committed
fix: use try/finally for opencode home cleanup in test
Addresses CodeRabbit review comment - ensures temp directory cleanup runs even if assertions fail mid-test.
1 parent 6e40384 commit 360934a

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/core/init.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,25 @@ describe('InitCommand - profile and detection features', () => {
541541
const opencodeHome = path.join(os.tmpdir(), `openspec-opencode-home-${Date.now()}`);
542542
process.env.OPENCODE_HOME = opencodeHome;
543543

544-
// Create legacy OpenCode command files (singular 'command' path)
545-
const legacyDir = path.join(testDir, '.opencode', 'command');
546-
await fs.mkdir(legacyDir, { recursive: true });
547-
await fs.writeFile(path.join(legacyDir, 'opsx-propose.md'), 'legacy content');
548-
549-
// Run init in non-interactive mode without --force
550-
const initCommand = new InitCommand({ tools: 'opencode' });
551-
await initCommand.execute(testDir);
552-
553-
// Legacy files should be cleaned up automatically
554-
expect(await fileExists(path.join(legacyDir, 'opsx-propose.md'))).toBe(false);
544+
try {
545+
// Create legacy OpenCode command files (singular 'command' path)
546+
const legacyDir = path.join(testDir, '.opencode', 'command');
547+
await fs.mkdir(legacyDir, { recursive: true });
548+
await fs.writeFile(path.join(legacyDir, 'opsx-propose.md'), 'legacy content');
549+
550+
// Run init in non-interactive mode without --force
551+
const initCommand = new InitCommand({ tools: 'opencode' });
552+
await initCommand.execute(testDir);
555553

556-
// New commands should be at the global OpenCode path
557-
const newCommandsDir = path.join(opencodeHome, 'commands');
558-
expect(await directoryExists(newCommandsDir)).toBe(true);
554+
// Legacy files should be cleaned up automatically
555+
expect(await fileExists(path.join(legacyDir, 'opsx-propose.md'))).toBe(false);
559556

560-
await fs.rm(opencodeHome, { recursive: true, force: true });
557+
// New commands should be at the global OpenCode path
558+
const newCommandsDir = path.join(opencodeHome, 'commands');
559+
expect(await directoryExists(newCommandsDir)).toBe(true);
560+
} finally {
561+
await fs.rm(opencodeHome, { recursive: true, force: true });
562+
}
561563
});
562564

563565
it('should preselect configured tools but not directory-detected tools in extend mode', async () => {

0 commit comments

Comments
 (0)