/** * 生成 ONES 回写参数 test-plan/ones-writeback-params.json * * 必测项用例固定、仅新增;用例与步骤的 UUID 与具体测试计划无关(plan UUID 是回写时的变量)。 * 本文件保存:计划内全部用例(号→uuid)+ 控制用例 15974/15975 的步骤 uuid。 * 后续给定任意必测项 plan UUID,即可按 key 规则拼出 key 直接回写: * case: testcase_plan_case-- * step: testcase_plan_case_step--- * * 用法: npx ts-node scripts/gen-writeback-params.ts [--plan CQz9YCNX] [--out test-plan/ones-writeback-params.json] * 用例新增后重跑刷新即可。 */ import { execSync } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; const ONES_CLI = '/Users/woan/local/bin/ones'; const DEFAULT_PLAN = 'CQz9YCNX'; // 必测项-AI自动化 const CONTROL = [ { number: 15975, name: '蓝牙控制设备', proto: 'ble' }, { number: 15974, name: 'WiFi控制设备', proto: 'wifi' }, ]; function ones(args: string): any { return JSON.parse(execSync(`${ONES_CLI} ${args}`, { encoding: 'utf-8', timeout: 30000 })); } function gql(q: string): any { return JSON.parse(execSync(`${ONES_CLI} graphql '${q.replace(/'/g, "'\\''")}'`, { encoding: 'utf-8', timeout: 30000 })); } function argVal(flag: string): string | undefined { const i = process.argv.indexOf(flag); return i >= 0 ? process.argv[i + 1] : undefined; } function main() { const plan = argVal('--plan') || DEFAULT_PLAN; const out = argVal('--out') || 'test-plan/ones-writeback-params.json'; const pc = gql(`{ testcasePlanCases(filter: { testcasePlan: { uuid_in: ["${plan}"] } }, limit: 300) { testcaseCase { uuid number name } } }`) .data.testcasePlanCases; const cases = pc .map((c: any) => ({ number: c.testcaseCase.number, uuid: c.testcaseCase.uuid, name: c.testcaseCase.name })) .sort((a: any, b: any) => a.number - b.number); const controlCases: Record = {}; for (const c of CONTROL) { const found = ones(`testcase case search --key ${c.number}`).cases?.[0]; controlCases[c.number] = { name: c.name, uuid: found?.uuid, proto: c.proto, steps: (found?.steps || []).map((s: any) => s.uuid), }; } const data = { _note: '必测项回写参数。用例固定仅新增;回写时 plan UUID 为变量。' + 'key 规则: case=testcase_plan_case--; step=testcase_plan_case_step---。' + '刷新: 重跑 scripts/gen-writeback-params.ts。', defaultPlan: plan, cases, controlCases, }; const outPath = path.resolve(__dirname, '..', out); fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.writeFileSync(outPath, JSON.stringify(data, null, 2), 'utf-8'); console.log( `已生成 ${out}: ${cases.length} 用例; ` + Object.entries(controlCases) .map(([n, v]: any) => `${n}=${v.steps.length}步`) .join(', ') ); } main();