GitNexus/gitnexus/src/core/graph/node-identity.ts
Gergő Magyar e6ae04ed84
fix(embeddings): reject corrupt identities before mutation (#3614)
* fix(embeddings): reject corrupt identities before mutation (U2)

* fix(embeddings): preserve exact Unicode keys (U2)

* fix(storage): validate identities before opening CSVs

* fix(embeddings): validate caches before mutation

* ci: gate native embedding identity benchmark

* test(embeddings): run identity proofs on native OSes

* docs: describe CSV identity validation pass

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-10-17 18:45:28 +01:00

15 lines
707 B
TypeScript

/** Identity columns must survive CSV encoding and address exactly one node. */
export function assertValidGraphNodeId(id: unknown, context: string): asserts id is string {
if (
typeof id === 'string' &&
id.trim().length > 0 &&
// CSV normalizes CR and strips these characters. The Unicode flag matches
// lone surrogates while preserving valid supplementary code points.
!/[\x00-\x08\x0B-\x1F\x7F\uD800-\uDFFF\uFFFE\uFFFF]/u.test(id)
)
return;
const sample = typeof id === 'string' ? JSON.stringify(id.slice(0, 120)) : typeof id;
throw new Error(
`${context}: invalid graph node ID (${sample}). Index integrity cannot be verified; rebuild with analyze --force.`,
);
}