Skip to content

fix: restore step toggle, run rename, delete, and print - #97

Merged
keyurgolani merged 9 commits into
nextfrom
fix/09.1-slice-0
Oct 20, 2026
Merged

keyurgolani merged 9 commits into
nextfrom
fix/09.1-slice-0

Conversation

@keyurgolani

@keyurgolani keyurgolani commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Implements CHECKMATE-09.1 · slice 0
Refs #53

Since c53d6ea, getById returns Result<Instance>, but the toggle route, GET, PUT, and DELETE /api/checklists/[id], and the run print page still read .data.checklist off it. The owner got 404 or notFound() from all five. The run page only logged the toggle's 404, and the tracker announced "marked as complete" anyway.

  1. All five read the run from .data, so toggle, rename, delete, and print work for the owner again. The print page finds the template title the way the run page does, which drops its @ts-ignore and any casts.
  2. A failed step toggle shows "Couldn't mark this step complete." with Retry under the step and announces nothing. The run page rejects when the route fails or answers without the step, and resolves with the state the server confirmed. The tracker announces only that state. A failed toggle logs one console.error with the step id and status, never step content.
  3. The error stays until a retry is confirmed. If the step reaches that state through realtime or the bulk bar, the tracker drops the error for good, so it can't come back. A toggle that fails after realtime already showed its step saved records no error, and the next toggle of a failed step always retries what that toggle aimed for, so Retry can't flip a step against its label. Retry is a 44px target, keeps focus while it runs, hands focus back to the step when it succeeds, and does nothing during selection.
  4. A toggle can save the step and then fail on the run's progress write. The next toggle of a failed step reads the saved step first and confirms it without flipping when it's already there. The run's progress stays stale after that partial write until SetStepState makes the step and progress one transaction.
  5. CHANGELOG.md records both fixes.

Decisions:

  1. Stacked on fix: remove the run sync stub and its success-shaped UI #96 ([CHECKMATE-07.3] Replace sync stubs with dry-run and apply upgrade plans #49 stub removal). Both change the same lines in src/app/api/checklists/[id]/route.ts, and [CHECKMATE-09.1] Redesign run execution around one focused next step #53 lets stub removal merge first. This needs a rebase onto next once fix: remove the run sync stub and its success-shaped UI #96 merges.
  2. The context menu's Mark Complete called the toggle directly, so its failures were silent too. The tracker now adds that entry itself and sends it through the same path as the checkbox. The bulk bar is SetStepState's and is unchanged.
  3. Another user's run now gets the same 404 body from PUT, DELETE, and the toggle that GET and a missing run get, instead of 403. That's [CHECKMATE-01.2] Specify command and projection authority for every actor type #30's concealing NOT_FOUND.
  4. Per the slice 0 criterion, a failure announces nothing. The message is the description of the step's checkbox and label, so a screen reader reads it there. [CHECKMATE-21.3] Standardize truthful async, stale, degraded, conflict, and recovery states #91's InlineError adds the one announcement through [CHECKMATE-21.1] Define shared responsive, focus, target-size, and motion primitives #89's announcer.

Testing

Test plan item 1 is node tests for the toggle route, GET, PUT, DELETE, and the print page, on #96's structural PocketBase fake with @/lib/server-auth mocked. Item 2 is checklist-tracker.test.ts (jsdom, React.createElement, @testing-library/react). I added checklist-detail-client.test.ts too, because a tracker test can't catch a run page that swallows the failure, which is the 9019d17 bug. It also covers the log line and both retry reads.

Against a clean 9019d17 checkout, 16 of the 24 new tests fail, covering every owner case and every failure, retry, and menu case. The 8 that pass are the another-user and missing-run 404 checks, since everything answered 404 then, and the two confirmed-announcement cases. The last commit adds two tracker tests, one for the retry target and one for a failure that arrives after realtime already showed the step saved. The second fails on the commit before it.

Gate on the rebased branch, against next with the gate A fixture:

  1. Changed files lint clean through scripts/ci/lint-changed.mjs, with no new eslint-disable. The rebase onto fix: remove the run sync stub and its success-shaped UI #96 and gate A brings the repo to fewer lint errors than next, since the touched route files drop their as any casts.
  2. npx tsc --noEmit: 0 errors.
  3. npm test: 28 files, 316 tests pass on the PocketBase fixture.
  4. npm run build with both PocketBase URLs on 127.0.0.1:9 passes.

I also rendered the tracker in next dev with a toggle that always fails. The error and Retry show under the step from the checkbox, the label, and the context menu, both live regions stay empty, Retry measures 52x44, and nothing overflows at 390px.

No migration or events. The run page looks the same until a toggle fails, so the SHOWCASE.md run section and screenshot still match. Rollback is a revert.

No owner steps.

Summary by Sourcery

Restore reliable owner run operations and make failed step toggles recoverable without misleading announcements.

Bug Fixes:

  • Restore owner access to step toggling, run retrieval, renaming, deletion, and printing after the checklist service result shape changed.
  • Ensure failed step toggles show an inline Retry action, announce only server-confirmed state changes, and handle partial saves and realtime updates safely.
  • Return concealed 404 responses for unauthorized run access consistently across run operations.

Enhancements:

  • Route context-menu step actions through the same toggle handling as checkboxes, including retry and accessibility behavior.
  • Simplify print-page blueprint title handling and remove obsolete type workarounds.

Documentation:

  • Document the restored run operations and failed-toggle behavior in the changelog.

Tests:

  • Add route, print-page, run-page, tracker, retry, accessibility, and partial-save coverage using shared PocketBase fixtures.

@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Sorry @keyurgolani, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 7 days by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Restores owner access to run toggle, rename, delete, and print flows by adapting callers to the service’s Result<Instance> shape, adds robust inline failure/retry behavior with confirmed-state announcements, and removes the obsolete template-sync feature and isSynced application metadata with extensive route, UI, and fixture-based tests.

Sequence diagram for confirmed step toggle and retry

sequenceDiagram
    actor User
    participant Tracker as ChecklistTracker
    participant Detail as ChecklistDetailClient
    participant API as Toggle route
    participant Service as ChecklistService

    User->>Tracker: Toggle step
    Tracker->>Detail: onToggleTask(stepId)
    Detail->>API: PUT /api/checklists/run-1/items/step-1/toggle
    API->>Service: getById(runId)
    Service-->>API: Result<Instance>
    API->>Service: toggleTaskCompletion(runId, stepId)
    Service-->>API: task and progress
    API-->>Detail: 200 confirmed step state
    Detail-->>Tracker: ToggleConfirmation
    Tracker-->>User: Announce confirmed state

    alt Toggle fails
        API-->>Detail: 404 or non-OK response
        Detail-->>Tracker: Reject
        Tracker-->>User: Show inline error and Retry
        User->>Tracker: Retry
        Tracker->>Detail: onToggleTask(stepId)
    end
Loading

Flow diagram for concealed run access and removed sync

flowchart TD
    Request[Authenticated run request] --> Lookup[ChecklistService.getById]
    Lookup --> Found{Run found and owned?}
    Found -->|Yes| Operation[Perform GET, PUT, DELETE, or toggle]
    Found -->|No| NotFound[404 Checklist not found]

    Sync[Signed-in sync request] --> Gone[410 RUN_SYNC_REMOVED]
    Anonymous[Anonymous sync request] --> Auth[401 Authentication required]
Loading

File-Level Changes

Change Details Files
Restore owner access to run operations after the service result shape changed.
  • Read checklist instances directly from Result<Instance>.data in the toggle and run CRUD routes.
  • Update the print page to use the instance data and typed blueprint expansion/fallback lookup.
  • Conceal another user’s run with the same 404 response used for missing runs.
  • Add route and print-page coverage for owner success, missing runs, and unauthorized-run behavior.
src/app/api/checklists/[id]/items/[itemId]/toggle/route.ts
src/app/api/checklists/[id]/route.ts
src/app/(print)/checklists/[id]/print/page.tsx
src/app/api/checklists/[id]/items/[itemId]/toggle/route.test.ts
src/app/api/checklists/[id]/route.test.ts
src/app/(print)/checklists/[id]/print/page.test.ts
Make step-toggle failures visible, retryable, and accurately announced.
  • Return the server-confirmed completion state from the run page and reject failed or malformed responses.
  • Track failed toggles in the tracker, render an inline error with Retry, and announce only confirmed state changes.
  • Route context-menu toggles through the same checkbox path; clear errors on confirmed retries or external state updates.
  • Preserve focus across retry, provide a 44px retry target, and disable retry during selection.
  • Add jsdom coverage for failure, retry, announcements, focus, external updates, and menu behavior.
src/app/(dashboard)/checklists/[id]/checklist-detail-client.tsx
src/components/checklists/checklist-tracker.tsx
src/app/(dashboard)/checklists/[id]/checklist-detail-client.test.ts
src/components/checklists/checklist-tracker.test.ts
Remove the nonfunctional template-sync feature and its legacy run metadata.
  • Replace the sync endpoint with a signed-in 410 RUN_SYNC_REMOVED response while retaining proxy-level anonymous 401 behavior.
  • Remove sync actions, menu entries, service implementation/types, seed writes, API fields, badges, and generated checklist metadata.
  • Retain the database column for a later migration and update related tests and changelog documentation.
  • Add an inventory test ensuring removed sync concepts do not remain in application code.
src/app/api/checklists/[id]/sync/route.ts
src/app/api/checklists/[id]/sync/route.test.ts
src/lib/services/checklist.ts
src/lib/pocketbase-types.ts
src/app/(dashboard)/checklists/actions.ts
src/app/(dashboard)/checklists/checklist-list-client.tsx
src/app/(dashboard)/dashboard/dashboard-view.tsx
src/app/(dashboard)/checklists/checklist-card.tsx
src/app/(dashboard)/checklists/page.tsx
src/app/(dashboard)/checklists/[id]/page.tsx
src/app/(dashboard)/workspaces/[id]/page.tsx
src/app/api/checklists/route.ts
src/app/api/checklists/[id]/route.ts
scripts/seed-data.ts
src/test/backend-verification.test.ts
src/test/generators.ts
src/test/integration.test.ts
CHANGELOG.md
Add reusable structural test fixtures for route and service verification without PocketBase.
  • Implement an in-memory PocketBase fake with call/write tracking and supported filtering/sorting.
  • Provide reusable owner/other-user run fixtures for API and print-page tests.
  • Reduce unsafe casts and update integration typing while preserving existing schema and build behavior.
src/test/fake-pocketbase.ts
src/test/run-fixture.ts
src/app/api/checklists/route.ts
src/app/api/checklists/[id]/route.ts
src/app/api/checklists/[id]/items/[itemId]/toggle/route.ts
src/app/api/checklists/route.ts
src/test/integration.test.ts

Possibly linked issues

  • #CHECKMATE-09.1: Link: the PR implements slice 0 by fixing the specified run and print reads and showing Retry without false completion announcements.
  • #CHECKMATE-09: The PR directly implements the epic’s planned 09.1 slice 0, fixing run operations and toggle feedback; it also removes the prerequisite sync stub.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@keyurgolani
keyurgolani force-pushed the fix/09.1-slice-0 branch 2 times, most recently from cd80f49 to 2fa1f20 Compare October 20, 2026 10:44
Node tests on the structural PocketBase fake, with server-auth mocked,
for the toggle route, GET, PUT, and DELETE /api/checklists/[id], and the
run print page. At 9019d17 each reads .data.checklist off getById's
Result<Instance>, so the owner gets 404 or notFound.

A jsdom tracker test: a failed toggle must show an inline error with
Retry and announce nothing, and only a confirmed change is announced.
At 9019d17 the tracker announces "marked as complete" for a toggle that
was never confirmed and shows nothing when one fails.
A jsdom test of the run page with fetch answering 404. At 9019d17 the
page logs the failure and the tracker still announces "marked as
complete", with no Retry.
getById returns Result<Instance>, but the toggle route, GET, PUT, and
DELETE /api/checklists/[id], and the run print page read .data.checklist
off it, so the owner got 404 or notFound in every image since c53d6ea.
Read the run from .data. The print page now resolves the template title
the way the run page does, which drops its ts-ignore and any casts.

A failed step toggle now shows an inline error with Retry under the step
and announces nothing. The run page rejects when the route fails or
answers without the step, and resolves with the state the server
confirmed. The tracker announces only that confirmed state and keeps
the error until a retry succeeds.

The run page's context menu called the toggle directly, so its failures
were silent. The tracker now adds Mark Complete itself and sends it
through the same path as the checkbox.
The theme sets a 14px root font, so rem sizing left Retry 39px tall.
Use pixel minimums. Point the step's aria-describedby at the error
message alone, so screen readers don't read the Retry label twice.
… toggle

GET already answers 404 for a run the caller doesn't own. PUT, DELETE,
and the step toggle now give the same 404 body as a missing run instead
of 403, matching the concealing NOT_FOUND in #30.
Drop a failure once the step reaches the state it was aiming for some
other way, such as a realtime update or the bulk bar, so Retry can't
flip the step the opposite way from its label. Retry stays focusable
while it runs and hands focus back to the step when the retry is
confirmed. It sends nothing while steps are being selected.
…ilures

The tracker hid a failure once its step reached the target state some
other way but kept the entry, so a later uncheck brought the same error
and Retry back. Prune entries during render whenever the steps change:
when the step reaches its target state or leaves the run.

A toggle can save the step and then fail on the run's progress. The next
toggle of a failed step now passes the state it aims for, and the run
page reads the saved step first. When the step is already there, the
page confirms it without sending another flip. The progress write itself
stays as it is until SetStepState.

Log one console.error per failed toggle with the step id and response
status only, never step content.
The next toggle after a failure now retries the state that failure aimed
for, instead of the opposite of what the step shows. A toggle that fails
after a realtime update already saved its step records no failure, so a
checked step can't show a stale error whose Retry would uncheck it.
@keyurgolani
keyurgolani merged commit cfcd9ae into next Oct 20, 2026
10 checks passed
@keyurgolani
keyurgolani deleted the fix/09.1-slice-0 branch October 20, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant