Engine: check stages, harness-agnostic delivery, read-only enforcement, complete captures

- New `type=check` stage: the server runs a `commands` block (sh -c, per
  command_timeout, workspace env) and routes on pass/fail; per-command status,
  exit code, duration and bounded output are recorded and the failing output is
  the handoff. With delivery=true it is the landing gate (commit leftovers,
  merge moved main, checks in a fresh candidate worktree, fast-forward main).
  Parser/registry, lint (silent guards), format docs, CLI inspect, app graph and
  run detail rendering.
- delivery=true is accepted on every harness (and on check stages).
- permissions.shell on claude stages maps to Bash(cmd) / Bash(prefix:*) rules
  instead of a bare Bash allow; stages without edit that change the workspace
  fail the visit with the changed files listed (allow_workspace_changes=true
  opts out; artifacts, public and harness state dirs are ignored).
- File-change capture: symlinks compared by target, untouched protected files no
  longer make captures partial, untracked caches/dependency/build output left
  out, lockfiles listed without patch, huge files compared by metadata, raised
  patch/line limits. Outcome repair follow-ups are logged and counted on the
  step (control.outcome_repairs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:52:16 +00:00
parent c4de1de27b
commit 87016ef5dc
47 changed files with 2674 additions and 129 deletions
@@ -13,7 +13,7 @@ const _expected = {
'budget':
'The workspace snapshot ran out of text budget, so no diff text was '
'recorded.',
'lines': 'The change is over 5,000 lines, so no diff text was recorded.',
'lines': 'The change is over 20,000 lines, so no diff text was recorded.',
'evidence_size':
"This visit's recorded changes reached their size limit, so this patch "
'was dropped.',
@@ -24,6 +24,15 @@ const _expected = {
"The file's content at stage start couldn't be recovered from Git, so no "
'diff was recorded.',
'binary': 'Binary file; only its metadata was recorded.',
'symlink': 'Symbolic link; only the change to its target was recorded.',
'protected':
'A protected file (secrets, credentials or a database); its content is '
'never read, only that it changed.',
'generated':
'A lockfile, minified or generated file; it is listed without a diff.',
'large':
'This file is too large to hash, so it was compared by size and '
'modification time only.',
};
FileChange _noPatch(Object? reason, {bool binary = false}) =>
@@ -0,0 +1,80 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/check_stage.dart';
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
import 'package:pipelines_app/features/graph/domain/stage_definition.dart';
Map<String, dynamic> _verify({Map<String, dynamic>? configs}) => {
'key': 'verify',
'type': 'check',
'configs':
configs ??
{
'command_timeout': '15m',
'timeout': '1h',
'keep_going': 'true',
'delivery': 'true',
},
'edges': {'pass': 'review', 'fail': 'implement', 'error': '#failure'},
'blocks': {'commands': 'go vet ./...\n\ngo test ./...\n'},
'prompt': '',
'output': '',
};
void main() {
test('a check stage reads its commands, one per non-blank line', () {
expect(isCheckStage(_verify()), isTrue);
expect(checkCommands(_verify()), ['go vet ./...', 'go test ./...']);
expect(isCheckStage({'type': 'model'}), isFalse);
expect(isCheckStage({'key': 'x'}), isFalse);
});
test('the delivery config marks the gate, and only on a check stage', () {
expect(isDeliveryGate(_verify()), isTrue);
expect(isDeliveryGate(_verify(configs: {'delivery': 'false'})), isFalse);
expect(isDeliveryGate(_verify(configs: {})), isFalse);
expect(
isDeliveryGate({
'type': 'model',
'configs': {'delivery': 'true'},
}),
isFalse,
);
});
test('graph nodes carry the stage type and the gate caption', () {
final nodes = graphNodes({
'stages': [
_verify(),
{
..._verify(configs: {}),
'key': 'lint',
},
{
'key': 'review',
'edges': {'success': '#'},
},
],
});
final byKey = {for (final node in nodes) node.key: node};
expect(byKey['verify']!.kindCaption, 'Delivery gate');
expect(byKey['lint']!.kindCaption, 'Check');
expect(byKey['review']!.kindCaption, isNull);
expect(byKey['#success']!.kindCaption, isNull);
});
test('a check definition lists its commands in place of a prompt', () {
final fields = stageDefinitionFields(_verify());
final byLabel = {for (final field in fields) field.label: field};
expect(byLabel['Type']!.value, 'check (delivery gate)');
final commands = byLabel['Commands']!;
expect(commands.value, 'go vet ./...\ngo test ./...');
expect(commands.monospace, isTrue);
expect(byLabel.containsKey('Prompt'), isFalse);
expect(byLabel['Command timeout']!.value, '15m');
expect(byLabel['Keep going']!.value, 'true');
expect(byLabel['Delivery gate']!.value, 'true');
expect(byLabel['Outcomes']!.value, contains('pass → review'));
expect(byLabel['Outcomes']!.value, contains('fail → implement'));
});
}
@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
Map<String, dynamic> _graph() => {
'stages': [
{
'key': 'verify',
'type': 'check',
'configs': {'delivery': 'true'},
'edges': {'pass': '#', 'fail': 'fix'},
'blocks': {'commands': 'go vet ./...\ngo test ./...'},
},
{
'key': 'fix',
'type': 'model',
'prompt': 'Fix it.',
'edges': {'success': 'verify'},
},
],
};
Widget _host(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)),
);
void main() {
testWidgets('a check node shows its kind under its name', (tester) async {
final nodes = {for (final node in graphNodes(_graph())) node.key: node};
await tester.pumpWidget(
_host(
Column(
mainAxisSize: MainAxisSize.min,
children: [
GraphStageNode(node: nodes['verify']!, onSelected: (_) {}),
GraphStageNode(node: nodes['fix']!, onSelected: (_) {}),
],
),
),
);
expect(find.byKey(const ValueKey('graph-node-kind-verify')), findsOne);
expect(find.byKey(const ValueKey('graph-node-kind-fix')), findsNothing);
expect(find.text('Delivery gate'), findsOne);
expect(find.byIcon(Icons.verified_outlined), findsOne);
expect(find.bySemanticsLabel('verify\nDelivery gate'), findsOne);
expect(find.bySemanticsLabel('fix'), findsOne);
expect(tester.takeException(), isNull);
});
testWidgets('a check definition lists its commands in monospace', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: StageDefinitionView(
graph: _graph(),
stageKey: 'verify',
pipelineId: 1,
pipelineName: 'Demo',
version: 3,
),
),
),
);
final commands = tester.widget<SelectableText>(
find.descendant(
of: find.byKey(const ValueKey('stage-definition-Commands')),
matching: find.byType(SelectableText),
),
);
expect(commands.data, 'go vet ./...\ngo test ./...');
expect(commands.style?.fontFamily, appMonospaceFamily);
expect(find.text('check (delivery gate)'), findsOne);
expect(find.text('Prompt'), findsNothing);
});
}
@@ -0,0 +1,77 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/domain/check_step_output.dart';
void main() {
test('a check output reads each command result', () {
final output = checkStepOutput({
'markdown': '# outcome\n\nfail\n',
'summary': '1 of 2 checks failed: go test ./...',
'delivery': true,
'checks': [
{
'command': 'go vet ./...',
'status': 'passed',
'exit_code': 0,
'duration_ms': 2100,
'output': '',
'truncated': false,
},
{
'command': 'go test ./...',
'status': 'failed',
'exit_code': 1,
'duration_ms': 51000,
'output': '--- FAIL',
'truncated': true,
},
{'command': 'make lint', 'status': 'not_run'},
'not a map',
],
})!;
expect(output.delivery, isTrue);
expect(output.summary, '1 of 2 checks failed: go test ./...');
expect(output.markdown, startsWith('# outcome'));
expect(output.checks, hasLength(3));
final [vet, test, lint] = output.checks;
expect(vet.status, CheckCommandStatus.passed);
expect(vet.meta, 'exit 0 · 2.1s');
expect(test.status, CheckCommandStatus.failed);
expect(test.meta, 'exit 1 · 51s');
expect(test.truncated, isTrue);
expect(lint.status, CheckCommandStatus.notRun);
expect(lint.meta, '');
expect(checkStatusLabel(lint), 'Not run');
});
test('statuses this client does not know keep their own word', () {
final output = checkStepOutput({
'checks': [
{'command': 'x', 'status': 'skipped_by_policy'},
{'command': 'y'},
{'command': 'z', 'status': 'timed_out'},
],
})!;
expect(output.checks[0].status, CheckCommandStatus.unknown);
expect(checkStatusLabel(output.checks[0]), 'skipped_by_policy');
expect(checkStatusLabel(output.checks[1]), 'Unknown status');
expect(checkStatusLabel(output.checks[2]), 'Timed out');
expect(output.delivery, isFalse);
});
test('outputs without a checks list are not check outputs', () {
expect(checkStepOutput(null), isNull);
expect(checkStepOutput('text'), isNull);
expect(checkStepOutput({'markdown': '# outcome'}), isNull);
expect(checkStepOutput({'checks': 'go test'}), isNull);
});
test('durations read compactly', () {
expect(formatCheckDuration(850), '850ms');
expect(formatCheckDuration(2000), '2s');
expect(formatCheckDuration(2100), '2.1s');
expect(formatCheckDuration(51000), '51s');
expect(formatCheckDuration(185000), '3m 05s');
expect(formatCheckDuration(3720000), '1h 02m');
});
}
@@ -0,0 +1,141 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/ui/run_check_output_view.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
import 'run_detail_graph_support.dart';
import 'run_detail_visit_support.dart';
/// verify (a delivery check) -> review, with one failed check visit.
JsonMap _checkRun({int repairs = 0}) => <String, dynamic>{
'id': 78,
'title': 'Check run',
'name': 'release',
'pipeline_id': 7,
'version': 4,
'status': 'succeeded',
'graph': <String, dynamic>{
'stages': <dynamic>[
<String, dynamic>{
'key': 'verify',
'type': 'check',
'configs': <String, dynamic>{'delivery': 'true'},
'edges': <String, String?>{'pass': '#', 'fail': 'verify'},
'blocks': <String, dynamic>{'commands': 'go vet ./...\ngo test ./...'},
},
],
},
'steps': <dynamic>[
<String, dynamic>{
'stage': 'verify',
'sequence': 1,
'status': 'completed',
'outcome': 'fail',
'target': 'verify',
'started_at': '2026-10-22T00:00:00Z',
'finished_at': '2026-10-22T00:01:00Z',
if (repairs > 0)
'control': <String, dynamic>{'visit': 1, 'outcome_repairs': repairs},
'output': <String, dynamic>{
'markdown': '# outcome\n\nfail\n\n# handoff\n\nFix the test.',
'summary': '1 of 2 checks failed: go test ./...',
'delivery': true,
'checks': <dynamic>[
<String, dynamic>{
'command': 'go vet ./...',
'status': 'passed',
'exit_code': 0,
'duration_ms': 2100,
'output': 'vet ok',
'truncated': false,
},
<String, dynamic>{
'command': 'go test ./...',
'status': 'failed',
'exit_code': 1,
'duration_ms': 51000,
'output': '--- FAIL: TestX',
'truncated': true,
},
],
},
},
],
};
void main() {
const platform = RunDetailTestPlatform.material;
testWidgets('a check visit shows one row per command with its output', (
tester,
) async {
await openVisit(tester, platform, run: _checkRun());
expect(find.byKey(const Key('run-check-output')), findsOneWidget);
expect(find.byKey(const Key('run-check-delivery')), findsOneWidget);
expect(find.text('1 of 2 checks failed: go test ./...'), findsOneWidget);
expect(find.text('go vet ./...'), findsOneWidget);
expect(find.text('Passed · exit 0 · 2.1s'), findsOneWidget);
expect(find.text('Failed · exit 1 · 51s'), findsOneWidget);
// The raw checks list is never shown as a `key=value` field dump.
expect(find.text('checks'), findsNothing);
// Output is collapsed until the row is expanded; then it is selectable
// monospace with the truncation note.
expect(find.text('--- FAIL: TestX'), findsNothing);
final row = find.byKey(const ValueKey('run-check-command-1'));
await tester.ensureVisible(row);
await tester.tap(find.text('go test ./...'));
await tester.pumpAndSettle();
final output = tester.widget<SelectableText>(
find.widgetWithText(SelectableText, '--- FAIL: TestX'),
);
expect(output.style?.fontFamily, appMonospaceFamily);
expect(find.text(checkOutputTruncated), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('a check visit has no model row and an honest session note', (
tester,
) async {
await openVisit(tester, platform, run: _checkRun());
expect(find.text('Provider/model'), findsNothing);
expect(find.text('fail'), findsWidgets);
await openVisitTab(tester, RunVisitSection.session);
expect(find.text(visitSessionCheck), findsOneWidget);
expect(find.text(visitSessionNoIdentity), findsNothing);
});
testWidgets('a repaired outcome is noted on the visit', (tester) async {
await openVisit(tester, platform, run: _checkRun(repairs: 1));
expect(find.byKey(const Key('run-visit-outcome-repaired')), findsOne);
expect(find.text('Outcome repaired by follow-up'), findsOneWidget);
});
testWidgets('an unrepaired visit shows no repair note', (tester) async {
await openVisit(tester, platform, run: _checkRun());
expect(find.byKey(const Key('run-visit-outcome-repaired')), findsNothing);
});
test('outcome repairs read from control, absent meaning none', () {
expect(detailVisitOutcomeRepairs({}), 0);
expect(detailVisitOutcomeRepairs({'control': 'x'}), 0);
expect(
detailVisitOutcomeRepairs({
'control': {'visit': 2},
}),
0,
);
expect(
detailVisitOutcomeRepairs({
'control': {'outcome_repairs': 2},
}),
2,
);
expect(outcomeRepairNote(2), 'Outcome repaired by follow-up (2 times)');
});
}