From e23b502dd939740edfc06bfe81bc6f9d05cc656e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Wed, 1 Apr 2026 09:58:20 +0200 Subject: [PATCH] test(repo): guard allocation drag helper boundaries --- scripts/check-architecture-guardrails.mjs | 46 +++++++++++++++++++ .../check-architecture-guardrails.test.mjs | 16 +++++++ 2 files changed, 62 insertions(+) diff --git a/scripts/check-architecture-guardrails.mjs b/scripts/check-architecture-guardrails.mjs index 373964b..30212d7 100644 --- a/scripts/check-architecture-guardrails.mjs +++ b/scripts/check-architecture-guardrails.mjs @@ -164,6 +164,40 @@ export const rules = [ ], forbidden: [], }, + { + file: "apps/web/src/hooks/timelineOptimisticAllocations.ts", + maxLines: 80, + required: [ + { + pattern: /\bexport function reconcileOptimisticEntries\b/, + message: "timeline optimistic helpers must keep server-reconciliation logic centralized", + }, + ], + forbidden: [], + }, + { + file: "apps/web/src/hooks/timelineAllocationFinalize.ts", + maxLines: 100, + required: [ + { + pattern: /\bexport function hasAllocationDateChange\b/, + message: "timeline allocation finalize helpers must keep date-change detection centralized", + }, + { + pattern: /\bexport function shouldTreatAllocationDragAsClick\b/, + message: "timeline allocation finalize helpers must keep click-vs-drag classification centralized", + }, + { + pattern: /\bexport function requiresAllocationFragmentExtraction\b/, + message: "timeline allocation finalize helpers must keep segment extraction rules centralized", + }, + { + pattern: /\bexport function buildAllocationMovedSnapshot\b/, + message: "timeline allocation finalize helpers must keep mutation snapshot creation centralized", + }, + ], + forbidden: [], + }, { file: "apps/web/src/hooks/useTimelineDrag.ts", required: [ @@ -183,6 +217,14 @@ export const rules = [ pattern: /from "\.\/timelineRangeSelection\.js"/, message: "timeline drag must keep range preview and finalization delegated to the extracted helper module", }, + { + pattern: /from "\.\/timelineOptimisticAllocations\.js"/, + message: "timeline drag must keep optimistic allocation reconciliation delegated to the extracted helper module", + }, + { + pattern: /from "\.\/timelineAllocationFinalize\.js"/, + message: "timeline drag must keep allocation drag completion rules delegated to the extracted helper module", + }, ], forbidden: [ { @@ -193,6 +235,10 @@ export const rules = [ pattern: /\bfunction toClientX\b/, message: "timeline drag must not re-inline touch coordinate fallback helpers", }, + { + pattern: /\bfunction (?:hasAllocationDateChange|shouldTreatAllocationDragAsClick|requiresAllocationFragmentExtraction|buildAllocationMovedSnapshot|reconcileOptimisticEntries)\b/, + message: "timeline drag must not re-inline extracted optimistic or allocation finalize helper implementations", + }, ], }, { diff --git a/scripts/check-architecture-guardrails.test.mjs b/scripts/check-architecture-guardrails.test.mjs index 7877853..d0b2c4f 100644 --- a/scripts/check-architecture-guardrails.test.mjs +++ b/scripts/check-architecture-guardrails.test.mjs @@ -74,18 +74,24 @@ describe("architecture guardrails", () => { const touchRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineTouch.ts"); const multiSelectRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineMultiSelect.ts"); const rangeRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineRangeSelection.ts"); + const optimisticRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineOptimisticAllocations.ts"); + const allocationFinalizeRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineAllocationFinalize.ts"); assert.ok(dragRule); assert.ok(livePreviewRule); assert.ok(touchRule); assert.ok(multiSelectRule); assert.ok(rangeRule); + assert.ok(optimisticRule); + assert.ok(allocationFinalizeRule); assert.deepEqual(evaluateRule(dragRule, "function clearLivePreview() {}\n"), [ "apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep live preview behavior delegated to the extracted helper module", "apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep touch fallback and drag disambiguation delegated to the extracted helper module", "apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep multi-select rectangle lifecycle delegated to the extracted helper module", "apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep range preview and finalization delegated to the extracted helper module", + "apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep optimistic allocation reconciliation delegated to the extracted helper module", + "apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep allocation drag completion rules delegated to the extracted helper module", "apps/web/src/hooks/useTimelineDrag.ts: forbidden pattern matched: timeline drag must not re-inline live preview helper implementations", ]); @@ -105,5 +111,15 @@ describe("architecture guardrails", () => { assert.deepEqual(evaluateRule(rangeRule, "export function updateRangeSelectionDraft() {}\n"), [ "apps/web/src/hooks/timelineRangeSelection.ts: missing guardrail anchor: timeline range helpers must keep ordered range finalization centralized", ]); + + assert.deepEqual(evaluateRule(optimisticRule, ""), [ + "apps/web/src/hooks/timelineOptimisticAllocations.ts: missing guardrail anchor: timeline optimistic helpers must keep server-reconciliation logic centralized", + ]); + + assert.deepEqual(evaluateRule(allocationFinalizeRule, "export function hasAllocationDateChange() {}\n"), [ + "apps/web/src/hooks/timelineAllocationFinalize.ts: missing guardrail anchor: timeline allocation finalize helpers must keep click-vs-drag classification centralized", + "apps/web/src/hooks/timelineAllocationFinalize.ts: missing guardrail anchor: timeline allocation finalize helpers must keep segment extraction rules centralized", + "apps/web/src/hooks/timelineAllocationFinalize.ts: missing guardrail anchor: timeline allocation finalize helpers must keep mutation snapshot creation centralized", + ]); }); });