@agentic-sdlc-kit/cli 1.0.1 → 1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-sdlc-kit/cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The `kit` executable: user-facing entry point for the Agentic SDLC Kit.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"src"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@agentic-sdlc-kit/contracts": "1.0
|
|
29
|
-
"@agentic-sdlc-kit/core": "1.0
|
|
28
|
+
"@agentic-sdlc-kit/contracts": "1.1.0",
|
|
29
|
+
"@agentic-sdlc-kit/core": "1.1.0",
|
|
30
30
|
"@modelcontextprotocol/sdk": "^1.32.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@agentic-sdlc-kit/testing": "1.0
|
|
33
|
+
"@agentic-sdlc-kit/testing": "1.1.0",
|
|
34
34
|
"@types/node": "^26.6.11",
|
|
35
35
|
"typescript": "^5.5.0",
|
|
36
36
|
"vitest": "^2.0.0"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// packages/cli/src/commands/evolve.test.ts
|
|
2
|
+
//
|
|
3
|
+
// CLI-layer tests for `kit evolve` (M31-M33): honest no-experience
|
|
4
|
+
// reporting (exit 1), the full no-benchmark pipeline over seeded
|
|
5
|
+
// experiences (distill → hypothesize → not-run verdicts → withheld
|
|
6
|
+
// metrics), --dry-run, and the --json surface.
|
|
7
|
+
//
|
|
8
|
+
// Seeded experiences use the real on-disk contract the command reads
|
|
9
|
+
// (.ai-kit/state/experiences.json); recurring failures on one stack
|
|
10
|
+
// produce one distilled lesson and one hypothesis whose Evolution Lab
|
|
11
|
+
// benchmark reports notImplemented — surfaced as verdict 'not-run',
|
|
12
|
+
// never as completed work (ADR-0018).
|
|
13
|
+
import { promises as fs } from 'node:fs';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import type { ExperienceRecord } from '@agentic-sdlc-kit/contracts';
|
|
17
|
+
import { describe, expect, it } from 'vitest';
|
|
18
|
+
import { evolveCommand } from './evolve.js';
|
|
19
|
+
import type { CommandContext } from './types.js';
|
|
20
|
+
|
|
21
|
+
const makeCtx = (
|
|
22
|
+
argv: string[],
|
|
23
|
+
cwd: string,
|
|
24
|
+
): CommandContext & { out: string[]; err: string[] } => {
|
|
25
|
+
const out: string[] = [];
|
|
26
|
+
const err: string[] = [];
|
|
27
|
+
return {
|
|
28
|
+
argv,
|
|
29
|
+
cwd,
|
|
30
|
+
stdout: (s) => void out.push(s),
|
|
31
|
+
stderr: (s) => void err.push(s),
|
|
32
|
+
out,
|
|
33
|
+
err,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function failureRecord(id: string): ExperienceRecord {
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
workflowId: 'feature',
|
|
41
|
+
featureId: 'FEATURE-001',
|
|
42
|
+
stack: 'node-typescript',
|
|
43
|
+
outcome: 'failure',
|
|
44
|
+
phases: [
|
|
45
|
+
{ name: 'specification', status: 'passed', durationMs: 100 },
|
|
46
|
+
{ name: 'implementation', status: 'failed', durationMs: 500 },
|
|
47
|
+
{ name: 'verification', status: 'passed', durationMs: 200 },
|
|
48
|
+
],
|
|
49
|
+
failureSummary: 'TASK-001: AssertionError: expected marker to exist',
|
|
50
|
+
timestamp: '2026-01-01T00:00:00.000Z',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function seedExperiences(root: string, records: readonly ExperienceRecord[]): Promise<void> {
|
|
55
|
+
const target = path.join(root, '.ai-kit', 'state', 'experiences.json');
|
|
56
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
57
|
+
await fs.writeFile(target, JSON.stringify({ schemaVersion: 1, records }, null, 2) + '\n', 'utf8');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function tmpRoot(): Promise<string> {
|
|
61
|
+
return fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-evolve-'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('kit evolve', () => {
|
|
65
|
+
it('shows usage with --help and exits 0', async () => {
|
|
66
|
+
const ctx = makeCtx(['--help'], await tmpRoot());
|
|
67
|
+
const result = await evolveCommand.run(ctx);
|
|
68
|
+
expect(result.exitCode).toBe(0);
|
|
69
|
+
expect(ctx.out.join('')).toContain('Usage: kit evolve [--dry-run] [--json]');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('fails honestly (exit 1) when no experiences have been accumulated', async () => {
|
|
73
|
+
const ctx = makeCtx([], await tmpRoot());
|
|
74
|
+
const result = await evolveCommand.run(ctx);
|
|
75
|
+
expect(result.exitCode).toBe(1);
|
|
76
|
+
expect(result.message).toBe('no experiences to distill');
|
|
77
|
+
const text = ctx.out.join('');
|
|
78
|
+
expect(text).toContain('no experience records found');
|
|
79
|
+
expect(text).toContain('kit feature');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('reports the no-experience state as JSON with --json', async () => {
|
|
83
|
+
const ctx = makeCtx(['--json'], await tmpRoot());
|
|
84
|
+
const result = await evolveCommand.run(ctx);
|
|
85
|
+
expect(result.exitCode).toBe(1);
|
|
86
|
+
const payload = JSON.parse(ctx.out.join('')) as { error: string };
|
|
87
|
+
expect(payload.error).toBe('no-experiences');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('distills lessons from recurring failures and reports the lab honestly as NOT RUN', async () => {
|
|
91
|
+
const root = await tmpRoot();
|
|
92
|
+
// Three independent failures on the same stack and phase → one
|
|
93
|
+
// distilled lesson with confidence 0.8 (>= 0.7) → one hypothesis.
|
|
94
|
+
await seedExperiences(root, [
|
|
95
|
+
failureRecord('EXP-001'),
|
|
96
|
+
failureRecord('EXP-002'),
|
|
97
|
+
failureRecord('EXP-003'),
|
|
98
|
+
]);
|
|
99
|
+
const ctx = makeCtx([], root);
|
|
100
|
+
const result = await evolveCommand.run(ctx);
|
|
101
|
+
expect(result.exitCode).toBe(0);
|
|
102
|
+
const text = ctx.out.join('');
|
|
103
|
+
expect(text).toContain('Experiences Loaded: 3');
|
|
104
|
+
expect(text).toContain('Distilled Lessons: 1');
|
|
105
|
+
expect(text).toContain('Hypotheses: 1');
|
|
106
|
+
expect(text).toContain('Evolution Lab: NOT RUN (benchmark environment unavailable)');
|
|
107
|
+
expect(text).toContain('Metrics: withheld (no executed benchmarks)');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('emits the machine-readable report with --json', async () => {
|
|
111
|
+
const root = await tmpRoot();
|
|
112
|
+
await seedExperiences(root, [
|
|
113
|
+
failureRecord('EXP-001'),
|
|
114
|
+
failureRecord('EXP-002'),
|
|
115
|
+
failureRecord('EXP-003'),
|
|
116
|
+
]);
|
|
117
|
+
const ctx = makeCtx(['--json', '--dry-run'], root);
|
|
118
|
+
const result = await evolveCommand.run(ctx);
|
|
119
|
+
expect(result.exitCode).toBe(0);
|
|
120
|
+
const payload = JSON.parse(ctx.out.join('')) as {
|
|
121
|
+
experiencesLoaded: number;
|
|
122
|
+
distilledLessons: number;
|
|
123
|
+
hypothesesGenerated: number;
|
|
124
|
+
benchmarksExecuted: number;
|
|
125
|
+
benchmarksNotRun: number;
|
|
126
|
+
metrics: null | Record<string, unknown>;
|
|
127
|
+
};
|
|
128
|
+
expect(payload.experiencesLoaded).toBe(3);
|
|
129
|
+
expect(payload.distilledLessons).toBe(1);
|
|
130
|
+
expect(payload.hypothesesGenerated).toBe(1);
|
|
131
|
+
expect(payload.benchmarksExecuted).toBe(0);
|
|
132
|
+
expect(payload.benchmarksNotRun).toBe(1);
|
|
133
|
+
expect(payload.metrics).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('persists distilled lessons to .ai-kit/state/memory.json', async () => {
|
|
137
|
+
const root = await tmpRoot();
|
|
138
|
+
await seedExperiences(root, [
|
|
139
|
+
failureRecord('EXP-001'),
|
|
140
|
+
failureRecord('EXP-002'),
|
|
141
|
+
failureRecord('EXP-003'),
|
|
142
|
+
]);
|
|
143
|
+
const result = await evolveCommand.run(makeCtx(['--dry-run'], root));
|
|
144
|
+
expect(result.exitCode).toBe(0);
|
|
145
|
+
const memoryFile = path.join(root, '.ai-kit', 'state', 'memory.json');
|
|
146
|
+
const stored = JSON.parse(await fs.readFile(memoryFile, 'utf8')) as {
|
|
147
|
+
entries: Array<{ id: string; type: string; domain: string }>;
|
|
148
|
+
};
|
|
149
|
+
expect(stored.entries).toHaveLength(1);
|
|
150
|
+
expect(stored.entries[0]?.type).toBe('semantic');
|
|
151
|
+
expect(stored.entries[0]?.domain).toBe('node-typescript');
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// packages/cli/src/commands/journal.test.ts
|
|
2
|
+
//
|
|
3
|
+
// CLI-layer tests for `kit journal` argument handling and output
|
|
4
|
+
// formatting (the chain-integration paths — read/verify/tamper on a
|
|
5
|
+
// driven feature run — are covered in next.test.ts). This file covers
|
|
6
|
+
// --help, the missing-identifier validation, empty journals, --limit
|
|
7
|
+
// truncation, and the --verify --json machine surface.
|
|
8
|
+
import { promises as fs } from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { appendJournalEvent } from '@agentic-sdlc-kit/core';
|
|
13
|
+
import { journalCommand } from './journal.js';
|
|
14
|
+
import type { CommandContext } from './types.js';
|
|
15
|
+
|
|
16
|
+
const makeCtx = (
|
|
17
|
+
argv: string[],
|
|
18
|
+
cwd: string,
|
|
19
|
+
): CommandContext & { out: string[]; err: string[] } => {
|
|
20
|
+
const out: string[] = [];
|
|
21
|
+
const err: string[] = [];
|
|
22
|
+
return {
|
|
23
|
+
argv,
|
|
24
|
+
cwd,
|
|
25
|
+
stdout: (s) => void out.push(s),
|
|
26
|
+
stderr: (s) => void err.push(s),
|
|
27
|
+
out,
|
|
28
|
+
err,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
async function tmpRoot(): Promise<string> {
|
|
33
|
+
return fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-journal-'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function seedEvents(root: string, featureId: string, count: number): Promise<void> {
|
|
37
|
+
for (let i = 0; i < count; i++) {
|
|
38
|
+
const res = await appendJournalEvent(root, {
|
|
39
|
+
featureId,
|
|
40
|
+
kind: 'workflow.started',
|
|
41
|
+
actor: { kind: 'kit' },
|
|
42
|
+
payload: { attempt: i },
|
|
43
|
+
});
|
|
44
|
+
expect(res.ok).toBe(true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('kit journal (argument handling)', () => {
|
|
49
|
+
it('shows usage with --help and exits 0', async () => {
|
|
50
|
+
const ctx = makeCtx(['--help'], await tmpRoot());
|
|
51
|
+
const result = await journalCommand.run(ctx);
|
|
52
|
+
expect(result.exitCode).toBe(0);
|
|
53
|
+
expect(ctx.out.join('')).toContain('Usage: kit journal <feature-id>');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('fails (exit 1) when the feature identifier is missing', async () => {
|
|
57
|
+
const ctx = makeCtx([], await tmpRoot());
|
|
58
|
+
const result = await journalCommand.run(ctx);
|
|
59
|
+
expect(result.exitCode).toBe(1);
|
|
60
|
+
expect(ctx.err.join('')).toContain('missing required feature identifier');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('kit journal (reading)', () => {
|
|
65
|
+
it('lists seeded events in human form', async () => {
|
|
66
|
+
const root = await tmpRoot();
|
|
67
|
+
await seedEvents(root, 'FEATURE-001', 2);
|
|
68
|
+
const ctx = makeCtx(['FEATURE-001'], root);
|
|
69
|
+
const result = await journalCommand.run(ctx);
|
|
70
|
+
expect(result.exitCode).toBe(0);
|
|
71
|
+
const text = ctx.out.join('');
|
|
72
|
+
expect(text).toContain('[0]');
|
|
73
|
+
expect(text).toContain('[1]');
|
|
74
|
+
expect(text).toContain('workflow.started');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('emits machine-readable events with --json', async () => {
|
|
78
|
+
const root = await tmpRoot();
|
|
79
|
+
await seedEvents(root, 'FEATURE-001', 2);
|
|
80
|
+
const ctx = makeCtx(['FEATURE-001', '--json'], root);
|
|
81
|
+
const result = await journalCommand.run(ctx);
|
|
82
|
+
expect(result.exitCode).toBe(0);
|
|
83
|
+
const events = JSON.parse(ctx.out.join('')) as Array<{ seq: number; kind: string }>;
|
|
84
|
+
expect(events).toHaveLength(2);
|
|
85
|
+
expect(events[0]?.seq).toBe(0);
|
|
86
|
+
expect(events[1]?.kind).toBe('workflow.started');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('hides earlier events with --limit N', async () => {
|
|
90
|
+
const root = await tmpRoot();
|
|
91
|
+
await seedEvents(root, 'FEATURE-001', 5);
|
|
92
|
+
const ctx = makeCtx(['FEATURE-001', '--limit', '2'], root);
|
|
93
|
+
const result = await journalCommand.run(ctx);
|
|
94
|
+
expect(result.exitCode).toBe(0);
|
|
95
|
+
const text = ctx.out.join('');
|
|
96
|
+
expect(text).toContain('3 earlier event(s) hidden');
|
|
97
|
+
expect(text).toContain('[4]');
|
|
98
|
+
expect(text).not.toContain('[0]');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('reports an empty journal honestly', async () => {
|
|
102
|
+
const root = await tmpRoot();
|
|
103
|
+
const file = path.join(root, '.ai-kit', 'journal', 'feature-runs', 'FEATURE-001.jsonl');
|
|
104
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
105
|
+
await fs.writeFile(file, '', 'utf8');
|
|
106
|
+
const ctx = makeCtx(['FEATURE-001'], root);
|
|
107
|
+
const result = await journalCommand.run(ctx);
|
|
108
|
+
expect(result.exitCode).toBe(0);
|
|
109
|
+
expect(ctx.out.join('')).toContain('is empty');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('fails (exit 1) when the journal does not exist', async () => {
|
|
113
|
+
const ctx = makeCtx(['FEATURE-404'], await tmpRoot());
|
|
114
|
+
const result = await journalCommand.run(ctx);
|
|
115
|
+
expect(result.exitCode).toBe(1);
|
|
116
|
+
expect(ctx.err.join('')).toContain('No journal found');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('kit journal (verification)', () => {
|
|
121
|
+
it('verifies a seeded chain (exit 0, human form)', async () => {
|
|
122
|
+
const root = await tmpRoot();
|
|
123
|
+
await seedEvents(root, 'FEATURE-001', 3);
|
|
124
|
+
const ctx = makeCtx(['FEATURE-001', '--verify'], root);
|
|
125
|
+
const result = await journalCommand.run(ctx);
|
|
126
|
+
expect(result.exitCode).toBe(0);
|
|
127
|
+
const text = ctx.out.join('');
|
|
128
|
+
expect(text).toContain('Journal verified for FEATURE-001: 3 event(s)');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('emits the verification result as JSON with --verify --json', async () => {
|
|
132
|
+
const root = await tmpRoot();
|
|
133
|
+
await seedEvents(root, 'FEATURE-001', 2);
|
|
134
|
+
const ctx = makeCtx(['FEATURE-001', '--verify', '--json'], root);
|
|
135
|
+
const result = await journalCommand.run(ctx);
|
|
136
|
+
expect(result.exitCode).toBe(0);
|
|
137
|
+
const payload = JSON.parse(ctx.out.join('')) as {
|
|
138
|
+
featureId: string;
|
|
139
|
+
valid: boolean;
|
|
140
|
+
eventCount: number;
|
|
141
|
+
lastHash?: string;
|
|
142
|
+
};
|
|
143
|
+
expect(payload.featureId).toBe('FEATURE-001');
|
|
144
|
+
expect(payload.valid).toBe(true);
|
|
145
|
+
expect(payload.eventCount).toBe(2);
|
|
146
|
+
if (payload.eventCount > 0) {
|
|
147
|
+
expect(payload.lastHash).toMatch(/^[0-9a-f]{64}$/);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// packages/cli/src/commands/memory.test.ts
|
|
2
|
+
//
|
|
3
|
+
// CLI-layer tests for `kit memory` (M29): honest no-memory reporting,
|
|
4
|
+
// query search, --list, --domain filtering, and the --json surface.
|
|
5
|
+
// The persisted memory is seeded through the real MemoryStore
|
|
6
|
+
// (saveToDisk), so the tests exercise the exact on-disk contract the
|
|
7
|
+
// command reads (.ai-kit/state/memory.json).
|
|
8
|
+
import { promises as fs } from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { MemoryStore } from '@agentic-sdlc-kit/core';
|
|
12
|
+
import type { MemoryEntry } from '@agentic-sdlc-kit/contracts';
|
|
13
|
+
import { describe, expect, it } from 'vitest';
|
|
14
|
+
import { memoryCommand } from './memory.js';
|
|
15
|
+
import type { CommandContext } from './types.js';
|
|
16
|
+
|
|
17
|
+
const makeCtx = (
|
|
18
|
+
argv: string[],
|
|
19
|
+
cwd: string,
|
|
20
|
+
): CommandContext & { out: string[]; err: string[] } => {
|
|
21
|
+
const out: string[] = [];
|
|
22
|
+
const err: string[] = [];
|
|
23
|
+
return {
|
|
24
|
+
argv,
|
|
25
|
+
cwd,
|
|
26
|
+
stdout: (s) => void out.push(s),
|
|
27
|
+
stderr: (s) => void err.push(s),
|
|
28
|
+
out,
|
|
29
|
+
err,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function entry(overrides: Partial<MemoryEntry> = {}): MemoryEntry {
|
|
34
|
+
return {
|
|
35
|
+
id: 'MEM-001',
|
|
36
|
+
type: 'semantic',
|
|
37
|
+
domain: 'architecture',
|
|
38
|
+
summary: 'Keep contracts package dependency-free',
|
|
39
|
+
content: 'The contracts package must import nothing from sibling packages.',
|
|
40
|
+
confidence: 0.8,
|
|
41
|
+
provenance: ['FEATURE-001'],
|
|
42
|
+
appliedCount: 2,
|
|
43
|
+
successCount: 2,
|
|
44
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
45
|
+
updatedAt: '2026-01-01T00:00:00.000Z',
|
|
46
|
+
...overrides,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function seedMemory(root: string, entries: readonly MemoryEntry[]): Promise<void> {
|
|
51
|
+
const store = new MemoryStore();
|
|
52
|
+
for (const e of entries) store.put(e);
|
|
53
|
+
await store.saveToDisk(root);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function tmpRoot(): Promise<string> {
|
|
57
|
+
return fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-memory-'));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('kit memory', () => {
|
|
61
|
+
it('shows usage with --help and exits 0', async () => {
|
|
62
|
+
const ctx = makeCtx(['--help'], await tmpRoot());
|
|
63
|
+
const result = await memoryCommand.run(ctx);
|
|
64
|
+
expect(result.exitCode).toBe(0);
|
|
65
|
+
expect(ctx.out.join('')).toContain('Usage: kit memory [query]');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('reports honestly when no memory has been accumulated yet', async () => {
|
|
69
|
+
const ctx = makeCtx(['architecture'], await tmpRoot());
|
|
70
|
+
const result = await memoryCommand.run(ctx);
|
|
71
|
+
expect(result.exitCode).toBe(0);
|
|
72
|
+
const text = ctx.out.join('');
|
|
73
|
+
expect(text).toContain('no memory entries found');
|
|
74
|
+
expect(text).toContain('kit evolve');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('reports the empty state as JSON with --json', async () => {
|
|
78
|
+
const ctx = makeCtx(['--json'], await tmpRoot());
|
|
79
|
+
const result = await memoryCommand.run(ctx);
|
|
80
|
+
expect(result.exitCode).toBe(0);
|
|
81
|
+
const payload = JSON.parse(ctx.out.join('')) as { entries: unknown[]; message: string };
|
|
82
|
+
expect(payload.entries).toEqual([]);
|
|
83
|
+
expect(payload.message).toContain('no memory entries found');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('finds memory entries by query text', async () => {
|
|
87
|
+
const root = await tmpRoot();
|
|
88
|
+
await seedMemory(root, [entry()]);
|
|
89
|
+
const ctx = makeCtx(['contracts'], root);
|
|
90
|
+
const result = await memoryCommand.run(ctx);
|
|
91
|
+
expect(result.exitCode).toBe(0);
|
|
92
|
+
const text = ctx.out.join('');
|
|
93
|
+
expect(text).toContain('Found 1 memory entries');
|
|
94
|
+
expect(text).toContain('MEM-001');
|
|
95
|
+
expect(text).toContain('[SEMANTIC]');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('says so when a query matches nothing', async () => {
|
|
99
|
+
const root = await tmpRoot();
|
|
100
|
+
await seedMemory(root, [entry()]);
|
|
101
|
+
const ctx = makeCtx(['kubernetes'], root);
|
|
102
|
+
const result = await memoryCommand.run(ctx);
|
|
103
|
+
expect(result.exitCode).toBe(0);
|
|
104
|
+
expect(ctx.out.join('')).toContain('No matching engineering memories found');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('lists all entries with --list', async () => {
|
|
108
|
+
const root = await tmpRoot();
|
|
109
|
+
await seedMemory(root, [
|
|
110
|
+
entry(),
|
|
111
|
+
entry({ id: 'MEM-002', type: 'procedural', domain: 'tdd', summary: 'Red before Green' }),
|
|
112
|
+
]);
|
|
113
|
+
const ctx = makeCtx(['--list'], root);
|
|
114
|
+
const result = await memoryCommand.run(ctx);
|
|
115
|
+
expect(result.exitCode).toBe(0);
|
|
116
|
+
const text = ctx.out.join('');
|
|
117
|
+
expect(text).toContain('MEM-001');
|
|
118
|
+
expect(text).toContain('MEM-002');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('filters --list output by --domain', async () => {
|
|
122
|
+
const root = await tmpRoot();
|
|
123
|
+
await seedMemory(root, [
|
|
124
|
+
entry(),
|
|
125
|
+
entry({ id: 'MEM-002', domain: 'tdd', summary: 'Red before Green' }),
|
|
126
|
+
]);
|
|
127
|
+
const ctx = makeCtx(['--list', '--domain', 'tdd'], root);
|
|
128
|
+
const result = await memoryCommand.run(ctx);
|
|
129
|
+
expect(result.exitCode).toBe(0);
|
|
130
|
+
const text = ctx.out.join('');
|
|
131
|
+
expect(text).not.toContain('MEM-001');
|
|
132
|
+
expect(text).toContain('MEM-002');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('emits machine-readable entries with --json', async () => {
|
|
136
|
+
const root = await tmpRoot();
|
|
137
|
+
await seedMemory(root, [entry()]);
|
|
138
|
+
const ctx = makeCtx(['--json', '--list'], root);
|
|
139
|
+
const result = await memoryCommand.run(ctx);
|
|
140
|
+
expect(result.exitCode).toBe(0);
|
|
141
|
+
const entries = JSON.parse(ctx.out.join('')) as Array<{ id: string; domain: string }>;
|
|
142
|
+
expect(entries).toHaveLength(1);
|
|
143
|
+
expect(entries[0]?.id).toBe('MEM-001');
|
|
144
|
+
expect(entries[0]?.domain).toBe('architecture');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// packages/cli/src/commands/optimize.test.ts
|
|
2
|
+
//
|
|
3
|
+
// CLI-layer tests for `kit optimize`: the informational surface of the
|
|
4
|
+
// M9 optimization workflow — exit code, baseline invariant, and the
|
|
5
|
+
// guidance content the host workflow expects.
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { optimizeCommand } from './optimize.js';
|
|
8
|
+
import type { CommandContext } from './types.js';
|
|
9
|
+
|
|
10
|
+
const makeCtx = (argv: string[], cwd = '/'): CommandContext & { out: string[]; err: string[] } => {
|
|
11
|
+
const out: string[] = [];
|
|
12
|
+
const err: string[] = [];
|
|
13
|
+
return {
|
|
14
|
+
argv,
|
|
15
|
+
cwd,
|
|
16
|
+
stdout: (s) => void out.push(s),
|
|
17
|
+
stderr: (s) => void err.push(s),
|
|
18
|
+
out,
|
|
19
|
+
err,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('kit optimize', () => {
|
|
24
|
+
it('exits 0 and prints the workflow guidance', () => {
|
|
25
|
+
const ctx = makeCtx([]);
|
|
26
|
+
const result = optimizeCommand.run(ctx);
|
|
27
|
+
expect(result.exitCode).toBe(0);
|
|
28
|
+
const text = ctx.out.join('');
|
|
29
|
+
expect(text).toContain('kit optimize — Performance optimization workflow');
|
|
30
|
+
expect(text).toContain('Expected lifecycle:');
|
|
31
|
+
expect(text).toContain('baseline');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('states the baseline measurement invariant', () => {
|
|
35
|
+
const ctx = makeCtx([]);
|
|
36
|
+
optimizeCommand.run(ctx);
|
|
37
|
+
const text = ctx.out.join('');
|
|
38
|
+
expect(text).toContain('performance optimization requires baseline');
|
|
39
|
+
expect(text).toContain('without an established baseline');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('declares its release status honestly', () => {
|
|
43
|
+
const ctx = makeCtx([]);
|
|
44
|
+
optimizeCommand.run(ctx);
|
|
45
|
+
expect(ctx.out.join('')).toContain('Status: declared in 0.6.0');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('never writes to stderr', () => {
|
|
49
|
+
const ctx = makeCtx([]);
|
|
50
|
+
optimizeCommand.run(ctx);
|
|
51
|
+
expect(ctx.err.join('')).toBe('');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// packages/cli/src/commands/refactor.test.ts
|
|
2
|
+
//
|
|
3
|
+
// CLI-layer tests for `kit refactor`: the informational surface of the
|
|
4
|
+
// M9 refactoring workflow — exit code, lifecycle description, and the
|
|
5
|
+
// behavioral-preservation constraints.
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { refactorCommand } from './refactor.js';
|
|
8
|
+
import type { CommandContext } from './types.js';
|
|
9
|
+
|
|
10
|
+
const makeCtx = (argv: string[], cwd = '/'): CommandContext & { out: string[]; err: string[] } => {
|
|
11
|
+
const out: string[] = [];
|
|
12
|
+
const err: string[] = [];
|
|
13
|
+
return {
|
|
14
|
+
argv,
|
|
15
|
+
cwd,
|
|
16
|
+
stdout: (s) => void out.push(s),
|
|
17
|
+
stderr: (s) => void err.push(s),
|
|
18
|
+
out,
|
|
19
|
+
err,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('kit refactor', () => {
|
|
24
|
+
it('exits 0 and prints the workflow guidance', () => {
|
|
25
|
+
const ctx = makeCtx([]);
|
|
26
|
+
const result = refactorCommand.run(ctx);
|
|
27
|
+
expect(result.exitCode).toBe(0);
|
|
28
|
+
const text = ctx.out.join('');
|
|
29
|
+
expect(text).toContain('kit refactor — Refactoring workflow');
|
|
30
|
+
expect(text).toContain('driven by your AI assistant');
|
|
31
|
+
expect(text).toContain('/kit:refactor <target module and goal>');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('lists the M9 lifecycle stages', () => {
|
|
35
|
+
const ctx = makeCtx([]);
|
|
36
|
+
refactorCommand.run(ctx);
|
|
37
|
+
const text = ctx.out.join('');
|
|
38
|
+
expect(text).toContain('characterization-tests');
|
|
39
|
+
expect(text).toContain('incremental-refactor');
|
|
40
|
+
expect(text).toContain('regression-testing');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('states the behavior-preservation constraints', () => {
|
|
44
|
+
const ctx = makeCtx([]);
|
|
45
|
+
refactorCommand.run(ctx);
|
|
46
|
+
const text = ctx.out.join('');
|
|
47
|
+
expect(text).toContain('Preserve observable behavior');
|
|
48
|
+
expect(text).toContain('Establish baseline tests before structural changes');
|
|
49
|
+
expect(text).toContain('Do not use a design pattern simply because it exists');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('never writes to stderr', () => {
|
|
53
|
+
const ctx = makeCtx([]);
|
|
54
|
+
refactorCommand.run(ctx);
|
|
55
|
+
expect(ctx.err.join('')).toBe('');
|
|
56
|
+
});
|
|
57
|
+
});
|