fix: unblock beta conflict recovery (#19068)
parent
9a64bdb539
commit
aa11fa865d
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
|
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
|
import fs from "fs/promises"
|
||||||
|
|
||||||
const model = "opencode/gpt-5.3-codex"
|
const model = "opencode/gpt-5.3-codex"
|
||||||
|
|
||||||
|
|
@ -57,6 +58,8 @@ function lines(prs: PR[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function typecheck() {
|
async function typecheck() {
|
||||||
|
console.log(" Running typecheck...")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $`bun typecheck`.cwd("packages/opencode")
|
await $`bun typecheck`.cwd("packages/opencode")
|
||||||
return true
|
return true
|
||||||
|
|
@ -67,6 +70,8 @@ async function typecheck() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function build() {
|
async function build() {
|
||||||
|
console.log(" Running final build smoke check...")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $`./script/build.ts --single`.cwd("packages/opencode")
|
await $`./script/build.ts --single`.cwd("packages/opencode")
|
||||||
return true
|
return true
|
||||||
|
|
@ -76,6 +81,20 @@ async function build() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function install() {
|
||||||
|
console.log(" Regenerating bun.lock...")
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.rm("bun.lock", { force: true })
|
||||||
|
await $`bun install`
|
||||||
|
await $`git add bun.lock`
|
||||||
|
return true
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Install failed: ${err}`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function fix(pr: PR, files: string[], prs: PR[], applied: number[], idx: number) {
|
async function fix(pr: PR, files: string[], prs: PR[], applied: number[], idx: number) {
|
||||||
console.log(` Trying to auto-resolve ${files.length} conflict(s) with opencode...`)
|
console.log(` Trying to auto-resolve ${files.length} conflict(s) with opencode...`)
|
||||||
|
|
||||||
|
|
@ -85,15 +104,18 @@ async function fix(pr: PR, files: string[], prs: PR[], applied: number[], idx: n
|
||||||
const prompt = [
|
const prompt = [
|
||||||
`Resolve the current git merge conflicts while merging PR #${pr.number} into the beta branch.`,
|
`Resolve the current git merge conflicts while merging PR #${pr.number} into the beta branch.`,
|
||||||
`PR #${pr.number}: ${pr.title}`,
|
`PR #${pr.number}: ${pr.title}`,
|
||||||
`Only touch these files: ${files.join(", ")}.`,
|
`Start with these conflicted files: ${files.join(", ")}.`,
|
||||||
`Merged PRs on HEAD:\n${done}`,
|
`Merged PRs on HEAD:\n${done}`,
|
||||||
`Pending PRs after this one (context only):\n${next}`,
|
`Pending PRs after this one (context only):\n${next}`,
|
||||||
"IMPORTANT: The conflict resolution must be consistent with already-merged PRs.",
|
"IMPORTANT: The conflict resolution must be consistent with already-merged PRs.",
|
||||||
"Pending PRs are context only; do not introduce their changes unless they are already present on HEAD.",
|
"Pending PRs are context only; do not introduce their changes unless they are already present on HEAD.",
|
||||||
"Prefer already-merged PRs over the base branch when resolving stacked conflicts.",
|
"Prefer already-merged PRs over the base branch when resolving stacked conflicts.",
|
||||||
|
"If bun.lock is conflicted, do not hand-merge it. Delete bun.lock and run bun install after the code conflicts are resolved.",
|
||||||
"If a PR already deleted a file/directory, do not re-add it, instead apply changes in the new semantic location.",
|
"If a PR already deleted a file/directory, do not re-add it, instead apply changes in the new semantic location.",
|
||||||
"If a PR already changed an import, keep that change.",
|
"If a PR already changed an import, keep that change.",
|
||||||
"After resolving the conflicts, run `bun typecheck` in `packages/opencode`.",
|
"After resolving the conflicts, run `bun typecheck` in `packages/opencode`.",
|
||||||
|
"If typecheck fails, you may also update any files reported by typecheck.",
|
||||||
|
"Keep any non-conflict edits narrowly scoped to restoring a valid merged state for the current PR batch.",
|
||||||
"Fix any merge-caused typecheck errors before finishing.",
|
"Fix any merge-caused typecheck errors before finishing.",
|
||||||
"Keep the merge in progress, do not abort the merge, and do not create a commit.",
|
"Keep the merge in progress, do not abort the merge, and do not create a commit.",
|
||||||
"When done, leave the working tree with no unmerged files and a passing typecheck.",
|
"When done, leave the working tree with no unmerged files and a passing typecheck.",
|
||||||
|
|
@ -112,6 +134,8 @@ async function fix(pr: PR, files: string[], prs: PR[], applied: number[], idx: n
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (files.includes("bun.lock") && !(await install())) return false
|
||||||
|
|
||||||
if (!(await typecheck())) return false
|
if (!(await typecheck())) return false
|
||||||
|
|
||||||
console.log(" Conflicts resolved with opencode")
|
console.log(" Conflicts resolved with opencode")
|
||||||
|
|
@ -196,7 +220,7 @@ async function main() {
|
||||||
const failed: FailedPR[] = []
|
const failed: FailedPR[] = []
|
||||||
|
|
||||||
for (const [idx, pr] of prs.entries()) {
|
for (const [idx, pr] of prs.entries()) {
|
||||||
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
|
console.log(`\nProcessing PR ${idx + 1}/${prs.length} #${pr.number}: ${pr.title}`)
|
||||||
|
|
||||||
console.log(" Fetching PR head...")
|
console.log(" Fetching PR head...")
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue