phase-4: the live tax position, deadlines and the notifications behind them

The dashboard, the deadline engine, the three sweeps and the notification
channels. Confirm a comprobante and the IVA and IRP figures move; every
headline number opens the documents behind it.

The dashboard does no arithmetic of its own: it picks inputs and calls
packages/rules. The acceptance test asserts the API's numbers equal what
computeF120 and computeF515 produce over the same rows, before and after the
bandeja is confirmed, so a drift in either direction fails.

Deadlines come from the calendario perpetuo, skipping any period earlier than
the date the taxpayer took the obligation on. Without that guard a brand new
account opens on a red overdue card for a period that predates it.

Sweeps are idempotent by dedupe key rather than bookkeeping: a restarted
poller, a second replica and a crash mid-sweep all converge on one run, and one
reminder per user per period per milestone. They queue notifications rather
than sending them, so a channel being down retries on the job schedule. The
T-10 test derives the date from dueDateFor rather than restating the calendar.

Auto-confirm only touches what the rules were confident about and never a
decision the user already made. An unconfigured channel is absent rather than
broken: the fan-out skips it, the UI hides it, and a frozen account receives
nothing.

Web: the dashboard's three zones with swipeable position cards and traceable
numbers, the deadlines timeline, and the app shell with the tab bar and the
persistent scan button FLOWS.md asks for.

Two additions to the specs, both marked: hasDocuments on DashboardDto, without
which a position of all zeros is indistinguishable from a real one and the
first-run state never shows; and an insight_dismissals table, which FLOWS.md
requires and SPEC.md has nowhere to put.

Also: pnpm db:reset, because the e2e suite changes the seed it runs against and
a suite that is not repeatable is not a suite.

280 vitest tests, 51 Playwright tests, rules coverage still 100%, typecheck and
lint clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-09-04 04:42:32 +00:00
co-authored by Claude Opus 5
parent b074456b70
commit 5dc284c5f2
42 changed files with 2915 additions and 66 deletions
+17 -2
View File
@@ -10,6 +10,7 @@ import type { AppDeps } from '../http/context';
import { type Env, parseEnv } from '../lib/env';
import { createHandlers, createPoller, type Poller } from '../modules/jobs';
import type { OcrProvider } from '../modules/documents/ocr';
import { createChannels, type Channels } from '../modules/notifications';
import { createStorage, type StorageDriver } from '../modules/storage';
export const TEST_ENV: Record<string, string> = {
@@ -25,12 +26,18 @@ export interface HarnessOptions {
/** Stand in for the Anthropic call, so OCR paths are testable without a key. */
ocr?: OcrProvider | null;
storage?: StorageDriver;
channels?: Channels;
/** Freezes the clock, so seeded dates and dashboard figures are deterministic. */
now?: Date;
}
export interface Harness extends AppHandle {
deps: AppDeps;
env: Env;
storage: StorageDriver;
channels: Channels;
/** The clock the harness was built with, frozen when one was supplied. */
now: () => Date;
/** Drains the job queue. Tests call this instead of waiting on the interval. */
runJobs: () => Promise<number>;
poller: Poller;
@@ -48,7 +55,10 @@ export async function createHarness(options: HarnessOptions = {}): Promise<Harne
await migrateToLatest(handle, env);
const auth = createAuth({ db: handle.db, dialect: handle.dialect, env, sendOtp: async () => undefined });
await seed(handle, auth);
await seed(handle, auth, options.now ? { now: options.now } : {});
const channels = options.channels ?? createChannels(env);
const now = options.now ? () => options.now as Date : () => new Date();
const storage =
options.storage ??
@@ -62,9 +72,12 @@ export async function createHarness(options: HarnessOptions = {}): Promise<Harne
const poller = createPoller({
db: handle.db,
dialect: handle.dialect,
handlers: createHandlers({ db: handle.db, storage, ocr }),
handlers: createHandlers({ db: handle.db, storage, ocr, channels, now }),
intervalMs: env.JOBS_POLL_INTERVAL_MS,
staleMinutes: env.JOBS_STALE_MINUTES,
// Tests queue exactly the work they mean to exercise.
scheduleSweeps: false,
now,
});
return {
@@ -72,6 +85,8 @@ export async function createHarness(options: HarnessOptions = {}): Promise<Harne
deps,
env,
storage,
channels,
now,
poller,
runJobs: () => poller.runOnce(),
close: async () => {