Files
pipelines/app/lib/features/runs/actions/cancel_eligibility.dart
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

32 lines
1.1 KiB
Dart

import '../../../core/api_gateway.dart';
/// Whether the operator may cancel [run], matching `canCancel` in
/// `web/src/actions.js` exactly:
///
/// `(executing || (status == "waiting" && export_pending_sequence > 0)) &&
/// !cancel_requested && !cleanup_unconfirmed`
///
/// The status word alone is not enough: a stale `running` status without
/// `executing` is not cancellable, while a run waiting on a pending session
/// export is.
bool canCancelRun(JsonMap? run) {
if (run == null) return false;
final exportPending = _number(run['export_pending_sequence']);
return (run['executing'] == true ||
(run['status'] == 'waiting' && exportPending > 0)) &&
run['cancel_requested'] != true &&
run['cleanup_unconfirmed'] != true;
}
/// The run id used by the cancel request, or null for a malformed run.
num? cancelRunId(JsonMap run) {
final id = run['id'];
return id is num ? id : null;
}
/// `Number(value) > 0`, tolerating numeric strings as the browser does.
double _number(dynamic value) {
if (value is num) return value.toDouble();
return double.tryParse('${value ?? ''}'.trim()) ?? 0;
}