Part II — Intermediate Development · Chapter 8 · Lesson 6 of 6 · 5 min read
Chapter 8 Checkpoint: Permission-Aware Data Utility
Checkpoint level: Intermediate
Purpose: Integrate the Chapter 8 standard-library skills into one small utility that reads synthetic order data, summarizes it, and writes a report, while requesting only the permissions it needs and failing predictably when they are denied.
Checkpoint outcomes
- Apply stable std conventions and verify names against the installed release.
- Use collections, strings, mathematics, and date-time operations in a pure core.
- Parse CSV input and emit JSON output with explicit validation.
- Use files and paths through narrow read and write adapters.
- Emit structured, redacted log events with stable reason codes.
- Derive a least-privilege permission set and test allow and deny paths.
8C.1 Project scenario: Daily order summary utility
An operations team needs a utility that reads one synthetic CSV file of orders for a single day, validates each row, groups totals by region, and writes a JSON summary and a short log. The utility must run with file read access to one input location and file write access to one output location, and nothing else. It must not use the network or start processes.
8C.2 Input and output contracts
| Item | Contract |
|---|---|
| Input CSV | Header order_id,region,amount,order_date; synthetic data only |
| Valid row | Non-empty id, known region, non-negative amount, ISO date within the run date |
| Output JSON | Run date, row counts, totals by region, rejected-row count, and reason-code counts |
| Log events | Operation, resource class, outcome, and reason code; no row contents |
8C.3 Requirements
- Keep parsing, validation, grouping, and formatting in a pure core with no capability.
- Provide one read adapter and one write adapter, each returning a result value with a stable reason code.
- Reject invalid rows without stopping the run, and count rejections by reason.
- Produce deterministic output: sorted regions, fixed number formatting, and a supplied run date rather than the current time.
- Write the report only after the whole summary is computed.
- Record a permission manifest listing each capability and its justification.
8C.4 Constraints
- Use only synthetic data; never include real customer information.
- No network, process, or cryptographic capability is requested.
- No log line may contain row contents or full file paths.
- Do not widen permissions or fall back to another location after a denial.
- Verify every std function name against the installed release before use.
8C.5 Acceptance criteria
- The summary for the reference input matches the expected totals exactly.
- Each invalid row category yields its own reason code and count.
- A denied read stops the run with permission_denied and writes no output.
- A denied write reports permission_denied and leaves no partial report.
- Two runs with the same input produce byte-identical output.
- The permission manifest matches the adapters exactly.
8C.6 Reference design
Attempt the project independently before comparing it with this design. Function names are illustrative.
| Component | Responsibility | Capability |
|---|---|---|
| read_orders(path) | Read the CSV text and return a Result | File read, one location |
| parse_rows(text) | Split and convert rows into maps | None |
| validate_row(row, run_date) | Return a reason code or ok | None |
| summarize(rows) | Group totals by region, count rejections | None |
| render_json(summary) | Produce deterministic JSON text | None |
| write_report(path, text) | Write the report as a single operation | File write, one location |
| log_event(event) | Emit a redacted structured event | Logging |
The main routine reads, parses, validates, summarizes, renders, and writes in that order. Only the first and last steps touch a capability, so any denial is raised at a known point and translated into a reason code.
8C.7 Reason codes
| Code | Meaning |
|---|---|
| ok | Row accepted |
| missing_id | Order identifier is empty |
| unknown_region | Region is not in the allowed list |
| bad_amount | Amount is not numeric or is negative |
| bad_date | Date is malformed or after the run date |
| permission_denied | Adapter operation was refused |
| io_failure | Resource missing or unreadable |
8C.8 Required test matrix
| Case | Scenario | Expected outcome |
|---|---|---|
| A | All rows valid | Totals match; zero rejections |
| B | One row per invalid category | Each reason code counted once |
| C | Empty file with header only | Zero totals; successful empty report |
| D | Amount exactly 0 | Accepted |
| E | Date equal to the run date | Accepted |
| F | Read capability denied | permission_denied; no output written |
| G | Write capability denied | permission_denied; no partial report |
| H | Missing input file | io_failure; distinct from denial |
| I | Same input run twice | Byte-identical reports |
Cases D and E test exact boundaries. Cases F, G, and H confirm that denial, write failure, and missing resources remain distinguishable.
8C.9 Validation workflow
- Prepare a small synthetic CSV and predict the full summary by hand.
- Run pea fmt --check and pea check on the source.
- Run the utility with both capabilities granted and compare output with the prediction.
- Run with only read, then only write, and confirm the denial behavior.
- Inspect the log for redaction and reason codes.
- Compare the permission manifest with the adapters.
8C.10 Debugging requirement
Introduce one temporary defect, such as placing a file read inside the validation step. Confirm that the pure-core tests or the permission review expose it, then restore the design and retest.
8C.11 Submission package
- Source files for the core, adapters, and main routine.
- The synthetic input and expected output.
- The test matrix with predicted and actual results.
- The permission manifest with a justification for each entry.
- A sample redacted log.
- A note describing the temporary defect and its correction.
8C.12 Assessment rubric
| Area | Evidence of mastery |
|---|---|
| Correctness | Totals, counts, and reason codes match predictions |
| Pure core | Parsing, validation, and summarizing use no capability |
| Permissions | Manifest is minimal and matches the adapters |
| Denial handling | Denied, failed, and missing cases are distinct and fail closed |
| Determinism | Repeated runs give identical output |
| Safety | Logs and output contain no sensitive data |
| Std usage | Function names verified against the installed release |
| Explanation | Learner can justify each capability and each reason code |
Completion standard: Every test case passes, the permission manifest is minimal, and the learner can explain why each capability is requested.
8C.13 Reflection questions
- Which step of the utility needed no capability, and why?
- How did separating denial from missing resources change your error handling?
- What would you remove from the manifest if the report were printed instead of written?
- Which std facilities did you check against the release documentation?
- How would you detect permission drift in a later version?
8C.14 Optional extensions
- Add a second region-level report in CSV form using the same write adapter.
- Add a deterministic test double for both adapters and run the core tests without any capability.
- Add a size limit on the input and a reason code for oversized files.
Chapter 8 summary
You can now rely on the stable std namespace and its compatibility conventions, work with collections, strings, mathematics, and date-time values, exchange JSON and CSV data, use regular expressions with care, and reach files, paths, HTTP, cryptography, logging, testing, and concurrency through capability-aware adapters. The checkpoint combined these into a permission-aware utility with a minimal manifest and predictable denial behavior.
Transition to Chapter 9
Chapter 9 turns from individual programs to project structure. The next lesson covers module boundaries, imports, exports, and initialization, showing how to divide the code you have written into modules with clear responsibilities.
Checkpoint status: Ready for review.