diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..4a655809 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,82 @@ +name: PR checks + +on: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + node: + name: Web, Agent and knowledge contract + # The 3090 runs branches from this private repository only. + if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository + runs-on: [self-hosted, linux, x64, xiaoyi-3090] + timeout-minutes: 30 + env: + CI: true + NEXT_TELEMETRY_DISABLED: 1 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + persist-credentials: false + - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 + with: + node-version: '24.22.1' + package-manager-cache: false + - name: Install locked dependencies + id: dependencies + run: | + npm ci --legacy-peer-deps --no-audit --no-fund + npm --prefix apps/detail-agent-pi ci --no-audit --no-fund + npm run prisma:generate + - name: TypeScript + run: npm run typecheck -- --incremental false + - name: Web tests + if: ${{ !cancelled() && steps.dependencies.outcome == 'success' }} + run: npm test -- --maxWorkers=2 + - name: Node script tests + if: ${{ !cancelled() && steps.dependencies.outcome == 'success' }} + run: npm run test:scripts + - name: Agent tests and white-label checks + if: ${{ !cancelled() && steps.dependencies.outcome == 'success' }} + run: npm run test:agent + - name: Knowledge contract drift + if: ${{ !cancelled() && steps.dependencies.outcome == 'success' }} + env: + KB_SOURCE: ${{ vars.XIAOYI_KB_CONTRACT_SOURCE }} + KB_RELEASE: ${{ vars.XIAOYI_KB_CONTRACT_RELEASE }} + run: | + if [[ -z "$KB_SOURCE" && -z "$KB_RELEASE" ]]; then + echo "No snapshot paths configured. The contract smoke test runs in the Node script suite." >> "$GITHUB_STEP_SUMMARY" + else + : "${KB_SOURCE:?Set the source snapshot path}" "${KB_RELEASE:?Set the release snapshot path}" + node scripts/check-kb-contract-drift.mjs "$KB_SOURCE" "$KB_RELEASE" + fi + + rust: + name: Windows Rust cross-check + if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository + runs-on: [self-hosted, linux, x64, xiaoyi-3090] + timeout-minutes: 45 + defaults: + run: + working-directory: apps/detail-photocraft + env: + CARGO_BUILD_JOBS: 4 + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: x86_64-w64-mingw32-gcc-win32 + CC_x86_64_pc_windows_gnu: x86_64-w64-mingw32-gcc-win32 + CXX_x86_64_pc_windows_gnu: x86_64-w64-mingw32-g++-win32 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + persist-credentials: false + - name: Install the Windows Rust target + run: rustup toolchain install 1.95.0 --profile minimal --target x86_64-pc-windows-gnu + - name: Check Windows client + run: rustup run 1.95.0 cargo check --locked --target x86_64-pc-windows-gnu -p photocraft --all-targets diff --git a/Dockerfile b/Dockerfile index c28df418..5d8a44ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ # 基础镜像(使用 Alpine,手动处理 OpenSSL 兼容性) -# 2026-10-22 核验 Node.js 安全更新,固定 Docker Hub 官方多架构清单。 +# 固定 Node 24 LTS 的 Docker Hub 官方多架构清单。 # Docker Hub 官方多架构清单 digest。生产默认值必须是不可变引用;本地测试 # 如需改镜像源,仍可显式传入 BASE_IMAGE,但发布脚本不得覆盖此默认值。 -ARG BASE_IMAGE=node:22.23.4-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 +ARG BASE_IMAGE=node:24.22.1-alpine@sha256:06d7adf3e0ef61a13f1d28682726366f97a15aa1888c934d3ecec86c33918b53 ARG ALPINE_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/alpine # Local/CI builds remain possible without Git metadata. Production deployment # supplies the exact SHA and rejects this sentinel before any container starts. ARG VCS_REF=0000000000000000000000000000000000000000 -ARG DETAIL_RENDERER_IMAGE=node:22.23.4-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 +ARG DETAIL_RENDERER_IMAGE=node:24.22.1-alpine@sha256:06d7adf3e0ef61a13f1d28682726366f97a15aa1888c934d3ecec86c33918b53 ARG POSTGRES_CLIENT_IMAGE=postgres:15-alpine@sha256:df7bca0066e6f60cc3dd32faa70caddec20e2c22b58932f79498e5704b23854a FROM ${BASE_IMAGE} AS base diff --git a/package.json b/package.json index ad2300d7..f0058234 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ "lint": "next lint", "typecheck": "tsc --noEmit", "test": "jest", + "test:all": "node scripts/test-all.mjs", + "test:scripts": "node --test --test-concurrency=4 scripts/*.test.mjs scripts/*.test.cjs", + "test:agent": "npm --prefix apps/detail-agent-pi test", + "test:whitelabel": "node --test apps/detail-agent-pi/test/whitelabel.test.mjs", "test:watch": "jest --watch", "test:coverage": "jest --coverage", "storage:legacy-boundary": "node scripts/check-legacy-storage-boundaries.mjs", @@ -102,6 +106,6 @@ } }, "engines": { - "node": ">=22.23.4 <23 || >=24.22.1 <25" + "node": ">=24.22.1 <25" } } diff --git a/scripts/README.md b/scripts/README.md index 0f42c0ce..5a1a16ae 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,6 +1,6 @@ # 脚本说明 -> 更新时间:2026-05-08 +> 更新时间:2026-12-05 > 部署相关脚本以 `scripts/git-incremental-deploy.ps1` 为当前默认口径。 详细说明: @@ -177,3 +177,41 @@ HISTORY_IMPORT_REMOTE_UPLOADS_DIR=/mnt/PoolOne/youyidian-uploads - 命令包含 `--apply --confirm=HARD_DELETE_HISTORY_MATERIALS`。 未确认清单前禁止执行正式硬删除。 + +## 6. Node 24 测试与 PR 检查 + +本机使用 Node 24.22.1 或更新的 Node 24。根仓与小壹智能体各自按锁文件安装依赖。 + +```sh +npm ci --legacy-peer-deps --no-audit --no-fund +npm --prefix apps/detail-agent-pi ci --no-audit --no-fund +npm run prisma:generate +npm run test:all +``` + +`test:all` 依次运行 Web Jest、根仓 Node 脚本测试、小壹智能体完整单测。智能体套件包含 Node 文案和 Rust UI 的白标检查,也可单独运行 `npm run test:whitelabel`。三套都会执行,任一失败时命令退出非零。旧部署入口的 Windows PowerShell 5.1 实机用例由 Windows 执行,Linux 会跳过这两项。 + +[PR 工作流](../.github/workflows/ci.yml) 使用标签 `xiaoyi-3090` 的仓库级 Linux x64 Runner,限本仓分支与手动触发。用独立非 root 账号部署 Runner,准备 Bash、Python 3、Rustup 和 MinGW-w64 Win32 线程模型工具链。工作流给 Runner 账号安装 Rust 1.95.0 及 Windows GNU target,使用 Actions 自己的检出目录和 Cargo 编译产物。 + +## 7. 知识库契约漂移 + +```sh +node scripts/check-kb-contract-drift.mjs <通用源导出目录> <小壹版本目录或出库根目录> +``` + +通用源按 JinBao 导出路径放置 `小壹/release.json` 和它引用的映射、图层清单。小壹侧提供 `manifest.json` 和从同一版本 `bundle.zip` 解压出的 JSON,保留包内路径。传出库根目录时,按各模板 `index.json` 的 `current` 指针选版本。可用脱敏快照,检查只读取 JSON。 + +结果按模板和组件列出绑定、原稿、字体等资产、映射字段、页面、图层及产品资料必填项差异。兼容 `ps_assets` 和 `source.assets`,忽略映射版本号。退出码 `0` 表示一致,`1` 表示发现漂移,`2` 表示输入无法完整校验。 + +CI 使用仓库变量 `XIAOYI_KB_CONTRACT_SOURCE` 和 `XIAOYI_KB_CONTRACT_RELEASE` 指向 Runner 可读的脱敏快照。两个变量都未配置时,执行仓库内的契约冒烟测试。 + +## 8. 一次性诊断归档 + +在仓库的命令、工作流、文档、应用、库代码和其他脚本中逐个核对文件名及调用路径。下列脚本只用于历史排查,已移入 [archive/](./archive/)。 + +| 脚本 | 原用途 | +| --- | --- | +| [analyze-missing-assets.ts](./archive/analyze-missing-assets.ts) | 盘点早期任务详情缺失的素材资产记录 | +| [audit-flower-mismatch.ts](./archive/audit-flower-mismatch.ts) | 只读排查花名与职级串档 | +| [check-materials-status.ts](./archive/check-materials-status.ts) | 检查任务详情素材旧链路迁移前后的状态 | +| [find-audio-materials.ts](./archive/find-audio-materials.ts) | 对照旧本地上传目录定位音频素材 | diff --git a/scripts/analyze-missing-assets.ts b/scripts/archive/analyze-missing-assets.ts similarity index 99% rename from scripts/analyze-missing-assets.ts rename to scripts/archive/analyze-missing-assets.ts index a7e473a3..59d7614a 100644 --- a/scripts/analyze-missing-assets.ts +++ b/scripts/archive/analyze-missing-assets.ts @@ -3,7 +3,7 @@ * 只读分析,不做任何修改 */ -import { prisma } from '../lib/prisma'; +import { prisma } from '../../lib/prisma'; import { access } from 'fs/promises'; import path from 'path'; diff --git a/scripts/audit-flower-mismatch.ts b/scripts/archive/audit-flower-mismatch.ts similarity index 96% rename from scripts/audit-flower-mismatch.ts rename to scripts/archive/audit-flower-mismatch.ts index afcc4b32..5bf4e278 100644 --- a/scripts/audit-flower-mismatch.ts +++ b/scripts/archive/audit-flower-mismatch.ts @@ -5,7 +5,7 @@ * 规则(用户确认):有花名 = 正式员工;无花名 = 外部人员/离职人员。 * 正式员工才应有 M/P 等级;无花名的档案若带等级,极可能是花名册同名串档。 * - * 用法:npx tsx --env-file=.env scripts/audit-flower-mismatch.ts + * 用法:npx tsx --env-file=.env scripts/archive/audit-flower-mismatch.ts */ import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() diff --git a/scripts/check-materials-status.ts b/scripts/archive/check-materials-status.ts similarity index 100% rename from scripts/check-materials-status.ts rename to scripts/archive/check-materials-status.ts diff --git a/scripts/find-audio-materials.ts b/scripts/archive/find-audio-materials.ts similarity index 100% rename from scripts/find-audio-materials.ts rename to scripts/archive/find-audio-materials.ts diff --git a/scripts/check-kb-contract-drift.mjs b/scripts/check-kb-contract-drift.mjs new file mode 100644 index 00000000..caff8480 --- /dev/null +++ b/scripts/check-kb-contract-drift.mjs @@ -0,0 +1,213 @@ +import { existsSync, readFileSync, readdirSync } from 'node:fs' +import { posix, resolve } from 'node:path' +import { parseArgs } from 'node:util' + +const MAX_DIFF_LINES = 60 +const bindingKeys = ['mapping', 'inventory', 'original', 'pages'] +const fields = ['productFields', 'barcodeFields'] + +function readJson(root, path) { + if (typeof path !== 'string' || /[\\:\x00]/u.test(path) + || path.split('/').some(part => part === '' || part === '.' || part === '..')) { + throw new Error('无效的知识包相对路径:' + JSON.stringify(path)) + } + try { + return JSON.parse(readFileSync(resolve(root, path), 'utf8').replace(/^\uFEFF/u, '')) + } catch (error) { + throw new Error(path + ' 无法读取为 JSON(' + (error.code ?? error.name) + ')') + } +} + +function keyed(rows, idOf, label) { + if (!Array.isArray(rows)) throw new Error(label + ' 必须是清单') + const index = new Map() + for (const row of rows) { + const id = idOf(row) + if (!id || index.has(id)) throw new Error(label + ' 中的标识缺失或重复:' + id) + index.set(id, row) + } + return index +} + +function sorted(value) { + if (Array.isArray(value)) return value.map(sorted) + if (value && typeof value === 'object') { + return Object.fromEntries(Object.keys(value).sort().map(key => [key, sorted(value[key])])) + } + return value +} + +function brief(value) { + const json = JSON.stringify(sorted(value)) + if (json === undefined) return '缺失' + return json.length <= 140 ? json : json.slice(0, 137) + '…' +} + +function compareEntries(report, label, source, release) { + for (const id of [...new Set([...source.keys(), ...release.keys()])].sort()) { + const before = source.get(id) + const after = release.get(id) + const location = label + ' ' + id + if (!source.has(id)) report('- 仅小壹包有 ' + location) + else if (!release.has(id)) report('+ 待补入小壹包 ' + location) + else if (JSON.stringify(sorted(before)) !== JSON.stringify(sorted(after))) { + report('~ ' + location + ' 通用源 ' + brief(before) + ' → 小壹包 ' + brief(after)) + } + } +} + +function pick(row, keys) { + return Object.fromEntries(keys.filter(key => row[key] !== undefined).map(key => [key, row[key]])) +} + +function sourceAssets(doc, label) { + const list = doc.source?.assets ?? doc.source?.ps_assets ?? doc.ps_assets + if (list === undefined) return new Map() + return keyed(list.map(asset => ({ + id: asset.asset_id ?? asset.assetId ?? asset.id, + digest: (asset.ps_sha256 ?? asset.sha256)?.toLowerCase(), + canvas: asset.canvas_px ?? asset.canvas, + })), asset => asset.id, label + ' 原稿') +} + +function mappingFields(doc, label) { + return keyed(doc.fields.map(field => ({ + id: field.field_id, + screen: field.screen_id, + type: field.type, + role: field.role, + asset: field.asset_id ?? field.ps_location?.asset_id, + layer: field.ps_location?.path ?? field.ps_location?.name, + layerId: field.ps_location?.layer_id ?? field.ps_location?.id, + embedded: field.embedded_target ?? field.ps_location?.embedded_target, + bounds: (field.type === '图片' ? field.ps_style?.coverage_rect : field.ps_style?.bounds), + })), field => field.id, label + ' 字段') +} + +function inventoryRows(doc, label) { + return keyed(doc.rows.map(row => ({ + id: row.id, + asset: row.asset_id ?? row.assetId, + path: row.path, + kind: row.kind, + parent: row.parent_id, + })), row => row.id == null && !row.path ? null : (row.asset ?? '') + '/' + (row.id ?? row.path), label + ' 图层') +} + +function compareTemplate(sourceRoot, releaseRoot, manifest, report) { + const descriptorPath = posix.join(posix.dirname(manifest.supplement), 'release.json') + const descriptor = readJson(sourceRoot, descriptorPath) + const expected = new Map(Object.entries(descriptor.bindings).map(([key, binding]) => [key, pick(binding, bindingKeys)])) + const published = new Map(Object.entries(manifest.bindings).map(([key, binding]) => [key, pick(binding, bindingKeys)])) + if (!expected.size || !published.size) throw new Error('组件绑定为空') + + if (descriptor.entrypoint !== manifest.entrypoint) { + report('~ 企业规则入口 通用源 ' + brief(descriptor.entrypoint) + ' → 小壹包 ' + brief(manifest.entrypoint)) + } + compareEntries(report, '组件绑定', expected, published) + const files = keyed(manifest.files, file => file.path, '出库文件清单') + const assets = keyed(manifest.assets, asset => asset.path, '出库资产清单') + for (const asset of descriptor.assets ?? []) { + const released = assets.get(asset.path) + if (!released || released.type !== asset.type || released.component !== asset.component) { + report('~ 资产缺失或归属不同 ' + asset.path + ' (' + asset.component + '/' + asset.type + ')') + } + } + + for (const [component, binding] of expected) { + const released = published.get(component) + if (!released) continue + for (const kind of ['mapping', 'inventory']) { + if (files.get(released[kind])?.type !== kind) { + report('- 小壹出库清单缺少 ' + component + ' ' + kind) + continue + } + const left = readJson(sourceRoot, binding[kind]) + const right = readJson(releaseRoot, released[kind]) + const label = component + '/' + kind + for (const [side, doc] of [['通用源', left], ['小壹包', right]]) { + if ((doc.template_id && doc.template_id !== manifest.templateId) || (doc.component && doc.component !== component)) { + report('~ ' + label + ' ' + side + ' 模板或组件标识不一致') + } + } + const rightAssets = sourceAssets(right, label) + compareEntries(report, label + ' 原稿', sourceAssets(left, label), rightAssets) + if (kind === 'inventory') { + compareEntries(report, label + ' 图层', inventoryRows(left, label), inventoryRows(right, label)) + } else { + const originals = released.original + ? [[released.original, rightAssets.size === 1 ? rightAssets.values().next().value?.digest : right.source?.sha256]] + : Object.values(released.pages ?? {}).map(page => [page.original, rightAssets.get(page.assetId)?.digest]) + for (const [path, sha256] of originals) { + const asset = assets.get(path) + if (asset?.type !== 'original' || (sha256 && asset.sha256?.toLowerCase() !== sha256.toLowerCase())) { + report('~ ' + label + ' 原稿与出库资产不一致 ' + path) + } + } + compareEntries(report, label + ' 字段', mappingFields(left, label), mappingFields(right, label)) + const screens = doc => keyed((doc.screens ?? []).map(screen => pick(screen, ['screen_id', 'asset_id', 'bounds'])), + screen => screen.screen_id, label + ' 页面') + compareEntries(report, label + ' 页面', screens(left), screens(right)) + } + } + } + + const productionPath = manifest.productionConfig + if (productionPath) { + const left = readJson(sourceRoot, productionPath) + const right = readJson(releaseRoot, productionPath) + for (const key of fields) { + const intake = config => keyed((config.intake?.[key] ?? []).map(field => + pick(field, ['id', 'type', 'required', 'multiple', 'imageRole', 'options'])), field => field.id, 'intake/' + key) + compareEntries(report, 'intake/' + key, intake(left), intake(right)) + } + } +} + +function releaseDirectories(root) { + if (existsSync(resolve(root, 'manifest.json'))) return [root] + const directories = [] + for (const entry of readdirSync(root, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) { + if (!entry.isDirectory() || !existsSync(resolve(root, entry.name, 'index.json'))) continue + const { current } = readJson(root, entry.name + '/index.json') + if (typeof current !== 'string' || !/^[a-z0-9][a-z0-9._-]*$/iu.test(current)) { + throw new Error(entry.name + '/index.json 缺少有效的 current 版本') + } + directories.push(resolve(root, entry.name, current)) + } + if (!directories.length) throw new Error('小壹目录中没有 manifest.json 或带 index.json 的模板') + return directories +} + +try { + const { values, positionals } = parseArgs({ options: { help: { type: 'boolean', short: 'h' } }, allowPositionals: true }) + if (values.help || positionals.length !== 2) { + console.log('用法:node scripts/check-kb-contract-drift.mjs <通用源导出目录> <小壹版本目录或出库根目录>') + process.exitCode = values.help ? 0 : 2 + } else { + const [sourceRoot, releaseRoot] = positionals + const releases = releaseDirectories(releaseRoot) + let diffCount = 0 + let errors = 0 + for (const root of releases) { + try { + const manifest = readJson(root, 'manifest.json') + if (typeof manifest.templateId !== 'string' || !manifest.templateId) throw new Error('manifest.json 缺少 templateId') + const before = diffCount + compareTemplate(sourceRoot, root, manifest, line => { + if (++diffCount <= MAX_DIFF_LINES) console.log('[' + manifest.templateId + '] ' + line) + }) + if (diffCount === before) console.log('[' + manifest.templateId + '] 契约一致') + } catch (error) { + errors++ + console.error('读取或校验知识契约失败(' + root + '):' + error.message) + } + } + if (diffCount > MAX_DIFF_LINES) console.log('另有 ' + (diffCount - MAX_DIFF_LINES) + ' 条差异未展开') + console.log('已检查 ' + releases.length + ' 套,契约差异 ' + diffCount + ' 条,输入错误 ' + errors + ' 套') + process.exitCode = errors ? 2 : Number(diffCount > 0) + } +} catch (error) { + console.error(error.message) + process.exitCode = 2 +} diff --git a/scripts/check-kb-contract-drift.test.mjs b/scripts/check-kb-contract-drift.test.mjs new file mode 100644 index 00000000..18d6b15f --- /dev/null +++ b/scripts/check-kb-contract-drift.test.mjs @@ -0,0 +1,79 @@ +import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' +import test from 'node:test' + +const script = fileURLToPath(new URL('./check-kb-contract-drift.mjs', import.meta.url)) +const binding = { + inventory: 'DEMO/inventory.json', + mapping: 'DEMO/map.json', + original: 'DEMO/detail.psd', +} +const bindings = { detail: binding } +const assets = [ + { path: binding.original, type: 'original', component: 'detail' }, + { path: 'DEMO/font.otf', type: 'font', component: 'shared' }, +] + +test('compares current JinBao releases and ignores legacy keys and mapping version differences', t => { + const root = mkdtempSync(join(tmpdir(), 'kb-contract-')) + t.after(() => rmSync(root, { recursive: true, force: true })) + + const source = join(root, 'source') + const release = join(root, 'release') + const active = join(release, 'DEMO', '2026-12-05.1') + function write(dir, name, value) { + const path = join(dir, name) + mkdirSync(dirname(path), { recursive: true }) + writeFileSync(path, JSON.stringify(value)) + } + + const mapping = { + fields: [{ field_id: 'D01-image', screen_id: 'D01', type: '图片', ps_location: { path: 'Group/Product' } }], + screens: [{ screen_id: 'D01', bounds: [0, 0, 100, 100] }], + } + const rows = [{ id: 10, asset_id: 'original', path: 'Group/Product' }] + const sourceAsset = { id: 'original', sha256: 'AB', canvas: [100, 100] } + const releasedAsset = { asset_id: 'original', ps_sha256: 'ab', canvas_px: [100, 100] } + const production = { intake: { barcodeFields: [{ id: 'color', type: 'text', required: true }] } } + write(source, 'DEMO/小壹/release.json', { bindings, assets }) + write(source, binding.mapping, { ...mapping, ps_assets: [sourceAsset] }) + write(source, binding.inventory, { rows }) + write(source, 'DEMO/小壹/production.json', production) + write(release, 'DEMO/index.json', { current: '2026-12-05.1' }) + write(active, 'manifest.json', { + templateId: 'DEMO', + supplement: 'DEMO/小壹/无人值守补充说明.md', + productionConfig: 'DEMO/小壹/production.json', + bindings, + assets: assets.map(asset => asset.type === 'original' ? { ...asset, sha256: 'ab' } : asset), + files: ['inventory', 'mapping'].map(type => ({ path: binding[type], type })), + }) + write(active, binding.mapping, { ...mapping, mapping_version: '1', source: { assets: [releasedAsset] } }) + write(active, binding.inventory, { rows, mapping_version: '1' }) + write(active, 'DEMO/小壹/production.json', production) + + const check = dir => spawnSync(process.execPath, [script, source, dir], { encoding: 'utf8' }) + const match = check(release) + assert.equal(match.status, 0, match.stderr || match.stdout) + assert.match(match.stdout, /\[DEMO\] 契约一致/u) + + const changedMapping = { ...mapping, fields: [{ ...mapping.fields[0], ps_location: { path: 'Group/NewProduct' } }] } + write(source, binding.mapping, { ...changedMapping, ps_assets: [sourceAsset] }) + write(source, binding.inventory, { rows: [...rows, { id: 11, asset_id: 'original', path: 'Group/Detail' }] }) + write(source, 'DEMO/小壹/production.json', { intake: { barcodeFields: [{ id: 'color', type: 'text' }] } }) + const diff = check(active) + assert.equal(diff.status, 1, diff.stderr || diff.stdout) + assert.match(diff.stdout, /detail\/mapping 字段 D01-image.*Group\/NewProduct.*Group\/Product/u) + assert.match(diff.stdout, /\+ 待补入小壹包 detail\/inventory 图层 original\/11/u) + assert.match(diff.stdout, /intake\/barcodeFields color/u) + assert.match(diff.stdout, /契约差异 3 条/u) + + rmSync(join(active, binding.inventory)) + const missing = check(release) + assert.equal(missing.status, 2, missing.stderr || missing.stdout) + assert.match(missing.stderr, /inventory\.json 无法读取为 JSON/u) +}) diff --git a/scripts/legacy-worker-bootstrap-deploy.test.mjs b/scripts/legacy-worker-bootstrap-deploy.test.mjs index b71b7cf8..2ee21ece 100644 --- a/scripts/legacy-worker-bootstrap-deploy.test.mjs +++ b/scripts/legacy-worker-bootstrap-deploy.test.mjs @@ -41,7 +41,7 @@ function findBash() { return candidates.find(existsSync) || null } -test('PowerShell 5 parser accepts the one-time bootstrap entry', () => { +test('PowerShell 5 parser accepts the one-time bootstrap entry', { skip: process.platform !== 'win32' }, () => { const command = [ '$tokens=$null', '$errors=$null', @@ -326,7 +326,7 @@ test('write modes are disabled unless both explicit authorization switches are p assert.match(script, /Mode=Audit does not accept write authorization switches/) }) -test('write authorization guard rejects an actual PowerShell invocation before SSH', () => { +test('write authorization guard rejects an actual PowerShell invocation before SSH', { skip: process.platform !== 'win32' }, () => { const args = [ '-NoProfile', '-File', scriptPath, diff --git a/scripts/safe-production-migrate.test.mjs b/scripts/safe-production-migrate.test.mjs index 690048cb..2758bb35 100644 --- a/scripts/safe-production-migrate.test.mjs +++ b/scripts/safe-production-migrate.test.mjs @@ -959,7 +959,7 @@ test('container supply chain and migrator image are immutable while SOP keeps co assert.match( dockerfile, - /^ARG BASE_IMAGE=node:22.23.4-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914$/m, + /^ARG BASE_IMAGE=node:24\.22\.1-alpine@sha256:06d7adf3e0ef61a13f1d28682726366f97a15aa1888c934d3ecec86c33918b53$/m, ) assert.match(deps, /^COPY package\.json package-lock\.json \.\/$/m) assert.match(deps, /npm ci --prefer-offline --no-audit --no-fund --legacy-peer-deps/) diff --git a/scripts/test-all.mjs b/scripts/test-all.mjs new file mode 100644 index 00000000..a2f51f2a --- /dev/null +++ b/scripts/test-all.mjs @@ -0,0 +1,15 @@ +import { spawnSync } from 'node:child_process' + +for (const args of [ + ['run', 'test', '--', '--maxWorkers=2'], + ['run', 'test:scripts'], + ['run', 'test:agent'], +]) { + const result = spawnSync(process.execPath, [process.env.npm_execpath, ...args], { stdio: 'inherit' }) + if (result.error) throw result.error + if (result.signal) { + process.exitCode = 1 + break + } + if (result.status !== 0) process.exitCode = 1 +}