Close the four earlier lessons and work from this brief. The workspace has
an executable case table but an unfinished run function. Complete the rule
before looking at the solution. Twenty-four minutes is a suggested first pass;
split the work across sessions if you need more time.
The brief
Allow read and write only within the actor’s tenant. Owners may read and write; reviewers may read but not write. Missing actors and unknown operations are denied.
Keep the function deterministic and leave its inputs unchanged. Explain how this rule connects to a Next.js page, action or route handler; the table is a contract harness, not a substitute for testing that transport.
Acceptance cases
- Input
{"actor": {"id": "ada", "tenantId": "a"}, "row": {"ownerId": "ada", "tenantId": "b"}, "operation": "write"}→false. - Input
{"actor": {"id": "grace", "tenantId": "a", "role": "reviewer"}, "row": {"ownerId": "ada", "tenantId": "a"}, "operation": "read"}→true. - Input
{"actor": {}, "row": {}, "operation": "write"}→false. An actor with no id or tenant must not match a row with no owner or tenant.
Add one case of your own to examples: the least convenient input you can
think of, such as an empty list, a missing field or a repeated value. Work out
its expected result before you run it. The table's Input kept column must
say yes on every row: the rule may not change what it was given.
npm install and npm run dev. Hint 1: the idea
Separate validation, calculation and output shaping. Decide the failure precedence before writing the happy path.
Hint 2: a first step
Tenant isolation is checked before role or ownership. Test a same-id actor from a different tenant.
Show one solution
npm install and npm run dev. A matching output alone is not the whole check: the Input kept column must say yes too. Then explain the rule to yourself without reading the implementation.
Before the next day
- Which layer owns this decision, and which layer translates it for the reader?
- What happens on the least convenient input, not only the happy path?
- What would you test in a real browser or server that this pure function cannot establish?
Completion is saved in this browser only. It does not measure mastery.