Handle empty GitHub PR listings and fallback branch lookup

- Treat empty `gh pr list` output as no results
- Fall back to `main` when provider default-branch detection fails
- Add coverage for PR creation fallback behavior
This commit is contained in:
Julius Marminge committed 2026-05-02 00:03:12 -07:00
1 parent 1e0a7598c7
commit a73408c324
4 files changed
+72 -7

No files matched your search

+43
View File
@@ -1731,6 +1731,49 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
it.effect("create_pr falls back to main when source control provider detection fails", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
yield* runGit(repoDir, ["checkout", "-b", "feature/provider-fallback"]);
fs.writeFileSync(path.join(repoDir, "provider-fallback.txt"), "fallback\n");
yield* runGit(repoDir, ["add", "provider-fallback.txt"]);
yield* runGit(repoDir, ["commit", "-m", "Provider fallback"]);
const remoteDir = yield* createBareRemote();
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
const { manager, ghCalls } = yield* makeManager({
ghScenario: {
prListSequence: [
"[]",
JSON.stringify([
{
number: 404,
title: "Provider fallback",
url: "https://github.com/pingdotgg/codething-mvp/pull/404",
baseRefName: "main",
headRefName: "feature/provider-fallback",
},
]),
],
},
});
const result = yield* runStackedAction(manager, {
cwd: repoDir,
action: "create_pr",
});
expect(result.pr.status).toBe("created");
expect(result.pr.number).toBe(404);
expect(
ghCalls.some((call) =>
call.includes("pr create --base main --head feature/provider-fallback"),
),
).toBe(true);
}),
);
it.effect("returns existing PR metadata for commit/push/pr action", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
+4 -3
View File
@@ -1045,9 +1045,10 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
}
}
const defaultFromProvider = yield* (yield* sourceControlProvider(cwd))
.getDefaultBranch({ cwd })
.pipe(Effect.catch(() => Effect.succeed(null)));
const defaultFromProvider = yield* sourceControlProvider(cwd).pipe(
Effect.flatMap((provider) => provider.getDefaultBranch({ cwd })),
Effect.catch(() => Effect.succeed(null)),
);
if (defaultFromProvider) {
return defaultFromProvider;
}
@@ -106,6 +106,23 @@ it.effect("uses gh json listing for non-open change request state queries", () =
}),
);
it.effect("treats empty non-open change request listing output as no results", () =>
Effect.gen(function* () {
const provider = yield* makeProvider({
execute: () => Effect.succeed(processResult("")),
});
const changeRequests = yield* provider.listChangeRequests({
cwd: "/repo",
headSelector: "feature/empty",
state: "all",
limit: 10,
});
assert.deepStrictEqual(changeRequests, []);
}),
);
it.effect("creates GitHub PRs through provider-neutral input names", () =>
Effect.gen(function* () {
let createInput: Parameters<GitHubCliShape["createPullRequest"]>[0] | null = null;
@@ -76,8 +76,12 @@ export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
],
})
.pipe(
Effect.flatMap((result) =>
Effect.sync(() => decodeGitHubPullRequestListJson(result.stdout.trim())).pipe(
Effect.flatMap((result) => {
const raw = result.stdout.trim();
if (raw.length === 0) {
return Effect.succeed([]);
}
return Effect.sync(() => decodeGitHubPullRequestListJson(raw)).pipe(
Effect.flatMap((decoded) =>
Result.isSuccess(decoded)
? Effect.succeed(
@@ -95,8 +99,8 @@ export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
}),
),
),
),
),
);
}),
Effect.mapError((error) =>
Schema.is(SourceControlProviderError)(error)
? error