chore: add eslint/prettier gates and fix windows test failures

This commit is contained in:
wdawdwa committed 2026-08-22 15:16:47 +08:00
1 parent b366e16087
commit b47302e2ff
42 files changed
+3460 -843

No files matched your search

+115 -79
View File
@@ -32,13 +32,19 @@ const eligible = {
test("only a passing conflicted writable current head is eligible", () => {
assert.equal(canAutoResolveConflicts(eligible), true);
assert.equal(canAutoResolveConflicts({ ...eligible, reviewPassed: false }), false);
assert.equal(canAutoResolveConflicts({ ...eligible, mergeable: true, mergeableState: "clean" }), false);
assert.equal(
canAutoResolveConflicts({ ...eligible, mergeable: true, mergeableState: "clean" }),
false
);
assert.equal(canAutoResolveConflicts({ ...eligible, headRepository: "contributor/fork" }), false);
assert.equal(canAutoResolveConflicts({
...eligible,
headRepository: "contributor/fork",
maintainerCanModify: true
}), true);
assert.equal(
canAutoResolveConflicts({
...eligible,
headRepository: "contributor/fork",
maintainerCanModify: true
}),
true
);
assert.equal(canAutoResolveConflicts({ ...eligible, currentHeadSha: "new-head" }), false);
assert.equal(canAutoResolveConflicts({ ...eligible, enabled: false }), false);
});
@@ -137,26 +143,38 @@ test("validation failure logs are bounded, readable, and keep the useful tail",
});
test("validation infrastructure failures are not sent to the code-repair agent", () => {
assert.equal(isValidationInfrastructureFailure({
code: 1,
stdout: "",
stderr: "fatal: detected dubious ownership in repository at '/workspace'"
}), true);
assert.equal(isValidationInfrastructureFailure({
code: 125,
stdout: "",
stderr: "docker failed before the command started"
}), true);
assert.equal(isValidationInfrastructureFailure({
code: 1,
stdout: "",
stderr: "permission denied while trying to connect to the Docker API at unix:///docker.sock"
}), true);
assert.equal(isValidationInfrastructureFailure({
code: 1,
stdout: "AssertionError: expected 2 but received 1",
stderr: ""
}), false);
assert.equal(
isValidationInfrastructureFailure({
code: 1,
stdout: "",
stderr: "fatal: detected dubious ownership in repository at '/workspace'"
}),
true
);
assert.equal(
isValidationInfrastructureFailure({
code: 125,
stdout: "",
stderr: "docker failed before the command started"
}),
true
);
assert.equal(
isValidationInfrastructureFailure({
code: 1,
stdout: "",
stderr: "permission denied while trying to connect to the Docker API at unix:///docker.sock"
}),
true
);
assert.equal(
isValidationInfrastructureFailure({
code: 1,
stdout: "AssertionError: expected 2 but received 1",
stderr: ""
}),
false
);
});
test("initial conflict prompt leaves full validation to the isolated host pass", () => {
@@ -173,66 +191,84 @@ test("initial conflict prompt leaves full validation to the isolated host pass",
});
test("diff-check whitespace diagnostics are repaired without another agent run", () => {
const diagnostics = parseDiffCheckWhitespaceDiagnostics([
"src/app.js:2: trailing whitespace.",
"+const value = true; ",
"src/app.js:3: space before tab in indent.",
"+ \treturn value;",
"src/app.js:4: leftover conflict marker."
].join("\n"));
const diagnostics = parseDiffCheckWhitespaceDiagnostics(
[
"src/app.js:2: trailing whitespace.",
"+const value = true; ",
"src/app.js:3: space before tab in indent.",
"+ \treturn value;",
"src/app.js:4: leftover conflict marker."
].join("\n")
);
assert.deepEqual(diagnostics, [
{ file: "src/app.js", line: 2, kind: "trailing-whitespace" },
{ file: "src/app.js", line: 3, kind: "space-before-tab" }
]);
assert.equal(
repairDiffCheckContent("function check() {\nconst value = true; \n \treturn value;\n}\n", diagnostics),
repairDiffCheckContent(
"function check() {\nconst value = true; \n \treturn value;\n}\n",
diagnostics
),
"function check() {\nconst value = true;\n\treturn value;\n}\n"
);
});
test("external fork conflict pushes use a head-SHA force lease", () => {
assert.deepEqual(buildConflictPushArgs({
baseRepository: "forumlify/public",
headRepository: "contributor/forumlify",
headBranch: "fix/conflicts",
expectedHeadSha: "a".repeat(40)
}), [
"push",
`--force-with-lease=refs/heads/fix/conflicts:${"a".repeat(40)}`,
"https://github.com/contributor/forumlify.git",
"HEAD:refs/heads/fix/conflicts"
]);
assert.deepEqual(buildConflictPushArgs({
baseRepository: "forumlify/public",
headRepository: "forumlify/public",
headBranch: "fix/conflicts",
expectedHeadSha: "b".repeat(40)
}), ["push", "origin", "HEAD:refs/heads/fix/conflicts"]);
assert.throws(() => buildConflictPushArgs({
baseRepository: "forumlify/public",
headRepository: "contributor/forumlify",
headBranch: "bad:branch",
expectedHeadSha: "c".repeat(40)
}), /Unsafe PR head branch/);
assert.deepEqual(
buildConflictPushArgs({
baseRepository: "forumlify/public",
headRepository: "contributor/forumlify",
headBranch: "fix/conflicts",
expectedHeadSha: "a".repeat(40)
}),
[
"push",
`--force-with-lease=refs/heads/fix/conflicts:${"a".repeat(40)}`,
"https://github.com/contributor/forumlify.git",
"HEAD:refs/heads/fix/conflicts"
]
);
assert.deepEqual(
buildConflictPushArgs({
baseRepository: "forumlify/public",
headRepository: "forumlify/public",
headBranch: "fix/conflicts",
expectedHeadSha: "b".repeat(40)
}),
["push", "origin", "HEAD:refs/heads/fix/conflicts"]
);
assert.throws(
() =>
buildConflictPushArgs({
baseRepository: "forumlify/public",
headRepository: "contributor/forumlify",
headBranch: "bad:branch",
expectedHeadSha: "c".repeat(40)
}),
/Unsafe PR head branch/
);
});
test("conflict commits use the GitHub bot user id for avatar attribution", async () => {
const requestedUsernames: string[] = [];
const identity = await resolveBotCommitIdentity({
rest: {
users: {
async getByUsername({ username }: { username: string }) {
requestedUsernames.push(username);
return {
data: {
id: 316580078,
login: "forumlify[bot]"
}
};
const identity = await resolveBotCommitIdentity(
{
rest: {
users: {
async getByUsername({ username }: { username: string }) {
requestedUsernames.push(username);
return {
data: {
id: 316580078,
login: "forumlify[bot]"
}
};
}
}
}
}
} as never, "@forumlify[bot]");
} as never,
"@forumlify[bot]"
);
assert.deepEqual(requestedUsernames, ["forumlify[bot]"]);
assert.deepEqual(identity, {
@@ -252,10 +288,11 @@ test("snapshot inventory detects related file additions, changes, and deletions"
["caller.ts", { hash: "same", size: 20 }],
["compatibility.test.ts", { hash: "new", size: 40 }]
]);
assert.deepEqual(
diffSnapshotInventories(before, after),
["compatibility.test.ts", "conflicted.ts", "removed.test.ts"]
);
assert.deepEqual(diffSnapshotInventories(before, after), [
"compatibility.test.ts",
"conflicted.ts",
"removed.test.ts"
]);
});
test("validation repair prompt leaves the authoritative rerun to the isolated host", () => {
@@ -273,11 +310,10 @@ test("validation repair prompt leaves the authoritative rerun to the isolated ho
test("final confirmation parser accepts a JSON object surrounded by prose", () => {
assert.deepEqual(
parseFinalConfirmation('Result:\n{"safeToCommit":true,"summary":"validated","concerns":[]}\nDone.'),
parseFinalConfirmation(
'Result:\n{"safeToCommit":true,"summary":"validated","concerns":[]}\nDone.'
),
{ safeToCommit: true, summary: "validated", concerns: [] }
);
assert.throws(
() => parseFinalConfirmation("safe to commit"),
/required JSON object/
);
assert.throws(() => parseFinalConfirmation("safe to commit"), /required JSON object/);
});