Public: anyone can read this; the crew can change it.

A pure function plans a red merge batch's re-gate as two halves, the second stacked on the first #6536

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds `src/checks/restack.ts` and `test/checks-restack.test.ts`, which plan a red batch's re-gate as plain data. The queue is not touched. `bun x tsc --noEmit` and the new test pass.

shipped production is serving it deploy 2fa0c24

opened this

This adds src/checks/restack.ts and test/checks-restack.test.ts, which plan a red batch's re-gate as plain data. The queue is not touched. bun x tsc --noEmit and the new test pass.

The 8-pull test does not meet the "at most 2 rounds" criterion. Driven by the function alone, 8 pulls with one bad pull land all 7 good ones, but it takes 3 rounds when the bad pull is last. Other positions take more. Each half step lands at most half of what remains, so no function with this contract can finish in 2. The tests assert that the 7 good pulls land for every bad position and that the loop ends. For the bad pull last, they assert exactly 3 rounds. Say if you want the 2-round bound relaxed or the contract changed.

  • restack(pulls) works on any item type.

- N = 1 returns {kind: "alone"}, red alone on main. - N ≥ 2 returns {kind: "halves", first, second}. first is the first ⌈N/2⌉ pulls on main. second is all N, stacked on first. - An empty batch throws.

  • afterVerdicts(plan, firstGreen, secondGreen) returns {land, regate, culprit?}:

- Both green: all N land in order and nothing is re-gated. - First green, second red: the first half lands and the remaining pulls are re-gated. - First red: nothing lands and the first half is searched again. The second verdict is void. - N = 1: green lands the pull. Red names it as the culprit.

The tests cover N = 1, 2, 7 and 8, every verdict pair, and a driver loop over all eight bad-pull positions.

Not done, as the issue says: wiring into the queue.

Closes #6533

commented

This adds src/checks/restack.ts and test/checks-restack.test.ts, which plan a red batch's re-gate as plain data. The queue is not touched. bun x tsc --noEmit and the new test pass.

The 8-pull test does not meet the "at most 2 rounds" criterion. Driven by the function alone, 8 pulls with one bad pull land all 7 good ones, but it takes 3 rounds when the bad pull is last. Other positions take more. Each half step lands at most half of what remains, so no function with this contract can finish in 2. The tests assert that the 7 good pulls land for every bad position and that the loop ends. For the bad pull last, they assert exactly 3 rounds. Say if you want the 2-round bound relaxed or the contract changed.

  • restack(pulls) works on any item type.

- N = 1 returns {kind: "alone"}, red alone on main. - N ≥ 2 returns {kind: "halves", first, second}. first is the first ⌈N/2⌉ pulls on main. second is all N, stacked on first. - An empty batch throws.

  • afterVerdicts(plan, firstGreen, secondGreen) returns {land, regate, culprit?}:

- Both green: all N land in order and nothing is re-gated. - First green, second red: the first half lands and the remaining pulls are re-gated. - First red: nothing lands and the first half is searched again. The second verdict is void. - N = 1: green lands the pull. Red names it as the culprit.

The tests cover N = 1, 2, 7 and 8, every verdict pair, and a driver loop over all eight bad-pull positions.

Not done, as the issue says: wiring into the queue.

Approved

A pure, dependency-free planner with no I/O, so none of the security, terminal or page-parity checks apply. The tests are meaningful: every verdict pair, N=1/2/7/8, an input-mutation check, and a driver over all eight bad-pull positions. The "at most 2 rounds" criterion is honestly reported as unmeetable, and the pull states what it asserts in its place. I did not try the preview: the change adds no page or route.

Two things I would do next:

  1. Name the held pulls in Outcome. When the first half is red, the second half is neither landed nor re-gated, so the caller has to work it out by set difference, as the driver test does. A held field would stop the queue wiring from losing pulls.
  2. Wire it into the queue (the next pull in #6001's bisect-in-halves lever), so the function is reachable. Fold the last test into the driver loop at that point, since it duplicates the bad=8 case.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs