# Specification: Global Test Stabilization & Pattern Alignment

## 1. Problem Statement
The Jomblo codebase currently has 73 failing test files and 259 failing tests (as of 2026-03-07). These failures are primarily caused by:
1. **Architectural Drift:** Core patterns like `createServerAction` and `Repository Pattern` were introduced but not project-wide.
2. **Signature Mismatches:** Migration from positional arguments to object-based inputs (e.g., `{ id, data }`) broke existing action calls and mocks.
3. **Response Handling:** The shift to a Discriminated Union `ActionResponse` broke tests that directly access `.data` or `.error`.
4. **Mocking Issues:** Outdated mocks for `catalog.ts` and `auth-utils.ts` causing `Vitest` errors.

## 2. Goals
- **Green Suite:** 100% pass rate for `pnpm test`.
- **Architectural Alignment:** All actions (Orders, Customers, Sales, Settings) refactored to Repository Pattern.
- **100% Coverage:** Verify and enforce 100% test coverage for all refactored modules.
- **Isomorphic Logging:** Ensure all tests handle the new logging context correctly.

## 3. Scope
- **Affected Modules:** Orders, Customers, Sales, Settings, Fulfillment, Checkout.
- **Test Files:** Update all failing unit and integration tests.
- **Repositories:** Implement missing repository classes in `lib/db/repositories/`.

## 4. Technical Constraints
- Must use `createServerAction` wrapper.
- Must use `Repository Pattern` (No raw SQL in actions).
- Must use `ActionResponse` union logic.
- Must adhere to Google TypeScript Style Guide.

## 5. Verification Criteria
- `pnpm test` returns 0 failures.
- `pnpm run test:coverage` shows 100% coverage for refactored files.
- `pnpm run build` passes.
