@lumenflow/cli 1.6.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/__tests__/backlog-prune.test.js +478 -0
- package/dist/__tests__/deps-operations.test.js +206 -0
- package/dist/__tests__/file-operations.test.js +906 -0
- package/dist/__tests__/git-operations.test.js +668 -0
- package/dist/__tests__/guards-validation.test.js +416 -0
- package/dist/__tests__/init-plan.test.js +340 -0
- package/dist/__tests__/lumenflow-upgrade.test.js +107 -0
- package/dist/__tests__/metrics-cli.test.js +619 -0
- package/dist/__tests__/rotate-progress.test.js +127 -0
- package/dist/__tests__/session-coordinator.test.js +109 -0
- package/dist/__tests__/state-bootstrap.test.js +432 -0
- package/dist/__tests__/trace-gen.test.js +115 -0
- package/dist/backlog-prune.js +299 -0
- package/dist/deps-add.js +215 -0
- package/dist/deps-remove.js +94 -0
- package/dist/docs-sync.js +72 -326
- package/dist/file-delete.js +236 -0
- package/dist/file-edit.js +247 -0
- package/dist/file-read.js +197 -0
- package/dist/file-write.js +220 -0
- package/dist/git-branch.js +187 -0
- package/dist/git-diff.js +177 -0
- package/dist/git-log.js +230 -0
- package/dist/git-status.js +208 -0
- package/dist/guard-locked.js +169 -0
- package/dist/guard-main-branch.js +202 -0
- package/dist/guard-worktree-commit.js +160 -0
- package/dist/init-plan.js +337 -0
- package/dist/lumenflow-upgrade.js +178 -0
- package/dist/metrics-cli.js +433 -0
- package/dist/rotate-progress.js +247 -0
- package/dist/session-coordinator.js +300 -0
- package/dist/state-bootstrap.js +307 -0
- package/dist/sync-templates.js +212 -0
- package/dist/trace-gen.js +331 -0
- package/dist/validate-agent-skills.js +218 -0
- package/dist/validate-agent-sync.js +148 -0
- package/dist/validate-backlog-sync.js +152 -0
- package/dist/validate-skills-spec.js +206 -0
- package/dist/validate.js +230 -0
- package/package.json +37 -7
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for init:plan command (WU-1105)
|
|
3
|
+
*
|
|
4
|
+
* The init:plan command links plan files to initiatives by setting
|
|
5
|
+
* the `related_plan` field in the initiative YAML.
|
|
6
|
+
*
|
|
7
|
+
* TDD: These tests are written BEFORE the implementation.
|
|
8
|
+
*/
|
|
9
|
+
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll } from 'vitest';
|
|
10
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { parseYAML, stringifyYAML } from '@lumenflow/core/dist/wu-yaml.js';
|
|
14
|
+
// Pre-import the module to ensure coverage tracking includes the module itself
|
|
15
|
+
let initPlanModule;
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
initPlanModule = await import('../init-plan.js');
|
|
18
|
+
});
|
|
19
|
+
// Mock modules before importing the module under test
|
|
20
|
+
const mockGit = {
|
|
21
|
+
branch: vi.fn().mockResolvedValue({ current: 'main' }),
|
|
22
|
+
status: vi.fn().mockResolvedValue({ isClean: () => true }),
|
|
23
|
+
};
|
|
24
|
+
vi.mock('@lumenflow/core/dist/git-adapter.js', () => ({
|
|
25
|
+
getGitForCwd: vi.fn(() => mockGit),
|
|
26
|
+
}));
|
|
27
|
+
vi.mock('@lumenflow/core/dist/wu-helpers.js', () => ({
|
|
28
|
+
ensureOnMain: vi.fn().mockResolvedValue(undefined),
|
|
29
|
+
}));
|
|
30
|
+
vi.mock('@lumenflow/core/dist/micro-worktree.js', () => ({
|
|
31
|
+
withMicroWorktree: vi.fn(async ({ execute }) => {
|
|
32
|
+
// Simulate micro-worktree by executing in temp dir
|
|
33
|
+
const tempDir = join(tmpdir(), `init-plan-test-${Date.now()}`);
|
|
34
|
+
mkdirSync(tempDir, { recursive: true });
|
|
35
|
+
try {
|
|
36
|
+
await execute({ worktreePath: tempDir });
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
// Cleanup handled by test
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
}));
|
|
43
|
+
describe('init:plan command', () => {
|
|
44
|
+
let tempDir;
|
|
45
|
+
let originalCwd;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
tempDir = join(tmpdir(), `init-plan-test-${Date.now()}`);
|
|
48
|
+
mkdirSync(tempDir, { recursive: true });
|
|
49
|
+
originalCwd = process.cwd();
|
|
50
|
+
});
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
process.chdir(originalCwd);
|
|
53
|
+
if (existsSync(tempDir)) {
|
|
54
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
vi.clearAllMocks();
|
|
57
|
+
});
|
|
58
|
+
describe('validateInitIdFormat', () => {
|
|
59
|
+
it('should accept valid INIT-NNN format', async () => {
|
|
60
|
+
const { validateInitIdFormat } = await import('../init-plan.js');
|
|
61
|
+
// Should not throw
|
|
62
|
+
expect(() => validateInitIdFormat('INIT-001')).not.toThrow();
|
|
63
|
+
expect(() => validateInitIdFormat('INIT-123')).not.toThrow();
|
|
64
|
+
});
|
|
65
|
+
it('should accept valid INIT-NAME format', async () => {
|
|
66
|
+
const { validateInitIdFormat } = await import('../init-plan.js');
|
|
67
|
+
expect(() => validateInitIdFormat('INIT-TOOLING')).not.toThrow();
|
|
68
|
+
expect(() => validateInitIdFormat('INIT-A1')).not.toThrow();
|
|
69
|
+
});
|
|
70
|
+
it('should reject invalid formats', async () => {
|
|
71
|
+
const { validateInitIdFormat } = await import('../init-plan.js');
|
|
72
|
+
expect(() => validateInitIdFormat('init-001')).toThrow();
|
|
73
|
+
expect(() => validateInitIdFormat('INIT001')).toThrow();
|
|
74
|
+
expect(() => validateInitIdFormat('WU-001')).toThrow();
|
|
75
|
+
expect(() => validateInitIdFormat('')).toThrow();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('validatePlanPath', () => {
|
|
79
|
+
it('should accept existing markdown files', async () => {
|
|
80
|
+
const { validatePlanPath } = await import('../init-plan.js');
|
|
81
|
+
const planPath = join(tempDir, 'test-plan.md');
|
|
82
|
+
writeFileSync(planPath, '# Test Plan');
|
|
83
|
+
// Should not throw
|
|
84
|
+
expect(() => validatePlanPath(planPath)).not.toThrow();
|
|
85
|
+
});
|
|
86
|
+
it('should reject non-existent files when not creating', async () => {
|
|
87
|
+
const { validatePlanPath } = await import('../init-plan.js');
|
|
88
|
+
const planPath = join(tempDir, 'nonexistent.md');
|
|
89
|
+
expect(() => validatePlanPath(planPath)).toThrow();
|
|
90
|
+
});
|
|
91
|
+
it('should reject non-markdown files', async () => {
|
|
92
|
+
const { validatePlanPath } = await import('../init-plan.js');
|
|
93
|
+
const planPath = join(tempDir, 'test-plan.txt');
|
|
94
|
+
writeFileSync(planPath, 'Test Plan');
|
|
95
|
+
expect(() => validatePlanPath(planPath)).toThrow();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe('formatPlanUri', () => {
|
|
99
|
+
it('should format plan path as lumenflow:// URI', async () => {
|
|
100
|
+
const { formatPlanUri } = await import('../init-plan.js');
|
|
101
|
+
expect(formatPlanUri('docs/04-operations/plans/my-plan.md')).toBe('lumenflow://plans/my-plan.md');
|
|
102
|
+
});
|
|
103
|
+
it('should handle nested paths', async () => {
|
|
104
|
+
const { formatPlanUri } = await import('../init-plan.js');
|
|
105
|
+
expect(formatPlanUri('docs/04-operations/plans/subdir/nested-plan.md')).toBe('lumenflow://plans/subdir/nested-plan.md');
|
|
106
|
+
});
|
|
107
|
+
it('should handle paths not in standard location', async () => {
|
|
108
|
+
const { formatPlanUri } = await import('../init-plan.js');
|
|
109
|
+
// Should still create a URI even for non-standard paths
|
|
110
|
+
expect(formatPlanUri('/absolute/path/custom-plan.md')).toBe('lumenflow://plans/custom-plan.md');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('checkInitiativeExists', () => {
|
|
114
|
+
it('should return initiative doc if found', async () => {
|
|
115
|
+
const { checkInitiativeExists } = await import('../init-plan.js');
|
|
116
|
+
// Create a mock initiative file
|
|
117
|
+
const initDir = join(tempDir, 'docs', '04-operations', 'tasks', 'initiatives');
|
|
118
|
+
mkdirSync(initDir, { recursive: true });
|
|
119
|
+
const initPath = join(initDir, 'INIT-001.yaml');
|
|
120
|
+
const initDoc = {
|
|
121
|
+
id: 'INIT-001',
|
|
122
|
+
slug: 'test-initiative',
|
|
123
|
+
title: 'Test Initiative',
|
|
124
|
+
status: 'open',
|
|
125
|
+
created: '2026-01-25',
|
|
126
|
+
};
|
|
127
|
+
writeFileSync(initPath, stringifyYAML(initDoc));
|
|
128
|
+
process.chdir(tempDir);
|
|
129
|
+
const result = checkInitiativeExists('INIT-001');
|
|
130
|
+
expect(result.id).toBe('INIT-001');
|
|
131
|
+
});
|
|
132
|
+
it('should throw if initiative not found', async () => {
|
|
133
|
+
const { checkInitiativeExists } = await import('../init-plan.js');
|
|
134
|
+
process.chdir(tempDir);
|
|
135
|
+
expect(() => checkInitiativeExists('INIT-999')).toThrow();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('updateInitiativeWithPlan', () => {
|
|
139
|
+
it('should add related_plan field to initiative', async () => {
|
|
140
|
+
const { updateInitiativeWithPlan } = await import('../init-plan.js');
|
|
141
|
+
// Setup mock initiative
|
|
142
|
+
const initDir = join(tempDir, 'docs', '04-operations', 'tasks', 'initiatives');
|
|
143
|
+
mkdirSync(initDir, { recursive: true });
|
|
144
|
+
const initPath = join(initDir, 'INIT-001.yaml');
|
|
145
|
+
const initDoc = {
|
|
146
|
+
id: 'INIT-001',
|
|
147
|
+
slug: 'test-initiative',
|
|
148
|
+
title: 'Test Initiative',
|
|
149
|
+
status: 'open',
|
|
150
|
+
created: '2026-01-25',
|
|
151
|
+
};
|
|
152
|
+
writeFileSync(initPath, stringifyYAML(initDoc));
|
|
153
|
+
// Update initiative
|
|
154
|
+
const changed = updateInitiativeWithPlan(tempDir, 'INIT-001', 'lumenflow://plans/test-plan.md');
|
|
155
|
+
expect(changed).toBe(true);
|
|
156
|
+
// Verify the file was updated
|
|
157
|
+
const updated = parseYAML(readFileSync(initPath, 'utf-8'));
|
|
158
|
+
expect(updated.related_plan).toBe('lumenflow://plans/test-plan.md');
|
|
159
|
+
});
|
|
160
|
+
it('should return false if plan already linked (idempotent)', async () => {
|
|
161
|
+
const { updateInitiativeWithPlan } = await import('../init-plan.js');
|
|
162
|
+
// Setup mock initiative with existing plan
|
|
163
|
+
const initDir = join(tempDir, 'docs', '04-operations', 'tasks', 'initiatives');
|
|
164
|
+
mkdirSync(initDir, { recursive: true });
|
|
165
|
+
const initPath = join(initDir, 'INIT-001.yaml');
|
|
166
|
+
const initDoc = {
|
|
167
|
+
id: 'INIT-001',
|
|
168
|
+
slug: 'test-initiative',
|
|
169
|
+
title: 'Test Initiative',
|
|
170
|
+
status: 'open',
|
|
171
|
+
created: '2026-01-25',
|
|
172
|
+
related_plan: 'lumenflow://plans/test-plan.md',
|
|
173
|
+
};
|
|
174
|
+
writeFileSync(initPath, stringifyYAML(initDoc));
|
|
175
|
+
// Update initiative with same plan
|
|
176
|
+
const changed = updateInitiativeWithPlan(tempDir, 'INIT-001', 'lumenflow://plans/test-plan.md');
|
|
177
|
+
expect(changed).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
it('should warn but proceed if different plan already linked', async () => {
|
|
180
|
+
const { updateInitiativeWithPlan } = await import('../init-plan.js');
|
|
181
|
+
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
|
|
182
|
+
// Setup mock initiative with different plan
|
|
183
|
+
const initDir = join(tempDir, 'docs', '04-operations', 'tasks', 'initiatives');
|
|
184
|
+
mkdirSync(initDir, { recursive: true });
|
|
185
|
+
const initPath = join(initDir, 'INIT-001.yaml');
|
|
186
|
+
const initDoc = {
|
|
187
|
+
id: 'INIT-001',
|
|
188
|
+
slug: 'test-initiative',
|
|
189
|
+
title: 'Test Initiative',
|
|
190
|
+
status: 'open',
|
|
191
|
+
created: '2026-01-25',
|
|
192
|
+
related_plan: 'lumenflow://plans/old-plan.md',
|
|
193
|
+
};
|
|
194
|
+
writeFileSync(initPath, stringifyYAML(initDoc));
|
|
195
|
+
// Update initiative with new plan
|
|
196
|
+
const changed = updateInitiativeWithPlan(tempDir, 'INIT-001', 'lumenflow://plans/new-plan.md');
|
|
197
|
+
expect(changed).toBe(true);
|
|
198
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Replacing existing related_plan'));
|
|
199
|
+
consoleSpy.mockRestore();
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
describe('createPlanTemplate', () => {
|
|
203
|
+
it('should create a plan template file', async () => {
|
|
204
|
+
const { createPlanTemplate } = await import('../init-plan.js');
|
|
205
|
+
const plansDir = join(tempDir, 'docs', '04-operations', 'plans');
|
|
206
|
+
mkdirSync(plansDir, { recursive: true });
|
|
207
|
+
const planPath = createPlanTemplate(tempDir, 'INIT-001', 'Test Initiative');
|
|
208
|
+
expect(existsSync(planPath)).toBe(true);
|
|
209
|
+
const content = readFileSync(planPath, 'utf-8');
|
|
210
|
+
expect(content).toContain('# INIT-001');
|
|
211
|
+
expect(content).toContain('Test Initiative');
|
|
212
|
+
expect(content).toContain('## Goal');
|
|
213
|
+
expect(content).toContain('## Scope');
|
|
214
|
+
});
|
|
215
|
+
it('should not overwrite existing plan file', async () => {
|
|
216
|
+
const { createPlanTemplate } = await import('../init-plan.js');
|
|
217
|
+
const plansDir = join(tempDir, 'docs', '04-operations', 'plans');
|
|
218
|
+
mkdirSync(plansDir, { recursive: true });
|
|
219
|
+
// Create existing file
|
|
220
|
+
const existingPath = join(plansDir, 'INIT-001-test-initiative.md');
|
|
221
|
+
writeFileSync(existingPath, '# Existing Content');
|
|
222
|
+
expect(() => createPlanTemplate(tempDir, 'INIT-001', 'Test Initiative')).toThrow();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
describe('LOG_PREFIX', () => {
|
|
226
|
+
it('should use correct log prefix', async () => {
|
|
227
|
+
const { LOG_PREFIX } = await import('../init-plan.js');
|
|
228
|
+
expect(LOG_PREFIX).toBe('[init:plan]');
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
describe('getCommitMessage', () => {
|
|
232
|
+
it('should generate correct commit message', async () => {
|
|
233
|
+
const { getCommitMessage } = await import('../init-plan.js');
|
|
234
|
+
expect(getCommitMessage('INIT-001', 'lumenflow://plans/my-plan.md')).toBe('docs: link plan my-plan.md to init-001');
|
|
235
|
+
});
|
|
236
|
+
it('should handle nested plan paths', async () => {
|
|
237
|
+
const { getCommitMessage } = await import('../init-plan.js');
|
|
238
|
+
expect(getCommitMessage('INIT-TOOLING', 'lumenflow://plans/subdir/nested-plan.md')).toBe('docs: link plan subdir/nested-plan.md to init-tooling');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('updateInitiativeWithPlan ID mismatch', () => {
|
|
242
|
+
it('should throw if initiative ID does not match', async () => {
|
|
243
|
+
const { updateInitiativeWithPlan } = await import('../init-plan.js');
|
|
244
|
+
// Setup mock initiative with different ID
|
|
245
|
+
const initDir = join(tempDir, 'docs', '04-operations', 'tasks', 'initiatives');
|
|
246
|
+
mkdirSync(initDir, { recursive: true });
|
|
247
|
+
const initPath = join(initDir, 'INIT-001.yaml');
|
|
248
|
+
const initDoc = {
|
|
249
|
+
id: 'INIT-002', // Wrong ID
|
|
250
|
+
slug: 'test-initiative',
|
|
251
|
+
title: 'Test Initiative',
|
|
252
|
+
status: 'open',
|
|
253
|
+
created: '2026-01-25',
|
|
254
|
+
};
|
|
255
|
+
writeFileSync(initPath, stringifyYAML(initDoc));
|
|
256
|
+
expect(() => updateInitiativeWithPlan(tempDir, 'INIT-001', 'lumenflow://plans/test-plan.md')).toThrow();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
describe('init:plan CLI integration', () => {
|
|
261
|
+
it('should require --initiative flag', async () => {
|
|
262
|
+
// This test verifies that the CLI requires the initiative flag
|
|
263
|
+
// The actual CLI integration is tested via subprocess
|
|
264
|
+
const { WU_OPTIONS } = await import('@lumenflow/core/dist/arg-parser.js');
|
|
265
|
+
expect(WU_OPTIONS.initiative).toBeDefined();
|
|
266
|
+
expect(WU_OPTIONS.initiative.flags).toContain('--initiative');
|
|
267
|
+
});
|
|
268
|
+
it('should export main function for CLI entry', async () => {
|
|
269
|
+
const initPlan = await import('../init-plan.js');
|
|
270
|
+
expect(typeof initPlan.main).toBe('function');
|
|
271
|
+
});
|
|
272
|
+
it('should export all required functions', async () => {
|
|
273
|
+
const initPlan = await import('../init-plan.js');
|
|
274
|
+
expect(typeof initPlan.validateInitIdFormat).toBe('function');
|
|
275
|
+
expect(typeof initPlan.validatePlanPath).toBe('function');
|
|
276
|
+
expect(typeof initPlan.formatPlanUri).toBe('function');
|
|
277
|
+
expect(typeof initPlan.checkInitiativeExists).toBe('function');
|
|
278
|
+
expect(typeof initPlan.updateInitiativeWithPlan).toBe('function');
|
|
279
|
+
expect(typeof initPlan.createPlanTemplate).toBe('function');
|
|
280
|
+
expect(typeof initPlan.getCommitMessage).toBe('function');
|
|
281
|
+
expect(typeof initPlan.LOG_PREFIX).toBe('string');
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
describe('createPlanTemplate edge cases', () => {
|
|
285
|
+
let tempDir;
|
|
286
|
+
let originalCwd;
|
|
287
|
+
beforeEach(() => {
|
|
288
|
+
tempDir = join(tmpdir(), `init-plan-test-${Date.now()}`);
|
|
289
|
+
mkdirSync(tempDir, { recursive: true });
|
|
290
|
+
originalCwd = process.cwd();
|
|
291
|
+
});
|
|
292
|
+
afterEach(() => {
|
|
293
|
+
process.chdir(originalCwd);
|
|
294
|
+
if (existsSync(tempDir)) {
|
|
295
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
296
|
+
}
|
|
297
|
+
vi.clearAllMocks();
|
|
298
|
+
});
|
|
299
|
+
it('should create plans directory if it does not exist', async () => {
|
|
300
|
+
const { createPlanTemplate } = await import('../init-plan.js');
|
|
301
|
+
// Do NOT pre-create the plans directory
|
|
302
|
+
const planPath = createPlanTemplate(tempDir, 'INIT-001', 'Test Initiative');
|
|
303
|
+
expect(existsSync(planPath)).toBe(true);
|
|
304
|
+
expect(planPath).toContain('docs/04-operations/plans');
|
|
305
|
+
});
|
|
306
|
+
it('should truncate long titles in filename', async () => {
|
|
307
|
+
const { createPlanTemplate } = await import('../init-plan.js');
|
|
308
|
+
const longTitle = 'This is an extremely long initiative title that should be truncated in the filename';
|
|
309
|
+
const planPath = createPlanTemplate(tempDir, 'INIT-001', longTitle);
|
|
310
|
+
expect(existsSync(planPath)).toBe(true);
|
|
311
|
+
// Filename should be truncated
|
|
312
|
+
const filename = planPath.split('/').pop() || '';
|
|
313
|
+
// INIT-001- is 9 chars, .md is 3 chars, slug should be max 30 chars
|
|
314
|
+
expect(filename.length).toBeLessThanOrEqual(9 + 30 + 3);
|
|
315
|
+
});
|
|
316
|
+
it('should handle special characters in title', async () => {
|
|
317
|
+
const { createPlanTemplate } = await import('../init-plan.js');
|
|
318
|
+
const specialTitle = "Test's Initiative: (Special) Chars! @#$%";
|
|
319
|
+
const planPath = createPlanTemplate(tempDir, 'INIT-001', specialTitle);
|
|
320
|
+
expect(existsSync(planPath)).toBe(true);
|
|
321
|
+
// Filename should only have kebab-case characters
|
|
322
|
+
expect(planPath).toMatch(/INIT-001-[a-z0-9-]+\.md$/);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
/**
|
|
326
|
+
* Note on main() function testing:
|
|
327
|
+
*
|
|
328
|
+
* The main() function is intentionally not unit-tested because:
|
|
329
|
+
* 1. It calls die() which invokes process.exit() - difficult to mock without complex test infrastructure
|
|
330
|
+
* 2. It involves micro-worktree operations with git
|
|
331
|
+
* 3. All business logic functions it calls ARE thoroughly tested above
|
|
332
|
+
*
|
|
333
|
+
* The main() function is integration/orchestration code that composes the tested helper functions.
|
|
334
|
+
* Integration testing via subprocess (pnpm init:plan) is the appropriate testing strategy for main().
|
|
335
|
+
*
|
|
336
|
+
* Coverage statistics:
|
|
337
|
+
* - All exported helper functions: ~100% coverage
|
|
338
|
+
* - main() function: Not unit tested (orchestration code)
|
|
339
|
+
* - Overall file coverage: ~50% (acceptable for CLI commands)
|
|
340
|
+
*/
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Tests for lumenflow-upgrade CLI command
|
|
4
|
+
*
|
|
5
|
+
* WU-1112: INIT-003 Phase 6 - Migrate remaining Tier 1 tools
|
|
6
|
+
*
|
|
7
|
+
* lumenflow-upgrade updates all @lumenflow/* packages to latest versions.
|
|
8
|
+
* Key requirements:
|
|
9
|
+
* - Uses worktree pattern (runs pnpm install in worktree, not main)
|
|
10
|
+
* - Checks all 7 @lumenflow/* packages
|
|
11
|
+
*/
|
|
12
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
13
|
+
// Import functions under test
|
|
14
|
+
import { parseUpgradeArgs, LUMENFLOW_PACKAGES, buildUpgradeCommands, } from '../lumenflow-upgrade.js';
|
|
15
|
+
describe('lumenflow-upgrade', () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vi.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
describe('LUMENFLOW_PACKAGES constant', () => {
|
|
20
|
+
it('should include all 7 @lumenflow/* packages', () => {
|
|
21
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/agent');
|
|
22
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/cli');
|
|
23
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/core');
|
|
24
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/initiatives');
|
|
25
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/memory');
|
|
26
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/metrics');
|
|
27
|
+
expect(LUMENFLOW_PACKAGES).toContain('@lumenflow/shims');
|
|
28
|
+
expect(LUMENFLOW_PACKAGES).toHaveLength(7);
|
|
29
|
+
});
|
|
30
|
+
it('should have packages in alphabetical order', () => {
|
|
31
|
+
const sorted = [...LUMENFLOW_PACKAGES].sort();
|
|
32
|
+
expect(LUMENFLOW_PACKAGES).toEqual(sorted);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('parseUpgradeArgs', () => {
|
|
36
|
+
it('should parse --version flag', () => {
|
|
37
|
+
const args = parseUpgradeArgs(['node', 'lumenflow-upgrade.js', '--version', '1.5.0']);
|
|
38
|
+
expect(args.version).toBe('1.5.0');
|
|
39
|
+
});
|
|
40
|
+
it('should parse --latest flag', () => {
|
|
41
|
+
const args = parseUpgradeArgs(['node', 'lumenflow-upgrade.js', '--latest']);
|
|
42
|
+
expect(args.latest).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
it('should parse --dry-run flag', () => {
|
|
45
|
+
const args = parseUpgradeArgs(['node', 'lumenflow-upgrade.js', '--dry-run']);
|
|
46
|
+
expect(args.dryRun).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('should parse --help flag', () => {
|
|
49
|
+
const args = parseUpgradeArgs(['node', 'lumenflow-upgrade.js', '--help']);
|
|
50
|
+
expect(args.help).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
it('should default latest to false', () => {
|
|
53
|
+
const args = parseUpgradeArgs(['node', 'lumenflow-upgrade.js']);
|
|
54
|
+
expect(args.latest).toBeFalsy();
|
|
55
|
+
});
|
|
56
|
+
it('should default dryRun to false', () => {
|
|
57
|
+
const args = parseUpgradeArgs(['node', 'lumenflow-upgrade.js']);
|
|
58
|
+
expect(args.dryRun).toBeFalsy();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('buildUpgradeCommands', () => {
|
|
62
|
+
it('should build commands for specific version', () => {
|
|
63
|
+
const args = { version: '1.5.0' };
|
|
64
|
+
const commands = buildUpgradeCommands(args);
|
|
65
|
+
// Should have pnpm add command for all packages
|
|
66
|
+
expect(commands.addCommand).toContain('pnpm add');
|
|
67
|
+
expect(commands.addCommand).toContain('@lumenflow/agent@1.5.0');
|
|
68
|
+
expect(commands.addCommand).toContain('@lumenflow/cli@1.5.0');
|
|
69
|
+
expect(commands.addCommand).toContain('@lumenflow/core@1.5.0');
|
|
70
|
+
expect(commands.addCommand).toContain('@lumenflow/initiatives@1.5.0');
|
|
71
|
+
expect(commands.addCommand).toContain('@lumenflow/memory@1.5.0');
|
|
72
|
+
expect(commands.addCommand).toContain('@lumenflow/metrics@1.5.0');
|
|
73
|
+
expect(commands.addCommand).toContain('@lumenflow/shims@1.5.0');
|
|
74
|
+
});
|
|
75
|
+
it('should build commands for latest version', () => {
|
|
76
|
+
const args = { latest: true };
|
|
77
|
+
const commands = buildUpgradeCommands(args);
|
|
78
|
+
// Should have pnpm add command for all packages with @latest
|
|
79
|
+
expect(commands.addCommand).toContain('pnpm add');
|
|
80
|
+
expect(commands.addCommand).toContain('@lumenflow/agent@latest');
|
|
81
|
+
expect(commands.addCommand).toContain('@lumenflow/cli@latest');
|
|
82
|
+
});
|
|
83
|
+
it('should include dev dependencies flag', () => {
|
|
84
|
+
const args = { version: '1.5.0' };
|
|
85
|
+
const commands = buildUpgradeCommands(args);
|
|
86
|
+
// LumenFlow packages are dev dependencies
|
|
87
|
+
expect(commands.addCommand).toContain('--save-dev');
|
|
88
|
+
});
|
|
89
|
+
it('should include all 7 packages in the command', () => {
|
|
90
|
+
const args = { version: '1.5.0' };
|
|
91
|
+
const commands = buildUpgradeCommands(args);
|
|
92
|
+
// Count how many packages are in the command
|
|
93
|
+
const packageCount = LUMENFLOW_PACKAGES.filter((pkg) => commands.addCommand.includes(pkg)).length;
|
|
94
|
+
expect(packageCount).toBe(7);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('worktree pattern enforcement', () => {
|
|
98
|
+
it('should include note about worktree usage in commands', () => {
|
|
99
|
+
const args = { version: '1.5.0' };
|
|
100
|
+
const commands = buildUpgradeCommands(args);
|
|
101
|
+
// The command should be designed to run in worktree
|
|
102
|
+
// Actual execution is tested in integration tests
|
|
103
|
+
expect(commands.addCommand).toBeDefined();
|
|
104
|
+
expect(commands.addCommand.length).toBeGreaterThan(0);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|