GitNexus/gitnexus/test/unit/structure-processor.test.ts
Gergő Magyar bf09eab95b
feat: configure prettier with pre-commit hook (#563)
* feat: configure prettier with pre-commit hook integration

Add prettier, lint-staged, and prettier-plugin-tailwindcss at the repo
root with husky pre-commit hook integration. Moves husky from
gitnexus/ to root package.json for reliable hook installation.

- Root package.json with prepare/format/format:check scripts
- .prettierrc with endOfLine:lf and tailwindStylesheet for TW v4
- .prettierignore excluding fixtures, vendor, generated, *.d.ts, *.md
- .gitattributes enforcing LF line endings for Windows consistency
- Pre-commit hook uses direct node_modules/.bin/ paths (no npx)

* style: apply prettier formatting to entire codebase

One-time bulk format. No logic changes.
Use .git-blame-ignore-revs to skip this commit in git blame.

* chore: add .git-blame-ignore-revs for prettier format commit

* perf: pre-commit hook runs only tests related to staged files

Use vitest --related to scope test execution to tests that import
the changed files, instead of running the full suite on every commit.

* perf: remove vitest from pre-commit hook, keep in CI only

Pre-commit now runs lint-staged + tsc only. Tests run in CI
(ci-tests.yml) where they belong — keeps commits fast.

* ci: add prettier format check to quality workflow

PRs will now fail if code isn't formatted with prettier.
2026-03-28 14:58:04 +00:00

95 lines
3.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { processStructure } from '../../src/core/ingestion/structure-processor.js';
import { createKnowledgeGraph } from '../../src/core/graph/graph.js';
describe('processStructure', () => {
it('creates File nodes for each path', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/index.ts', 'src/utils.ts']);
const fileNodes = graph.nodes.filter((n) => n.label === 'File');
expect(fileNodes).toHaveLength(2);
expect(fileNodes.map((n) => n.properties.name)).toContain('index.ts');
expect(fileNodes.map((n) => n.properties.name)).toContain('utils.ts');
});
it('creates Folder nodes for directories', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/lib/utils.ts']);
const folderNodes = graph.nodes.filter((n) => n.label === 'Folder');
expect(folderNodes.map((n) => n.properties.name)).toContain('src');
expect(folderNodes.map((n) => n.properties.name)).toContain('lib');
});
it('creates CONTAINS relationships from parent to child', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/index.ts']);
const rels = graph.relationships.filter((r) => r.type === 'CONTAINS');
expect(rels).toHaveLength(1);
expect(rels[0].sourceId).toBe('Folder:src');
expect(rels[0].targetId).toBe('File:src/index.ts');
});
it('creates nested folder hierarchy', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/core/graph/types.ts']);
const folderNodes = graph.nodes.filter((n) => n.label === 'Folder');
expect(folderNodes).toHaveLength(3); // src, core, graph
const rels = graph.relationships.filter((r) => r.type === 'CONTAINS');
expect(rels).toHaveLength(3); // src->core, core->graph, graph->types.ts
});
it('deduplicates shared folders', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/a.ts', 'src/b.ts']);
const folderNodes = graph.nodes.filter((n) => n.label === 'Folder');
// 'src' should only appear once
expect(folderNodes.filter((n) => n.properties.name === 'src')).toHaveLength(1);
});
it('handles single file without directory', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['index.ts']);
expect(graph.nodes).toHaveLength(1);
expect(graph.nodes[0].label).toBe('File');
expect(graph.relationships).toHaveLength(0);
});
it('handles empty paths array', () => {
const graph = createKnowledgeGraph();
processStructure(graph, []);
expect(graph.nodeCount).toBe(0);
expect(graph.relationshipCount).toBe(0);
});
it('sets CONTAINS relationship confidence to 1.0', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/index.ts']);
const rels = graph.relationships;
for (const rel of rels) {
expect(rel.confidence).toBe(1.0);
}
});
it('stores filePath as the full cumulative path', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/core/utils.ts']);
const utils = graph.nodes.find((n) => n.properties.name === 'utils.ts');
expect(utils!.properties.filePath).toBe('src/core/utils.ts');
const core = graph.nodes.find((n) => n.properties.name === 'core');
expect(core!.properties.filePath).toBe('src/core');
});
it('handles deeply nested paths', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['a/b/c/d/e.ts']);
expect(graph.nodes.filter((n) => n.label === 'Folder')).toHaveLength(4);
expect(graph.nodes.filter((n) => n.label === 'File')).toHaveLength(1);
});
it('generates correct node IDs', () => {
const graph = createKnowledgeGraph();
processStructure(graph, ['src/index.ts']);
expect(graph.getNode('Folder:src')).toBeDefined();
expect(graph.getNode('File:src/index.ts')).toBeDefined();
});
});