import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import test from 'node:test' const commandsView = await readFile(new URL('../src/views/Commands.vue', import.meta.url), 'utf8') const balanceDrawer = await readFile(new URL('../src/components/commands/BalanceDrawer.vue', import.meta.url), 'utf8') const commandChat = await readFile(new URL('../src/components/commands/CommandChat.vue', import.meta.url), 'utf8') const commandTimeline = await readFile(new URL('../src/components/commands/CommandTimeline.vue', import.meta.url), 'utf8') const commandAudioPlayer = await readFile(new URL('../src/components/commands/CommandAudioPlayer.vue', import.meta.url), 'utf8') const commandComposer = await readFile(new URL('../src/components/commands/CommandComposer.vue', import.meta.url), 'utf8') const balancePanel = await readFile(new URL('../src/components/commands/BalancePanel.vue', import.meta.url), 'utf8') const ruleEditor = await readFile(new URL('../src/components/commands/RuleEditorDrawer.vue', import.meta.url), 'utf8') const commandService = await readFile(new URL('../src/services/commands.ts', import.meta.url), 'utf8') const globalStyles = await readFile(new URL('../src/style.css', import.meta.url), 'utf8') test('command workspace keeps an inline responsive balance rail beside the conversation', () => { const chatIndex = commandsView.indexOf('= 0, 'independent chat is present') assert.ok(balanceIndex > chatIndex, 'balance rail follows chat inside the workspace') assert.match(balanceDrawer, /class="balance-rail"/) assert.match(balanceDrawer, / { assert.match(commandTimeline, /]*controls/) assert.match(commandAudioPlayer, /aria-label="录音播放进度"/) assert.match(commandAudioPlayer, /aria-label="录音音量"/) assert.doesNotMatch(commandAudioPlayer, /\.volume-range\s*\{\s*display:\s*none/) assert.match(commandAudioPlayer, /\.playback-range, \.volume-range \{ height: 44px; \}/) assert.match(commandAudioPlayer, /\.volume-controls \{ grid-column: 1 \/ -1;/) assert.match(commandAudioPlayer, /togglePlayback/) assert.match(commandAudioPlayer, /toggleMuted/) assert.match(commandAudioPlayer, /handleMediaError/) assert.match(commandAudioPlayer, /loadRecording\(attachment\.recording\)/) }) test('command conversation uses the Studio event rail instead of chat bubbles', () => { assert.match(commandChat, /class="chat-title-icon"/) assert.match(commandChat, /实时连接/) assert.match(commandChat, /class="device-target"/) assert.match(commandTimeline, /class="timeline-track"/) assert.match(commandTimeline, /class="event-marker"/) assert.match(commandTimeline, /`tone-\$\{item\.presentation\.tone\}`/) assert.match(commandTimeline, /\.tone-sent \{ color: var\(--ui-communication\); \}/) assert.match(commandTimeline, /\.tone-running, \.tone-waiting \{ color: var\(--ui-warning\); \}/) assert.match(commandTimeline, /\.tone-parsed \{ color: var\(--ui-info\); \}/) assert.match(commandTimeline, /\.tone-success \{ color: var\(--ui-success\); \}/) assert.match(commandTimeline, /\.tone-danger \{ color: var\(--ui-danger\); \}/) assert.equal((globalStyles.match(/--ui-info:/g) || []).length, 2) assert.doesNotMatch(commandTimeline, /class="message"/) }) test('command composer source stays visible above the mobile safe area', () => { assert.match(commandComposer, /env\(safe-area-inset-bottom\)/) assert.match(commandComposer, /@media \(max-width: 1023px\).*position:\s*sticky;\s*bottom:\s*0;/s) assert.match(commandComposer, /@media \(max-width: 820px\).*bottom:\s*calc\(72px \+ env\(safe-area-inset-bottom\)\)/s) assert.match(commandComposer, /v-for="definition in definitions"/) assert.match(commandComposer, /definition\.dangerous/) assert.match(commandComposer, /retargetDeviceCommand/) assert.match(commandComposer, /prefers-reduced-motion: reduce/) }) test('command workspace stacks cleanly at the application mobile boundary', () => { assert.match(commandsView, /@media \(max-width: 1023px\)[\s\S]*grid-template-columns:\s*minmax\(0, 1fr\)/) assert.match(commandsView, /height:\s*690px;\s*min-height:\s*690px/) assert.match(balanceDrawer, /@media \(max-width: 1023px\)[\s\S]*border-top:[^;]+;\s*border-left:\s*0;/) assert.match(commandChat, /@media \(max-width: 640px\)[\s\S]*grid-template-areas:\s*"heading" "device" "actions"/) assert.match(commandTimeline, /@media \(prefers-reduced-motion: reduce\)/) }) test('command realtime stream starts before secondary page data finishes', () => { const pageDataIndex = commandsView.indexOf('const pageData = Promise.all') const historyIndex = commandsView.indexOf('await loadEvents()') const connectIndex = commandsView.indexOf('void stream.connect()') const pageDataAwaitIndex = commandsView.indexOf('await pageData') assert.ok(pageDataIndex >= 0) assert.ok(historyIndex > pageDataIndex) assert.ok(connectIndex > historyIndex) assert.ok(pageDataAwaitIndex > connectIndex) assert.match(commandsView, /await loadEvents\(\)\s+if \(disposed\) return/) assert.match(commandsView, /await pageData\s+if \(disposed\) return/) assert.match(commandsView, /onUnmounted\(\(\) => \{\s+disposed = true/) }) test('command timeline opens at the latest record without stealing historical reading position', () => { assert.match(commandTimeline, /ref="timelineScroll"/) assert.match(commandTimeline, /captureVisibleAnchor/) assert.match(commandTimeline, /restoreVisibleAnchor/) assert.match(commandTimeline, /followingLatest\.value/) assert.match(commandTimeline, /\{\{ pendingRecordCount \}\} 条新记录 · 查看最新/) assert.match(commandTimeline, /prefers-reduced-motion: reduce/) assert.match(commandChat, /:history-version="historyVersion"/) assert.match(commandsView, /historyVersion\.value \+= 1/) }) test('command runtime state refreshes periodically and exposes a unified manual refresh', () => { assert.match(commandsView, /runtimeStatus\.startPolling\(\)/) assert.match(commandsView, /runtimeStatus\.refresh\(\{ background: true \}\)/) assert.match(commandsView, /@refresh="refreshAll"/) assert.match(commandsView, /stream\.lastError\.value/) assert.match(commandChat, /aria-label="刷新命令与状态"/) assert.match(commandChat, /:loading="refreshing"/) assert.match(commandChat, /class="sync-warning" role="status"/) assert.match(commandChat, /:context-key="`\$\{selectedDevice\}:\$\{refreshVersion\}`"/) }) test('carrier rule manager uses the real backend CRUD contract', () => { assert.match(commandService, /api\.get\('\/carrier-query-rules'\)/) assert.match(commandService, /createRule[\s\S]*api\.post\('\/carrier-query-rules', rule\)/) assert.match(commandService, /updateRule[\s\S]*api\.put\(`\/carrier-query-rules\/\$\{encodeURIComponent\(id\)\}`, rule\)/) assert.match(commandService, /deleteRule[\s\S]*api\.delete\(`\/carrier-query-rules\/\$\{encodeURIComponent\(id\)\}`\)/) assert.match(commandsView, /updating\s*\? await commandService\.updateRule\(rule\.id, rule\)/) assert.match(commandsView, /: await commandService\.createRule\(rule\)/) assert.match(commandsView, /const refreshed = await loadRules\(\)/) }) test('carrier rule source and mutation states are explicit without demo data', () => { assert.match(balancePanel, /后端规则库/) assert.match(balancePanel, /内置可覆盖编辑 · 数据库自定义可管理/) assert.match(balancePanel, /v-else-if="rulesError"[\s\S]*role="alert"/) assert.match(ruleEditor, /实时后端规则库/) assert.match(ruleEditor, /同 ID 数据库规则完整替代内置规则;删除覆盖后恢复内置规则/) assert.match(ruleEditor, /数据库中暂无自定义规则/) assert.match(ruleEditor, /自定义规则尚未从后端读取成功/) assert.match(ruleEditor, /`数据库自定义 \$\{loaded \? custom\.length : '—'\}`/) assert.match(ruleEditor, /`服务端内置 \$\{loaded \? builtIn\.length : '—'\}`/) assert.match(ruleEditor, /服务端内置 · 数据库覆盖可编辑/) assert.match(ruleEditor, /@click="startEditing\(rule\)"/) assert.match(ruleEditor, /保存数据库覆盖/) assert.match(balancePanel, /emit\('editRule', rule\)/) assert.match(ruleEditor, /@click="emit\('delete', rule\.id\)"/) assert.match(ruleEditor, /`恢复 \$\{rule\.id\} 的内置规则`/) assert.match(ruleEditor, /ArrowReset24Regular/) assert.match(ruleEditor, /恢复内置规则/) assert.match(ruleEditor, /@click="requestRestore\(rule\.id, \$event\)"/) assert.match(ruleEditor, /只会删除同 ID 的数据库覆盖,随后重新启用服务端内置规则/) assert.match(ruleEditor, /@click="confirmRestore"/) assert.match(ruleEditor, /aria-labelledby="restore-built-in-title"/) assert.match(ruleEditor, /aria-describedby="restore-built-in-description"/) assert.match(ruleEditor, /restoreCancelButton\.value\?\.\$el\?\.focus\(\)/) assert.match(ruleEditor, /trigger\?\.focus\(\)/) assert.match(ruleEditor, /if \(!isOverride\(restorePendingID\.value\)\)/) assert.match(ruleEditor, /props\.builtIn\.map\(\(rule\) => rule\.id\)/) assert.match(ruleEditor, /data-builtin-rule-id/) assert.match(ruleEditor, /:close-on-press-escape="!mutationBusy"/) assert.match(ruleEditor, /:show-close="!mutationBusy"/) assert.match(ruleEditor, /if \(!open && mutationBusy\.value\) return/) assert.match(commandsView, /@restore="restoreBuiltInRule"/) assert.match(commandsView, /removeRule\(id, '已恢复服务端内置规则'\)/) assert.match(ruleEditor, /emit\('save',[\s\S]*isExisting\.value\)/) assert.match(ruleEditor, /loading: props\.loading,[\s\S]*saving: props\.saving/) assert.match(ruleEditor, /class="rule-select" :disabled="mutationBusy"/) assert.match(commandsView, /async function loadRules\(\) \{\s+if \(ruleOperationBlocked\.value\) return false/) assert.ok((commandsView.match(/if \(ruleOperationBlocked\.value\) return/g) || []).length >= 4) assert.match(commandsView, /savingRule\.value = false\s+const refreshed = await loadRules\(\)/) assert.match(commandsView, /deletingRuleID\.value = ''\s+const refreshed = await loadRules\(\)/) assert.match(ruleEditor, /min-height: 44px/) assert.doesNotMatch(ruleEditor, /mock|fixture|demo/i) }) test('carrier rules remain fully reachable in a right-side management tray', () => { assert.match(balancePanel, /const effectiveRules = computed/) assert.doesNotMatch(balancePanel, /effectiveCarrierRules\([^\n]+\)\.slice\(0, 4\)/) assert.match(balancePanel, /v-for="rule in effectiveRules"/) assert.match(balancePanel, /向下滚动可查看并选择全部规则/) assert.match(balancePanel, /aria-label="编辑内置运营商规则"[\s\S]*emit\('editBuiltInRules'\)/) assert.match(balancePanel, /rules-edit-button/) assert.match(balanceDrawer, /@edit-built-in-rules="emit\('editBuiltInRules'\)"/) assert.match(commandsView, /@edit-built-in-rules="openBuiltInRuleEditor"/) assert.match(commandsView, /openRuleEditor\(null, 'builtin'\)/) assert.match(commandsView, /:initial-tab="rulesInitialTab"/) assert.match(ruleEditor, /resetEditor\(props\.initialTab\)/) assert.match(balancePanel, /\.rule-list \{[^}]*overflow-y: auto;/) assert.match(ruleEditor, /