G
YouTube TikTok Games
Skip to content

u8: registerDayCloseGuard in CloseBusinessDay [04 §4.5 A-1] - #112

Open
arsiihere wants to merge 1 commit into
module-04from
lane-U3/u8
Open

arsiihere wants to merge 1 commit into
module-04from
lane-U3/u8

Conversation

@arsiihere

Copy link
Copy Markdown
Owner

Lane U3, task u8: 04 §4.5 row A-1, built against 01a v2.5 §6.18b (Script row and the "Day-close guard" note) and 01a tests #196 and #197. Marker: Cross (01a). Only the hub half: the client half (G-21) is task UA.

Spec sections

  • 04 v1.0.2 §4.5 A-1.
  • 01a v2.5 §6.18b (:1025, :1033), §9 DAY_CLOSE_BLOCKED (:1208), §10 tests 196 and 197 (:1498–1499).

Change (apps/hub/src/commands/close-business-day.ts)

  • Exports DayCloseGuard = (db, state: Readonly<EngineState>) → { code: ErrorCode; details } | null, plus registerDayCloseGuard(fn), resetDayCloseGuard() and checkDayCloseGuard(db, state). This copies tables/merge-guard.ts: one guard, and a later registration replaces the earlier one.
  • In handle, the guard is asked after the not_open and opened_recently returns and before withStockEffects / append. A non-null result throws new DomainError(code, details). The throw rolls the tx back, so there is no event and no processed_commands row. DAY_CLOSE_BLOCKED (409) already exists in @pos/domain (P0.3).

Tests added (apps/hub/test/commands/business-day.int.test.ts, describe "day-close guard"; afterEach now calls resetDayCloseGuard())

Test Failing first
[01a #196] no guard registered → CloseBusinessDay closes as before, 0 extra statements TypeError: registerDayCloseGuard is not a function
[01a #197] a stub guard → 409 DAY_CLOSE_BLOCKED with its details, no event, no processed_commands row, day still open; asked with (db, state) after not_open / opened_recently TypeError: registerDayCloseGuard is not a function
[01a #197] a stub guard returning null → the day closes TypeError: registerDayCloseGuard is not a function

(Before the implementation, the file's existing 11 tests also failed, on the resetDayCloseGuard import in afterEach.)

Run: business-day.int.test.ts → 14 passed. All 7 hub test files that send CloseBusinessDay → 106 passed. pnpm --filter @pos/hub typecheck and typecheck:tests are clean; eslint is clean.

Statement counts asserted (statementCounter, engine-host snapshot writes left out, as in the existing A-14 count test)

  • With no guard, a guard that issues no statement and returns null gives the same count, and a guard doing one read gives +1. So the guard path costs only the guard's own reads, and unregistered costs 0.

Readings

  • 01a v2.5 allows the guard "in close-business-day.ts (or a sibling day-close-guard.ts)". It is in close-business-day.ts, the row's file.
  • The guard gets ctx.tx.db (the writer's connection, inside BEGIN IMMEDIATE) and ctx.state.

STOPs

None.

Needs: #94 (P0.3, DAY_CLOSE_BLOCKED), merged.


Generated by Claude Code

01a v2.5 §6.18b: registerDayCloseGuard((db, state) → { code, details } | null)
with resetDayCloseGuard / checkDayCloseGuard, the 02a merge-guard pattern.
Asked after not_open / opened_recently and before the append; a non-null
result throws DomainError(code, details) (409 DAY_CLOSE_BLOCKED for 04).
Unregistered → 0 statements, the day closes. Tests 196, 197.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DTZfXNz91zTbB1oaHWoFxj
@arsiihere arsiihere added the lane:U3 label Nov 12, 2026 — with Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant