// PBI-74 / T-846: dev-only schaduw-store fingerprint verifyer. // Logt counts van oude (useBacklogStore) en nieuwe (useProductWorkspaceStore) // na elke hydratie- of realtime-event. Bij mismatch verschijnt er een // console.warn zodat we tijdens Story 2 in dev-tools zien dat beide stores // dezelfde inhoud houden. // // TODO(PBI-74 / Story 8 / T-878): verwijder dit bestand en alle aanroepen // vóór merge van de cleanup-PR. import { useBacklogStore } from '@/stores/backlog-store' import { useProductWorkspaceStore } from '@/stores/product-workspace/store' interface Fingerprint { pbis: number storiesByPbi: Record tasksByStory: Record } function fingerprintOld(): Fingerprint { const s = useBacklogStore.getState() const storiesByPbi: Record = {} for (const [pbiId, list] of Object.entries(s.storiesByPbi)) { storiesByPbi[pbiId] = list.length } const tasksByStory: Record = {} for (const [storyId, list] of Object.entries(s.tasksByStory)) { tasksByStory[storyId] = list.length } return { pbis: s.pbis.length, storiesByPbi, tasksByStory } } function fingerprintNew(): Fingerprint { const s = useProductWorkspaceStore.getState() const storiesByPbi: Record = {} for (const [pbiId, ids] of Object.entries(s.relations.storyIdsByPbi)) { storiesByPbi[pbiId] = ids.length } const tasksByStory: Record = {} for (const [storyId, ids] of Object.entries(s.relations.taskIdsByStory)) { tasksByStory[storyId] = ids.length } return { pbis: s.relations.pbiIds.length, storiesByPbi, tasksByStory } } function shapeEqual(a: Record, b: Record): boolean { const keys = new Set([...Object.keys(a), ...Object.keys(b)]) for (const k of keys) { if ((a[k] ?? 0) !== (b[k] ?? 0)) return false } return true } export function logWorkspaceFingerprint(label: string): void { if (process.env.NODE_ENV === 'production') return const oldFp = fingerprintOld() const newFp = fingerprintNew() const match = oldFp.pbis === newFp.pbis && shapeEqual(oldFp.storiesByPbi, newFp.storiesByPbi) && shapeEqual(oldFp.tasksByStory, newFp.tasksByStory) if (!match) { console.warn( `[workspace-fingerprint:${label}] MISMATCH oud↔nieuw`, { old: oldFp, new: newFp }, ) } else if (process.env.NEXT_PUBLIC_DEBUG_WORKSPACE_FINGERPRINT === '1') { console.debug(`[workspace-fingerprint:${label}] match`, oldFp) } }