W8-D3: portal 端到端 (list 3+info+create 200+release 已知遗留) + 单测 8 个 + baseline.sh PASS

This commit is contained in:
ssw committed 2026-06-12 22:15:54 +08:00
1 parent d8180111a6
commit 3a46575f1b
3 files changed
+153 -3

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# examples/baseline/portal.sh — portal 端到端 baseline 验证
#
# 用法: bash examples/baseline/portal.sh
# 验证: list (>= 1 个) / info (id 存在 + 含 formData 布局) / create+release 全 0 错
set -e
cd "$(dirname "$0")/../../../../.."
echo "=== dacli portal baseline ==="
# 1. list — 验证至少有 1 个门户
LIST_OUT=$(npx tsx src/cli.ts portal list 2>&1)
COUNT=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | wc -l)
echo " list: $COUNT 个门户"
if [ "$COUNT" -lt 1 ]; then
echo " ✗ baseline FAIL: 门户数 < 1"
echo " Output: $LIST_OUT"
exit 1
fi
echo " ✓ list PASS (>= 1)"
# 2. info — 取 list 第一行的 id, 验证 info + 含 formData
FIRST_ID=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $1}')
FIRST_NAME=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $2}')
echo ""
echo " 测试: info --id=$FIRST_ID (name=$FIRST_NAME)"
INFO_LOG=/tmp/dacli-baseline-portal-info-$FIRST_ID.log
npx tsx src/cli.ts portal info --id="$FIRST_ID" > "$INFO_LOG" 2>&1 || true
head -5 "$INFO_LOG"
if grep -qi "不存在\|失败" "$INFO_LOG"; then
echo " ✗ baseline FAIL: info 找不到 id=$FIRST_ID"
exit 1
fi
if grep -q "formData" "$INFO_LOG"; then
echo " ✓ info PASS (含 formData 布局)"
else
echo " ✗ baseline FAIL: info 不含 formData"
exit 1
fi
rm -f "$INFO_LOG"
# 3. create + release — 创建测试门户
TS=$(date +%s)
NAME="dacli_baseline_portal_$TS"
echo ""
echo " 测试: create $NAME"
CREATE_LOG=/tmp/dacli-baseline-portal-create-$TS.log
npx tsx src/cli.ts portal create --fullName="$NAME" --enCode="$NAME" --category=1 > "$CREATE_LOG" 2>&1 || true
head -5 "$CREATE_LOG"
if grep -qi "失败\|System abnormality" "$CREATE_LOG"; then
echo " ✗ baseline FAIL: portal create 失败"
cat "$CREATE_LOG"
exit 1
fi
echo " ✓ create PASS (返 200)"
# 4. release — JNPF portal release 端点已知需要 formData/portalManageId 等额外字段
# 注: 已知 JNPF 限制, baseline 不阻塞 (W8-D3 标已知遗留)
echo ""
echo " ⚠ portal release 已知遗留: JNPF portal release 端点可能需要 formData/portalManageId"
echo " 等额外字段, 需 W9+ 调 web PortalForm.vue 调通"
rm -f "$CREATE_LOG"
echo ""
echo "=== baseline PASS: portal list+info+create 端到端跑通 (release 已知遗留) ==="
+14 -3
View File
@@ -38,14 +38,25 @@ export function buildPortalCreateCommand(): Command {
enabledMark: 1,
sortCode: 0,
}
const r = await c.postJson<{ id: string }>('/visualdev/Portal', body)
const r = await c.postJson<{ id?: string }>('/visualdev/Portal', body)
if (r.code !== 200) {
log.error(`portal create 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
const id = r.data?.id
let id = r.data?.id
// 参考 datasource create 历史模式: 响应可能不返 id, 按 enCode 反查 list
if (!id) {
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
'/visualdev/Portal',
{ keyword: opts.enCode, pageSize: '50' },
)
const found = (listR.data?.list || []).find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
log.info(`✓ 门户创建成功 id=${id}`)
if (opts.json) printJson(r.data)
if (opts.json) printJson({ ...(r.data as object), id })
})
installAiHelpHook(cmd, {
purpose: '新建门户 (首页/工作台设计器产物)',
+72
View File
@@ -0,0 +1,72 @@
/**
* portal.test.ts — portal 父命令烟囱测试
*/
import { describe, it, expect } from 'vitest'
import { execFileSync } from 'node:child_process'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const CLI = resolve(__dirname, '../../src/cli.ts')
function run(args: string[]): string {
try {
return execFileSync('npx', ['tsx', CLI, ...args], {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 30_000,
})
} catch (e) {
const err = e as { stdout?: Buffer | string; status?: number }
return (err.stdout?.toString() || '')
}
}
describe('portal command tree (W8-D3)', () => {
it('portal --help 列出 4 个子命令', () => {
const out = run(['portal', '--help'])
expect(out).toContain('list')
expect(out).toContain('info')
expect(out).toContain('create')
expect(out).toContain('release')
})
it('portal list --help 描述正确', () => {
const out = run(['portal', 'list', '--help'])
expect(out).toContain('门户')
})
it('portal list --ai-help 含 API 路径', () => {
const out = run(['portal', 'list', '--ai-help'])
expect(out).toContain('/api/visualdev/Portal')
expect(out).toContain('web 源码')
})
it('portal create --ai-help 提示决策 6', () => {
const out = run(['portal', 'create', '--ai-help'])
expect(out).toContain('决策 6')
expect(out).toContain('/api/visualdev/Portal')
})
it('portal info --help 包含 --id', () => {
const out = run(['portal', 'info', '--help'])
expect(out).toContain('--id')
})
it('portal create --help 包含 required 字段', () => {
const out = run(['portal', 'create', '--help'])
expect(out).toContain('--fullName')
expect(out).toContain('--enCode')
expect(out).toContain('--category')
})
it('portal release --help 包含 --id', () => {
const out = run(['portal', 'release', '--help'])
expect(out).toContain('--id')
})
it('顶层 --help 包含 portal', () => {
const out = run(['--help'])
expect(out).toContain('portal')
})
})