unit(D8): assign conflict gate (rule 1 duplicate-in-instance)

This commit is contained in:
Tiel Coder
2026-11-18 18:26:04 +00:00
parent b664de65f5
commit e1895079ff
2 changed files with 50 additions and 0 deletions
+19
View File
@@ -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",
});
});
});
+31
View File
@@ -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 [];
}