Scope file failures to their requests, preserve accurate route failures and validate Server settings before initialization. Repair source capability and observation lifetimes, restart failed WASM loading, and align playback, input and read-marker state with the owning operation.
319 lines
20 KiB
TypeScript
319 lines
20 KiB
TypeScript
import { execFileSync, spawnSync } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { describe, expect, it } from "vitest";
|
|
import { pullRequestNotes, releaseNotes, releaseNotesSection } from "../scripts/release-notes.mjs";
|
|
import { splitReleaseHeadline } from "../src/shared/release-headline.mjs";
|
|
import { buildVersion, isReleaseVersion, releaseCommits, stableTags } from "../scripts/release-version.mjs";
|
|
import { readReleaseArtifacts } from "../scripts/release-artifacts.mjs";
|
|
|
|
const planner = fileURLToPath(new URL("../scripts/release-version.mjs", import.meta.url));
|
|
const publisher = fileURLToPath(new URL("../scripts/publish-release.mjs", import.meta.url));
|
|
const sha = (value: string) => createHash("sha256").update(value).digest("hex");
|
|
|
|
describe("release automation", () => {
|
|
it("accepts explicit prerelease builds without treating them as stable releases", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "piik-candidate-version-"));
|
|
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
|
|
try {
|
|
git("init", "--quiet", "--initial-branch=main");
|
|
git("config", "user.name", "Piik fixture");
|
|
git("config", "user.email", "fixture@example.invalid");
|
|
git("config", "commit.gpgSign", "false");
|
|
git("commit", "--allow-empty", "-m", "candidate source");
|
|
const revision = git("rev-parse", "HEAD");
|
|
for (const version of ["development", "v3.0.0", "v3.0.0-beta.4", "v3.0.0-rc.1"])
|
|
expect(buildVersion(root, revision, version)).toBe(version);
|
|
for (const version of ["3.0.0-beta.4", "v03.0.0", "v3.0.0-beta.04", "v3.0.0-", "v3.0.0-beta.4+build", " v3.0.0"])
|
|
expect(() => buildVersion(root, revision, version)).toThrow("Build version");
|
|
const beta = "v3.0.0-beta.4";
|
|
expect(isReleaseVersion(beta)).toBe(false);
|
|
expect(() => readReleaseArtifacts(root, beta, revision)).toThrow("stable version");
|
|
expect(() => releaseNotes(root, beta, revision, "owner/repo")).toThrow("stable version");
|
|
git("tag", beta);
|
|
expect(stableTags(root)).toEqual([]);
|
|
expect(buildVersion(root, revision, "")).toBe("development");
|
|
git("commit", "--allow-empty", "-m", "another source");
|
|
expect(() => buildVersion(root, git("rev-parse", "HEAD"), beta)).toThrow("two source revisions");
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
});
|
|
it("shares only an authored leading bilingual headline with the website", () => {
|
|
const opening = "**Play together. Your turn!**\n\n**远程同乐,轮到你啦!**";
|
|
expect(splitReleaseHeadline(`${opening}\n\n### 中文\n\n修复开播。`)).toEqual({
|
|
headline: { "zh-CN": { title: "远程同乐,轮到你啦!", description: "" }, en: { title: "Play together. Your turn!", description: "" } },
|
|
notes: "### 中文\n\n修复开播。",
|
|
});
|
|
expect(splitReleaseHeadline(opening.replaceAll("\n\n", "\r\n\r\n\r\n")).headline)
|
|
.toEqual({ "zh-CN": { title: "远程同乐,轮到你啦!", description: "" }, en: { title: "Play together. Your turn!", description: "" } });
|
|
const explained = "**Play together. Your turn!**\n\nPiik now supports remote control and remote co-play.\n\n" +
|
|
"**远程同乐,轮到你啦!**\n\nPiik 现已支持远程控制与远程同乐。";
|
|
expect(splitReleaseHeadline(`${explained}\n\n### English\n\nSharing fixes.`)).toEqual({
|
|
headline: {
|
|
en: { title: "Play together. Your turn!", description: "Piik now supports remote control and remote co-play." },
|
|
"zh-CN": { title: "远程同乐,轮到你啦!", description: "Piik 现已支持远程控制与远程同乐。" },
|
|
},
|
|
notes: "### English\n\nSharing fixes.",
|
|
});
|
|
for (const body of [undefined, "旧版本说明", "**只有一句**", "** **\n\n**English**",
|
|
"**Fixed** **disconnects**\n\n**Details**", `本次更新\n\n${opening}`, `### 中文\n\n${opening}`]) {
|
|
expect(splitReleaseHeadline(body)).toEqual({ headline: null, notes: body ?? "" });
|
|
}
|
|
});
|
|
|
|
it("validates the PR body against its net product diff before the squash", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "piik-pr-notes-"));
|
|
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
|
|
const commit = () => { git("add", "."); git("commit", "-m", "checkpoint without release notes"); return git("rev-parse", "HEAD"); };
|
|
try {
|
|
git("init", "--quiet", "--initial-branch=main");
|
|
git("config", "user.name", "Piik fixture");
|
|
git("config", "user.email", "fixture@example.invalid");
|
|
git("config", "commit.gpgSign", "false");
|
|
mkdirSync(join(root, "public"));
|
|
mkdirSync(join(root, "site"));
|
|
writeFileSync(join(root, "public/asset.svg"), "art");
|
|
const base = commit();
|
|
writeFileSync(join(root, "README.md"), "guide");
|
|
const docs = commit();
|
|
const event = { pull_request: { number: 1, base: { sha: base }, head: { sha: docs }, body: "" } };
|
|
expect(pullRequestNotes(root, event)).toBe("");
|
|
// Moving a product file out is still a deletion from the shipped surface.
|
|
git("mv", "public/asset.svg", "site/asset.svg");
|
|
event.pull_request.head.sha = commit();
|
|
expect(() => pullRequestNotes(root, event)).toThrow("one nonempty");
|
|
for (const body of ["## Release notes\n???", "## Release notes\n\uFFFD"]) {
|
|
event.pull_request.body = body;
|
|
expect(() => pullRequestNotes(root, event)).toThrow("damaged");
|
|
}
|
|
event.pull_request.body = "## Release notes\nOne\n## Release notes\nTwo";
|
|
expect(() => pullRequestNotes(root, event)).toThrow("one nonempty");
|
|
event.pull_request.body = "## Implementation\nprivate detail\n## Release notes\n修复分享 / Sharing fixes.\nLiteral `code` and $(text).";
|
|
expect(pullRequestNotes(root, event)).toBe("修复分享 / Sharing fixes.\nLiteral `code` and $(text).");
|
|
const eventFile = join(root, "event.json");
|
|
writeFileSync(join(root, ".git/info/exclude"), "event.json\n");
|
|
writeFileSync(eventFile, JSON.stringify(event));
|
|
const script = fileURLToPath(new URL("../scripts/release-notes.mjs", import.meta.url));
|
|
expect(execFileSync(process.execPath, [script, "--pull-request"], {
|
|
cwd: root, encoding: "utf8", env: { ...process.env, GITHUB_EVENT_PATH: eventFile },
|
|
})).toContain("validated");
|
|
// Reverting the product change leaves a documentation-only PR.
|
|
git("mv", "site/asset.svg", "public/asset.svg");
|
|
event.pull_request.head.sha = commit();
|
|
event.pull_request.body = "";
|
|
expect(pullRequestNotes(root, event)).toBe("");
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
}, 15_000);
|
|
|
|
it("publishes reviewed notes, excludes private history and retains every unreleased phase on retries", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "piik-release-notes-"));
|
|
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
|
|
const commit = (message: string, path = "index.html") => {
|
|
mkdirSync(dirname(join(root, path)), { recursive: true });
|
|
writeFileSync(join(root, path), message);
|
|
git("add", "--", path);
|
|
git("commit", "-m", message);
|
|
return git("rev-parse", "HEAD");
|
|
};
|
|
try {
|
|
git("init", "--quiet", "--initial-branch=main");
|
|
git("config", "user.name", "Piik fixture");
|
|
git("config", "user.email", "fixture@example.invalid");
|
|
git("config", "commit.gpgSign", "false");
|
|
commit("chore: private history without release copy");
|
|
const launch = commit("feat: launch\n\n## Problem\nInternal discussion\n\n## Release notes\n" +
|
|
"<!-- Editor guidance -->\n### 开始分享\n\n- 一起玩,一起看。\n\n## Verification\nInternal log");
|
|
const first = releaseNotes(root, "v1.0.0", launch, "fixture/Piik");
|
|
expect(first).toContain("### 开始分享\n\n- 一起玩,一起看。");
|
|
expect(first).toContain(`/tree/${launch}`);
|
|
expect(first).not.toMatch(/private history|Internal|Editor guidance/);
|
|
git("tag", "-a", "v1.0.0", "-m", "Launch");
|
|
expect(releaseNotes(root, "v1.0.0", launch, "fixture/Piik")).toBe(first);
|
|
const website = commit("feat(site)!: redesign the homepage", "site/index.html");
|
|
expect(() => releaseNotes(root, "v1.0.1", website, "fixture/Piik")).toThrow("No release changes");
|
|
expect(releaseNotes(root, "v1.0.1", website, "fixture/Piik", { allowEmpty: true })).toBe("");
|
|
const candidate = JSON.parse(execFileSync(process.execPath, [planner, "build"], {
|
|
cwd: root, encoding: "utf8", env: { ...process.env, PIIK_BUILD_VERSION: "v1.0.1" },
|
|
}));
|
|
expect(candidate).toMatchObject({ version: "v1.0.1", publish: false });
|
|
commit("fix: repair playback\n\n## Release notes\n**Earlier theme**\n\n**旧主题**\n\n- Playback resumes after reconnecting.");
|
|
const opening = "**Play together. Your turn!**\n\nPiik now supports remote control and remote co-play.\n\n" +
|
|
"**远程同乐,轮到你啦!**\n\nPiik 现已支持远程控制与远程同乐。";
|
|
const next = commit(`feat: add a sharing option\n\n## Release notes\n${opening}\n\n- Choose a window to share.`);
|
|
const notes = releaseNotes(root, "v1.1.0", next, "fixture/Piik");
|
|
expect(notes.startsWith(opening)).toBe(true);
|
|
expect(notes).not.toMatch(/旧主题|Earlier theme/);
|
|
expect(notes).toContain("- Playback resumes after reconnecting.\n\n- Choose a window to share.");
|
|
expect(notes).toContain(`/compare/v1.0.0...${next}`);
|
|
expect(notes).not.toContain("开始分享");
|
|
expect(notes).not.toContain("redesign");
|
|
const omitted = commit("fix: reconnect\n\n## Release notes\n- Reconnect reliably.");
|
|
const plain = releaseNotes(root, "v1.1.0", omitted, "fixture/Piik");
|
|
expect(splitReleaseHeadline(plain).headline).toBeNull();
|
|
expect(plain).toContain("- Playback resumes after reconnecting.\n\n- Choose a window to share.\n\n- Reconnect reliably.");
|
|
git("tag", "v1.1.0", next);
|
|
expect(releaseNotes(root, "v1.1.0", next, "fixture/Piik")).toBe(notes);
|
|
// A checkout may have advanced; generation still uses the requested SHA.
|
|
expect(releaseNotes(root, "v1.0.0", launch, "fixture/Piik")).toBe(first);
|
|
const invalid = commit("chore: maintenance");
|
|
expect(() => releaseNotes(root, "v1.1.1", invalid, "fixture/Piik")).toThrow(`Commit ${invalid} needs one nonempty`);
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
}, 15_000); // Real Git subprocesses share the runner with the rest of the suite.
|
|
|
|
it("rejects empty, duplicate, heading-only and damaged notes", () => {
|
|
const headline = "**Play together!**\n\n**一起玩!**";
|
|
for (const section of ["", "## Release notes", "## Release notes\n<!-- Fill in -->\n### Changes",
|
|
"## Release notes\n- One\n## Release notes\n- Two", `## Release notes\n${headline}`]) {
|
|
expect(() => releaseNotesSection(`chore: maintenance\n\n${section}`, "Fixture")).toThrow("one nonempty");
|
|
}
|
|
for (const damaged of ["????????????", "Updated \uFFFD capture"]) {
|
|
expect(() => releaseNotesSection(`fix: capture\n\n## Release notes\n${damaged}`, "Fixture"))
|
|
.toThrow("damaged Release notes");
|
|
}
|
|
});
|
|
|
|
it("plans from immutable tags and all unreleased main changes without editing version files", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "piik-release-plan-"));
|
|
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
|
|
const plan = () => JSON.parse(execFileSync(process.execPath, [planner, "plan"], { cwd: root, encoding: "utf8" }));
|
|
const commit = (message: string, path = "index.html") => {
|
|
mkdirSync(dirname(join(root, path)), { recursive: true });
|
|
writeFileSync(join(root, path), message);
|
|
git("add", "--", path);
|
|
git("commit", "-m", message);
|
|
};
|
|
try {
|
|
git("init", "--quiet", "--initial-branch=main");
|
|
git("config", "user.name", "Piik fixture");
|
|
git("config", "user.email", "fixture@example.invalid");
|
|
git("config", "commit.gpgSign", "false");
|
|
commit("chore: initial");
|
|
expect(plan().version).toBe("v1.0.0");
|
|
const candidate = JSON.parse(execFileSync(process.execPath, [planner, "build"], {
|
|
cwd: root, encoding: "utf8", env: { ...process.env, PIIK_BUILD_VERSION: "v1.0.0" },
|
|
}));
|
|
expect(candidate).toMatchObject({ version: "v1.0.0", publish: false });
|
|
expect(git("tag")).toBe("");
|
|
git("tag", "v1.0.0");
|
|
// The tag might belong to an unfinished draft: publication can resume.
|
|
expect(plan()).toMatchObject({ version: "v1.0.0", publish: true });
|
|
for (const path of ["site/film/art.js", "site/docs/package.json", "site/docs/package-lock.json",
|
|
"site/docs/.vitepress/config.mjs", "docs/guide/troubleshooting.md", "docs/deployment.md", "README.zh-CN.md",
|
|
"scripts/build-website.mjs", "scripts/check-docs.mjs", "scripts/check-container.mjs", "scripts/markdown-slug.mjs", "scripts/release-notes.mjs",
|
|
"scripts/publish-container.mjs",
|
|
"scripts/browser-gate-harness.ts", "scripts/browser-local-pool-probe.ts",
|
|
"scripts/network-lab.ts", "scripts/media-gate-geometry.ts",
|
|
"scripts/network-lab/network.ts", "scripts/network-lab/udp.ts", "scripts/network-lab/packets.ts",
|
|
"tests/room.test.ts", ".agents/skills/ponytail/SKILL.md", ".github/workflows/website.yml",
|
|
".github/workflows/atomgit-mirror.yml", ".github/workflows/gitee-mirror.yml", "mobile/README.md", "scripts/release-mirror-source.mjs"]) {
|
|
mkdirSync(dirname(join(root, path)), { recursive: true });
|
|
writeFileSync(join(root, path), "Peripheral content");
|
|
}
|
|
git("add", ".");
|
|
git("commit", "-m", "feat(site)!: redesign the website\n\nBREAKING CHANGE: website layout only");
|
|
expect(plan()).toMatchObject({ version: "development", publish: false });
|
|
git("rm", ".github/workflows/gitee-mirror.yml");
|
|
git("commit", "-m", "chore(mirror): remove retired workflow");
|
|
expect(plan()).toMatchObject({ version: "development", publish: false });
|
|
commit("fix: repair playback\n\nExample text:\nfeat: is not this commit's type");
|
|
expect(plan().version).toBe("v1.0.1");
|
|
commit("feat(site)!: refresh the film", "site/film/art.js");
|
|
expect(plan()).toMatchObject({ version: "v1.0.1", revision: git("rev-parse", "HEAD"), publish: true });
|
|
commit("feat(app): add a sharing option");
|
|
expect(plan().version).toBe("v1.1.0");
|
|
commit("refactor!: replace the public contract");
|
|
expect(plan().version).toBe("v2.0.0");
|
|
expect(git("tag")).toBe("v1.0.0");
|
|
const reused = spawnSync(process.execPath, [planner, "build"], {
|
|
cwd: root, encoding: "utf8", env: { ...process.env, PIIK_BUILD_VERSION: "v1.0.0" },
|
|
});
|
|
expect(reused.status).not.toBe(0);
|
|
expect(reused.stderr).toContain("two source revisions");
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
}, 15_000); // Real Git subprocesses share the runner with the rest of the suite.
|
|
|
|
it("keeps shipped assets, build inputs and moves across the website boundary release-worthy", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "piik-release-paths-"));
|
|
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
|
|
const plan = () => JSON.parse(execFileSync(process.execPath, [planner, "plan"], { cwd: root, encoding: "utf8" }));
|
|
try {
|
|
git("init", "--quiet", "--initial-branch=main");
|
|
git("config", "user.name", "Piik fixture");
|
|
git("config", "user.email", "fixture@example.invalid");
|
|
git("config", "commit.gpgSign", "false");
|
|
mkdirSync(join(root, "public"));
|
|
writeFileSync(join(root, "public", "asset.svg"), "Shared artwork");
|
|
git("add", ".");
|
|
git("commit", "-m", "feat: launch");
|
|
git("tag", "v1.0.0");
|
|
const inputs = ["src/client/styles.css", "src/shared/protocol.ts", "prototype/channel-server/src/domain.rs",
|
|
"cmd/piik-app/piik.ico", "scripts/windows-capture-deps.mjs", "public/guide.md",
|
|
"licenses/NOTICE.md", "LICENSE", "package-lock.json", ".go-version",
|
|
"scripts/check-rust.mjs", "scripts/app-package-targets.mjs", ".github/workflows/repository-hygiene.yml",
|
|
"new-product-input.json"];
|
|
for (const path of inputs) {
|
|
mkdirSync(dirname(join(root, path)), { recursive: true });
|
|
writeFileSync(join(root, path), "Changed product input");
|
|
git("add", "--", path);
|
|
git("commit", "-m", `fix: update ${path}`);
|
|
}
|
|
const selected = releaseCommits(root, "HEAD", "v1.0.0");
|
|
expect(selected.map(({ message }) => message.trim())).toEqual(inputs.map(path => `fix: update ${path}`));
|
|
expect(plan()).toMatchObject({ version: "v1.0.1", publish: true });
|
|
git("checkout", "--quiet", "--detach", "v1.0.0");
|
|
mkdirSync(join(root, "site"), { recursive: true });
|
|
git("mv", "public/asset.svg", "site/asset.svg");
|
|
git("commit", "-m", "fix: retire the product asset");
|
|
expect(plan()).toMatchObject({ version: "v1.0.1", publish: true });
|
|
git("tag", "v1.0.1");
|
|
mkdirSync(join(root, "public"), { recursive: true });
|
|
git("mv", "site/asset.svg", "public/asset.svg");
|
|
git("commit", "-m", "feat: add the product asset");
|
|
expect(plan()).toMatchObject({ version: "v1.1.0", publish: true });
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
}, 15_000);
|
|
|
|
it("accepts only a complete same-build package set before contacting GitHub", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "piik-release-assets-"));
|
|
const version = "v1.0.0";
|
|
const revision = "a".repeat(40);
|
|
const run = () => spawnSync(process.execPath, [publisher, root, version, revision, "--dry-run"], { encoding: "utf8" });
|
|
try {
|
|
for (const target of ["server", "server-linux-arm64", "server-windows-amd64", "windows-amd64", "linux-amd64", "linux-arm64", "darwin-arm64", "darwin-amd64", "android-universal"]) {
|
|
const server = target.startsWith("server");
|
|
const archive = target === "android-universal" ? "apk" : target === "server-windows-amd64" ? "zip" : server ? "tar.gz" : "zip";
|
|
const artifact = `${target}.${archive}`;
|
|
writeFileSync(join(root, artifact), target);
|
|
const descriptor = { schema: 2, version, revision, artifact, artifactSha256: sha(target),
|
|
target, ...(server ? { manifest: `${target}.manifest.tsv`, manifestSha256: sha("manifest") } : {}) };
|
|
writeFileSync(join(root, `${target}.release.json`), JSON.stringify(descriptor));
|
|
if (server) writeFileSync(join(root, `${target}.manifest.tsv`), "manifest");
|
|
else writeFileSync(join(root, `${artifact}.sha256`), `${sha(target)} ${artifact}\n`);
|
|
}
|
|
const complete = run();
|
|
expect(complete.status, complete.stderr).toBe(0);
|
|
expect(JSON.parse(complete.stdout).targets).toHaveLength(9);
|
|
expect(JSON.parse(complete.stdout).files).toBe(9);
|
|
const androidDescriptor = join(root, "android-universal.release.json");
|
|
const androidMetadata = readFileSync(androidDescriptor, "utf8");
|
|
rmSync(androidDescriptor);
|
|
expect(run().stderr).toContain("every registered Server and App target");
|
|
writeFileSync(androidDescriptor, androidMetadata);
|
|
const checksum = join(root, "windows-amd64.zip.sha256");
|
|
const originalChecksum = readFileSync(checksum, "utf8");
|
|
writeFileSync(checksum, "wrong checksum");
|
|
expect(run().stderr).toContain("App checksum file mismatch");
|
|
writeFileSync(checksum, originalChecksum);
|
|
const path = join(root, "windows-amd64.release.json");
|
|
const original = readFileSync(path, "utf8");
|
|
writeFileSync(path, JSON.stringify({ ...JSON.parse(original), revision: "b".repeat(40) }));
|
|
expect(run().stderr).toContain("Release identity mismatch");
|
|
writeFileSync(path, original);
|
|
writeFileSync(join(root, "windows-amd64.zip"), "changed bytes");
|
|
expect(run().stderr).toContain("checksum mismatch");
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
});
|
|
});
|