From ea81c754edd8aab5aad377ab4d3ab5e0c6e96a75 Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 20 Oct 2026 21:24:21 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E5=8C=85=E8=BF=90=E8=A1=8C=E6=97=B6=E9=A2=84=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../raw/completion-evidence.json | 4 +- scripts/deploy/package-release.mjs | 4 ++ scripts/deploy/runtime-preflight.mjs | 57 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 scripts/deploy/runtime-preflight.mjs diff --git a/.codex-tasks/template-audit-execution/raw/completion-evidence.json b/.codex-tasks/template-audit-execution/raw/completion-evidence.json index be35694..b16ec7c 100644 --- a/.codex-tasks/template-audit-execution/raw/completion-evidence.json +++ b/.codex-tasks/template-audit-execution/raw/completion-evidence.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "scope": "模板完成证据登记,保留命令、日志与产物哈希", - "generatedAt": "2026-10-20T09:58:15.011Z", + "generatedAt": "2026-10-20T13:23:08.179Z", "templates": { "acheng-campus-food": { "real-manifest-interaction": { @@ -256,5 +256,5 @@ } } }, - "sourceTreeHash": "a1dbfac7dbf6897814276ca0188c78808c587253307fa6f865761645bf054cdb" + "sourceTreeHash": "d7e89045378d64c92977fbd664fac32902bc6fcdf003d9e79a7c9b6bf5b22c46" } diff --git a/scripts/deploy/package-release.mjs b/scripts/deploy/package-release.mjs index 54251db..ea8c22c 100644 --- a/scripts/deploy/package-release.mjs +++ b/scripts/deploy/package-release.mjs @@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url"; import { spawnSync } from "node:child_process"; import { createRequire } from "node:module"; import { checkPackage } from "./check-package.mjs"; +import { verifyRuntimePreflight } from "./runtime-preflight.mjs"; const require = createRequire(import.meta.url); const { findLeaks, loadConfig } = require("../../apps/taro/config/mask-taro.cjs"); @@ -173,6 +174,8 @@ async function buildTemplateCatalog() { } async function main() { + if (Number(process.versions.node.split(".")[0]) !== 24) + throw new Error("Node.js 24 is required to build the release"); if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,100}$/.test(version)) throw new Error("Invalid release version"); const adminDist = path.join(root, "apps/admin/dist"); @@ -245,6 +248,7 @@ async function main() { } await writeFile(path.join(output, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n"); await checkPackage(output); + await verifyRuntimePreflight(output); run("tar", ["-czf", archive, "-C", output, "."]); const checksum = createHash("sha256") .update(await readFile(archive)) diff --git a/scripts/deploy/runtime-preflight.mjs b/scripts/deploy/runtime-preflight.mjs new file mode 100644 index 0000000..e6ecaf1 --- /dev/null +++ b/scripts/deploy/runtime-preflight.mjs @@ -0,0 +1,57 @@ +import { cp, mkdtemp, rm } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { spawnSync } from "node:child_process"; + +/** + * 在临时目录中验证发布包的运行时依赖闭包。 + * 冻结安装只能证明锁文件一致,不能证明打包时没有遗漏 workspace package。 + */ +export async function verifyRuntimePreflight(releaseDirectory) { + const temporary = await mkdtemp(path.join(os.tmpdir(), "personal-brand-runtime-")); + const apiDirectory = path.join(temporary, "apps/api"); + try { + await cp(releaseDirectory, temporary, { recursive: true }); + run( + "pnpm", + [ + "--filter", + "@personal-brand/api...", + "--filter", + "@personal-brand/taro...", + "--filter", + "@personal-brand/template-acheng-campus-food", + "--filter", + "@personal-brand/template-linjing-editorial", + "--filter", + "@personal-brand/template-atelier-solopreneur", + "install", + "--frozen-lockfile", + "--prefer-offline", + "--ignore-scripts", + ], + temporary, + ); + run("pnpm", ["--filter", "@personal-brand/api", "exec", "prisma", "generate"], temporary); + run( + process.execPath, + ["--input-type=module", "-e", "await import('./dist/main.js')"], + apiDirectory, + { NODE_ENV: "test" }, + ); + } finally { + await rm(temporary, { recursive: true, force: true }); + } +} + +function run(command, args, cwd, extraEnvironment = {}) { + const result = spawnSync(command, args, { + cwd, + stdio: "inherit", + env: { ...process.env, ...extraEnvironment }, + }); + if (result.status !== 0) + throw new Error( + `${command} failed during release runtime preflight with exit ${result.status}`, + ); +}