@laitszkin/apollo-toolkit 4.0.11 → 4.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/AGENTS.md +37 -27
- package/CHANGELOG.md +31 -0
- package/CLAUDE.md +37 -27
- package/README.md +15 -2
- package/assets/spec/rg13-1780435029246/test-questions.json +1 -0
- package/assets/spec/rg13-1780468345132/test-questions.json +1 -0
- package/package.json +3 -3
- package/packages/cli/dist/tool-registration.js +1 -0
- package/packages/cli/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/cli/tool-registration.ts +1 -0
- package/packages/tools/architecture/dist/index.js +539 -2
- package/packages/tools/architecture/dist/index.test.d.ts +1 -0
- package/packages/tools/architecture/dist/index.test.js +229 -0
- package/packages/tools/architecture/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/tools/architecture/index.test.ts +329 -0
- package/packages/tools/architecture/index.ts +607 -5
- package/packages/tools/codegraph/dist/index.d.ts +3 -0
- package/packages/tools/codegraph/dist/index.js +157 -0
- package/packages/tools/codegraph/dist/lib/cg-instance.d.ts +29 -0
- package/packages/tools/codegraph/dist/lib/cg-instance.js +59 -0
- package/packages/tools/codegraph/dist/lib/cg-instance.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cg-instance.test.js +27 -0
- package/packages/tools/codegraph/dist/lib/cmd-explore.d.ts +5 -0
- package/packages/tools/codegraph/dist/lib/cmd-explore.js +95 -0
- package/packages/tools/codegraph/dist/lib/cmd-explore.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-explore.test.js +133 -0
- package/packages/tools/codegraph/dist/lib/cmd-flag-splice.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-flag-splice.test.js +83 -0
- package/packages/tools/codegraph/dist/lib/cmd-init.d.ts +5 -0
- package/packages/tools/codegraph/dist/lib/cmd-init.js +50 -0
- package/packages/tools/codegraph/dist/lib/cmd-init.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-init.test.js +51 -0
- package/packages/tools/codegraph/dist/lib/cmd-list-apis.d.ts +5 -0
- package/packages/tools/codegraph/dist/lib/cmd-list-apis.js +64 -0
- package/packages/tools/codegraph/dist/lib/cmd-list-apis.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-list-apis.test.js +69 -0
- package/packages/tools/codegraph/dist/lib/cmd-search.d.ts +5 -0
- package/packages/tools/codegraph/dist/lib/cmd-search.js +21 -0
- package/packages/tools/codegraph/dist/lib/cmd-search.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-search.test.js +30 -0
- package/packages/tools/codegraph/dist/lib/cmd-status.d.ts +4 -0
- package/packages/tools/codegraph/dist/lib/cmd-status.js +44 -0
- package/packages/tools/codegraph/dist/lib/cmd-status.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-status.test.js +72 -0
- package/packages/tools/codegraph/dist/lib/cmd-survey.d.ts +36 -0
- package/packages/tools/codegraph/dist/lib/cmd-survey.js +142 -0
- package/packages/tools/codegraph/dist/lib/cmd-survey.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-survey.test.js +136 -0
- package/packages/tools/codegraph/dist/lib/cmd-sync.d.ts +4 -0
- package/packages/tools/codegraph/dist/lib/cmd-sync.js +51 -0
- package/packages/tools/codegraph/dist/lib/cmd-sync.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-sync.test.js +30 -0
- package/packages/tools/codegraph/dist/lib/cmd-verify.d.ts +4 -0
- package/packages/tools/codegraph/dist/lib/cmd-verify.js +134 -0
- package/packages/tools/codegraph/dist/lib/cmd-verify.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/cmd-verify.test.js +139 -0
- package/packages/tools/codegraph/dist/lib/formatter.d.ts +67 -0
- package/packages/tools/codegraph/dist/lib/formatter.js +107 -0
- package/packages/tools/codegraph/dist/lib/formatter.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/formatter.test.js +41 -0
- package/packages/tools/codegraph/dist/lib/survey/grouper.d.ts +19 -0
- package/packages/tools/codegraph/dist/lib/survey/grouper.js +194 -0
- package/packages/tools/codegraph/dist/lib/survey/grouper.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/survey/grouper.test.js +62 -0
- package/packages/tools/codegraph/dist/lib/survey/scanner.d.ts +31 -0
- package/packages/tools/codegraph/dist/lib/survey/scanner.js +50 -0
- package/packages/tools/codegraph/dist/lib/verify/checker.d.ts +32 -0
- package/packages/tools/codegraph/dist/lib/verify/checker.js +146 -0
- package/packages/tools/codegraph/dist/lib/verify/checker.test.d.ts +1 -0
- package/packages/tools/codegraph/dist/lib/verify/checker.test.js +128 -0
- package/packages/tools/codegraph/dist/tsconfig.tsbuildinfo +1 -0
- package/packages/tools/codegraph/env.d.ts +56 -0
- package/packages/tools/codegraph/index.ts +173 -0
- package/packages/tools/codegraph/lib/cg-instance.test.ts +36 -0
- package/packages/tools/codegraph/lib/cg-instance.ts +66 -0
- package/packages/tools/codegraph/lib/cmd-explore.test.ts +195 -0
- package/packages/tools/codegraph/lib/cmd-explore.ts +129 -0
- package/packages/tools/codegraph/lib/cmd-flag-splice.test.ts +94 -0
- package/packages/tools/codegraph/lib/cmd-init.test.ts +68 -0
- package/packages/tools/codegraph/lib/cmd-init.ts +60 -0
- package/packages/tools/codegraph/lib/cmd-list-apis.test.ts +80 -0
- package/packages/tools/codegraph/lib/cmd-list-apis.ts +90 -0
- package/packages/tools/codegraph/lib/cmd-search.test.ts +37 -0
- package/packages/tools/codegraph/lib/cmd-search.ts +32 -0
- package/packages/tools/codegraph/lib/cmd-status.test.ts +86 -0
- package/packages/tools/codegraph/lib/cmd-status.ts +53 -0
- package/packages/tools/codegraph/lib/cmd-survey.test.ts +161 -0
- package/packages/tools/codegraph/lib/cmd-survey.ts +199 -0
- package/packages/tools/codegraph/lib/cmd-sync.test.ts +41 -0
- package/packages/tools/codegraph/lib/cmd-sync.ts +62 -0
- package/packages/tools/codegraph/lib/cmd-verify.test.ts +162 -0
- package/packages/tools/codegraph/lib/cmd-verify.ts +145 -0
- package/packages/tools/codegraph/lib/formatter.test.ts +47 -0
- package/packages/tools/codegraph/lib/formatter.ts +130 -0
- package/packages/tools/codegraph/lib/survey/grouper.test.ts +72 -0
- package/packages/tools/codegraph/lib/survey/grouper.ts +226 -0
- package/packages/tools/codegraph/lib/survey/scanner.ts +89 -0
- package/packages/tools/codegraph/lib/verify/checker.test.ts +140 -0
- package/packages/tools/codegraph/lib/verify/checker.ts +172 -0
- package/packages/tools/codegraph/package.json +23 -0
- package/packages/tools/codegraph/tsconfig.json +22 -0
- package/resources/project-architecture/atlas/atlas.history.log +32 -0
- package/resources/project-architecture/atlas/atlas.history.undo.json +356 -28
- package/resources/project-architecture/atlas/atlas.history.undo.stack.json +14350 -0
- package/resources/project-architecture/atlas/atlas.index.yaml +76 -12
- package/resources/project-architecture/atlas/features/codegraph.yaml +95 -0
- package/resources/project-architecture/atlas/features/eval-ci-gate.yaml +6 -1
- package/resources/project-architecture/atlas/features/eval-cli.yaml +16 -1
- package/resources/project-architecture/atlas/features/eval-executor.yaml +12 -2
- package/resources/project-architecture/atlas/features/eval-isolation.yaml +6 -1
- package/resources/project-architecture/atlas/features/eval-optimizer.yaml +17 -2
- package/resources/project-architecture/atlas/features/eval-question.yaml +12 -2
- package/resources/project-architecture/atlas/features/eval-reporter.yaml +6 -1
- package/resources/project-architecture/atlas/features/eval-scorer.yaml +12 -2
- package/resources/project-architecture/features/codegraph/cg-discovery.html +47 -0
- package/resources/project-architecture/features/codegraph/cg-lifecycle.html +48 -0
- package/resources/project-architecture/features/codegraph/cg-validation.html +47 -0
- package/resources/project-architecture/features/codegraph/index.html +58 -0
- package/resources/project-architecture/features/eval-ci-gate/workflow-trigger.html +6 -1
- package/resources/project-architecture/features/eval-cli/cli-handler.html +8 -1
- package/resources/project-architecture/features/eval-executor/exec-api-client.html +6 -1
- package/resources/project-architecture/features/eval-executor/trace-recorder.html +6 -1
- package/resources/project-architecture/features/eval-isolation/tool-dispatcher.html +6 -1
- package/resources/project-architecture/features/eval-optimizer/dedup-engine.html +6 -1
- package/resources/project-architecture/features/eval-optimizer/issue-extractor.html +7 -1
- package/resources/project-architecture/features/eval-question/question-loader.html +6 -1
- package/resources/project-architecture/features/eval-question/variant-generator.html +6 -1
- package/resources/project-architecture/features/eval-reporter/report-composer.html +6 -1
- package/resources/project-architecture/features/eval-scorer/judge-api-client.html +6 -1
- package/resources/project-architecture/features/eval-scorer/judge-prompt-builder.html +6 -1
- package/resources/project-architecture/index.html +200 -94
- package/skills/design/SKILL.md +33 -0
- package/skills/init-project-html/SKILL.md +12 -11
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { describe, it, before, beforeEach, afterEach, mock } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
describe('cmd-survey', () => {
|
|
6
|
+
let handleSurvey;
|
|
7
|
+
// Mock CodeGraph instance shared across tests:
|
|
8
|
+
// - Symbol A in src/feature/a.ts calls symbol B in src/lib/b.ts (cross-boundary)
|
|
9
|
+
// - Symbol X in src/feature/a.ts is exported but only called internally
|
|
10
|
+
const mockCg = {
|
|
11
|
+
getFiles: () => [{ path: 'src/feature/a.ts', language: 'typescript' }],
|
|
12
|
+
getNodesInFile: () => [
|
|
13
|
+
{
|
|
14
|
+
id: 'node-a',
|
|
15
|
+
name: 'A',
|
|
16
|
+
kind: 'function',
|
|
17
|
+
qualifiedName: 'A',
|
|
18
|
+
startLine: 1,
|
|
19
|
+
endLine: 10,
|
|
20
|
+
isExported: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'node-x',
|
|
24
|
+
name: 'X',
|
|
25
|
+
kind: 'function',
|
|
26
|
+
qualifiedName: 'X',
|
|
27
|
+
startLine: 20,
|
|
28
|
+
endLine: 30,
|
|
29
|
+
isExported: true,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
getNodesByName: (name) => {
|
|
33
|
+
if (name === 'A') {
|
|
34
|
+
return [{ id: 'node-a', filePath: 'src/feature/a.ts', name: 'A' }];
|
|
35
|
+
}
|
|
36
|
+
if (name === 'X') {
|
|
37
|
+
return [{ id: 'node-x', filePath: 'src/feature/a.ts', name: 'X' }];
|
|
38
|
+
}
|
|
39
|
+
return [];
|
|
40
|
+
},
|
|
41
|
+
getCallees: (_id) => {
|
|
42
|
+
if (_id === 'node-a') {
|
|
43
|
+
return [{ node: { name: 'B', filePath: 'src/lib/b.ts' } }];
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
},
|
|
47
|
+
getCallers: (_id) => {
|
|
48
|
+
if (_id === 'node-x') {
|
|
49
|
+
return [{ node: { name: 'internal', filePath: 'src/feature/a.ts' } }];
|
|
50
|
+
}
|
|
51
|
+
return [];
|
|
52
|
+
},
|
|
53
|
+
close: () => { },
|
|
54
|
+
};
|
|
55
|
+
before(async () => {
|
|
56
|
+
// Module-level mocks (only need to be set up once):
|
|
57
|
+
mock.module('./survey/scanner.js', {
|
|
58
|
+
namedExports: {
|
|
59
|
+
scanDirectory: async () => ({
|
|
60
|
+
directory: 'src/feature',
|
|
61
|
+
files: [
|
|
62
|
+
{
|
|
63
|
+
filePath: 'src/feature/a.ts',
|
|
64
|
+
language: 'typescript',
|
|
65
|
+
symbols: [
|
|
66
|
+
{ name: 'A', kind: 'function', qualifiedName: 'A', startLine: 1, endLine: 10, isExported: true, signature: undefined },
|
|
67
|
+
{ name: 'X', kind: 'function', qualifiedName: 'X', startLine: 20, endLine: 30, isExported: true, signature: undefined },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
allSymbols: [
|
|
72
|
+
{ name: 'A', kind: 'function', filePath: 'src/feature/a.ts', qualifiedName: 'A', startLine: 1, isExported: true },
|
|
73
|
+
{ name: 'X', kind: 'function', filePath: 'src/feature/a.ts', qualifiedName: 'X', startLine: 20, isExported: true },
|
|
74
|
+
],
|
|
75
|
+
totalFiles: 1,
|
|
76
|
+
totalSymbols: 2,
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
mock.module('./survey/grouper.js', {
|
|
81
|
+
namedExports: { groupIntoSubmodules: () => [] },
|
|
82
|
+
});
|
|
83
|
+
mock.module('./cg-instance.js', {
|
|
84
|
+
namedExports: { closeIndex: () => { } },
|
|
85
|
+
});
|
|
86
|
+
// Import the compiled module (dist/lib/cmd-survey.js has the fixed code)
|
|
87
|
+
const mod = await import('./cmd-survey.js');
|
|
88
|
+
handleSurvey = mod.handleSurvey;
|
|
89
|
+
});
|
|
90
|
+
beforeEach(() => {
|
|
91
|
+
// Re-apply CodeGraph.open mock before each test (mock.reset() in afterEach clears it).
|
|
92
|
+
// Must use manual mock.method instead of mock.module because lazy CJS require()
|
|
93
|
+
// inside handlers bypasses mock.module interception.
|
|
94
|
+
const { CodeGraph } = require('@colbymchenry/codegraph');
|
|
95
|
+
mock.method(CodeGraph, 'open', async () => mockCg);
|
|
96
|
+
});
|
|
97
|
+
afterEach(() => {
|
|
98
|
+
mock.reset();
|
|
99
|
+
});
|
|
100
|
+
it('REGTEST-10: Cross-boundary edges point outside the scanned directory', async () => {
|
|
101
|
+
const stdoutChunks = [];
|
|
102
|
+
mock.method(process.stdout, 'write', (chunk) => {
|
|
103
|
+
stdoutChunks.push(String(chunk));
|
|
104
|
+
return true;
|
|
105
|
+
});
|
|
106
|
+
// Use a real directory for projectRoot so existsSync returns true naturally
|
|
107
|
+
const exitCode = await handleSurvey(process.cwd(), 'packages');
|
|
108
|
+
assert.equal(exitCode, 0);
|
|
109
|
+
const output = stdoutChunks.join('');
|
|
110
|
+
assert.ok(output.includes('src/feature/a.ts -> src/lib/b.ts'), `Expected cross-boundary edge label in output, got:\n${output}`);
|
|
111
|
+
});
|
|
112
|
+
it('REGTEST-11: Exported symbol called only from within the directory is not an entry point', async () => {
|
|
113
|
+
const stdoutChunks = [];
|
|
114
|
+
mock.method(process.stdout, 'write', (chunk) => {
|
|
115
|
+
stdoutChunks.push(String(chunk));
|
|
116
|
+
return true;
|
|
117
|
+
});
|
|
118
|
+
// Use a real directory for projectRoot so existsSync returns true naturally
|
|
119
|
+
const exitCode = await handleSurvey(process.cwd(), 'packages');
|
|
120
|
+
assert.equal(exitCode, 0);
|
|
121
|
+
const output = stdoutChunks.join('');
|
|
122
|
+
// X has only internal callers, so "(none)" should appear for entry points
|
|
123
|
+
assert.ok(output.includes('(none)'), `Expected "(none)" for entry points, got:\n${output}`);
|
|
124
|
+
});
|
|
125
|
+
it('REGTEST-12: Non-existent directory returns exit code 1 with error message', async () => {
|
|
126
|
+
const stderrChunks = [];
|
|
127
|
+
mock.method(process.stderr, 'write', (chunk) => {
|
|
128
|
+
stderrChunks.push(String(chunk));
|
|
129
|
+
return true;
|
|
130
|
+
});
|
|
131
|
+
// Use a path that does not exist on disk
|
|
132
|
+
const exitCode = await handleSurvey('/tmp', 'nonexistent-' + process.hrtime.bigint().toString());
|
|
133
|
+
assert.equal(exitCode, 1);
|
|
134
|
+
assert.ok(stderrChunks.join('').includes('Directory not found'), `Expected "Directory not found" error, got: ${stderrChunks.join('')}`);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import { closeIndex } from './cg-instance.js';
|
|
4
|
+
import { formatSummary, formatOutput } from './formatter.js';
|
|
5
|
+
export async function handleSync(projectRoot, options = {}) {
|
|
6
|
+
const { CodeGraph } = require('@colbymchenry/codegraph');
|
|
7
|
+
if (!CodeGraph.isInitialized(projectRoot)) {
|
|
8
|
+
process.stderr.write('CodeGraph is not initialized. Run `apltk codegraph init` first.\n');
|
|
9
|
+
return 1;
|
|
10
|
+
}
|
|
11
|
+
const cg = await CodeGraph.open(projectRoot, { sync: false, readOnly: false });
|
|
12
|
+
let progressEvents = [];
|
|
13
|
+
const result = await cg.sync({
|
|
14
|
+
onProgress: (p) => {
|
|
15
|
+
progressEvents.push({ phase: p.phase, current: p.current, total: p.total });
|
|
16
|
+
if (process.stdout.isTTY) {
|
|
17
|
+
process.stdout.write(`\r Indexing: ${p.phase} ${p.current}/${p.total}`);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
if (process.stdout.isTTY) {
|
|
22
|
+
process.stdout.write('\n');
|
|
23
|
+
}
|
|
24
|
+
closeIndex(cg);
|
|
25
|
+
const output = {
|
|
26
|
+
projectRoot,
|
|
27
|
+
filesChecked: result.filesChecked,
|
|
28
|
+
filesAdded: result.filesAdded,
|
|
29
|
+
filesModified: result.filesModified,
|
|
30
|
+
filesRemoved: result.filesRemoved,
|
|
31
|
+
nodesUpdated: result.nodesUpdated,
|
|
32
|
+
durationMs: result.durationMs,
|
|
33
|
+
progress: progressEvents.length > 0 ? progressEvents : undefined,
|
|
34
|
+
};
|
|
35
|
+
if (options.json) {
|
|
36
|
+
process.stdout.write(formatOutput(output, { json: true }) + '\n');
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const summary = [
|
|
40
|
+
['Project:', projectRoot],
|
|
41
|
+
['Checked:', result.filesChecked],
|
|
42
|
+
['Added:', result.filesAdded],
|
|
43
|
+
['Modified:', result.filesModified],
|
|
44
|
+
['Removed:', result.filesRemoved],
|
|
45
|
+
['Nodes updated:', result.nodesUpdated],
|
|
46
|
+
['Duration:', `${result.durationMs}ms`],
|
|
47
|
+
];
|
|
48
|
+
process.stdout.write(formatSummary(summary) + '\n');
|
|
49
|
+
}
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, it, mock } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
describe('cmd-sync handleSync', () => {
|
|
6
|
+
it('should return exit code 1 when CodeGraph is not initialized', async () => {
|
|
7
|
+
// Pre-load CodeGraph via CJS require (same mechanism used by cmd-sync.ts)
|
|
8
|
+
// and mock isInitialized BEFORE the module under test is evaluated, so
|
|
9
|
+
// the mock is in place when cmd-sync.ts runs its own require().
|
|
10
|
+
const { CodeGraph } = require('@colbymchenry/codegraph');
|
|
11
|
+
const isInitializedMock = mock.method(CodeGraph, 'isInitialized', () => false);
|
|
12
|
+
// Capture stderr output
|
|
13
|
+
const stderrWriteMock = mock.method(process.stderr, 'write', () => true);
|
|
14
|
+
// Import the module under test after mocks are set up
|
|
15
|
+
const { handleSync } = await import('./cmd-sync.js');
|
|
16
|
+
// Call the handler with an uninitialized project
|
|
17
|
+
const exitCode = await handleSync('/tmp/fake-project', { json: false });
|
|
18
|
+
// Verify exit code is 1 (error)
|
|
19
|
+
assert.strictEqual(exitCode, 1);
|
|
20
|
+
// Verify stderr mentions "init"
|
|
21
|
+
assert.strictEqual(stderrWriteMock.mock.calls.length, 1);
|
|
22
|
+
const callArg = stderrWriteMock.mock.calls[0].arguments[0];
|
|
23
|
+
assert.ok(callArg !== undefined, 'Expected stderr write argument to be defined');
|
|
24
|
+
const stderrOutput = typeof callArg === 'string' ? callArg : Buffer.from(callArg).toString('utf8');
|
|
25
|
+
assert.ok(stderrOutput.toLowerCase().includes('init'), `Expected stderr to mention "init", got: ${JSON.stringify(stderrOutput)}`);
|
|
26
|
+
// Cleanup mocks
|
|
27
|
+
isInitializedMock.mock.restore();
|
|
28
|
+
stderrWriteMock.mock.restore();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
import { closeIndex } from './cg-instance.js';
|
|
6
|
+
import { formatOutput } from './formatter.js';
|
|
7
|
+
import { verifyOverlay } from './verify/checker.js';
|
|
8
|
+
import yaml from 'js-yaml';
|
|
9
|
+
/**
|
|
10
|
+
* Read a spec overlay from the standard atlas directory layout.
|
|
11
|
+
* Loads the overlay in the same way as skills/init-project-html/lib/atlas/state.js::loadOverlay.
|
|
12
|
+
*/
|
|
13
|
+
function loadOverlay(specDir) {
|
|
14
|
+
const overlayDir = path.join(specDir, 'architecture_diff', 'atlas');
|
|
15
|
+
if (!fs.existsSync(overlayDir)) {
|
|
16
|
+
throw new Error(`No architecture diff atlas found at: ${overlayDir}. Run "apltk architecture diff" first to generate the overlay.`);
|
|
17
|
+
}
|
|
18
|
+
const overlay = {
|
|
19
|
+
meta: null,
|
|
20
|
+
actors: null,
|
|
21
|
+
edges: null,
|
|
22
|
+
featureOrder: null,
|
|
23
|
+
features: {},
|
|
24
|
+
removed: { features: [], submodules: [] },
|
|
25
|
+
};
|
|
26
|
+
// Parse atlas.index.yaml via js-yaml
|
|
27
|
+
const indexFile = path.join(overlayDir, 'atlas.index.yaml');
|
|
28
|
+
if (fs.existsSync(indexFile)) {
|
|
29
|
+
const raw = fs.readFileSync(indexFile, 'utf8');
|
|
30
|
+
if (raw.trim()) {
|
|
31
|
+
const index = yaml.load(raw);
|
|
32
|
+
if (index && typeof index === 'object' && !Array.isArray(index)) {
|
|
33
|
+
if (index.meta !== undefined)
|
|
34
|
+
overlay.meta = index.meta;
|
|
35
|
+
if (index.actors !== undefined)
|
|
36
|
+
overlay.actors = index.actors;
|
|
37
|
+
if (index.edges !== undefined)
|
|
38
|
+
overlay.edges = index.edges;
|
|
39
|
+
if (Array.isArray(index.features)) {
|
|
40
|
+
overlay.featureOrder = index.features
|
|
41
|
+
.map((entry) => (typeof entry === 'string' ? entry : entry?.slug))
|
|
42
|
+
.filter(Boolean);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Load feature files via js-yaml
|
|
48
|
+
const featuresDir = path.join(overlayDir, 'features');
|
|
49
|
+
if (fs.existsSync(featuresDir)) {
|
|
50
|
+
for (const entry of fs.readdirSync(featuresDir)) {
|
|
51
|
+
if (!entry.endsWith('.yaml'))
|
|
52
|
+
continue;
|
|
53
|
+
const featureFile = path.join(featuresDir, entry);
|
|
54
|
+
const raw = fs.readFileSync(featureFile, 'utf8');
|
|
55
|
+
if (raw.trim()) {
|
|
56
|
+
const data = yaml.load(raw);
|
|
57
|
+
if (data && typeof data === 'object' && data.slug) {
|
|
58
|
+
const feature = {
|
|
59
|
+
slug: data.slug,
|
|
60
|
+
submodules: Array.isArray(data.submodules)
|
|
61
|
+
? data.submodules.map(normalizeSubmodule)
|
|
62
|
+
: [],
|
|
63
|
+
edges: Array.isArray(data.edges) ? data.edges : [],
|
|
64
|
+
};
|
|
65
|
+
if (data.action !== undefined)
|
|
66
|
+
feature.action = data.action;
|
|
67
|
+
overlay.features[data.slug] = feature;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Load _removed.yaml via js-yaml
|
|
73
|
+
const removedFile = path.join(overlayDir, '_removed.yaml');
|
|
74
|
+
if (fs.existsSync(removedFile)) {
|
|
75
|
+
const raw = fs.readFileSync(removedFile, 'utf8');
|
|
76
|
+
if (raw.trim()) {
|
|
77
|
+
const removed = yaml.load(raw);
|
|
78
|
+
if (removed && typeof removed === 'object' && !Array.isArray(removed)) {
|
|
79
|
+
if (Array.isArray(removed.features))
|
|
80
|
+
overlay.removed.features = removed.features;
|
|
81
|
+
if (Array.isArray(removed.submodules))
|
|
82
|
+
overlay.removed.submodules = removed.submodules;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return overlay;
|
|
87
|
+
}
|
|
88
|
+
function normalizeSubmodule(sub) {
|
|
89
|
+
if (!sub || typeof sub !== 'object')
|
|
90
|
+
return sub;
|
|
91
|
+
return {
|
|
92
|
+
slug: sub.slug,
|
|
93
|
+
kind: sub.kind || 'service',
|
|
94
|
+
role: sub.role || '',
|
|
95
|
+
functions: Array.isArray(sub.functions) ? sub.functions : [],
|
|
96
|
+
variables: Array.isArray(sub.variables) ? sub.variables : [],
|
|
97
|
+
...(sub.action !== undefined ? { action: sub.action } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export async function handleVerify(projectRoot, specDir, options = {}) {
|
|
101
|
+
const resolvedSpecDir = path.resolve(specDir);
|
|
102
|
+
let overlay;
|
|
103
|
+
try {
|
|
104
|
+
overlay = loadOverlay(resolvedSpecDir);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
process.stderr.write(`Error loading overlay: ${err.message}\n`);
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
const { CodeGraph } = require('@colbymchenry/codegraph');
|
|
111
|
+
const cg = await CodeGraph.open(projectRoot, { sync: false, readOnly: true });
|
|
112
|
+
const report = await verifyOverlay(cg, overlay);
|
|
113
|
+
closeIndex(cg);
|
|
114
|
+
if (options.json) {
|
|
115
|
+
process.stdout.write(formatOutput(report, { json: true }) + '\n');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
process.stdout.write(`\n=== Verify Report ===\n\n`);
|
|
119
|
+
process.stdout.write(`Total: ${report.total}\n`);
|
|
120
|
+
process.stdout.write(`Passed: ${report.passed}\n`);
|
|
121
|
+
process.stdout.write(`Failed: ${report.failed.length}\n`);
|
|
122
|
+
process.stdout.write(`Skipped: ${report.skipped}\n`);
|
|
123
|
+
if (report.failed.length > 0) {
|
|
124
|
+
process.stdout.write('\nFailures:\n');
|
|
125
|
+
for (const f of report.failed) {
|
|
126
|
+
process.stdout.write(` [${f.type}] ${f.location}\n`);
|
|
127
|
+
if (f.suggestion)
|
|
128
|
+
process.stdout.write(` Suggestion: ${f.suggestion}\n`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
process.stdout.write('\n');
|
|
132
|
+
}
|
|
133
|
+
return report.failed.length > 0 ? 1 : 0;
|
|
134
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import yaml from 'js-yaml';
|
|
7
|
+
/**
|
|
8
|
+
* REGTEST-1: Verify that the js-yaml based parser (used in `loadOverlay`)
|
|
9
|
+
* correctly parses object-format YAML function declarations.
|
|
10
|
+
*
|
|
11
|
+
* The fix replaced a custom YAML parser with `js-yaml`. The old parser
|
|
12
|
+
* incorrectly produced raw string fragments like `"name: init"` when
|
|
13
|
+
* encountering object-format functions:
|
|
14
|
+
*
|
|
15
|
+
* functions:
|
|
16
|
+
* - name: init
|
|
17
|
+
* in: string
|
|
18
|
+
* out: void
|
|
19
|
+
*
|
|
20
|
+
* With `js-yaml`, the parser produces actual objects:
|
|
21
|
+
* `{ name: "init", in: "string", out: "void" }`
|
|
22
|
+
*
|
|
23
|
+
* This test exercises the same parsing path as `loadOverlay`: reading a YAML
|
|
24
|
+
* file from disk with `fs.readFileSync`, then parsing with `yaml.load`.
|
|
25
|
+
*/
|
|
26
|
+
describe('REGTEST-1: loadOverlay YAML parser', () => {
|
|
27
|
+
it('should parse object-format functions and correctly extract .name', () => {
|
|
28
|
+
const yamlStr = [
|
|
29
|
+
'slug: test-feature',
|
|
30
|
+
'submodules:',
|
|
31
|
+
' - slug: module-a',
|
|
32
|
+
' functions:',
|
|
33
|
+
' - name: init',
|
|
34
|
+
' in: string',
|
|
35
|
+
' out: void',
|
|
36
|
+
'edges:',
|
|
37
|
+
' - from: funcA',
|
|
38
|
+
' to: funcB',
|
|
39
|
+
' kind: call',
|
|
40
|
+
].join('\n');
|
|
41
|
+
// Parse with js-yaml (same library used by loadOverlay)
|
|
42
|
+
const data = yaml.load(yamlStr);
|
|
43
|
+
// Verify object-format function parsing
|
|
44
|
+
const fn = data.submodules[0].functions[0];
|
|
45
|
+
assert.strictEqual(typeof fn, 'object', 'object-format function should be parsed as object, not string');
|
|
46
|
+
assert.strictEqual(fn.name, 'init', 'parsed function .name should be "init"');
|
|
47
|
+
// Verify the old bug is fixed: no raw "name: init" string
|
|
48
|
+
assert.notStrictEqual(fn, 'name: init', 'function should NOT be a raw string fragment');
|
|
49
|
+
assert.notStrictEqual(typeof fn, 'string', 'object-format function should not be a string');
|
|
50
|
+
// Verify additional fields are preserved
|
|
51
|
+
assert.strictEqual(fn.in, 'string', 'function "in" field should be preserved');
|
|
52
|
+
assert.strictEqual(fn.out, 'void', 'function "out" field should be preserved');
|
|
53
|
+
// Verify string-format functions still work
|
|
54
|
+
// Note: the YAML above only has object-format functions; string format is tested separately
|
|
55
|
+
});
|
|
56
|
+
it('should parse string-format functions correctly', () => {
|
|
57
|
+
const yamlStr = [
|
|
58
|
+
'slug: test-feature',
|
|
59
|
+
'submodules:',
|
|
60
|
+
' - slug: module-a',
|
|
61
|
+
' functions:',
|
|
62
|
+
' - init',
|
|
63
|
+
' - process',
|
|
64
|
+
].join('\n');
|
|
65
|
+
const data = yaml.load(yamlStr);
|
|
66
|
+
const functions = data.submodules[0].functions;
|
|
67
|
+
assert.strictEqual(functions.length, 2, 'should have 2 string-format functions');
|
|
68
|
+
assert.strictEqual(typeof functions[0], 'string', 'string-format function should be a string');
|
|
69
|
+
assert.strictEqual(functions[0], 'init', 'string function name should be "init"');
|
|
70
|
+
assert.strictEqual(functions[1], 'process', 'string function name should be "process"');
|
|
71
|
+
});
|
|
72
|
+
it('should parse mixed object and string format functions', () => {
|
|
73
|
+
const yamlStr = [
|
|
74
|
+
'slug: test-feature',
|
|
75
|
+
'submodules:',
|
|
76
|
+
' - slug: module-a',
|
|
77
|
+
' functions:',
|
|
78
|
+
' - name: init',
|
|
79
|
+
' in: string',
|
|
80
|
+
' out: void',
|
|
81
|
+
' - process',
|
|
82
|
+
' - name: render',
|
|
83
|
+
' in: string',
|
|
84
|
+
' out: void',
|
|
85
|
+
' - cleanup',
|
|
86
|
+
].join('\n');
|
|
87
|
+
const data = yaml.load(yamlStr);
|
|
88
|
+
const functions = data.submodules[0].functions;
|
|
89
|
+
assert.strictEqual(functions.length, 4, 'should have 4 functions total');
|
|
90
|
+
// Index 0: object-format
|
|
91
|
+
assert.strictEqual(typeof functions[0], 'object', 'functions[0] should be object');
|
|
92
|
+
assert.strictEqual(functions[0].name, 'init');
|
|
93
|
+
// Index 1: string-format
|
|
94
|
+
assert.strictEqual(typeof functions[1], 'string', 'functions[1] should be string');
|
|
95
|
+
assert.strictEqual(functions[1], 'process');
|
|
96
|
+
// Index 2: object-format
|
|
97
|
+
assert.strictEqual(typeof functions[2], 'object', 'functions[2] should be object');
|
|
98
|
+
assert.strictEqual(functions[2].name, 'render');
|
|
99
|
+
// Index 3: string-format
|
|
100
|
+
assert.strictEqual(typeof functions[3], 'string', 'functions[3] should be string');
|
|
101
|
+
assert.strictEqual(functions[3], 'cleanup');
|
|
102
|
+
});
|
|
103
|
+
it('should parse feature YAML from disk (same path as loadOverlay)', async () => {
|
|
104
|
+
// Create a temp directory matching the loadOverlay structure
|
|
105
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-verify-test-'));
|
|
106
|
+
try {
|
|
107
|
+
const featuresDir = path.join(tmpDir, 'architecture_diff', 'atlas', 'features');
|
|
108
|
+
fs.mkdirSync(featuresDir, { recursive: true });
|
|
109
|
+
const yamlPath = path.join(featuresDir, 'test-feature.yaml');
|
|
110
|
+
fs.writeFileSync(yamlPath, [
|
|
111
|
+
'slug: test-feature',
|
|
112
|
+
'submodules:',
|
|
113
|
+
' - slug: module-a',
|
|
114
|
+
' functions:',
|
|
115
|
+
' - name: init',
|
|
116
|
+
' in: string',
|
|
117
|
+
' out: void',
|
|
118
|
+
' edges:',
|
|
119
|
+
' - from: funcA',
|
|
120
|
+
' to: funcB',
|
|
121
|
+
' kind: call',
|
|
122
|
+
].join('\n') + '\n');
|
|
123
|
+
// Read file and parse (same as loadOverlay)
|
|
124
|
+
const raw = fs.readFileSync(yamlPath, 'utf8');
|
|
125
|
+
const data = yaml.load(raw);
|
|
126
|
+
assert.ok(data, 'parsed data should be truthy');
|
|
127
|
+
assert.strictEqual(typeof data, 'object', 'parsed data should be an object');
|
|
128
|
+
assert.strictEqual(data.slug, 'test-feature', 'feature slug should be preserved');
|
|
129
|
+
const fn = data.submodules[0].functions[0];
|
|
130
|
+
assert.strictEqual(typeof fn, 'object', 'object-format function parsed from file should be object');
|
|
131
|
+
assert.strictEqual(fn.name, 'init', 'function .name should be "init"');
|
|
132
|
+
assert.strictEqual(fn.in, 'string', 'function .in should be "string"');
|
|
133
|
+
assert.strictEqual(fn.out, 'void', 'function .out should be "void"');
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format structured data for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* - TTY mode produces human-readable tables and headings.
|
|
5
|
+
* - Non-TTY or `--json` produces JSON.stringify with 2-space indent.
|
|
6
|
+
* - Auto-detects TTY via `process.stdout.isTTY`.
|
|
7
|
+
*/
|
|
8
|
+
export interface FormatOptions {
|
|
9
|
+
json?: boolean;
|
|
10
|
+
tty?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Format generic data for output.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatOutput(data: unknown, options?: FormatOptions): string;
|
|
16
|
+
/**
|
|
17
|
+
* Format a key-value summary block for human-readable output.
|
|
18
|
+
* Example:
|
|
19
|
+
* Files: 42
|
|
20
|
+
* Nodes: 1280
|
|
21
|
+
* Edges: 5600
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatSummary(rows: [string, string | number][]): string;
|
|
24
|
+
/**
|
|
25
|
+
* Format a list of search results as a human-readable table.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatSearchResults(results: Array<{
|
|
28
|
+
node: {
|
|
29
|
+
name: string;
|
|
30
|
+
kind: string;
|
|
31
|
+
filePath: string;
|
|
32
|
+
startLine: number;
|
|
33
|
+
};
|
|
34
|
+
score: number;
|
|
35
|
+
}>): string;
|
|
36
|
+
/**
|
|
37
|
+
* Format an API directory listing for human-readable output.
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatApiList(apis: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
kind: string;
|
|
42
|
+
filePath: string;
|
|
43
|
+
startLine: number;
|
|
44
|
+
signature?: string;
|
|
45
|
+
callerCount: number;
|
|
46
|
+
callers?: Array<{
|
|
47
|
+
name: string;
|
|
48
|
+
filePath: string;
|
|
49
|
+
startLine: number;
|
|
50
|
+
}>;
|
|
51
|
+
}>): string;
|
|
52
|
+
/**
|
|
53
|
+
* Format an API listing grouped by directory.
|
|
54
|
+
*/
|
|
55
|
+
export declare function formatApiListGrouped(apis: Array<{
|
|
56
|
+
name: string;
|
|
57
|
+
kind: string;
|
|
58
|
+
filePath: string;
|
|
59
|
+
startLine: number;
|
|
60
|
+
signature?: string;
|
|
61
|
+
callerCount: number;
|
|
62
|
+
callers?: Array<{
|
|
63
|
+
name: string;
|
|
64
|
+
filePath: string;
|
|
65
|
+
startLine: number;
|
|
66
|
+
}>;
|
|
67
|
+
}>): string;
|