MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / main

Function main

scripts/fungrim/recompile-drift.ts:46–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44type Artifact = { rules: CompiledFungrimRule[] };
45type DivergenceAllow = {
46 dropped?: Record<string, string>;
47 added?: Record<string, string>;
48 changed?: Record<string, string>;
49};
50
51/**
52 * Deterministic serialization for content comparison: JSON with object keys
53 * sorted at every level. Rule records are pure JSON data (no functions, no
54 * undefined-bearing holes that matter), so equal stable strings ⇔ equal
55 * content regardless of field order.
56 */
57function stableStringify(value: unknown): string {
58 if (Array.isArray(value))
59 return '[' + value.map(stableStringify).join(',') + ']';
60 if (value !== null && typeof value === 'object') {
61 const entries = Object.entries(value as Record<string, unknown>)
62 .filter(([, v]) => v !== undefined)
63 .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
64 return (
65 '{' +
66 entries
67 .map(([k, v]) => JSON.stringify(k) + ':' + stableStringify(v))
68 .join(',') +
69 '}'
70 );
71 }
72 return JSON.stringify(value);
73}
74
75/** Short content fingerprint (FNV-1a, 32-bit) for compact drift reporting. */
76function contentHash(value: unknown): string {
77 const s = stableStringify(value);
78 let h = 0x811c9dc5;
79 for (let i = 0; i < s.length; i++) {
80 h ^= s.charCodeAt(i);
81 h = Math.imul(h, 0x01000193);
82 }
83 return (h >>> 0).toString(16).padStart(8, '0');
84}
85
86/** Top-level rule fields whose stable serialization differs between sides. */
87function changedFields(
88 a: CompiledFungrimRule,
89 b: CompiledFungrimRule
90): string[] {
91 const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
92 return [...keys]
93 .filter(
94 (k) =>
95 stableStringify((a as Record<string, unknown>)[k]) !==
96 stableStringify((b as Record<string, unknown>)[k])
97 )
98 .sort();
99}
100
101function main(): void {
102 const scriptDir = path.dirname(path.resolve(process.argv[1]));
103 const rootDir = path.resolve(scriptDir, '../..');

Callers 1

recompile-drift.tsFile · 0.70

Calls 10

loadCorpusFunction · 0.90
compileEntriesFunction · 0.90
bareFunction · 0.85
parseMethod · 0.65
logMethod · 0.65
mapMethod · 0.65
hasMethod · 0.65
getMethod · 0.65
keysMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected