()
| 44 | type Artifact = { rules: CompiledFungrimRule[] }; |
| 45 | type 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 | */ |
| 57 | function 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. */ |
| 76 | function 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. */ |
| 87 | function 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 | |
| 101 | function main(): void { |
| 102 | const scriptDir = path.dirname(path.resolve(process.argv[1])); |
| 103 | const rootDir = path.resolve(scriptDir, '../..'); |
no test coverage detected