0791a4702d
The Artifacts badge counted every recorded turn document (input, memory, output, session.html) while the tab lists only deliverables, so a run whose visits recorded only debugging files (the Caplens ticket runs) badged dozens of artifacts and opened to an empty tab. The badge and the header now count deliverables only; the tab stays reachable when only debugging files exist and ends with a collapsed 'Show debugging files' entry naming their count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
287 lines
9.8 KiB
Dart
287 lines
9.8 KiB
Dart
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/data/runs_repository.dart';
|
|
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
|
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_tab_button.dart';
|
|
|
|
import '../../artifacts/domain/artifact_fixtures.dart';
|
|
|
|
class _FakeGateway implements ApiGateway {
|
|
_FakeGateway(this.detail);
|
|
final JsonMap detail;
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
|
if (type != 'get_run') throw UnsupportedError(type);
|
|
return Future.value({'run_detail': detail});
|
|
}
|
|
}
|
|
|
|
JsonMap _run({required List<JsonMap> steps}) => <String, dynamic>{
|
|
'id': 21,
|
|
'title': 'Artifacts wiring run',
|
|
'name': 'gallery',
|
|
'status': 'succeeded',
|
|
'steps': steps,
|
|
};
|
|
|
|
Future<void> _pumpDetail(
|
|
WidgetTester tester,
|
|
RunsController controller,
|
|
ApiGateway gateway,
|
|
) async {
|
|
tester.view.physicalSize = const Size(500, 1200);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final view = RunDetailView(
|
|
controller: controller,
|
|
gateway: gateway,
|
|
onBack: () {},
|
|
);
|
|
await tester.pumpWidget(MaterialApp(home: Scaffold(body: view)));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Future<RunsController> _loaded(ApiGateway gateway) async {
|
|
final controller = RunsController(RunsRepository(gateway));
|
|
await controller.select(21);
|
|
return controller;
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('the action opens the recorded groups', (tester) async {
|
|
final gateway = _FakeGateway(
|
|
_run(
|
|
steps: [
|
|
step(
|
|
stage: 'implementer',
|
|
sequence: 1,
|
|
artifacts: [
|
|
artifact('build.log', contentType: 'text/plain', sizeBytes: 2337),
|
|
],
|
|
),
|
|
step(
|
|
stage: 'reviewer',
|
|
sequence: 2,
|
|
artifacts: [
|
|
artifact('shot.png', contentType: 'image/png', sizeBytes: 80544),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final controller = await _loaded(gateway);
|
|
addTearDown(controller.dispose);
|
|
await _pumpDetail(tester, controller, gateway);
|
|
|
|
expect(
|
|
find.byKey(const ValueKey('run-detail-tab-artifacts')),
|
|
findsOneWidget,
|
|
);
|
|
await tester.ensureVisible(
|
|
find.byKey(const ValueKey('run-detail-tab-artifacts')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('run-detail-tab-artifacts')));
|
|
await tester.pumpAndSettle();
|
|
// Artifact groups start open: the files show without a tap.
|
|
|
|
expect(find.text('Artifacts · 2 recorded'), findsOneWidget);
|
|
expect(find.text('build.log'), findsOneWidget);
|
|
expect(find.text('shot.png'), findsOneWidget);
|
|
expect(find.text('implementer · visit 1'), findsOneWidget);
|
|
expect(find.text('reviewer · visit 1'), findsOneWidget);
|
|
});
|
|
|
|
/// Shaped like the live Caplens ticket runs (133-139): every visit recorded
|
|
/// only server-grouped debugging files (turn documents, history, private
|
|
/// scratch) and no `public/` deliverable.
|
|
JsonMap debugOnly(String name, {String url = ''}) => artifact(
|
|
name,
|
|
url: url.isEmpty ? null : url,
|
|
contentType: 'text/markdown; charset=utf-8',
|
|
sizeBytes: 3000,
|
|
extra: const {'group': 'debug'},
|
|
);
|
|
|
|
testWidgets('debugging files are never badged as artifacts', (tester) async {
|
|
final gateway = _FakeGateway(
|
|
_run(
|
|
steps: [
|
|
for (final (index, stage) in ['build', 'review', 'verify'].indexed)
|
|
step(
|
|
stage: stage,
|
|
sequence: index + 1,
|
|
artifacts: [
|
|
for (final name in [
|
|
'input.md',
|
|
'memory.md',
|
|
'history.md',
|
|
'output.md',
|
|
'session.html',
|
|
'private/notes.md',
|
|
])
|
|
debugOnly(name, url: '/artifacts/21/${index + 1}/$name'),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final controller = await _loaded(gateway);
|
|
addTearDown(controller.dispose);
|
|
await _pumpDetail(tester, controller, gateway);
|
|
|
|
final tab = find.byKey(const ValueKey('run-detail-tab-artifacts'));
|
|
// The badge says 0: none of the 18 recorded files is a deliverable.
|
|
expect(find.descendant(of: tab, matching: find.text('0')), findsOneWidget);
|
|
expect(find.descendant(of: tab, matching: find.text('18')), findsNothing);
|
|
// The tab still opens, to an honest summary and a collapsed debug entry.
|
|
expect(tester.widget<FloatingTabButton>(tab).enabled, isTrue);
|
|
await tester.ensureVisible(tab);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(tab);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('No artifacts recorded for this run.'), findsOneWidget);
|
|
final reveal = find.byKey(const Key('artifact-debug-reveal'));
|
|
expect(reveal, findsOneWidget);
|
|
expect(find.textContaining('18 files'), findsOneWidget);
|
|
expect(find.text('history.md'), findsNothing);
|
|
|
|
await tester.tap(reveal);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('build · visit 1'), findsOneWidget);
|
|
expect(find.text('history.md'), findsWidgets);
|
|
});
|
|
|
|
testWidgets('deliverables are badged and listed before debugging files', (
|
|
tester,
|
|
) async {
|
|
// Shaped like the live Research run 132: public/ deliverables beside
|
|
// stage-root copies and turn files the server groups as debug.
|
|
JsonMap deliverable(String name, int sequence) => artifact(
|
|
name,
|
|
url: '/artifacts/21/$sequence/$name',
|
|
contentType: 'text/markdown; charset=utf-8',
|
|
extra: const {'group': 'deliverable'},
|
|
);
|
|
final gateway = _FakeGateway(
|
|
_run(
|
|
steps: [
|
|
step(
|
|
stage: 'ground',
|
|
sequence: 1,
|
|
artifacts: [
|
|
debugOnly('input.md', url: '/artifacts/21/1/input.md'),
|
|
debugOnly('output.md', url: '/artifacts/21/1/output.md'),
|
|
debugOnly('ground.md', url: '/artifacts/21/1/ground.md'),
|
|
deliverable('public/ground.md', 1),
|
|
],
|
|
),
|
|
step(
|
|
stage: 'research',
|
|
sequence: 2,
|
|
artifacts: [
|
|
debugOnly('input.md', url: '/artifacts/21/2/input.md'),
|
|
debugOnly('output.md', url: '/artifacts/21/2/output.md'),
|
|
deliverable('public/ground.md', 2),
|
|
deliverable('public/research.md', 2),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final controller = await _loaded(gateway);
|
|
addTearDown(controller.dispose);
|
|
await _pumpDetail(tester, controller, gateway);
|
|
|
|
final tab = find.byKey(const ValueKey('run-detail-tab-artifacts'));
|
|
// public/ground.md is shared, so it counts once: 2 deliverables.
|
|
expect(find.descendant(of: tab, matching: find.text('2')), findsOneWidget);
|
|
await tester.ensureVisible(tab);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(tab);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Artifacts · 2 recorded'), findsOneWidget);
|
|
expect(find.text('public/ground.md'), findsOneWidget);
|
|
expect(find.text('public/research.md'), findsOneWidget);
|
|
expect(find.text('ground.md'), findsNothing);
|
|
expect(find.text('input.md'), findsNothing);
|
|
expect(find.textContaining('5 files'), findsOneWidget);
|
|
});
|
|
|
|
/// The Artifacts tab keeps its place on a run with none: disabled, badged
|
|
/// `0`, and its tooltip (and accessibility hint) says why.
|
|
Future<void> expectDisabledArtifacts(WidgetTester tester, String why) async {
|
|
final tab = find.byKey(const ValueKey('run-detail-tab-artifacts'));
|
|
expect(tab, findsOneWidget);
|
|
final button = tester.widget<FloatingTabButton>(tab);
|
|
expect(button.enabled, isFalse);
|
|
expect(button.tooltip, why);
|
|
expect(
|
|
find.descendant(
|
|
of: tab,
|
|
matching: find.byKey(const ValueKey('run-detail-artifacts-count')),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.descendant(of: tab, matching: find.text('0')), findsOneWidget);
|
|
// A tap does not open an empty gallery: Summary stays.
|
|
await tester.tap(tab, warnIfMissed: false);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text(why), findsNothing);
|
|
// Changes, after it, keeps its place.
|
|
final order = [
|
|
for (final name in ['summary', 'timeline', 'artifacts', 'changes'])
|
|
tester.getCenter(find.byKey(ValueKey('run-detail-tab-$name'))).dx,
|
|
];
|
|
expect(order, orderedEquals([...order]..sort()));
|
|
}
|
|
|
|
testWidgets('a run without steps keeps a disabled Artifacts tab', (
|
|
tester,
|
|
) async {
|
|
final gateway = _FakeGateway(_run(steps: const []));
|
|
final controller = await _loaded(gateway);
|
|
addTearDown(controller.dispose);
|
|
await _pumpDetail(tester, controller, gateway);
|
|
await expectDisabledArtifacts(
|
|
tester,
|
|
'No artifacts recorded for this run.',
|
|
);
|
|
});
|
|
|
|
testWidgets('a recorded empty capture keeps its explicit wording', (
|
|
tester,
|
|
) async {
|
|
final gateway = _FakeGateway(
|
|
_run(
|
|
steps: [step(stage: 'reviewer', visit: 1, artifacts: const [])],
|
|
),
|
|
);
|
|
final controller = await _loaded(gateway);
|
|
addTearDown(controller.dispose);
|
|
await _pumpDetail(tester, controller, gateway);
|
|
await expectDisabledArtifacts(
|
|
tester,
|
|
'No artifacts recorded for this run.',
|
|
);
|
|
});
|
|
|
|
testWidgets('an unavailable capture is never reported as empty', (
|
|
tester,
|
|
) async {
|
|
final gateway = _FakeGateway(
|
|
_run(steps: [step(stage: 'reviewer', visit: 1, includeArtifacts: false)]),
|
|
);
|
|
final controller = await _loaded(gateway);
|
|
addTearDown(controller.dispose);
|
|
await _pumpDetail(tester, controller, gateway);
|
|
await expectDisabledArtifacts(tester, 'Artifacts · capture unavailable');
|
|
});
|
|
}
|