57f5219628
Each recorded artifact now carries a server group (deliverable or debug). public/ files are deliverables; input/memory/history/output.md, session exports and private/ scratch are debugging files. The app's Artifacts tab lists deliverables and the Debug toggle reveals a separate Debugging files group (older servers fall back to the filename rule); the TUI lists deliverables first and marks debug rows; artifact search excludes debug files unless include_debug / --debug-files is set.
315 lines
11 KiB
Dart
315 lines
11 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/cupertino.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/artifacts/ui/artifact_external_open.dart';
|
|
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
|
|
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
|
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
|
|
|
import '../domain/artifact_fixtures.dart';
|
|
|
|
enum _Platform { material, cupertino }
|
|
|
|
const String _endpoint = 'ws://127.0.0.1:8081/connect';
|
|
|
|
JsonMap _recorded(
|
|
String name, {
|
|
required String contentType,
|
|
required int sizeBytes,
|
|
}) => artifact(name, contentType: contentType, sizeBytes: sizeBytes);
|
|
|
|
/// Visit 1 records every turn document except memory. Visit 2 records input and
|
|
/// memory only, so both visits carry recorded and missing document slots.
|
|
List<JsonMap> _steps() => <JsonMap>[
|
|
step(
|
|
stage: 'review',
|
|
sequence: 1,
|
|
visit: 1,
|
|
artifacts: [
|
|
_recorded('report.csv', contentType: 'text/csv', sizeBytes: 23),
|
|
_recorded('input.md', contentType: 'text/markdown', sizeBytes: 120),
|
|
_recorded('output.md', contentType: 'text/markdown', sizeBytes: 240),
|
|
_recorded('session.html', contentType: 'text/plain', sizeBytes: 512),
|
|
],
|
|
),
|
|
step(
|
|
stage: 'review',
|
|
sequence: 2,
|
|
visit: 2,
|
|
artifacts: [
|
|
_recorded('notes.md', contentType: 'text/markdown', sizeBytes: 64),
|
|
_recorded('input.md', contentType: 'text/markdown', sizeBytes: 130),
|
|
_recorded('memory.md', contentType: 'text/markdown', sizeBytes: 256),
|
|
],
|
|
),
|
|
];
|
|
|
|
Future<void> _pump(
|
|
WidgetTester tester,
|
|
_Platform platform, {
|
|
List<JsonMap>? steps,
|
|
ArtifactFetch? fetch,
|
|
ArtifactExternalOpen? openExternal,
|
|
int? focusIndex,
|
|
}) async {
|
|
tester.view.physicalSize = const Size(900, 2600);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final page = ArtifactGalleryPage(
|
|
steps: steps ?? _steps(),
|
|
focusIndex: focusIndex,
|
|
configuredEndpoint: _endpoint,
|
|
openExternal: openExternal ?? (_) async => true,
|
|
fetch:
|
|
fetch ??
|
|
(_) async => ArtifactFetchResult(
|
|
status: 200,
|
|
bytes: Uint8List.fromList('# Recorded input'.codeUnits),
|
|
),
|
|
markdownBuilder: (context, value) => Text(value),
|
|
);
|
|
await tester.pumpWidget(
|
|
platform == _Platform.material
|
|
? MaterialApp(home: page)
|
|
: CupertinoApp(home: page),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> _showTurnDocuments(WidgetTester tester) async {
|
|
await tester.tap(find.byKey(const Key('artifact-debug-toggle')));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Finder _dialog(_Platform platform, String text) => find.descendant(
|
|
of: find.byType(
|
|
platform == _Platform.material ? AlertDialog : CupertinoAlertDialog,
|
|
),
|
|
matching: find.text(text),
|
|
);
|
|
|
|
void main() {
|
|
for (final platform in _Platform.values) {
|
|
testWidgets('${platform.name}: debug hides documents by default and shows '
|
|
'each visit when enabled', (tester) async {
|
|
await _pump(tester, platform);
|
|
expect(find.text('input.md'), findsNothing);
|
|
expect(find.textContaining('Turn documents'), findsNothing);
|
|
expect(find.byTooltip('Show debugging files'), findsOneWidget);
|
|
await _showTurnDocuments(tester);
|
|
expect(find.byTooltip('Hide debugging files'), findsOneWidget);
|
|
expect(find.text('input.md'), findsNWidgets(2));
|
|
expect(find.text('output.md'), findsNWidgets(2));
|
|
expect(find.text('session.html'), findsNWidgets(2));
|
|
expect(find.text('memory.md'), findsNWidgets(2));
|
|
expect(find.text('text/markdown · 120\u00a0B'), findsOneWidget);
|
|
expect(find.text('text/plain · 512\u00a0B'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('${platform.name}: missing documents show exact wording', (
|
|
tester,
|
|
) async {
|
|
await _pump(tester, platform);
|
|
await _showTurnDocuments(tester);
|
|
expect(find.text('No memory recorded for this visit.'), findsOneWidget);
|
|
expect(find.text('No output recorded.'), findsOneWidget);
|
|
expect(find.text('This visit has no harness session.'), findsOneWidget);
|
|
expect(find.text('No input recorded.'), findsNothing);
|
|
});
|
|
|
|
testWidgets('${platform.name}: markdown opens the existing renderer', (
|
|
tester,
|
|
) async {
|
|
await _pump(tester, platform);
|
|
await _showTurnDocuments(tester);
|
|
await tester.tap(find.text('input.md').first);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
|
expect(find.text('# Recorded input'), findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('artifact-info')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('review · visit 1'), findsOneWidget);
|
|
expect(find.text('text/markdown · 120\u00a0B'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'${platform.name}: absent rows are informational, not controls',
|
|
(tester) async {
|
|
await _pump(tester, platform);
|
|
await _showTurnDocuments(tester);
|
|
final absence = find.text('No output recorded.');
|
|
expect(absence, findsOneWidget);
|
|
if (platform == _Platform.material) {
|
|
// Not disabled: the absence line is content, not a skipped action, and
|
|
// is painted with the normal secondary label colour.
|
|
final tile = tester.widget<ListTile>(
|
|
find.ancestor(of: absence, matching: find.byType(ListTile)),
|
|
);
|
|
expect(tile.enabled, isTrue);
|
|
expect(tile.onTap, isNull);
|
|
expect(
|
|
tester.widget<Text>(absence).style?.color,
|
|
Theme.of(tester.element(absence)).colorScheme.onSurfaceVariant,
|
|
);
|
|
} else {
|
|
expect(
|
|
find.ancestor(of: absence, matching: find.byType(CupertinoButton)),
|
|
findsNothing,
|
|
);
|
|
}
|
|
await tester.tap(absence);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsNothing);
|
|
expect(find.byType(AlertDialog), findsNothing);
|
|
expect(find.byType(CupertinoAlertDialog), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets('${platform.name}: session.html stays external-only', (
|
|
tester,
|
|
) async {
|
|
final opened = <Uri>[];
|
|
await _pump(
|
|
tester,
|
|
platform,
|
|
openExternal: (uri) async {
|
|
opened.add(uri);
|
|
return true;
|
|
},
|
|
fetch: (_) async => throw StateError('x'),
|
|
);
|
|
await _showTurnDocuments(tester);
|
|
await tester.tap(find.text('session.html').first);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsNothing);
|
|
expect(_dialog(platform, 'session.html'), findsOneWidget);
|
|
expect(_dialog(platform, 'text/plain · 512\u00a0B'), findsOneWidget);
|
|
await tester.tap(_dialog(platform, 'Open in browser'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsNothing);
|
|
expect(opened, [
|
|
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/session.html'),
|
|
]);
|
|
});
|
|
|
|
testWidgets('${platform.name}: a stage artifact pages only through stage '
|
|
'artifacts while Debug is off', (tester) async {
|
|
await _pump(tester, platform);
|
|
|
|
// report.csv (visit 1) and notes.md (visit 2) are the only stage
|
|
// artifacts; the visits' turn documents stay out of the viewer.
|
|
await tester.tap(find.text('report.csv'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
|
expect(find.text('1 of 2 · text/csv'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('${platform.name}: with Debug on, a stage artifact pages '
|
|
'through turn documents too', (tester) async {
|
|
await _pump(tester, platform);
|
|
await _showTurnDocuments(tester);
|
|
|
|
await tester.tap(find.text('report.csv'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
|
// Both stage artifacts plus the recorded viewer documents
|
|
// (session.html opens externally only).
|
|
expect(find.text('1 of 6 · text/csv'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('${platform.name}: documents do not count as artifacts and '
|
|
'viewer paging stays within documents', (tester) async {
|
|
await _pump(
|
|
tester,
|
|
platform,
|
|
steps: [
|
|
step(
|
|
stage: 'review',
|
|
visit: 1,
|
|
artifacts: [
|
|
_recorded('report.csv', contentType: 'text/csv', sizeBytes: 23),
|
|
_recorded('input.md', contentType: 'text/markdown', sizeBytes: 1),
|
|
_recorded(
|
|
'output.md',
|
|
contentType: 'text/markdown',
|
|
sizeBytes: 1,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
|
|
expect(find.text('Artifact · 1 recorded'), findsOneWidget);
|
|
expect(find.text('report.csv'), findsOneWidget);
|
|
expect(find.text('input.md'), findsNothing);
|
|
await _showTurnDocuments(tester);
|
|
await tester.tap(find.text('input.md'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
|
expect(find.text('1 of 2 · text/markdown'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('${platform.name}: document-only visits retain an honest empty '
|
|
'artifact state', (tester) async {
|
|
await _pump(
|
|
tester,
|
|
platform,
|
|
steps: [
|
|
step(
|
|
stage: 'review',
|
|
visit: 1,
|
|
artifacts: [
|
|
_recorded('input.md', contentType: 'text/markdown', sizeBytes: 1),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
|
|
expect(find.text('No artifacts recorded for this run.'), findsOneWidget);
|
|
expect(find.text('input.md'), findsNothing);
|
|
await _showTurnDocuments(tester);
|
|
expect(find.text('input.md'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('${platform.name}: focused document-only visits retain turn '
|
|
'documents', (tester) async {
|
|
await _pump(
|
|
tester,
|
|
platform,
|
|
focusIndex: 0,
|
|
steps: [
|
|
step(
|
|
stage: 'review',
|
|
visit: 1,
|
|
artifacts: [
|
|
_recorded('input.md', contentType: 'text/markdown', sizeBytes: 1),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
|
|
expect(
|
|
find.text('No artifacts recorded for this visit.'),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('input.md'), findsNothing);
|
|
await _showTurnDocuments(tester);
|
|
expect(find.text('input.md'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('${platform.name}: focused visits retain session documents', (
|
|
tester,
|
|
) async {
|
|
await _pump(tester, platform, focusIndex: 0);
|
|
|
|
expect(find.text('session.html'), findsNothing);
|
|
await _showTurnDocuments(tester);
|
|
expect(find.text('session.html'), findsOneWidget);
|
|
});
|
|
}
|
|
}
|