diff --git a/src/domain/assign.test.ts b/src/domain/assign.test.ts new file mode 100644 index 0000000..7b2ad64 --- /dev/null +++ b/src/domain/assign.test.ts @@ -0,0 +1,19 @@ +import { describe, test, expect } from "vitest"; +import { assignHardConflicts } from "@/domain/assign"; + +describe("assignHardConflicts", () => { + test("allows an assign when the volunteer is not already in the instance", () => { + const conflicts = assignHardConflicts({ alreadyAssignedInInstance: false }); + expect(conflicts).toEqual([]); + }); + + test("hard-blocks a duplicate assignment in the same instance (rule 1)", () => { + const conflicts = assignHardConflicts({ alreadyAssignedInInstance: true }); + + expect(conflicts).toHaveLength(1); + expect(conflicts[0]).toMatchObject({ + code: "duplicate_in_instance", + severity: "hard", + }); + }); +}); diff --git a/src/domain/assign.ts b/src/domain/assign.ts new file mode 100644 index 0000000..77ed105 --- /dev/null +++ b/src/domain/assign.ts @@ -0,0 +1,31 @@ +import type { Conflict } from "./conflicts"; + +/** + * Assign conflict gate — unit D8 (BUILD-SPEC §7 rule 1). + * + * Pure decision the assign route calls after it resolves the slot's facts. + * D8 enforces the duplicate-in-instance rule here (a volunteer holds one + * active assignment per service instance); skill gating (rules 6/13) stays on + * the ranked picker and is expanded by D9/D10. + */ + +export interface AssignFacts { + /** True when the volunteer already holds an active assignment in this instance. */ + alreadyAssignedInInstance: boolean; +} + +/** Every hard conflict that blocks the assign; empty when the assign is allowed. */ +export function assignHardConflicts(facts: AssignFacts): Conflict[] { + if (facts.alreadyAssignedInInstance) { + return [ + { + code: "duplicate_in_instance", + severity: "hard", + message: + "Already assigned in this instance; a volunteer holds one active " + + "assignment per service instance.", + }, + ]; + } + return []; +}