Skip to content

Lab 04: Build in slices

Objectives

Generate the separate practice app in small vertical slices. Prove actual SQLite save/load/restart, revision-safe review/edit, original export, and deletion without replacing persistence with mocks.

Prerequisites and stop gate

Complete contracts. Read learner PRD, source ledger, API/data/UX contracts, and toolchain evidence.

[!WARNING] Excluded npm resources remain excluded. Do not retry or reconstruct them locally, elsewhere, or through hosted Actions. The current application uses the separately reviewed Python stack, not an alternate proxy for npm content.

The Python 3.13.14/SQLite 3.50.4 implementation and original HTML/CSS/JavaScript UI/proxy now exist. A fresh Windows x64 corporate-index hash-locked install, 18 backend tests and 10 separate proxy tests passed. Read LearnerRoot's README.md, adr-002-python-stack.md and python-dependency-review.md. ReportLab 5.1.0, pypdf 7.1.1, Pillow 13.0.0 and charset-normalizer 3.5.2 are selected; ODS guidance informs original CSS without official assets. Browser/manual acceptance and release are pending. Live source acceptance remains pending, so review/export return SOURCE_REVIEW_REQUIRED.

Bounded prompt

Use the following prompt for the first slice. For each later slice, replace the named slice and its allowed paths with the corresponding scope below; do not ask for all remaining work in one run.

Work only in C:\src\GitHub\devopsabcs-engineering\ontario-form-practice.
Read specs/source-traceability.md, docs/product/prd.md, the API/data/overview
contracts and docs/design/ontario-form-lab-experience.md. Confirm approved
dependency access and actual notice review first; stop if unresolved.
Inspect the already implemented slice 1 before editing: incomplete create/load
with real Python stdlib SQLite and semantic HTML/vanilla-JavaScript entry/save/resume.
Allowed paths: requirements.in/requirements.txt, web/, api/, tests/, and
sanitized evidence/qa/. Preserve historical Node probe records without using them
as app gates. Write failing tests before changing behavior where a defect exists.
Use Python compileall/unittest and module startup, not invented npm scripts.
Use the exact nine data keys, defaults, source snapshot, transport bounds,
loopback proxy and schema migration contracts. No browser draft persistence,
list endpoint, extra private fields, public hosting, auth or government calls.
Show saved only after commit. Run scoped checks and report exact changed
paths, commands, exits and unexecuted checks. Stop after slice 1; do not
approve source/release, invent screenshots, or implement later slices.

Steps

Step 1: Establish the application commands

Use Lab 00 for approved Python setup; reuse the existing application .venv. Inspect requirements.in and its hash-locked requirements.txt; preserve the native probe as historical evidence only. The current commands are python -m api.server, python -m web.dev_server, compileall and named unittest modules using that .venv interpreter. There is no React bundle, TypeScript typecheck, or npm build/dev/test requirement. Record versions/notices and actual assertions, not empty passing tests.

Step 2: Build incomplete create and load

Allowed paths are the first prompt's scope. Implement migration 001, strict validation, source registry, parameterized SQL, and semantic HTML/JavaScript start/form/resume in web\index.html, app.js and styles.css. POST {"data":{}} creates revision 1 with supported defaults; GET returns the same persisted object. Do not require name/identifiers/confirmation on Save. Reject malformed present values and unsupported scope with explicit errors.

UI starts in memory and creates only on Save. Show the local UUID locator after acknowledgment, not full values in the URL. Save/load failures preserve input and never display a blank "saved" record. Check syntax and test before the next slice.

Step 3: Add guarded replacement and restart

Limit changes to web/, api/, tests/test_api.py, tests/test_persistence.py, and sanitized QA evidence. PUT sends all nine data keys plus the last acknowledged revision. Any successful save increments and clears review, including an unchanged save.

Start two clients from one revision. The first save succeeds; the stale client gets 409 and retains input without automatically overwriting. Save synthetic values to a distinct ignored disk DB, stop the exact API process, restart with the same DB path, and reload by locator. A scratch-driver result is not this application restart test.

Step 4: Add review and edit

Keep scope to web/API review behavior and its tests. Review dirty content only after guarded save succeeds; send only expectedRevision. Validate the persisted row, accepted source, name, true confirmation, and plate OR VIN. Test missing/both-absent, plate-only, VIN-only, and both-present cases.

Review increments revision and sets reviewedRevision equal to it. Show "Reviewed locally", not approved/submitted/certified. Edit mode alone does not mutate. Saved edits clear review; stale review fails with 409. Source pending blocks review/export but leaves recovery load/save/delete usable.

Step 5: Add original summary

Limit changes to export code, download UI, tests/test_pdf.py, scoped API tests, and reviewed Python dependency entries. Acquire no excluded generator/parser. Use the selected ReportLab generator and pypdf test parser. With accepted source, generate original buffered PDF from an immutable copy of the current persisted reviewed snapshot. Recheck existence/revisions/source before sending; do not hold a write lock during generation.

Keep the exact training disclaimer and provenance/values specified in Lab 03. Enforce 1-4 Letter pages and 1 MiB maximum, long-name wrapping, and no server PDF retention. Check status and MIME before download; JSON errors must not become .pdf files. Keep HTML review. Use a separately selected parser and human visual inspection, not the generator's own success message.

Step 6: Add confirmed deletion and truthful failure states

Limit changes to delete UI/API and its tests. Cancel preserves the record and restores focus. DELETE uses expectedRevision; only committed 204 clears UI. Stale deletion is 409; missing/already deleted is 404. All subsequent record endpoints return 404. Storage failures roll back and never announce success. Explain that downloads/backups/SQLite pages are not securely erased.

Validation

Run these with the approved existing application environment:

Set-Location C:\src\GitHub\devopsabcs-engineering\ontario-form-practice
.\.venv\Scripts\python.exe -m pip check
if ($LASTEXITCODE -ne 0) { throw 'Application dependencies failed' }
.\.venv\Scripts\python.exe -m compileall -q api web tests
if ($LASTEXITCODE -ne 0) { throw 'Python syntax check failed' }
.\.venv\Scripts\python.exe -m unittest tests.test_validation tests.test_api tests.test_persistence tests.test_source tests.test_pdf web.test_dev_server -v
if ($LASTEXITCODE -ne 0) { throw 'Application assertions failed' }

An optional node --check web\app.js uses only an already installed Node; do not install npm tooling for it. Syntax and proxy tests do not prove a browser journey. Start the API from LearnerRoot in one terminal:

.\.venv\Scripts\python.exe -m api.server

In another LearnerRoot terminal:

.\.venv\Scripts\python.exe -m web.dev_server

Open http://127.0.0.1:5173. The Python proxy forwards /api to fixed loopback 127.0.0.1:3001, preserving Origin and rewriting Host. Run this PowerShell 7 create/load probe. It leaves a synthetic draft for the following steps; keep the ID in private evidence.

Set-Location C:\src\GitHub\devopsabcs-engineering\ontario-form-practice
$base = 'http://127.0.0.1:3001'
$created = Invoke-WebRequest -Method Post -Uri "$base/api/drafts" -ContentType 'application/json' -Body '{"data":{}}'
if ($created.StatusCode -ne 201) { throw 'Expected create 201' }
$draft = ($created.Content | ConvertFrom-Json).draft
if ($draft.revision -ne 1 -or $null -ne $draft.reviewedRevision) { throw 'Incorrect initial revision' }
$loaded = Invoke-RestMethod -Uri "$base/api/drafts/$($draft.id)"
if ($loaded.draft.id -ne $draft.id -or $loaded.draft.revision -ne 1) { throw 'Persisted load mismatch' }

Now fill synthetic values in the live UI, save, copy the locator, and record the acknowledged revision. Stop the API with Ctrl+C in its own terminal, or use Stop-Process -Id only with its verified exact PID. Restart with .\.venv\Scripts\python.exe -m api.server and the same DB path, load the locator, and compare values/revision. Do not infer a restart from a browser refresh. Close helper processes by specific PID after testing.

Expected observable results

After the prerequisites and slices actually run, every UI action reaches the real API and disk DB. Incomplete save/load survives an API restart; stale mutations do not overwrite; saved edits invalidate review; summary contains the requested reviewed values; deletion removes the live record. These are browser acceptance targets, not a completed browser run. The 18 backend tests prove their named HTTP/restart/PDF/recovery/source/unit cases and the 10 proxy tests prove their named proxy cases. Live review/export remain source-gated; never use test acceptance as human approval to complete a browser journey.

Observed synthetic review excerpt

Actual English-only practice UI excerpt showing Reviewed locally, a historical draft ID, revision 6 and reviewed revision 6, with neutral individual-owner, passenger-vehicle, vehiclePermit and LOST labels before deletion.

Caption: real cropped viewport excerpt, not a full page or PDF screenshot. The English-only app used an isolated synthetic accepted fixture, not human source approval. Revision 6 was observed before deletion; its historical draft ID no longer resumes. The original 1280 by 960 image was cropped only to remove the blank upper 298 pixels, leaving 1280 by 662. This is not human French, accessibility, PDF visual or release approval.

The parent observed create/reload, validation and linked-error focus, normalization, review, a 409 conflict with retained input and explicit reconciliation, edit/re-review, user-confirmed saved r3/r6 PDFs independently parsed with pypdf, and deletion followed by 404 responses. These are limited browser-tool observations, not a full automated browser suite in the repository. The DELETE observer reported an abort around history replacement, not a captured 204. See LearnerRoot evidence/qa/browser-results.md and evidence/accessibility/browser-checks.md for limits. Live source approval, human French/release review, full keyboard/screen-reader/touch/form-reflow/zoom and human PDF visual checks remain pending.

Troubleshooting

For missing modules, inspect the application README and environment rather than inventing npm scripts or returning zero. For failed migration, preserve the DB and diagnose version/config; do not delete it to hide an error. For 409, keep input and explicitly reload. For unknown first-create outcome, do not auto-retry; later synthetic teardown can remove an unlocated row. See troubleshooting.

Costs

Build/AI usage is unmeasured. Record each slice's actual usage and elapsed time. No production-cloud resources or predicted credits are included.

Knowledge checks

  • Which observation proves process-restart persistence rather than refresh?
  • Why does the API accept incomplete but not malformed drafts?
  • Why is a parser independent of the PDF generator needed?

Previous: Contracts. Next: QA, critic and security.