feat: add the schedule resolution engine with its test table

This is the business core, written before any UI as the spec requires.
It is pure: no I/O, no database, no clock of its own. Everything arrives
in a ScheduleContext, so every rule below is exhaustively testable.

The engine works on civil (wall-clock) values rather than instants. A
slot that runs 10:00-18:30 runs 10:00-18:30 on the nights the clocks
change too, and day arithmetic goes through UTC, which has no daylight
saving. That turns the March and October switches from edge cases into
non-events, and the tests pin both of them.

Priority order, highest first: a dated exception, a vacation period, a
public holiday the shop closes for, the reference week, then closed.
Exceptions are badged by their stated reason rather than by who created
them, so a holiday imported by the sync shows as a holiday in the UI.

The search for the next opening is bounded to fourteen days. A shop that
is closed forever must not make the server spin; past the horizon the
screen simply says nothing about reopening. Both the never-open week and
the beyond-the-horizon reopening are covered.

"Soon" is strictly under thirty minutes, so a change exactly half an
hour away still reads as plain OPEN or CLOSED.

55 tests; lib/schedule sits at 97% statements and 93% branches against
an 85% floor. The thresholds were verified to actually fail the build
before being committed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
This commit is contained in:
2026-09-20 17:38:01 +02:00
co-authored by Claude Opus 5
parent 42ce09100e
commit 7a1e833971
7 changed files with 1069 additions and 2 deletions
+6 -1
View File
@@ -14,7 +14,12 @@ export default defineConfig({
provider: 'v8',
reporter: ['text', 'html', 'lcov'],
include: ['lib/**'],
exclude: ['lib/**/*.test.ts', 'lib/**/*.test.tsx'],
exclude: [
'lib/**/*.test.ts',
'lib/**/*.test.tsx',
// Generated by `prisma generate`; not ours to cover.
'lib/generated/**',
],
// The business core must stay covered; the CI fails below these.
thresholds: {
'lib/schedule/**': { statements: 85, branches: 85, functions: 85, lines: 85 },