dsh-sansheng-liubu/sansheng/test/master-model.test.js

157 lines
6.8 KiB
JavaScript

// 只测纯视图模型与静态前端契约,绝不 import React 组件入口。
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import {
buildMasterItems,
computeMasterLayoutMode,
filterMasterItems,
groupModelChoices,
modelObjectFromParts,
sortMasterColumnItems,
} from '../src/client/master-model.js'
const CATALOG = {
providers: [
{
provider: 'deepseek',
models: [
{ model: 'deepseek-chat', reasoningEffort: ['low', 'high'] },
{ model: 'deepseek-reasoner' },
],
},
],
}
test('computeMasterLayoutMode 严格按看板有效宽度划分四列 / 三列 / 自动列表', () => {
assert.equal(computeMasterLayoutMode(1280, true), 'board4')
assert.equal(computeMasterLayoutMode(1100, true), 'board3')
assert.equal(computeMasterLayoutMode(900, true), 'list')
assert.equal(computeMasterLayoutMode(900, false), 'board4')
assert.equal(computeMasterLayoutMode(760, false), 'board3')
assert.equal(computeMasterLayoutMode(520, false), 'list')
})
test('groupModelChoices 去重汇总推理等级,且绝不出现 inherit', () => {
const choices = groupModelChoices(CATALOG)
assert.equal(choices.length, 2)
assert.equal(choices[0].value, 'deepseek::deepseek-chat')
assert.deepEqual(choices[0].efforts, ['low', 'high'])
assert.equal(choices[1].value, 'deepseek::deepseek-reasoner')
assert.deepEqual(choices[1].efforts, [])
assert.ok(!choices.some(c => c.value === 'inherit'))
assert.equal(modelObjectFromParts('inherit', ''), null)
assert.deepEqual(modelObjectFromParts('deepseek::deepseek-chat', 'high'), {
provider: 'deepseek',
model: 'deepseek-chat',
reasoningEffort: 'high',
})
})
test('buildMasterItems 汇总流程与执行子项、传播阻塞、纳入未下派需求并剔除已取消项', () => {
const bundles = [
{
project: {
id: 'proj-a',
name: 'alpha',
seats: [
{ id: 'lead', status: 'bound', model: { provider: 'deepseek', model: 'deepseek-chat' } },
{ id: 'zhongshu', status: 'bound', model: { provider: 'deepseek', model: 'deepseek-reasoner' } },
{ id: 'menxia', status: 'bound', model: { provider: 'deepseek', model: 'deepseek-chat' } },
{ id: 'gongbu', status: 'bound', model: { provider: 'deepseek', model: 'deepseek-chat', reasoningEffort: 'high' } },
{ id: 'bingbu', status: 'missing', model: { provider: 'deepseek', model: 'deepseek-chat' } },
],
},
tasks: [
{
id: 't-plan', title: '拟案中', kind: 'workflow', ownerSeatId: 'zhongshu',
stage: 'zhongshu_draft', status: 'running', requirementId: 'R-001', requirementRevision: 1, updatedAt: 100,
},
{
id: 't-rev', title: '待门下复核', kind: 'workflow', ownerSeatId: 'menxia',
stage: 'menxia_review', status: 'prepared', requirementId: 'R-002', requirementRevision: 1, updatedAt: 200,
},
{
id: 't-run', title: '六部并行实施', kind: 'workflow', ownerSeatId: 'gongbu',
stage: 'department_exec', status: 'running', requirementId: 'R-003', requirementRevision: 1, updatedAt: 300,
},
{
id: 't-sub-1', title: '前端样式', kind: 'execution', parentTaskId: 't-run', ownerSeatId: 'gongbu',
status: 'done', result: '已完成', updatedAt: 310,
},
{
id: 't-sub-2', title: '部署验证', kind: 'execution', parentTaskId: 't-run', ownerSeatId: 'bingbu',
status: 'running', deliveryState: 'unknown', deliveryId: 'del-9', note: '会话缺失导致未知', updatedAt: 320,
},
{
id: 't-done', title: '已交付基线', kind: 'workflow', ownerSeatId: 'zhongshu',
stage: 'delivered', status: 'done', deliveryNote: '验收通过', updatedAt: 50,
},
{
id: 't-cancel', title: '作废任务', kind: 'workflow', ownerSeatId: 'zhongshu',
stage: 'zhongshu_draft', status: 'cancelled', updatedAt: 999,
},
],
requirements: [
{ id: 'R-001', revision: 1, title: '已下派的需求', status: 'published', summary: '应由 t-plan 承接' },
{ id: 'R-004', revision: 1, title: '待下派新需求', status: 'ready', summary: '待丞相发布', updatedAt: 400 },
{ id: 'R-005', revision: 1, title: '已取消需求', status: 'cancelled', updatedAt: 500 },
],
artifacts: [
{ id: 'art-1', taskId: 't-sub-1', title: '样式产出', path: 'src/styles.js' },
],
},
]
const items = buildMasterItems(bundles, CATALOG, 1000)
const keys = items.map(i => i.id)
assert.ok(!keys.includes('t-sub-1'), '已归并到父任务的子项不应重复铺在看板顶层')
assert.ok(!keys.includes('t-sub-2'))
assert.ok(!keys.includes('t-cancel'), '已取消任务不应出现在看板')
assert.ok(!keys.includes('R-001'), '已有流转任务覆盖的需求不重复建卡')
assert.ok(!keys.includes('R-005'), '已取消需求不应出现')
assert.ok(keys.includes('R-004'), '未下派活跃需求应落入规划列')
const plan = items.find(i => i.id === 't-plan')
const rev = items.find(i => i.id === 't-rev')
const run = items.find(i => i.id === 't-run')
const reqCard = items.find(i => i.id === 'R-004')
const done = items.find(i => i.id === 't-done')
assert.equal(plan.col, 'planning')
assert.equal(rev.col, 'review')
assert.equal(run.col, 'running')
assert.equal(reqCard.col, 'planning')
assert.equal(done.col, 'done')
assert.deepEqual(run.progress, { done: 1, total: 2 })
assert.equal(run.subtasks.length, 2)
assert.equal(run.artifacts.length, 1)
assert.equal(run.blockage.label, '子项阻塞')
assert.equal(run.blockage.canRedispatch, true)
assert.equal(run.blockage.targetTaskId, 't-sub-2')
assert.equal(run.blockage.deliveryId, 'del-9')
const sorted = sortMasterColumnItems([plan, run])
assert.equal(sorted[0].id, 't-run', '阻塞任务在同列排序时置顶')
const filtered = filterMasterItems(items, { projectFilter: 'proj-a', search: '兵部' })
assert.equal(filtered.length, 1)
assert.equal(filtered[0].id, 't-run')
})
test('前端源码静态检查:无 Tailwind CDN、无 inherit 选项、保留关键契约类名与文案', async () => {
const masterSrc = await readFile(new URL('../src/client/master-workbench.js', import.meta.url), 'utf8')
const sidebarSrc = await readFile(new URL('../src/client/workbench-v2.js', import.meta.url), 'utf8')
const stylesSrc = await readFile(new URL('../src/client/styles.js', import.meta.url), 'utf8')
for (const src of [masterSrc, sidebarSrc]) {
assert.doesNotMatch(src, /tailwindcss/i)
assert.doesNotMatch(src, /value:\s*['"]inherit['"]/)
}
assert.match(sidebarSrc, /ssv2 ssw-tab-body/)
assert.match(sidebarSrc, /需求清单/)
assert.match(stylesSrc, /\.ssmwb/)
assert.match(stylesSrc, /\.ssv2/)
})