Skip to content

Commit 705c34a

Browse files
committed
add UTs for iflow-cli
1 parent c946706 commit 705c34a

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

test/core/init.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,59 @@ describe('InitCommand', () => {
416416
expect(updatedContent).not.toContain('Custom instruction added by user');
417417
});
418418

419+
it('should create IFlow CLI slash command files with templates', async () => {
420+
queueSelections('iflow', DONE);
421+
await initCommand.execute(testDir);
422+
423+
const iflowProposal = path.join(
424+
testDir,
425+
'.iflow/commands/openspec-proposal.md'
426+
);
427+
const iflowApply = path.join(
428+
testDir,
429+
'.iflow/commands/openspec-apply.md'
430+
);
431+
const iflowArchive = path.join(
432+
testDir,
433+
'.iflow/commands/openspec-archive.md'
434+
);
435+
436+
expect(await fileExists(iflowProposal)).toBe(true);
437+
expect(await fileExists(iflowApply)).toBe(true);
438+
expect(await fileExists(iflowArchive)).toBe(true);
439+
440+
const proposalContent = await fs.readFile(iflowProposal, 'utf-8');
441+
expect(proposalContent).toContain('description: Scaffold a new OpenSpec change and validate strictly.');
442+
expect(proposalContent).toContain('<!-- OPENSPEC:START -->');
443+
expect(proposalContent).toContain('**Guardrails**');
444+
expect(proposalContent).toContain('<!-- OPENSPEC:END -->');
445+
446+
const applyContent = await fs.readFile(iflowApply, 'utf-8');
447+
expect(applyContent).toContain('description: Implement an approved OpenSpec change and keep tasks in sync.');
448+
expect(applyContent).toContain('Work through tasks sequentially');
449+
450+
const archiveContent = await fs.readFile(iflowArchive, 'utf-8');
451+
expect(archiveContent).toContain('description: Archive a deployed OpenSpec change and update specs.');
452+
expect(archiveContent).toContain('openspec archive <id>');
453+
});
454+
455+
it('should update existing IFLOW.md with markers', async () => {
456+
queueSelections('iflow', DONE);
457+
458+
const iflowPath = path.join(testDir, 'IFLOW.md');
459+
const existingContent = '# My IFLOW Instructions\nCustom instructions here';
460+
await fs.writeFile(iflowPath, existingContent);
461+
462+
await initCommand.execute(testDir);
463+
464+
const updatedContent = await fs.readFile(iflowPath, 'utf-8');
465+
expect(updatedContent).toContain('<!-- OPENSPEC:START -->');
466+
expect(updatedContent).toContain("@/openspec/AGENTS.md");
467+
expect(updatedContent).toContain('openspec update');
468+
expect(updatedContent).toContain('<!-- OPENSPEC:END -->');
469+
expect(updatedContent).toContain('Custom instructions here');
470+
});
471+
419472
it('should create OpenCode slash command files with templates', async () => {
420473
queueSelections('opencode', DONE);
421474

test/core/update.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,53 @@ Old Gemini body
663663

664664
consoleSpy.mockRestore();
665665
});
666+
667+
it('should refresh existing IFLOW slash commands', async () => {
668+
const iflowProposal = path.join(
669+
testDir,
670+
'.iflow/commands/openspec-proposal.md'
671+
);
672+
await fs.mkdir(path.dirname(iflowProposal), { recursive: true });
673+
const initialContent = `description: Scaffold a new OpenSpec change and validate strictly."
674+
675+
prompt = """
676+
<!-- OPENSPEC:START -->
677+
Old IFlow body
678+
<!-- OPENSPEC:END -->
679+
"""
680+
`;
681+
await fs.writeFile(iflowProposal, initialContent);
682+
683+
const consoleSpy = vi.spyOn(console, 'log');
684+
685+
await updateCommand.execute(testDir);
686+
687+
const updated = await fs.readFile(iflowProposal, 'utf-8');
688+
expect(updated).toContain('description: Scaffold a new OpenSpec change and validate strictly.');
689+
expect(updated).toContain('<!-- OPENSPEC:START -->');
690+
expect(updated).toContain('**Guardrails**');
691+
expect(updated).toContain('<!-- OPENSPEC:END -->');
692+
expect(updated).not.toContain('Old IFlow body');
693+
694+
const iflowApply = path.join(
695+
testDir,
696+
'.iflow/commands/openspec-apply.md'
697+
);
698+
const iflowArchive = path.join(
699+
testDir,
700+
'.iflow/commands/openspec-archive.md'
701+
);
702+
703+
await expect(FileSystemUtils.fileExists(iflowApply)).resolves.toBe(false);
704+
await expect(FileSystemUtils.fileExists(iflowArchive)).resolves.toBe(false);
705+
706+
const [logMessage] = consoleSpy.mock.calls[0];
707+
expect(logMessage).toContain(
708+
'Updated slash commands: .iflow/commands/openspec-proposal.md'
709+
);
710+
711+
consoleSpy.mockRestore();
712+
});
666713

667714
it('should refresh existing Factory slash commands', async () => {
668715
const factoryPath = path.join(

0 commit comments

Comments
 (0)