fix(types): P1 — src tsc errors 33→0
Root cause (24/33): JnpfResp<T> envelope treated as inner type.
- form/_ai.ts: callNcpfBackendWithRetry returns JnpfResp<AiFormResponse>
(body already reads .code/.msg/.data); callAiForm r typed as envelope,
unwrap data explicitly; drop as-unknown-as casts; fix stale workflow log fields
- form/create.ts: infer-category postJson generic was double-wrapped envelope
→ pass inner {id,fullName}; add columnNaming to CreateOpts (option existed)
- form/bindflow.ts: workflow Info get<> passed envelope shape → inner type,
flowNodes typed string|Record instead of any-ized {data?:any}
Stragglers:
- _precheck.ts: await fromToken() before initWebapi
- verify-runner.ts: import currentBaseUrl (was undefined name, real bug); +warn? on VerifyResult
- codegen.ts: ctx.addFix → addSuggestion (only method on ctx)
- audit.ts: source.blindspot → ref (fits type)
- test/render.ts: componentOk widened to number|boolean (holds false|count)
- log.ts: raw writer param (s:string) → (...a) to match writer map contravariance
- kb/_client.ts: install @types/pg (also P4)
Verified: tsc src=0 (total 51→18, rest in tests/); vitest unit 361 pass /
19 fail (fail set == pre-existing blindspot_guards + doc-md-slice, audit §12.2;
no regression in touched files).
Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
d52744d697
commit
e4b9ffa471
11 files changed
+37
-18
No files matched your search
Generated
+13
@@ -27,6 +27,7 @@
|
||||
"@types/bpmn-moddle": "^10.0.0",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/node": "^22.0.0",
|
||||
"@types/pg": "^8.20.0",
|
||||
"pixelmatch": "^6.0.0",
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.6.0",
|
||||
@@ -937,6 +938,18 @@
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/pg": {
|
||||
"version": "8.20.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.20.0.tgz",
|
||||
"integrity": "sha512-bEPFOaMAHTEP1EzpvHTbmwR8UsFyHSKsRisLIHVMXnpNefSbGA1bD6CVy+qKjGSqmZqNqBDV2azOBo8TgkcVow==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"pg-protocol": "*",
|
||||
"pg-types": "^2.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "2.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.9.tgz",
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"@types/bpmn-moddle": "^10.0.0",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/node": "^22.0.0",
|
||||
"@types/pg": "^8.20.0",
|
||||
"pixelmatch": "^6.0.0",
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.6.0",
|
||||
|
||||
@@ -85,7 +85,7 @@ export async function preCheckFormCreate(
|
||||
// 当前只警告不阻断 (datasource 列表可能权限问题 + '0' 主库不在列表)
|
||||
try {
|
||||
const { initWebapi, loadDataSource } = await import('../webapi/dataSource.ts')
|
||||
await initWebapi(_client || (await import('../core/client.ts')).JnpfClient.fromToken())
|
||||
await initWebapi(_client || await (await import('../core/client.ts')).JnpfClient.fromToken())
|
||||
const ds = (await loadDataSource.getDataSourceList({})) as {
|
||||
list?: Array<{ id?: string; enCode?: string; fullName?: string }>
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* - workflow/create.ts: --ai → callAiWorkflow
|
||||
*/
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import type { JnpfResp } from '../../core/types.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
|
||||
/** AI 返回的 form 模型 (5.10.1, 镜像 web 端 VisualAiModel)
|
||||
@@ -157,7 +158,7 @@ import { isTokenPlanExhausted, isLoginExpired, backoffSleep, withSswRetry } from
|
||||
async function callNcpfBackendWithRetry(
|
||||
keyword: string,
|
||||
maxRetries = 3,
|
||||
): Promise<AiFormResponse> {
|
||||
): Promise<JnpfResp<AiFormResponse>> {
|
||||
const c = await JnpfClient.fromToken()
|
||||
let lastError: Error | null = null
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
@@ -207,7 +208,7 @@ async function callNcpfBackendWithRetry(
|
||||
|
||||
export async function callAiForm(keyword: string): Promise<AiFormResponse> {
|
||||
const aiChain: string[] = [] // v0.19+ BS-新72: 调用链, 失败时给用户看
|
||||
let r: AiFormResponse
|
||||
let r: JnpfResp<AiFormResponse>
|
||||
try {
|
||||
r = await callNcpfBackendWithRetry(keyword)
|
||||
} catch (e) {
|
||||
@@ -225,8 +226,8 @@ export async function callAiForm(keyword: string): Promise<AiFormResponse> {
|
||||
// 根因: NCPF 后端 AI 服务 token 失效, SSW /ssw/ai/repair 也走同 token 必 fail
|
||||
// 检测 Login expired 后跳过 SSW fallback (浪费 2 次重试), 直接返回
|
||||
// loginExpired=true 让 create.ts 走 web buildFormData 默认空 schema
|
||||
if (isLoginExpired(r as unknown as { code?: number; msg?: string })) {
|
||||
aiChain.push(`NCPF: Login expired (code=${(r as any).code}, msg=${((r as any).msg || '').slice(0, 80)})`)
|
||||
if (isLoginExpired(r)) {
|
||||
aiChain.push(`NCPF: Login expired (code=${r.code}, msg=${(r.msg || '').slice(0, 80)})`)
|
||||
log.warn(`! NCPF Login expired → AI 后端 token 失效, 跳过 SSW fallback (BS-新113 P1-7)`)
|
||||
log.warn(` SSW 同 token 失效, 不重试 (会浪费 5s/10s/20s), 走 web buildFormData 默认空 schema`)
|
||||
return { _aiChain: aiChain, loginExpired: true }
|
||||
@@ -238,7 +239,7 @@ export async function callAiForm(keyword: string): Promise<AiFormResponse> {
|
||||
|
||||
// 场景 B: 静默截断 (code=200 但 data 空) → fallback SSW
|
||||
// 修复 加 fieldCount 检测, 避免中间截断 (enCode 有但 fields=[]) 漏判
|
||||
const data = r.data || {}
|
||||
const data: AiFormResponse = r.data ?? {}
|
||||
const isEmpty = !data.enCode && !data.fullName && (!data.aiModelList || data.aiModelList.length === 0)
|
||||
// 估算 keyword 实际要求字段数 (每个"/"或"字段"/"列"分隔符 +1)
|
||||
const requiredFieldCount = estimateFieldCount(keyword)
|
||||
@@ -395,7 +396,7 @@ async function callSswAiWorkflowRepair(keyword: string, reason: string): Promise
|
||||
try {
|
||||
const r = await c.postJson<AiWorkflowResponse>('/ssw/ai/repair-workflow', { keyword })
|
||||
if (r.code === 200 && r.data && r.data.flowXml) {
|
||||
log.ok(`✓ SSW workflow 修复成功: enCode=${r.data.enCode}, fullName=${r.data.fullName}, flowXml ${r.data.flowXml.length} 字符`)
|
||||
log.ok(`✓ SSW workflow 修复成功: flowXml ${r.data.flowXml.length} 字符`)
|
||||
return r.data
|
||||
}
|
||||
// SSW 429: retry
|
||||
|
||||
@@ -630,7 +630,7 @@ export function buildFormAuditCommand(): Command {
|
||||
'dacli form audit --all --json | jq .results[].issues # JSON 聚合',
|
||||
],
|
||||
source: {
|
||||
blindspot: 'docs/dos/debug.md §5.2 (dos 26 P0 漏洞) + docs/dos/TC_C_SOURCE_IMPORT.md (testspace 复现)',
|
||||
ref: 'docs/dos/debug.md §5.2 (dos 26 P0 漏洞) + docs/dos/TC_C_SOURCE_IMPORT.md (testspace 复现)',
|
||||
web: 'web/.../FormGenerator/FormGenerator.vue (字段渲染) + web/.../onlineDev/Form.vue (formRules 配置)',
|
||||
api: '/visualdev/Base/{id} (webapi 镜像 formData/columnData/tables)',
|
||||
},
|
||||
|
||||
@@ -92,8 +92,8 @@ export function buildFormBindFlowCommand(): Command {
|
||||
let flowNodes: Record<string, any> = {}
|
||||
let templateMeta: any = {}
|
||||
try {
|
||||
const iR = await c.get<{ data?: any }>(`/workflow/template/Info/${versionId}`)
|
||||
const d = iR.data || {}
|
||||
const iR = await c.get<{ flowXml?: string; flowNodes?: string | Record<string, any>; [k: string]: unknown }>(`/workflow/template/Info/${versionId}`)
|
||||
const d: { flowXml?: string; flowNodes?: string | Record<string, any>; [k: string]: unknown } = iR.data ?? {}
|
||||
templateMeta = d
|
||||
flowXml = d.flowXml || ''
|
||||
if (typeof d.flowNodes === 'string') {
|
||||
@@ -166,9 +166,9 @@ export function buildFormBindFlowCommand(): Command {
|
||||
log.info(`[3] GET /workflow/template/Info/${persistedVersionId} 验证`)
|
||||
let persistedFormId = ''
|
||||
try {
|
||||
const vR = await c.get<{ data?: any }>(`/workflow/template/Info/${persistedVersionId}`)
|
||||
const d = vR.data || {}
|
||||
let nodes: Record<string, any> = d.flowNodes || {}
|
||||
const vR = await c.get<{ flowNodes?: string | Record<string, any>; [k: string]: unknown }>(`/workflow/template/Info/${persistedVersionId}`)
|
||||
const d: { flowNodes?: string | Record<string, any>; [k: string]: unknown } = vR.data ?? {}
|
||||
let nodes: Record<string, any> = (typeof d.flowNodes === 'object' && d.flowNodes) || {}
|
||||
if (typeof d.flowNodes === 'string') {
|
||||
try { nodes = JSON.parse(d.flowNodes) } catch {}
|
||||
}
|
||||
|
||||
@@ -252,14 +252,14 @@ async function autoMountMenu(
|
||||
log.warn(`--auto-menu: 挂菜单失败 (code=${r.code}): ${r.msg}`)
|
||||
log.warn(` 手动: dacli menu create --formId=${formId} --pcParents=${root}`)
|
||||
// v2.4+ L3: codegen 成功但 menu 未挂, 让 AI 跑 log last 看 fallback 命令
|
||||
ctx.addFix(remindCodeGenMenuMountFail(formId, r.code, r.msg))
|
||||
ctx.addSuggestion(remindCodeGenMenuMountFail(formId, r.code, r.msg))
|
||||
return
|
||||
}
|
||||
log.ok(`✓ --auto-menu: 已挂菜单 (fullName=${fullName}, enCode=${enCode}, 父菜单=${root})`)
|
||||
} catch (e) {
|
||||
log.warn(`--auto-menu: 异常 (${(e as Error).message?.slice(0, 100)}), 跳过`)
|
||||
// v2.4+ L3: 异常路径同样归档
|
||||
ctx.addFix(remindCodeGenMenuMountFail(formId, undefined, (e as Error).message?.slice(0, 100)))
|
||||
ctx.addSuggestion(remindCodeGenMenuMountFail(formId, undefined, (e as Error).message?.slice(0, 100)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ interface CreateOpts {
|
||||
verbose?: boolean
|
||||
/** 5.10.1 AI 快速建表 — 自然语言描述, 平台 LLM 生成 enCode/fullName/fields */
|
||||
ai?: string
|
||||
/** columnList 命名规范: auto | snake | f_prefix (默认 snake). 见 --column-naming 选项 (create.ts:315) */
|
||||
columnNaming?: string
|
||||
/** 5.10.2 AI 推荐字段 — 自然语言描述, 平台 LLM 推荐单字段, 不建表单 */
|
||||
aiField?: string
|
||||
// 历史 --ai-json 已删 (跟 --ai 路径重复, 避免两条相似代码路径漂移)
|
||||
@@ -237,7 +239,7 @@ async function autoDeriveCategoryFromBusinessType(
|
||||
if (!picked) {
|
||||
const categoriesJson = JSON.stringify(items.map(it => ({ id: it.id, fullName: it.fullName })))
|
||||
try {
|
||||
const catResp = await c.postJson<{ code?: number; msg?: string; data?: { id?: string; fullName?: string } }>(
|
||||
const catResp = await c.postJson<{ id?: string; fullName?: string }>(
|
||||
'/ssw/ai/infer-category', {
|
||||
formName: formName || appCode,
|
||||
appCode,
|
||||
|
||||
@@ -4386,7 +4386,7 @@ async function renderBigscreen(
|
||||
let configDetails = ''
|
||||
if (config) {
|
||||
let detailOk = false
|
||||
let componentOk = false
|
||||
let componentOk: number | boolean = false
|
||||
if (typeof config.detail === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(config.detail)
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ const _writers: Record<string, (...args: unknown[]) => void> = {
|
||||
ok: (...a) => console.log(`${C.green}✓${C.reset}`, ...a),
|
||||
warn: (...a) => console.warn(`${C.yellow}!${C.reset}`, ...a),
|
||||
dim: (...a) => console.log(`${C.dim}${a.join(' ')}${C.reset}`),
|
||||
raw: (s: string) => process.stdout.write(s),
|
||||
raw: (...a) => process.stdout.write(String(a[0] ?? '')),
|
||||
debug: (...a) => console.error(`${C.dim}[debug]${C.reset}`, ...a),
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
import { existsSync, mkdirSync, copyFileSync, readdirSync, statSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { currentBaseUrl } from './config.ts'
|
||||
|
||||
export interface Deps {
|
||||
playwright: boolean
|
||||
@@ -39,6 +40,7 @@ export interface VerifyResult {
|
||||
sampleUsed?: number
|
||||
error?: string
|
||||
skipped?: boolean
|
||||
warn?: string
|
||||
}
|
||||
|
||||
const WORK_DIR = process.env.CCWORKDIR || '/home/ubuntu/ccWorkDir'
|
||||
|
||||
Reference in new issue
Block a user