* chore(#604): rename get-shit-done/ runtime directory to gsd-core/ Renames the installed runtime directory `get-shit-done/` to `gsd-core/` so the on-disk name matches the package (`@opengsd/gsd-core`), repo, and binary (`gsd-tools`). The npm package name and binary are unchanged; npx/npm consumers are unaffected. Mechanical (bulk, ~90% of the diff): - `git mv get-shit-done gsd-core` - Swept path/identifier references across the repo via `perl -pe 's/get-shit-done(?!-\w)/gsd-core/g'`. The negative lookahead preserves the five legitimate slug variants that are NOT the directory: get-shit-done-{OLD,cc,classic,cli,redux} (old package/repo names). - Build/manifest wiring: package.json (bin, files, coverage globs), tsconfig.build.json (outDir), ~86 .gitignore build-output entries, stryker.config.mjs, scan-ignore files, install.js path strings. - Frozen (not rewritten): CHANGELOG.md history; translated docs (README.<locale>.md and docs/{ja-JP,ko-KR,pt-BR,zh-CN}/). New logic (review here): - src/installer-migrations/003-rename-get-shit-done-to-gsd-core.cts: a proper ADR-0008 installer migration. On upgrade it walks the legacy `~/.claude/get-shit-done/` tree, classifies each file via the prior install manifest, and emits remove-managed / backup-and-remove for managed files while PRESERVING unknown user-added files. Symlink-safe (skips a symlinked root and symlinked entries; bounds-checks every path under configDir). The framework rolls back on install failure. Emptied dirs may remain (framework has no recursive dir-removal primitive) — documented. - scripts/lint-legacy-dir-name.cjs: CI regression guard forbidding the bare `get-shit-done` directory token (split token to avoid self-match; case- insensitive; `(?!-\w)` lookahead allows the slug variants; allowlists CHANGELOG, translated docs, and `gsd-allow-legacy-name` marker lines). Wired into the lint-tests CI job. - Restored scripts/lint-package-identity-drift.cjs detection regexes (the mechanical sweep had wrongly rewritten the old-name patterns it exists to detect) and marked them as intentional legacy references. - TDD tests for the migration and the guard; do.md slash-command guard regex tightened so a `/gsd-core/bin` path segment is not mistaken for a command; changeset + docs/installer-migrations.md row added. Breaking: the installed runtime path moves `~/.claude/get-shit-done/` -> `~/.claude/gsd-core/`. Migration 003 removes the stale legacy dir's managed files (preserving user files) on upgrade. Users with custom hooks/configs hardcoding the old path must update them. Closes #604 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unsweep pending changesets + allowlist injection-example docs CI fixes for the rename PR: - Do not sweep pending .changeset/*.md (ephemeral release-note fragments, like CHANGELOG); reverted those body edits so 5 pre-existing malformed fragments (missing type/pr) no longer enter the PR diff and trip docs-lint. Allowlisted .changeset/ in the legacy-name guard accordingly. - Allowlisted TEST-EXAMPLES.md and docs/explanation/security-model.md in prompt-injection-scan.sh: they contain intentional injection examples / security-model prose; the path-reference rewrites are kept. CodeQL alerts on this PR are pre-existing (alert lines unchanged by this PR; none in the new migration/guard) and are out of scope for the rename. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): resolve CodeQL alerts surfaced on this PR The rename diff touched files carrying pre-existing CodeQL findings; per the no-pre-existing-dismissal rule, fixing every surfaced alert rather than waving them off. All behavior-preserving: - scripts/ci-test-scope.cjs: build the config-path match from string .includes() instead of a RegExp over an arg-derived value (js/regex-injection). - src/profile-output.cts: escape backslashes before pipe-escaping desc/safeName so the table-cell escape is complete (js/incomplete-sanitization). - tests/{bug-2643,bug-2808,docs-parity-live-registry}: two-pass HTML-comment strip so a bare/unclosed `<!--` cannot survive (js/incomplete-multi-character-sanitization). - tests/inline-plan-threshold: drop the no-op `\s`->`\s` identity replace, keep the meaningful POSIX-class conversion (js/identity-replacement). Verified: build:lib green; the touched test files + ci-test-scope + profile-output suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): correctly resolve remaining CodeQL alerts (regex-injection + sanitization) The prior commit's fixes for two alerts were ineffective: - ci-test-scope.cjs js/regex-injection: the alert is the CLI-arg-derived `file` reaching static regex `.test(file)` calls (not the config rule). Removed ALL regex over file/t — startsWith/includes/=== string checks + an isWindowsHint helper — so there is no regex sink for the tainted value. - js/incomplete-multi-character-sanitization (3 test files): a single `.replace(/<!--...-->/g,'')` can let `<!--` re-form. Replaced with a fixpoint loop (replace until stable) plus a final bare-opener strip. Verified: no regex over file/t remains; ci-test-scope + the 3 test suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): make ci-test-scope + comment-strippers regex-free to clear CodeQL CodeQL flags the regex PATTERNS syntactically (regex-injection on the --files arg split; incomplete-multi-character-sanitization on the <!--...--> replace), so loop fixes do not satisfy it. Made these paths regex-free: - ci-test-scope.cjs splitFiles: char-by-char separator tokenizer (no /[,\\s]+/). - 3 test files: indexOf/slice HTML-comment stripper (no .replace(/<!--/)). Behavior preserved; ci-test-scope + the 3 suites pass; guard clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unblock security base64 scan on the large rename diff The security job hit its 10m timeout: base64-scan.sh choked on the binary test fixture tests/feat-3594-parser-property-style.test.cjs (embedded NUL/ non-UTF8 bytes -> thousands of bogus blobs + "ignored null byte" warnings), and the ~800-file rename diff is slow to scan regardless. - scripts/base64-scan.sh: skip binary-by-content files (grep -Iq .) — they can't carry base64-obfuscated *text* and feeding NUL bytes through the per-line scanner is pathologically slow. collect_files already filtered binary *extensions*; this catches binary *content* in text extensions. - .github/workflows/security-scan.yml: raise the security job timeout 10m->30m to accommodate very large diffs (the scan itself is unchanged). Verified locally: scan skips the fixture, 0 "ignored null byte" warnings, 0 findings, exit 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): sweep get-shit-done refs introduced by merging next The branch was updated with next (#614/#384/#618 etc.), which reference the get-shit-done/ dir (still named that on next). Swept the stale references in the merged files to gsd-core so the rename stays consistent and lint:legacy-name passes: - commands/gsd/discuss-phase.md (runtime-launcher shim paths) - src/core.cts (getAgentsDir layout comments) - tests/bug-384-agents-runtime-aware.test.cjs (require path to runtime lib) Verified: guard 0 violations; build green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): exclude gsd-core/ path segments from bug-3683 command cross-ref invariant The #614 runtime-launcher shim added to discuss-phase.md references `${_GSD_RUNTIME_ROOT}/gsd-core/bin/...`. bug-3683's REF_PATTERN excluded path-y refs only via lookbehind, but `}` precedes `/gsd-core/` in the shim, so it mis-read the directory path as a dangling `/gsd-core` command ref (same class as the #604 bug-2954 fix). Added a trailing `(?![\w-]*\/)` so `/gsd-<x>/...` path segments are not treated as slash-command references. Verified locally on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22 image) full suite: 0 failures - bug-3683 + bug-2954 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): lazily resolve findProjectRoot in gsd-tools (harden flaky CI) CI intermittently failed state.test's gsd-tools subprocess with "findProjectRoot is not a function" (flip-flopping across legs; not reproducible on mac full suite, gsd-test linux full suite, test:unit, or state.test x8). findProjectRoot is a re-export from core.cjs (sourced from project-root.cjs); binding it via destructure at module-load can be undefined under a load-ordering edge. Resolve it lazily at call time via a small wrapper so the lookup happens after core.cjs is fully initialized. Verified green on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22) full suite: 0 failures - state.test.cjs: 106/106; gsd-tools loads cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): allowlist verification-patterns.md placeholder examples in secret scan The rename git-mv'd references/verification-patterns.md into gsd-core/, pulling it into the secret-scan diff. It documents stub/placeholder RED-FLAG env-var examples (illustrative Stripe test-key / database-URL / API-key placeholders) — not real credentials. Added it to .secretscanignore with the strict annotation, mirroring the existing gsd-core/workflows/plan-phase.md exception. Verified locally: secret-scan-lint --strict OK; secret-scan --diff origin/next exits 0 with 0 findings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
448 lines
18 KiB
JavaScript
448 lines
18 KiB
JavaScript
'use strict';
|
|
|
|
// Tests for graphify.cjs — query describe block.
|
|
// Split from the consolidated 2336-LOC file. Refs #3761.
|
|
|
|
const { describe, test, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { createTempProject, cleanup } = require('./helpers.cjs');
|
|
|
|
const {
|
|
graphifyQuery,
|
|
graphifyStatus,
|
|
graphifyDiff,
|
|
safeReadJson,
|
|
buildAdjacencyMap,
|
|
seedAndExpand,
|
|
applyBudget,
|
|
} = require('../gsd-core/bin/lib/graphify.cjs');
|
|
|
|
const {
|
|
enableGraphify,
|
|
writeGraphJson,
|
|
writeSnapshotJson,
|
|
SAMPLE_GRAPH,
|
|
} = require('./helpers/graphify.cjs');
|
|
|
|
// ─── query describe ───────────────────────────────────────────────────────────
|
|
|
|
describe('query', () => {
|
|
describe('safeReadJson', () => {
|
|
let tmpDir;
|
|
let planningDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
planningDir = path.join(tmpDir, '.planning');
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('returns parsed object for valid JSON file', () => {
|
|
const filePath = path.join(planningDir, 'test.json');
|
|
const data = { foo: 'bar', num: 42 };
|
|
fs.writeFileSync(filePath, JSON.stringify(data), 'utf8');
|
|
const result = safeReadJson(filePath);
|
|
assert.deepStrictEqual(result, data);
|
|
});
|
|
|
|
test('returns null for malformed JSON', () => {
|
|
const filePath = path.join(planningDir, 'bad.json');
|
|
fs.writeFileSync(filePath, 'not json', 'utf8');
|
|
const result = safeReadJson(filePath);
|
|
assert.strictEqual(result, null);
|
|
});
|
|
|
|
test('returns null for non-existent file', () => {
|
|
const result = safeReadJson(path.join(planningDir, 'does-not-exist.json'));
|
|
assert.strictEqual(result, null);
|
|
});
|
|
});
|
|
|
|
describe('buildAdjacencyMap', () => {
|
|
test('creates bidirectional adjacency entries', () => {
|
|
const adj = buildAdjacencyMap(SAMPLE_GRAPH);
|
|
// n1 -> n2 edge exists, so adj['n1'] should have target n2 AND adj['n2'] should have target n1
|
|
assert.ok(adj['n1'].some(e => e.target === 'n2'));
|
|
assert.ok(adj['n2'].some(e => e.target === 'n1'));
|
|
});
|
|
|
|
test('initializes empty arrays for nodes without edges', () => {
|
|
const graph = {
|
|
nodes: [
|
|
...SAMPLE_GRAPH.nodes,
|
|
{ id: 'n99', label: 'Orphan', description: 'No edges', type: 'orphan' },
|
|
],
|
|
edges: SAMPLE_GRAPH.edges,
|
|
};
|
|
const adj = buildAdjacencyMap(graph);
|
|
assert.ok(Array.isArray(adj['n99']));
|
|
assert.strictEqual(adj['n99'].length, 0);
|
|
});
|
|
|
|
test('stores full edge object in adjacency entries', () => {
|
|
const adj = buildAdjacencyMap(SAMPLE_GRAPH);
|
|
const entry = adj['n1'].find(e => e.target === 'n2');
|
|
assert.ok(entry);
|
|
assert.strictEqual(entry.edge.label, 'reads_from');
|
|
assert.strictEqual(entry.edge.confidence, 'EXTRACTED');
|
|
});
|
|
|
|
// LINKS-01: graphify emits 'links' key; reader must fall back to it
|
|
test('falls back to graph.links when graph.edges is absent (LINKS-01)', () => {
|
|
const graphWithLinks = {
|
|
nodes: SAMPLE_GRAPH.nodes,
|
|
links: SAMPLE_GRAPH.edges,
|
|
};
|
|
const adj = buildAdjacencyMap(graphWithLinks);
|
|
assert.ok(adj['n1'].some(e => e.target === 'n2'), 'adjacency must traverse links');
|
|
assert.ok(adj['n2'].some(e => e.target === 'n1'), 'reverse adjacency must work');
|
|
});
|
|
});
|
|
|
|
describe('seedAndExpand', () => {
|
|
test('finds seed nodes by label match (case-insensitive)', () => {
|
|
const result = seedAndExpand(SAMPLE_GRAPH, 'auth');
|
|
assert.ok(result.seeds.has('n1'), 'AuthService should be a seed');
|
|
assert.ok(result.nodes.some(n => n.id === 'n1'));
|
|
});
|
|
|
|
test('finds seed nodes by description match', () => {
|
|
const result = seedAndExpand(SAMPLE_GRAPH, 'credentials');
|
|
assert.ok(result.seeds.has('n2'), 'UserModel description contains credentials');
|
|
assert.ok(result.nodes.some(n => n.id === 'n2'));
|
|
});
|
|
|
|
test('BFS expands 1-2 hops from seeds', () => {
|
|
// 'auth' matches n1 (label: AuthService) and n2 (description: authentication)
|
|
// n1 seeds: 1-hop -> n2, n3; 2-hop -> n4 (via n3->n4)
|
|
// n5 is 3 hops from n1 (n1->n3->n4->n5) so should NOT appear
|
|
const result = seedAndExpand(SAMPLE_GRAPH, 'auth');
|
|
const nodeIds = result.nodes.map(n => n.id);
|
|
assert.ok(nodeIds.includes('n1'), 'seed n1');
|
|
assert.ok(nodeIds.includes('n2'), '1-hop from n1');
|
|
assert.ok(nodeIds.includes('n3'), '1-hop from n1');
|
|
assert.ok(nodeIds.includes('n4'), '2-hop from n3');
|
|
// n5 is reachable only at 3 hops from n1 seeds, but n2 is also a seed
|
|
// (description contains "authentication"), and n2->n3->n4->n5 is also 3 hops
|
|
// So n5 should NOT be in results with maxHops=2
|
|
assert.ok(!nodeIds.includes('n5'), 'n5 should be beyond 2 hops');
|
|
});
|
|
|
|
test('returns empty results for no matches', () => {
|
|
const result = seedAndExpand(SAMPLE_GRAPH, 'nonexistent');
|
|
assert.strictEqual(result.nodes.length, 0);
|
|
assert.strictEqual(result.edges.length, 0);
|
|
assert.strictEqual(result.seeds.size, 0);
|
|
});
|
|
|
|
test('respects maxHops parameter', () => {
|
|
const result = seedAndExpand(SAMPLE_GRAPH, 'auth', 1);
|
|
const nodeIds = result.nodes.map(n => n.id);
|
|
assert.ok(nodeIds.includes('n1'), 'seed');
|
|
assert.ok(nodeIds.includes('n2'), '1-hop');
|
|
assert.ok(nodeIds.includes('n3'), '1-hop');
|
|
assert.ok(!nodeIds.includes('n4'), 'n4 is 2 hops away');
|
|
});
|
|
});
|
|
|
|
describe('applyBudget', () => {
|
|
test('returns result unchanged when no budget', () => {
|
|
const input = { nodes: SAMPLE_GRAPH.nodes, edges: SAMPLE_GRAPH.edges, seeds: new Set(['n1']) };
|
|
const result = applyBudget(input, null);
|
|
assert.strictEqual(result.nodes, input.nodes);
|
|
assert.strictEqual(result.edges, input.edges);
|
|
});
|
|
|
|
test('drops AMBIGUOUS edges first when over budget', () => {
|
|
const input = { nodes: SAMPLE_GRAPH.nodes, edges: SAMPLE_GRAPH.edges, seeds: new Set(['n1']) };
|
|
// Set a budget small enough to trigger trimming but large enough to keep some edges
|
|
// The full graph serialized is ~600+ chars = ~150+ tokens. Use a small budget.
|
|
const result = applyBudget(input, 50);
|
|
const confidences = result.edges.map(e => e.confidence);
|
|
assert.ok(!confidences.includes('AMBIGUOUS'), 'AMBIGUOUS edges should be dropped first');
|
|
});
|
|
|
|
test('drops INFERRED edges after AMBIGUOUS', () => {
|
|
const input = { nodes: SAMPLE_GRAPH.nodes, edges: SAMPLE_GRAPH.edges, seeds: new Set(['n1']) };
|
|
// Very tight budget to force dropping both AMBIGUOUS and INFERRED
|
|
const result = applyBudget(input, 10);
|
|
const confidences = result.edges.map(e => e.confidence);
|
|
assert.ok(!confidences.includes('AMBIGUOUS'), 'AMBIGUOUS removed');
|
|
assert.ok(!confidences.includes('INFERRED'), 'INFERRED removed');
|
|
// Only EXTRACTED should remain (if any)
|
|
for (const c of confidences) {
|
|
assert.strictEqual(c, 'EXTRACTED');
|
|
}
|
|
});
|
|
|
|
test('appends trimmed footer with counts', () => {
|
|
const input = { nodes: SAMPLE_GRAPH.nodes, edges: SAMPLE_GRAPH.edges, seeds: new Set(['n1']) };
|
|
const result = applyBudget(input, 10);
|
|
assert.ok(result.trimmed !== null, 'trimmed should not be null');
|
|
assert.ok(/\d+ edges omitted/.test(result.trimmed), 'trimmed contains edge count');
|
|
assert.ok(/\d+ nodes unreachable/.test(result.trimmed), 'trimmed contains node count');
|
|
});
|
|
});
|
|
|
|
describe('graphifyQuery', () => {
|
|
let tmpDir;
|
|
let planningDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
planningDir = path.join(tmpDir, '.planning');
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
// QUERY-01: returns disabled response when graphify not enabled
|
|
test('returns disabled response when graphify not enabled', () => {
|
|
const result = graphifyQuery(tmpDir, 'auth');
|
|
assert.strictEqual(result.disabled, true);
|
|
});
|
|
|
|
// QUERY-01: returns error when graph.json does not exist
|
|
test('returns error when graph.json does not exist', () => {
|
|
enableGraphify(planningDir);
|
|
const result = graphifyQuery(tmpDir, 'auth');
|
|
assert.ok(result.error);
|
|
assert.ok(result.error.includes('No graph'));
|
|
});
|
|
|
|
// QUERY-01: returns matching nodes and edges for valid query
|
|
test('returns matching nodes and edges for valid query', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyQuery(tmpDir, 'auth');
|
|
assert.ok(result.nodes.length > 0, 'should have matching nodes');
|
|
assert.ok(result.edges.length > 0, 'should have matching edges');
|
|
assert.strictEqual(result.term, 'auth');
|
|
});
|
|
|
|
// QUERY-03: includes confidence on edges
|
|
test('includes confidence on edges (QUERY-03)', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyQuery(tmpDir, 'auth');
|
|
const validTiers = ['EXTRACTED', 'INFERRED', 'AMBIGUOUS'];
|
|
for (const edge of result.edges) {
|
|
assert.ok(validTiers.includes(edge.confidence), `edge confidence ${edge.confidence} is valid tier`);
|
|
}
|
|
});
|
|
|
|
// QUERY-02: respects --budget option
|
|
test('respects --budget option (QUERY-02)', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyQuery(tmpDir, 'auth', { budget: 50 });
|
|
// With a very small budget, trimming should occur
|
|
assert.ok(result.trimmed !== null, 'trimmed should indicate budget was applied');
|
|
});
|
|
|
|
// QUERY-01: returns total_nodes and total_edges counts
|
|
test('returns total_nodes and total_edges counts', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyQuery(tmpDir, 'auth');
|
|
assert.strictEqual(typeof result.total_nodes, 'number');
|
|
assert.strictEqual(typeof result.total_edges, 'number');
|
|
});
|
|
});
|
|
|
|
describe('graphifyDiff', () => {
|
|
let tmpDir;
|
|
let planningDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
planningDir = path.join(tmpDir, '.planning');
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
// DIFF-01: returns disabled response when not enabled
|
|
test('returns disabled response when not enabled', () => {
|
|
const result = graphifyDiff(tmpDir);
|
|
assert.strictEqual(result.disabled, true);
|
|
});
|
|
|
|
// D-09: returns no_baseline when no snapshot exists
|
|
test('returns no_baseline when no snapshot exists (D-09)', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyDiff(tmpDir);
|
|
assert.strictEqual(result.no_baseline, true);
|
|
assert.ok(result.message.includes('No previous snapshot'));
|
|
});
|
|
|
|
// DIFF-01: returns error when no current graph but snapshot exists
|
|
test('returns error when no current graph but snapshot exists', () => {
|
|
enableGraphify(planningDir);
|
|
writeSnapshotJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyDiff(tmpDir);
|
|
assert.ok(result.error);
|
|
assert.ok(result.error.includes('No current graph'));
|
|
});
|
|
|
|
// DIFF-02: detects added and removed nodes
|
|
test('detects added and removed nodes (DIFF-02)', () => {
|
|
enableGraphify(planningDir);
|
|
const snapshot = {
|
|
nodes: [
|
|
{ id: 'n1', label: 'AuthService', description: 'Auth', type: 'service' },
|
|
{ id: 'n2', label: 'UserModel', description: 'User', type: 'model' },
|
|
],
|
|
edges: [],
|
|
};
|
|
const current = {
|
|
nodes: [
|
|
{ id: 'n1', label: 'AuthService', description: 'Auth', type: 'service' },
|
|
{ id: 'n3', label: 'SessionManager', description: 'Sessions', type: 'service' },
|
|
],
|
|
edges: [],
|
|
};
|
|
writeSnapshotJson(planningDir, snapshot);
|
|
writeGraphJson(planningDir, current);
|
|
const result = graphifyDiff(tmpDir);
|
|
assert.strictEqual(result.nodes.added, 1, 'n3 added');
|
|
assert.strictEqual(result.nodes.removed, 1, 'n2 removed');
|
|
});
|
|
|
|
// DIFF-02: detects changed nodes and edges
|
|
test('detects changed nodes and edges (DIFF-02)', () => {
|
|
enableGraphify(planningDir);
|
|
const snapshot = {
|
|
nodes: [
|
|
{ id: 'n1', label: 'OldName', description: 'Auth', type: 'service' },
|
|
{ id: 'n2', label: 'UserModel', description: 'User', type: 'model' },
|
|
],
|
|
edges: [
|
|
{ source: 'n1', target: 'n2', label: 'reads_from', confidence: 'INFERRED' },
|
|
],
|
|
};
|
|
const current = {
|
|
nodes: [
|
|
{ id: 'n1', label: 'NewName', description: 'Auth', type: 'service' },
|
|
{ id: 'n2', label: 'UserModel', description: 'User', type: 'model' },
|
|
],
|
|
edges: [
|
|
{ source: 'n1', target: 'n2', label: 'reads_from', confidence: 'EXTRACTED' },
|
|
],
|
|
};
|
|
writeSnapshotJson(planningDir, snapshot);
|
|
writeGraphJson(planningDir, current);
|
|
const result = graphifyDiff(tmpDir);
|
|
assert.strictEqual(result.nodes.changed, 1, 'n1 label changed');
|
|
assert.strictEqual(result.edges.changed, 1, 'edge confidence changed');
|
|
});
|
|
|
|
// LINKS-03: diff must handle links key in both current and snapshot (LINKS-03)
|
|
test('detects edge changes when graphs use links key (LINKS-03)', () => {
|
|
enableGraphify(planningDir);
|
|
const snapshot = {
|
|
nodes: [
|
|
{ id: 'n1', label: 'AuthService', description: 'Auth', type: 'service' },
|
|
{ id: 'n2', label: 'UserModel', description: 'User', type: 'model' },
|
|
],
|
|
links: [
|
|
{ source: 'n1', target: 'n2', label: 'reads_from', confidence: 'INFERRED' },
|
|
],
|
|
};
|
|
const current = {
|
|
nodes: [
|
|
{ id: 'n1', label: 'AuthService', description: 'Auth', type: 'service' },
|
|
{ id: 'n2', label: 'UserModel', description: 'User', type: 'model' },
|
|
],
|
|
links: [
|
|
{ source: 'n1', target: 'n2', label: 'reads_from', confidence: 'EXTRACTED' },
|
|
],
|
|
};
|
|
writeSnapshotJson(planningDir, snapshot);
|
|
writeGraphJson(planningDir, current);
|
|
const result = graphifyDiff(tmpDir);
|
|
assert.strictEqual(result.edges.changed, 1, 'edge confidence change must be detected via links key');
|
|
assert.strictEqual(result.edges.added, 0);
|
|
assert.strictEqual(result.edges.removed, 0);
|
|
});
|
|
});
|
|
|
|
// AGENT-03: Graceful degradation (graph absent)
|
|
describe('graceful degradation (AGENT-03)', () => {
|
|
let tmpDir;
|
|
let planningDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
planningDir = path.join(tmpDir, '.planning');
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
// AGENT-03: graphifyQuery returns error object when graph.json absent (not exception)
|
|
test('graphifyQuery returns clean error object when graph.json does not exist', () => {
|
|
enableGraphify(planningDir);
|
|
const result = graphifyQuery(tmpDir, 'anything');
|
|
assert.ok(result.error, 'should have error property');
|
|
assert.ok(result.error.includes('No graph'), 'error should mention no graph');
|
|
assert.strictEqual(typeof result.error, 'string', 'error should be a string, not thrown');
|
|
});
|
|
|
|
// AGENT-03: graphifyStatus returns exists:false when graph.json absent (not exception)
|
|
test('graphifyStatus returns exists:false when graph.json does not exist', () => {
|
|
enableGraphify(planningDir);
|
|
const result = graphifyStatus(tmpDir);
|
|
assert.strictEqual(result.exists, false, 'should report exists as false');
|
|
assert.ok(result.message, 'should have a message');
|
|
assert.ok(result.message.includes('No graph'), 'message should mention no graph');
|
|
});
|
|
|
|
// AGENT-03: graphifyQuery with various terms all return clean errors when no graph
|
|
test('graphifyQuery gracefully handles any query term when graph absent', () => {
|
|
enableGraphify(planningDir);
|
|
const terms = ['auth', 'payment', 'nonexistent', ''];
|
|
for (const term of terms) {
|
|
const result = graphifyQuery(tmpDir, term);
|
|
assert.ok(result.error || result.nodes !== undefined,
|
|
`term "${term}" should return error or valid result, not throw`);
|
|
}
|
|
});
|
|
|
|
// D-12: Integration test - query returns expected structure with known graph.json
|
|
test('graphifyQuery returns non-empty results with expected structure for known graph', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyQuery(tmpDir, 'auth');
|
|
assert.ok(!result.error, 'should not have error when graph exists');
|
|
assert.ok(Array.isArray(result.nodes), 'nodes should be an array');
|
|
assert.ok(Array.isArray(result.edges), 'edges should be an array');
|
|
assert.ok(result.nodes.length > 0, 'should have matching nodes for auth term');
|
|
assert.strictEqual(typeof result.total_nodes, 'number', 'total_nodes should be a number');
|
|
assert.strictEqual(typeof result.total_edges, 'number', 'total_edges should be a number');
|
|
assert.strictEqual(result.term, 'auth', 'term should be echoed back');
|
|
});
|
|
|
|
// D-12: graphifyStatus returns valid structure with known graph.json
|
|
test('graphifyStatus returns valid structure when graph.json exists', () => {
|
|
enableGraphify(planningDir);
|
|
writeGraphJson(planningDir, SAMPLE_GRAPH);
|
|
const result = graphifyStatus(tmpDir);
|
|
assert.strictEqual(result.exists, true, 'should report exists as true');
|
|
assert.strictEqual(typeof result.node_count, 'number', 'node_count should be number');
|
|
assert.strictEqual(typeof result.edge_count, 'number', 'edge_count should be number');
|
|
assert.strictEqual(typeof result.stale, 'boolean', 'stale should be boolean');
|
|
assert.strictEqual(typeof result.age_hours, 'number', 'age_hours should be number');
|
|
});
|
|
});
|
|
});
|