Part I — Foundations · Chapter 1 · Lesson 5 of 5 · 6 min read
Chapter 1 Checkpoint: Build and Run a Small Command-Line Rules Program
Checkpoint level: Foundation
Purpose: Integrate Chapter 1 skills into one repeatable PeaLang workflow without introducing functions, loops, modules, or external capabilities.
Checkpoint outcomes
By completing this checkpoint, you will demonstrate that you can:
- translate a short business policy into explicit inputs, rules, calculations, and outputs;
- create a readable .pea source file;
- use let, const, arithmetic, comparisons, assignment, if/else, and interpolation;
- format, check, run, and debug a program;
- predict and record expected results;
- test boundary cases; and
- explain the program’s behavior and security posture.
Project scenario: Support-case priority and response target
A support team needs a small command-line rules program that recommends a priority and response target for a case. The first version uses values declared at the top of the source file rather than interactive input. This keeps the checkpoint focused on language execution and disciplined testing.
The policy is:
- A security-relevant case is critical with a 15-minute response target.
- Otherwise, service impact of 8 or more is high with a 60-minute target.
- Otherwise, 100 or more affected users is high with a 60-minute target.
- Otherwise, a gold-tier customer with impact of 5 or more is medium with a 240-minute target.
- All remaining cases are low with a 480-minute target.
1C.1 Required inputs
Declare these values at the beginning of case_priority.pea:
| Name | Meaning | Example |
|---|---|---|
| case_id | Readable case identifier | "CASE-1042" |
| customer_tier | Customer service tier | "gold" |
| service_impact | Impact score from 0 through 10 | 6 |
| affected_users | Number of affected users | 25 |
| security_relevant | Whether the case concerns security | false |
Use const for policy thresholds and response targets. Use let for scenario inputs and calculated outputs that you will change while testing.
1C.2 Required outputs
The program must print labeled lines for:
- case identifier;
- customer tier;
- service impact;
- affected-user count;
- security relevance;
- recommended priority;
- response target in minutes; and
- a short reason code.
Reason codes make the decision traceable. Use SECURITY, IMPACT, USER_COUNT, GOLD_IMPACT, or DEFAULT according to the rule that wins.
1C.3 Implementation constraints
- Use only constructs introduced in Chapter 1.
- Keep all values portable: strings, numbers, and booleans.
- Do not read files, call HTTP services, start processes, or use secrets.
- Do not enable process execution.
- Keep the policy constants separate from the scenario inputs.
- Use ordered if/else-if/else branches so that the first matching rule wins.
- Print a complete, labeled decision summary.
1C.4 Acceptance criteria
- The file is plain UTF-8 text and uses the .pea extension.
- pea fmt --check case_priority.pea succeeds after formatting.
- pea check case_priority.pea reports no error.
- pea run case_priority.pea completes successfully.
- Every test case produces the expected priority, response target, and reason code.
- The program does not request unnecessary capabilities.
- A reader can trace the selected rule from the output.
1C.5 Reference implementation
Attempt the project independently before comparing your work with this reference.
const critical_minutes = 15
const high_minutes = 60
const medium_minutes = 240
const low_minutes = 480
const high_impact_threshold = 8
const user_threshold = 100
const gold_impact_threshold = 5
let case_id = "CASE-1042"
let customer_tier = "gold"
let service_impact = 6
let affected_users = 25
let security_relevant = false
let priority = "low"
let response_minutes = low_minutes
let reason_code = "DEFAULT"
if security_relevant {
priority = "critical"
response_minutes = critical_minutes
reason_code = "SECURITY"
} else if service_impact >= high_impact_threshold {
priority = "high"
response_minutes = high_minutes
reason_code = "IMPACT"
} else if affected_users >= user_threshold {
priority = "high"
response_minutes = high_minutes
reason_code = "USER_COUNT"
} else if customer_tier == "gold" and service_impact >= gold_impact_threshold {
priority = "medium"
response_minutes = medium_minutes
reason_code = "GOLD_IMPACT"
} else {
priority = "low"
response_minutes = low_minutes
reason_code = "DEFAULT"
}
print "Case: {case_id}"
print "Customer tier: {customer_tier}"
print "Service impact: {service_impact}"
print "Affected users: {affected_users}"
print "Security relevant: {security_relevant}"
print "Priority: {priority}"
print "Response target: {response_minutes} minutes"
print "Reason: {reason_code}"
1C.6 Why the order matters
The chain stops at the first true condition. A security case may also have high impact and many affected users, but the security rule appears first and therefore wins. This is policy precedence expressed through control-flow order.
The program initializes outputs to the default decision before entering the rule chain. Every branch then sets priority, response target, and reason code together. Updating the three outputs as one decision prevents mismatched results such as high priority with a low-priority target.
The final else branch repeats the defaults for clarity. In a larger program, tests should protect this invariant: every path must produce a complete and internally consistent decision.
1C.7 Expected result for the reference inputs
The reference inputs describe a gold-tier customer, service impact 6, 25 affected users, and no security relevance. The first three rules are false. The gold-and-impact rule is true, so the expected decision is:
Case: CASE-1042
Customer tier: gold
Service impact: 6
Affected users: 25
Security relevant: false
Priority: medium
Response target: 240 minutes
Reason: GOLD_IMPACT
1C.8 Required test matrix
| Case | Tier | Impact | Users | Security | Expected decision |
|---|---|---|---|---|---|
| A | standard | 2 | 5 | false | low, 480, DEFAULT |
| B | gold | 5 | 20 | false | medium, 240, GOLD_IMPACT |
| C | standard | 8 | 10 | false | high, 60, IMPACT |
| D | standard | 4 | 100 | false | high, 60, USER_COUNT |
| E | gold | 9 | 150 | true | critical, 15, SECURITY |
| F | gold | 8 | 100 | false | high, 60, IMPACT |
Cases B, C, and D test exact thresholds. Cases E and F test precedence by making more than one condition true.
1C.9 Validation workflow
For each test case:
- change only the scenario inputs;
- predict the selected branch and complete output;
- run pea fmt case_priority.pea after source edits;
- run pea fmt --check case_priority.pea;
- run pea check case_priority.pea;
- run pea run case_priority.pea;
- compare actual and expected priority, minutes, and reason code; and
- record pass or fail with a short note.
If a test fails, trace conditions from top to bottom. Stop at the first true condition, then confirm that all three output variables receive their matching values.
1C.10 Debugging requirement
Introduce one temporary defect, such as changing an exact-threshold comparison from >= to >. Confirm that the corresponding boundary test fails. Restore the correct operator and rerun the test.
Optionally start a debug session with a breakpoint on the first conditional line. Record the state needed to explain why the selected branch runs. Remove the temporary defect before submission.
1C.11 Submission package
- case_priority.pea in canonical formatting;
- a test-results table covering cases A through F;
- captured version, format-check, source-check, and run results;
- a short rule-precedence explanation;
- a note describing the temporary defect and its correction; and
- a brief security statement confirming that no external capability or process permission was required.
1C.12 Assessment rubric
| Area | Evidence of mastery |
|---|---|
| Correctness | All policy branches and expected outputs are accurate. |
| Boundary testing | Exact thresholds and overlapping conditions are tested. |
| Readability | Names, ordering, formatting, labels, and constants make intent clear. |
| Workflow discipline | Formatting, checking, execution, and evidence are recorded separately. |
| Debugging | A deliberate defect is detected, explained, corrected, and retested. |
| Security | No unnecessary permission, secret, file, network, or process access is used. |
| Explanation | The learner can trace precedence and final state without guessing. |
Completion standard: Every test passes, every acceptance criterion is met, and the learner can explain why cases E and F select their documented rules.
1C.13 Reflection questions
- Which rule was easiest to translate into code, and why?
- Which test best demonstrated the importance of an exact boundary?
- How would changing branch order alter cases E or F?
- Which names made the program easier to trace?
- What information in the output helps an operator trust the recommendation?
- Which responsibilities would remain in a host application if this rule were embedded in a real service?
1C.14 Optional extensions
Complete these only after the required project passes:
- Add a platinum tier rule while preserving existing precedence.
- Add a separate boolean indicating whether executive notification is required.
- Print a warning when an input falls outside its documented range.
- Create an additional test where impact, user count, and gold-tier rules all match but security does not.
- Generate source documentation and review whether the declarations communicate enough intent.
Keep optional work within Chapter 1 constructs. Functions, loops, modules, and formal tests will be introduced later.
Chapter 1 summary
You now have a working mental model of PeaLang, a verified toolchain, a command-line development workflow, experience with a first program, and a complete rules checkpoint. You can create readable source, preserve secure defaults, validate it through distinct tooling stages, reason about ordered decisions, test boundaries, and explain results.
Transition to Chapter 2
Chapter 2 examines the language itself in greater precision. The next lesson covers source files, lexical structure, comments, identifiers, and literals. It will establish the vocabulary needed to describe how PeaLang reads source text before moving into variables, expressions, and evaluation.
Checkpoint status: Approved.