test(repo): guard allocation drag helper boundaries

This commit is contained in:
2026-04-01 09:58:20 +02:00
parent 6dac993521
commit e23b502dd9
2 changed files with 62 additions and 0 deletions
+46
View File
@@ -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",
},
],
},
{
@@ -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",
]);
});
});