fix(app): expose exact visit turn documents in Session

This commit is contained in:
2026-10-24 02:00:18 +01:00
parent 027be68ae7
commit 285392982d
4 changed files with 324 additions and 0 deletions
@@ -0,0 +1,95 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../artifacts/domain/artifact_capture.dart';
import '../../artifacts/domain/artifact_document.dart';
import '../../artifacts/domain/artifact_groups.dart';
import '../../artifacts/domain/artifact_record.dart';
import '../../artifacts/domain/gallery_navigation.dart';
import '../../artifacts/ui/artifact_document_section.dart';
import '../../artifacts/ui/artifact_viewer_page.dart';
import '../../graph/domain/stage_visits.dart';
import 'run_detail_visit_recorded.dart';
/// Raw turn documents, never the Summary's interpreted step input/output maps.
/// Only this step's inventory enters the viewer or its Previous/Next controls.
/// The session export remains with the session metadata and repair controls.
class RunVisitDocuments extends StatelessWidget {
const RunVisitDocuments({
super.key,
required this.step,
required this.run,
required this.configuredEndpoint,
});
final JsonMap step;
final JsonMap run;
final String configuredEndpoint;
int _visitNumber() {
final steps = run['steps'];
final stage = '${step['stage'] ?? ''}';
final visits =
visitsByStage(
steps is List ? steps.cast<JsonMap>() : <JsonMap>[step],
)[stage] ??
<JsonMap>[];
final position = visits.indexWhere(
(candidate) =>
identical(candidate, step) ||
candidate['sequence'] == step['sequence'],
);
return displayVisit(step, position < 0 ? 0 : position);
}
@override
Widget build(BuildContext context) {
final capture = ArtifactCapture.fromStep(step);
if (!capture.isAvailable) {
return const Text('Turn documents · capture unavailable');
}
final recorded = visitDocuments(step);
// Unlike the gallery, Session must explain even an entirely empty capture.
final documents = recorded.isEmpty
? const [
ArtifactDocument(
name: 'input.md',
record: null,
absence: noInputDocument,
),
ArtifactDocument(
name: 'output.md',
record: null,
absence: noOutputDocument,
),
ArtifactDocument(
name: 'memory.md',
record: null,
absence: noMemoryDocument,
),
]
: recorded.where((doc) => !doc.externalOnly).toList(growable: false);
final group = ArtifactGroup(
stageKey: recordedText(step['stage']) ?? '',
visit: _visitNumber(),
artifacts: const [],
documents: documents,
);
void select(ArtifactGroup group, ArtifactRecord artifact) {
final page = ArtifactViewerPage(
groups: [group],
selectedIdentity: artifactVisitIdentityOf(group, artifact),
configuredEndpoint: configuredEndpoint,
);
Navigator.of(context).push<void>(
usesCupertinoHost(context)
? CupertinoPageRoute<void>(builder: (_) => page)
: MaterialPageRoute<void>(builder: (_) => page),
);
}
return ArtifactDocumentSection(group: group, onSelected: select);
}
}
@@ -9,6 +9,7 @@ import '../../artifacts/domain/artifact_url.dart';
import '../../artifacts/ui/artifact_external_open.dart';
import '../actions/session_export_repair_action.dart';
import 'run_detail_visit_recorded.dart';
import 'run_detail_visit_documents.dart';
import 'run_detail_visit_session_state.dart';
/// The visit's recorded session pointer, its recorded export state and, when
@@ -105,6 +106,11 @@ class _RunVisitSessionState extends State<RunVisitSession> {
padding: const EdgeInsets.only(top: 8),
child: Semantics(liveRegion: true, child: Text(_status!)),
),
RunVisitDocuments(
step: widget.step,
run: widget.run,
configuredEndpoint: widget.configuredEndpoint,
),
];
if (usesCupertinoHost(context)) {
return ListView(
+31
View File
@@ -0,0 +1,31 @@
# Stage detail debugging fixes
- Stage Summary Input and Output start collapsed (commit `027be68a`). Existing
native section toggles and copy actions remain. Both Material and Cupertino
regression assertions failed before the one-line initial-state fix; all 18
section tests passed afterward.
- Session adds the selected step's inventory-backed input.md, memory.md and
output.md rows through ArtifactDocumentSection. ArtifactViewerPage receives
only those documents from that exact step, so paging cannot escape to an
earlier repeated visit. Its default selectable-text markdown preview exposes
the raw recorded document, not the interpreted Summary maps. Existing safe URL
resolution, same-origin fetch, copy-link and file actions are reused.
- Session export remains external-only with the existing metadata, diagnostics
and export-only repair controls unchanged. Missing documents remain
non-actionable; unavailable capture is distinguished from an empty inventory.
No document URL is constructed or borrowed.
## Verification
- `flutter pub get`: passed using /Users/alan/development/flutter/bin/flutter.
- New exact-visit document tests failed on both hosts before implementation
because Session had no input.md row.
- Six new document tests cover both hosts: repeated visit 2 (sequence 3), exact
inventory and selection, fixture-byte previews and copy-link controls, missing
sibling documents/URLs without borrowing, and unavailable versus empty capture.
- `flutter test test/features/runs test/features/artifacts`: 469 passed.
- Focused `flutter analyze` for the three changed production widgets and two
changed test files: no issues.
- No browser captures, integrated web build, mobile checks, APK build, ADB,
deployment, restart, production data mutation or backend edits performed.
Browser verification and integration/deployment belong to the manager.
@@ -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);
},
);
}
}