GitNexus/gitnexus/test/unit/reference-edge-key.test.ts
Gergő Magyar 3f2f3ce18e
fix(graph): validate reference sites and dedupe context (#3845)
* fix(context): dedupe references before limits

Select distinct relationship types and symbols in all seven graph
queries before applying their existing 30-row limits. Repeated call
sites must not hide other callers.

Refs #3500

* fix(graph): validate reference provenance

Check source identities and spans before either writer drops provenance.
Retain full spans so nested calls sharing a start stay distinct. Reject
invalid records without publishing a clean receipt; preserve the prior
published index on failure.

Expose repository-wide ingestion receipts to MCP callers. Legacy,
collapsed, point-only and extracted-buffer provenance stays unverified.
Identical identities keep the existing first-writer-wins evidence policy.

Refs #3500

* fix(graph): leave notebook spans unverified

Notebook captures map JSON rows but retain extracted-code columns. Keep these identities explicitly unverified instead of certifying a span that no single source buffer can validate.

Refs #3500

* feat(graph): log ingestion integrity checks

Record summary counts, bounded debug examples, and actionable rejection diagnostics before provenance is discarded. Document the debug command and verify both graph writers retain the logging contract.

Refs #3500

* refactor(graph): simplify reference validation

Refs #3500

* fix(graph): harden reference integrity checks

Reject conflicting sites across streaming partitions.
Preserve DISTINCT limits with indexed label anchors.
Verify span migrations without weakening benchmark gates.

Refs #3500, #3845.

* fix(graph): validate canonical reference spans

Reject access-kind prefixes and use parser UTF-16 column units for source bounds. Cover both writers with malformed identities and native Unicode parser regressions.

Refs #3500, #3845

* test(graph): verify streamed integrity runs

Force streaming in cold and changed-source cases and assert the emitted manifest. Clarify complete-span identity and successful Cypher response docs.

Refs #3500, #3845

* fix(graph): preserve parsed-source provenance

Keep concurrent source edits unverified, bound streamed identity probes,
and distinguish transient MCP uncertainty from missing receipts.

Refs #3845, #3500

* fix(graph): avoid retaining skipped endpoint IDs

Resolve parser identity before allocating test directories.

Refs #3845, #3500

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-08 20:55:14 +00:00

30 lines
1.1 KiB
TypeScript

import { describe, expect, expectTypeOf, it } from 'vitest';
import { referenceEdgeKey } from '../../src/core/ingestion/scope-resolution/graph-bridge/edges.js';
type ReferenceSite = Parameters<typeof referenceEdgeKey>[3];
describe('reference edge span contract', () => {
it('accepts complete spans and legacy points, but rejects partial end coordinates', () => {
expectTypeOf<{
kind: string;
atRange: { startLine: number; startCol: number; endLine: number };
}>().not.toMatchTypeOf<ReferenceSite>();
expectTypeOf<{
kind: string;
atRange: { startLine: number; startCol: number; endCol: number };
}>().not.toMatchTypeOf<ReferenceSite>();
expect(
referenceEdgeKey('CALLS', 'caller', 'target', {
kind: 'call',
atRange: { startLine: 2, startCol: 3 },
}),
).toBe('CALLS:caller->target:2:3');
expect(
referenceEdgeKey('CALLS', 'caller', 'target', {
kind: 'call',
atRange: { startLine: 2, startCol: 3, endLine: 4, endCol: 5 },
}),
).toBe('CALLS:caller->target:2:3:4:5');
});
});