GitNexus/gitnexus-web/test/unit/constants.test.ts
Gergő Magyar 4cfd3e4cde
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
fix(ingestion): stabilize community and process IDs (#3855)
* fix: stabilize community and process IDs

Run-order IDs renumbered unrelated records during analysis. Derive community
IDs from their smallest member and process IDs from their endpoint pair.
Preserve opaque community IDs in web grouping and color selection.

Refresh PDG and mini-repo graph digests for stable fallback community labels;
node/edge counts and membership-normalized edge triples are unchanged.
Update singleton skill-generation expectations for the same stable IDs.

Reanalysis migrates positional IDs once. Selective database reconciliation
remains separate work.

Closes #3851

* perf: trim stable graph identity overhead

Avoid per-symbol entry tuples and reuse each community color during graph conversion.

* perf: reduce graph processing allocations

* perf: release completed pipeline context

Isolate the graph integrity lookup's closure so retained graphs cannot
keep pipeline phase results alive. Drop the completed deferred callback
before database loading. Regression tests fail on both prior paths.

* docs: clarify stable graph ID contracts

* fix: address stable ID review feedback (#3855)

Compare parser output across runtimes while keeping full-graph reuse
checks. Release deferred phases before compaction writes and document
the ID migration, tie ordering, and identity limits.

Pin breadth-first layout, palette coverage, and callback lifetime.

Refs #3855

Note: pre-existing failure in setup-skills.test.ts not addressed by this PR.

Note: pre-existing failure in setup.test.ts not addressed by this PR.

Note: pre-existing failure in worker-pool-resilience.test.ts not addressed by this PR.

* fix(bench): read packed cache sections

The #3856 cache migration replaced loose V8 shards with file-result
packs. The interning probe fails before timing on unchanged ea97d6db8.

Load every published facts and scope section through the baseline
readers. Reject incomplete or corrupt corpora and retain legacy support.
Record the format; preserve timed operations, warmups, equality checks,
and the 5% acceptance budget. Packed and legacy timings are not directly
comparable.

Validate with 95 tests, source/test typechecks, and real-cache base/base
and base/PR controls. Both controls pass the unchanged interning gate.

Refs #3856, #3855

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-10 17:21:43 +00:00

144 lines
4.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
NODE_COLORS,
NODE_SIZES,
COMMUNITY_COLORS,
getCommunityColor,
DEFAULT_VISIBLE_LABELS,
FILTERABLE_LABELS,
ALL_EDGE_TYPES,
DEFAULT_VISIBLE_EDGES,
EDGE_INFO,
} from '../../src/lib/constants';
describe('NODE_COLORS', () => {
it('has a color for every node label used in NODE_SIZES', () => {
for (const label of Object.keys(NODE_SIZES)) {
expect(NODE_COLORS).toHaveProperty(label);
expect(NODE_COLORS[label as keyof typeof NODE_COLORS]).toMatch(/^#[0-9a-f]{6}$/i);
}
});
});
describe('NODE_SIZES', () => {
it('gives Project the largest size', () => {
const maxLabel = Object.entries(NODE_SIZES).reduce((a, b) => (a[1] > b[1] ? a : b));
expect(maxLabel[0]).toBe('Project');
});
it('gives structural nodes larger sizes than code nodes', () => {
expect(NODE_SIZES.Folder).toBeGreaterThan(NODE_SIZES.Function);
expect(NODE_SIZES.File).toBeGreaterThan(NODE_SIZES.Variable);
});
});
describe('getCommunityColor', () => {
it('preserves colors for legacy community IDs', () => {
for (let i = 0; i < 20; i++) {
expect(getCommunityColor(`comm_${i}`)).toBe(getCommunityColor(i));
}
});
it('assigns deterministic valid colors to opaque IDs without collapsing the palette', () => {
const ids = [
...Array.from({ length: 32 }, (_, i) => `comm_abcdef${i.toString(16).padStart(6, '0')}`),
'comm_123456789012',
'comm_abcdef123456_2',
];
const before = ids.map((id) => getCommunityColor(id));
const reversed = new Map([...ids].reverse().map((id) => [id, getCommunityColor(id)]));
for (const [i, id] of ids.entries()) {
expect(before[i]).toMatch(/^#[0-9a-f]{6}$/i);
expect(reversed.get(id)).toBe(before[i]);
}
expect(new Set(before)).toEqual(new Set(COMMUNITY_COLORS));
});
it('preserves safe numeric IDs and hashes digit strings outside the safe integer range', () => {
expect(getCommunityColor('comm_123456789013')).toBe('#f97316');
expect(getCommunityColor('comm_9007199254740993')).toBe('#f97316');
});
it('returns valid hex colors', () => {
for (let i = 0; i < 20; i++) {
expect(getCommunityColor(i)).toMatch(/^#[0-9a-f]{6}$/i);
}
});
it('wraps around the palette', () => {
const paletteSize = COMMUNITY_COLORS.length;
expect(getCommunityColor(0)).toBe(getCommunityColor(paletteSize));
expect(getCommunityColor(1)).toBe(getCommunityColor(paletteSize + 1));
});
});
describe('DEFAULT_VISIBLE_LABELS', () => {
it('includes common structural and code labels', () => {
expect(DEFAULT_VISIBLE_LABELS).toContain('File');
expect(DEFAULT_VISIBLE_LABELS).toContain('Function');
expect(DEFAULT_VISIBLE_LABELS).toContain('Class');
});
it('excludes noisy labels by default', () => {
expect(DEFAULT_VISIBLE_LABELS).not.toContain('Variable');
expect(DEFAULT_VISIBLE_LABELS).not.toContain('Import');
});
});
describe('FILTERABLE_LABELS', () => {
it('includes all newly added node types', () => {
expect(FILTERABLE_LABELS).toContain('Enum');
expect(FILTERABLE_LABELS).toContain('Type');
expect(FILTERABLE_LABELS).toContain('Decorator');
expect(FILTERABLE_LABELS).toContain('Variable');
expect(FILTERABLE_LABELS).toContain('Protocol');
expect(FILTERABLE_LABELS).toContain('Category');
});
it('every filterable label has a defined color in NODE_COLORS', () => {
for (const label of FILTERABLE_LABELS) {
expect(NODE_COLORS).toHaveProperty(label);
expect(NODE_COLORS[label as keyof typeof NODE_COLORS]).toMatch(/^#[0-9a-f]{6}$/i);
}
});
it('every filterable label has a defined size in NODE_SIZES', () => {
for (const label of FILTERABLE_LABELS) {
expect(NODE_SIZES).toHaveProperty(label);
expect(NODE_SIZES[label as keyof typeof NODE_SIZES]).toBeGreaterThan(0);
}
});
it('has no duplicate entries', () => {
const unique = new Set(FILTERABLE_LABELS);
expect(unique.size).toBe(FILTERABLE_LABELS.length);
});
it('is a subset of DEFAULT_VISIBLE_LABELS plus togglable labels', () => {
const allKnown = new Set(Object.keys(NODE_COLORS));
for (const label of FILTERABLE_LABELS) {
expect(allKnown.has(label)).toBe(true);
}
});
});
describe('edge types', () => {
it('ALL_EDGE_TYPES contains all EDGE_INFO keys', () => {
const edgeInfoKeys = Object.keys(EDGE_INFO).sort();
const allEdgeTypes = [...ALL_EDGE_TYPES].sort();
expect(edgeInfoKeys).toEqual(allEdgeTypes);
});
it('DEFAULT_VISIBLE_EDGES is a subset of ALL_EDGE_TYPES', () => {
for (const type of DEFAULT_VISIBLE_EDGES) {
expect(ALL_EDGE_TYPES).toContain(type);
}
});
it('EDGE_INFO entries have color and label', () => {
for (const info of Object.values(EDGE_INFO)) {
expect(info.color).toMatch(/^#[0-9a-f]{6}$/i);
expect(info.label.length).toBeGreaterThan(0);
}
});
});