59 lines
4.3 KiB
TypeScript
59 lines
4.3 KiB
TypeScript
import { test, expect } from "bun:test";
|
|
import { defaultProductProfiles, snapshotProductProfile } from "@bbbug/shared/product_profiles";
|
|
import type { Task, Feature } from "@bbbug/shared/types";
|
|
import { productRemoteMatches, prepareProductRepository } from "../src/product_profile";
|
|
import { buildSinglePrompt, buildCriticPrompt } from "../src/runner";
|
|
import { buildFeatureFirstPrompt, buildFeatureSecondPrompt } from "../src/feature_runner";
|
|
|
|
const config = defaultProductProfiles();
|
|
config.profiles.forEach((p) => { p.enabled = true; });
|
|
const productProfile = snapshotProductProfile(config, "notes", "ios");
|
|
const tiktokProfile = snapshotProductProfile(config, "tiktok", "ios");
|
|
|
|
test("origin matching checks the namespace, platform and host, not just /TikTok", () => {
|
|
expect(productRemoteMatches("git@code.byted.org:ugc/TikTok.git", "ugc/TikTok")).toBe(true);
|
|
expect(productRemoteMatches("https://code.byted.org/ugc-android/TikTok.git", "ugc-android/TikTok")).toBe(true);
|
|
expect(productRemoteMatches("https://code.byted.org/ugc/TikTok", "ugc-android/TikTok")).toBe(false);
|
|
expect(productRemoteMatches("https://example.org/ugc/TikTok", "ugc/TikTok")).toBe(false);
|
|
expect(productRemoteMatches("https://code.byted.org/ugc/TikTok-fork", "ugc/TikTok")).toBe(false);
|
|
});
|
|
test("legacy and default TikTok preflight do not access the filesystem or network", async () => {
|
|
expect(await prepareProductRepository({ platform: "ios" }, "/definitely/not-a-checkout")).toBeNull();
|
|
expect(await prepareProductRepository({ platform: "ios", productProfile: tiktokProfile }, "/definitely/not-a-checkout")).toBeNull();
|
|
await expect(prepareProductRepository({ platform: "android", productProfile }, "/definitely/not-a-checkout")).rejects.toThrow("Invalid product");
|
|
});
|
|
test("preflight fetches exact base/target refs, pins a commit, and never falls back on failures", async () => {
|
|
const work = { platform: "ios" as const, productProfile: { ...productProfile!, targetBranch: "notes/release" } };
|
|
const commands: string[][] = [];
|
|
const runGit = async (_cwd: string, args: string[]) => {
|
|
commands.push(args);
|
|
return args[0] === "remote" ? "git@code.byted.org:ugc/TikTok.git" : args[0] === "rev-parse" ? "abc123" : "";
|
|
};
|
|
expect(await prepareProductRepository(work, "/fixture", runGit)).toBe("abc123");
|
|
expect(commands[1]).toEqual(["fetch", "--no-tags", "origin", "+refs/heads/notes/develop:refs/remotes/origin/notes/develop", "+refs/heads/notes/release:refs/remotes/origin/notes/release"]);
|
|
expect(commands[2]).toEqual(["rev-parse", "--verify", "refs/remotes/origin/notes/develop^{commit}"]);
|
|
await expect(prepareProductRepository(work, "/fixture", async () => "git@code.byted.org:ugc-android/TikTok.git")).rejects.toThrow("origin does not match");
|
|
await expect(prepareProductRepository(work, "/fixture", async (cwd, args) => {
|
|
if (args[0] === "fetch") throw new Error("branch missing");
|
|
return runGit(cwd, args);
|
|
})).rejects.toThrow("branch missing");
|
|
});
|
|
test("custom branch drives {{baseBranch}}; no extra product contract is appended", () => {
|
|
const task = { id: "profile-test", platform: "ios", productProfile, baseRef: "notes/develop", attempts: 0, lang: "en" } as Task;
|
|
const feature = { ...task, title: "Notes", description: "test", baseRef: "notes/develop" } as unknown as Feature;
|
|
for (const prompt of [
|
|
buildSinglePrompt(task, "/tmp/no-such-profile-test", false, 0, "custom {{baseBranch}}"),
|
|
buildCriticPrompt(task, "/tmp/no-such-profile-test", "custom {{baseBranch}}"),
|
|
buildFeatureFirstPrompt(feature, "/tmp/no-such-profile-test", 0, "custom {{baseBranch}}"),
|
|
buildFeatureSecondPrompt(feature, "/tmp/no-such-profile-test", 0, "custom {{baseBranch}}"),
|
|
]) {
|
|
expect(prompt).toContain("custom notes/develop");
|
|
expect(prompt).not.toContain('"product":"Notes"');
|
|
expect(prompt).not.toContain('"repo":"ugc/TikTok"');
|
|
}
|
|
expect(buildSinglePrompt(task, "/tmp/no-such-profile-test", false, 0)).toContain("本单的基线是特性分支 `notes/develop`");
|
|
expect(buildFeatureFirstPrompt(feature, "/tmp/no-such-profile-test", 0)).toContain("本单的基线是特性分支 `notes/develop`");
|
|
const tiktokTask = { ...task, productProfile: tiktokProfile, baseRef: null };
|
|
expect(buildSinglePrompt(tiktokTask, "/tmp/no-such-profile-test", false, 0)).not.toContain("本单的基线是特性分支");
|
|
});
|