GitNexus/gitnexus/test/integration/orm-dataflow.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

80 lines
3.2 KiB
TypeScript

/**
* Integration Tests: ORM Dataflow Detection (Prisma + Supabase)
*/
import { describe, it, expect, beforeAll } from 'vitest';
import path from 'path';
import { runPipelineFromRepo } from '../../src/core/ingestion/pipeline.js';
import type { PipelineResult } from '../../src/types/pipeline.js';
const ORM_REPO = path.resolve(__dirname, '..', 'fixtures', 'orm-repo');
describe('ORM dataflow detection', () => {
let result: PipelineResult;
beforeAll(async () => {
result = await runPipelineFromRepo(ORM_REPO, () => {});
}, 60000);
it('creates QUERIES edges for Prisma calls', () => {
const queryEdges: { source: string; target: string; reason: string }[] = [];
for (const rel of result.graph.iterRelationships()) {
if (rel.type === 'QUERIES') {
const source = result.graph.getNode(rel.sourceId);
const target = result.graph.getNode(rel.targetId);
if (source && target) {
queryEdges.push({
source: source.properties.filePath || source.properties.name,
target: target.properties.name,
reason: rel.reason ?? '',
});
}
}
}
const prismaEdges = queryEdges.filter((e) => e.source.includes('prisma-service'));
const prismaModels = [...new Set(prismaEdges.map((e) => e.target))];
expect(prismaModels).toContain('user');
expect(prismaModels).toContain('post');
const reasons = prismaEdges.map((e) => e.reason);
expect(reasons.some((r) => r.includes('prisma-findMany'))).toBe(true);
expect(reasons.some((r) => r.includes('prisma-create'))).toBe(true);
});
it('creates QUERIES edges for Supabase calls', () => {
const queryEdges: { source: string; target: string; reason: string }[] = [];
for (const rel of result.graph.iterRelationships()) {
if (rel.type === 'QUERIES') {
const source = result.graph.getNode(rel.sourceId);
const target = result.graph.getNode(rel.targetId);
if (source && target) {
queryEdges.push({
source: source.properties.filePath || source.properties.name,
target: target.properties.name,
reason: rel.reason ?? '',
});
}
}
}
const supabaseEdges = queryEdges.filter((e) => e.source.includes('supabase-service'));
const supabaseModels = [...new Set(supabaseEdges.map((e) => e.target))];
expect(supabaseModels).toContain('bookings');
expect(supabaseModels).toContain('interpreters');
expect(supabaseModels).toContain('sessions');
const reasons = supabaseEdges.map((e) => e.reason);
expect(reasons.some((r) => r.includes('supabase-select'))).toBe(true);
expect(reasons.some((r) => r.includes('supabase-insert'))).toBe(true);
});
it('creates CodeElement nodes for ORM models', () => {
const codeElements: string[] = [];
result.graph.forEachNode((n) => {
if (n.label === 'CodeElement' && n.properties.description?.includes('model/table')) {
codeElements.push(n.properties.name);
}
});
expect(codeElements).toContain('user');
expect(codeElements).toContain('post');
expect(codeElements).toContain('bookings');
expect(codeElements).toContain('interpreters');
expect(codeElements).toContain('sessions');
});
});