Skip to content

Commit e455caf

Browse files
authored
fix(release): run ClawHub prepublish fixture from isolated cwd (#120692)
1 parent da4a656 commit e455caf

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

‎scripts/e2e/lib/clawhub-fixture-server.cjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ const profile = process.argv[2];
1111
const portFile = process.argv[3];
1212
const artifactManifestFile = process.argv[4];
1313
const requireFromApp = createRequire(path.join(process.cwd(), "package.json"));
14-
const JSZip = requireFromApp("jszip");
15-
const tar = requireFromApp("tar");
1614
const packageName = "@openclaw/kitchen-sink";
1715
const pluginId = "openclaw-kitchen-sink-fixture";
1816

@@ -211,6 +209,7 @@ const buildClawPackSummary = ({
211209
});
212210

213211
async function buildNpmPackArtifact(fixture) {
212+
const tar = requireFromApp("tar");
214213
const packRoot = await fs.promises.mkdtemp(path.join(os.tmpdir(), "openclaw-clawhub-fixture-"));
215214
try {
216215
const packageDir = path.join(packRoot, "package");
@@ -625,6 +624,7 @@ if (!fixture || !portFile) {
625624
}
626625

627626
async function main() {
627+
const JSZip = requireFromApp("jszip");
628628
const zip = new JSZip();
629629
zip.file("package/package.json", `${JSON.stringify(fixture.packageJson, null, 2)}\n`, {
630630
date: new Date(0),

‎test/scripts/clawhub-fixture-server.test.ts‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import path from "node:path";
66
import type { Readable } from "node:stream";
77
import { setTimeout as delay } from "node:timers/promises";
88
import { afterEach, describe, expect, it } from "vitest";
9-
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
9+
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
1010

11-
const SCRIPT_PATH = "scripts/e2e/lib/clawhub-fixture-server.cjs";
11+
const SCRIPT_PATH = path.resolve("scripts/e2e/lib/clawhub-fixture-server.cjs");
1212
const PACKAGE_NAME = "@openclaw/kitchen-sink";
1313
const PACKAGE_PATH = `/api/v1/packages/${encodeURIComponent(PACKAGE_NAME)}`;
1414
const KITCHEN_SINK_VERSION = "0.2.5";
15-
const tempDirs: string[] = [];
1615
type FixtureServerChild = ChildProcessByStdio<null, Readable, Readable>;
1716
const servers: FixtureServerChild[] = [];
1817

1918
afterEach(async () => {
2019
await Promise.all(servers.splice(0).map(stopServer));
21-
cleanupTempDirs(tempDirs);
2220
});
21+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
2322

2423
function collectStream(stream: NodeJS.ReadableStream) {
2524
let text = "";
@@ -45,11 +44,11 @@ async function stopServer(child: FixtureServerChild) {
4544
}
4645
}
4746

48-
async function startFixtureServer(profile: string, args: string[] = []) {
49-
const root = makeTempDir(tempDirs, "openclaw-clawhub-fixture-server-");
47+
async function startFixtureServer(profile: string, args: string[] = [], cwd = process.cwd()) {
48+
const root = tempDirs.make("openclaw-clawhub-fixture-server-");
5049
const portFile = path.join(root, "port");
5150
const child = spawn(process.execPath, [SCRIPT_PATH, profile, portFile, ...args], {
52-
cwd: process.cwd(),
51+
cwd,
5352
env: { ...process.env },
5453
stdio: ["ignore", "pipe", "pipe"],
5554
});
@@ -80,11 +79,16 @@ async function fetchJson(baseUrl: string, requestPath: string) {
8079
return response.json();
8180
}
8281

83-
function runPrepublishAssertion(baseUrl?: string, packageName?: string, version?: string) {
82+
function runPrepublishAssertion(
83+
baseUrl?: string,
84+
packageName?: string,
85+
version?: string,
86+
cwd = process.cwd(),
87+
) {
8488
return spawnSync(
8589
process.execPath,
8690
[SCRIPT_PATH, "assert-prepublish-requests", baseUrl ?? "", packageName ?? "", version ?? ""],
87-
{ cwd: process.cwd(), encoding: "utf8", env: { ...process.env } },
91+
{ cwd, encoding: "utf8", env: { ...process.env } },
8892
);
8993
}
9094

@@ -141,7 +145,8 @@ describe("ClawHub fixture server", () => {
141145
});
142146

143147
it("serves exact prepublish tarballs through the ClawHub artifact contract", async () => {
144-
const root = makeTempDir(tempDirs, "openclaw-clawhub-prepublish-");
148+
const root = tempDirs.make("openclaw-clawhub-prepublish-");
149+
const isolatedCwd = tempDirs.make("openclaw-clawhub-isolated-");
145150
const packageDir = path.join(root, "package");
146151
const tarball = "openclaw-whatsapp-2026.8.1-beta.1.tgz";
147152
const tarballPath = path.join(root, tarball);
@@ -166,7 +171,11 @@ describe("ClawHub fixture server", () => {
166171
})}\n`,
167172
);
168173

169-
const { baseUrl } = await startFixtureServer("prepublish-artifacts", [manifestPath]);
174+
const { baseUrl } = await startFixtureServer(
175+
"prepublish-artifacts",
176+
[manifestPath],
177+
isolatedCwd,
178+
);
170179
const whatsappPath = `/api/v1/packages/${encodeURIComponent("@openclaw/whatsapp")}`;
171180
const detail = await fetchJson(baseUrl, whatsappPath);
172181
expect(detail.package).toMatchObject({
@@ -190,7 +199,9 @@ describe("ClawHub fixture server", () => {
190199
`GET ${whatsappPath}/versions/${version}/security`,
191200
`GET ${whatsappPath}/versions/${version}/artifact/download`,
192201
]);
193-
expect(runPrepublishAssertion(baseUrl, "@openclaw/whatsapp", version).status).toBe(0);
202+
expect(runPrepublishAssertion(baseUrl, "@openclaw/whatsapp", version, isolatedCwd).status).toBe(
203+
0,
204+
);
194205
expect((await fetch(`${baseUrl}${whatsappPath}/versions/0.0.0/artifact`)).status).toBe(404);
195206
const mismatch = runPrepublishAssertion(baseUrl, "@openclaw/whatsapp", version);
196207
expect(mismatch.status).toBe(1);

0 commit comments

Comments
 (0)