PeaBox Lab › PeaLang › Learn › Chapter 8 › Lesson 6

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

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

ItemContract
Input CSVHeader order_id,region,amount,order_date; synthetic data only
Valid rowNon-empty id, known region, non-negative amount, ISO date within the run date
Output JSONRun date, row counts, totals by region, rejected-row count, and reason-code counts
Log eventsOperation, resource class, outcome, and reason code; no row contents

8C.3 Requirements

8C.4 Constraints

8C.5 Acceptance criteria

8C.6 Reference design

Attempt the project independently before comparing it with this design. Function names are illustrative.

ComponentResponsibilityCapability
read_orders(path)Read the CSV text and return a ResultFile read, one location
parse_rows(text)Split and convert rows into mapsNone
validate_row(row, run_date)Return a reason code or okNone
summarize(rows)Group totals by region, count rejectionsNone
render_json(summary)Produce deterministic JSON textNone
write_report(path, text)Write the report as a single operationFile write, one location
log_event(event)Emit a redacted structured eventLogging

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

CodeMeaning
okRow accepted
missing_idOrder identifier is empty
unknown_regionRegion is not in the allowed list
bad_amountAmount is not numeric or is negative
bad_dateDate is malformed or after the run date
permission_deniedAdapter operation was refused
io_failureResource missing or unreadable

8C.8 Required test matrix

CaseScenarioExpected outcome
AAll rows validTotals match; zero rejections
BOne row per invalid categoryEach reason code counted once
CEmpty file with header onlyZero totals; successful empty report
DAmount exactly 0Accepted
EDate equal to the run dateAccepted
FRead capability deniedpermission_denied; no output written
GWrite capability deniedpermission_denied; no partial report
HMissing input fileio_failure; distinct from denial
ISame input run twiceByte-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

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

8C.12 Assessment rubric

AreaEvidence of mastery
CorrectnessTotals, counts, and reason codes match predictions
Pure coreParsing, validation, and summarizing use no capability
PermissionsManifest is minimal and matches the adapters
Denial handlingDenied, failed, and missing cases are distinct and fail closed
DeterminismRepeated runs give identical output
SafetyLogs and output contain no sensitive data
Std usageFunction names verified against the installed release
ExplanationLearner 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

8C.14 Optional extensions

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.

← Previous Next →