|
1 | 1 | import { spawnSync } from "node:child_process"; |
| 2 | +import { createHash } from "node:crypto"; |
2 | 3 | import { |
3 | 4 | chmodSync, |
4 | 5 | existsSync, |
@@ -307,6 +308,143 @@ function executeParentFilterValidation( |
307 | 308 | } |
308 | 309 |
|
309 | 310 | describe("release validation no-push transport", () => { |
| 311 | + it.each([ |
| 312 | + { name: "local validated package", imported: false, status: 0, calls: 0 }, |
| 313 | + { name: "imported package", imported: true, status: 0, calls: 1 }, |
| 314 | + { name: "imported validator failure", imported: true, checkExit: 7, status: 7, calls: 1 }, |
| 315 | + { |
| 316 | + name: "local source mismatch", |
| 317 | + imported: false, |
| 318 | + wrongSource: true, |
| 319 | + status: 1, |
| 320 | + calls: 0, |
| 321 | + error: "Exact-target package build commit differs from the selected SHA.", |
| 322 | + }, |
| 323 | + { |
| 324 | + name: "imported digest mismatch", |
| 325 | + imported: true, |
| 326 | + wrongDigest: true, |
| 327 | + status: 1, |
| 328 | + calls: 0, |
| 329 | + error: "Declared package tarball SHA-256 differs from package_sha256.", |
| 330 | + }, |
| 331 | + { |
| 332 | + name: "imported version mismatch", |
| 333 | + imported: true, |
| 334 | + wrongVersion: true, |
| 335 | + status: 1, |
| 336 | + calls: 1, |
| 337 | + error: "Resolved package identity differs from the declared immutable tuple.", |
| 338 | + }, |
| 339 | + { |
| 340 | + name: "local metadata mismatch", |
| 341 | + imported: false, |
| 342 | + wrongMetadata: true, |
| 343 | + status: 1, |
| 344 | + calls: 0, |
| 345 | + error: "Exact-target package metadata does not bind the selected SHA and tarball.", |
| 346 | + }, |
| 347 | + ])("validates package identity without repeating local pack checks: $name", (fixture) => { |
| 348 | + const validate = step( |
| 349 | + job(readWorkflow(LIVE_E2E), "prepare_docker_e2e_image"), |
| 350 | + "Validate OpenClaw Docker E2E package", |
| 351 | + ); |
| 352 | + const root = tempDirs.make("release package identity-"); |
| 353 | + const artifacts = join(root, ".artifacts/docker-e2e-package"); |
| 354 | + const bin = join(root, "bin"); |
| 355 | + const calls = join(root, "validator-calls"); |
| 356 | + const output = join(root, "github-output"); |
| 357 | + const source = "a".repeat(40); |
| 358 | + const version = "2026.8.1"; |
| 359 | + for (const directory of [ |
| 360 | + artifacts, |
| 361 | + bin, |
| 362 | + "package/dist", |
| 363 | + "scripts", |
| 364 | + ".release-harness/scripts", |
| 365 | + ]) { |
| 366 | + mkdirSync(resolve(root, directory), { recursive: true }); |
| 367 | + } |
| 368 | + writeFileSync( |
| 369 | + join(root, "package/package.json"), |
| 370 | + JSON.stringify({ name: "openclaw", version }), |
| 371 | + ); |
| 372 | + writeFileSync( |
| 373 | + join(root, "package/dist/build-info.json"), |
| 374 | + JSON.stringify({ commit: fixture.wrongSource ? "b".repeat(40) : source }), |
| 375 | + ); |
| 376 | + const fileName = fixture.imported ? "provided package.tgz" : "openclaw-current.tgz"; |
| 377 | + const tarball = join(artifacts, fileName); |
| 378 | + const pack = spawnSync("tar", ["-czf", tarball, "-C", root, "package"], { encoding: "utf8" }); |
| 379 | + expect(pack.status, pack.stderr).toBe(0); |
| 380 | + const digest = createHash("sha256").update(readFileSync(tarball)).digest("hex"); |
| 381 | + if (fixture.wrongMetadata) { |
| 382 | + writeFileSync( |
| 383 | + join(artifacts, "package-candidate.json"), |
| 384 | + JSON.stringify({ |
| 385 | + name: "openclaw", |
| 386 | + packageSourceSha: source, |
| 387 | + sha256: "b".repeat(64), |
| 388 | + version, |
| 389 | + }), |
| 390 | + ); |
| 391 | + } |
| 392 | + writeFileSync(output, ""); |
| 393 | + writeFileSync(calls, ""); |
| 394 | + // Instrument only the validator/package-manager boundary; identity checks use real tar, jq and hashes. |
| 395 | + writeFileSync( |
| 396 | + join(root, "scripts/check-openclaw-package-tarball.mjs"), |
| 397 | + 'throw new Error("local pack already validated this package");\n', |
| 398 | + ); |
| 399 | + writeFileSync( |
| 400 | + join(root, ".release-harness/scripts/check-openclaw-package-tarball.mjs"), |
| 401 | + 'import fs from "node:fs"; fs.appendFileSync(process.env.VALIDATOR_CALLS, JSON.stringify(process.argv.slice(2)) + "\\n"); process.exit(Number(process.env.CHECK_EXIT));\n', |
| 402 | + ); |
| 403 | + writeFileSync( |
| 404 | + join(bin, "pnpm"), |
| 405 | + '#!/usr/bin/env bash\n[[ "$1" == exec ]] || exit 98\nshift\nexec "$@"\n', |
| 406 | + ); |
| 407 | + chmodSync(join(bin, "pnpm"), 0o755); |
| 408 | + const result = spawnSync("bash", ["-euo", "pipefail", "-c", validate.run ?? ""], { |
| 409 | + cwd: root, |
| 410 | + encoding: "utf8", |
| 411 | + env: { |
| 412 | + PATH: `${bin}:${process.env.PATH ?? ""}`, |
| 413 | + CHECK_EXIT: String(fixture.checkExit ?? 0), |
| 414 | + EXPECTED_PACKAGE_FILE_NAME: fixture.imported ? fileName : "", |
| 415 | + EXPECTED_PACKAGE_SHA256: fixture.imported |
| 416 | + ? fixture.wrongDigest |
| 417 | + ? "b".repeat(64) |
| 418 | + : digest |
| 419 | + : "", |
| 420 | + EXPECTED_PACKAGE_SOURCE_SHA: fixture.imported ? source : "", |
| 421 | + EXPECTED_PACKAGE_VERSION: fixture.imported |
| 422 | + ? fixture.wrongVersion |
| 423 | + ? "2026.7.1" |
| 424 | + : version |
| 425 | + : "", |
| 426 | + GITHUB_OUTPUT: output, |
| 427 | + GITHUB_STEP_SUMMARY: join(root, "summary"), |
| 428 | + GITHUB_WORKSPACE: root, |
| 429 | + SELECTED_SHA: source, |
| 430 | + SHARED_IMAGE_POLICY: "no-push-artifact", |
| 431 | + VALIDATOR_CALLS: calls, |
| 432 | + }, |
| 433 | + }); |
| 434 | + expect(result.status, result.stderr).toBe(fixture.status); |
| 435 | + if (fixture.error) { |
| 436 | + expect(result.stderr).toContain(fixture.error); |
| 437 | + } |
| 438 | + expect(readFileSync(calls, "utf8")).toBe( |
| 439 | + fixture.calls ? `${JSON.stringify([join(artifacts, "openclaw-current.tgz")])}\n` : "", |
| 440 | + ); |
| 441 | + expect(readFileSync(output, "utf8")).toBe( |
| 442 | + fixture.status === 0 |
| 443 | + ? `sha256=${digest}\nversion=${version}\nfile_name=openclaw-current.tgz\nsource_sha=${source}\ntag=pkg-${digest.slice(0, 32)}\n` |
| 444 | + : "", |
| 445 | + ); |
| 446 | + }); |
| 447 | + |
310 | 448 | it("routes release retries through explicit concrete groups and resource gates", () => { |
311 | 449 | const full = readWorkflow(FULL_RELEASE); |
312 | 450 | const release = readWorkflow(RELEASE_CHECKS); |
|
0 commit comments