a26bfe2b0c
Review 139 found the selected task's output page unbounded, overflowing a phone-height conversation. The bar now keeps half the viewport and scrolls its own body, the output pane is capped at twelve scaled lines, row labels elide instead of overflowing, and a reply without a page reads as unavailable rather than empty.
166 lines
5.4 KiB
Dart
166 lines
5.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_shells.dart';
|
|
|
|
JsonMap _shell(String id, String status, {String command = ''}) => {
|
|
'id': id,
|
|
'status': status,
|
|
'command': command,
|
|
};
|
|
|
|
void main() {
|
|
group('recorded running tasks', () {
|
|
test('only a non-blank id with status running is a task', () {
|
|
final shells = [
|
|
_shell('sh1', 'running', command: 'go test ./...'),
|
|
_shell('sh2', 'exited', command: 'pnpm build'),
|
|
_shell('', 'running', command: 'no identity'),
|
|
{'status': 'running', 'command': 'no id'},
|
|
_shell('sh3', 'pending', command: 'not started'),
|
|
];
|
|
|
|
expect(runningShells(shells).map((shell) => shell['id']), ['sh1']);
|
|
});
|
|
|
|
test('a shell frame merges by id and keeps the command already known', () {
|
|
final first = mergeShellFrame(
|
|
const [],
|
|
_shell('sh1', 'running', command: 'go test ./...'),
|
|
);
|
|
final exited = mergeShellFrame(first, _shell('sh1', 'exited'));
|
|
final other = mergeShellFrame(
|
|
exited,
|
|
_shell('sh2', 'running', command: 'sleep 1'),
|
|
);
|
|
|
|
expect(other, hasLength(2));
|
|
expect(other.first['status'], 'exited');
|
|
expect(other.first['command'], 'go test ./...');
|
|
expect(runningShells(other).map((shell) => shell['id']), ['sh2']);
|
|
expect(mergeShellFrame(other, null), same(other));
|
|
expect(mergeShellFrame(other, _shell('', 'running')), same(other));
|
|
});
|
|
|
|
test('the retained observation tail is bounded', () {
|
|
var shells = const <JsonMap>[];
|
|
for (var index = 0; index < observedShellLimit + 4; index++) {
|
|
shells = mergeShellFrame(shells, _shell('sh$index', 'running'));
|
|
}
|
|
|
|
expect(shells, hasLength(observedShellLimit));
|
|
expect(shells.first['id'], 'sh4');
|
|
expect(shells.last['id'], 'sh${observedShellLimit + 3}');
|
|
});
|
|
|
|
test('a snapshot keeps observed exits and drops shells never seen', () {
|
|
final observed = [
|
|
_shell('exited', 'exited', command: 'pnpm build'),
|
|
_shell('running', 'running', command: 'go test ./...'),
|
|
_shell('gone', 'running', command: 'old fact'),
|
|
];
|
|
final loaded = shellsLoaded(observed, [
|
|
_shell('running', 'running', command: 'go test ./...'),
|
|
_shell('new', 'running', command: 'tail -f log'),
|
|
]);
|
|
|
|
expect(loaded.map((shell) => '${shell['id']}:${shell['status']}'), [
|
|
'exited:exited',
|
|
'running:running',
|
|
'new:running',
|
|
]);
|
|
expect(runningShells(loaded).map((shell) => shell['id']), [
|
|
'running',
|
|
'new',
|
|
]);
|
|
});
|
|
});
|
|
|
|
group('shell wording', () {
|
|
test('the command collapses whitespace and names a blank one', () {
|
|
expect(shellCommandSummary(' go test\n ./... '), 'go test ./...');
|
|
expect(shellCommandSummary(' '), 'background process');
|
|
expect(shellCommandSummary(null), 'background process');
|
|
});
|
|
|
|
test('a long command is elided to the tool-detail width', () {
|
|
final summary = shellCommandSummary('x' * 200);
|
|
|
|
expect(summary.length, shellCommandSummaryLength);
|
|
expect(summary.endsWith('…'), isTrue);
|
|
expect(summary, '${'x' * (shellCommandSummaryLength - 1)}…');
|
|
});
|
|
|
|
test('the heading keeps the recorded count', () {
|
|
expect(backgroundTasksTitle, 'Background tasks');
|
|
expect(backgroundTasksRunningLabel(0), '0 running');
|
|
expect(backgroundTasksRunningLabel(3), '3 running');
|
|
});
|
|
});
|
|
|
|
group('bounded output page', () {
|
|
test('a page carries its output, bound and reported shell', () {
|
|
final page = ChatShellOutputPage.fromReply({
|
|
'chat_shell_output': {
|
|
'shell': {'id': 'sh1', 'status': 'running', 'command': 'go test'},
|
|
'output': 'ok example\n',
|
|
'cursor': 0,
|
|
'size': 11,
|
|
'truncated': true,
|
|
},
|
|
});
|
|
|
|
expect(page.output, 'ok example\n');
|
|
expect(page.truncated, isTrue);
|
|
expect(page.unavailable, isFalse);
|
|
expect(page.shell?['command'], 'go test');
|
|
expect(chatShellOutputLimit, 64 * 1024);
|
|
});
|
|
|
|
test('a reply without the page is unavailable, never invented output', () {
|
|
final page = ChatShellOutputPage.fromReply(const {});
|
|
|
|
expect(page.output, '');
|
|
expect(page.shell, isNull);
|
|
expect(page.unavailable, isTrue);
|
|
expect(
|
|
ChatShellOutputSnapshot(page: page).state,
|
|
ChatShellOutputState.unavailable,
|
|
);
|
|
expect(
|
|
const ChatShellOutputSnapshot(page: ChatShellOutputPage()).state,
|
|
ChatShellOutputState.empty,
|
|
);
|
|
});
|
|
|
|
test(
|
|
'the pane state follows loading, error, unavailable, empty, ready',
|
|
() {
|
|
expect(
|
|
const ChatShellOutputSnapshot().state,
|
|
ChatShellOutputState.none,
|
|
);
|
|
expect(
|
|
const ChatShellOutputSnapshot(loading: true).state,
|
|
ChatShellOutputState.loading,
|
|
);
|
|
expect(
|
|
const ChatShellOutputSnapshot(error: 'refused').state,
|
|
ChatShellOutputState.error,
|
|
);
|
|
expect(
|
|
const ChatShellOutputSnapshot(
|
|
page: ChatShellOutputPage(unavailable: true),
|
|
).state,
|
|
ChatShellOutputState.unavailable,
|
|
);
|
|
expect(
|
|
const ChatShellOutputSnapshot(
|
|
page: ChatShellOutputPage(output: 'ready'),
|
|
).state,
|
|
ChatShellOutputState.ready,
|
|
);
|
|
},
|
|
);
|
|
});
|
|
}
|