mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-08-28 05:25:25 +00:00
* 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.
74 lines
2.8 KiB
TypeScript
74 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
// ==========================================================================
|
|
// PR4 Performance Optimizations — verify behavior preserved after changes
|
|
// Tests the pure functions underlying the O(1) lookup optimizations.
|
|
// ==========================================================================
|
|
|
|
describe('nodeById Map — O(1) lookup correctness', () => {
|
|
// Positive: Map.get returns correct node
|
|
it('Map provides O(1) lookup by ID', () => {
|
|
const nodes = [
|
|
{ id: 'Function:a.ts:foo', label: 'Function', name: 'foo' },
|
|
{ id: 'Class:b.ts:Bar', label: 'Class', name: 'Bar' },
|
|
{ id: 'File:c.ts', label: 'File', name: 'c.ts' },
|
|
];
|
|
const nodeById = new Map(nodes.map((n) => [n.id, n]));
|
|
|
|
expect(nodeById.get('Function:a.ts:foo')?.name).toBe('foo');
|
|
expect(nodeById.get('Class:b.ts:Bar')?.name).toBe('Bar');
|
|
expect(nodeById.get('File:c.ts')?.label).toBe('File');
|
|
});
|
|
|
|
// Positive: handles duplicate IDs (last wins)
|
|
it('last node wins on duplicate IDs', () => {
|
|
const nodes = [
|
|
{ id: 'File:a.ts', label: 'File', name: 'first' },
|
|
{ id: 'File:a.ts', label: 'File', name: 'second' },
|
|
];
|
|
const nodeById = new Map(nodes.map((n) => [n.id, n]));
|
|
|
|
expect(nodeById.get('File:a.ts')?.name).toBe('second');
|
|
expect(nodeById.size).toBe(1);
|
|
});
|
|
|
|
// Negative: missing ID returns undefined
|
|
it('returns undefined for non-existent ID', () => {
|
|
const nodeById = new Map([['File:a.ts', { id: 'File:a.ts' }]]);
|
|
expect(nodeById.get('NonExistent:x')).toBeUndefined();
|
|
});
|
|
|
|
// Negative: empty map
|
|
it('empty Map returns undefined for any key', () => {
|
|
const nodeById = new Map<string, any>();
|
|
expect(nodeById.get('anything')).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('Set.has — O(1) highlight matching', () => {
|
|
// Positive: exact match
|
|
it('Set.has returns true for present IDs', () => {
|
|
const idSet = new Set(['Function:a.ts:foo', 'Class:b.ts:Bar']);
|
|
expect(idSet.has('Function:a.ts:foo')).toBe(true);
|
|
expect(idSet.has('Class:b.ts:Bar')).toBe(true);
|
|
});
|
|
|
|
// Negative: missing ID
|
|
it('Set.has returns false for absent IDs', () => {
|
|
const idSet = new Set(['Function:a.ts:foo']);
|
|
expect(idSet.has('Function:a.ts:bar')).toBe(false);
|
|
expect(idSet.has('')).toBe(false);
|
|
});
|
|
|
|
// Positive: works with graph node IDs containing special chars
|
|
it('handles IDs with colons, dots, and slashes', () => {
|
|
const idSet = new Set(['Function:src/utils/path-resolver.ts:resolveFile']);
|
|
expect(idSet.has('Function:src/utils/path-resolver.ts:resolveFile')).toBe(true);
|
|
});
|
|
|
|
// Negative: case sensitive
|
|
it('is case-sensitive', () => {
|
|
const idSet = new Set(['Function:a.ts:Foo']);
|
|
expect(idSet.has('Function:a.ts:foo')).toBe(false);
|
|
});
|
|
});
|