Merge main into flutter/route-vocabulary: adopt the session actions and artifact gallery work
This commit is contained in:
@@ -0,0 +1,281 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_document.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_summary.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/gallery_navigation.dart';
|
||||
|
||||
import 'artifact_fixtures.dart';
|
||||
|
||||
Map<String, dynamic> _doc(
|
||||
String name, {
|
||||
String contentType = 'text/markdown',
|
||||
int sizeBytes = 12,
|
||||
}) => artifact(name, contentType: contentType, sizeBytes: sizeBytes);
|
||||
|
||||
ArtifactGroup _docGroup(List<String> recorded) {
|
||||
final recordedStep = step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [for (final name in recorded) _doc(name)],
|
||||
);
|
||||
return ArtifactGroup(
|
||||
stageKey: 'review',
|
||||
visit: 1,
|
||||
artifacts: const <ArtifactRecord>[],
|
||||
documents: visitDocuments(recordedStep),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('visit documents', () {
|
||||
test('a recorded document carries its exact recorded record', () {
|
||||
final docs = visitDocuments(
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_doc('input.md', sizeBytes: 12),
|
||||
_doc('memory.md', sizeBytes: 34),
|
||||
_doc('output.md', sizeBytes: 56),
|
||||
_doc('session.html', contentType: 'text/html', sizeBytes: 78),
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(docs.map((doc) => doc.name), turnDocumentNames);
|
||||
expect(docs.every((doc) => doc.record != null), isTrue);
|
||||
expect(docs.every((doc) => doc.absence.isEmpty), isTrue);
|
||||
expect(docs[0].record!.contentType, 'text/markdown');
|
||||
expect(docs[0].record!.sizeBytes, 12);
|
||||
expect(docs[3].record!.contentType, 'text/html');
|
||||
expect(docs[3].record!.sizeBytes, 78);
|
||||
});
|
||||
|
||||
test('only input and output absent messages use the audit words', () {
|
||||
final docs = visitDocuments(
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_doc('input.md'), _doc('output.md')],
|
||||
),
|
||||
);
|
||||
expect(docs[1].record, isNull);
|
||||
expect(docs[1].absence, 'No memory recorded for this visit.');
|
||||
expect(docs[3].record, isNull);
|
||||
expect(docs[3].absence, 'This visit has no harness session.');
|
||||
});
|
||||
|
||||
test('a missing capture yields no slots, never four missing documents', () {
|
||||
final docs = visitDocuments(
|
||||
step(stage: 'review', visit: 1, includeArtifacts: false),
|
||||
);
|
||||
expect(docs, isEmpty);
|
||||
});
|
||||
|
||||
test('step fields never stand in for a missing document', () {
|
||||
final docs = visitDocuments(<String, dynamic>{
|
||||
'stage': 'review',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'input': 'looks like input',
|
||||
'memory': 'looks like memory',
|
||||
'output': 'looks like output',
|
||||
'artifacts': <Map<String, dynamic>>[],
|
||||
});
|
||||
expect(docs, isEmpty);
|
||||
});
|
||||
|
||||
test('a recorded session id is not reported as no session', () {
|
||||
final docs = visitDocuments(<String, dynamic>{
|
||||
'stage': 'review',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'session_id': 'ses-42',
|
||||
'artifacts': <Map<String, dynamic>>[_doc('input.md')],
|
||||
});
|
||||
expect(
|
||||
docs[3].absence,
|
||||
'Session ses-42 is recorded. Its export is not yet available.',
|
||||
);
|
||||
});
|
||||
|
||||
test('the session export is external-only even when sniffed as text', () {
|
||||
final docs = visitDocuments(
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_doc('input.md'),
|
||||
_doc('session.html', contentType: 'text/plain', sizeBytes: 99),
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(docs[3].externalOnly, isTrue);
|
||||
expect(docs[3].opensInViewer, isFalse);
|
||||
expect(docs[0].opensInViewer, isTrue);
|
||||
});
|
||||
|
||||
test('the turn document names share the stage filter order', () {
|
||||
expect(turnDocumentNames, systemArtifactNames);
|
||||
});
|
||||
|
||||
// Every remaining branch of the contextual session wording is exact product
|
||||
// copy, so each is pinned rather than reached only through the probe.
|
||||
String sessionAbsence(Map<String, dynamic> fields) =>
|
||||
visitDocuments(<String, dynamic>{
|
||||
'stage': 'review',
|
||||
'sequence': 1,
|
||||
'artifacts': <Map<String, dynamic>>[_doc('input.md')],
|
||||
...fields,
|
||||
})[3].absence;
|
||||
|
||||
test('a skipped or stopped stage never claims a harness session', () {
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'status': 'skipped'}),
|
||||
'This visit was skipped; no harness session was started.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'outcome': 'skipped'}),
|
||||
'This visit was skipped; no harness session was started.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'status': 'canceled'}),
|
||||
'The stage stopped before a harness session was recorded.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'status': 'interrupted'}),
|
||||
'The stage stopped before a harness session was recorded.',
|
||||
);
|
||||
});
|
||||
|
||||
test('a model stage states whether its session is running or failed', () {
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'status': 'running', 'model': 'luna'}),
|
||||
'The stage session is being created.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'status': 'failed', 'model': 'luna'}),
|
||||
'The stage did not create a harness session.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{
|
||||
'status': 'failed',
|
||||
'model': 'luna',
|
||||
'diagnostic': 'provider rejected the request.',
|
||||
}),
|
||||
'The stage did not create a harness session.'
|
||||
' provider rejected the request.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{'provider': 'local'}),
|
||||
'Runtime error: this model stage has no recorded session identity.',
|
||||
);
|
||||
});
|
||||
|
||||
test('a recorded session reports its export recovery state', () {
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{
|
||||
'session_id': 'ses-9',
|
||||
'session_export_recovery': <String, dynamic>{'status': 'pending'},
|
||||
}),
|
||||
'Session ses-9 is recorded. Its export is pending recovery.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{
|
||||
'session_id': 'ses-9',
|
||||
'session_export_recovery': <String, dynamic>{'status': 'running'},
|
||||
}),
|
||||
'Session ses-9 is recorded. Its export is pending recovery.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{
|
||||
'session_export': <String, dynamic>{
|
||||
'session_id': 'ses-8',
|
||||
'status': 'complete',
|
||||
},
|
||||
}),
|
||||
'Session ses-8 is recorded.'
|
||||
' Its export is not available in the artifact inventory.',
|
||||
);
|
||||
expect(
|
||||
sessionAbsence(<String, dynamic>{
|
||||
'session_export': <String, dynamic>{
|
||||
'session_id': 'ses-7',
|
||||
'status': 'failed',
|
||||
'diagnostic': 'Disk full.',
|
||||
},
|
||||
}),
|
||||
'Session ses-7 is recorded. Its export is failed. Disk full.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('gallery groups', () {
|
||||
test('groups documents per visit without changing stage grouping', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: [_doc('input.md'), _doc('output.md')],
|
||||
),
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 2,
|
||||
visit: 2,
|
||||
artifacts: [_doc('input.md'), _doc('memory.md')],
|
||||
),
|
||||
];
|
||||
expect(artifactGroups(steps), isEmpty);
|
||||
final groups = galleryGroups(steps);
|
||||
expect(groups.map((group) => group.visit), <int>[1, 2]);
|
||||
expect(groups[0].artifacts, isEmpty);
|
||||
expect(groups[0].documents[0].record!.sizeBytes, 12);
|
||||
expect(groups[1].documents[2].record, isNull);
|
||||
expect(groups.map((group) => group.recordedCount), <int>[2, 2]);
|
||||
});
|
||||
|
||||
test('a visit with neither artifacts nor recorded documents is absent', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(stage: 'a', sequence: 1, includeArtifacts: false),
|
||||
step(stage: 'a', sequence: 2, artifacts: const []),
|
||||
];
|
||||
expect(galleryGroups(steps), isEmpty);
|
||||
});
|
||||
|
||||
test('the header counts recorded documents and stage artifacts', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
artifact('report.csv', contentType: 'text/csv'),
|
||||
_doc('input.md'),
|
||||
_doc('output.md'),
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(
|
||||
artifactsHeader(steps, executing: false),
|
||||
'Artifacts · 3 recorded',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'markdown documents page in the viewer but session.html never does',
|
||||
() {
|
||||
final group = _docGroup(<String>[
|
||||
'input.md',
|
||||
'output.md',
|
||||
'session.html',
|
||||
]);
|
||||
final pages = pagedArtifacts(<ArtifactGroup>[group]);
|
||||
expect(pages.map((page) => page.artifact.name), <String>[
|
||||
'input.md',
|
||||
'output.md',
|
||||
]);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
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,
|
||||
}) 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(),
|
||||
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();
|
||||
}
|
||||
|
||||
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}: every recorded document is an entry', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, platform);
|
||||
expect(find.text('Turn documents'), findsNWidgets(2));
|
||||
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);
|
||||
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 tester.tap(find.text('input.md').first);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(find.text('# Recorded input'), findsOneWidget);
|
||||
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);
|
||||
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 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'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(opened, [
|
||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/session.html'),
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -515,4 +515,42 @@ void main() {
|
||||
// The viewer and its markdown add no Material control to a Cupertino host.
|
||||
expect(find.byType(Material), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Material paging stays inside 320px at 2x text', (tester) async {
|
||||
tester.view.physicalSize = const Size(640, 1200);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
final first = recordedArtifact(
|
||||
'a.png',
|
||||
url: '/artifacts/1/1/a.png',
|
||||
contentType: 'image/png',
|
||||
);
|
||||
final second = recordedArtifact(
|
||||
'b.png',
|
||||
url: '/artifacts/1/2/b.png',
|
||||
contentType: 'image/png',
|
||||
);
|
||||
final groups = [
|
||||
_group([first], visit: 1),
|
||||
_group([second], visit: 2),
|
||||
];
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: groups,
|
||||
selected: artifactVisitIdentity(groups[0], first),
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
// Both labelled controls are whole: a clipped Row overflowed the viewport.
|
||||
for (final label in ['Previous artifact', 'Next artifact']) {
|
||||
final rect = tester.getRect(find.text(label));
|
||||
expect(rect.left, greaterThanOrEqualTo(0), reason: label);
|
||||
expect(rect.right, lessThanOrEqualTo(320), reason: label);
|
||||
expect(rect.width, greaterThan(0), reason: label);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_draft.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart';
|
||||
|
||||
void main() {
|
||||
test('passes the chosen names, MIME types and bytes through', () async {
|
||||
final bytes = Uint8List.fromList([0, 1, 2, 250]);
|
||||
final picked = ChatPickedFile(
|
||||
name: 'screen.png',
|
||||
mime: 'image/png',
|
||||
bytes: bytes,
|
||||
);
|
||||
final picker = ChatAttachmentPicker(select: () async => [picked]);
|
||||
|
||||
expect(picker.isSupported, isTrue);
|
||||
final files = await picker.pick();
|
||||
|
||||
expect(files, hasLength(1));
|
||||
expect(files!.single.name, 'screen.png');
|
||||
expect(files.single.mime, 'image/png');
|
||||
expect(files.single.bytes, bytes);
|
||||
expect(files.single.sizeBytes, 4);
|
||||
});
|
||||
|
||||
test('feeds the picked file to the attachment draft', () async {
|
||||
final picker = ChatAttachmentPicker(
|
||||
select: () async => [
|
||||
ChatPickedFile(
|
||||
name: 'notes.txt',
|
||||
mime: 'text/plain',
|
||||
bytes: Uint8List.fromList([1, 2, 3]),
|
||||
),
|
||||
],
|
||||
);
|
||||
final draft = ChatAttachmentDraft();
|
||||
|
||||
final files = await picker.pick();
|
||||
|
||||
expect(draft.add(files!.single.attachment), isNull);
|
||||
expect(
|
||||
draft.attachments.single,
|
||||
const ChatAttachment(
|
||||
name: 'notes.txt',
|
||||
mime: 'text/plain',
|
||||
sizeBytes: 3,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns nothing when the operator dismisses the picker', () async {
|
||||
var opened = 0;
|
||||
final picker = ChatAttachmentPicker(
|
||||
select: () async {
|
||||
opened += 1;
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
expect(await picker.pick(), isNull);
|
||||
expect(opened, 1);
|
||||
});
|
||||
|
||||
test('the host picker reports its unsupported capability honestly', () async {
|
||||
final picker = hostChatAttachmentPicker;
|
||||
|
||||
expect(picker.isSupported, isFalse);
|
||||
await expectLater(
|
||||
picker.pick(),
|
||||
throwsA(
|
||||
isA<UnsupportedError>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'Attaching files is not supported on this platform yet.',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// The dialogs this slice delivers at the smallest supported size with 2x text.
|
||||
void main() {
|
||||
testWidgets('Material rename refusal fits 320px at 2x', (tester) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
|
||||
],
|
||||
}
|
||||
..failures['chat_rename'] = 'a title with usable text is required';
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Rename…'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' x ');
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('a title with usable text is required'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino rename refusal fits 320px at 2x', (tester) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
|
||||
],
|
||||
}
|
||||
..failures['chat_rename'] = 'a title with usable text is required';
|
||||
await pumpCupertinoChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Rename…'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' x ');
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('a title with usable text is required'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Material create catalog fits real paths at 320px and 2x', (
|
||||
tester,
|
||||
) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..directoriesHandler = () async => {
|
||||
'chat_directories': [
|
||||
'/work',
|
||||
'/Users/alan/repos/pipelines/tmp/flutter-chat-list',
|
||||
],
|
||||
};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-create-server-directory')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(
|
||||
find.text('/Users/alan/repos/pipelines/tmp/flutter-chat-list').last,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('chat-create-name')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino create catalog fits real paths at 320px and 2x', (
|
||||
tester,
|
||||
) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway();
|
||||
await pumpCupertinoChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Server directory:'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// Long enough that a single ellipsised line would visibly lose the reason.
|
||||
const _refusal =
|
||||
'the chat is locked by another operator and cannot be reopened from here; '
|
||||
'refresh the list to see its current state';
|
||||
|
||||
void main() {
|
||||
testWidgets('hide is device-local and Undo restores the row', (tester) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {'chat_sessions': sampleSessions()};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Hide on this device'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open chat'), findsNothing);
|
||||
expect(
|
||||
find.text('Hidden on this device; the chat stays on the server.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(gateway.count('chat_close'), 0);
|
||||
|
||||
await tester.tap(find.text('Undo'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open chat'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Hidden on this device; the chat stays on the server.'),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('New appears only for a recency newer than this device read', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
var updatedAt = 1000;
|
||||
gateway.sessionsHandler = () async => {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 's1',
|
||||
'title': 'Seen chat',
|
||||
'directory': '/work',
|
||||
'updated_at': updatedAt,
|
||||
},
|
||||
],
|
||||
};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
expect(find.text('/work · New'), findsNothing);
|
||||
|
||||
updatedAt = 2000;
|
||||
await tester.tap(find.byKey(const Key('chat-refresh')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('/work · New'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-row-s1')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-refresh')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('/work · New'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a closed row never reports New after newer activity', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
var updatedAt = 1000;
|
||||
var closed = false;
|
||||
gateway.sessionsHandler = () async => {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 's1',
|
||||
'title': 'Seen chat',
|
||||
'directory': '/work',
|
||||
'updated_at': updatedAt,
|
||||
if (closed) 'closed_at': '2026-01-03',
|
||||
},
|
||||
],
|
||||
};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
expect(find.text('/work · New'), findsNothing);
|
||||
|
||||
// Another device moved the chat on and closed it after this device read it.
|
||||
updatedAt = 2000;
|
||||
closed = true;
|
||||
await tester.tap(find.byKey(const Key('chat-refresh')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('/work · New'), findsNothing);
|
||||
expect(find.text('Closed'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Material row refusal is readable at 320px 2x dark', (
|
||||
tester,
|
||||
) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 's4',
|
||||
'title': 'Closed chat',
|
||||
'directory': '/work',
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
],
|
||||
}
|
||||
..failures['chat_reopen'] = _refusal;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reopen'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final paragraph = tester.renderObject<RenderParagraph>(
|
||||
find.byKey(const Key('chat-row-error-s4')),
|
||||
);
|
||||
expect(paragraph.didExceedMaxLines, isFalse);
|
||||
expect(find.text(_refusal), findsOneWidget);
|
||||
// The refusal is its own full-width row, never a `ListTile` subtitle that
|
||||
// would squeeze the passage into the tile's trailing controls.
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byKey(const Key('chat-row-error-s4')),
|
||||
matching: find.byType(ListTile),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino row refusal is readable at 320px 2x dark', (
|
||||
tester,
|
||||
) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 's4',
|
||||
'title': 'Closed chat',
|
||||
'directory': '/work',
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
],
|
||||
}
|
||||
..failures['chat_reopen'] = _refusal;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reopen'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Regression: `CupertinoListTile.subtitle` is wrapped by the SDK in
|
||||
// `DefaultTextStyle(maxLines: 1, overflow: ellipsis)`. The full sentence
|
||||
// must be readable, so it cannot live inside that tile.
|
||||
final paragraph = tester.renderObject<RenderParagraph>(
|
||||
find.byKey(const Key('chat-row-error-s4')),
|
||||
);
|
||||
expect(paragraph.didExceedMaxLines, isFalse);
|
||||
expect(find.text(_refusal), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byKey(const Key('chat-row-error-s4')),
|
||||
matching: find.byType(CupertinoListTile),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
test('hidden ids are local, idempotent and restorable', () {
|
||||
const empty = ChatSessionLocal();
|
||||
final hidden = empty.hide('s1').hide('s1').hide('');
|
||||
expect(hidden.hidden, ['s1']);
|
||||
expect(hidden.isHidden('s1'), isTrue);
|
||||
expect(hidden.restore('s2'), same(hidden));
|
||||
expect(hidden.restore('s1').hidden, isEmpty);
|
||||
});
|
||||
|
||||
test('the read watermark only advances and cannot rewind', () {
|
||||
const empty = ChatSessionLocal();
|
||||
expect(empty.watermark('s1'), 0);
|
||||
final read = empty.read('s1', 200);
|
||||
expect(read.watermark('s1'), 200);
|
||||
expect(read.read('s1', 100), same(read));
|
||||
expect(read.read('', 500), same(read));
|
||||
});
|
||||
|
||||
test('first sight seeds a baseline only when no watermark exists', () {
|
||||
const empty = ChatSessionLocal();
|
||||
final seeded = empty.seed([
|
||||
(id: 's1', updatedAt: 50),
|
||||
(id: 's2', updatedAt: 0),
|
||||
(id: '', updatedAt: 60),
|
||||
]);
|
||||
expect(seeded.watermark('s1'), 50);
|
||||
expect(seeded.watermark('s2'), 0);
|
||||
final newer = seeded.seed([(id: 's1', updatedAt: 90)]);
|
||||
expect(newer.watermark('s1'), 50);
|
||||
});
|
||||
|
||||
test('corrupt stored values decode to the empty model', () {
|
||||
expect(ChatSessionLocal.decode(null).hidden, isEmpty);
|
||||
expect(ChatSessionLocal.decode('not json').seenAt, isEmpty);
|
||||
expect(
|
||||
ChatSessionLocal.decode('{"hidden":"x","seenAt":[]}').hidden,
|
||||
isEmpty,
|
||||
);
|
||||
expect(
|
||||
ChatSessionLocal.decode(
|
||||
'{"hidden":["s1",3],"seenAt":{"s1":"x","s2":7}}',
|
||||
).hidden,
|
||||
['s1'],
|
||||
);
|
||||
expect(ChatSessionLocal.decode('{"seenAt":{"s2":7}}').watermark('s2'), 7);
|
||||
});
|
||||
|
||||
test('the preferences store round-trips the device state', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
const store = SharedPreferencesChatSessionLocalStore();
|
||||
expect((await store.load()).hidden, isEmpty);
|
||||
|
||||
final saved = const ChatSessionLocal().hide('s1').read('s1', 42);
|
||||
await store.save(saved);
|
||||
final loaded = await store.load();
|
||||
expect(loaded.hidden, ['s1']);
|
||||
expect(loaded.watermark('s1'), 42);
|
||||
|
||||
final encoded = loaded.encode();
|
||||
expect(ChatSessionLocal.decode(encoded).hidden, ['s1']);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('create refusal keeps the dialog and retries the same intent', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
final bodies = <JsonMap>[];
|
||||
JsonMap? opened;
|
||||
gateway.createHandler = (fields) async {
|
||||
final body = fields['chat_create']! as JsonMap;
|
||||
bodies.add(body);
|
||||
if (bodies.length == 1) {
|
||||
throw StateError('no chat harness is available on this server');
|
||||
}
|
||||
return {
|
||||
'chat_session': {'id': 'created', 'title': body['title']},
|
||||
};
|
||||
};
|
||||
await pumpMaterialChat(
|
||||
tester,
|
||||
gateway,
|
||||
onOpen: (session) => opened = session,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-create-name')),
|
||||
'Probe chat',
|
||||
);
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('chat-create-name')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Bad state: no chat harness is available on this server'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(opened, isNull);
|
||||
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(bodies, hasLength(2));
|
||||
expect(bodies[1]['operation_id'], bodies[0]['operation_id']);
|
||||
expect(bodies[1]['title'], 'Probe chat');
|
||||
expect(find.byKey(const Key('chat-create-name')), findsNothing);
|
||||
expect(opened?['id'], 'created');
|
||||
expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2));
|
||||
});
|
||||
|
||||
testWidgets('double submit sends one create with one operation id', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
final reply = Completer<JsonMap>();
|
||||
gateway.createHandler = (_) => reply.future;
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Creating…'), warnIfMissed: false);
|
||||
await tester.pump();
|
||||
expect(gateway.count('chat_create'), 1);
|
||||
|
||||
reply.complete({
|
||||
'chat_session': {'id': 'created'},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.count('chat_create'), 1);
|
||||
});
|
||||
|
||||
testWidgets('rename seeds the current title and refreshes from the server', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
var sessions = sampleSessions();
|
||||
gateway.sessionsHandler = () async => {'chat_sessions': sessions};
|
||||
gateway.actionHandler = (type, fields) async {
|
||||
if (type == 'chat_rename') {
|
||||
final body = fields['chat_rename']! as JsonMap;
|
||||
sessions = [
|
||||
for (final session in sessions)
|
||||
if (session['id'] == body['session_id'])
|
||||
{...session, 'title': body['title']}
|
||||
else
|
||||
session,
|
||||
];
|
||||
}
|
||||
return const {};
|
||||
};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Rename…'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(const Key('chat-rename-field')))
|
||||
.controller!
|
||||
.text,
|
||||
'Open chat',
|
||||
);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-rename-field')),
|
||||
' Renamed chat ',
|
||||
);
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.lastFields('chat_rename'), {
|
||||
'chat_rename': {'session_id': 's2', 'title': 'Renamed chat'},
|
||||
});
|
||||
expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2));
|
||||
expect(find.text('Renamed chat'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('star toggles one field and refreshes the rows', (tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
var sessions = sampleSessions();
|
||||
gateway.sessionsHandler = () async => {'chat_sessions': sessions};
|
||||
gateway.actionHandler = (type, fields) async {
|
||||
if (type == 'chat_star') {
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
sessions = [
|
||||
for (final session in sessions)
|
||||
if (session['id'] == body['session_id'])
|
||||
{...session, 'starred': body['starred']}
|
||||
else
|
||||
session,
|
||||
];
|
||||
}
|
||||
return const {};
|
||||
};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-star-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.lastFields('chat_star'), {
|
||||
'chat_query': {'session_id': 's2', 'starred': true},
|
||||
});
|
||||
expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-star-s2')),
|
||||
matching: find.byIcon(Icons.star),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('close refusal stays visible on its row', (tester) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {'chat_sessions': sampleSessions()}
|
||||
..failures['chat_close'] = 'another operator already closed this chat';
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Close chat…'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Close chat'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('chat-row-error-s2')), findsOneWidget);
|
||||
expect(
|
||||
find.text('another operator already closed this chat'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(gateway.count('chat_sessions'), 1);
|
||||
});
|
||||
|
||||
testWidgets('a create reply without chat_session shows the web wording', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway()..createReply = const {};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text('The server did not return the new chat session.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('Bad state'), findsNothing);
|
||||
expect(find.byKey(const Key('chat-create-name')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('rename refusal stays in the dialog, not on the row', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {'chat_sessions': sampleSessions()}
|
||||
..failures['chat_rename'] = 'a title with usable text is required';
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Rename…'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' x ');
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('chat-rename-field')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-row-error-s2')), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-row-error-s2')), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
void main() {
|
||||
@@ -18,7 +19,11 @@ void main() {
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ChatSessionsScreen(gateway: gateway, onOpen: (_) {}),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
@@ -56,7 +61,11 @@ void main() {
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ChatSessionsScreen(gateway: gateway, onOpen: (_) {}),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
@@ -3,9 +3,23 @@ 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/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart';
|
||||
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// In-memory device-local store; widget tests never read real preferences.
|
||||
class MemoryChatSessionLocalStore implements ChatSessionLocalStore {
|
||||
MemoryChatSessionLocalStore([this.state]);
|
||||
|
||||
ChatSessionLocal? state;
|
||||
|
||||
@override
|
||||
Future<ChatSessionLocal> load() async => state ?? const ChatSessionLocal();
|
||||
|
||||
@override
|
||||
Future<void> save(ChatSessionLocal next) async => state = next;
|
||||
}
|
||||
|
||||
List<JsonMap> sampleSessions() => [
|
||||
{'id': 's1', 'title': 'Starred chat', 'directory': '/work', 'starred': true},
|
||||
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
|
||||
@@ -33,7 +47,11 @@ Future<void> pumpMaterialChat(
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: ChatSessionsScreen(gateway: gateway, onOpen: onOpen ?? (_) {}),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: onOpen ?? (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -46,7 +64,11 @@ Future<void> pumpCupertinoChat(
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: ChatSessionsScreen(gateway: gateway, onOpen: onOpen ?? (_) {}),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: onOpen ?? (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -62,7 +84,11 @@ Future<void> pumpIosMaterialChat(
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.iOS),
|
||||
home: ChatSessionsScreen(gateway: gateway, onOpen: onOpen ?? (_) {}),
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: onOpen ?? (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -75,3 +101,13 @@ void usePhoneSurface(WidgetTester tester) {
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
}
|
||||
|
||||
/// The project's smallest supported acceptance size with 2x text.
|
||||
void useSmallTextSurface(WidgetTester tester) {
|
||||
tester.view.physicalSize = const Size(320, 640);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// The hide report is a floating overlay, not a body row: at the project's
|
||||
/// smallest size with 2x text it must stay on screen and leave the list usable.
|
||||
void main() {
|
||||
testWidgets('Material Undo bar fits 320px at 2x', (tester) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
|
||||
],
|
||||
};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Hide on this device'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('chat-undo-hide')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Hidden on this device; the chat stays on the server.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.text('Undo'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open chat'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino Undo bar fits 320px at 2x', (tester) async {
|
||||
useSmallTextSurface(tester);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
|
||||
],
|
||||
};
|
||||
await pumpCupertinoChat(tester, gateway);
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Hide on this device'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('chat-undo-hide')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.text('Undo'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open chat'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -2,16 +2,20 @@ import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
|
||||
/// Scripted gateway for session-browser widget tests.
|
||||
class FakeChatGateway implements ApiGateway {
|
||||
final calls = <({String type, JsonMap fields})>[];
|
||||
final pendingSessions = Queue<Completer<JsonMap>>();
|
||||
final failures = <String, String>{};
|
||||
JsonMap sessionsReply = const {'chat_sessions': []};
|
||||
Future<JsonMap> Function()? sessionsHandler;
|
||||
JsonMap createReply = const {
|
||||
'chat_session': {'id': 'created', 'title': 'New chat'},
|
||||
};
|
||||
Future<JsonMap> Function(JsonMap fields)? createHandler;
|
||||
Future<JsonMap> Function(String type, JsonMap fields)? actionHandler;
|
||||
Future<JsonMap> Function()? directoriesHandler;
|
||||
Future<JsonMap> Function()? backendsHandler;
|
||||
|
||||
@@ -21,6 +25,8 @@ class FakeChatGateway implements ApiGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
calls.add((type: type, fields: fields));
|
||||
final failure = failures[type];
|
||||
if (failure != null) return Future.error(ProtocolError(failure));
|
||||
switch (type) {
|
||||
case 'chat_sessions':
|
||||
if (pendingSessions.isNotEmpty) {
|
||||
@@ -39,8 +45,10 @@ class FakeChatGateway implements ApiGateway {
|
||||
'chat_backends': ['opencode', 'codex'],
|
||||
});
|
||||
case 'chat_create':
|
||||
if (createHandler != null) return createHandler!(fields);
|
||||
return Future.value(createReply);
|
||||
default:
|
||||
if (actionHandler != null) return actionHandler!(type, fields);
|
||||
return Future.value(const {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user