fix(app): expose exact visit turn documents in Session
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
JsonMap document(String name, int sequence, {String? url}) => {
|
||||
'name': name,
|
||||
'url': url ?? '/artifacts/$sequence/$name',
|
||||
'content_type': 'text/markdown',
|
||||
'size_bytes': 24,
|
||||
};
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets(
|
||||
'${platform.name} Session exposes exact repeated visit documents',
|
||||
(tester) async {
|
||||
final run = visitRunFixture();
|
||||
final first = firstVisitStep(run);
|
||||
(first['artifacts'] as List).addAll([
|
||||
document('input.md', 1),
|
||||
document('output.md', 1),
|
||||
document('memory.md', 1),
|
||||
]);
|
||||
final second = <String, dynamic>{
|
||||
...first,
|
||||
'sequence': 3,
|
||||
'session_id': 'sess-3',
|
||||
'artifacts': [
|
||||
document('input.md', 3),
|
||||
document('output.md', 3),
|
||||
document('memory.md', 3),
|
||||
{
|
||||
...document(
|
||||
'session.html',
|
||||
3,
|
||||
url: 'https://example.test/artifacts/3/session.html',
|
||||
),
|
||||
'content_type': 'text/html',
|
||||
},
|
||||
],
|
||||
};
|
||||
(run['steps'] as List).add(second);
|
||||
await openVisit(tester, platform, run: run, sequence: 3);
|
||||
await openVisitTab(tester, RunVisitSection.session);
|
||||
expect(find.text('sess-3'), findsOneWidget);
|
||||
expect(find.text('sess-1'), findsNothing);
|
||||
expect(find.text('input.md'), findsOneWidget);
|
||||
expect(find.text('Open session.html'), findsOneWidget);
|
||||
for (final name in ['input.md', 'output.md', 'memory.md']) {
|
||||
final row = find.text(name);
|
||||
await tester.ensureVisible(row);
|
||||
await tester.tap(row);
|
||||
await tester.pumpAndSettle();
|
||||
final viewer = tester.widget<ArtifactViewerPage>(
|
||||
find.byType(ArtifactViewerPage),
|
||||
);
|
||||
expect(viewer.groups, hasLength(1));
|
||||
expect(viewer.groups.single.visit, 2);
|
||||
expect(viewer.groups.single.documents.map((d) => d.record?.url), [
|
||||
'/artifacts/3/input.md',
|
||||
'/artifacts/3/memory.md',
|
||||
'/artifacts/3/output.md',
|
||||
]);
|
||||
expect(viewer.selectedIdentity, contains('/artifacts/3/$name'));
|
||||
// Exercise the routed viewer's exact snapshot with fixture transport.
|
||||
final fetched = <Uri>[];
|
||||
final preview = ArtifactViewerPage(
|
||||
groups: viewer.groups,
|
||||
selectedIdentity: viewer.selectedIdentity,
|
||||
configuredEndpoint: 'wss://example.test/connect',
|
||||
fetch: (uri) async {
|
||||
fetched.add(uri);
|
||||
return ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: utf8.encode('Raw $name visit 3'),
|
||||
);
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpWidget(
|
||||
platform == RunDetailTestPlatform.cupertino
|
||||
? CupertinoApp(home: preview)
|
||||
: MaterialApp(home: preview),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(fetched.single.path, '/artifacts/3/$name');
|
||||
expect(find.text('Raw $name visit 3'), findsOneWidget);
|
||||
expect(find.text('Ship it.'), findsNothing);
|
||||
String? copied;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied = (call.arguments as Map)['text'] as String;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('artifact-copy-link')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(copied, 'https://example.test/artifacts/3/$name');
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
);
|
||||
await openVisit(tester, platform, run: run, sequence: 3);
|
||||
await openVisitTab(tester, RunVisitSection.session);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'${platform.name} repeated visit never borrows missing documents or URLs',
|
||||
(tester) async {
|
||||
final run = visitRunFixture();
|
||||
final first = firstVisitStep(run);
|
||||
first['artifacts'] = [
|
||||
document('input.md', 1),
|
||||
document('output.md', 1),
|
||||
document('memory.md', 1),
|
||||
];
|
||||
(run['steps'] as List).add({
|
||||
...first,
|
||||
'sequence': 2,
|
||||
'artifacts': [document('input.md', 2, url: '')],
|
||||
});
|
||||
await openVisit(tester, platform, run: run, sequence: 2);
|
||||
await openVisitTab(tester, RunVisitSection.session);
|
||||
expect(find.text('No output recorded.'), findsOneWidget);
|
||||
expect(find.text('No memory recorded for this visit.'), findsOneWidget);
|
||||
await tester.ensureVisible(find.text('input.md'));
|
||||
await tester.tap(find.text('input.md'));
|
||||
await tester.pumpAndSettle();
|
||||
final viewer = tester.widget<ArtifactViewerPage>(
|
||||
find.byType(ArtifactViewerPage),
|
||||
);
|
||||
final docs = viewer.groups.single.documents;
|
||||
expect(docs.where((doc) => doc.record != null), hasLength(1));
|
||||
expect(docs.first.record!.url, isEmpty);
|
||||
expect(find.byKey(const Key('artifact-copy-link')), findsNothing);
|
||||
expect(find.byKey(const Key('artifact-open')), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'${platform.name} Session distinguishes absent docs and unavailable capture',
|
||||
(tester) async {
|
||||
final run = visitRunFixture();
|
||||
firstVisitStep(run)['artifacts'] = <dynamic>[];
|
||||
await openVisit(tester, platform, run: run);
|
||||
await openVisitTab(tester, RunVisitSection.session);
|
||||
expect(find.text('No input recorded.'), findsOneWidget);
|
||||
for (final text in [
|
||||
'No input recorded.',
|
||||
'No output recorded.',
|
||||
'No memory recorded for this visit.',
|
||||
]) {
|
||||
await tester.scrollUntilVisible(
|
||||
find.text(text),
|
||||
150,
|
||||
scrollable: find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('run-visit-body-session')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(find.text(text), findsOneWidget);
|
||||
}
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
firstVisitStep(run).remove('artifacts');
|
||||
await openVisit(tester, platform, run: run);
|
||||
await openVisitTab(tester, RunVisitSection.session);
|
||||
expect(
|
||||
find.text('Turn documents · capture unavailable'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('No input recorded.'), findsNothing);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user