Files
photoreport/infra/deploy-receiver/src/deploy-guard.test.ts
T
Tiago NevesandClaude Sonnet 5.5 664f55ee83
ci / typescript (push) Skipped
ci / rust (push) Skipped
ci / rust (pull_request) Successful in 5m4s
ci / typescript (pull_request) Successful in 10m56s
fix(deploy): skip SHAs that are not the tip of origin/main (BIT-34038)
A redelivered webhook for an old ancestor passed the ancestry check and reset the site backwards (BIT-34036). deploy.sh now fetches and skips with exit 0 unless SHA == origin/main tip. Rollback path unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-04 22:37:09 +00:00

43 lines
1.8 KiB
TypeScript

import { execFileSync, spawnSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterAll, describe, expect, it } from "vitest";
const SCRIPT = path.resolve(__dirname, "../../deploy/deploy.sh");
const tmp = mkdtempSync(path.join(tmpdir(), "deploy-guard-"));
afterAll(() => rmSync(tmp, { recursive: true, force: true }));
const git = (cwd: string, ...args: string[]) =>
execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd, encoding: "utf8" }).trim();
describe("deploy.sh anti-downgrade (BIT-34038)", () => {
it("skips an old ancestor SHA with exit 0 and leaves the checkout untouched", () => {
const origin = path.join(tmp, "origin.git");
const work = path.join(tmp, "work");
git(tmp, "init", "-q", "--bare", "-b", "main", origin);
git(tmp, "clone", "-q", origin, work);
git(work, "commit", "-q", "--allow-empty", "-m", "old");
const oldSha = git(work, "rev-parse", "HEAD");
git(work, "commit", "-q", "--allow-empty", "-m", "new");
const tip = git(work, "rev-parse", "HEAD");
git(work, "push", "-q", "origin", "main");
const r = spawnSync("bash", [SCRIPT, "pending", oldSha], {
env: { ...process.env, DEPLOY_REPO_DIR: work, DEPLOY_BRANCH: "main" },
encoding: "utf8",
});
expect(r.status).toBe(0);
expect(r.stdout).toContain("SKIP");
expect(git(work, "rev-parse", "HEAD")).toBe(tip);
// The tip itself is deployed (the "workers" service is a no-op build).
const ok = spawnSync("bash", [SCRIPT, "workers", tip], {
env: { ...process.env, DEPLOY_REPO_DIR: work, DEPLOY_BRANCH: "main" },
encoding: "utf8",
});
expect(ok.status).toBe(0);
expect(ok.stdout).toContain("succeeded");
});
});