#!/usr/bin/env bun
/**
* End-to-end check for AI merge fixes against a running dev server started with MERGEFIX_PROVIDER=mock.
*
* bun scripts/e2e-mergefix.ts # seeds a user + token in the local D1, uses BASE_URL
* BASE_URL=http://localhost:3000 D1_CWD=/path/to/checkout bun scripts/e2e-mergefix.ts
*
* Scenario 1: a cosmetic conflict is fixed automatically; the merge commit lands on the head branch, is
* marker-free, and a CI run is scheduled for it. Scenario 2: a security-looking conflict is only suggested.
*/
import {
api,
assert,
CI_TIMEOUT_MS,
d1,
EXPECTED_MIN_CALLS,
MERGE_PARENT_FIELDS,
poll,
scenario,
} from "./mergefix-harness";
const line = (middle: string) => `header\none\n${middle}\nthree\nfooter\n`;
const appFile = (lines: { base: string; head: string; main: string }) => [
{ path: "app.txt", base: line(lines.base), head: line(lines.head), main: line(lines.main) },
];
const user = await api<{ login: string }>("GET", "/user");
const stamp = Date.now().toString(36);
const cosmetic = await scenario(
user.login,
`mergefix-e2e-${stamp}`,
appFile({ base: "two", head: "two (head wording)", main: "two (main wording)" }),
);
try {
assert(cosmetic.fix.status === "applied", `expected applied, got ${cosmetic.fix.status}: ${cosmetic.fix.error}`);
const sha = cosmetic.fix.commit_sha;
assert(sha, "fix commit sha");
assert(cosmetic.remoteHead() === sha, "head branch moved to the fix commit");
cosmetic.git("fetch", "-q", cosmetic.url, `+refs/heads/feature:refs/remotes/check/feature`);