53 lines
2.2 KiB
JavaScript
53 lines
2.2 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { setupService } from './helpers.js'
|
|
import { buildWorkbenchView } from '../src/client/workbench.js'
|
|
import { buildPanelView } from '../src/native/panel.js'
|
|
|
|
function childNodes(node) {
|
|
const kids = node?.children ?? node?.items ?? []
|
|
return Array.isArray(kids) ? kids : []
|
|
}
|
|
function countNodes(node) {
|
|
if (!node || typeof node !== 'object') return 0
|
|
let total = 1
|
|
for (const child of childNodes(node)) total += countNodes(child)
|
|
return total
|
|
}
|
|
function depth(node) {
|
|
if (!node || typeof node !== 'object') return 0
|
|
let max = 0
|
|
for (const child of childNodes(node)) max = Math.max(max, depth(child))
|
|
return 1 + max
|
|
}
|
|
|
|
test('宿主项目视图可直接喂给 Web 纯视图模型', async () => {
|
|
const { service } = await setupService()
|
|
const opened = await service.open({ path: '/ui', name: '界面项目' })
|
|
await service.enable(opened.project.id)
|
|
await service.configure(opened.project.id, 'gongbu', { model: { provider: 'deepseek', model: 'deepseek-chat' } })
|
|
|
|
const view = await service.project(opened.project.id)
|
|
const models = await service.models()
|
|
const vm = buildWorkbenchView(view, { selectedSeatId: 'gongbu', models })
|
|
|
|
assert.equal(vm.seats.length, 10)
|
|
assert.ok(vm.seats.every(s => s.name.length === 2))
|
|
assert.deepEqual(vm.groups, { lead: ['lead'], sansheng: ['zhongshu', 'shangshu', 'menxia'], liubu: ['libu', 'hubu', 'lipu', 'bingbu', 'xingbu', 'gongbu'] })
|
|
assert.equal(vm.ready, true)
|
|
assert.equal(vm.selected.id, 'gongbu')
|
|
assert.match(vm.selected.modelLabel, /deepseek-chat/)
|
|
assert.ok(!vm.selected.modelOptions.some(o => o.value === 'inherit'))
|
|
})
|
|
|
|
test('宿主项目视图可直接喂给原生面板并满足容量约束', async () => {
|
|
const { service } = await setupService()
|
|
const opened = await service.open({ path: '/ui2', name: '原生项目' })
|
|
await service.enable(opened.project.id)
|
|
const view = await service.project(opened.project.id)
|
|
const models = await service.models()
|
|
const tree = buildPanelView({ project: view.project, selectedSeatId: 'lead', models })
|
|
assert.ok(countNodes(tree) <= 120, '节点数应 ≤120')
|
|
assert.ok(depth(tree) <= 8, '深度应 ≤8')
|
|
})
|