This commit is contained in:
Julius Marminge authored and maria-rcks committed 2026-08-03 11:44:55 -04:00
1 parent 21622d5bb7
commit a38b30441f
14 files changed
+1298 -1061

No files matched your search

+170 -171
View File
@@ -676,14 +676,7 @@ const GitManagerTestLayer = GitVcsDriver.layer.pipe(
);
it.layer(GitManagerTestLayer)("GitManager", (it) => {
const LONG_EFFECT_TEST_TIMEOUT_MS = 30_000;
const effect = (
name: string,
test: Parameters<typeof it.effect>[1],
timeout = LONG_EFFECT_TEST_TIMEOUT_MS,
) => it.effect(name, test, timeout);
effect("status includes PR metadata when branch already has an open PR", () =>
it.effect("status includes PR metadata when branch already has an open PR", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -725,7 +718,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status trims PR metadata returned by gh before publishing it", () =>
it.effect("status trims PR metadata returned by gh before publishing it", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -764,7 +757,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status ignores invalid gh pr list entries and keeps valid ones", () =>
it.effect("status ignores invalid gh pr list entries and keeps valid ones", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -816,7 +809,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status preserves lowercase merged and closed PR states from gh json", () =>
it.effect("status preserves lowercase merged and closed PR states from gh json", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -866,7 +859,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status returns an explicit non-repo result for non-git directories", () =>
it.effect("status returns an explicit non-repo result for non-git directories", () =>
Effect.gen(function* () {
const cwd = yield* makeTempDir("t3code-git-manager-non-repo-");
const { manager } = yield* makeManager();
@@ -893,7 +886,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status returns an explicit non-repo result for deleted directories", () =>
it.effect("status returns an explicit non-repo result for deleted directories", () =>
Effect.gen(function* () {
const rootDir = yield* makeTempDir("t3code-git-manager-missing-dir-");
const cwd = NodePath.join(rootDir, "deleted-repo");
@@ -923,7 +916,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status briefly caches repeated lookups for the same cwd", () =>
it.effect("status briefly caches repeated lookups for the same cwd", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -955,7 +948,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect(
it.effect(
"status ignores unrelated fork PRs when the current branch tracks the same repository",
() =>
Effect.gen(function* () {
@@ -997,7 +990,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect(
it.effect(
"status detects cross-repo PRs from the upstream remote URL owner",
() =>
Effect.gen(function* () {
@@ -1063,10 +1056,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
"pr list --head jasonLaster:statemachine --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
);
}),
LONG_EFFECT_TEST_TIMEOUT_MS,
20_000,
);
effect(
it.effect(
"status ignores synthetic local branch aliases when the upstream remote name contains slashes",
() =>
Effect.gen(function* () {
@@ -1179,10 +1172,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
),
).toBe(false);
}),
LONG_EFFECT_TEST_TIMEOUT_MS,
20_000,
);
effect("status returns merged PR state when latest PR was merged", () =>
it.effect("status returns merged PR state when latest PR was merged", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1221,7 +1214,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status prefers open PR when merged PR has newer updatedAt", () =>
it.effect("status prefers open PR when merged PR has newer updatedAt", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1269,7 +1262,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("status is resilient to gh lookup failures and returns pr null", () =>
it.effect("status is resilient to gh lookup failures and returns pr null", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1294,7 +1287,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("creates a commit when working tree is dirty", () =>
it.effect("creates a commit when working tree is dirty", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1344,7 +1337,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("uses custom commit message when provided", () =>
it.effect("uses custom commit message when provided", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1387,7 +1380,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("commits only selected files when filePaths is provided", () =>
it.effect("commits only selected files when filePaths is provided", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1412,7 +1405,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("creates feature branch, commits, and pushes with featureBranch option", () =>
it.effect("creates feature branch, commits, and pushes with featureBranch option", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1475,7 +1468,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("featureBranch uses custom commit message and derives branch name", () =>
it.effect("featureBranch uses custom commit message and derives branch name", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1518,7 +1511,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("skips commit when there are no uncommitted changes", () =>
it.effect("skips commit when there are no uncommitted changes", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1536,7 +1529,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("featureBranch returns error when worktree is clean", () =>
it.effect("featureBranch returns error when worktree is clean", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1557,7 +1550,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("commits and pushes with upstream auto-setup when needed", () =>
it.effect("commits and pushes with upstream auto-setup when needed", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1584,7 +1577,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect(
it.effect(
"pushes and creates PR from a no-upstream branch when local commits are ahead of base",
() =>
Effect.gen(function* () {
@@ -1636,7 +1629,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("skips push when branch is already up to date", () =>
it.effect("skips push when branch is already up to date", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1657,7 +1650,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("pushes existing clean commits without rerunning commit logic", () =>
it.effect("pushes existing clean commits without rerunning commit logic", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1685,7 +1678,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("create_pr pushes a clean branch before creating the PR when needed", () =>
it.effect("create_pr pushes a clean branch before creating the PR when needed", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1732,7 +1725,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("returns existing PR metadata for commit/push/pr action", () =>
it.effect("returns existing PR metadata for commit/push/pr action", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -1778,7 +1771,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect(
it.effect(
"returns existing cross-repo PR metadata using the fork owner selector",
() =>
Effect.gen(function* () {
@@ -1836,10 +1829,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
).toBe(true);
expect(ghCalls.some((call) => call.startsWith("pr create "))).toBe(false);
}),
LONG_EFFECT_TEST_TIMEOUT_MS,
12_000,
);
effect(
it.effect(
"returns the correct existing PR when a slash remote checks out to a synthetic local alias",
() =>
Effect.gen(function* () {
@@ -1936,10 +1929,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
false,
);
}),
LONG_EFFECT_TEST_TIMEOUT_MS,
20_000,
);
effect(
it.effect(
"prefers owner-qualified selectors before bare branch names for cross-repo PRs",
() =>
Effect.gen(function* () {
@@ -2011,10 +2004,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
expect(ownerSelectorCallIndex).toBeGreaterThanOrEqual(0);
expect(ghCalls.some((call) => call.startsWith("pr create "))).toBe(false);
}),
LONG_EFFECT_TEST_TIMEOUT_MS,
12_000,
);
effect(
it.effect(
"stops probing head selectors after finding an existing PR",
() =>
Effect.gen(function* () {
@@ -2078,10 +2071,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
"pr list --head octocat:statemachine --state open --limit 1",
);
}),
LONG_EFFECT_TEST_TIMEOUT_MS,
12_000,
);
effect("creates PR when one does not already exist", () =>
it.effect("creates PR when one does not already exist", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2156,75 +2149,79 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("creates a new PR instead of reusing an unrelated fork PR with the same head branch", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
yield* runGit(repoDir, ["checkout", "-b", "feature/no-fork-match"]);
const remoteDir = yield* createBareRemote();
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
fs.writeFileSync(path.join(repoDir, "changes.txt"), "change\n");
yield* runGit(repoDir, ["add", "changes.txt"]);
yield* runGit(repoDir, ["commit", "-m", "Feature commit"]);
yield* runGit(repoDir, ["push", "-u", "origin", "feature/no-fork-match"]);
it.effect(
"creates a new PR instead of reusing an unrelated fork PR with the same head branch",
() =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
yield* runGit(repoDir, ["checkout", "-b", "feature/no-fork-match"]);
const remoteDir = yield* createBareRemote();
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
fs.writeFileSync(path.join(repoDir, "changes.txt"), "change\n");
yield* runGit(repoDir, ["add", "changes.txt"]);
yield* runGit(repoDir, ["commit", "-m", "Feature commit"]);
yield* runGit(repoDir, ["push", "-u", "origin", "feature/no-fork-match"]);
const { manager, ghCalls } = yield* makeManager({
ghScenario: {
prListSequence: [
JSON.stringify([
{
number: 1661,
title: "Fork PR with same branch name",
url: "https://github.com/pingdotgg/t3code/pull/1661",
baseRefName: "main",
headRefName: "feature/no-fork-match",
state: "OPEN",
isCrossRepository: true,
headRepository: {
nameWithOwner: "lnieuwenhuis/t3code",
const { manager, ghCalls } = yield* makeManager({
ghScenario: {
prListSequence: [
JSON.stringify([
{
number: 1661,
title: "Fork PR with same branch name",
url: "https://github.com/pingdotgg/t3code/pull/1661",
baseRefName: "main",
headRefName: "feature/no-fork-match",
state: "OPEN",
isCrossRepository: true,
headRepository: {
nameWithOwner: "lnieuwenhuis/t3code",
},
headRepositoryOwner: {
login: "lnieuwenhuis",
},
},
headRepositoryOwner: {
login: "lnieuwenhuis",
]),
JSON.stringify([
{
number: 188,
title: "Add stacked git actions",
url: "https://github.com/pingdotgg/codething-mvp/pull/188",
baseRefName: "main",
headRefName: "feature/no-fork-match",
state: "OPEN",
isCrossRepository: false,
},
},
]),
JSON.stringify([
{
number: 188,
title: "Add stacked git actions",
url: "https://github.com/pingdotgg/codething-mvp/pull/188",
baseRefName: "main",
headRefName: "feature/no-fork-match",
state: "OPEN",
isCrossRepository: false,
},
]),
],
},
});
const result = yield* runStackedAction(manager, {
cwd: repoDir,
action: "commit_push_pr",
});
]),
],
},
});
const result = yield* runStackedAction(manager, {
cwd: repoDir,
action: "commit_push_pr",
});
expect(result.pr.status).toBe("created");
expect(result.pr.number).toBe(188);
expect(result.toast).toEqual({
title: "Created PR #188",
description: "Add stacked git actions",
cta: {
kind: "open_pr",
label: "View PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/188",
},
});
expect(
ghCalls.some((call) => call.includes("pr create --base main --head feature/no-fork-match")),
).toBe(true);
}),
expect(result.pr.status).toBe("created");
expect(result.pr.number).toBe(188);
expect(result.toast).toEqual({
title: "Created PR #188",
description: "Add stacked git actions",
cta: {
kind: "open_pr",
label: "View PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/188",
},
});
expect(
ghCalls.some((call) =>
call.includes("pr create --base main --head feature/no-fork-match"),
),
).toBe(true);
}),
);
effect("creates cross-repo PRs with the fork owner selector and default base branch", () =>
it.effect("creates cross-repo PRs with the fork owner selector and default base branch", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2295,7 +2292,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("rejects push/pr actions from detached HEAD", () =>
it.effect("rejects push/pr actions from detached HEAD", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2313,7 +2310,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("surfaces missing gh binary errors", () =>
it.effect("surfaces missing gh binary errors", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2343,7 +2340,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("surfaces gh auth errors with guidance", () =>
it.effect("surfaces gh auth errors with guidance", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2373,7 +2370,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("resolves pull requests from #number references", () =>
it.effect("resolves pull requests from #number references", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2408,7 +2405,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("prepares pull request threads in local mode by checking out the PR branch", () =>
it.effect("prepares pull request threads in local mode by checking out the PR branch", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2444,7 +2441,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("prepares pull request threads in worktree mode on the PR head branch", () =>
it.effect("prepares pull request threads in worktree mode on the PR head branch", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2663,7 +2660,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("preserves fork upstream tracking when preparing a local PR thread", () =>
it.effect("preserves fork upstream tracking when preparing a local PR thread", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2716,7 +2713,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("derives fork repository identity from PR URL when GitHub omits nameWithOwner", () =>
it.effect("derives fork repository identity from PR URL when GitHub omits nameWithOwner", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2773,7 +2770,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("reuses an existing dedicated worktree for the PR head branch", () =>
it.effect("reuses an existing dedicated worktree for the PR head branch", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -2825,7 +2822,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect(
it.effect(
"does not block fork PR worktree prep when the fork head branch collides with root main",
() =>
Effect.gen(function* () {
@@ -2885,65 +2882,67 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("does not overwrite an existing local main branch when preparing a fork PR worktree", () =>
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", "add", "fork-seed", forkDir]);
yield* runGit(repoDir, ["checkout", "-b", "fork-main-source"]);
fs.writeFileSync(path.join(repoDir, "fork-main-second.txt"), "fork main second\n");
yield* runGit(repoDir, ["add", "fork-main-second.txt"]);
yield* runGit(repoDir, ["commit", "-m", "Fork main second branch"]);
yield* runGit(repoDir, ["push", "-u", "fork-seed", "fork-main-source:main"]);
yield* runGit(repoDir, ["checkout", "main"]);
const localMainBefore = (yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim();
yield* runGit(repoDir, ["checkout", "-b", "feature/root-branch"]);
it.effect(
"does not overwrite an existing local main branch when preparing a fork PR worktree",
() =>
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", "add", "fork-seed", forkDir]);
yield* runGit(repoDir, ["checkout", "-b", "fork-main-source"]);
fs.writeFileSync(path.join(repoDir, "fork-main-second.txt"), "fork main second\n");
yield* runGit(repoDir, ["add", "fork-main-second.txt"]);
yield* runGit(repoDir, ["commit", "-m", "Fork main second branch"]);
yield* runGit(repoDir, ["push", "-u", "fork-seed", "fork-main-source:main"]);
yield* runGit(repoDir, ["checkout", "main"]);
const localMainBefore = (yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim();
yield* runGit(repoDir, ["checkout", "-b", "feature/root-branch"]);
const { manager } = yield* makeManager({
ghScenario: {
pullRequest: {
number: 92,
title: "Fork main overwrite PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/92",
baseRefName: "main",
headRefName: "main",
state: "open",
isCrossRepository: true,
headRepositoryNameWithOwner: "octocat/codething-mvp",
headRepositoryOwnerLogin: "octocat",
},
repositoryCloneUrls: {
"octocat/codething-mvp": {
url: forkDir,
sshUrl: forkDir,
const { manager } = yield* makeManager({
ghScenario: {
pullRequest: {
number: 92,
title: "Fork main overwrite PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/92",
baseRefName: "main",
headRefName: "main",
state: "open",
isCrossRepository: true,
headRepositoryNameWithOwner: "octocat/codething-mvp",
headRepositoryOwnerLogin: "octocat",
},
repositoryCloneUrls: {
"octocat/codething-mvp": {
url: forkDir,
sshUrl: forkDir,
},
},
},
},
});
});
const result = yield* preparePullRequestThread(manager, {
cwd: repoDir,
reference: "92",
mode: "worktree",
});
const result = yield* preparePullRequestThread(manager, {
cwd: repoDir,
reference: "92",
mode: "worktree",
});
expect(result.branch).toBe("t3code/pr-92/main");
expect((yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim()).toBe(localMainBefore);
expect(
(yield* runGit(result.worktreePath as string, [
"rev-parse",
"--abbrev-ref",
"@{upstream}",
])).stdout.trim(),
).toBe("fork-seed/main");
}),
expect(result.branch).toBe("t3code/pr-92/main");
expect((yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim()).toBe(localMainBefore);
expect(
(yield* runGit(result.worktreePath as string, [
"rev-parse",
"--abbrev-ref",
"@{upstream}",
])).stdout.trim(),
).toBe("fork-seed/main");
}),
);
effect("reuses an existing PR worktree and restores fork upstream tracking", () =>
it.effect("reuses an existing PR worktree and restores fork upstream tracking", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -3087,7 +3086,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("emits ordered progress events for commit hooks", () =>
it.effect("emits ordered progress events for commit hooks", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -3150,7 +3149,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
effect("emits action_failed when a commit hook rejects", () =>
it.effect("emits action_failed when a commit hook rejects", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* initRepo(repoDir);
@@ -96,6 +96,22 @@ function withFakeAcpAgent<A, E, R>(
});
}
function waitForFileContent(path: string): Effect.Effect<string> {
return Effect.promise(async () => {
const deadline = Date.now() + 5_000;
for (;;) {
try {
return readFileSync(path, "utf8");
} catch (error) {
if (Date.now() >= deadline) {
throw error instanceof Error ? error : new Error(String(error));
}
}
await new Promise((resolve) => setTimeout(resolve, 25));
}
});
}
it.layer(CursorTextGenerationTestLayer)("CursorTextGenerationLive", (it) => {
it.effect("uses ACP model config options instead of raw CLI model ids", () => {
const requestLogDir = mkdtempSync(path.join(os.tmpdir(), "t3code-cursor-text-log-"));
@@ -145,14 +161,6 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGenerationLive", (it) => {
parameterizedModelPicker: true,
},
});
expect(
requests.some(
(request) =>
request.method === "session/set_config_option" &&
request.params?.configId === "mode" &&
request.params?.value === "ask",
),
).toBe(true);
expect(
requests.some(
(request) =>
@@ -250,4 +258,41 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGenerationLive", (it) => {
}),
),
);
it.effect("closes the ACP child process after text generation completes", () => {
const exitLogDir = mkdtempSync(path.join(os.tmpdir(), "t3code-cursor-text-exit-log-"));
const exitLogPath = path.join(exitLogDir, "exit.log");
return withFakeAcpAgent(
{
T3_ACP_EXIT_LOG_PATH: exitLogPath,
T3_ACP_PROMPT_RESPONSE_TEXT: JSON.stringify({
subject: "Close runtime after generation",
body: "",
}),
},
Effect.gen(function* () {
const textGeneration = yield* TextGeneration;
const generated = yield* textGeneration.generateCommitMessage({
cwd: process.cwd(),
branch: "feature/cursor-runtime-close",
stagedSummary: "M apps/server/src/git/Layers/CursorTextGeneration.ts",
stagedPatch:
"diff --git a/apps/server/src/git/Layers/CursorTextGeneration.ts b/apps/server/src/git/Layers/CursorTextGeneration.ts",
modelSelection: {
provider: "cursor",
model: "composer-2",
},
});
expect(generated.subject).toBe("Close runtime after generation");
const exitLog = yield* waitForFileContent(exitLogPath);
expect(exitLog).toContain("exit:0");
rmSync(exitLogDir, { recursive: true, force: true });
}),
);
});
});
+194 -187
View File
@@ -183,16 +183,8 @@ function splitNullSeparatedPaths(input: string): string[] {
// ── Tests ──
it.layer(TestLayer)("git integration", (it) => {
const LONG_EFFECT_TEST_TIMEOUT_MS = 30_000;
const ASYNC_GIT_WAIT_TIMEOUT_MS = 30_000;
const effect = (
name: string,
test: Parameters<typeof it.effect>[1],
timeout = LONG_EFFECT_TEST_TIMEOUT_MS,
) => it.effect(name, test, timeout);
describe("shell process execution", () => {
effect("caps captured output when maxOutputBytes is exceeded", () =>
it.effect("caps captured output when maxOutputBytes is exceeded", () =>
Effect.gen(function* () {
const result = yield* runShellCommand({
command: `node -e "process.stdout.write('x'.repeat(2000))"`,
@@ -211,7 +203,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── initGitRepo ──
describe("initGitRepo", () => {
effect("creates a valid git repo", () =>
it.effect("creates a valid git repo", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* (yield* GitCore).initRepo({ cwd: tmp });
@@ -219,7 +211,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("listGitBranches reports isRepo: true after init + commit", () =>
it.effect("listGitBranches reports isRepo: true after init + commit", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -315,7 +307,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── listGitBranches ──
describe("listGitBranches", () => {
effect("returns isRepo: false for non-git directory", () =>
it.effect("returns isRepo: false for non-git directory", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const result = yield* (yield* GitCore).listBranches({ cwd: tmp });
@@ -325,7 +317,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("returns isRepo: false for deleted directories", () =>
it.effect("returns isRepo: false for deleted directories", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const deletedDir = path.join(tmp, "deleted-repo");
@@ -340,7 +332,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("returns the current branch with current: true", () =>
it.effect("returns the current branch with current: true", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -351,7 +343,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("does not include detached HEAD pseudo-refs as branches", () =>
it.effect("does not include detached HEAD pseudo-refs as branches", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -363,7 +355,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("keeps current branch first and sorts the remaining branches by recency", () =>
it.effect("keeps current branch first and sorts the remaining branches by recency", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -401,7 +393,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("keeps default branch right after current branch", () =>
it.effect("keeps default branch right after current branch", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
@@ -445,7 +437,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("lists multiple branches after creating them", () =>
it.effect("lists multiple branches after creating them", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -556,7 +548,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("lists local branches first and remote branches last", () =>
it.effect("lists local branches first and remote branches last", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const tmp = yield* makeTmpDir();
@@ -603,7 +595,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("includes remoteName metadata for remotes with slash in the name", () =>
it.effect("includes remoteName metadata for remotes with slash in the name", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const tmp = yield* makeTmpDir();
@@ -674,7 +666,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── checkoutGitBranch ──
describe("checkoutGitBranch", () => {
effect("checks out an existing branch", () =>
it.effect("checks out an existing branch", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -688,7 +680,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("refreshes upstream behind count after checkout when remote branch advanced", () =>
it.effect("refreshes upstream behind count after checkout when remote branch advanced", () =>
Effect.gen(function* () {
const context = yield* Effect.context<never>();
const runPromise = Effect.runPromiseWith(context);
@@ -734,7 +726,7 @@ it.layer(TestLayer)("git integration", (it) => {
expect(details.behindCount).toBe(1);
},
{
timeout: ASYNC_GIT_WAIT_TIMEOUT_MS,
timeout: 10_000,
interval: 100,
},
),
@@ -742,7 +734,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("statusDetails remains successful when upstream refresh fails after checkout", () =>
it.effect("statusDetails remains successful when upstream refresh fails after checkout", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
@@ -789,7 +781,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("defers upstream refresh until statusDetails is requested", () =>
it.effect("defers upstream refresh until statusDetails is requested", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
@@ -834,7 +826,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("shares upstream refreshes across worktrees that use the same git common dir", () =>
it.effect("coalesces upstream refreshes across sibling worktrees on the same remote", () =>
Effect.gen(function* () {
const ok = (stdout = "") =>
Effect.succeed({
@@ -908,78 +900,83 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("briefly backs off failed upstream refreshes across sibling worktrees", () =>
Effect.gen(function* () {
const ok = (stdout = "") =>
Effect.succeed({
code: 0,
stdout,
stderr: "",
stdoutTruncated: false,
stderrTruncated: false,
});
it.effect(
"briefly backs off failed upstream refreshes across sibling worktrees on one remote",
() =>
Effect.gen(function* () {
const ok = (stdout = "") =>
Effect.succeed({
code: 0,
stdout,
stderr: "",
stdoutTruncated: false,
stderrTruncated: false,
});
let fetchCount = 0;
const core = yield* makeIsolatedGitCore((input) => {
if (
input.args[0] === "rev-parse" &&
input.args[1] === "--abbrev-ref" &&
input.args[2] === "--symbolic-full-name" &&
input.args[3] === "@{upstream}"
) {
return ok(
input.cwd === "/repo/worktrees/pr-123" ? "origin/feature/pr-123\n" : "origin/main\n",
);
}
if (input.args[0] === "remote") {
return ok("origin\n");
}
if (input.args[0] === "rev-parse" && input.args[1] === "--git-common-dir") {
return ok("/repo/.git\n");
}
if (input.args[0] === "--git-dir" && input.args[2] === "fetch") {
fetchCount += 1;
let fetchCount = 0;
const core = yield* makeIsolatedGitCore((input) => {
if (
input.args[0] === "rev-parse" &&
input.args[1] === "--abbrev-ref" &&
input.args[2] === "--symbolic-full-name" &&
input.args[3] === "@{upstream}"
) {
return ok(
input.cwd === "/repo/worktrees/pr-123"
? "origin/feature/pr-123\n"
: "origin/main\n",
);
}
if (input.args[0] === "remote") {
return ok("origin\n");
}
if (input.args[0] === "rev-parse" && input.args[1] === "--git-common-dir") {
return ok("/repo/.git\n");
}
if (input.args[0] === "--git-dir" && input.args[2] === "fetch") {
fetchCount += 1;
return Effect.fail(
new GitCommandError({
operation: input.operation,
command: `git ${input.args.join(" ")}`,
cwd: input.cwd,
detail: "simulated fetch timeout",
}),
);
}
if (input.operation === "GitCore.statusDetails.status") {
return ok(
input.cwd === "/repo/worktrees/pr-123"
? "# branch.head feature/pr-123\n# branch.upstream origin/feature/pr-123\n# branch.ab +0 -0\n"
: "# branch.head main\n# branch.upstream origin/main\n# branch.ab +0 -0\n",
);
}
if (
input.operation === "GitCore.statusDetails.unstagedNumstat" ||
input.operation === "GitCore.statusDetails.stagedNumstat"
) {
return ok();
}
if (input.operation === "GitCore.statusDetails.defaultRef") {
return ok("refs/remotes/origin/main\n");
}
return Effect.fail(
new GitCommandError({
operation: input.operation,
command: `git ${input.args.join(" ")}`,
cwd: input.cwd,
detail: "simulated fetch timeout",
detail: "Unexpected git command in refresh failure cooldown test.",
}),
);
}
if (input.operation === "GitCore.statusDetails.status") {
return ok(
input.cwd === "/repo/worktrees/pr-123"
? "# branch.head feature/pr-123\n# branch.upstream origin/feature/pr-123\n# branch.ab +0 -0\n"
: "# branch.head main\n# branch.upstream origin/main\n# branch.ab +0 -0\n",
);
}
if (
input.operation === "GitCore.statusDetails.unstagedNumstat" ||
input.operation === "GitCore.statusDetails.stagedNumstat"
) {
return ok();
}
if (input.operation === "GitCore.statusDetails.defaultRef") {
return ok("refs/remotes/origin/main\n");
}
return Effect.fail(
new GitCommandError({
operation: input.operation,
command: `git ${input.args.join(" ")}`,
cwd: input.cwd,
detail: "Unexpected git command in refresh failure cooldown test.",
}),
);
});
yield* core.statusDetails("/repo/worktrees/main");
yield* core.statusDetails("/repo/worktrees/pr-123");
expect(fetchCount).toBe(1);
}),
});
yield* core.statusDetails("/repo/worktrees/main");
yield* core.statusDetails("/repo/worktrees/pr-123");
expect(fetchCount).toBe(1);
}),
);
effect("throws when branch does not exist", () =>
it.effect("throws when branch does not exist", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -990,7 +987,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("does not silently checkout a local branch when a remote ref no longer exists", () =>
it.effect("does not silently checkout a local branch when a remote ref no longer exists", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
@@ -1013,7 +1010,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("checks out a remote tracking branch when remote name contains slashes", () =>
it.effect("checks out a remote tracking branch when remote name contains slashes", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const prefixRemote = yield* makeTmpDir();
@@ -1078,7 +1075,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect(
it.effect(
"falls back to detached checkout when --track would conflict with an existing local branch",
() =>
Effect.gen(function* () {
@@ -1108,7 +1105,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("throws when checkout would overwrite uncommitted changes", () =>
it.effect("throws when checkout would overwrite uncommitted changes", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1146,7 +1143,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── createGitBranch ──
describe("createGitBranch", () => {
effect("creates a new branch visible in listGitBranches", () =>
it.effect("creates a new branch visible in listGitBranches", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1157,7 +1154,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("throws when branch already exists", () =>
it.effect("throws when branch already exists", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1173,7 +1170,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── renameGitBranch ──
describe("renameGitBranch", () => {
effect("renames the current branch", () =>
it.effect("renames the current branch", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1195,7 +1192,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("returns success without git invocation when old/new names match", () =>
it.effect("returns success without git invocation when old/new names match", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1213,7 +1210,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("appends numeric suffix when target branch already exists", () =>
it.effect("appends numeric suffix when target branch already exists", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1240,7 +1237,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("increments suffix until it finds an available branch name", () =>
it.effect("increments suffix until it finds an available branch name", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1259,7 +1256,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("uses '--' separator for branch rename arguments", () =>
it.effect("uses '--' separator for branch rename arguments", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1290,7 +1287,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── createGitWorktree + removeGitWorktree ──
describe("createGitWorktree", () => {
effect("creates a worktree with a new branch from the base branch", () =>
it.effect("creates a worktree with a new branch from the base branch", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1317,7 +1314,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("worktree has the new branch checked out", () =>
it.effect("worktree has the new branch checked out", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1342,7 +1339,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("creates a worktree for an existing branch when newBranch is omitted", () =>
it.effect("creates a worktree for an existing branch when newBranch is omitted", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1364,7 +1361,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("throws when new branch name already exists", () =>
it.effect("throws when new branch name already exists", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1387,7 +1384,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("listGitBranches from worktree cwd reports worktree branch as current", () =>
it.effect("listGitBranches from worktree cwd reports worktree branch as current", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1419,7 +1416,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("removeGitWorktree cleans up the worktree", () =>
it.effect("removeGitWorktree cleans up the worktree", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1442,7 +1439,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("removeGitWorktree force removes a dirty worktree", () =>
it.effect("removeGitWorktree force removes a dirty worktree", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1477,7 +1474,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── Full flow: local branch checkout ──
describe("full flow: local branch checkout", () => {
effect("init → commit → create branch → checkout → verify current", () =>
it.effect("init → commit → create branch → checkout → verify current", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1494,7 +1491,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── Full flow: worktree creation from base branch ──
describe("full flow: worktree creation", () => {
effect("creates worktree with new branch from current branch", () =>
it.effect("creates worktree with new branch from current branch", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1529,7 +1526,7 @@ it.layer(TestLayer)("git integration", (it) => {
});
describe("fetchPullRequestBranch", () => {
effect("fetches a GitHub pull request ref into a local branch without checkout", () =>
it.effect("fetches a GitHub pull request ref into a local branch without checkout", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(tmp);
@@ -1562,7 +1559,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── Full flow: thread switching simulation ──
describe("full flow: thread switching (checkout toggling)", () => {
effect("checkout a → checkout b → checkout a → current matches", () =>
it.effect("checkout a → checkout b → checkout a → current matches", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1590,7 +1587,7 @@ it.layer(TestLayer)("git integration", (it) => {
// ── Full flow: checkout conflict ──
describe("full flow: checkout conflict", () => {
effect("uncommitted changes prevent checkout to a diverged branch", () =>
it.effect("uncommitted changes prevent checkout to a diverged branch", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1624,7 +1621,7 @@ it.layer(TestLayer)("git integration", (it) => {
});
describe("GitCore", () => {
effect("supports branch lifecycle operations through the service API", () =>
it.effect("supports branch lifecycle operations through the service API", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const core = yield* GitCore;
@@ -1648,7 +1645,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect(
it.effect(
"reuses an existing remote when the target URL only differs by a trailing slash after .git",
() =>
Effect.gen(function* () {
@@ -1669,7 +1666,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("reports status details and dirty state", () =>
it.effect("reports status details and dirty state", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1685,7 +1682,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("returns a non-repo status for deleted directories", () =>
it.effect("returns a non-repo status for deleted directories", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const deletedDir = path.join(tmp, "deleted-repo");
@@ -1716,7 +1713,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("computes ahead count against base branch when no upstream is configured", () =>
it.effect("computes ahead count against base branch when no upstream is configured", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1736,37 +1733,39 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("computes ahead count against origin/default when local default branch is missing", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
yield* git(remote, ["init", "--bare"]);
it.effect(
"computes ahead count against origin/default when local default branch is missing",
() =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
yield* git(remote, ["init", "--bare"]);
yield* initRepoWithCommit(source);
const initialBranch = (yield* (yield* GitCore).listBranches({
cwd: source,
})).branches.find((branch) => branch.current)!.name;
yield* git(source, ["remote", "add", "origin", remote]);
yield* git(source, ["push", "-u", "origin", initialBranch]);
yield* git(source, ["checkout", "-b", "feature/remote-base-only"]);
yield* writeTextFile(
path.join(source, "feature.txt"),
`ahead of origin/${initialBranch}\n`,
);
yield* git(source, ["add", "feature.txt"]);
yield* git(source, ["commit", "-m", "feature commit"]);
yield* git(source, ["branch", "-D", initialBranch]);
yield* initRepoWithCommit(source);
const initialBranch = (yield* (yield* GitCore).listBranches({
cwd: source,
})).branches.find((branch) => branch.current)!.name;
yield* git(source, ["remote", "add", "origin", remote]);
yield* git(source, ["push", "-u", "origin", initialBranch]);
yield* git(source, ["checkout", "-b", "feature/remote-base-only"]);
yield* writeTextFile(
path.join(source, "feature.txt"),
`ahead of origin/${initialBranch}\n`,
);
yield* git(source, ["add", "feature.txt"]);
yield* git(source, ["commit", "-m", "feature commit"]);
yield* git(source, ["branch", "-D", initialBranch]);
const core = yield* GitCore;
const details = yield* core.statusDetails(source);
expect(details.branch).toBe("feature/remote-base-only");
expect(details.hasUpstream).toBe(false);
expect(details.aheadCount).toBe(1);
expect(details.behindCount).toBe(0);
}),
const core = yield* GitCore;
const details = yield* core.statusDetails(source);
expect(details.branch).toBe("feature/remote-base-only");
expect(details.hasUpstream).toBe(false);
expect(details.aheadCount).toBe(1);
expect(details.behindCount).toBe(0);
}),
);
effect(
it.effect(
"computes ahead count against a non-origin remote-prefixed gh-merge-base candidate",
() =>
Effect.gen(function* () {
@@ -1804,7 +1803,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("skips push when no upstream is configured and branch is not ahead of base", () =>
it.effect("skips push when no upstream is configured and branch is not ahead of base", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -1820,7 +1819,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("pushes with upstream setup when no comparable base branch exists", () =>
it.effect("pushes with upstream setup when no comparable base branch exists", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
@@ -1845,7 +1844,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("pushes with upstream setup to the only configured non-origin remote", () =>
it.effect("pushes with upstream setup to the only configured non-origin remote", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
@@ -1870,7 +1869,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect(
it.effect(
"pushes with upstream setup when comparable base exists but remote branch is missing",
() =>
Effect.gen(function* () {
@@ -1906,7 +1905,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("prefers branch pushRemote over origin when setting upstream", () =>
it.effect("prefers branch pushRemote over origin when setting upstream", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const origin = yield* makeTmpDir();
@@ -1943,7 +1942,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect(
it.effect(
"pushes renamed PR worktree branches to their tracked upstream branch even when push.default is current",
() =>
Effect.gen(function* () {
@@ -1990,7 +1989,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("pushes to the tracked upstream when the remote name contains slashes", () =>
it.effect("pushes to the tracked upstream when the remote name contains slashes", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
@@ -2031,7 +2030,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("includes command context when worktree removal fails", () =>
it.effect("includes command context when worktree removal fails", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2052,38 +2051,46 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("refreshes upstream before statusDetails so behind count reflects remote updates", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
const clone = yield* makeTmpDir();
yield* git(remote, ["init", "--bare"]);
it.effect(
"refreshes upstream before statusDetails so behind count reflects remote updates",
() =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
const clone = yield* makeTmpDir();
yield* git(remote, ["init", "--bare"]);
yield* initRepoWithCommit(source);
const initialBranch = (yield* (yield* GitCore).listBranches({
cwd: source,
})).branches.find((branch) => branch.current)!.name;
yield* git(source, ["remote", "add", "origin", remote]);
yield* git(source, ["push", "-u", "origin", initialBranch]);
yield* initRepoWithCommit(source);
const initialBranch = (yield* (yield* GitCore).listBranches({
cwd: source,
})).branches.find((branch) => branch.current)!.name;
yield* git(source, ["remote", "add", "origin", remote]);
yield* git(source, ["push", "-u", "origin", initialBranch]);
yield* git(clone, ["clone", remote, "."]);
yield* git(clone, ["config", "user.email", "[email protected]"]);
yield* git(clone, ["config", "user.name", "Test"]);
yield* git(clone, ["checkout", "-B", initialBranch, "--track", `origin/${initialBranch}`]);
yield* writeTextFile(path.join(clone, "CHANGELOG.md"), "remote change\n");
yield* git(clone, ["add", "CHANGELOG.md"]);
yield* git(clone, ["commit", "-m", "remote update"]);
yield* git(clone, ["push", "origin", initialBranch]);
yield* git(clone, ["clone", remote, "."]);
yield* git(clone, ["config", "user.email", "[email protected]"]);
yield* git(clone, ["config", "user.name", "Test"]);
yield* git(clone, [
"checkout",
"-B",
initialBranch,
"--track",
`origin/${initialBranch}`,
]);
yield* writeTextFile(path.join(clone, "CHANGELOG.md"), "remote change\n");
yield* git(clone, ["add", "CHANGELOG.md"]);
yield* git(clone, ["commit", "-m", "remote update"]);
yield* git(clone, ["push", "origin", initialBranch]);
const core = yield* GitCore;
const details = yield* core.statusDetails(source);
expect(details.branch).toBe(initialBranch);
expect(details.aheadCount).toBe(0);
expect(details.behindCount).toBe(1);
}),
const core = yield* GitCore;
const details = yield* core.statusDetails(source);
expect(details.branch).toBe(initialBranch);
expect(details.aheadCount).toBe(0);
expect(details.behindCount).toBe(1);
}),
);
effect("prepares commit context by auto-staging and creates commit", () =>
it.effect("prepares commit context by auto-staging and creates commit", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2101,7 +2108,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("prepareCommitContext stages only selected files when filePaths provided", () =>
it.effect("prepareCommitContext stages only selected files when filePaths provided", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2124,7 +2131,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("prepareCommitContext stages everything when filePaths is undefined", () =>
it.effect("prepareCommitContext stages everything when filePaths is undefined", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2140,7 +2147,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("prepareCommitContext truncates oversized staged patches instead of failing", () =>
it.effect("prepareCommitContext truncates oversized staged patches instead of failing", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2155,7 +2162,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("readRangeContext truncates oversized diff patches instead of failing", () =>
it.effect("readRangeContext truncates oversized diff patches instead of failing", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(tmp);
@@ -2174,7 +2181,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("pushes with upstream setup and then skips when up to date", () =>
it.effect("pushes with upstream setup and then skips when up to date", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
@@ -2202,7 +2209,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("pulls behind branch and then reports up-to-date", () =>
it.effect("pulls behind branch and then reports up-to-date", () =>
Effect.gen(function* () {
const remote = yield* makeTmpDir();
const source = yield* makeTmpDir();
@@ -2234,7 +2241,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("top-level pullGitBranch rejects when no upstream exists", () =>
it.effect("top-level pullGitBranch rejects when no upstream exists", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2246,7 +2253,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("lists branches when recency lookup fails", () =>
it.effect("lists branches when recency lookup fails", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
@@ -2276,7 +2283,7 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
effect("falls back to empty remote branch data when remote lookups fail", () =>
it.effect("falls back to empty remote branch data when remote lookups fail", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
@@ -49,16 +49,16 @@ const makeRoutingTextGeneration = Effect.gen(function* () {
const codex = yield* CodexTextGen;
const claude = yield* ClaudeTextGen;
const cursor = yield* CursorTextGen;
const opencode = yield* OpenCodeTextGen;
const openCode = yield* OpenCodeTextGen;
const providerToService = {
codex,
claudeAgent: claude,
cursor,
opencode,
};
const route = (provider: TextGenerationProvider | "opencode") => providerToService[provider];
const route = (provider?: TextGenerationProvider): TextGenerationShape =>
provider === "claudeAgent"
? claude
: provider === "opencode"
? openCode
: provider === "cursor"
? cursor
: codex;
return {
generateCommitMessage: (input) =>
@@ -13,7 +13,7 @@ import type { ChatAttachment, ModelSelection } from "@t3tools/contracts";
import type { TextGenerationError } from "@t3tools/contracts";
/** Providers that support git text generation (commit messages, PR content, branch names). */
export type TextGenerationProvider = "codex" | "claudeAgent" | "cursor";
export type TextGenerationProvider = "codex" | "claudeAgent" | "cursor" | "opencode";
export interface CommitMessageGenerationInput {
cwd: string;