mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-05 08:06:02 +00:00
* feat: configure eslint with unused import removal Add ESLint v9 (flat config) for code quality: - eslint-plugin-unused-imports for auto-removing dead imports - @typescript-eslint for TypeScript-aware linting - eslint-plugin-react-hooks for React hooks rules - eslint-config-prettier to avoid formatting conflicts - lint-staged runs eslint --fix before prettier on .ts/.tsx - CI lint job added to ci-quality.yml * refactor: remove unused imports via eslint --fix Auto-fixed by eslint-plugin-unused-imports. No logic changes. * chore: add eslint fix commit to .git-blame-ignore-revs
126 lines
3.1 KiB
TypeScript
126 lines
3.1 KiB
TypeScript
/**
|
|
* Test helper: In-memory knowledge graph builder
|
|
*
|
|
* Provides a convenient API for constructing test graphs
|
|
* without touching the filesystem or LadybugDB.
|
|
*/
|
|
import { createKnowledgeGraph } from '../../src/core/graph/graph.js';
|
|
import type { KnowledgeGraph, NodeLabel, RelationshipType } from '../../src/core/graph/types.js';
|
|
|
|
export interface TestNodeInput {
|
|
id: string;
|
|
label: NodeLabel;
|
|
name: string;
|
|
filePath: string;
|
|
startLine?: number;
|
|
endLine?: number;
|
|
isExported?: boolean;
|
|
extra?: Record<string, any>;
|
|
}
|
|
|
|
export interface TestRelInput {
|
|
sourceId: string;
|
|
targetId: string;
|
|
type: RelationshipType;
|
|
confidence?: number;
|
|
reason?: string;
|
|
step?: number;
|
|
}
|
|
|
|
/**
|
|
* Build a test graph from simple input arrays.
|
|
*/
|
|
export function buildTestGraph(
|
|
nodes: TestNodeInput[],
|
|
relationships: TestRelInput[] = [],
|
|
): KnowledgeGraph {
|
|
const graph = createKnowledgeGraph();
|
|
|
|
for (const n of nodes) {
|
|
graph.addNode({
|
|
id: n.id,
|
|
label: n.label,
|
|
properties: {
|
|
name: n.name,
|
|
filePath: n.filePath,
|
|
startLine: n.startLine,
|
|
endLine: n.endLine,
|
|
isExported: n.isExported,
|
|
...n.extra,
|
|
},
|
|
});
|
|
}
|
|
|
|
for (const r of relationships) {
|
|
graph.addRelationship({
|
|
id: `${r.sourceId}-${r.type}-${r.targetId}`,
|
|
sourceId: r.sourceId,
|
|
targetId: r.targetId,
|
|
type: r.type,
|
|
confidence: r.confidence ?? 1.0,
|
|
reason: r.reason ?? '',
|
|
step: r.step,
|
|
});
|
|
}
|
|
|
|
return graph;
|
|
}
|
|
|
|
/**
|
|
* Create a minimal graph with a few files, functions, and relationships.
|
|
* Useful as a baseline for integration tests.
|
|
*/
|
|
export function createMinimalTestGraph(): KnowledgeGraph {
|
|
return buildTestGraph(
|
|
[
|
|
{ id: 'File:src/index.ts', label: 'File', name: 'index.ts', filePath: 'src/index.ts' },
|
|
{ id: 'File:src/utils.ts', label: 'File', name: 'utils.ts', filePath: 'src/utils.ts' },
|
|
{
|
|
id: 'Function:src/index.ts:main:1',
|
|
label: 'Function',
|
|
name: 'main',
|
|
filePath: 'src/index.ts',
|
|
startLine: 1,
|
|
endLine: 10,
|
|
isExported: true,
|
|
},
|
|
{
|
|
id: 'Function:src/utils.ts:helper:1',
|
|
label: 'Function',
|
|
name: 'helper',
|
|
filePath: 'src/utils.ts',
|
|
startLine: 1,
|
|
endLine: 5,
|
|
isExported: true,
|
|
},
|
|
{
|
|
id: 'Class:src/index.ts:App:12',
|
|
label: 'Class',
|
|
name: 'App',
|
|
filePath: 'src/index.ts',
|
|
startLine: 12,
|
|
endLine: 30,
|
|
isExported: true,
|
|
},
|
|
{ id: 'Folder:src', label: 'Folder', name: 'src', filePath: 'src' },
|
|
],
|
|
[
|
|
{
|
|
sourceId: 'Function:src/index.ts:main:1',
|
|
targetId: 'Function:src/utils.ts:helper:1',
|
|
type: 'CALLS',
|
|
},
|
|
{
|
|
sourceId: 'Function:src/index.ts:main:1',
|
|
targetId: 'Class:src/index.ts:App:12',
|
|
type: 'CALLS',
|
|
},
|
|
{ sourceId: 'File:src/index.ts', targetId: 'Function:src/index.ts:main:1', type: 'CONTAINS' },
|
|
{
|
|
sourceId: 'File:src/utils.ts',
|
|
targetId: 'Function:src/utils.ts:helper:1',
|
|
type: 'CONTAINS',
|
|
},
|
|
],
|
|
);
|
|
}
|