Repository navigation
fix(server): find newly opened pull requests after agent turns #9125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ab90d4
fix(server): surface pull requests sooner without extra host requests
t3dotgg 9c5de9f
fix(server): address review on turn-end pull request refresh
t3dotgg 3279a7b
fix(server): verify branch lookup identity on the resolved remote
t3dotgg 9ed47c2
fix(server): keep turn-end PR refreshes scoped and ordered
t3dotgg e44509e
fix(server): skip PR refreshes for auxiliary turn completions
t3dotgg f1118b4
docs(server): correct the runtime event delivery comment
t3dotgg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -999,6 +999,80 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => { | |
| }), | ||
| ); | ||
|
|
||
| it.effect("turn-end refresh finds a new PR and keeps known PRs cached", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
| yield* initRepo(repoDir); | ||
| const remoteDir = yield* createBareRemote(); | ||
| yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]); | ||
| yield* runGit(repoDir, ["push", "-u", "origin", "main"]); | ||
| yield* runGit(repoDir, ["checkout", "-b", "feature/turn-refresh", "origin/main"]); | ||
| yield* runGit(repoDir, ["push", "origin", "feature/turn-refresh"]); | ||
|
|
||
| const { manager, ghCalls } = yield* makeManager({ | ||
| ghScenario: { | ||
| prListSequence: [ | ||
| "[]", | ||
| // Fake gh returns raw JSON stdout, matching the CLI boundary under test. | ||
| // @effect-diagnostics-next-line preferSchemaOverJson:off | ||
| JSON.stringify([ | ||
| { | ||
| number: 114, | ||
| title: "Opened during the turn", | ||
| url: "https://github.com/pingdotgg/codething-mvp/pull/114", | ||
| baseRefName: "main", | ||
| headRefName: "feature/turn-refresh", | ||
| }, | ||
| ]), | ||
| ], | ||
| }, | ||
| }); | ||
| expect((yield* manager.remoteStatus({ cwd: repoDir }))?.pr).toBeNull(); | ||
| expect( | ||
| (yield* manager.remoteStatus({ cwd: repoDir }, { refreshUpstream: false }))?.pr, | ||
| ).toBeNull(); | ||
|
|
||
| const refreshed = yield* manager.remoteStatus( | ||
| { cwd: repoDir }, | ||
| { refreshUpstream: false, refreshMissingPullRequest: true }, | ||
| ); | ||
| expect(refreshed?.pr?.number).toBe(114); | ||
| yield* manager.remoteStatus( | ||
| { cwd: repoDir }, | ||
| { refreshUpstream: false, refreshMissingPullRequest: true }, | ||
| ); | ||
| expect(ghCalls.filter((call) => call.startsWith("pr list "))).toHaveLength(2); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("turn-end refresh preserves failed PR lookup backoff", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
| yield* initRepo(repoDir); | ||
| const remoteDir = yield* createBareRemote(); | ||
| yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]); | ||
| yield* runGit(repoDir, ["checkout", "-b", "feature/rate-limited"]); | ||
| yield* runGit(repoDir, ["push", "-u", "origin", "feature/rate-limited"]); | ||
| const { manager, ghCalls } = yield* makeManager({ | ||
| ghScenario: { | ||
| failWith: new GitHubCli.GitHubCliUnavailableError({ | ||
| command: "gh", | ||
| cwd: repoDir, | ||
| cause: new Error("rate limited"), | ||
| }), | ||
| }, | ||
| }); | ||
| yield* manager.remoteStatus({ cwd: repoDir }); | ||
| const callsAfterFailure = ghCalls.length; | ||
| yield* manager.remoteStatus( | ||
| { cwd: repoDir }, | ||
| { refreshUpstream: false, refreshMissingPullRequest: true }, | ||
| ); | ||
| expect(callsAfterFailure).toBeGreaterThan(0); | ||
| expect(ghCalls).toHaveLength(callsAfterFailure); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("status skips the provider lookup for a branch that was never pushed", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
|
|
@@ -1909,6 +1983,211 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => { | |
| }), | ||
| ); | ||
|
|
||
| it.effect("status finds a PR pushed under the branch's own name despite a default upstream", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
| yield* initRepo(repoDir); | ||
| const remoteDir = yield* createBareRemote(); | ||
| yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]); | ||
| yield* runGit(repoDir, ["push", "-u", "origin", "main"]); | ||
| yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]); | ||
| yield* runGit(repoDir, ["checkout", "-b", "feature/pushed-plain", "origin/main"]); | ||
| // A plain push (no -u) leaves the upstream on origin/main. | ||
| yield* runGit(repoDir, ["push", "origin", "feature/pushed-plain"]); | ||
|
|
||
| const { manager, ghCalls } = yield* makeManager({ | ||
| ghScenario: { | ||
| prListByHeadSelector: { | ||
| // Fake gh returns raw JSON stdout, matching the CLI boundary under test. | ||
| // @effect-diagnostics-next-line preferSchemaOverJson:off | ||
| "feature/pushed-plain": JSON.stringify([ | ||
| { | ||
| number: 88, | ||
| title: "Pushed without -u", | ||
| url: "https://github.com/pingdotgg/codething-mvp/pull/88", | ||
| baseRefName: "main", | ||
| headRefName: "feature/pushed-plain", | ||
| state: "OPEN", | ||
| updatedAt: "2026-05-01T10:00:00Z", | ||
| }, | ||
| ]), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const status = yield* manager.status({ cwd: repoDir }); | ||
| expect(status.refName).toBe("feature/pushed-plain"); | ||
| expect(status.pr?.number).toBe(88); | ||
| expect(ghCalls.some((call) => call.includes("--head main"))).toBe(false); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect( | ||
| "status finds a fork PR pushed under the branch's own name despite a default upstream", | ||
| () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
| yield* initRepo(repoDir); | ||
| const originDir = yield* createBareRemote(); | ||
| const forkDir = yield* createBareRemote(); | ||
| yield* runGit(repoDir, ["remote", "add", "origin", originDir]); | ||
| yield* runGit(repoDir, ["push", "-u", "origin", "main"]); | ||
| yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]); | ||
| yield* configureRemote(repoDir, "team/fork", forkDir, "team/fork"); | ||
| yield* runGit(repoDir, ["checkout", "-b", "feature/fork-plain", "origin/main"]); | ||
| // Pushed to the fork without -u: upstream stays origin/main. | ||
| yield* runGit(repoDir, ["push", "team/fork", "feature/fork-plain"]); | ||
| yield* configureVisibleRemoteUrlWithLocalRewrite( | ||
| repoDir, | ||
| "origin", | ||
| "[email protected]:pingdotgg/codething-mvp.git", | ||
| originDir, | ||
| ); | ||
| yield* configureVisibleRemoteUrlWithLocalRewrite( | ||
| repoDir, | ||
| "team/fork", | ||
| "[email protected]:contributor/codething-mvp.git", | ||
| forkDir, | ||
| ); | ||
|
|
||
| const { manager, ghCalls } = yield* makeManager({ | ||
| ghScenario: { | ||
| prListByHeadSelector: { | ||
| // Fake gh returns raw JSON stdout, matching the CLI boundary under test. | ||
| // @effect-diagnostics-next-line preferSchemaOverJson:off | ||
| "contributor:feature/fork-plain": JSON.stringify([ | ||
| { | ||
| number: 89, | ||
| title: "Fork PR pushed without -u", | ||
| url: "https://github.com/pingdotgg/codething-mvp/pull/89", | ||
| baseRefName: "main", | ||
| headRefName: "feature/fork-plain", | ||
| state: "OPEN", | ||
| updatedAt: "2026-05-01T10:00:00Z", | ||
| isCrossRepository: true, | ||
| headRepository: { nameWithOwner: "contributor/codething-mvp" }, | ||
| headRepositoryOwner: { login: "contributor" }, | ||
| }, | ||
| ]), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const status = yield* manager.status({ cwd: repoDir }); | ||
| expect(status.pr?.number).toBe(89); | ||
| expect(ghCalls.some((call) => call.includes("--head contributor:feature/fork-plain"))).toBe( | ||
| true, | ||
| ); | ||
| expect(ghCalls.some((call) => call.includes("--head main"))).toBe(false); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("branch PR lookup verifies identity on the fork that holds the own-name ref", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
| yield* initRepo(repoDir); | ||
| const originDir = yield* createBareRemote(); | ||
| const forkDir = yield* createBareRemote(); | ||
| yield* runGit(repoDir, ["remote", "add", "origin", originDir]); | ||
| yield* runGit(repoDir, ["push", "-u", "origin", "main"]); | ||
| yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]); | ||
| yield* configureRemote(repoDir, "team/fork", forkDir, "team/fork"); | ||
| yield* runGit(repoDir, ["checkout", "-b", "feature/fork-settle", "origin/main"]); | ||
| yield* runGit(repoDir, ["push", "team/fork", "feature/fork-settle"]); | ||
| yield* configureVisibleRemoteUrlWithLocalRewrite( | ||
| repoDir, | ||
| "origin", | ||
| "[email protected]:pingdotgg/codething-mvp.git", | ||
| originDir, | ||
| ); | ||
| yield* configureVisibleRemoteUrlWithLocalRewrite( | ||
| repoDir, | ||
| "team/fork", | ||
| "[email protected]:contributor/codething-mvp.git", | ||
| forkDir, | ||
| ); | ||
|
|
||
| const { manager } = yield* makeManager({ | ||
| ghScenario: { | ||
| prListByHeadSelector: { | ||
| // Fake gh returns raw JSON stdout, matching the CLI boundary under test. | ||
| // @effect-diagnostics-next-line preferSchemaOverJson:off | ||
| "contributor:feature/fork-settle": JSON.stringify([ | ||
| { | ||
| number: 91, | ||
| title: "Fork PR to settle", | ||
| url: "https://github.com/pingdotgg/codething-mvp/pull/91", | ||
| baseRefName: "main", | ||
| headRefName: "feature/fork-settle", | ||
| state: "MERGED", | ||
| updatedAt: "2026-05-02T10:00:00Z", | ||
| isCrossRepository: true, | ||
| headRepository: { nameWithOwner: "contributor/codething-mvp" }, | ||
| headRepositoryOwner: { login: "contributor" }, | ||
| }, | ||
| ]), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const pullRequest = yield* manager.branchPullRequest({ | ||
| cwd: repoDir, | ||
| branch: "feature/fork-settle", | ||
| }); | ||
|
|
||
| expect(pullRequest).toEqual({ | ||
| state: "merged", | ||
| updatedAt: "2026-05-02T10:00:00.000Z", | ||
| }); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("status keeps an own-name PR when a later lookup fails on a default upstream", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
| yield* initRepo(repoDir); | ||
| const remoteDir = yield* createBareRemote(); | ||
| yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]); | ||
| yield* runGit(repoDir, ["push", "-u", "origin", "main"]); | ||
| yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]); | ||
| yield* runGit(repoDir, ["checkout", "-b", "feature/sticky-plain", "origin/main"]); | ||
| yield* runGit(repoDir, ["push", "origin", "feature/sticky-plain"]); | ||
|
|
||
| const { manager } = yield* makeManager({ | ||
| ghScenario: { | ||
| prListByHeadSelector: { | ||
| // Fake gh returns raw JSON stdout, matching the CLI boundary under test. | ||
| // @effect-diagnostics-next-line preferSchemaOverJson:off | ||
| "feature/sticky-plain": JSON.stringify([ | ||
| { | ||
| number: 90, | ||
| title: "Sticky own-name PR", | ||
| url: "https://github.com/pingdotgg/codething-mvp/pull/90", | ||
| baseRefName: "main", | ||
| headRefName: "feature/sticky-plain", | ||
| state: "OPEN", | ||
| updatedAt: "2026-05-01T10:00:00Z", | ||
| }, | ||
| ]), | ||
| }, | ||
| failWith: new GitHubCli.GitHubCliUnavailableError({ | ||
| command: "gh", | ||
| cwd: repoDir, | ||
| cause: new Error("rate limited"), | ||
| }), | ||
| failAfterCalls: 1, | ||
| }, | ||
| }); | ||
|
|
||
| const first = yield* manager.status({ cwd: repoDir }); | ||
| expect(first.pr?.number).toBe(90); | ||
|
|
||
| yield* manager.invalidateStatus(repoDir); | ||
| const second = yield* manager.status({ cwd: repoDir }); | ||
| expect(second.pr?.number).toBe(90); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("status prefers open PR when merged PR has newer updatedAt", () => | ||
| Effect.gen(function* () { | ||
| const repoDir = yield* makeTempDir("t3code-git-manager-"); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.