# Blueprint Analysis: drydock Layers Testing Uat Case

## Commander Expectations

- assert the completed ledger is a command-line cash ledger that stores all data in SQLite through the shipped persistence library
- assert every command either completes in full or changes nothing
- assert the supplied grader `sources/run.sh` passes with exit code zero
- assert every report is computed from the database and never embedded as an answer
- assert a rejected command leaves all previously stored records unchanged

## Crew

| Crew | Charge |
|---|---|
| Commander | Defines intent and decides what done means. |
| Team Lead | Confirms epic completeness and stakeholder expectations. |
| Planning Crew | Authors atomic specifications and the ordered Manifest. |
| Shipyard Crew | Builds the tickets without synchronous Commander access. |

## Story List

### Feature: Schema and Bulk Load

| ID | Story | High-level AC |
|---|---|---|
| LEDGER-SCHEMA-001 | Initialize an empty ledger with `ledger init` | `init` prepares three tables (accounts, categories, transactions) with the specified columns and keys, writes nothing, and removes existing records when rerun; `count` reports 0 rows for each table |
| LEDGER-LOAD-001 | Load accounts from CSV with `ledger load accounts <csv>` | Header must match `account,name`; all rows accepted; writes `table,loaded` and `accounts,<rows>`; invalid row rejects the whole file with exit 3 |
| LEDGER-LOAD-002 | Load categories from CSV with `ledger load categories <csv>` | Header must match `category,description`; all rows accepted; writes `table,loaded` and `categories,<rows>`; invalid row rejects the whole file with exit 3 |
| LEDGER-LOAD-003 | Load transactions from CSV with `ledger load transactions <csv>` | Header must match `txn_id,date,account,category,amount,memo`; keeps file `txn_id`; all rows accepted or none; unknown account or category rejects the whole file with exit 3 |
| LEDGER-LOAD-004 | Reject a load file with unreadable path | Unreadable file named on command line exits 1 with no writes |

### Feature: Account Management

| ID | Story | High-level AC |
|---|---|---|
| LEDGER-ACCT-001 | Add an account with `ledger account add <code> <name>` | Validates code (1–12 chars `A-Z0-9`) and name (1–40 chars, no comma/newline); duplicate key rejected with exit 3; returns account row with 0 transactions and 0.00 balance |
| LEDGER-ACCT-002 | Retrieve an account with `ledger account get <code>` | Returns current account row; absent code exits 4 |
| LEDGER-ACCT-003 | Rename an account with `ledger account rename <code> <name>` | Updates name only; returns updated row; absent code exits 4 |
| LEDGER-ACCT-004 | Delete an account with `ledger account delete <code>` | Removes account and writes `deleted` and code; refused with exit 3 while transactions exist; absent code exits 4 |

### Feature: Transaction Management

| ID | Story | High-level AC |
|---|---|---|
| LEDGER-TXN-001 | Post a transaction with `ledger txn post` | Validates account, category (must exist), amount (`-?DIGITS[.D[D]]`, nonzero, ≤2 decimals), date (real calendar date), memo (0–60 chars); assigns `txn_id` as max+1 or 1; returns row; invalid input exits 3 |
| LEDGER-TXN-002 | Retrieve a transaction with `ledger txn get <id>` | Returns current transaction row; absent id exits 4 |
| LEDGER-TXN-003 | Amend a transaction amount with `ledger txn amend <id> <amount>` | Changes only amount; returns updated row; rejected if resulting balance would go negative; absent id exits 4 |
| LEDGER-TXN-004 | Delete a transaction with `ledger txn delete <id>` | Removes row and writes `deleted` and id; rejected if resulting balance would go negative; absent id exits 4 |

### Feature: Transfers

| ID | Story | High-level AC |
|---|---|---|
| LEDGER-XFER-001 | Transfer cash between accounts with `ledger transfer <from> <to> <amount> <date>` | Records two rows in category `TRANSFER` (outgoing `-amount` then incoming `+amount`) with specified memos and consecutive ids; accounts must differ and amount must be positive; rejected entirely if source would go negative |

### Feature: Reporting

| ID | Story | High-level AC |
|---|---|---|
| LEDGER-RPT-001 | Report account balances with `ledger report balances` | Per-account rows ordered by code with count and balance, then `TOTAL,,<count>,<sum>` |
| LEDGER-RPT-002 | Report category totals with `ledger report categories` | Per-category rows ordered by code (including empty categories) with inflow, outflow, net, then TOTAL row |
| LEDGER-RPT-003 | Report monthly totals with `ledger report monthly` | Per `YYYY-MM` with transactions, ascending, with inflow, outflow, net, then TOTAL row |

### Feature: Command Contract

| ID | Story | High-level AC |
|---|---|---|
| LEDGER-CLI-001 | Enforce the CSV output contract and exit codes | Successful commands write CSV headers, `\n` endings, two-decimal amounts, no trailing spaces; failures write nothing to stdout and one diagnostic to stderr; exit 2 for unknown commands, tables, reports, or wrong argument counts |
| LEDGER-CLI-002 | Enforce the no-negative-balance rule across all writing commands | Loading, posting, amending, deleting, and transferring each check every resulting balance before any write and reject the whole command with exit 3 |

## Story Guidance

Named stories planning must produce. Authoritative record: `STORY_GUIDANCE.json`.

None.

## Surfaced Acceptance Criteria

| ID | Story ID | Criterion |
|---|---|---|
| AC-001 | LEDGER-SCHEMA-001 | `init` writes nothing to standard output and exits 0 |
| AC-002 | LEDGER-LOAD-001 | A rejected accounts load stores none of the rows before the rejected row |
| AC-003 | LEDGER-LOAD-003 | A rejected transactions load stores none of the rows before the rejected row |
| AC-004 | LEDGER-ACCT-001 | Account code validation rejects lowercase letters, codes longer than 12 characters, and empty codes with exit 3 |
| AC-005 | LEDGER-TXN-001 | Amount input with three decimal places is rejected with exit 3 |
| AC-006 | LEDGER-TXN-001 | Date `2026-02-30` is rejected with exit 3 |
| AC-007 | LEDGER-TXN-003 | Amending a transaction to an amount that would drive its account below zero exits 3 and leaves the original amount |
| AC-008 | LEDGER-TXN-004 | Deleting a transaction that would drive its account below zero exits 3 and keeps the row |
| AC-009 | LEDGER-XFER-001 | A transfer whose source would go negative stores neither of its two rows |
| AC-010 | LEDGER-XFER-001 | A transfer with equal source and destination accounts exits 3 |
| AC-011 | LEDGER-RPT-002 | Categories with no transactions appear in the report with zero values |

## Source Inventory

| Path | Content kind | Disposition | Reason |
|---|---|---|---|
| `sources/INSTRUCTIONS.md` | markdown | analyzed | readable UTF-8 |
| `sources/run.sh` | code | analyzed | readable UTF-8 |
| `sources/seed_accounts.csv` | text | analyzed | readable UTF-8 |
| `sources/seed_categories.csv` | text | analyzed | readable UTF-8 |
| `sources/seed_transactions.csv` | text | analyzed | readable UTF-8 |
| `sources/seed_transactions_bad.csv` | text | analyzed | readable UTF-8 |

## Relationship Model

| Source or group | Relationship type | Related source or group | Evidence | Delivery implication |
|---|---|---|---|---|
| `sources/run.sh` | instruction-to-test | `sources/INSTRUCTIONS.md` | Grader known answers mirror the CLI contract and rules in INSTRUCTIONS.md | Grader is the final acceptance gate; stories must reproduce its outputs exactly |
| `sources/seed_accounts.csv` | dependency | `sources/run.sh` (B1, D2, C1) | Grader loads these rows and asserts their counts and balances | Account load story must precede balance report stories |
| `sources/seed_categories.csv` | dependency | `sources/run.sh` (B2, C2) | Grader loads these rows and asserts category totals | Category load story must precede category report story |
| `sources/seed_transactions.csv` | dependency | `sources/run.sh` (B3, C1–C3) | Grader loads 120 rows and asserts all report totals | Transaction load story must precede all report stories |
| `sources/seed_transactions_bad.csv` | instruction-to-test | `sources/run.sh` (D1) | Row 11 names unknown account `NOSUCH`; grader expects exit 3 with no writes | Load validation must be atomic |
| `sources/INSTRUCTIONS.md` | dependency | `sources/run.sh` | Output formats and exit codes are fixed by INSTRUCTIONS.md | Output and exit-code stories derive from this file |

## Source Roles

| Path | Role | Plan disposition | Build disposition |
|---|---|---|---|
| sources/INSTRUCTIONS.md | normative specification | context | prompt-only |
| sources/run.sh | conformance harness | compass | stage |
| sources/seed_accounts.csv | test helper | context | stage |
| sources/seed_categories.csv | test helper | context | stage |
| sources/seed_transactions.csv | test helper | context | stage |
| sources/seed_transactions_bad.csv | test helper | context | stage |

## Planning Instructions

### Delivery Shape

The system is a Python 3.11+ command-line executable named `ledger` at the application root. Inputs are command-line arguments and CSV files named on the command line. Outputs are CSV on standard output and diagnostics on standard error. All persistence goes through the shipped persistence library over SQLite, with `DATABASE_URL` or `DATABASE_PATH` selecting the database file. Each writing command validates all inputs and rules before its first write, so it either completes fully or changes nothing.

### Story Realization Map

- LEDGER-SCHEMA-001: `sources/INSTRUCTIONS.md` Commands table (`init`, `count`); `sources/run.sh` A1–A2, Z1–Z2. Requires persistence library schema setup and a `count` command.
- LEDGER-LOAD-001: `sources/INSTRUCTIONS.md` Database and Commands (`load accounts`); `sources/seed_accounts.csv`; `sources/run.sh` B1, D2. Requires the accounts table and atomic load.
- LEDGER-LOAD-002: `sources/seed_categories.csv`; `sources/run.sh` B2. Requires the categories table and atomic load.
- LEDGER-LOAD-003: `sources/seed_transactions.csv`, `sources/seed_transactions_bad.csv`; `sources/run.sh` B3, D1. Requires foreign-key validation before any write.
- LEDGER-LOAD-004: `sources/INSTRUCTIONS.md` Exit codes (1); `sources/run.sh` (no direct check; covered by the exit-code contract).
- LEDGER-ACCT-001 through LEDGER-ACCT-004: `sources/INSTRUCTIONS.md` account commands and rules 3–4; `sources/run.sh` E1–E8.
- LEDGER-TXN-001 through LEDGER-TXN-004: `sources/INSTRUCTIONS.md` transaction commands and rules 5–7; `sources/run.sh` F1–F10, G3–G5.
- LEDGER-XFER-001: `sources/INSTRUCTIONS.md` transfer command and rule 1; `sources/run.sh` G1–G2.
- LEDGER-RPT-001 through LEDGER-RPT-003: `sources/INSTRUCTIONS.md` report commands; `sources/run.sh` C1–C3, H1–H3.
- LEDGER-CLI-001: `sources/INSTRUCTIONS.md` Output and Exit codes; `sources/run.sh` U1–U2.
- LEDGER-CLI-002: `sources/INSTRUCTIONS.md` Rule 2; `sources/run.sh` G3–G5.

### Test and Acceptance Strategy

Focused story tests run the story's own slice of the Python test suite in `bin/test.sh`, scoped per story. The terminal verification story runs the grader `sh sources/run.sh` and the unfiltered suite. Sea Trials are verified by the SEA_TRIALS.md criteria, and the grader is the authoritative proof for report and workflow correctness.

### Sequencing and Dependencies

1. LEDGER-SCHEMA-001 (init and count) first.
2. LEDGER-LOAD-001, LEDGER-LOAD-002 in parallel after LEDGER-SCHEMA-001.
3. LEDGER-LOAD-003 after LEDGER-LOAD-001 and LEDGER-LOAD-002.
4. Account, transaction, and transfer stories after the loads.
5. Report stories after all write stories are in place.
6. LEDGER-CLI-001 and LEDGER-CLI-002 cross-cut and are verified during each story they touch.
7. Terminal verification story runs the full grader after all others.

### Source Conflicts and Gaps

- Source conflict: none. INSTRUCTIONS.md and run.sh agree on every output format, exit code, and rule checked by the grader.
- Gap: INSTRUCTIONS.md does not state the exit code for a missing or invalid `DATABASE_URL` value. Resolved by choosing the narrowest behavior: exit 1 as an operational failure, with no writes.
- Gap: The behavior when `ledger init` is run with no prior database file is not stated. Resolved by creating the file and schema.

## Analysis Notes
generated: 2026-10-27
blueprint: /mnt/c/Users/barlo/projects/drydock/uat/LayersTesting/runs/20261027.135355/workspace/targets/LayersTesting/blueprint

Quality: Ready
  blockers: 0
  questions: 0
  features: 6
  stories: 15
  stack: Python 3.11+, SQLite, pytest
  display_name: not proposed
  short_description: not proposed

Observations:
- SEA_TRIALS.md is a prior project acceptance contract; its stable IDs st-001, st-004 through st-008, st-010, and st-011 are preserved. st-002, st-003, and st-009 are retired and not re-emitted.
- The grader `sources/run.sh` is the single authoritative project-level verification command.
- `count` appears in the Commands table and the grader but is not listed in the Story List's original commands; it is folded into LEDGER-SCHEMA-001.
- `init` requires no separate schema-building story; the persistence library generates the schema.
