fix: extend code queue pr preflight diagnostics
This commit is contained in:
@@ -5284,6 +5284,8 @@ async function route(req: Request): Promise<Response> {
|
||||
includeRemote: url.searchParams.get("remote") === "1",
|
||||
includePushDryRun: url.searchParams.get("pushDryRun") === "1",
|
||||
pushDryRunRef: url.searchParams.get("pushDryRunRef") ?? undefined,
|
||||
includePrCreateDryRun: url.searchParams.get("prCreateDryRun") === "1",
|
||||
prCreateDryRunHead: url.searchParams.get("prCreateDryRunHead") ?? undefined,
|
||||
issueNumber: Number(url.searchParams.get("issue") ?? url.searchParams.get("issueNumber") ?? NaN),
|
||||
})),
|
||||
});
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface RuntimePreflightOptions {
|
||||
includeRemote?: boolean;
|
||||
includePushDryRun?: boolean;
|
||||
pushDryRunRef?: string;
|
||||
includePrCreateDryRun?: boolean;
|
||||
prCreateDryRunHead?: string;
|
||||
issueNumber?: number;
|
||||
}
|
||||
|
||||
@@ -115,6 +117,7 @@ export interface PullRequestDeliveryPreflight {
|
||||
ghPrReadOnly: RuntimeCommandProbe | null;
|
||||
};
|
||||
pushDryRun?: RuntimeCommandProbe;
|
||||
prCreateDryRun?: RuntimeCommandProbe;
|
||||
limitations: string[];
|
||||
risks: string[];
|
||||
}
|
||||
@@ -309,6 +312,55 @@ function httpsGitUrl(repo: string | null, host: string): string | null {
|
||||
return repo === null ? null : `https://${host}/${repo}.git`;
|
||||
}
|
||||
|
||||
function prCreateDryRunProbe(repo: string | null, issueNumber: number, head: string | null): RuntimeCommandProbe {
|
||||
if (repo === null) {
|
||||
return shellProbe("echo 'cannot run PR create dry-run: GitHub repo is unknown' >&2; exit 2", 2000);
|
||||
}
|
||||
const headRef = head?.trim() || "probe/code-queue-pr-capability";
|
||||
const body = [
|
||||
"# Code Queue PR preflight",
|
||||
"",
|
||||
`Related issue: #${issueNumber}`,
|
||||
"",
|
||||
"Validation:",
|
||||
"- runtime PR create dry-run only",
|
||||
"",
|
||||
"Risk:",
|
||||
"- no remote PR is created by this probe",
|
||||
"",
|
||||
].join("\n");
|
||||
const script = [
|
||||
"set -eu",
|
||||
"root=$(git rev-parse --show-toplevel 2>/dev/null || pwd)",
|
||||
"body_file=$(mktemp /tmp/unidesk-pr-create-dry-run.XXXXXX.md)",
|
||||
"trap 'rm -f \"$body_file\"' EXIT",
|
||||
`cat > "$body_file" <<'EOF_PR_PREFLIGHT_BODY'`,
|
||||
body,
|
||||
"EOF_PR_PREFLIGHT_BODY",
|
||||
"cd \"$root\"",
|
||||
"test -f scripts/cli.ts",
|
||||
[
|
||||
"bun",
|
||||
"scripts/cli.ts",
|
||||
"gh",
|
||||
"pr",
|
||||
"create",
|
||||
"--repo",
|
||||
shellQuote(repo),
|
||||
"--title",
|
||||
shellQuote("Code Queue PR preflight dry run"),
|
||||
"--body-file",
|
||||
"\"$body_file\"",
|
||||
"--base",
|
||||
"master",
|
||||
"--head",
|
||||
shellQuote(headRef),
|
||||
"--dry-run",
|
||||
].join(" "),
|
||||
].join("\n");
|
||||
return shellProbe(script, 20_000);
|
||||
}
|
||||
|
||||
function collectPullRequestDeliveryPreflight(options: RuntimePreflightOptions, checkedAt: string): PullRequestDeliveryPreflight {
|
||||
const tools = {
|
||||
git: toolStatus("git", ["--version"]),
|
||||
@@ -392,6 +444,10 @@ function collectPullRequestDeliveryPreflight(options: RuntimePreflightOptions, c
|
||||
const pushDryRun = options.includePushDryRun === true
|
||||
? commandProbe("git", ["push", "--dry-run", "origin", `HEAD:${pushDryRunRef}`], { timeoutMs: 30_000 })
|
||||
: undefined;
|
||||
const prCreateDryRunHead = options.prCreateDryRunHead?.trim() || gitInfo.branch || "probe/code-queue-pr-capability";
|
||||
const prCreateDryRun = options.includePrCreateDryRun === true
|
||||
? prCreateDryRunProbe(githubRepo, issueProbeNumber, prCreateDryRunHead)
|
||||
: undefined;
|
||||
const limitations: string[] = [];
|
||||
const risks: string[] = [];
|
||||
if (!tools.git.ok) limitations.push("missing git CLI");
|
||||
@@ -419,12 +475,14 @@ function collectPullRequestDeliveryPreflight(options: RuntimePreflightOptions, c
|
||||
if (tools.gh.ok && remote.ghPrReadOnly !== null && !remote.ghPrReadOnly.ok) limitations.push("gh pr read-only probe failed");
|
||||
}
|
||||
if (pushDryRun !== undefined && !pushDryRun.ok) limitations.push("git push --dry-run failed for probe branch");
|
||||
if (prCreateDryRun !== undefined && !prCreateDryRun.ok) limitations.push("PR create dry-run body/command guard failed");
|
||||
const prCliReady = tools.gh.ok || tools.hub.ok;
|
||||
const tokenOrGhStore = credentials.ghTokenPresent || credentials.githubTokenPresent || credentials.ghHostsConfigPresent || (remote?.ghAuthStatus?.ok === true);
|
||||
const remoteReady = remote === undefined || (egress.githubDefault.ok && egress.apiDefault.ok && remote.gitLsRemote.ok && remote.githubSshAuthenticated);
|
||||
const pushReady = pushDryRun === undefined || pushDryRun.ok;
|
||||
const prCreateDryRunReady = prCreateDryRun === undefined || prCreateDryRun.ok;
|
||||
return {
|
||||
ok: tools.git.ok && tools.jq.ok && prCliReady && tokenOrGhStore && gitInfo.insideWorktree && gitInfo.remoteOrigin !== null && gitInfo.homeWritable && remoteReady && pushReady,
|
||||
ok: tools.git.ok && tools.jq.ok && prCliReady && tokenOrGhStore && gitInfo.insideWorktree && gitInfo.remoteOrigin !== null && gitInfo.homeWritable && remoteReady && pushReady && prCreateDryRunReady,
|
||||
checkedAt,
|
||||
tools,
|
||||
credentials,
|
||||
@@ -438,6 +496,7 @@ function collectPullRequestDeliveryPreflight(options: RuntimePreflightOptions, c
|
||||
git: gitInfo,
|
||||
remote,
|
||||
pushDryRun,
|
||||
prCreateDryRun,
|
||||
limitations,
|
||||
risks,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user