Skip to content

Commit b9c17d7

Browse files
fix(server): stack rebase, fork workflow approvals, and the reserve flag hold against live GitHub
- The stack rebase preflight always selects $ids. GitHub refuses a document that declares a variable it never uses, which failed every rebase at the first layer. The stack test fake now refuses such documents too. - A run waiting on a maintainer reports completed with an action_required conclusion, so the revalidated runs are filtered on either; fork PRs no longer show zero workflows to approve. - AllowGitHubReserve is the one in GitHubApi, so interactive writes go through a background pause. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent b5daebf commit b9c17d7

7 files changed

Lines changed: 67 additions & 13 deletions

File tree

‎apps/server/src/pullRequest/GitHubPullRequestCli.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as GitHubCredentials from "../sourceControl/GitHubCredentials.ts";
1717
import * as GitHubGraphQlBudget from "../sourceControl/githubGraphQlBudget.ts";
1818
import * as SourceControlRateLimit from "../sourceControl/SourceControlRateLimit.ts";
1919
import * as GitHubPullRequestCli from "./GitHubPullRequestCli.ts";
20+
import { KnownWorkflowRuns } from "./gitHubConditionalChecks.ts";
2021
import { BASE_COMPARISON_GRAPHQL_QUERY } from "./gitHubPullRequestJson.ts";
2122

2223
const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
@@ -2483,6 +2484,43 @@ layer("GitHubPullRequestCli.layer", (it) => {
24832484
}),
24842485
);
24852486

2487+
it.effect("counts revalidated runs that wait on a maintainer as GitHub reports them", () =>
2488+
Effect.gen(function* () {
2489+
workflowApprovalRoutes(() => crossRepositoryDetail(), heads([7]), workflowRuns([]));
2490+
const cli = yield* GitHubPullRequestCli.GitHubPullRequestCli;
2491+
2492+
const runs = yield* cli
2493+
.listWorkflowRunsRequiringApproval({
2494+
cwd: "/w",
2495+
repository: "acme/web",
2496+
host: "github.com",
2497+
number: 7,
2498+
headSha: "abc123",
2499+
headBranch: "feat/page",
2500+
headRepositoryOwner: "octocat",
2501+
isCrossRepository: true,
2502+
})
2503+
.pipe(
2504+
Effect.provideService(KnownWorkflowRuns, {
2505+
headSha: "abc123",
2506+
runs: [
2507+
// Live shape: waiting on approval is completed + action_required.
2508+
{
2509+
id: 10,
2510+
status: "completed",
2511+
conclusion: "action_required",
2512+
head_branch: "feat/page",
2513+
},
2514+
{ id: 11, status: "completed", conclusion: "success", head_branch: "feat/page" },
2515+
],
2516+
}),
2517+
);
2518+
2519+
expect(runs.map((run) => run.id)).toEqual([10]);
2520+
assert.strictEqual(restCallsTo("actions/runs?").length, 0);
2521+
}),
2522+
);
2523+
24862524
it.effect("refuses a stale workflow approval after the pull request head changes", () =>
24872525
Effect.gen(function* () {
24882526
let detailReads = 0;

‎apps/server/src/pullRequest/GitHubPullRequestCli.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,10 @@ export const make = Effect.gen(function* () {
16441644
const known = yield* KnownWorkflowRuns;
16451645
if (known !== null && known.headSha === input.headSha) {
16461646
return known.runs.flatMap((run) =>
1647-
run.status === "action_required" && run.head_branch === input.headBranch
1647+
// A run waiting on a maintainer reports `completed` with an `action_required`
1648+
// conclusion; the `status=action_required` query matches either.
1649+
(run.conclusion === "action_required" || run.status === "action_required") &&
1650+
run.head_branch === input.headBranch
16481651
? [
16491652
{
16501653
id: run.id,

‎apps/server/src/pullRequest/gitHubConditionalChecks.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ it.effect(
5151
: head
5252
? encodeJson({ head: { sha, repo: { id: 2 } }, base: { repo: { id: 1 } } })
5353
: runs
54-
? encodeJson({ workflow_runs: [{ id: 9, status: "action_required" }] })
54+
? encodeJson({
55+
workflow_runs: [
56+
{ id: 9, status: "completed", conclusion: "action_required" },
57+
],
58+
})
5559
: "{}",
5660
truncated: false,
5761
invalidUtf8: false,
@@ -79,7 +83,10 @@ it.effect(
7983
yield* poll();
8084
expect(reads).toBe(1);
8185
// The fork's runs were just confirmed, so the read is handed them instead of listing them.
82-
expect(known[0]).toEqual({ headSha: sha, runs: [{ id: 9, status: "action_required" }] });
86+
expect(known[0]).toEqual({
87+
headSha: sha,
88+
runs: [{ id: 9, status: "completed", conclusion: "action_required" }],
89+
});
8390
requests.length = 0;
8491
yield* poll();
8592
expect(reads).toBe(1);

‎apps/server/src/pullRequest/gitHubConditionalChecks.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const WorkflowRunSchema = Schema.Struct({
2727
name: Schema.optional(Schema.NullOr(Schema.String)),
2828
html_url: Schema.optional(Schema.NullOr(Schema.String)),
2929
status: Schema.optional(Schema.NullOr(Schema.String)),
30+
conclusion: Schema.optional(Schema.NullOr(Schema.String)),
3031
head_branch: Schema.optional(Schema.NullOr(Schema.String)),
3132
});
3233
const decodeWorkflowRuns = Schema.decodeUnknownOption(

‎apps/server/src/pullRequest/githubStackActions.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ const runGitHubStackAction = (send: Send, input: Parameters<typeof runStackActio
2121
runStackAction(input).pipe(
2222
Effect.provide(
2323
Layer.mock(GitHubApi.GitHubApi)({
24-
graphql: (request) => send(words(request.query, request.variables), "graphql"),
24+
graphql: (request) => {
25+
// GitHub refuses a document that declares a variable it never uses.
26+
const declared = [...request.query.matchAll(/\$(\w+)\s*:/g)].map((match) => match[1]!);
27+
const unused = declared.filter(
28+
(name) => !new RegExp(`\\$${name}(?!\\w)(?!\\s*:)`).test(request.query),
29+
);
30+
if (unused.length > 0) {
31+
return Effect.die(new Error(`Variables declared but not used: ${unused.join(", ")}`));
32+
}
33+
return send(words(request.query, request.variables), "graphql");
34+
},
2535
rest: (request) =>
2636
send(words(request.path, request.body), "rest").pipe(
2737
Effect.map((body) => ({

‎apps/server/src/pullRequest/githubStackActions.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,9 @@ export const runGitHubStackAction = Effect.fn("runGitHubStackAction")(function*
256256
sha: layer.headSha,
257257
ids: processed.map((head) => head.id),
258258
},
259-
query: `query($owner:String!,$name:String!,$number:Int!,$sha:String!,$ids:[ID!]!){${
260-
processed.length === 0
261-
? ""
262-
: "processed:nodes(ids:$ids){... on PullRequest{headRefOid}}"
263-
} repository(owner:$owner,name:$name){pullRequest(number:$number){id headRefOid baseRef{compare(headRef:$sha){behindBy}}}}}`,
259+
// GitHub rejects a declared variable the document never uses, so `$ids` is always
260+
// selected; an empty list asks for nothing.
261+
query: `query($owner:String!,$name:String!,$number:Int!,$sha:String!,$ids:[ID!]!){processed:nodes(ids:$ids){... on PullRequest{headRefOid}} repository(owner:$owner,name:$name){pullRequest(number:$number){id headRefOid baseRef{compare(headRef:$sha){behindBy}}}}}`,
264262
});
265263
const {
266264
data: {

‎apps/server/src/sourceControl/GitHubCli.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ const DEFAULT_TIMEOUT_MS = 30_000;
3838
/** Server-local credential scope; never put its value in RPC payloads or cache keys. */
3939
export const PinnedGitHubCredential = GitHubApi.PinnedGitHubCredential;
4040

41-
export const AllowGitHubReserve = Context.Reference<boolean>(
42-
"t3/sourceControl/AllowGitHubReserve",
43-
{ defaultValue: () => false },
44-
);
41+
export const AllowGitHubReserve = GitHubApi.AllowGitHubReserve;
4542

4643
function commandHosts(args: ReadonlyArray<string>): Array<string | null> {
4744
const hosts: Array<string | null> = [];

0 commit comments

Comments
 (0)