# Teaching example: intake summary crash

Status: self-built practice project, not client work.

## Reproduction

The original `before/brief.mjs` assumes every field exists and calls `.trim()` directly. A valid request containing only the required goal throws `TypeError: Cannot read properties of undefined` when it reaches the optional stack field.

## Change

The fixed `after/brief.mjs`:

- normalizes missing and repeated whitespace consistently;
- keeps the primary goal required;
- gives optional fields an explicit `To confirm` value;
- bounds each input before producing the summary.

## Verification

Run from `paid-services/site/`:

```powershell
npm test
```

The suite preserves the previous failure as a regression reproduction and verifies four fixed behaviors: optional fields, required-goal validation, whitespace normalization, and input limits.

## Teaching sequence

1. Run the smallest failing input.
2. Read the stack trace and identify the first unsafe assumption.
3. Mark required and optional inputs before editing code.
4. Apply one normalization path.
5. Re-run tests and explain why the error no longer occurs.

## Evidence-based project wording

> Built input normalization and boundary tests for a local project-brief module, reproducing and fixing a runtime error caused by omitted optional fields.

This wording describes this teaching example only. It must not be presented as paid client work.

