Tool Library: Rehearse the Design

Design problem and decision

  • Design problem The design is on paper. Someone else, or an AI, will build it. The architect must know it works before release, and know each later release is safe before it is installed.
  • Viewer's decision What evidence do I ask for, and how do I write it down so that it can be run?
  • Outcome The viewer can write a simulation as commands, expected outcomes and invariants, including refusals. They can write a release rehearsal as a populated old release, a list of upgrade attempts, and values compared before and after. They can say which question each one answers and assemble the complete brief.
  • Starting point Lesson 7 left the app on release 3 and three build cards on the rail.
  • Handoff This is the last film. The Rechain, Reactor and Takt films cover modules that use this same memory model.
  • Pacing Four minutes.

Worked design

Tool Library is illustrative. Every result below is expected and was not run.

Simulation. Release 1 rules, day 100, starting state as in lesson 2.

# Command Expected outcome State change
1 lend(501, 3, 17) Lent { loan 7, due 114 } drill 4/1, 501 active 3, loans 5
2 lend(501, 3, 17) Refused(LimitReached) none
3 lend(502, 3, 22) Refused(NoneAvailable) none
4 give_back(5) Returned ladder 1/1, 501 active 2, loans 4
5 lend(502, 3, 22) Lent { loan 8, due 114 } ladder 1/0, 502 active 3, loans 5
6 close_branch(3) Refused(ToolsOut) none

Invariants, checked after every command.

Rule
I1 For every tool, 0 ≤ available ≤ owned.
I2 For every member, the active count equals that member's rows in Loans, and is at most the limit.
I3 For every branch, the tools out, owned − available summed over its shelf, equal that branch's rows in Loans.
I4 A refused command leaves every saved value equal to what it was.

Rehearsal. A local canister running release 2, populated as in lesson 7.

# Attempt Expected result Values after
1 r3 built without a named predecessor refused equal to before
2 r3-late-fail rolled back equal to before
3 r3 converted before, plus good on every tool
4 r2 refused equal to after attempt 3
5 r3 again accepted equal to after attempt 3

After attempts 3 and 5: lend, give_back and set_condition each succeed once. The lend uses a new member, because release 2 and later refuse members 501 and 502, who have overdue loans on day 120.

The story in one pass

Write one scenario row and watch the app react to it. Play six rows with the invariant lights on. Point at the refused rows. Say what a simulation cannot show. Fill a canister with an old release, record its values, and play five upgrade attempts with a before and after card under each. Then run ordinary commands on the result. End on the assembled brief.

Views and visual objects

Use the shared visual language. This film introduces ScenarioSheet, RehearsalStrip and BriefCard.

View Framing and anchor
simulate ScenarioSheet at left: a table with columns command, expect, got. The app at right, reduced, with no canister boundary and no rail. Four invariant lights, I1 to I4, in a row above the app.
rehearse The app inside its canister boundary with ReleaseRail and Gate. RehearsalStrip along the bottom: five slots, each with a small before and after value card.
brief One BriefCard centered, with the AppTree small at left.

Scene simulate — Do the rules hold?

Already on screen The app on release 3 from lesson 7.

Beat one_row — A command and what must come back

View and focus simulate.

Narration

Before anything is deployed, we can run the modules on their own. No canister, no upgrade. Just commands going in and answers coming out. Each row of a simulation says three things: the command, the answer we expect, and what must still be true afterward.

Cue and animation On “run the modules on their own”, the canister boundary and the rail fade, and the app resets to the lesson 2 starting state on day 100. On “Each row”, the sheet draws with one row: lend(501, 3, 17) · Lent { 7, 114 } · blank. On “still be true afterward”, the four lights I1 to I4 appear, each with its short rule beneath.

Leaves with One row, four lights, the app at its starting state.

Beat six_rows — Play the scenario

View and focus simulate. Focus follows the active row.

Narration

Run it. Loan seven goes out. The same member asks again and is refused. A ladder that is out is refused. Loan five comes back, and now the ladder can go. And a branch with tools out will not close. After every single command, all four rules are checked.

Cue and animation Each row appears, its pill enters the app, the capsules react exactly as in lessons 2 and 3, and the got column fills. On “Loan seven goes out”, row 1: drill 2 → 1, 501 2 → 3, a new Loans row, green tick. On “asks again and is refused”, row 2: neutral card, tick. On “A ladder that is out”, row 3: neutral card, tick. On “Loan five comes back”, row 4: ladder 0 → 1 in green, 501 3 → 2 in red, a Loans row leaves, tick. On “now the ladder can go”, row 5: ladder 1 → 0, 502 2 → 3, new row (114, 8), tick. On “will not close”, row 6: neutral card, tick. On “all four rules are checked”, the lights I1 to I4 blink green in sequence.

Leaves with Six rows with ticks. Four green lights.

Beat refusals_count — Half the rows are refusals

View and focus simulate. PauseAndExplain pointing at rows 2, 3 and 6.

Hold The balloon reads:

A good scenario has
  the ordinary path
  every refusal, each with its named reason
  the edges: the last tool, the third loan, the 33rd branch
  rule I4: a refusal changed nothing
  then a few thousand random commands from a fixed seed,
    with the same four rules after each

Narration

Look at how many of these rows are refusals. That is deliberate. The ordinary path rarely hides a mistake. The edges do. And rule four checks the thing we asked for in lesson one: a refusal changes nothing. Once the hand-written rows pass, ask for a long random run under the same rules.

Cue and animation All motion holds. Rows 2, 3 and 6 outline. Light I4 pulses on “a refusal changes nothing”. On “long random run”, a compressed band of many thin rows scrolls under the sheet with the four lights steady.

Leaves with Sheet complete.

Beat what_it_cannot_show — Rules, not releases

View and focus simulate.

Narration

A simulation answers one question: are the rules right? It is fast, and it sets the day itself, because the day is an argument. It says nothing about an upgrade. For that we need a real canister with a real old release in it.

Cue and animation On “sets the day itself”, the today value 100 shows beside the sheet and steps to 120. On “says nothing about an upgrade”, the place where the rail and gate would be shows as a faint empty outline. On “a real canister”, the canister boundary draws back around the app.

Leaves with The app inside its boundary. Sheet sliding away.

Scene rehearse — Is this release safe on real data?

Already on screen The app inside its canister boundary.

Beat populate_old — Start from the old release, full

View and focus rehearse.

Narration

A rehearsal starts where production is. Install the old release, the real build. Fill it through its public methods: two branches, three tools, five loans. Then write down what is there. These values are the test.

Cue and animation On “Install the old release”, r2 sits in the socket. On “Fill it”, pills stream through the canister edge and the vault tables fill to the lesson 7 state. On “write down what is there”, a before card fills in the first slot of the strip: drill 4/1 · ladder 1/0 · saw 2/1 · 501: 3 · 502: 2 · loans 5 · branches 3, 5.

Leaves with A populated release 2 and one before card.

Beat five_attempts — Try everything that could happen

View and focus rehearse. Focus moves along the strip.

Narration

Now attempt every upgrade that could happen, in order. A build that forgot to name its predecessor: refused, values equal. A build that fails late: rolled back, values equal. The real release three: converted, and every old value is there with the new field beside it. Then the old build again: refused, nothing lost. Then release three once more, over itself: accepted, values equal. Five attempts. Each one has a before, an after, and an expected difference. Four of the five expect no difference at all.

Cue and animation For each attempt its card travels to the gate and the strip slot fills. On “forgot to name its predecessor”, slot 1: red bar, after equals before, an equals sign between them. On “fails late”, slot 2: the conversion flashes and snaps back, equals sign. On “The real release three”, slot 3: green tick, v2 tabs appear on root, Branches and shelves, after shows each tool with good, and a small + condition mark sits between the cards. On “the old build again”, slot 4: red bar, equals sign against slot 3's after. On “once more”, slot 5: green tick, equals sign. On “Four of the five”, the four equals signs pulse.

Leaves with Five filled slots. The app on release 3.

Beat still_works — Then use it

View and focus rehearse. Focus on the app.

Narration

One more step, and it is the one people skip. After the upgrade, use the app. Lend a tool. Take one back. Record a condition. Old data read correctly is half of it. New writes on top of old data is the other half.

Cue and animation On “Lend a tool”, a new member joins with join(503) and lend(503, 3, 30) returns Lent { loan 8, due 134 }, with saw 1 → 0. On “Take one back”, give_back(7) shows drill 1 → 2. On “Record a condition”, set_condition(3, 17, worn) changes good to worn.

Hold PauseAndExplain pointing at the strip. The balloon reads:

Simulation                    Rehearsal
  are the rules right?          is this release safe on real data?
  modules only, no canister     real builds on a local canister
  seconds                       minutes
  every change to rules         every change under memory/,
                                and every release

Leaves with The app on release 3 with drill 4/2 worn and saw 2/0 good.

Scene hand_over — The complete brief

Already on screen The app on release 3 and the filled strip.

Beat brief — What you give the team

View and focus brief.

Narration

This is what you hand over. The modules and what each one saves. Who owns whom, and who calls whom. A bound on every collection. What each storage choice must promise. The files that are frozen. When the app is ready to upgrade. The scenario, and the rehearsal. You did not write a line of the code. You decided everything that the code must be.

Cue and animation The app and strip shrink into small icons that settle onto the BriefCard as its sections: on “The modules”, capsules; on “Who owns whom”, the two drawings; on “A bound”, a counter; on “each storage choice”, a ChoiceCard; on “frozen”, a locked file; on “ready to upgrade”, the readiness shield; on “The scenario”, the sheet and the strip. On “everything that the code must be”, the AppTree at left lights every folder once.

Leaves with The complete BriefCard and the file tree.

Brief to hand over

Illustrative. This is the card on screen at the end.

Tool Library — design brief

  1. Modules. Policy, Members, Branches, Shelf, Loans each save their own state and expose public functions. Desk saves nothing.
  2. Owning tree. Root owns Policy, Members, Branches, Loans. Branches owns one Shelf per branch number.
  3. Call graph. Desk calls Policy, Members, Branches, Loans. Branches calls its shelves. Public canister methods call Desk, Branches or Loans and nothing else.
  4. Rules. Decide expected refusals, including capacity checks, before the first write. Public methods check the caller and supply the canister's date. Simulations give Desk a fixed today value.
  5. Bounds. 32 branches. 500 tools per shelf. 10,000 open loans. 3 loans per member.
  6. Storage. Loans is exact and ordered by (due day, loan). Everything uses the default engine.
  7. Frozen. No shipped vN.rs is ever edited.
  8. Readiness. Ship the readiness check in release 1. Pause new fees, settle outstanding outcomes, and proceed when the pending count is zero. Resume intake after the release checks pass.
  9. Simulation. The six-row scenario and invariants I1 to I4, then 5,000 random commands from a fixed seed, checking I1 to I4 after each. Also once with the services dropped and bound again halfway through.
  10. Rehearsal. For every release: the old release populated through its public methods, the five attempts, values recorded before and after each, and one lend, give_back and set_condition after each accepted upgrade. Builds come from the canonical builder. No build is patched to fake a change.

Production and source notes

  • Tool Library, the scenario, the invariants, the rehearsal and the brief are illustrative. Nothing here was run. Label the sheet and the strip expected in a small caption when they first appear.
  • The simulation is modelled on Shop's native tests, which install the app on a native store, call service methods, assert each result, drop the app and open it again. Shop tests, lines 4 to 36. Its second test is all refusals and bounds, then asserts stock unchanged. Lines 38 to 60.
  • What a native simulation cannot establish: "Native tests do not establish IC endpoint or lifecycle behavior." Upgrades, lines 246 to 253. Native tests also have no rollback of their own. After a panic the test must discard the whole store. Conventions, lines 138 to 143.
  • The rehearsal follows the order of the root authoring lifecycle test: populate, refused builds with old values asserted, late failure with old values asserted, successful conversion, refused downgrade, a second upgrade to the same target, and a fresh write. Read, not run. Root authoring lifecycle test, lines 58 to 96.
  • "Install populated state, exercise its real methods, then upgrade with KEEP and verify restoration. Test rejected source/layout contracts and trap rollback as well as successful conversions." The checkout provides no universal canister runner. The app supplies its own. SDK tests, lines 28 to 37.
  • "No build is patched" follows the nested lifecycle test's first rule: use real source variants and never patch a build to simulate a change. Nested lifecycle test, line 2.
  • The rehearsal's upgrades keep main memory and use builds from the canonical builder. A raw build lacks the startup check. Upgrades, lines 141 to 146.
  • A deterministic random run is a design request in this course. The checkout has its own seeded fuzz targets for store migration, cited only as evidence that the practice fits. Store migration fuzz target
  • In still_works, give_back(7) returns the drill lent in lesson 2, so the drill reads 4/2. Member 501 goes to 2 active. Member 503 is new because 501 and 502 both hold overdue loans on day 120 and release 3 keeps the release 2 rule. Keep the resulting rows in the vault tables.
  • A passing rehearsal covers the builds and the data it used. Say "this release, on this data". Do not say the release is proven safe in general. Status, lines 104 to 108.
  • Do not show test runner output, command lines or file names of test scripts.