feat(entry): operator-issued entry + exit plate-swap reconciliation
Build desktop / desktop (push) Successful in 4m29s
Build & push images / images (push) Successful in 2m51s
CI / check (push) Successful in 37s

Two halves of one anti-fraud design.

(A) Operator-issued entry — when the physical entry button is broken, an
operator can issue an entry ticket so a real car isn't blocked out of the lot.
This hands the operator-adversary a mint, so it is:
  - PRESENCE-GATED like the physical button: a real car must be present (radar/
    loop AND camera busy). Enforced BOTH sides — the server re-checks current
    presence so a direct POST can't bypass a disabled button; no presence loop
    => feature unavailable; a no-presence attempt signs an anomaly.
  - FLAGGED: vehicle_entry source=manual + operatorInitiated + operator, PLUS a
    companion entry.operatorIssued anomaly (the adversary path always leaves a
    red-flag row).
  - capacity-OVERRIDE allowed but stamped lotFull (a broken button mustn't trap
    a legit car).
  New session:create permission (migration 0019 -> operator role, admin-
  revocable), POST /api/entry/issue (open-shift gated), EntryFlow.
  issueForOperator; the fraud-critical print->sign->open->snapshot sequence is
  factored into one shared #issueTicket (button + operator). UI: the entry
  BarrierLight becomes a clickable issue-control when presence+permission+shift
  meet (confirm -> issue).

(B) Exit plate-swap reconciliation — defends the ticket-swap fraud the mint
enables (paid car let out on a fresh $0 ticket, original ticket lingers
"inside", occupancy drifts up by phantom cars). The plate is the invariant:
ExitFlow.#reconcilePlateAtExit compares the exiting plate against all OPEN
sessions' entry plates, EXACT + HIGH-CONFIDENCE only (>=0.85; a fuzzy read never
gates — ANPR is advisory). On a match under a DIFFERENT ticket:
  - BOOTH path: returns swap_suspected + signs exit.plateSwapSuspected; the
    pay/exit modal shows a red warning + "Override & release" (override signs an
    attributed exit.plateSwapOverride). Flag+override, never a silent hard block
    (exit fails-open; a plate is never the sole gate).
  - READER path (no operator): log-only anomaly + fail-open.
  Extended BoothExitResult + /api/exit (override); boothExit client returns a
  structured swap result.

Verified: full monorepo build/lint/test green (229 server tests incl. 4 new:
hold-on-swap, override-releases-with-attribution, low-confidence-no-warning,
own-plate-no-warning). New wiki: operator-issued-entry.md +
plate-reconciliation.md; cross-linked from entry-exit-points, capacity-
occupancy, index. Preserves "a plate never OPENS a barrier alone — and now never
TRAPS a car alone either."

Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
2026-07-01 12:17:52 +02:00
parent 114a32e6f2
commit 33c4ea1e91
20 changed files with 760 additions and 62 deletions
+35
View File
@@ -0,0 +1,35 @@
import type { FastifyInstance } from "fastify";
import { requirePermission } from "../auth.js";
import type { EntryFlow } from "../entry-flow.js";
import type { LaneStatus } from "../lane-status.js";
import type { ShiftService } from "../shift-service.js";
import { NoShiftOpenError } from "../shift-service.js";
// Operator-issued entry (2026-07-01). When the physical entry button is broken, an operator
// may issue an entry ticket — a FLAGGED mint (vehicle_entry source=manual + operatorInitiated
// + a companion anomaly), gated EXACTLY like the physical button: a real vehicle must be
// present (radar/loop AND camera). The presence gate is enforced HERE (server-side), so a
// direct POST can't bypass a disabled UI button. Money-adjacent → requires an open shift.
// See wiki/concepts/operator-issued-entry.md.
export async function entryRoutes(
app: FastifyInstance,
entryFlow: EntryFlow,
laneStatus: LaneStatus,
shift: ShiftService,
): Promise<void> {
const guard = requirePermission("session:create");
app.post("/api/entry/issue", { preHandler: guard }, async (req, reply) => {
// Gate on an open shift (a minted entry belongs to an accountable operator).
if (!shift.currentOpenShift()) {
return reply.code(409).send({ error: new NoShiftOpenError().message });
}
// The camera side of the presence gate = the live entry lane-busy state; the radar/loop
// side is checked inside the flow (its per-relay presence guard).
const cameraBusy = laneStatus.snapshot().entry;
const res = await entryFlow.issueForOperator(req.user.username, cameraBusy);
if (!res.ok) return reply.code(409).send({ error: res.reason });
return res;
});
}
+14 -2
View File
@@ -30,6 +30,9 @@ interface PayBody {
}
interface ExitBody {
identity: string;
/** Operator consciously releases a suspected plate-swap exit (re-submit after the
* first call returned status "swap_suspected"). Signs an attributed override anomaly. */
override?: boolean;
}
interface VoucherBody {
identity: string;
@@ -109,8 +112,17 @@ export async function payRoutes(
async (req, reply) => {
const identity = (req.body?.identity ?? "").trim();
if (!identity) return reply.code(400).send({ error: "identity required" });
const res = await exitFlow.exitForBooth(identity);
if (!res.ok) return reply.code(409).send({ error: res.reason, status: res.status });
const res = await exitFlow.exitForBooth(identity, {
override: req.body?.override === true,
operator: req.user?.username,
});
// A suspected plate-swap returns the full detail so the modal can warn + offer override.
if (!res.ok) {
if (res.status === "swap_suspected") {
return reply.code(409).send({ error: res.reason, status: res.status, plate: res.plate, otherIdentity: res.otherIdentity, otherEnteredAt: res.otherEnteredAt });
}
return reply.code(409).send({ error: res.reason, status: res.status });
}
return reply.code(200).send(res);
},
);