feat: 收口模板升级与阶段七持续回归

This commit is contained in:
que01 committed 2026-10-17 21:33:57 +08:00
1 parent ec16fff70e
commit 71c528de34
29 files changed
+1962 -304

No files matched your search

+53 -13
View File
@@ -1,7 +1,7 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";
import { cpSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os";
import path from "node:path";
import { test } from "node:test";
@@ -24,17 +24,23 @@ interface Fixture {
function createTemplateFixture(packageKey: string): Fixture {
const root = mkdtempSync(path.join(os.tmpdir(), `template-preview-matrix-${packageKey}-`));
execFileSync(
process.execPath,
[
path.resolve(process.cwd(), "../../scripts/template-pack.cjs"),
"--template",
packageKey,
"--out",
root,
],
{ cwd: path.resolve(process.cwd(), "../.."), stdio: "ignore" },
);
try {
execFileSync(
process.execPath,
[
path.resolve(process.cwd(), "../../scripts/template-pack.cjs"),
"--template",
packageKey,
"--out",
root,
],
{ cwd: path.resolve(process.cwd(), "../.."), stdio: "pipe", encoding: "utf8" },
);
} catch (error) {
const details =
error instanceof Error && "stderr" in error ? String(error.stderr) : String(error);
throw new Error(`Could not package discovered template ${packageKey}: ${details}`);
}
const filename = readdirSync(root).find((item) => item.endsWith(".tar.gz"));
assert.ok(filename);
const archivePath = path.join(root, filename);
@@ -58,8 +64,42 @@ function createTemplateFixture(packageKey: string): Fixture {
};
}
function discoverTemplatePackages(packageRoot: string): string[] {
return readdirSync(packageRoot, { withFileTypes: true })
.filter(
(entry) =>
entry.isDirectory() &&
entry.name.startsWith("template-") &&
readdirSync(path.join(packageRoot, entry.name)).includes("template.json"),
)
.map((entry) => {
const manifest = JSON.parse(
readFileSync(path.join(packageRoot, entry.name, "template.json"), "utf8"),
) as TemplatePackageManifest;
return manifest.packageKey;
})
.sort();
}
test("template preview matrix discovers newly added package manifests", () => {
const packageRoot = mkdtempSync(path.join(os.tmpdir(), "template-discovery-matrix-"));
const source = path.resolve(process.cwd(), "../../packages/template-atelier-solopreneur");
const packageDirectory = path.join(packageRoot, "template-discovery-probe");
cpSync(source, packageDirectory, { recursive: true });
const manifestPath = path.join(packageDirectory, "template.json");
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as TemplatePackageManifest;
writeFileSync(manifestPath, JSON.stringify({ ...manifest, packageKey: "discovery-probe" }));
try {
assert.deepEqual(discoverTemplatePackages(packageRoot), ["discovery-probe"]);
} finally {
rmSync(packageRoot, { recursive: true, force: true });
}
});
test("template preview matrix keeps every deployed package, industry, and version isolated", async () => {
const packageKeys = ["acheng-campus-food", "atelier-solopreneur", "linjing-editorial"];
const packageRoot = path.resolve(process.cwd(), "../../packages");
const packageKeys = discoverTemplatePackages(packageRoot);
assert.ok(packageKeys.length > 0, "at least one template package must be discovered");
const fixtures = packageKeys.map(createTemplateFixture);
let sequence = 0;
const versionFixture = (fixture: Fixture) => {