Merge branch 'main' into flutter/chat-activity
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import 'dart:async';
|
||||
|
||||
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/attention/notify/notification_controller.dart';
|
||||
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
|
||||
import 'package:pipelines_app/features/attention/ui/needs_you_runs_heading.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_notifications_section.dart';
|
||||
|
||||
import 'notification_test_support.dart';
|
||||
|
||||
/// The manager-owned wiring: the bell surface publishes live transitions and
|
||||
/// Settings renders the same controller's permission.
|
||||
void main() {
|
||||
testWidgets('a seed never notifies and one live transition notifies once', (
|
||||
tester,
|
||||
) async {
|
||||
final bridge = FakeNotificationBridge(permission: 'granted');
|
||||
final notify = NotificationController(
|
||||
store: MemoryNotificationStore(),
|
||||
bridge: bridge,
|
||||
);
|
||||
final frames = StreamController<JsonMap>.broadcast();
|
||||
addTearDown(frames.close);
|
||||
addTearDown(notify.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: NeedsYouRunsHeading(
|
||||
rows: <JsonMap>[runSummary(1, 'failed'), runSummary(2, 'running')],
|
||||
frames: frames.stream,
|
||||
onOpen: (_) {},
|
||||
now: () => attentionNow,
|
||||
notifications: notify,
|
||||
cupertino: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
// Let the persisted ledger read and the seed publish settle. A plain
|
||||
// `Future.delayed` would deadlock inside the widget test's fake clock.
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
expect(bridge.shown, isEmpty, reason: 'the initial list is a seed');
|
||||
expect(notify.permission.name, 'granted');
|
||||
|
||||
frames.add(runFrame(2, 'failed'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
expect(bridge.shown, hasLength(1));
|
||||
expect(bridge.shown.single.runId, 2);
|
||||
|
||||
// The same transition instance again (a reconnect reseed of that frame)
|
||||
// must not announce twice.
|
||||
frames.add(runFrame(2, 'failed'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
expect(bridge.shown, hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('Settings renders the platform permission from the controller', (
|
||||
tester,
|
||||
) async {
|
||||
final notify = NotificationController(
|
||||
store: MemoryNotificationStore(),
|
||||
bridge: FakeNotificationBridge(permission: 'granted'),
|
||||
);
|
||||
addTearDown(notify.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SettingsNotificationsSection(controller: notify),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Notifications'), findsWidgets);
|
||||
|
||||
// A denied platform answer shows its own words and no Enable action.
|
||||
final denied = NotificationController(
|
||||
store: MemoryNotificationStore(),
|
||||
bridge: FakeNotificationBridge(permission: 'denied'),
|
||||
);
|
||||
addTearDown(denied.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SettingsNotificationsSection(controller: denied),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Notifications'), findsWidgets);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
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/pipelines/pipeline_format.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_summary_fields.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
|
||||
/// A run whose latest visit recorded every summary fact, plus reported usage.
|
||||
JsonMap recordedRunFixture() => <String, dynamic>{
|
||||
'id': 51,
|
||||
'title': 'Summary run',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'current_stage': 'review',
|
||||
'created_at': '2026-10-19T09:30:00Z',
|
||||
'finished_at': '2026-10-19T09:32:05Z',
|
||||
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||
'steps': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'provider': 'openai',
|
||||
'model': 'gpt-luna',
|
||||
'target': 'review',
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'review',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'provider': 'anthropic',
|
||||
'model': 'claude-x',
|
||||
'target': '#success',
|
||||
'verdict': <String, dynamic>{
|
||||
'option': 'approve',
|
||||
'reason': 'Looks good.',
|
||||
},
|
||||
},
|
||||
],
|
||||
'usage': <String, dynamic>{
|
||||
'stages': 1,
|
||||
'tokens_total': 123,
|
||||
'tokens_known_stages': 1,
|
||||
'tokens_in': 100,
|
||||
'tokens_out': 23,
|
||||
'split_known': true,
|
||||
'cost_known_stages': 1,
|
||||
'cost_usd': 0.5,
|
||||
},
|
||||
};
|
||||
|
||||
/// A run that recorded none of the summary facts and reported no usage.
|
||||
JsonMap absentRunFixture() => <String, dynamic>{
|
||||
'id': 51,
|
||||
'title': 'Sparse run',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'current_stage': ' ',
|
||||
'created_at': '',
|
||||
'finished_at': '',
|
||||
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||
'steps': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'provider': ' ',
|
||||
'model': '',
|
||||
'target': ' ',
|
||||
'verdict': null,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const summaryFacts = [
|
||||
'Stage',
|
||||
'Started',
|
||||
'Finished',
|
||||
'Duration',
|
||||
'Provider/model',
|
||||
'Target',
|
||||
'Verdict',
|
||||
];
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} summary renders each recorded field', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(
|
||||
tester,
|
||||
platform,
|
||||
run: recordedRunFixture(),
|
||||
size: const Size(900, 1600),
|
||||
);
|
||||
|
||||
for (final label in summaryFacts) {
|
||||
expect(find.text(label), findsOneWidget, reason: label);
|
||||
}
|
||||
expect(find.text('review'), findsOneWidget);
|
||||
final started = formatLocalTimestamp('2026-10-19T09:30:00Z');
|
||||
final finished = formatLocalTimestamp('2026-10-19T09:32:05Z');
|
||||
expect(find.text(started!), findsOneWidget);
|
||||
expect(find.text(finished!), findsOneWidget);
|
||||
expect(find.text('2m 5s'), findsOneWidget);
|
||||
expect(find.text('anthropic / claude-x'), findsOneWidget);
|
||||
expect(find.text('#success'), findsOneWidget);
|
||||
expect(find.text('approve\nLooks good.'), findsOneWidget);
|
||||
|
||||
// Tokens and cost keep their existing Summary home and exact values.
|
||||
await tester.ensureVisible(find.text('Metrics'));
|
||||
await tester.tap(find.text('Metrics'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('123'), findsOneWidget);
|
||||
expect(find.text('100'), findsOneWidget);
|
||||
expect(find.text('23'), findsOneWidget);
|
||||
expect(find.text('\$0.500000'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} summary states absent facts as unknown', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(
|
||||
tester,
|
||||
platform,
|
||||
run: absentRunFixture(),
|
||||
size: const Size(900, 1600),
|
||||
);
|
||||
|
||||
for (final label in summaryFacts) {
|
||||
expect(find.text(label), findsOneWidget, reason: label);
|
||||
}
|
||||
expect(
|
||||
find.text(summaryUnknownValue),
|
||||
findsNWidgets(summaryFacts.length),
|
||||
);
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('false'), findsNothing);
|
||||
|
||||
await tester.ensureVisible(find.text('Metrics'));
|
||||
await tester.tap(find.text('Metrics'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No reported usage.'), findsOneWidget);
|
||||
expect(find.text('0'), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
test('visit facts come from the current stage latest visit', () {
|
||||
final run = recordedRunFixture()..['current_stage'] = 'build';
|
||||
final fields = detailSummaryFields(run);
|
||||
String value(String label) =>
|
||||
fields.firstWhere((field) => field.label == label).value;
|
||||
expect(value('Provider/model'), 'openai / gpt-luna');
|
||||
expect(value('Target'), 'review');
|
||||
expect(value('Verdict'), 'Unavailable');
|
||||
});
|
||||
|
||||
test('a current stage without a visit records no visit facts', () {
|
||||
final run = recordedRunFixture()..['current_stage'] = 'audit';
|
||||
final fields = detailSummaryFields(run);
|
||||
for (final label in ['Provider/model', 'Target', 'Verdict']) {
|
||||
expect(
|
||||
fields.firstWhere((field) => field.label == label).value,
|
||||
'Unavailable',
|
||||
reason: label,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('unknown wording is the web usage word and never zero', () {
|
||||
expect(summaryUnknownValue, 'Unavailable');
|
||||
final fields = detailSummaryFields(absentRunFixture());
|
||||
expect(fields.map((field) => field.label), summaryFacts);
|
||||
expect(fields.every((field) => field.value == 'Unavailable'), isTrue);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/search/domain/search_target.dart';
|
||||
|
||||
JsonMap pipelineHit([JsonMap overrides = const {}]) => {
|
||||
'kind': 'pipeline',
|
||||
'target': 'pipeline:7',
|
||||
'pipeline': {
|
||||
'id': 7,
|
||||
'name': 'release',
|
||||
'version': 3,
|
||||
'stages': 4,
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
JsonMap versionHit([JsonMap overrides = const {}]) => {
|
||||
'kind': 'version',
|
||||
'target': 'pipeline:9:v2',
|
||||
'version': {
|
||||
'pipeline_id': 9,
|
||||
'version': 2,
|
||||
'content_hash': 'abc',
|
||||
'created_at': '2026-01-01T00:00:00Z',
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
JsonMap runHit([JsonMap overrides = const {}]) => {
|
||||
'kind': 'run',
|
||||
'target': 'run:11',
|
||||
'run': {
|
||||
'id': 11,
|
||||
'pipeline_name': 'release',
|
||||
'status': 'succeeded',
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
JsonMap stepHit([JsonMap overrides = const {}]) => {
|
||||
'kind': 'step',
|
||||
'target': 'run:11:4',
|
||||
'step': {
|
||||
'run_id': 11,
|
||||
'sequence': 4,
|
||||
'stage': 'builder',
|
||||
'visit': 2,
|
||||
'outcome': 'success',
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
JsonMap fieldHit([JsonMap overrides = const {}]) => {
|
||||
'kind': 'field',
|
||||
'target': 'run:11:4:output',
|
||||
'matched_field': 'output',
|
||||
'field': {
|
||||
'run_id': 11,
|
||||
'sequence': 4,
|
||||
'field': 'output',
|
||||
'snippet': 'the release is ready',
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
JsonMap artifactHit([JsonMap overrides = const {}]) => {
|
||||
'kind': 'artifact',
|
||||
'target': '/artifacts/11/4/notes.md',
|
||||
'artifact': {
|
||||
'run_id': 11,
|
||||
'sequence': 4,
|
||||
'name': 'notes.md',
|
||||
'content_type': 'text/markdown',
|
||||
'size_bytes': 2048,
|
||||
'url': '/artifacts/11/4/notes.md',
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
SearchTarget resolved(JsonMap hit) {
|
||||
final resolution = searchTargetFor(hit);
|
||||
expect(resolution, isA<ResolvedSearchTarget>(), reason: '$hit');
|
||||
return (resolution as ResolvedSearchTarget).target;
|
||||
}
|
||||
|
||||
UnresolvedSearchTarget unresolved(JsonMap hit) {
|
||||
final resolution = searchTargetFor(hit);
|
||||
expect(resolution, isA<UnresolvedSearchTarget>(), reason: '$hit');
|
||||
return resolution as UnresolvedSearchTarget;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('every recorded hit kind serialises back to its server token', () {
|
||||
final pipeline = resolved(pipelineHit());
|
||||
expect(pipeline, isA<SearchPipelineTarget>());
|
||||
expect((pipeline as SearchPipelineTarget).pipelineId, 7);
|
||||
expect(pipeline.kind, SearchTargetKind.pipeline);
|
||||
expect(pipeline.wire, pipelineHit()['target']);
|
||||
|
||||
final version = resolved(versionHit());
|
||||
expect(version, isA<SearchVersionTarget>());
|
||||
expect((version as SearchVersionTarget).pipelineId, 9);
|
||||
expect(version.version, 2);
|
||||
expect(version.wire, versionHit()['target']);
|
||||
|
||||
final run = resolved(runHit());
|
||||
expect(run, isA<SearchRunTarget>());
|
||||
expect((run as SearchRunTarget).runId, 11);
|
||||
expect(run.wire, runHit()['target']);
|
||||
|
||||
final step = resolved(stepHit());
|
||||
expect(step, isA<SearchStepTarget>());
|
||||
expect((step as SearchStepTarget).runId, 11);
|
||||
expect(step.sequence, 4);
|
||||
expect(step.stage, 'builder');
|
||||
expect(step.visit, 2);
|
||||
expect(step.wire, stepHit()['target']);
|
||||
|
||||
final field = resolved(fieldHit());
|
||||
expect(field, isA<SearchFieldTarget>());
|
||||
expect((field as SearchFieldTarget).runId, 11);
|
||||
expect(field.sequence, 4);
|
||||
expect(field.field, 'output');
|
||||
expect(field.wire, fieldHit()['target']);
|
||||
|
||||
final artifact = resolved(artifactHit());
|
||||
expect(artifact, isA<SearchArtifactTarget>());
|
||||
expect((artifact as SearchArtifactTarget).url, '/artifacts/11/4/notes.md');
|
||||
expect(artifact.runId, 11);
|
||||
expect(artifact.sequence, 4);
|
||||
expect(artifact.wire, artifactHit()['target']);
|
||||
});
|
||||
|
||||
test('a payload without its identity is reported as unresolvable', () {
|
||||
expect(unresolved({}).reason, 'no recorded target payload');
|
||||
expect(unresolved(pipelineHit({'id': null})).reason, contains('pipeline'));
|
||||
expect(
|
||||
unresolved(versionHit({'pipeline_id': 9, 'version': 0})).reason,
|
||||
contains('version'),
|
||||
);
|
||||
expect(unresolved(runHit({'id': 0})).reason, contains('run'));
|
||||
expect(
|
||||
unresolved(stepHit({'run_id': 11, 'sequence': 0})).reason,
|
||||
contains('step'),
|
||||
);
|
||||
expect(
|
||||
unresolved(fieldHit({'run_id': 11, 'sequence': 4, 'field': ' '})).reason,
|
||||
contains('field'),
|
||||
);
|
||||
expect(unresolved(artifactHit({'url': ' '})).reason, contains('artifact'));
|
||||
expect(
|
||||
unresolved({'kind': 'future_kind', 'target': 'widget:7'}).reason,
|
||||
'no recorded target payload',
|
||||
);
|
||||
});
|
||||
|
||||
test('a hit without a matching recorded token is unresolvable', () {
|
||||
expect(
|
||||
unresolved({
|
||||
'kind': 'run',
|
||||
'run': {'id': 11},
|
||||
}).reason,
|
||||
'recorded target is missing',
|
||||
);
|
||||
expect(
|
||||
unresolved({...pipelineHit(), 'target': 'pipeline:8'}).reason,
|
||||
contains('does not match'),
|
||||
);
|
||||
expect(
|
||||
unresolved({...stepHit(), 'target': 'run:11:5'}).reason,
|
||||
contains('does not match'),
|
||||
);
|
||||
});
|
||||
|
||||
test('a serialised target parses back to the same identity', () {
|
||||
final targets = <SearchTarget>[
|
||||
resolved(pipelineHit()),
|
||||
resolved(versionHit()),
|
||||
resolved(runHit()),
|
||||
resolved(stepHit()),
|
||||
resolved(fieldHit()),
|
||||
resolved(artifactHit()),
|
||||
];
|
||||
for (final target in targets) {
|
||||
final parsed = SearchTarget.fromWire(target.wire);
|
||||
expect(parsed, target, reason: target.wire);
|
||||
expect(parsed!.wire, target.wire, reason: target.wire);
|
||||
}
|
||||
|
||||
// The token names the visit's run and sequence, not its stage/visit facts.
|
||||
final step = resolved(stepHit()) as SearchStepTarget;
|
||||
final parsed = SearchTarget.fromWire(step.wire) as SearchStepTarget;
|
||||
expect(parsed, step);
|
||||
expect(parsed.stage, isNull);
|
||||
expect(parsed.visit, isNull);
|
||||
});
|
||||
|
||||
test('a token outside the server vocabulary names no target', () {
|
||||
for (final token in const [
|
||||
'',
|
||||
' ',
|
||||
'widget:7',
|
||||
'pipeline:0',
|
||||
'pipeline:7:v0',
|
||||
'run:11:0',
|
||||
'run:11:4:',
|
||||
'http://example.test/not-an-artifact',
|
||||
]) {
|
||||
expect(SearchTarget.fromWire(token), isNull, reason: token);
|
||||
}
|
||||
expect(SearchTarget.fromWire('run:11'), const SearchRunTarget(11));
|
||||
expect(
|
||||
SearchTarget.fromWire('pipeline:7:v2'),
|
||||
const SearchVersionTarget(7, 2),
|
||||
);
|
||||
expect(SearchTarget.fromWire('pipeline:7'), const SearchPipelineTarget(7));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user