Files
pipelines/app/notes/R2b.md
T
alan faa5866410 feat(app): add deliberate run cancellation action
Port the browser's canCancel rule and cancel_run request into a native
Material/Cupertino confirmation. Opening the prompt or choosing Keep sends
nothing; a refusal stays visible with the server's words and the run is
re-read so the owner always receives server truth. Includes eligibility,
double-submit, disposal and narrow 2x-text tests plus R2b evidence.
2026-10-21 14:41:33 +01:00

97 lines
5.0 KiB
Markdown

# R2b — native run cancellation
## What changed
New `lib/features/runs/actions/cancel*` slice plus its tests. No existing source
file was edited.
| File | Lines | Responsibility |
| --- | --- | --- |
| `lib/features/runs/actions/cancel_eligibility.dart` | 31 | Web-exact `canCancelRun`, run-id extraction, numeric export counter |
| `lib/features/runs/actions/cancel_wording.dart` | 23 | Web-verbatim words, dialog title, error text, test keys |
| `lib/features/runs/actions/cancel_dialog.dart` | 145 | Native Material/Cupertino confirmation and inline refusal |
| `lib/features/runs/actions/cancel_run_action.dart` | 101 | `CancelRunAction`, gating, send/refusal/resync orchestration |
| `test/features/runs/actions/cancel_test_support.dart` | 101 | Fake gateway, run fixtures, stateful host, app wrappers |
| `test/features/runs/actions/cancel_action_test.dart` | 192 | Eligibility and both-platform deliberate-confirm flows |
| `test/features/runs/actions/cancel_resilience_test.dart` | 176 | Refusal/resync, resync failure, double submit, disposal, 2x/narrow |
`CancelRunAction` takes the run, the shared `ApiGateway` and an
`onRunChanged` callback. It renders one native `FilledButton` (`Cancel run`) on
Material and one `CupertinoButton.filled` on Cupertino, and nothing at all when
the browser rule says the run is not cancellable. Platform style follows the
enclosing app (`MaterialLocalizations` presence); no extra style parameter or
dependency was added.
## Behaviour
Eligibility is a direct port of `canCancel` in `../web/src/actions.js`:
```
(executing || (status == "waiting" && export_pending_sequence > 0))
&& !cancel_requested && !cleanup_unconfirmed
```
A run with a stale `running` status but `executing == false` is therefore not
cancellable, while a `waiting` run with a pending session export is. A run
without a numeric `id` is not offered because the request cannot be addressed
(the pure eligibility function still matches the web rule exactly).
Opening the prompt sends nothing and `Keep` only closes it. The prompt uses the
web wording (`Cancel run {id}?`, `This asks the server to stop the active run.`,
`Cancel run`, `Keep`). Only the confirm action calls
`RunsRepository.cancelRun(id)`, which sends the exact envelope
`cancel_run {"run_id": id}`.
Both the dialog and the action guard the in-flight state: a second confirm tap
or a `Keep` tap while sending is ignored, and the dialog's actions are disabled
until the reply arrives. A successful reply closes the prompt and passes the
server's returned `run_detail` to `onRunChanged`; no local status is invented.
A refusal keeps the prompt open and shows the server's message verbatim. The
action then calls `RunsRepository.getRun(id)` and passes the refreshed run to
`onRunChanged`, so the owner sees server truth (for example the run finished
before cancellation). If the re-read also fails, the original refusal stays
visible and no synthetic run is delivered. Every asynchronous resume checks
`mounted` before `setState` or `onRunChanged`, so a late reply after disposal is
ignored.
## Checks actually run
```
flutter pub get # dependencies resolved
dart format lib/features/runs/actions/cancel*.dart \
test/features/runs/actions/cancel*.dart # clean
flutter analyze # No issues found!
flutter test test/features/runs/actions # 16 passed
flutter test # 45 passed
flutter build web # Built build/web (15.5s)
```
Focused coverage maps to the requested acceptance:
- eligibility: executing, export-wait, waiting without export, stale `running`
without `executing`, already stopping, cleanup unconfirmed, finished/failed;
plus widget visibility for the same states;
- both platforms: native prompt opens, nothing is sent on open or `Keep`, exact
`cancel_run` envelope, callback receives the returned run, action disappears;
- refusal: cancellation error shown verbatim, `get_run` resync delivered to the
owner, and a failed resync leaves the refusal visible with no callback;
- double submit: two confirm taps produce one `cancel_run`, both actions disable;
- stale disposal: a reply after the tree is replaced causes no exception and no
callback;
- 320x480 at 2x text: both prompts open with no rendering exception.
## Honest limits
- **Not wired into a run-detail screen.** This branch has no run-detail screen
or controller; the manager owns integration. There is therefore no real
browser interaction or capture for this widget. `flutter build web` proves
compilation only, not rendered behavior, and no visible feature is claimed.
- **Mobile unverified.** No Android/iOS build, emulator, ADB or device was used.
Source uses only portable Flutter/Cupertino/Material widgets.
- No real server or run was mutated. Tests use a local fake gateway with no
socket.
- No controller/screen/main/domain/repository/pubspec, `web/`, Go server,
installer or deployment file was changed. Nothing was committed, pushed or
deployed.