Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Merge batch 11-04 b0815: #2866 (#2870)

0xken15f3a82b94bd01
diff --git a/desktop/lib/super_tabs/backlog.dart b/desktop/lib/super_tabs/backlog.dart
index 1103d5a4e..9771252a9 100644
--- a/desktop/lib/super_tabs/backlog.dart
+++ b/desktop/lib/super_tabs/backlog.dart
@@ -18,11 +18,24 @@ enum SuperTabBacklogGroup {
final String label;
}
-/// Which group [task] is listed in; null for a cancelled task, which is not
-/// listed. A wait on a person is "Waiting on someone", as the sidebar's groups
-/// read it (task_groups.dart, Huy); the task's own line says on whom.
-SuperTabBacklogGroup? superTabBacklogGroupOf(SuperTabConversation task) {
- if (task.shippedAt != null) return SuperTabBacklogGroup.shipped;
+/// How far back Shipped looks: fixed, with no control to change it (the PM's
+/// reshape of Scholes's ask, task #2551).
+const superTabBacklogShippedWindow = Duration(days: 7);
+
+/// Which group [task] is listed in at [now]; null for one that is not listed:
+/// cancelled, closed without shipping, or shipped before the window. A wait on
+/// a person is "Waiting on someone", as the sidebar's groups read it
+/// (task_groups.dart, Huy); the task's own line says on whom.
+SuperTabBacklogGroup? superTabBacklogGroupOf(
+ SuperTabConversation task,
+ DateTime now,
+) {
+ if (task.shippedAt case final shipped?) {
+ return now.difference(shipped) > superTabBacklogShippedWindow
+ ? null
+ : SuperTabBacklogGroup.shipped;
+ }
+ if (task.closed) return null;
final assignment = task.assignment;
final status = assignment?['status'];
final liveness = task.liveness;
@@ -48,16 +61,26 @@ SuperTabBacklogGroup? superTabBacklogGroupOf(SuperTabConversation task) {
return SuperTabBacklogGroup.working;
}
-/// Every task of the Swarm the controller holds, open and closed, across
-/// projects, newest first: the groups the server lets this reader read, less
-/// project chats, Buddy chats, steps and private chats, as the sidebar lists
-/// a project's work (project_sidebar.dart superTabOpenWorkgroups).
-List<SuperTabConversation> superTabBacklogTasks(SuperTabController c) {
+/// Every task of the Swarm the controller holds, open and closed, and of
+/// [closed], those read for the list alone, across projects, newest first: the
+/// groups the server lets this reader read, less project chats, Buddy chats,
+/// steps and private chats, as the sidebar lists a project's work
+/// (project_sidebar.dart superTabOpenWorkgroups). What the controller holds is
+/// newer than a read, so it wins.
+List<SuperTabConversation> superTabBacklogTasks(
+ SuperTabController c, {
+ Iterable<SuperTabConversation> closed = const [],
+}) {
final snapshot = c.snapshot;
if (snapshot == null) return const [];
+ final byProject = closed.groupListsBy((g) => g.projectId);
final tasks = [
for (final project in snapshot.projects)
- for (final g in superTabListedWork(c.projectConversations(project.id)))
+ for (final g in superTabListedWork([
+ ...c.projectConversations(project.id),
+ for (final g in byProject[project.id] ?? const <SuperTabConversation>[])
+ if (snapshot.conversation(g.id) == null) g,
+ ]))
if (g.id != project.leadConversationId &&
!g.isBuddyChat &&
!c.hiddenByBuddies(g))
diff --git a/desktop/lib/super_tabs/backlog_view.dart b/desktop/lib/super_tabs/backlog_view.dart
index e0673eb09..82bbf35ee 100644
--- a/desktop/lib/super_tabs/backlog_view.dart
+++ b/desktop/lib/super_tabs/backlog_view.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
@@ -42,12 +44,37 @@ class _SuperTabBacklogViewState extends State<SuperTabBacklogView> {
/// The pull requests watched for their checks: open tasks' alone.
Set<String> _watched = const {};
+ @override
+ void initState() {
+ super.initState();
+ _readClosed();
+ }
+
+ @override
+ void didUpdateWidget(SuperTabBacklogView old) {
+ super.didUpdateWidget(old);
+ if (!identical(old.controller, widget.controller)) _readClosed();
+ }
+
@override
void dispose() {
widget.facts?.unwatch(_watched);
super.dispose();
}
+ void _readClosed() => unawaited(
+ widget.controller.readClosedShipped(
+ widget.now().subtract(superTabBacklogShippedWindow),
+ ),
+ );
+
+ /// Opens [task]'s chat, reading it first when the controller does not hold it.
+ Future<void> _open(SuperTabConversation task) async {
+ if (await widget.controller.loadGroup(task.id) && mounted) {
+ widget.onOpenConversation(task.id);
+ }
+ }
+
void _watch(Iterable<SuperTabConversation> open) {
final facts = widget.facts;
if (facts == null) return;
@@ -59,24 +86,25 @@ class _SuperTabBacklogViewState extends State<SuperTabBacklogView> {
_watched = next;
}
- // Rebuilt when GitHub's answer lands, as the live cards are: Manage rebuilds
- // only on the controller (review of #2776).
+ // Rebuilt when GitHub's answer lands, as the live cards are, and when a page
+ // of closed tasks does: Manage rebuilds only on the controller (review of
+ // #2776), which a page does not tell.
@override
- Widget build(BuildContext context) => switch (widget.facts) {
- final facts? => ListenableBuilder(
- listenable: facts,
- builder: (context, _) => _build(context),
- ),
- null => _build(context),
- };
+ Widget build(BuildContext context) => ListenableBuilder(
+ listenable: Listenable.merge([
+ widget.controller.closedShippedChanged,
+ ?widget.facts,
+ ]),
+ builder: (context, _) => _build(context),
+ );
Widget _build(BuildContext context) {
grid.AppTheme.watch(context);
final c = widget.controller, snapshot = c.snapshot;
- final all = superTabBacklogTasks(c);
+ final now = widget.now();
final placed = [
- for (final task in all)
- if (superTabBacklogGroupOf(task) case final group?) (task, group),
+ for (final task in superTabBacklogTasks(c, closed: c.closedShipped))
+ if (superTabBacklogGroupOf(task, now) case final group?) (task, group),
];
// Watched after the frame: a build changes nothing outside itself.
final open = [
@@ -86,13 +114,22 @@ class _SuperTabBacklogViewState extends State<SuperTabBacklogView> {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _watch(open);
});
- final shown = [
+ final matching = [
for (final (task, group) in placed)
if ((_project == null || task.projectId == _project) &&
(!_mine || task.requesterId == c.accountId) &&
(_group == null || group == _group))
(task, group),
];
+ // Mine with nothing open says so and links to what shipped, whatever else
+ // the reader asked for. All of it is shipped here, or it would be open.
+ final noneOpen =
+ _mine &&
+ _group == null &&
+ matching.every((e) => e.$2 == SuperTabBacklogGroup.shipped);
+ final shown = noneOpen
+ ? const <(SuperTabConversation, SuperTabBacklogGroup)>[]
+ : matching;
final entries = <Object>[
for (final group in SuperTabBacklogGroup.values)
if (shown.where((e) => e.$2 == group).toList() case final tasks
@@ -165,14 +202,57 @@ class _SuperTabBacklogViewState extends State<SuperTabBacklogView> {
],
),
),
+ if (c.closedShippedFailed)
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: grid.AppDesktop.groupGap,
+ ),
+ child: Row(
+ children: [
+ Text(
+ 'Some shipped tasks could not be read.',
+ style: DesktopChrome.metadata(color: DesktopChrome.muted),
+ ),
+ const SizedBox(width: grid.AppDesktop.controlGap),
+ DesktopPill(
+ key: const ValueKey('super-backlog-shipped-retry'),
+ label: 'Try again',
+ quiet: true,
+ compact: true,
+ onPressed: _readClosed,
+ ),
+ ],
+ ),
+ ),
Expanded(
child: entries.isEmpty
? Center(
- child: Text(
- _mine && all.isNotEmpty
- ? 'No tasks you asked for'
- : 'No tasks',
- style: DesktopChrome.control(color: DesktopChrome.muted),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ noneOpen
+ ? 'No open tasks of yours'
+ : _mine
+ ? 'No tasks you asked for'
+ : 'No tasks',
+ style: DesktopChrome.control(
+ color: DesktopChrome.muted,
+ ),
+ ),
+ if (noneOpen && matching.isNotEmpty)
+ DesktopPill(
+ key: const ValueKey('super-backlog-mine-shipped'),
+ label:
+ 'Your shipped tasks from the last 7 days · '
+ '${matching.length}',
+ quiet: true,
+ compact: true,
+ onPressed: () => setState(
+ () => _group = SuperTabBacklogGroup.shipped,
+ ),
+ ),
+ ],
),
)
: LaidOutListView.builder(
@@ -187,8 +267,8 @@ class _SuperTabBacklogViewState extends State<SuperTabBacklogView> {
task: task,
controller: c,
facts: widget.facts,
- now: widget.now(),
- onOpen: () => widget.onOpenConversation(task.id),
+ now: now,
+ onOpen: () => _open(task),
),
_ => const SizedBox.shrink(),
},
@@ -290,7 +370,8 @@ class _Row extends StatelessWidget {
snapshot.projectById(task.projectId)?.name,
if (task.requesterId case final id?) _personName(id),
].nonNulls.join(' · ');
- final changed = controller.groupChangedAt(task.id);
+ // One read for the list alone is not held: when it shipped stands in.
+ final changed = controller.groupChangedAt(task.id) ?? task.shippedAt;
final muted = DesktopChrome.metadata(color: DesktopChrome.muted);
return InkWell(
key: ValueKey('super-backlog-row-${task.id}'),
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index 258f14acf..acb8fd836 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -59,6 +59,10 @@ String superTabMessageId({
.join()
.substring(0, 24);
+/// The most pages of closed groups one read goes through (50 a page), so a
+/// Swarm whose old groups all changed lately cannot read without an end.
+const _closedSincePages = 40;
+
/// Saved for a text still queued when the window closed. Older versions read
/// and show it; this one knows it by [_unsentKey] and shows Not sent alone.
const _unsentReason = 'Not sent before this window closed.';
@@ -2648,6 +2652,7 @@ class SuperTabController extends ChangeNotifier {
}
accessRevoked = true;
devicesSelected = false;
+ _forgetClosedShipped();
_forgetAttention();
error = message;
snapshot = null;
@@ -3725,6 +3730,10 @@ class SuperTabController extends ChangeNotifier {
for (final project in expandedProjects) {
unawaited(loadDormant(project));
}
+ if (_closedShippedSince case final since?) {
+ _forgetClosedShipped();
+ unawaited(readClosedShipped(since));
+ }
}
}
// A first open draws its sidebar now, not once its chat answers.
@@ -4002,6 +4011,117 @@ class SuperTabController extends ChangeNotifier {
}
}
+ /// Closed tasks read for the Backlog that shipped since the read's window
+ /// began, by id. Kept here so an open of the tab reads nothing again: a task
+ /// that closes later is one this reader holds, and [snapshot] keeps it. They
+ /// join no snapshot, which is built again on every change, and no project's
+ /// "Closed" count.
+ final _closedShipped = <String, SuperTabConversation>{};
+ final _closedShippedProjects = <String>{};
+ final _closedShippedChanged = ValueNotifier<int>(0);
+ Future<void>? _closedShippedRead;
+ DateTime? _closedShippedSince;
+ int _closedShippedEpoch = 0;
+
+ /// Whether a project's closed tasks could not be read; [readClosedShipped]
+ /// tries it again.
+ bool closedShippedFailed = false;
+
+ Iterable<SuperTabConversation> get closedShipped => _closedShipped.values;
+
+ /// Tells of a change to [closedShipped] or [closedShippedFailed], and nobody
+ /// else who watches this controller: a page changes only the Backlog.
+ Listenable get closedShippedChanged => _closedShippedChanged;
+
+ /// Reads the closed tasks shipped since [since] of each project not read yet.
+ /// Joins a read under way.
+ Future<void> readClosedShipped(DateTime since) {
+ if (_disposed || accessRevoked || _parts == null) return Future.value();
+ if (_closedShippedRead case final reading?) return reading;
+ late final Future<void> reading;
+ reading = _readClosedShipped(since, _closedShippedEpoch).whenComplete(() {
+ if (identical(_closedShippedRead, reading)) _closedShippedRead = null;
+ });
+ return _closedShippedRead = reading;
+ }
+
+ Future<void> _readClosedShipped(DateTime since, int epoch) async {
+ _closedShippedSince = since;
+ if (closedShippedFailed) {
+ closedShippedFailed = false;
+ _closedShippedChanged.value++;
+ }
+ final projects = snapshot?.projects ?? const <SuperTabProject>[];
+ for (final project in projects) {
+ if (_closedShippedProjects.contains(project.id)) continue;
+ try {
+ await _readProjectClosedShipped(project.id, since, epoch);
+ if (epoch != _closedShippedEpoch) return;
+ _closedShippedProjects.add(project.id);
+ } catch (failure) {
+ if (_disposed || epoch != _closedShippedEpoch) return;
+ if (_isUpdateRequired(failure)) return _requireUpdate();
+ appLog.warn(
+ 'swarm',
+ 'closed tasks read failed: '
+ '${failure is SuperTabFailure ? '${failure.code} (status ${failure.statusCode})' : failure.runtimeType}',
+ );
+ closedShippedFailed = true;
+ _closedShippedChanged.value++;
+ }
+ }
+ }
+
+ /// One project's closed groups, newest first, a page at a time: by project,
+ /// as only a project's list has an index that serves its order. A page whose
+ /// last group last changed before [since] is the last read, since those after
+ /// it were last active earlier still.
+ Future<void> _readProjectClosedShipped(
+ String projectId,
+ DateTime since,
+ int epoch,
+ ) async {
+ String? before;
+ for (var page = 0; page < _closedSincePages; page++) {
+ final answer = await request(
+ 'GET',
+ '$_path/groups?dormant=1&projectId=${Uri.encodeQueryComponent(projectId)}'
+ '${before == null ? '' : '&before=${Uri.encodeQueryComponent(before)}'}',
+ );
+ if (_disposed || accessRevoked || epoch != _closedShippedEpoch) return;
+ final groups = answer['groups'] as List;
+ var added = false;
+ for (final raw in groups) {
+ final task = SuperTabConversation.fromJson(
+ superTabMap(superTabMap(raw)['data']),
+ );
+ if (task.shippedAt case final at? when !at.isBefore(since)) {
+ _closedShipped[task.id] = task;
+ added = true;
+ }
+ }
+ if (added) _closedShippedChanged.value++;
+ before = answer['next'] as String?;
+ final last = groups.lastOrNull;
+ if (before == null || last == null) return;
+ final changedAt = superTabMap(last)['changedAt'];
+ if (changedAt is num && changedAt < since.millisecondsSinceEpoch) return;
+ }
+ appLog.warn(
+ 'swarm',
+ 'closed tasks read stopped at $_closedSincePages pages',
+ );
+ }
+
+ void _forgetClosedShipped() {
+ _closedShippedEpoch++;
+ _closedShippedRead = null;
+ _closedShipped.clear();
+ _closedShippedProjects.clear();
+ closedShippedFailed = false;
+ if (!_disposed) _closedShippedChanged.value++;
+ }
+
/// Builds the snapshot again from the parts held, after a read on demand.
void _redraw() {
final parts = _parts;
@@ -4198,6 +4318,7 @@ class SuperTabController extends ChangeNotifier {
const {'FORBIDDEN', 'NOT_FOUND'}.contains(failure.code)) {
accessRevoked = true;
devicesSelected = false;
+ _forgetClosedShipped();
_forgetAttention();
snapshot = null;
_showingSaved = false;
@@ -5131,6 +5252,7 @@ class SuperTabController extends ChangeNotifier {
_markAll?._commit();
_disposed = true;
_machinesChanged.dispose();
+ _closedShippedChanged.dispose();
_silenceWatch?.cancel();
for (final then in _onDispose) {
then();
diff --git a/desktop/test/super_tab_backlog_shots_test.dart b/desktop/test/super_tab_backlog_shots_test.dart
index afc3d02b4..33f43fda3 100644
--- a/desktop/test/super_tab_backlog_shots_test.dart
+++ b/desktop/test/super_tab_backlog_shots_test.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'dart:io';
import 'dart:ui' as ui;
@@ -129,19 +130,53 @@ void main() {
return server;
}
+ /// [server]'s Swarm as Scholes met it: the reader has nothing open, and what
+ /// they asked for shipped and was archived.
+ void nothingOpenWithArchived(ConversationServer server) {
+ final conversations = server.state['conversations'] as List;
+ for (final g in conversations.cast<Map>()) {
+ if (g['requesterId'] == 'owner') g['requesterId'] = 'huy';
+ }
+ final shipped = DateTime(2026, 11, 3, 17).millisecondsSinceEpoch;
+ conversations.addAll(<Map<String, dynamic>>[
+ for (final (i, title) in const [
+ 'Thread tags in the sidebar',
+ 'Round dial fix',
+ 'Machine row menu',
+ ].indexed)
+ {
+ ...conversationFixture('shipped-$i', title),
+ 'projectId': 'p0',
+ 'number': 2200 - i,
+ 'requesterId': 'owner',
+ 'archived': true,
+ 'agentIds': ['thorne'],
+ 'assignment': {'id': 'a-s$i', 'agentId': 'thorne', 'status': 'done'},
+ 'shippedAt': shipped,
+ 'pullRequestUrls': [
+ 'https://github.com/autonomous-ai/openharness/pull/${2600 + i}',
+ ],
+ },
+ ]);
+ }
+
Future<void> show(
WidgetTester tester,
ConversationServer server, {
Brightness brightness = Brightness.light,
GlobalKey? picture,
+ Stopwatch? firstFrame,
}) async {
final c = server.controller();
addTearDown(c.dispose);
await c.refresh();
+ // Reads wait, so the first frame is timed alone.
+ if (firstFrame != null) server.holdReads = Completer<void>();
grid.AppTheme.brightness.value = brightness;
addTearDown(() => grid.AppTheme.brightness.value = Brightness.light);
await tester.binding.setSurfaceSize(const Size(900, 640));
addTearDown(() => tester.binding.setSurfaceSize(null));
+ firstFrame?.start();
await tester.pumpWidget(
MaterialApp(
theme: grid.buildAppTheme(brightness: brightness),
@@ -162,24 +197,34 @@ void main() {
),
),
);
+ firstFrame?.stop();
await tester.pumpAndSettle();
}
for (final brightness in Brightness.values) {
- for (final scene in ['all', 'mine', 'project']) {
+ for (final scene in [
+ 'all',
+ 'mine',
+ 'project',
+ 'mine-empty',
+ 'mine-shipped',
+ ]) {
testWidgets('screenshots for review ($scene, ${brightness.name})', (
tester,
) async {
final picture = GlobalKey();
- await show(
- tester,
- swarm(perProject: 3),
- brightness: brightness,
- picture: picture,
- );
- if (scene == 'mine') {
+ final server = swarm(perProject: 3);
+ if (scene.startsWith('mine-')) nothingOpenWithArchived(server);
+ await show(tester, server, brightness: brightness, picture: picture);
+ if (scene.startsWith('mine')) {
await tester.tap(find.byKey(const ValueKey('super-backlog-mine')));
await tester.pumpAndSettle();
+ if (scene == 'mine-shipped') {
+ await tester.tap(
+ find.byKey(const ValueKey('super-backlog-mine-shipped')),
+ );
+ await tester.pumpAndSettle();
+ }
} else if (scene == 'project') {
await tester.tap(find.byKey(const ValueKey('super-backlog-project')));
await tester.pumpAndSettle();
@@ -201,22 +246,45 @@ void main() {
}
}
- testWidgets('300 tasks across 30 projects: build and rebuild times', (
+ testWidgets('300 open and 300 closed tasks across 30 projects: times', (
tester,
) async {
final server = swarm(projects: 30, perProject: 10);
- final first = Stopwatch()..start();
- await show(tester, server);
- first.stop();
+ final shipped = DateTime(2026, 11, 3, 17).millisecondsSinceEpoch;
+ (server.state['conversations'] as List).addAll(<Map<String, dynamic>>[
+ for (var p = 0; p < 30; p++)
+ for (var i = 0; i < 10; i++)
+ {
+ ...conversationFixture('closed-$p-$i', 'Shipped and archived'),
+ 'projectId': 'p$p',
+ 'number': 1000 + p * 10 + i,
+ 'requesterId': 'owner',
+ 'archived': true,
+ 'assignment': {
+ 'id': 'c$p$i',
+ 'agentId': 'thorne',
+ 'status': 'done',
+ },
+ 'shippedAt': shipped,
+ },
+ ]);
+ final first = Stopwatch();
+ await show(tester, server, firstFrame: first);
+ final settled = Stopwatch()..start();
+ server.holdReads!.complete();
+ server.holdReads = null;
+ await tester.pumpAndSettle();
+ settled.stop();
final rebuild = Stopwatch()..start();
await tester.tap(find.byKey(const ValueKey('super-backlog-mine')));
await tester.pump();
rebuild.stop();
// ignore: avoid_print
print(
- 'Backlog, 300 tasks: first frame ${first.elapsedMilliseconds} ms '
- '(controller read included), filter rebuild '
- '${rebuild.elapsedMilliseconds} ms (headless debug VM)',
+ 'Backlog: first frame ${first.elapsedMilliseconds} ms, then '
+ '${settled.elapsedMilliseconds} ms to settle (closed reads on the fake '
+ 'server included), filter rebuild ${rebuild.elapsedMilliseconds} ms '
+ '(headless debug VM)',
);
}, skip: !bench);
}
diff --git a/desktop/test/super_tab_backlog_test.dart b/desktop/test/super_tab_backlog_test.dart
index 966bff834..0c619cea0 100644
--- a/desktop/test/super_tab_backlog_test.dart
+++ b/desktop/test/super_tab_backlog_test.dart
@@ -140,10 +140,65 @@ void main() {
),
('cancelled', task(assignment: working('cancelled')), null),
]) {
- test(name, () => expect(superTabBacklogGroupOf(built), expected));
+ test(
+ name,
+ () => expect(
+ superTabBacklogGroupOf(
+ built,
+ DateTime.fromMillisecondsSinceEpoch(now),
+ ),
+ expected,
+ ),
+ );
}
});
+ group('Shipped looks back 7 days, and a closed task only counts shipped', () {
+ final at = DateTime.fromMillisecondsSinceEpoch(now);
+ const day = 86400000;
+
+ test('a task shipped within 7 days is listed, an older one is not', () {
+ expect(
+ superTabBacklogGroupOf(
+ task(assignment: working('done'), shippedAt: now - 7 * day),
+ at,
+ ),
+ SuperTabBacklogGroup.shipped,
+ );
+ expect(
+ superTabBacklogGroupOf(
+ task(assignment: working('done'), shippedAt: now - 7 * day - 1),
+ at,
+ ),
+ isNull,
+ );
+ });
+
+ test('a task closed without shipping is on its way nowhere', () {
+ for (final closed in const [
+ {'archived': true},
+ {'dormant': true},
+ ]) {
+ final group = SuperTabConversation.fromJson({
+ ...conversationFixture('work', 'A task'),
+ 'assignment': working('stopped'),
+ ...closed,
+ });
+ expect(superTabBacklogGroupOf(group, at), isNull);
+ }
+ });
+
+ test('an archived task that shipped stays in Shipped', () {
+ final group = SuperTabConversation.fromJson({
+ ...conversationFixture('work', 'A task'),
+ 'assignment': working('done'),
+ 'archived': true,
+ 'shippedAt': now,
+ });
+ expect(superTabBacklogGroupOf(group, at), SuperTabBacklogGroup.shipped);
+ });
+ });
+
test('the groups read in order, as the mockup Scholes accepted', () {
expect(SuperTabBacklogGroup.values.map((g) => g.label), [
'Waiting for a machine',
@@ -325,11 +380,17 @@ void main() {
WidgetTester tester,
ConversationServer server, {
SuperTabPullRequestFacts? facts,
+ DateTime? today,
+ VoidCallback? beforeBuild,
+ SuperTabController? held,
}) async {
opened.clear();
- final c = shown = server.controller();
- addTearDown(c.dispose);
- await c.refresh();
+ final c = shown = held ?? server.controller();
+ if (held == null) {
+ addTearDown(c.dispose);
+ await c.refresh();
+ }
+ beforeBuild?.call();
await tester.binding.setSurfaceSize(const Size(1100, 900));
addTearDown(() => tester.binding.setSurfaceSize(null));
await tester.pumpWidget(
@@ -344,9 +405,11 @@ void main() {
onOpenConversation: opened.add,
// Five minutes after #11 last changed (the fixture's own
// clock), for its row's age.
- now: () => (c.groupChangedAt('working') ?? at).add(
- const Duration(minutes: 5),
- ),
+ now: () =>
+ today ??
+ (c.groupChangedAt('working') ?? at).add(
+ const Duration(minutes: 5),
+ ),
),
),
),
@@ -564,10 +627,382 @@ void main() {
await show(tester, other);
await tester.tap(find.byKey(const ValueKey('super-backlog-mine')));
await tester.pumpAndSettle();
- expect(find.text('No tasks you asked for'), findsOneWidget);
+ expect(find.text('No open tasks of yours'), findsOneWidget);
expect(find.text('0 tasks'), findsOneWidget);
});
+ group('closed tasks the app does not hold', () {
+ const day = 86400000;
+
+ /// A task of the project that shipped [daysAgo] days ago and was archived
+ /// since, so a first read leaves it out as the backend does.
+ Map<String, dynamic> archived(
+ String id,
+ int number, {
+ double daysAgo = 2,
+ String requester = 'owner',
+ String status = 'done',
+ bool shipped = true,
+ }) => {
+ ...conversationFixture(id, 'Archived $id'),
+ 'projectId': 'lead',
+ 'number': number,
+ 'requesterId': requester,
+ 'archived': true,
+ 'assignment': {'id': 'a-$id', 'agentId': 'kestrel', 'status': status},
+ if (shipped) 'shippedAt': now - (daysAgo * day).round(),
+ };
+
+ /// [swarm] with nothing open: every task of it asked for by someone else.
+ ConversationServer nothingOpen() {
+ final server = swarm();
+ for (final g in (server.state['conversations'] as List)) {
+ (g as Map)['requesterId'] = 'pilot';
+ }
+ return server;
+ }
+
+ void add(
+ ConversationServer server,
+ Iterable<Map<String, dynamic>> tasks,
+ ) {
+ (server.state['conversations'] as List).addAll(tasks);
+ }
+
+ testWidgets('Shipped lists archived tasks from the last 7 days, not '
+ 'older ones, and they stay out of what the app holds', (
+ tester,
+ ) async {
+ final server = swarm();
+ // Time runs as the app does: what is read counts as changed just now.
+ server.parts.clock = now;
+ add(server, [
+ archived('recent', 30),
+ archived('week-old', 31, daysAgo: 6.9),
+ archived('too-old', 32, daysAgo: 8),
+ archived('gave-up', 33, status: 'stopped', shipped: false),
+ ]);
+ final c = await show(tester, server, today: at);
+ expect(row('recent'), findsOneWidget);
+ expect(row('week-old'), findsOneWidget);
+ expect(row('too-old'), findsNothing);
+ expect(row('gave-up'), findsNothing);
+ expect(
+ tester.getTopLeft(row('recent')).dy,
+ greaterThan(
+ tester.getTopLeft(header(SuperTabBacklogGroup.shipped)).dy,
+ ),
+ );
+ expect(find.text('Shipped · 3'), findsOneWidget);
+ // The snapshot is built again on every change: these never join it.
+ expect(c.snapshot!.conversation('recent'), isNull);
+ });
+
+ testWidgets('it reads on through every page of the last 7 days', (
+ tester,
+ ) async {
+ final server = swarm()..parts.dormantPage = 2;
+ server.parts.clock = now;
+ add(server, [for (var i = 0; i < 5; i++) archived('page$i', 40 + i)]);
+ await show(tester, server, today: at);
+ for (var i = 0; i < 5; i++) {
+ expect(row('page$i'), findsOneWidget);
+ }
+ });
+
+ testWidgets('it reads each project through that project\'s index, never '
+ 'the whole Swarm\'s list, which no index can sort', (tester) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [
+ archived('here', 80),
+ {...archived('there', 81), 'projectId': 'api'},
+ ]);
+ await show(tester, server, today: at);
+ expect(row('here'), findsOneWidget);
+ expect(row('there'), findsOneWidget);
+ final pages = server.parts.reads.where((p) => p.contains('dormant=1'));
+ expect(pages, isNotEmpty);
+ expect(pages.where((p) => !p.contains('projectId=')), isEmpty);
+ });
+
+ testWidgets('a project that cannot be read does not stop the others', (
+ tester,
+ ) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [
+ archived('here', 80),
+ {...archived('there', 81), 'projectId': 'api'},
+ ]);
+ await show(
+ tester,
+ server,
+ today: at,
+ beforeBuild: () => server.failReadsOf = 'projectId=lead',
+ );
+ expect(row('here'), findsNothing);
+ expect(row('there'), findsOneWidget);
+ expect(
+ find.byKey(const ValueKey('super-backlog-shipped-retry')),
+ findsOneWidget,
+ );
+ });
+
+ Iterable<String> closedReads(ConversationServer server) =>
+ server.parts.reads.where((p) => p.contains('dormant=1'));
+
+ testWidgets('opening the tab again reads nothing again and keeps the '
+ 'rows', (tester) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [archived('recent', 30)]);
+ final c = await show(tester, server, today: at);
+ expect(row('recent'), findsOneWidget);
+ final reads = closedReads(server).length;
+ await tester.pumpWidget(const SizedBox());
+ await show(tester, server, today: at, held: c);
+ expect(row('recent'), findsOneWidget);
+ expect(closedReads(server), hasLength(reads));
+ });
+
+ testWidgets('a task that closes while the app is open stays listed '
+ 'after the tab opens again', (tester) async {
+ final server = swarm();
+ server.parts.clock = now;
+ final c = await show(tester, server, today: at);
+ await tester.pumpWidget(const SizedBox());
+ (server.state['conversations'] as List).cast<Map>().firstWhere(
+ (g) => g['id'] == 'shipped',
+ )['archived'] = true;
+ await c.refresh();
+ await show(tester, server, today: at, held: c);
+ expect(row('shipped'), findsOneWidget);
+ });
+
+ testWidgets('trying again reads only the project that failed', (
+ tester,
+ ) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [
+ archived('here', 80),
+ {...archived('there', 81), 'projectId': 'api'},
+ ]);
+ await show(
+ tester,
+ server,
+ today: at,
+ beforeBuild: () => server.failReadsOf = 'projectId=lead',
+ );
+ server.parts.reads.clear();
+ server.failReadsOf = null;
+ await tester.tap(
+ find.byKey(const ValueKey('super-backlog-shipped-retry')),
+ );
+ await tester.pumpAndSettle();
+ expect(row('here'), findsOneWidget);
+ expect(row('there'), findsOneWidget);
+ expect(
+ closedReads(server).where((p) => p.contains('projectId=api')),
+ isEmpty,
+ );
+ });
+
+ testWidgets('a reload forgets what the reader may no longer read', (
+ tester,
+ ) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [archived('recent', 30), archived('kept', 31)]);
+ final c = await show(tester, server, today: at);
+ expect(row('recent'), findsOneWidget);
+ (server.state['conversations'] as List).cast<Map>().firstWhere(
+ (g) => g['id'] == 'recent',
+ )['audience'] = {
+ 'people': [
+ {'id': 'pilot'},
+ ],
+ };
+ server.parts.epoch++;
+ await c.refresh();
+ await tester.pumpAndSettle();
+ expect(row('recent'), findsNothing);
+ expect(row('kept'), findsOneWidget);
+ });
+
+ testWidgets('a page that reaches past 7 days ends the read', (
+ tester,
+ ) async {
+ final server = swarm()..parts.dormantPage = 1;
+ add(server, [
+ archived('oldest', 50, daysAgo: 20),
+ archived('older', 51, daysAgo: 19),
+ ]);
+ server.parts.clock = now - 30 * day;
+ await show(
+ tester,
+ server,
+ today: at,
+ beforeBuild: () {
+ server.parts.clock = now;
+ add(server, [archived('fresh', 52)]);
+ server.parts.reads.clear();
+ },
+ );
+ expect(row('fresh'), findsOneWidget);
+ final pages = server.parts.reads.where(
+ (p) => p.contains('dormant=1') && p.contains('projectId=lead'),
+ );
+ // The fresh task's page, then the first whose task is past the window.
+ expect(pages, hasLength(2));
+ });
+
+ testWidgets(
+ 'a task that is back at work shows as the app holds it, once',
+ (tester) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [archived('woken', 60)]);
+ final c = await show(tester, server, today: at);
+ expect(
+ find.byKey(const ValueKey('super-backlog-row-woken')),
+ findsOne,
+ );
+ final woken = (server.state['conversations'] as List).firstWhere(
+ (g) => (g as Map)['id'] == 'woken',
+ );
+ woken
+ ..remove('archived')
+ ..remove('shippedAt')
+ ..['assignment'] = {
+ 'id': 'a-woken',
+ 'agentId': 'kestrel',
+ 'status': 'working',
+ };
+ await c.refresh();
+ await tester.pumpAndSettle();
+ expect(row('woken'), findsOneWidget);
+ expect(
+ tester.getTopLeft(row('woken')).dy,
+ lessThan(
+ tester.getTopLeft(header(SuperTabBacklogGroup.shipped)).dy,
+ ),
+ );
+ },
+ );
+
+ testWidgets('clicking an archived row reads it and opens its chat', (
+ tester,
+ ) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [archived('recent', 30)]);
+ final c = await show(tester, server, today: at);
+ await tester.tap(row('recent'));
+ await tester.pumpAndSettle();
+ expect(opened, ['recent']);
+ expect(c.snapshot!.conversation('recent'), isNotNull);
+ });
+
+ testWidgets(
+ 'an empty Mine says so and links to what the reader shipped',
+ (tester) async {
+ final server = nothingOpen();
+ server.parts.clock = now;
+ add(server, [
+ archived('mine-a', 30),
+ archived('mine-b', 31),
+ archived('theirs', 32, requester: 'pilot'),
+ ]);
+ await show(tester, server, today: at);
+ await tester.tap(find.byKey(const ValueKey('super-backlog-mine')));
+ await tester.pumpAndSettle();
+ expect(find.text('No open tasks of yours'), findsOneWidget);
+ expect(row('mine-a'), findsNothing);
+ final link = find.byKey(const ValueKey('super-backlog-mine-shipped'));
+ expect(
+ find.descendant(
+ of: link,
+ matching: find.text(
+ 'Your shipped tasks from the last 7 days · 2',
+ ),
+ ),
+ findsOneWidget,
+ );
+ await tester.tap(link);
+ await tester.pumpAndSettle();
+ expect(find.text('No open tasks of yours'), findsNothing);
+ expect(row('mine-a'), findsOneWidget);
+ expect(row('mine-b'), findsOneWidget);
+ expect(row('theirs'), findsNothing);
+ expect(find.text('Shipped · 2'), findsOneWidget);
+ expect(find.text('2 tasks'), findsOneWidget);
+ },
+ );
+
+ testWidgets('an empty Mine with nothing shipped has no link', (
+ tester,
+ ) async {
+ await show(tester, nothingOpen(), today: at);
+ await tester.tap(find.byKey(const ValueKey('super-backlog-mine')));
+ await tester.pumpAndSettle();
+ expect(find.text('No open tasks of yours'), findsOneWidget);
+ expect(
+ find.byKey(const ValueKey('super-backlog-mine-shipped')),
+ findsNothing,
+ );
+ });
+
+ testWidgets('Mine goes by who asked, not who worked on it', (
+ tester,
+ ) async {
+ final server = nothingOpen();
+ server.parts.clock = now;
+ final conversations = server.state['conversations'] as List;
+ conversations.add({
+ ...archived('no-one-asked', 70),
+ 'requesterId': null,
+ });
+ // The reader's own machine and agent did this one; Pilot asked for it.
+ add(server, [archived('theirs', 71, requester: 'pilot')]);
+ add(server, [archived('asked', 72)]);
+ await show(tester, server, today: at);
+ await tester.tap(find.byKey(const ValueKey('super-backlog-mine')));
+ await tester.pumpAndSettle();
+ expect(
+ find.text('Your shipped tasks from the last 7 days · 1'),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('a failed read says so, and trying again reads it', (
+ tester,
+ ) async {
+ final server = swarm();
+ server.parts.clock = now;
+ add(server, [archived('recent', 30)]);
+ await show(
+ tester,
+ server,
+ today: at,
+ beforeBuild: () => server.failReads = true,
+ );
+ expect(row('recent'), findsNothing);
+ final retry = find.byKey(const ValueKey('super-backlog-shipped-retry'));
+ expect(retry, findsOneWidget);
+ expect(
+ find.text('Some shipped tasks could not be read.'),
+ findsOneWidget,
+ );
+ server.failReads = false;
+ await tester.tap(retry);
+ await tester.pumpAndSettle();
+ expect(retry, findsNothing);
+ expect(row('recent'), findsOneWidget);
+ });
+ });
+
testWidgets('a shipped task whose agent was removed still shows', (
tester,
) async {
diff --git a/desktop/test/support/super_tab_fixture.dart b/desktop/test/support/super_tab_fixture.dart
index 6e3c91da0..c04de566f 100644
--- a/desktop/test/support/super_tab_fixture.dart
+++ b/desktop/test/support/super_tab_fixture.dart
@@ -447,6 +447,9 @@ class ConversationServer {
void Function(String path)? onRead;
bool loseReply = false, reject = false, failSave = false, failReads = false;
+ /// Fails, as if offline, each read whose path holds this.
+ String? failReadsOf;
+
/// Names a person's message as the backend does: a hash of the Swarm, the
/// sender and the send's receipt id (backend model.ts `stableId`, used by
/// `message.send` in commands.ts), not `message-N`.
@@ -1498,6 +1501,9 @@ class ConversationServer {
}
if (holdReads case final hold?) await hold.future;
if (failReads) throw StateError('Offline');
+ if (failReadsOf case final part? when path.contains(part)) {
+ throw StateError('Offline');
+ }
final uri = Uri.parse(path);
if (uri.pathSegments.length > 5 &&
uri.pathSegments[3] == 'projects' &&