diff --git a/SOURCE-SHA256.json b/SOURCE-SHA256.json index 41f6eed..0382b81 100644 --- a/SOURCE-SHA256.json +++ b/SOURCE-SHA256.json @@ -21,7 +21,7 @@ "gpuqueue/__init__.py": "852c85083667b737e5b2f4896532f7c94fa07abc4531c0b32fd37d990242fb17", "gpuqueue/chat.py": "d469f71a3f1dab8d00253dc437d94951bbf1a8cb7510006098246f84d5a33289", "gpuqueue/cli.py": "7a0533a80c366c4c178c7d3f4ba61c610269c271f8cbdb2ed53e86bd8a6741d2", - "gpuqueue/control.py": "f21c9135bca6d2b5ec4fbefd58a54323638df916ac59c8f83d97e847c309ca0a", + "gpuqueue/control.py": "3986d2ee0450654a907f3a00e00809d99c67394f7a2361dcc3aed1103226e233", "gpuqueue/core.py": "e800ed44068bc0c0054f128410e594945d55028d502f40b55d31c15739a579dc", "gpuqueue/feishu.py": "87712f82f27dd58650d9d1d47e1a2ff246d8559e02d57a89692bcc81da8456b7", "gpuqueue/host_monitor.py": "6e407dabd35633af1e459d9b1ac02c1675510df25b9dea64de977d1cc2989c40", @@ -56,20 +56,20 @@ "serverbox/README.gpu-console.md": "9382da5e514c692c85cdbba18375689b45f09033bd8ba17f8db2c9b5226875a4", "serverbox/SOURCE.json": "db8f26cf434db5f91438decee35ae5e5367a4a7611ec3a992bdaaff6661b1f7f", "serverbox/lib/app.dart": "11e6ba26315e67706cafd9c0aeb8fbf9c3e86a2799d0f489d8ab3dc57cbc3303", - "serverbox/lib/core/gpu_queue/presentation.dart": "325fdbf339b578bf9d5067a0eec33a6c680edeaa78b8c0929c3252a42838fe60", + "serverbox/lib/core/gpu_queue/presentation.dart": "29005cec6a7547429c3acdcee63865a14f7e3a0049da45849acb7a0cae24f2d9", "serverbox/lib/core/gpu_queue/protocol.dart": "5e17ea93d9bafc7df9872ffd3b902d7cd8b2a6fc2fefcb0fa137e8a24e5f0e95", "serverbox/lib/core/utils/gpu_queue.dart": "d03bc0fb6b834f0b6b34e9c842d45290abb70eee52192d10744d643d6e78d3be", "serverbox/lib/core/utils/gpu_queue_theme.dart": "56f24afdb62cb6d19a405e0d04ed1af0834cb3b317ebd63b3c81fb836af0d860", - "serverbox/lib/view/page/gpu_queue/page.dart": "d045200ec56d8751c0516b65d332cfa54d7e9b3e699eb666b35b81259de0047c", - "serverbox/lib/view/page/gpu_queue/workspace.dart": "775c3091acc280569327c3f9f2234bb26d1ec4d8acfae7253773edb34bca6e6b", + "serverbox/lib/view/page/gpu_queue/page.dart": "2a7513c777878092ae24aaabab6bed217d2b364d40ebd9dcdcea946cb276ebd1", + "serverbox/lib/view/page/gpu_queue/workspace.dart": "ebcdfaa5f1da0913eb70277d4f8f76c28ba80f0f61242afba0d9c68179650ae6", "serverbox/lib/view/page/overview/gpu.dart": "316680cf4887df41b7fbabee78d35c2925d6245bed45060fa6dd2e3a73fe4050", "serverbox/lib/view/page/server/detail/bar_actions.dart": "5e1e70040a6fe5e782a94691198f4311ada7196a44da240bf8f5fefe33b3281e", "serverbox/lib/view/page/setting/about.dart": "91f55cb7948bf3df042b56cf16cbfc2e4fc2816021f1157c59840d6090a1f591", "serverbox/lib/view/page/setting/entry.dart": "ba2458b4597053dfed03c774f014068dd193d45862a41c334fc5b44c48f5acd0", "serverbox/test/unit/app/gpu_queue_test.dart": "e3514fe355b58f3a86d1cb83ccff58129532d5da132013f76cfdcc9bfeb7e854", - "serverbox/test/unit/app/queue_presentation_test.dart": "bf1c73790b9947d7a50c6c17e336af528f434d4fed1287b0c6a72d8c101c96d2", + "serverbox/test/unit/app/queue_presentation_test.dart": "4c7c6debe6c05c57679fad3d553bc4f7fed04af940701856ab600eefed61e71a", "serverbox/test/unit/app/queue_protocol_test.dart": "f80ddb23f95e2f70b6068728cf4ee1151a8e0c86dc28ae60aa21708b0fb26ee5", - "serverbox/test/unit/app/queue_workspace_widget_test.dart": "2ee524ec4bb7f95a4f94d6278155e9b1a14a103d5514709a0e9e8c849c95699b", + "serverbox/test/unit/app/queue_workspace_widget_test.dart": "72b4e892a50590bb838d861d49e3c6ebf4b13c7a9e6e8ef057dcc4d6991fea7e", "skills/inspire-queue/SKILL.md": "c8e1aacb4d38e79aa9e930e9e60c8db2147d4ea8a058996dd19e35b9a15b1161", "tests/browser_check.py": "f5885e5acf430749364699e81fdecf257906f898c971d39f837ae70811b14cd4", "tests/browser_monitor_check.py": "47c5a064bcd92dcab4d3f7f824e65134afb44e48e8313ed5a268ea5573df6c04", @@ -94,7 +94,7 @@ "tests/test_runner_telemetry.py": "605c9ad101e4130942bb67c35b60890ef92a59ad7413db8242c64460bc281e27", "tests/test_scheduler_resilience.py": "25127cc69af4511b87527f7b432544d5527680f452c32820a65f4fb8aec8a936", "tests/test_serverbox.py": "207d3e284bc39de5f7741ca8a42a9270bc1c562b377b93e0efbb07e5ea8b8062", - "tests/test_short_tasks.py": "ae64176fa80c9abd608aa0a4f622db7816a1188c85cafc820f9b317fad564c2f", + "tests/test_short_tasks.py": "bee44efd5a5b9360245220de759e7ff4de00d9de847f437e0b2d3a0da19a5f48", "tests/test_smoke.py": "7b332ea2c00138b51dda9221b09b8f637715026b2dcbaa94a960cb482af154b5", "tests/test_snapshot_control_boundaries.py": "95d90372efe1d6280b2710cd12593c81a4f3602d625f064de5c3ae4e90e24345", "tests/test_stop.py": "c452e9f5b04d4272471172b7cfbe578763bcd2e2e0678c2eb36c72db61156bdc", diff --git a/gpuqueue/control.py b/gpuqueue/control.py index a81a03a..43057cc 100644 --- a/gpuqueue/control.py +++ b/gpuqueue/control.py @@ -232,6 +232,8 @@ def rows(table, *, ordered=False): task_id = record['id'] task = dict(record['public']) internal = record['internal'] + if record.get('runtime_limit_seconds') is not None: + task['runtime_limit_seconds'] = record['runtime_limit_seconds'] replacement = internal.get('timeout_replacement') if replacement: replacements[task_id] = replacement @@ -317,8 +319,10 @@ def rows(table, *, ordered=False): def _state(self, db, *, include_deleted=False, browser=False): visible = '' if include_deleted else ' WHERE NOT EXISTS (SELECT 1 FROM task_deletions WHERE task_deletions.id=tasks.id)' - rows = db.execute('SELECT id,digest,public,internal FROM tasks'+visible+' ORDER BY rowid') - snapshots = (Store.decode(row, include_doc=False) for row in rows) + rows = db.execute("SELECT id,digest,public,internal,json_extract(doc, '$.runtime_limit_seconds') " + 'AS runtime_limit_seconds FROM tasks'+visible+' ORDER BY rowid') + snapshots = (Store.decode(row, include_doc=False) | + {'runtime_limit_seconds': row['runtime_limit_seconds']} for row in rows) heartbeat = self.read_heartbeat(db) tasks = self.task_views(db, snapshots, heartbeat=heartbeat, browser=browser) tasks.sort(key=lambda task: task['position']) diff --git a/serverbox/lib/core/gpu_queue/presentation.dart b/serverbox/lib/core/gpu_queue/presentation.dart index d871f2f..25b061d 100644 --- a/serverbox/lib/core/gpu_queue/presentation.dart +++ b/serverbox/lib/core/gpu_queue/presentation.dart @@ -15,7 +15,6 @@ enum QueueTaskAction { latest('查看最新版本'), copySummary('复制任务摘要'), results('查看结果文件'), - directory('打开工作目录'), deleteRecord('删除历史记录'); const QueueTaskAction(this.label); @@ -108,6 +107,51 @@ abstract final class QueuePresentation { '${memory != null && memory > 0 ? ' / ${_decimal(memory)} GB' : ' · 显存未指定'}'; } + static Map resourceSpecs(Map task) { + final resources = task['resources'] is Map + ? task['resources'] as Map + : const {}; + final estimate = _number(resources['estimated_hours']); + final limit = _number(task['runtime_limit_seconds']); + return { + '资源类型': _text(resources['type']) ?? '未提供', + 'GPU 数量': _requirement(resources['gpus'], '张'), + '单卡显存': _requirement(resources['memory_gb'] ?? task['memory'], 'GB'), + if (estimate != null && estimate > 0) + '预计时长': estimate < 1 + ? _requirement((estimate * 60).round(), '分钟') + : _requirement(estimate, '小时'), + if (limit != null && limit > 0) + '硬时限': limit % 60 == 0 + ? _requirement(limit / 60, '分钟') + : _requirement(limit, '秒'), + }; + } + + static String shortTaskId(String id) => + id.length > 11 ? '${id.substring(0, 11)}…' : id; + + static String? assignedInstance(Map task) { + final execution = task['execution']; + if (execution is Map && _text(execution['instance_id']) != null) { + return QueueTarget.instance(task); + } + // A pending request UUID alone does not identify an allocated instance. + if (const {'starting', 'running'}.contains(task['state']) || + _text(task['job_uuid']) != null || + QueueTarget.directory(task) != null) { + return QueueTarget.instance(task); + } + return null; + } + + static String overviewEvent(Object? line) => switch (line) { + '代码和配置已固定版本' => '代码和配置已保存', + '代码快照已校验' => '代码文件已检查', + '草稿已撤回,原快照已保留' => '已手动撤回,未占用 GPU', + _ => '$line', + }; + static String version(Map task) { final value = task['version'] ?? task['digest']; return value is String && value.trim().isNotEmpty ? value : '未提供'; @@ -195,7 +239,7 @@ abstract final class QueuePresentation { static String nextAction(Map task) => reviewClosed(task) ? '核查依据见事件。可以查看任务日志和已有产物。' : switch (task['state']) { - 'ready' => '检查资源需求和固定版本后,点击开始。准备完成的任务不会占用 GPU。', + 'ready' => '核对资源需求后,点击开始。', 'queued' => '已收到启动授权,等待调度。无需重复提交。', 'waiting_gpu' => '正在等待满足资源条件,具体原因见任务阶段。请核对申请回执、显存与已有任务;回执不明时不要重复申请。', 'checking_resources' => '正在检查已有 GPU 的可用性。查询超时不代表实例已释放。', @@ -204,8 +248,8 @@ abstract final class QueuePresentation { 'stopping' => '停止请求已记录,等待执行端确认。停止任务不等于释放 GPU。', 'completed' => '流程已完成,可查看结果。GPU 是否释放以平台回执为准。', 'failed' || 'interrupted' => '查看失败步骤与日志,修复后提交新版本,再手动开始。', - 'superseded' => '原快照已保留。请查看最新版本。', - 'withdrawn' => '草稿已撤回,原快照已保留。', + 'superseded' => '此任务已被新版本替代。', + 'withdrawn' => '已手动撤回,未占用 GPU。', 'blocked' || 'execution_unknown' => '先核对申请和执行端状态,避免重复申请或重复运行。', 'stopped' || 'cancelled' => '这一版已结束;如需再运行,请提交新版本。已有产物保留。', _ => '服务返回了尚未识别的状态,请在连接诊断中核对版本并联系维护者。', @@ -405,7 +449,7 @@ abstract final class QueuePresentation { case 'superseded': final successor = latest != task['id'] ? latest : null; return QueueTaskActionCardData( - conclusion: state == 'withdrawn' ? '草稿已撤回,未占用 GPU。' : '草稿已被新版本替代。', + conclusion: nextAction(task), primary: successor == null ? null : QueueTaskAction.latest, versionId: successor, secondary: [summary], @@ -416,7 +460,7 @@ abstract final class QueuePresentation { conclusion: '全部步骤已完成。', detail: elapsed == null ? '总耗时未提供' : '总耗时 $elapsed', primary: QueueTaskAction.results, - secondary: [QueueTaskAction.directory, QueueTaskAction.deleteRecord], + secondary: [QueueTaskAction.deleteRecord], ); default: return QueueTaskActionCardData( diff --git a/serverbox/lib/view/page/gpu_queue/page.dart b/serverbox/lib/view/page/gpu_queue/page.dart index 547eca0..41cad28 100644 --- a/serverbox/lib/view/page/gpu_queue/page.dart +++ b/serverbox/lib/view/page/gpu_queue/page.dart @@ -268,7 +268,7 @@ class _GpuQueuePageState extends ConsumerState final actor = snapshot['actor'] as Map; final execution = attempt['job'] ?? attempt['request'] ?? attempt['claimed_at'] ?? '尚未领取'; final description = switch (action) { - 'withdraw' when snapshot['state'] == 'ready' => '草稿将移入历史,原快照保留。', + 'withdraw' when snapshot['state'] == 'ready' => '撤回后,草稿会移到历史记录。', 'withdraw' => '任务将移出执行队列。已提交的 GPU 申请仍按平台状态处理。', 'stop' => '服务器将请求停止这一执行尝试并核查退出。已写入的日志和产物保留。', _ => '填写核查依据后,任务将归档。日志与产物保留,GPU 是否归还以执行器或平台回执为准。', @@ -1016,11 +1016,11 @@ class _GpuQueuePageState extends ConsumerState bool mobile = false, }) { servers = ref.read(serversProvider).servers; - final target = _target(service, task, servers); + final instance = QueuePresentation.assignedInstance(task); final directory = QueueTarget.directory(task); - final resource = queue.resources - .where((r) => r['id'] == QueueTarget.instance(task)) - .firstOrNull; + final resource = instance == null + ? null + : queue.resources.where((r) => r['id'] == instance).firstOrNull; final enabled = queue.connected && !queue.acting && !queue.loading; final state = task['state']; final retiredDraft = QueuePresentation.retiredDraftStates.contains(state); @@ -1032,21 +1032,6 @@ class _GpuQueuePageState extends ConsumerState connected: queue.connected, queueRank: queueIndex < 0 ? null : queueIndex + 1, ); - final previous = task['previous_task_id']; - final latest = task['latest_task_id']; - final successor = queue.tasks - .where((t) => t['id'] == card.versionId) - .firstOrNull; - Widget versionLink(String label, Object id) { - final linked = queue.tasks.where((t) => t['id'] == id).firstOrNull; - final text = '$label · $id'; - if (linked == null || id == task['id']) return SelectableText(text); - return TextButton( - onPressed: () => _openTask(linked, service, queue, servers, !mobile), - child: Text(text), - ); - } - final control = task['control_action']; final capabilities = queue.snapshot['capabilities']; VoidCallback? confirm(String label) => enabled && control is Map @@ -1066,18 +1051,142 @@ class _GpuQueuePageState extends ConsumerState updateDetail(() {}); } - final openDirectory = target == null || directory == null - ? null - : () => Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => SftpPage( - args: SftpPageArgs(spi: target, initPath: directory), + final checksAndEvents = [ + ...(task['checks'] as List? ?? []), + ...(task['events'] as List? ?? []), + ]; + Widget overview(BuildContext context, StateSetter updateDetail) { + final target = instance == null ? null : _target(service, task, servers); + return QueueTaskOverview( + key: PageStorageKey('${task['id']}:overview'), + task: task, + card: card, + tasks: queue.tasks, + onOpenTask: (linked) => + _openTask(linked, service, queue, servers, !mobile), + actions: { + QueueTaskAction.start: enabled && !queue.auto + ? () => _start(queue, task) + : null, + QueueTaskAction.editMode: () => queue.setAuto(false), + QueueTaskAction.withdrawDraft: confirm( + QueueTaskAction.withdrawDraft.label, + ), + QueueTaskAction.removeFromQueue: confirm( + QueueTaskAction.removeFromQueue.label, + ), + QueueTaskAction.moveUp: enabled && !queue.auto && queueIndex > 0 + ? () => _move(queue, task, -1) + : null, + QueueTaskAction.moveDown: + enabled && + !queue.auto && + queueIndex >= 0 && + queueIndex < pending.length - 1 + ? () => _move(queue, task, 1) + : null, + QueueTaskAction.logs: () => selectTab(1, updateDetail), + QueueTaskAction.stop: confirm(QueueTaskAction.stop.label), + QueueTaskAction.close: confirm( + QueuePresentation.controlLabels['close']!, + ), + QueueTaskAction.copyError: () async { + final handoff = QueuePresentation.handoff(task); + final reason = card.reason; + await Clipboard.setData( + ClipboardData( + text: reason == null ? handoff : '$handoff\n\n报错:$reason', ), - ), - ); - final openSuccessor = successor == null - ? null - : () => _openTask(successor, service, queue, servers, !mobile); + ); + _message('已复制报错与任务摘要'); + }, + QueueTaskAction.copySummary: () async { + await Clipboard.setData( + ClipboardData(text: QueuePresentation.taskSummary(task)), + ); + _message('已复制任务摘要'); + }, + QueueTaskAction.results: () => selectTab(2, updateDetail), + QueueTaskAction.deleteRecord: + enabled && + !_deleting && + capabilities is Map && + capabilities['task_delete'] == true + ? () => _deleteRecord(queue, task) + : null, + }, + serverName: target?.name, + onBindServer: () async { + await _bind(service, task, servers); + if (context.mounted) updateDetail(() {}); + }, + onMonitor: target == null + ? null + : () => Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => + ServerDetailPage(args: SpiRequiredArgs(target)), + ), + ), + onTerminal: target == null + ? null + : () => Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => SSHPage( + args: SshPageArgs( + source: ServerSource(target), + initCmd: directory == null + ? null + : 'cd -- ${QueueProtocol.quote(directory)}', + ), + ), + ), + ), + onDirectory: target == null || directory == null + ? null + : () => Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => SftpPage( + args: SftpPageArgs(spi: target, initPath: directory), + ), + ), + ), + details: [ + if ((capabilities is! Map || + capabilities['task_control_receipts'] != true) && + !_ended.contains(state) && + !retiredDraft) + const Text('撤单与停止确认需要更新个人任务服务。'), + if (resource != null) + QueueResourceView(resource: resource, connected: queue.connected), + if (receipts.isNotEmpty || + checksAndEvents.isNotEmpty || + state == 'stopped' && + task['stopped_at'] != null && + !QueuePresentation.reviewClosed(task)) ...[ + const SizedBox(height: 24), + Text('准备检查与事件', style: Theme.of(context).textTheme.titleLarge), + for (final receipt in receipts) + SelectableText( + [ + QueuePresentation.controlOutcomes[receipt['outcome']], + receipt['actor']?['account'], + receipt['at'], + receipt['attempt']?['job'], + receipt['evidence'], + ].whereType().join(' · '), + ), + if (state == 'stopped' && + task['stopped_at'] != null && + !QueuePresentation.reviewClosed(task)) + SelectableText('已证实终止 · ${task['stopped_at']}'), + for (final line in checksAndEvents) + Text('· ${QueuePresentation.overviewEvent(line)}'), + ], + ], + ); + } + return StatefulBuilder( builder: (context, updateDetail) => QueueDetailPane( task: task, @@ -1093,164 +1202,7 @@ class _GpuQueuePageState extends ConsumerState child: IndexedStack( index: _detailTab, children: [ - page('overview', [ - QueueTaskActionCard( - data: card, - actions: { - QueueTaskAction.start: enabled && !queue.auto - ? () => _start(queue, task) - : null, - QueueTaskAction.editMode: () => queue.setAuto(false), - QueueTaskAction.withdrawDraft: confirm( - QueueTaskAction.withdrawDraft.label, - ), - QueueTaskAction.removeFromQueue: confirm( - QueueTaskAction.removeFromQueue.label, - ), - QueueTaskAction.moveUp: - enabled && !queue.auto && queueIndex > 0 - ? () => _move(queue, task, -1) - : null, - QueueTaskAction.moveDown: - enabled && - !queue.auto && - queueIndex >= 0 && - queueIndex < pending.length - 1 - ? () => _move(queue, task, 1) - : null, - QueueTaskAction.logs: () => selectTab(1, updateDetail), - QueueTaskAction.stop: confirm(QueueTaskAction.stop.label), - QueueTaskAction.close: confirm( - QueuePresentation.controlLabels['close']!, - ), - QueueTaskAction.latestReady: openSuccessor, - QueueTaskAction.latest: openSuccessor, - QueueTaskAction.copyError: () async { - final handoff = QueuePresentation.handoff(task); - final reason = card.reason; - await Clipboard.setData( - ClipboardData( - text: reason == null - ? handoff - : '$handoff\n\n报错:$reason', - ), - ); - _message('已复制报错与任务摘要'); - }, - QueueTaskAction.copySummary: () async { - await Clipboard.setData( - ClipboardData(text: QueuePresentation.taskSummary(task)), - ); - _message('已复制任务摘要'); - }, - QueueTaskAction.results: () => selectTab(2, updateDetail), - QueueTaskAction.directory: openDirectory, - QueueTaskAction.deleteRecord: - enabled && - !_deleting && - capabilities is Map && - capabilities['task_delete'] == true - ? () => _deleteRecord(queue, task) - : null, - }, - ), - const SizedBox(height: 16), - SelectableText( - '任务 ID:${task['id']}\n授权:${task['approved_at'] ?? (state == 'ready' ? '等待点击开始' : '未记录授权')}\n${task['description'] ?? ''}', - style: const TextStyle(fontSize: 12), - ), - if (previous != null || latest != null && latest != task['id'] && latest != card.versionId) - Wrap( - spacing: 8, - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - if (previous != null) - versionLink(task['version_relation'] == 'retry' ? '原失败任务' : '上一版本', previous), - if (latest != null && latest != task['id'] && latest != card.versionId) - versionLink('最新版本', latest), - ], - ), - const SizedBox(height: 16), - Text('申请资源需求', style: Theme.of(context).textTheme.titleMedium), - SelectableText(QueuePresentation.requirements(task)), - SelectableText('固定版本:${QueuePresentation.version(task)}'), - if ((capabilities is! Map || capabilities['task_control_receipts'] != true) && - !_ended.contains(state) && !retiredDraft) - const Text('撤单与停止确认需要更新个人任务服务。'), - const Divider(height: 32), - SelectableText( - 'GPU 实例:${QueueTarget.instance(task) ?? '尚未分配'}\n服务器:${target?.name ?? '尚未关联服务器'}\n工作目录:${directory ?? '等待执行端提供'}', - ), - Wrap( - spacing: 8, - runSpacing: 8, - children: [ - TextButton( - onPressed: QueueTarget.instance(task) == null - ? null - : () => _bind(service, task, servers), - child: const Text('关联 / 更改服务器'), - ), - OutlinedButton( - onPressed: target == null - ? null - : () => Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => ServerDetailPage( - args: SpiRequiredArgs(target), - ), - ), - ), - child: const Text('关联服务器监控'), - ), - OutlinedButton( - onPressed: target == null - ? null - : () => Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => SSHPage( - args: SshPageArgs( - source: ServerSource(target), - initCmd: directory == null - ? null - : 'cd -- ${QueueProtocol.quote(directory)}', - ), - ), - ), - ), - child: const Text('SSH 终端'), - ), - if (state != 'completed') - OutlinedButton( - onPressed: openDirectory, - child: const Text('工作目录 / SFTP'), - ), - ], - ), - if (resource != null) - QueueResourceView( - resource: resource, - connected: queue.connected, - ), - const SizedBox(height: 24), - Text('准备检查与事件', style: Theme.of(context).textTheme.titleLarge), - for (final receipt in receipts) - SelectableText([ - QueuePresentation.controlOutcomes[receipt['outcome']], - receipt['actor']?['account'], - receipt['at'], - receipt['attempt']?['job'], - receipt['evidence'], - ].whereType().join(' · ')), - if (task['state'] == 'stopped' && task['stopped_at'] != null && - !QueuePresentation.reviewClosed(task)) - SelectableText('已证实终止 · ${task['stopped_at']}'), - for (final line in [ - ...(task['checks'] as List? ?? []), - ...(task['events'] as List? ?? []), - ]) - Text('· $line'), - ]), + overview(context, updateDetail), page('logs', [ Text( QueuePresentation.compactRequirements(task), diff --git a/serverbox/lib/view/page/gpu_queue/workspace.dart b/serverbox/lib/view/page/gpu_queue/workspace.dart index cff8b9a..1416a9a 100644 --- a/serverbox/lib/view/page/gpu_queue/workspace.dart +++ b/serverbox/lib/view/page/gpu_queue/workspace.dart @@ -1,6 +1,7 @@ import 'package:flutter/services.dart'; import 'package:material_ui/material_ui.dart'; import 'package:server_box/core/gpu_queue/presentation.dart'; +import 'package:server_box/core/gpu_queue/protocol.dart'; class QueueWelcome extends StatelessWidget { const QueueWelcome({super.key, required this.hasServers, required this.onAdd, required this.onGuide}); @@ -336,6 +337,155 @@ class QueueDetailPane extends StatelessWidget { ); } +class QueueTaskOverview extends StatelessWidget { + const QueueTaskOverview({ + super.key, + required this.task, + required this.card, + required this.actions, + required this.tasks, + required this.onOpenTask, + this.serverName, + this.onBindServer, + this.onMonitor, + this.onTerminal, + this.onDirectory, + this.details = const [], + }); + + final Map task; + final QueueTaskActionCardData card; + final Map actions; + final List> tasks; + final ValueChanged> onOpenTask; + final String? serverName; + final VoidCallback? onBindServer, onMonitor, onTerminal, onDirectory; + final List details; + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final id = task['id'] as String; + VoidCallback? openVersion(Object? versionId) { + if (versionId == null || versionId == id) return null; + final linked = tasks.where((item) => item['id'] == versionId).firstOrNull; + return linked == null ? null : () => onOpenTask(linked); + } + + final openPrevious = openVersion(task['previous_task_id']); + final latest = task['latest_task_id']; + final openLatest = latest == card.versionId ? null : openVersion(latest); + final openCardVersion = openVersion(card.versionId); + final instance = QueuePresentation.assignedInstance(task); + final directory = QueueTarget.directory(task); + final accessInfo = { + 'GPU 实例': ?instance, + '服务器': ?serverName, + '工作目录': ?directory, + }; + final accessActions = { + if (onBindServer case final bind? when instance != null) + (serverName == null ? '关联服务器' : '更改服务器'): bind, + if (onMonitor case final monitor? when serverName != null) + '关联服务器监控': monitor, + if (onTerminal case final terminal? when serverName != null) + 'SSH 终端': terminal, + if (onDirectory case final open? + when serverName != null && directory != null) + '工作目录 / SFTP': open, + }; + final description = (task['description'] as String?)?.trim(); + return ListView( + padding: const EdgeInsets.all(24), + children: [ + QueueTaskActionCard( + data: card, + actions: { + ...actions, + QueueTaskAction.latest: openCardVersion, + QueueTaskAction.latestReady: openCardVersion, + }, + ), + const SizedBox(height: 12), + Align( + alignment: Alignment.centerLeft, + child: TextButton.icon( + onPressed: () async { + await Clipboard.setData(ClipboardData(text: id)); + if (context.mounted) { + ScaffoldMessenger.of(context) + .showSnackBar(const SnackBar(content: Text('已复制完整任务 ID'))); + } + }, + icon: const Icon(Icons.copy_outlined, size: 16), + label: Text('任务号 ${QueuePresentation.shortTaskId(id)}'), + ), + ), + if (description != null && + description.isNotEmpty && + description != task['name']) + SelectableText(description, style: theme.textTheme.bodySmall), + if (openPrevious != null || openLatest != null) + Wrap( + spacing: 8, + children: [ + if (openPrevious != null) + TextButton( + onPressed: openPrevious, + child: Text( + task['version_relation'] == 'retry' ? '原失败任务' : '上一版本', + ), + ), + if (openLatest != null) + TextButton(onPressed: openLatest, child: const Text('最新版本')), + ], + ), + const SizedBox(height: 12), + Text('申请资源', style: theme.textTheme.titleMedium), + const SizedBox(height: 6), + Table( + columnWidths: const {0: FlexColumnWidth(), 1: FlexColumnWidth(1.6)}, + children: [ + for (final spec in QueuePresentation.resourceSpecs(task).entries) + TableRow( + children: [ + Padding( + padding: const EdgeInsets.only(right: 8, bottom: 4), + child: Text(spec.key, style: theme.textTheme.bodySmall), + ), + SelectableText(spec.value, style: theme.textTheme.bodySmall), + ], + ), + ], + ), + if (accessInfo.isNotEmpty || accessActions.isNotEmpty) ...[ + const Divider(height: 24), + for (final info in accessInfo.entries) + SelectableText( + '${info.key}:${info.value}', + style: theme.textTheme.bodySmall, + ), + if (accessActions.isNotEmpty) ...[ + const SizedBox(height: 8), + Wrap( + spacing: 8, + runSpacing: 4, + children: [ + for (final action in accessActions.entries) + OutlinedButton( + onPressed: action.value, + child: Text(action.key), + ), + ], + ), + ], + ], + ...details, + ], + ); + } +} + class QueueTaskActionCard extends StatelessWidget { const QueueTaskActionCard({ super.key, @@ -349,7 +499,9 @@ class QueueTaskActionCard extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Theme.of(context); - final primary = data.primary; + final primary = data.versionId != null && actions[data.primary] == null + ? null + : data.primary; return Material( color: theme.colorScheme.surfaceContainerHighest, borderRadius: BorderRadius.circular(8), diff --git a/serverbox/test/unit/app/queue_presentation_test.dart b/serverbox/test/unit/app/queue_presentation_test.dart index 5993e2f..9a8f869 100644 --- a/serverbox/test/unit/app/queue_presentation_test.dart +++ b/serverbox/test/unit/app/queue_presentation_test.dart @@ -296,10 +296,7 @@ void main() { expect(successor.secondary, [QueueTaskAction.copySummary]); } expect(card('completed').primary, QueueTaskAction.results); - expect(card('completed').secondary, [ - QueueTaskAction.directory, - QueueTaskAction.deleteRecord, - ]); + expect(card('completed').secondary, [QueueTaskAction.deleteRecord]); }); test('closed exceptions keep their archive status and recorded actions', () { diff --git a/serverbox/test/unit/app/queue_workspace_widget_test.dart b/serverbox/test/unit/app/queue_workspace_widget_test.dart index 60b746f..bbd75c0 100644 --- a/serverbox/test/unit/app/queue_workspace_widget_test.dart +++ b/serverbox/test/unit/app/queue_workspace_widget_test.dart @@ -412,7 +412,7 @@ void main() { control: null, next: null, primary: '查看结果文件', - secondary: '打开工作目录', + secondary: '删除历史记录', icon: Icons.check_circle_outline, ), ]; @@ -512,6 +512,195 @@ void main() { }, ); + testWidgets('overview uses one title and only offers valid version links', ( + tester, + ) async { + const id = 'GQ-0123456789abcdef'; + const previousId = 'GQ-fedcba9876543210'; + const latestId = 'GQ-1122334455667788'; + const title = '示例训练任务'; + String? copied, opened; + tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + (call) async { + if (call.method == 'Clipboard.setData') { + copied = (call.arguments as Map)['text'] as String; + } + return null; + }, + ); + addTearDown( + () => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + null, + ), + ); + + for (final state in [ + 'withdrawn', + 'superseded', + 'cancelled', + 'ready', + 'queued', + 'waiting_gpu', + ]) { + final record = { + 'id': id, + 'name': title, + 'description': title, + 'state': state, + 'latest_task_id': id, + 'previous_task_id': previousId, + 'request_uuid': 'request-fixture', + 'resources': { + 'type': 'GPU', + 'gpus': 2, + 'memory_gb': 24, + 'estimated_hours': 0.25, + }, + 'runtime_limit_seconds': 1200, + }; + await show( + tester, + QueueDetailPane( + task: record, + tab: 0, + onTab: (_) {}, + onClose: () {}, + child: QueueTaskOverview( + task: record, + card: QueuePresentation.taskActionCard(record), + actions: const {}, + tasks: [ + record, + {'id': previousId}, + ], + onOpenTask: (item) => opened = item['id'] as String, + onBindServer: () => fail('Unassigned task offered server binding'), + ), + ), + size: const Size(416, 700), + scale: 1.25, + ); + expect(find.text(title), findsOneWidget, reason: state); + for (final label in [ + '最新版本', + '固定版本', + '未授权', + '原快照', + 'GPU 实例', + '服务器', + '工作目录', + 'SSH 终端', + id, + ]) { + expect(find.textContaining(label), findsNothing, reason: state); + } + if (state == 'withdrawn') { + expect(find.text('已手动撤回,未占用 GPU。'), findsOneWidget); + } + expect(find.text('15 分钟'), findsOneWidget); + expect(find.text('20 分钟'), findsOneWidget); + expect(tester.takeException(), isNull); + } + await tester.tap(find.text('任务号 GQ-01234567…')); + await tester.pump(); + expect(copied, id); + await tester.tap(find.text('上一版本')); + expect(opened, previousId); + + for (final state in ['ready', 'superseded']) { + final record = { + 'id': id, + 'state': state, + 'latest_task_id': latestId, + }; + opened = null; + await show( + tester, + QueueTaskOverview( + task: record, + card: QueuePresentation.taskActionCard(record), + actions: const {}, + tasks: [ + record, + {'id': latestId}, + ], + onOpenTask: (item) => opened = item['id'] as String, + ), + size: const Size(416, 700), + ); + final latest = find.textContaining('最新版本'); + expect(latest, findsOneWidget); + await tester.tap(latest); + expect(opened, latestId); + } + }); + + testWidgets( + 'overview opens available tools for running and completed tasks', + (tester) async { + const labels = ['更改服务器', '关联服务器监控', 'SSH 终端', '工作目录 / SFTP']; + String? opened; + for (final (state, bound, hasDirectory) in [ + ('running', false, true), + ('running', true, false), + ('running', true, true), + ('completed', true, true), + ]) { + final record = { + 'id': 'GQ-0123456789abcdef', + 'name': '示例训练任务', + 'state': state, + 'execution': { + 'instance_id': 'instance-fixture', + if (hasDirectory) 'workspace': '/tmp/example-home/code', + }, + }; + await show( + tester, + QueueDetailPane( + task: record, + tab: 0, + onTab: (_) {}, + onClose: () {}, + child: QueueTaskOverview( + task: record, + card: QueuePresentation.taskActionCard(record), + actions: const {}, + tasks: [record], + onOpenTask: (_) {}, + serverName: bound ? '示例服务器' : null, + onBindServer: () => opened = bound ? labels[0] : '关联服务器', + onMonitor: () => opened = labels[1], + onTerminal: () => opened = labels[2], + onDirectory: () => opened = labels[3], + ), + ), + size: const Size(416, 720), + scale: 1.5, + ); + expect(find.text('GPU 实例:instance-fixture'), findsOneWidget); + expect( + find.text('工作目录:/tmp/example-home/code'), + hasDirectory ? findsOneWidget : findsNothing, + ); + final available = bound + ? labels.take(hasDirectory ? labels.length : labels.length - 1) + : ['关联服务器']; + expect(find.byType(OutlinedButton), findsNWidgets(available.length)); + for (final label in available) { + final button = find.widgetWithText(OutlinedButton, label); + await tester.ensureVisible(button); + await tester.pumpAndSettle(); + await tester.tap(button); + expect(opened, label, reason: state); + } + expect(tester.takeException(), isNull); + } + }, + ); + testWidgets('auto monitoring switches to edit without activating start', ( tester, ) async { diff --git a/tests/test_short_tasks.py b/tests/test_short_tasks.py index 1b92fc3..5b7aa49 100644 --- a/tests/test_short_tasks.py +++ b/tests/test_short_tasks.py @@ -82,6 +82,9 @@ def test_generic_manifest_validates_submits_and_reports_approval(self): status, = self.queue_cli('status', task_id) self.assertEqual(status['state'], 'ready') self.assertIsNone(status['approved_at']) + (detail,) = self.control.state()['tasks'] + self.assertEqual(detail['runtime_limit_seconds'], 17 * 60) + self.assertNotIn('doc', detail) platform = Mock(resources={}) Service({}, self.store, platform).tick() platform.select.assert_not_called()