99 lines
6.0 KiB
TypeScript
99 lines
6.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { EDDY_EXPORT_PRODUCTS, exportRecipe } from "@bbbug/shared/eddy_export";
|
|
import { exportBuildPrompt, exportBuildCommand } from "../src/eddy_export_build";
|
|
import { airbuildSkill, pinBranch } from "../src/eddy_export_config";
|
|
import { spawnSync } from "node:child_process";
|
|
|
|
describe("Eddy export build", () => {
|
|
test("the task's product picks the recipe; nothing is configured per node", () => {
|
|
expect(exportRecipe("notes", "tiktok-ios")?.app).toBe("TikTokNotes.app");
|
|
expect(exportRecipe("lemon8", "tiktok-ios")).toBeNull();
|
|
expect(exportRecipe("tiktok", "tiktok-android")).toBeNull();
|
|
const pairs = EDDY_EXPORT_PRODUCTS.map(r => r.product + "/" + r.repoKey);
|
|
expect(new Set(pairs).size).toBe(pairs.length);
|
|
for (const r of EDDY_EXPORT_PRODUCTS) {
|
|
expect(r.key).toMatch(/^[a-z][a-z0-9-]{0,39}$/);
|
|
expect(r.app).toMatch(/^[A-Za-z0-9]+\.app$/);
|
|
}
|
|
});
|
|
|
|
test("the agent builds the pinned commit through the airbuild skill section for the product", () => {
|
|
const recipe = exportRecipe("whee", "tiktok-ios")!;
|
|
const prompt = exportBuildPrompt({ recipe, commit: "a".repeat(40), branch: "feature/x", checkout: "/ws/TikTok", out: "/x/build", receipt: "/x/airbuild-receipt.json" });
|
|
expect(prompt).toContain("Skill(airbuild)");
|
|
expect(prompt).toContain("「工程专用」里 Whee 的部分");
|
|
// On the branch name: airb sync cannot reach a feature-branch commit from a detached HEAD.
|
|
expect(prompt).toContain("共享检出 `/ws/TikTok`,已在分支 `feature/x` 上、固定在提交 `" + "a".repeat(40) + "`");
|
|
expect(prompt).not.toContain("分离 HEAD");
|
|
expect(prompt).not.toContain("git fetch");
|
|
expect(prompt).toContain("`Whee.app`");
|
|
expect(prompt).toContain("/x/airbuild-receipt.json");
|
|
// Whee builds with its extensions (`make whee ext`); nothing tells the agent to strip them.
|
|
expect(prompt).not.toContain("WheeNotificationService");
|
|
});
|
|
|
|
test("the agent reuses the checkout's Airspace instead of opening one per export", () => {
|
|
// Two Airspaces per person: a fresh one per export (and the failed ones kept) exhausted the quota.
|
|
const prompt = exportBuildPrompt({ recipe: exportRecipe("tiktok", "tiktok-ios")!, commit: "a".repeat(40), branch: "feature/x",
|
|
checkout: "/ws/TikTok", out: "/x/build", receipt: "/x/r.json" });
|
|
expect(prompt).toContain("不要 `airb init` 新开空间");
|
|
expect(prompt).toContain("不要 `airb release`");
|
|
expect(prompt).not.toContain("airb release --force");
|
|
expect(prompt).not.toContain("released");
|
|
});
|
|
|
|
test("the agent starts where fix/verify agents start, with the long Bash ceiling and no secrets added", () => {
|
|
const run = exportBuildCommand("prompt", "/x", { PATH: "/bin", CLUSTER_SECRET: "" });
|
|
// One token: a bare variadic `--add-dir /x` would swallow the prompt the PTY wrapper appends last.
|
|
expect(run.cmd).toContain("--add-dir=/x");
|
|
expect(run.cmd).not.toContain("--add-dir");
|
|
expect(run.env.CLUSTER_SECRET).toBe("");
|
|
expect(Number(run.env.BASH_MAX_TIMEOUT_MS)).toBeGreaterThanOrEqual(3_600_000);
|
|
});
|
|
|
|
test("the airbuild skill is found at project or user level", () => {
|
|
const root = mkdtempSync(path.join(tmpdir(), "airbuild-skill-"));
|
|
try {
|
|
const home = path.join(root, "home"), workspace = path.join(root, "ws");
|
|
expect(airbuildSkill(home, workspace)).toBeNull();
|
|
mkdirSync(path.join(home, ".claude/skills/airbuild"), { recursive: true });
|
|
writeFileSync(path.join(home, ".claude/skills/airbuild/SKILL.md"), "user");
|
|
expect(airbuildSkill(home, workspace)).toBe(path.join(home, ".claude/skills/airbuild/SKILL.md"));
|
|
mkdirSync(path.join(workspace, ".claude/skills/airbuild"), { recursive: true });
|
|
writeFileSync(path.join(workspace, ".claude/skills/airbuild/SKILL.md"), "project");
|
|
expect(airbuildSkill(home, workspace)).toBe(path.join(workspace, ".claude/skills/airbuild/SKILL.md"));
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
});
|
|
|
|
test("the shared checkout is put on the branch name at the pinned commit, keeping local-only commits", async () => {
|
|
const root = mkdtempSync(path.join(tmpdir(), "pin-branch-"));
|
|
const git = (...args: string[]) => spawnSync("git", ["-c", "user.name=F", "-c", "user.email=f@example.invalid", ...args], { cwd: root, encoding: "utf8" }).stdout.trim();
|
|
try {
|
|
git("init", "-q"); writeFileSync(path.join(root, "code"), "1"); git("add", "."); git("commit", "-qm", "1");
|
|
const first = git("rev-parse", "HEAD");
|
|
writeFileSync(path.join(root, "code"), "2"); git("commit", "-qam", "2");
|
|
const pinned = git("rev-parse", "HEAD");
|
|
git("checkout", "-q", "--detach", first);
|
|
// Branch absent → created at the pinned commit.
|
|
expect(await pinBranch(root, "feature/x", pinned)).toEqual({ ok: true, backup: null });
|
|
expect(git("symbolic-ref", "--short", "HEAD")).toBe("feature/x");
|
|
expect(git("rev-parse", "HEAD")).toBe(pinned);
|
|
// Local branch ahead of the pinned commit (unpushed work) → reset, old tip kept.
|
|
writeFileSync(path.join(root, "code"), "3"); git("commit", "-qam", "local only");
|
|
const local = git("rev-parse", "HEAD");
|
|
git("checkout", "-q", "--detach", first);
|
|
const result = await pinBranch(root, "feature/x", pinned);
|
|
expect(result).toEqual({ ok: true, backup: "refs/eddy-export/backup/feature/x/" + local.slice(0, 12) });
|
|
expect(git("rev-parse", "refs/eddy-export/backup/feature/x/" + local.slice(0, 12))).toBe(local);
|
|
expect(git("rev-parse", "HEAD")).toBe(pinned);
|
|
// Behind (fast-forward) → no backup.
|
|
git("branch", "-f", "feature/x", first);
|
|
expect(await pinBranch(root, "feature/x", pinned)).toEqual({ ok: true, backup: null });
|
|
expect((await pinBranch(root, "bad..name", pinned)).ok).toBe(false);
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
});
|
|
});
|