Files
alan 2c105074aa feat(app): add graph domain model for runs and definitions
Pure-Dart graph foundation mirroring the current web client:
terminal targets and labels, definition edges and nodes with web
outcome ordering, recorded run evidence (visited stages, taken
routes, current stage and live start), and sequence-ordered stage
visit selection with clamping.

No layout, widgets, screens or coordinates; fixtures cover linear,
diamond, self-loop, repeated visits, mixed outcomes, terminals and
missing/malformed evidence.
2026-10-21 15:31:43 +01:00

44 lines
1.6 KiB
Dart

/// Protocol terminal targets and the labels the graph uses for them.
///
/// Mirrors `web/src/protocol.js` (`SUCCESS_END`, `FAILURE_END`,
/// `isTerminal`, `resolveTarget`) and the label helpers in `web/src/graph.js`.
/// Pure Dart: no Flutter imports and no layout or rendering decisions.
library;
/// The explicit success terminal (`Protocol.SUCCESS_END`).
const String successEnd = '#success';
/// The explicit failure terminal (`Protocol.FAILURE_END`).
const String failureEnd = '#failure';
/// True only for the two explicit terminal targets.
///
/// A bare `#` is not itself terminal; [resolveTarget] turns it into one using
/// the outcome, exactly as the server and the web client do.
bool isTerminalTarget(String? target) =>
target == successEnd || target == failureEnd;
/// Mirrors `Protocol.resolveTarget`: a bare `#` is the outcome's terminal.
///
/// Every other value is preserved verbatim, including an empty or unknown
/// stage key. A missing target stays null rather than becoming a terminal, so
/// a blank edge cannot fabricate a visit or a terminal node.
String? resolveTarget(String? outcome, String? target) {
if (target != '#') return target;
return outcome == 'error' ? failureEnd : successEnd;
}
/// A graph node title: a stage keeps its key, a terminal reads Success/Failure.
String nodeDisplayLabel(String? key) {
if (key == successEnd) return 'Success';
if (key == failureEnd) return 'Failure';
return key ?? '';
}
/// The TUI-mirroring label: terminal targets are all caps.
String nodeLabel(String? key) {
if (key == successEnd) return 'SUCCESS';
if (key == failureEnd) return 'FAILURE';
return key ?? '';
}