Skip to the lesson
CivOps AI Academy · F11Supervisor Review and the Manager View
0%

Chapter 1 · Session 13

Plan both screens with the people who use them

The operator records. The supervisor decides whether the record stands. The manager acts on what the records add up to. Claude Code writes both screens out in plain words, with the matrix change they need; you check them with a supervisor and a manager before anything is built.

25 min2 stepsNo code yetAbout 3 hours hands-on in all

By the end of this chapter you can

  • Explain why a review is a new row with a reason, and never an edit or a delete.
  • Explain why separation of duties belongs in the database, not in a hidden button.
  • Have Claude Code plan the review queue, the manager view and the matrix change, and check them with the people who use them.

One record, three jobs

Session 12 made each first-piece result a row in inspections. Two people need it next. The supervisor on the shift decides, quickly, whether a lot's first piece stands, or goes back to the operator to adjust the die and measure again. The manager needs to see, without asking anyone, how the shift is starting its lots, and where results are waiting. Neither screen needs anyone to type the data again.

Three surfaces, one recordOperator, supervisor and manager surfaces each shaped for its job, all reading the same record under the same access rules. Operatorenters one checkphone or tablet, arm's lengthSupervisorreviews the differencephone, tablet or deskManageracts on the measurewall board or deskOne record, one set of access rules from the matrix,three screens shaped for three jobs
Three screens, one record. Each screen is shaped for its job; the records and the access rules underneath are the same.

Approve or return, never delete

A review is a decision, so it is kept like the hold decisions from Session 5: a new row in its own table, saying who decided, what, when and why, and never changed or deleted. Return means "adjust and measure again", not "throw away". The returned result stays exactly as recorded; the operator's new measurement is a new row that points at it and says why, the correction rule from Session 5. The history then tells the truth: the first piece was out, the die was adjusted, the second piece was good.

Review statesA lot's first-piece results are recorded, wait in the queue, and are approved or returned with a reason; a returned result is corrected with a new linked row and goes back to the queue. A lot's first piece through review. Every arrow writes a new row; nothing is changed or deleted.Recordedby the operatorWaitingoldest firstApprovedby a supervisorReturnedreason requiredCorrectednew row, linkedback to the queue
Review states. Every arrow writes a new row. A returned result is never edited; the correction is a new row linked to it.

Regulated manufacturers will recognise this. The US FDA's rule for electronic records asks for secure, computer-generated, time-stamped audit trails that do not hide earlier entries [1], and its data integrity guidance asks that records be attributable, legible, contemporaneous, original and accurate (ALCOA) [2]. Outside regulated work it is still the right design: a decision nobody can trace is a decision nobody owns.

Separation of duties, in the database

The person who recorded a result must not be the person who approves it. Security frameworks call this separation of duties [3]. Hiding the Approve button on your own entries is not enough: anyone can send the request without the button. Broken access control is first in OWASP's list of web risks for exactly this reason [4]. The rule goes in the matrix as a named rule, is generated into the database with the other access rules, and a test proves it.

Separation of dutiesThe operator who enters a record cannot review it; the rule is enforced by the database, which refuses a self-review. Operator 1187enters the checkSupervisor 2204reviews itDatabase rulereviewer ≠ author1187 reviews ownrefused by the serverEnforced where it cannotbe skipped: in the database,not only by hiding a button
Separation of duties. The database refuses a self-review, whatever the screen shows.

The manager view shows only what someone measured

The manager view is a short page of counts straight from the records: first pieces recorded this shift, results outside limits, lots waiting for review and how long the oldest has waited, lots returned, lots on hold. Every number says where it comes from, and a tap shows the rows behind it. Session 15 turns this into the plant's dashboard with written definitions; today the rule is simpler and stricter: no number on screen that nobody measured.

Step 1

Ask Claude Code to plan both screens and the matrix change

10 minutes

Why

The review queue needs a new decision table and new rights, and both come from the matrix, never from a hand-written policy. Asking for the plan and the matrix change in plain words first means the supervisor and the manager can correct them before a migration exists, and you see exactly which rights change before any are granted.

Do this

Terminal or PowerShell
cd ~/code/acme-platform && git switch main && git pull && claude
Paste into Claude Code
Read docs/INTENT.md, docs/SCHEMA-PLAN.md, docs/matrix.json, docs/naming-standard.md and docs/screens/operator-first-piece.md. Do not write any code and do not change docs/matrix.json yet.

On a new branch ui/review-plan, write two plain-English plans for someone who does not write code:

docs/screens/supervisor-review.md, the supervisor's review queue:
1. One card per lot whose first-piece results are waiting for a decision, oldest first, for the supervisor's own site, with how long each has waited.
2. Each card shows every result with the value, the part's limits from characteristics and the difference worked out by the database, in words for anything outside ("0.11 mm above the upper limit"), plus the last first piece on the same press.
3. Two decisions only: Approve, or Return to the operator with a reason (never empty). Nothing can be edited or deleted. A returned result is corrected by the operator as a new row that points at it and says why.
4. Who may decide: the roles docs/matrix.json allows, never anyone who recorded any of that lot's results.
5. If someone else decided on the lot after the card was opened, the decision is refused with "Already decided by <name> at <time>: reload".
6. What the operator sees when a lot is returned to them.

docs/screens/manager-view.md, the manager's view for this shift at the manager's site: each count, where it comes from (table and rows), what it shows when there are no rows ("No data") and when it cannot read ("Could not read"), and the time it was last read. No targets, ratios or numbers that are not counted from the records.

Then a section "Matrix change proposed" in supervisor-review.md: the new decision table first_piece_reviews, which roles may read it and which may add to it, the named rule "nobody reviews a lot whose results they recorded", the two new screens and which roles may open each. No role may update or delete anything.

End each plan with "Questions for the supervisor" or "Questions for the manager". Open a pull request titled "Review queue and manager view: plans" and show me the link.

You will see recreated screen

claude — acme-platform
⏺ Read(docs/matrix.json)
⎿ Read 118 lines
⏺ Read(docs/screens/operator-first-piece.md)
⎿ Read 64 lines
⏺ Write(docs/screens/supervisor-review.md)
+## Matrix change proposed
+first_piece_reviews (decision): supervisor add + read, own site;
+ operator, quality_lead, manager read, own site. Nobody updates or deletes.
+Rule: nobody reviews a lot whose results they recorded.
+Screens: /supervisor/review → supervisor; /manager → manager.
1
⏺ Write(docs/screens/manager-view.md)
+Waiting for review: lots with results and no decision since. From first_piece_reviews and inspections.
+ No rows → "None waiting". Could not read → "Could not read", never the last number.
2
⏺ Pull request #34 adds two plans and a proposed matrix change: one new decision table, read and add rights only, and two screens. Three questions need the supervisor's and the manager's answers.
Claude Code writes the two plans and the proposed matrix change as text. Nothing in the matrix changes yet.
  1. The rights change, in plain words, before it exists. Read it as carefully as a contract.
  2. Every count says where it comes from and what it shows when there is nothing to count.

Check it worked

The pull request has two new files. The proposed matrix change grants no update or delete right, names the separation rule, and lists the two screens with their roles. docs/matrix.json is unchanged.

If it goes wrong

The plan has targets, percentages or a trend chart

Say: Remove every number that is not a count of records. Targets and definitions come in Session 15, written down in docs/measures.md.

The plan gives the manager the right to approve, or the supervisor the right to edit a result

Say: Remove that right. The manager only reads. Nobody edits a result: a correction is a new row. Rights are decided by what an action does, not by who seems senior.

Claude Code changed docs/matrix.json

Say: Undo the change to docs/matrix.json. I asked for a proposal in the plan only. The matrix changes in Step 3, with its tests.

Step 2

Check the plans with a supervisor and a manager

15 minutes

Why

The supervisor knows what makes a review fast or slow at 06:00: which result they look at first, when they return a lot rather than ring the operator, how long a lot can wait before the press runs bad parts. The manager knows which counts change what they do. Each answer is a card, a rule or a count; finding it now costs a conversation, finding it after go-live costs a rebuild.

Do this

Read supervisor-review.md with a supervisor on the shift, and manager-view.md with the manager, on GitHub (Files changed tab). Ask:

  • Supervisor: Is this card everything you need to decide in under a minute? What reasons do you give when you send a part back? How long may a lot wait before you would stop the press?
  • Manager: Which of these counts would change what you do this shift? Which would you never look at? What is missing?
  • Both: Are the roles in the matrix change right? Should anyone else be able to read the decisions?
Paste into Claude Code, after replacing the <...> parts
The supervisor and the manager checked the plans in this pull request:
Supervisor: <paste their answers>
Manager: <paste their answers>
Changes to the matrix proposal: <paste any, or "none">

Update both plans and the matrix proposal to match, add "Checked with the supervisor on <date>" and "Checked with the manager on <date>" at the top of each, and push to the same pull request.

When both plans are right, owner two approves and the pull request merges.

You will see recreated screen

github.com/acme-ops/acme-platform/pull/34/files
ConversationCommitsFiles changed
docs/screens/supervisor-review.md
Checked with the supervisor on 2026-10-281
Return reasonsPick from: adjust die and re-measure; wrong part; measure again. Or type your own. Never empty.2
WaitingA lot waiting more than 30 minutes is shown first, in amber, with the minutes in words.
The supervisor's plan after the conversation: a sign-off line, and changes that came from the shift.
  1. Who checked it and when.
  2. A rule from the shift: quick reasons save typing in gloves, and the database still refuses an empty one.

Check it worked

Both plans are merged on main, each with its sign-off line, the matrix proposal agreed, and no open questions.

Fastest path

Do the supervisor at the start of a shift, beside the press, with a returned lot in mind; do the manager at their shift meeting. Two short conversations, no meeting to book.

If it goes wrong

The supervisor wants to fix a wrong value themselves

Explain the rule: the person who recorded it re-measures, and the correction is a new row with a reason. If they insist (for example a typing error they saw), write it under Not now and raise it with the quality lead: a supervisor correction is a new role right, decided in the matrix, never a quiet edit.

The manager asks for a percentage or a target

Write it under Not now with "Session 15, docs/measures.md". A percentage needs a written definition (what counts, which rows, which time) before it is shown.

Knowledge check

A supervisor returns a lot's first piece. What happens to the returned result?

Knowledge check

Where must the rule 'nobody reviews a lot whose results they recorded' be enforced?

References

  1. eCFR: 21 CFR Part 11, Electronic Records; Electronic Signatures (§ 11.10(e) audit trails). https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
  2. U.S. FDA: Data Integrity and Compliance With Drug CGMP, Questions and Answers. https://www.fda.gov/regulatory-information/search-fda-guidance-documents/data-integrity-and-compliance-drug-cgmp-questions-and-answers
  3. NIST SP 800-53 Rev. 5: Security and Privacy Controls (AC-5 Separation of Duties). https://csrc.nist.gov/pubs/sp/800/53/r5/upd1/final
  4. OWASP Top 10: A01 Broken Access Control. https://owasp.org/Top10/A01_2021-Broken_Access_Control/

Chapter 2 · Session 13

Build the review queue and check it as two people

One complete brief changes the matrix, regenerates the access rules, adds the decision table and builds the queue, with acceptance checks written first. Then you play operator and supervisor on the preview, try what must be refused, and merge so the deploy applies it.

45 min3 stepsOne pull request

By the end of this chapter you can

  • Give Claude Code one brief that goes from a matrix change to a working, tested review queue.
  • Walk a lot through record, return, correct and approve on the preview, as two people.
  • Prove that a self-review, a second decision and a delete are refused by the database.

From the matrix to the screen

A new right never starts as a policy someone types. It starts as a line in docs/matrix.json; the generator from Session 8 writes the policies from it into a new migration, with an allowed and a refused test for every cell; the route list from Session 9 opens the new screen for the roles the matrix names and keeps it shut for everyone else. The brief below asks for all of it in one pull request, so the right, its rule and its proof arrive together.

Anatomy of a review cardA review card for a lot's first piece shows each measure, the entered value, the limits and the difference; flange height is highlighted 0.11 mm above its limit, with approve, return and a reason required to return. First piece · Press 03 · part 7741 · lot L-0412Entered by operator 1187 · 06:42 · Shift B · 18 minutes waitingMeasureEnteredLimitsDifferenceHole position (mm)12.0411.90 – 12.10insideFlange height (mm)25.3124.80 – 25.20+0.11 above limitBurrnonenone allowedinsideLast first piece on this press: 25.06, inside limits, 2 days agoApproveReturnReason (to return)
Anatomy of a review card. The supervisor sees in seconds which result is out, by how much, and what the press did last time. The difference is worked out by the database, not typed.
What the brief asksWhyFrom what we hit
The screen says Approved only after the database confirms the new row, and re-reads itA button that claims success while nothing happened is worse than an errorOur "Send all" marked every message sent while none left the building
A test per role that the decision really changed the database, not only the responseIn Postgres a change can quietly do nothing when the role cannot read the row it changesA Publish button reported success and nothing changed
The reviewer is taken from the session by the databaseThe page can send anyone's nameEvery record on our platform once said it was made by the founder, whoever was signed in
A second decision on the same lot, after the card was opened, is refused with who and whenTwo supervisors at once must not both decide without knowingTwo saves at once lost one of them: the app said Created, the record was gone a minute later
Generated files are regenerated, never editedThe matrix is the one source of truthA check failed that named a list, not the mistake, and held a fix up
Step 3

One brief: the matrix change, the decision table and the queue

20 minutes

Why

Each of these parts is useless alone: a table with no rights cannot be written, rights with no screen cannot be used, a screen with no tests can quietly lose its rules in the next change. One complete brief, with acceptance checks first and the questions you would ask at review built into the report, gets them in one pull request and one reading, instead of five rounds.

Do this

Paste into Claude Code
Save everything between the two lines of dashes below as docs/briefs/13-supervisor-review.md on a new branch ui/supervisor-review, commit it, then carry it out.
----------
# Brief 13: the supervisor review queue

## Goal
A supervisor approves a lot's first piece, or returns it to the operator with a reason, in under a minute, and every decision is kept for good with who, when and why.

## Context (read first)
- docs/screens/supervisor-review.md (signed off), including its agreed matrix change; docs/screens/operator-first-piece.md.
- docs/matrix.json, scripts/gen-policies.mjs, lib/access/routes.ts, proxy.ts, supabase/migrations/, CLAUDE.md.
- This Next.js version differs from older guides. Before writing any page or proxy code, read the relevant guides in node_modules/next/dist/docs/.

## Acceptance checks (write these first, run them, show me they fail, then build)
pgTAP tests in supabase/tests/ and Playwright tests in tests/e2e/supervisor-review.spec.ts at 360 and 390 px, against the local Supabase database with the made-up seed, the same way the Session 9 route tests run. Never against the development or production project.
1. A supervisor approves a waiting lot; a new row exists in first_piece_reviews, re-read from the database, and the card leaves the queue.
2. A supervisor returns a lot with a reason; a return with an empty or blank reason is refused by the database.
3. The operator who recorded the lot's results sees it under "Returned to you" with the reason, records a correction as a new inspections row that points at the returned one with a reason, and the lot comes back to the queue. The returned row is unchanged.
4. A supervisor who recorded any of the lot's results cannot decide on it: refused by the database, even when the request is sent directly.
5. A second decision on a lot after the card was opened is refused with "Already decided by <name> at <time>: reload".
6. Update and delete on first_piece_reviews are refused for every role, including through the append-only trigger.
7. reviewed_by is the signed-in supervisor, set by the database, whatever the page sends.
8. For every role in docs/matrix.json, /supervisor/review is allowed or refused exactly as the matrix says; a supervisor of the other made-up site sees none of this site's lots.
9. Every tappable control is at least 44 x 44 px; Approve and Return at least 64 px high; no sideways scroll.

## What to build
1. Apply the agreed matrix change to docs/matrix.json. Regenerate the policies with scripts/gen-policies.mjs into a new migration and the route list with its generator. Do not hand-edit generated files.
2. A new migration (npx supabase migration new first_piece_reviews): a decision table first_piece_reviews with id, site_id, lot_id, action ('approve' or 'return'), reason (required and not blank for return), reviewed_by and reviewed_at (set by the database from the session), and latest_inspection_id (the newest result the supervisor saw). Use the existing append_only() trigger. The separation rule and the "already decided" rule are enforced in the database. Do not edit any existing migration.
3. The queue at /supervisor/review, as the plan describes, with the difference from the limits worked out by the database. "Approved" or "Returned" appears only after the database confirms the new row.
4. "Returned to you" on the operator's first-piece screen, with the correction as a new row.

## Out of scope
The manager view (next brief). Holding or releasing lots. Changing any existing test, check or limit. Touching the development or production project.

## How to show it works
Open a pull request titled "Supervisor review queue". Wait for every check on GitHub to finish. Report in plain words: each acceptance check, pass or fail, and how you showed it failing first; the new migration files; the preview link. Then answer Yes or No, with file and line: (a) any update or delete right anywhere? (b) any number or name shown that the database did not supply? (c) any use of the service role key? (d) any existing test or check changed? If a check fails, fix the code, never the check, and wait again before reporting.
----------

You will see recreated screen

claude — acme-platform
⏺ Write(docs/matrix.json)
+ "first_piece_reviews": { "supervisor": "read,add", "operator": "read", "quality_lead": "read", "manager": "read" },
+ "rules": ["nobody reviews a lot whose results they recorded"],
1
⏺ Bash(node scripts/gen-policies.mjs)
⎿ Wrote supabase/migrations/20261029101500_policies_first_piece_reviews.sql · 6 allowed + 6 refused tests
2
⏺ Bash(npx supabase test db)
⎿ 18 failed (relation first_piece_reviews does not exist)
⏺ Bash(gh pr checks --watch)
⎿ schema pass · access pass · routes pass · c9-phone pass · Vercel Preview ready
⏺ Pull request #35 is green. All 9 acceptance checks pass; all failed before the code existed. (a) No update or delete right anywhere. (b) Every value on the card comes from the database. (c) No service role key. (d) No existing test changed. Preview: https://acme-platform-git-ui-supervisor-review-acme-ops.vercel.app/supervisor/review3
The matrix changes first; the generators write the rules from it; the tests fail first; then the queue is built until GitHub's checks are green.
  1. The right is a line in the matrix, as agreed in the plan.
  2. The policies and their allowed and refused tests are generated, not typed.
  3. The four review answers are in the report, so you read one message, not four.

Check it worked

Pull request Supervisor review queue is green; the report lists nine passing acceptance checks, each shown failing first, and answers (a) to (d) with No.

Fastest path

Putting your four review questions into the brief's report saves the separate reading round: you check the answers against the Files changed tab instead of asking for them.

If it goes wrong

Approve shows Approved but no row appears in first_piece_reviews

In Postgres a role that cannot read the row it writes may be refused quietly. Say: Approve reports success but no row is stored. Check the supervisor's read right covers the new row, make the screen show Approved only after re-reading the row, and add a test per role that the row really exists.

A check named for a list fails (the routes or the policies)

The generated files no longer match the matrix. Say: The "<check name>" check failed. Read its log, run the generator it names, commit the result and show me what changed. If a role gained a right I did not agree, stop and tell me.

Claude Code wrote the policy by hand instead of generating it

Say: Remove the hand-written policy. Change docs/matrix.json and run scripts/gen-policies.mjs. If the generator cannot express the separation rule, show me the smallest change to the generator and wait.

It reports success but a check on GitHub is red

Say: The check is red. Run gh pr checks, read the failed log, fix the cause and wait for green before you report. Trust the check on GitHub, never the summary.

Step 4

Play operator and supervisor on the preview, and try what must be refused

20 minutes

Why

Tests prove the rules on a database built from nothing. Walking one lot through record, return, correct and approve on the preview, as two different people, proves the whole loop on the made-up plant data the floor will resemble. Trying the three things that must be refused, yourself, shows you the safety net is real and not only a line in a report.

Do this

In a terminal (not inside Claude Code), apply the branch's two new migrations to the development project, typing its database password from the password manager:

Terminal or PowerShell
cd ~/code/acme-platform && git fetch && git switch ui/supervisor-review && npx supabase link --project-ref tsrqponmlkjihgfedcba && npx supabase migration list && npx supabase db push
Open

https://github.com/acme-ops/acme-platform/pulls

Open Supervisor review queue, then Visit Preview. Use two browsers (or a phone and a laptop): one signed in as the operator test user, one as the supervisor test user.

  • Operator: on /operator/first-piece, enter a first piece with flange height 25.31 (above 25.20).
  • Supervisor: on /supervisor/review, find the card. Return it with the reason Flange high: adjust die and re-measure.
  • Operator: open Returned to you, record 25.04 as the correction, with the reason Die adjusted.
  • Supervisor: the lot is back, showing both values. Approve it.
  • Two decisions at once: have the operator enter another lot. As the supervisor, open the queue in two tabs, approve the lot in the first, then press Approve in the second. The second must be refused with Already decided by a name and time.
  • Wrong role: as the operator, type /supervisor/review into the address bar. It must be refused. (Only operators record first pieces, so a supervisor reviewing their own lot cannot be tried from the screens; acceptance check 4 proves the database refuses it if it is ever tried directly.)

Then, in the development project's SQL editor, try to delete the decision you just made. This must fail, even though the dashboard's own login skips access rules:

Open

https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new

The development project's SQL editor. Never run this in production.

Supabase SQL Editor (development project)
-- Must fail: decisions are never deleted.
delete from public.first_piece_reviews
where id = (select max(id) from public.first_piece_reviews);

You will see recreated screen

acme-platform-git-ui-supervisor-review-acme-ops.vercel.app/supervisor/review
Waiting for review · Cleveland · Shift B
Press 03 · part 7741 · lot L-0412 · waiting 6 minCorrected by operator (test) at 07:12: flange height 25.04, inside 24.80 to 25.201
Returned at 06:58 by supervisor (test)Flange height 25.31, 0.11 mm above the upper limit. Reason: Flange high: adjust die and re-measure2
Approve
Return
The supervisor's queue on the preview: the returned lot is back with both values, and the difference in words.
  1. The correction, a new row, with who and when.
  2. The returned result, unchanged, with its reason.
  3. Shown only after the database confirmed the new row.

You will see recreated screen

supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new
Table EditorSQL EditorDatabaseAuthentication
delete from public.first_piece_reviews where id = (select max(id) …
The delete, refused by the append-only trigger from Session 5.
  1. The refusal is what you want. If the row is deleted, stop: the trigger is missing, and nothing merges until it is back.

Check it worked

The lot went recorded, returned, corrected, approved, with both values kept; the second decision and the operator's visit to /supervisor/review were refused; the delete failed with the append-only message.

If it goes wrong

The operator can open /supervisor/review

Stop: do not merge. Say: The operator can open /supervisor/review. Show me which line of docs/matrix.json or lib/access/routes.ts allows it, without changing anything. If the matrix is right, the generated list or the proxy is wrong, and the per-role test missed it: ask for both to be fixed.

The second approval was accepted too

Two decisions on one lot, neither knowing of the other: the "already decided" rule is missing or only on the screen. Say: Two tabs both approved the same lot. The database must refuse a decision when the lot has a newer result or decision than the card's latest_inspection_id. Fix it and add a test that sends two decisions from the same starting card and expects exactly one to succeed, failing first.

The delete worked

The append-only trigger is not on the new table. Say: Delete on first_piece_reviews succeeded in the development project. Add the append_only() trigger in a new migration with a test that update and delete are refused, and show it failing first. Then reseed the development project as Session 6 documents.

The supervisor's queue is empty although the operator entered a lot

Check the supervisor test user is a member of the same site as the operator's lot. If they are, ask Claude Code: The supervisor sees no waiting lots on the preview although lot L-0412 has new results. Explain which rule hides it, without changing anything.

Step 5

Merge, and let the deploy apply it

5 minutes

Why

Merging is what changes production: the deploy workflow applies the two new migrations (the table and its generated policies) before the new screens go live. Checking the run, and that the new screen refuses a signed-out visitor on the live address, proves the right and its lock reached production together.

Do this

Owner two reads the pull request and its report, approves; merge. Then:

Open

https://github.com/acme-ops/acme-platform/actions/workflows/deploy.yml

The run for the merge commit: both migrations applied, production ready, freshness green.

Open

https://acme-platform.vercel.app/supervisor/review

Signed out, this must send you to sign in.

You will see recreated screen

github.com/acme-ops/acme-platform/actions/workflows/deploy.yml
deploy · Supervisor review queue (#35)
The deploy after the merge: the decision table and its policies applied before the code went live.
  1. Both files, in order: the table, then its access rules.

Check it worked

The deploy run is green with both migrations applied, and https://acme-platform.vercel.app/supervisor/review sends a signed-out visitor to sign in.

If it goes wrong

The deploy fails at the migration step

Production keeps the old code. Do not run anything against production yourself. Ask Claude Code to read the log and explain why, without changing any project, then follow docs/runbook.md.

After merging main into the branch, a test or column you added has gone

Someone undid a batch on main and the undo took yours with it, with no conflict. Say: I merged main. List every migration, policy and test this branch added and confirm each is still there. If any disappeared, find the commit that removed it and tell me before changing anything.

Knowledge check

Approve shows Approved, but no new row is in first_piece_reviews. What is the likely cause?

Knowledge check

Why does the brief change docs/matrix.json and run the generator, instead of asking for a policy?

References

  1. PostgreSQL Documentation: Row Security Policies. https://www.postgresql.org/docs/current/ddl-rowsecurity.html
  2. Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
  3. Supabase Docs: Database migrations. https://supabase.com/docs/guides/deployment/database-migrations
  4. Supabase Docs: Testing your database (pgTAP). https://supabase.com/docs/guides/database/testing

Chapter 3 · Session 13

The manager view, and every role tested

One brief builds a manager view of counts straight from the records, each traceable to its rows. A second prompt adds the test that signs in as every role and checks each sees exactly the screens the matrix allows, and that every link on them goes somewhere. Then you check the numbers by hand and merge.

35 min3 stepsEnds with a gate

By the end of this chapter you can

  • Have Claude Code build a manager view that shows only counted numbers, with where each comes from.
  • Add a test, generated from the matrix, that every role sees exactly the screens it is allowed and every link resolves.
  • Check every number against its rows, take the view offline, and merge.

Rules for every number on the view

RuleIn practiceWhy
Counted from records, never typed or generated"Outside limits: 2" is two rows in inspectionsInvented numbers look finished and are believed
Says where it comes fromUnder each count: the table, the shift's time window and the row countA manager who doubts a number can check it in one tap
Tap to see the rowsThe list behind "Waiting for review: 3" has exactly three lotsA number that cannot be traced is an opinion
No rows is "No data" or a true zero, never a guessA count of zero is shown only when the read succeeded; a ratio with no rows is not shownAn unreadable value shown as 0 is a false reading
Fresh, or says it is not"As of 07:42"; refreshed every 60 s, paused when the tab is hidden [1]; greyed with "Not updating since 07:42" after three missed readsA frozen view that looks live is worse than a blank one
Words as well as colour"2 waiting more than 30 min" in amber, with the wordsColour must not be the only way information is shown [2]
Review waiting timeBars of the oldest waiting record at each hour of a shift; two hours exceed the limit line. Oldest record waiting for review at each hour, minutes (limit 30)4069072208350912106113112813
How long lots wait for review. The oldest waiting lot at each hour of a shift, from made-up data; at 09:00 and 12:00 it passed the 30-minute limit the supervisor set. The manager view shows the current value of this, counted from the records.

Tests per role, from the matrix

Each screen so far has its own tests. One more test looks across them all: it reads docs/matrix.json, signs in as every role in turn [3], opens every screen, and expects allowed or refused exactly as the matrix says. Signed in is not the same as allowed: our platform once let any signed-in user delete a whole site because the only check was that someone was signed in. Because the test is driven by the matrix, a new screen without a row in it fails the build.

The same test visits every link on every screen it may open and fails on a not-found page, an error page or a console error. A link that compiles is not a link that goes somewhere: we once had 130 tool links pointing at an address that did not exist, and a redesign that silently dropped notifications and help from every page.

Step 6

One brief: the manager view, with only measured numbers

15 minutes

Why

The manager acts on these numbers, so each must be one that someone measured, and traceable to the rows behind it. Writing those rules into the brief as acceptance checks, including a test that renders the view with no data, is what stops an agent filling the empty places with something that looks finished.

Do this

Paste into Claude Code
Save everything between the two lines of dashes below as docs/briefs/13-manager-view.md on a new branch ui/manager-view (from the latest main), commit it, then carry it out.
----------
# Brief 13b: the manager view

## Goal
The manager sees, for this shift at their site, how first pieces are going and where lots are waiting, from counts of the records, each traceable to its rows.

## Context (read first)
- docs/screens/manager-view.md (signed off); docs/matrix.json; supabase/migrations/; CLAUDE.md.
- This Next.js version differs from older guides. Before writing any page or proxy code, read the relevant guides in node_modules/next/dist/docs/.

## Acceptance checks (write these first, run them, show me they fail, then build)
Playwright tests in tests/e2e/manager-view.spec.ts at 360 and 390 px, against the local Supabase database with the made-up seed, never against the development or production project.
1. Each count on /manager equals the number of rows behind it, counted separately by the test with its own query.
2. Tapping a count lists exactly those rows.
3. With no records for the shift, each count says "No data" or a true 0 as the plan says; no number appears that the database did not supply.
4. When the read fails, the view says "Could not read" and does not show earlier numbers as current; after three missed reads it is greyed with "Not updating since <time>".
5. The view shows "As of <time>", refreshes every 60 seconds and pauses while the tab is hidden.
6. A manager of the other made-up site sees none of this site's counts or rows.
7. For every role in docs/matrix.json, /manager is allowed or refused exactly as the matrix says. The view has no buttons that change anything.
8. Every tappable control is at least 44 x 44 px; no sideways scroll; status in words as well as colour.

## What to build
1. The view at /manager, as the plan describes. Counts come from database queries or views run with the manager's own session; any new database view goes in a new migration, created with security_invoker = true. No service role key. No hard-coded, sample or generated value anywhere.
2. Under each count, where it comes from: table, time window and row count. Each count opens its rows.
3. Add /manager to docs/matrix.json as the plan agreed, and regenerate the route list. Do not hand-edit generated files.

## Out of scope
Targets, percentages, trends and charts (Session 15). Changing any existing test, check or limit. Touching the development or production project.

## How to show it works
Open a pull request titled "Manager view". Wait for every check on GitHub to finish. Report in plain words: each acceptance check, pass or fail, and how you showed it failing first; the preview link. Then list every number the view can show with the query that produces it. If a check fails, fix the code, never the check, and wait again before reporting.
----------

You will see recreated screen

claude — acme-platform
⏺ Bash(npx playwright test tests/e2e/manager-view.spec.ts)
⎿ 16 failed (page /manager does not exist yet)
1
⏺ Bash(npx supabase migration new manager_view_counts)
⎿ Created new migration at supabase/migrations/20261030083000_manager_view_counts.sql
⏺ Bash(gh pr checks --watch)
⎿ schema pass · access pass · routes pass · c9-phone pass · Vercel Preview ready
⏺ Pull request #36 is green; all 8 checks failed first and pass now. Numbers on the view: First pieces recorded (inspections, distinct lots this shift); Outside limits (inspections joined to characteristics); Waiting for review (lots with results and no decision since, from first_piece_reviews); Returned, not yet corrected; On hold (lot_status). No other number appears.2
The report ends with every number and the query behind it: the list you check in Step 8.
  1. Red first, at both phone widths.
  2. Every number and its source, in one list. Anything you cannot match to a row is a finding.

Check it worked

Pull request Manager view is green, and the report lists every number with the query that produces it, and nothing else.

If it goes wrong

The view shows a percentage, a target or a trend you did not ask for

Say: Remove every number that is not a count from the plan. Targets and definitions come in Session 15. Then check the empty-data test still passes.

A count is wrong by a few rows near the start of the shift

The shift's time window is probably worked out in the wrong time zone. Say: Work out the shift window in the plant's time zone from the timestamptz columns, and add a test with a result at 05:59 and one at 06:01.

Claude Code used the service role key to make the counts faster

Say: Remove the service role key. The counts run with the manager's own session so the access rules apply. A manager of another site must see nothing. The service role key skips every access rule.

Step 7

Add the test that every role sees exactly what the matrix allows

10 minutes

Why

Each screen's own tests check its own roles. This test checks the whole platform at once, from the matrix: every role, every screen, every link. It is the test that catches the screen someone adds next month without a matrix row, the link that goes nowhere, and the role that can open a page it should not.

Do this

Paste into Claude Code
On the branch ui/manager-view, add tests/e2e/roles-and-links.spec.ts, generated from docs/matrix.json so it changes when the matrix changes:

1. For every role in the matrix, sign in as that role's test user (the same way the Session 9 route tests do) and open every screen in the matrix. Each is allowed or refused exactly as the matrix says. Signed out, every screen sends you to sign in.
2. The navigation each role sees lists exactly the screens it may open.
3. On every screen a role may open, visit every link and button that navigates. Fail on a not-found page, an error page or a console error, and report each by role, screen and link.
4. If a screen exists under app/ that the matrix does not list, fail with its address.

Run against the local Supabase database with the made-up seed, never against the development or production project. Show the test failing once by removing one screen's line from a copy of the matrix in the test, then restore it. Push, wait for every check on GitHub, and report: roles tested, screens, links visited, and the failing-first result. If a check fails, fix the code, never the check.

You will see recreated screen

claude — acme-platform
⏺ Bash(npx playwright test tests/e2e/roles-and-links.spec.ts)
⎿ 6 roles × 4 screens: 24 access checks · 41 links visited · 0 not found · 0 errors
1
⏺ Bash(npx playwright test -g "unlisted screen")
⎿ 1 failed (planted): /manager exists under app/ but not in the matrix · exit code 1
2
⏺ Bash(gh pr checks --watch)
⎿ e2e pass · c9-phone pass · Vercel Preview ready
⏺ The roles-and-links test checks 6 roles against 4 screens and visits 41 links; all pass. With /manager removed from a copy of the matrix it failed as it should. Checks on GitHub are green.
Every role, every screen, every link, from the matrix.
  1. Each role against each screen: allowed or refused as the matrix says.
  2. Shown failing first. A test that cannot fail proves nothing.

Check it worked

The report names every role and screen, the number of links visited with none broken, and a failing-first result; the checks on GitHub are green.

If it goes wrong

The test finds a role can open a screen the matrix does not give it

That is the test doing its job. Say: Role <role> can open <screen>, which the matrix does not allow. Show me which file allows it, fix it there (or in the generator), and do not change the matrix or the test.

A link goes to a page that does not exist yet (for example a dashboard from Session 15)

Say: Remove the link until the page exists. Do not add an exception to the test. A link to nowhere is a defect, even a temporary one.

The test passes but visited 0 links

It could not sign in, so it saw only the sign-in page. Say: The test visited no links. Show me which page each role landed on. Landing on the sign-in page is "could not measure", not a pass; make the test fail in that case.

Step 8

Check the numbers by hand on the preview, then merge

10 minutes

Why

The tests count rows on a database built from nothing; you check the view on the made-up plant data, as the manager, against the rows behind each number. Taking it offline proves it says when it is not updating instead of showing old numbers as live. Then the merge carries the view to production through the pipeline.

Do this

Apply the branch's migration to the development project, as before (password from the password manager):

Terminal or PowerShell
cd ~/code/acme-platform && git fetch && git switch ui/manager-view && npx supabase migration list && npx supabase db push
Open

https://github.com/acme-ops/acme-platform/pulls

Open Manager view, then Visit Preview, and sign in as the manager test user. Go to /manager on a phone.

  • Tap each number. Count the rows it lists. They must match.
  • In another browser, as the operator, enter a first piece outside its limits. Within a minute, Outside limits and Waiting for review each go up by one.
  • Turn on airplane mode. After about three minutes the view greys and says Not updating since a time. Turn it off: it recovers by itself.

Then owner two reviews, approves and merges, and you check the deploy and the live address as in Step 5:

Open

https://github.com/acme-ops/acme-platform/actions/workflows/deploy.yml

The run for the merge commit: green, migration applied.

You will see recreated screen

acme-platform-git-ui-manager-view-acme-ops.vercel.app/manager
Cleveland · Shift B · as of 07:421
First pieces recorded: 9inspections · 9 lots since 06:002
Outside limits: 2inspections and characteristics · 2 results
Waiting for review: 3 · oldest 34 minfirst_piece_reviews · 3 lots with no decision since their latest result3
Returned, not yet corrected: No datafirst_piece_reviews · no returns this shift
On hold: 1lot_status · 1 lot
The manager view on the preview: counts from the records, each with where it comes from.
  1. The time of the last successful read. Older than three minutes, the view greys and says so.
  2. Every number says where it comes from.
  3. Status in words as well as colour.

Check it worked

Every number matched its rows, the counts moved after the operator's entry, the view said Not updating offline and recovered, and after the merge the deploy is green and https://acme-platform.vercel.app/manager refuses a signed-out visitor.

If it goes wrong

A number does not match its rows

Stop: do not merge. Say: On the preview, <count> shows N but its list has M rows. Find the difference, fix the query, and add the case to the acceptance test, showing it failing first.

Offline, the view keeps showing the numbers as if live

Say: With no network the view shows old numbers as current. Make it grey with "Not updating since <time>" after three missed reads, as acceptance check 4 says, and show me why the test did not catch it.

The preview shows a counted value the development project does not have (such as seven made-up managers)

Something is invented. Say: Search every screen for hard-coded, sample or generated values, including 0 used for unknown. For each, show me where it comes from, and replace any that is not a stored value with "No data".

Before you go on · Session 13 is done whenTick each one

Knowledge check

The manager view has no returns this shift. What should the Returned count show?

Knowledge check

Why is the roles-and-links test generated from docs/matrix.json?

References

  1. MDN Web Docs: Page Visibility API. https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
  2. W3C: Understanding WCAG 2.2 Success Criterion 1.4.1 Use of Color. https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html
  3. Playwright: Authentication (signing in as different users). https://playwright.dev/docs/auth
  4. PostgreSQL Documentation: CREATE VIEW (security_invoker). https://www.postgresql.org/docs/current/sql-createview.html

Chapter 4 · 12 questions · 80% passes

Final assessment

Twelve questions across the session. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.

15 min12 questions≈ 15 minutesRetake allowed

Choose one answer for each question, then submit. You will see the right answer and why for every question.

1. What are the supervisor's two decisions on a lot's first piece?
2. A lot is returned and the operator re-measures. How is the new value recorded?
3. How are decisions made impossible to change or delete?
4. Where is 'nobody reviews a lot whose results they recorded' enforced?
5. How does a new right, such as supervisors adding reviews, reach the database?
6. Approve shows Approved, but no row is stored. What should the screen have done?
7. Two supervisors approve the same lot from cards opened at the same time. What should happen?
8. Who is recorded as the reviewer?
9. Which number may the manager view show?
10. The manager view cannot reach the database for three minutes. What should it show?
11. Why is the roles-and-links test generated from docs/matrix.json?
12. The roles-and-links test passes but visited 0 links. What does that mean?