App: dark-aware HTML views, run cards, changed/missing file notes, one card width, dense diff rows
show_html documents that declare dark support follow the app theme; others stay light. Tool description and skill docs say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_html_theme.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_html_view.dart';
|
||||
|
||||
const _aware = '''<!doctype html><html><head><style>
|
||||
body{background:#fff;color:#111}
|
||||
@media (prefers-color-scheme: dark){body{background:#111;color:#eee}}
|
||||
@media (prefers-color-scheme:light){.hint{display:block}}
|
||||
</style></head><body>Hi</body></html>''';
|
||||
|
||||
const _plain = '<!DOCTYPE html><body style="color:#222">No dark styles</body>';
|
||||
|
||||
void main() {
|
||||
test('only a document that supports dark mode is shown dark', () {
|
||||
expect(artifactHtmlSupportsDark(_aware), isTrue);
|
||||
expect(artifactHtmlSupportsDark(_plain), isFalse);
|
||||
expect(
|
||||
artifactHtmlSupportsDark('<p style="color: light-dark(#000, #fff)">'),
|
||||
isTrue,
|
||||
);
|
||||
expect(artifactHtmlScheme(_aware, dark: true), 'dark');
|
||||
expect(artifactHtmlScheme(_aware, dark: false), 'light');
|
||||
expect(artifactHtmlScheme(_plain, dark: true), 'light');
|
||||
});
|
||||
|
||||
test('a dark-aware document gets the app scheme and fixed queries', () {
|
||||
final dark = artifactHtmlForScheme(_aware, dark: true);
|
||||
expect(
|
||||
dark,
|
||||
contains('<head><meta name="color-scheme" content="dark"><style>'),
|
||||
);
|
||||
expect(dark, contains('@media (min-width: 0px){body{background:#111'));
|
||||
expect(dark, contains('@media (max-width: -1px){.hint'));
|
||||
expect(dark, isNot(contains('prefers-color-scheme')));
|
||||
|
||||
final light = artifactHtmlForScheme(_aware, dark: false);
|
||||
expect(light, contains('<meta name="color-scheme" content="light">'));
|
||||
expect(light, contains('@media (max-width: -1px){body{background:#111'));
|
||||
expect(light, contains('@media (min-width: 0px){.hint'));
|
||||
});
|
||||
|
||||
test('a document without dark styles stays light, after its doctype', () {
|
||||
final shown = artifactHtmlForScheme(_plain, dark: true);
|
||||
expect(
|
||||
shown,
|
||||
'<!DOCTYPE html><meta name="color-scheme" content="light">'
|
||||
'<body style="color:#222">No dark styles</body>',
|
||||
);
|
||||
expect(
|
||||
artifactHtmlForScheme('<svg viewBox="0 0 1 1"></svg>', dark: true),
|
||||
startsWith('<meta name="color-scheme" content="light"><svg'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the HTML view follows the app theme, not the system', (
|
||||
tester,
|
||||
) async {
|
||||
bool? seen;
|
||||
Future<void> pump(ThemeMode mode) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(brightness: Brightness.light),
|
||||
darkTheme: ThemeData(brightness: Brightness.dark),
|
||||
themeMode: mode,
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
seen = artifactHtmlDark(context);
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
// The theme change animates; read it once settled.
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
await pump(ThemeMode.dark);
|
||||
expect(seen, isTrue);
|
||||
await pump(ThemeMode.light);
|
||||
expect(seen, isFalse);
|
||||
});
|
||||
}
|
||||
@@ -58,6 +58,25 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('a replaced card keeps its place in the transcript', () {
|
||||
final held = [_item('a', 100, kind: 'run'), _item('b', 200)];
|
||||
final replaced = {
|
||||
..._item('a', 100, kind: 'run'),
|
||||
'updated_at': 300,
|
||||
'title': 'A, now finished',
|
||||
};
|
||||
final merged = mergeChatShownItems(held, [replaced]);
|
||||
final rows = withChatShownItems(
|
||||
[
|
||||
{'kind': 'user', 'key': 'u', 'created_at': 150},
|
||||
],
|
||||
merged,
|
||||
hasMore: false,
|
||||
);
|
||||
expect(_shape(rows), ['shown:a', 'user:u', 'shown:b']);
|
||||
expect((rows.first['item'] as Map)['title'], 'A, now finished');
|
||||
});
|
||||
|
||||
group('withChatShownItems', () {
|
||||
final messages = [
|
||||
_message('u1', 'user', 100),
|
||||
|
||||
@@ -144,4 +144,51 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a head revision and paths are named in the comparison', (
|
||||
tester,
|
||||
) async {
|
||||
final item = _item();
|
||||
final diff = item['diff'] as JsonMap;
|
||||
diff['head_revision'] = 'pipelines/run-123';
|
||||
diff['paths'] = ['app/lib', '*.go', 'docs', 'web'];
|
||||
await _pump(tester, item);
|
||||
expect(
|
||||
find.text(
|
||||
'pipelines · pipelines/run-123 vs main · app/lib, *.go, docs +1',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('file rows are one dense line each', (tester) async {
|
||||
await _pump(tester, _item());
|
||||
final row = find.byType(ChangeFileRow).first;
|
||||
expect(tester.getSize(row).height, lessThanOrEqualTo(48));
|
||||
// The counts share the path's line instead of a subtitle below it.
|
||||
expect(
|
||||
tester.getCenter(find.text('app/lib/a.dart')).dy,
|
||||
closeTo(tester.getCenter(row).dy, 2),
|
||||
);
|
||||
});
|
||||
|
||||
test('run items are a recorded kind and show_run calls are hidden', () {
|
||||
expect(chatShownKinds, contains('run'));
|
||||
expect(
|
||||
chatPipelinesToolRepresented({
|
||||
'type': 'tool',
|
||||
'name': 'pipelines_show_run',
|
||||
'state': {'status': 'completed'},
|
||||
}),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
chatPipelinesToolRepresented({
|
||||
'type': 'tool',
|
||||
'name': 'mcp__pipelines__schedule_followup',
|
||||
'state': {'status': 'completed'},
|
||||
}),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
import 'dart:convert';
|
||||
|
||||
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_viewer_fetch.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_run_opener.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_viewer.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_card.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_run_card.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_surface.dart';
|
||||
|
||||
const _png =
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
|
||||
|
||||
final _start = DateTime.utc(2026, 12, 1, 9);
|
||||
|
||||
JsonMap _run(String status, {int? finishedMinutes, String stage = 'review'}) =>
|
||||
{
|
||||
'id': 'r',
|
||||
'kind': 'run',
|
||||
'created_at': 1,
|
||||
'run': {
|
||||
'id': 42,
|
||||
'pipeline': 'Feature',
|
||||
'title': 'Add show_run',
|
||||
'status': status,
|
||||
'current_stage': stage,
|
||||
'started_at': _start.millisecondsSinceEpoch,
|
||||
if (finishedMinutes != null)
|
||||
'finished_at': _start
|
||||
.add(Duration(minutes: finishedMinutes))
|
||||
.millisecondsSinceEpoch,
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
late FileUrlResolver original;
|
||||
final fetched = <Uri>[];
|
||||
final opened = <int>[];
|
||||
setUp(() {
|
||||
original = resolveFileUrls;
|
||||
resolveFileUrls = (endpoint, path) => fileUrls(endpoint, path);
|
||||
fetched.clear();
|
||||
opened.clear();
|
||||
});
|
||||
tearDown(() => resolveFileUrls = original);
|
||||
|
||||
final viewer = FilesViewer(
|
||||
fetch: (uri) async {
|
||||
fetched.add(uri);
|
||||
final path = uri.queryParameters['path'] ?? '';
|
||||
return ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: path.endsWith('.png')
|
||||
? base64Decode(_png)
|
||||
: utf8.encode('line one\n'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Future<void> pump(WidgetTester tester, Widget card) async {
|
||||
await tester.binding.setSurfaceSize(const Size(1400, 900));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
await tester.pumpWidget(
|
||||
ChatRunOpener(
|
||||
openRun: opened.add,
|
||||
child: MaterialApp(
|
||||
home: Scaffold(body: SingleChildScrollView(child: card)),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Widget shown(JsonMap item) => ChatShownCard(
|
||||
row: {'kind': 'shown', 'item': item},
|
||||
endpoint: 'ws://peer.example.test/peers/abc/connect',
|
||||
viewer: viewer,
|
||||
htmlBuilder: (_, _) => const SizedBox.expand(),
|
||||
);
|
||||
|
||||
testWidgets('a changed live file says so and still opens', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
shown({
|
||||
'id': 'c',
|
||||
'kind': 'file',
|
||||
'path': '/home/demo/notes.txt',
|
||||
'size': 40,
|
||||
'state': 'changed',
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Changed since shown'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-shown-file-lines')), findsOneWidget);
|
||||
expect(find.byType(InkWell), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a missing file says so and loads nothing', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
shown({
|
||||
'id': 'm',
|
||||
'kind': 'image',
|
||||
'path': '/home/demo/gone.png',
|
||||
'size': 10,
|
||||
'state': 'missing',
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No longer exists'), findsOneWidget);
|
||||
expect(find.byType(Image), findsNothing);
|
||||
expect(fetched, isEmpty);
|
||||
expect(find.byType(InkWell), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a fetched web image draws its snapshot and names the address', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(
|
||||
tester,
|
||||
shown({
|
||||
'id': 'w',
|
||||
'kind': 'image',
|
||||
'path': '/home/demo/.local/share/pipelines/chat-shown/s/w/cat.png',
|
||||
'name': 'cat.png',
|
||||
'snapshot': true,
|
||||
'url': 'https://images.example.test/cat.png',
|
||||
}),
|
||||
);
|
||||
expect(find.text('images.example.test'), findsOneWidget);
|
||||
expect(find.text('https://images.example.test/cat.png'), findsOneWidget);
|
||||
expect(find.text('No longer exists'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a running run ticks its duration and opens the run', (
|
||||
tester,
|
||||
) async {
|
||||
var now = _start.add(const Duration(minutes: 2, seconds: 5));
|
||||
await pump(tester, ChatShownRunCard(item: _run('running'), now: () => now));
|
||||
expect(find.text('Add show_run'), findsOneWidget);
|
||||
expect(find.text('Feature'), findsOneWidget);
|
||||
expect(find.text('Running'), findsOneWidget);
|
||||
expect(find.text('#42 · review · 2m 5s'), findsOneWidget);
|
||||
expect(find.bySemanticsLabel(RegExp('Shown run Add show_run')), findsOne);
|
||||
now = now.add(const Duration(seconds: 3));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(find.text('#42 · review · 2m 8s'), findsOneWidget);
|
||||
await tester.tap(find.text('Add show_run'));
|
||||
expect(opened, [42]);
|
||||
});
|
||||
|
||||
testWidgets('a finished run shows its outcome and final duration', (
|
||||
tester,
|
||||
) async {
|
||||
final item = _run('failed', finishedMinutes: 7);
|
||||
(item['run'] as Map)['outcome'] = 'tests_failed';
|
||||
await pump(tester, shown(item));
|
||||
expect(find.text('Failed · tests_failed'), findsOneWidget);
|
||||
expect(find.text('#42 · 7m 0s'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.error_outline), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a replaced run item updates the same card in place', (
|
||||
tester,
|
||||
) async {
|
||||
final now = _start.add(const Duration(minutes: 1));
|
||||
Widget card(JsonMap item) => ChatShownRunCard(
|
||||
key: const ValueKey('chat-shown-r'),
|
||||
item: item,
|
||||
now: () => now,
|
||||
);
|
||||
await pump(tester, card(_run('running')));
|
||||
final state = tester.state(find.byType(ChatShownRunCard));
|
||||
await pump(tester, card(_run('succeeded', finishedMinutes: 4)));
|
||||
expect(tester.state(find.byType(ChatShownRunCard)), same(state));
|
||||
expect(find.text('Succeeded'), findsOneWidget);
|
||||
expect(find.text('#42 · 4m 0s'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('file, image, view, diff and run cards share one width', (
|
||||
tester,
|
||||
) async {
|
||||
final items = <JsonMap>[
|
||||
{'id': 'f', 'kind': 'file', 'path': '/home/demo/a.txt', 'size': 1},
|
||||
{'id': 'i', 'kind': 'image', 'path': '/home/demo/a.png', 'size': 1},
|
||||
{'id': 'h', 'kind': 'html', 'html': '<p>x</p>', 'html_bytes': 8},
|
||||
{
|
||||
'id': 'd',
|
||||
'kind': 'diff',
|
||||
'diff': {'repo': '/r', 'files': 0, 'additions': 0, 'deletions': 0},
|
||||
},
|
||||
_run('running'),
|
||||
];
|
||||
for (final item in items) {
|
||||
await pump(tester, shown(item));
|
||||
final card = find.byType(Card);
|
||||
expect(card, findsOneWidget, reason: '${item['kind']}');
|
||||
expect(
|
||||
tester.getSize(card).width,
|
||||
chatShownCardMaxWidth,
|
||||
reason: '${item['kind']}',
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user