Skip to content

Commit d1aeed2

Browse files
ferhtgoldarazclaudejuliusmarminge
authored
fix(server): repos without a remote no longer record failed spans on status refresh (pingdotgg#32905)
Co-authored-by: ferhtgoldaraz <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 61cb845 commit d1aeed2

2 files changed

Lines changed: 60 additions & 14 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as Schema from "effect/Schema";
2323
import * as Sink from "effect/Sink";
2424
import * as Stream from "effect/Stream";
2525
import * as TestClock from "effect/testing/TestClock";
26+
import * as Tracer from "effect/Tracer";
2627
import { ChildProcess, ChildProcessSpawner, CommandLine } from "effect/process";
2728

2829
import {
@@ -4001,6 +4002,44 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40014002
}),
40024003
);
40034004

4005+
it.effect("records no failed span reading status of a repository without a remote", () =>
4006+
Effect.gen(function* () {
4007+
const cwd = yield* makeTmpDir();
4008+
yield* initRepoWithCommit(cwd);
4009+
yield* git(cwd, ["checkout", "-b", "feature"]);
4010+
const driver = yield* GitVcsDriver.GitVcsDriver;
4011+
const spans: Array<Tracer.NativeSpan> = [];
4012+
const tracer = Tracer.make({
4013+
span: (options) => {
4014+
const span = new Tracer.NativeSpan(options);
4015+
spans.push(span);
4016+
return span;
4017+
},
4018+
});
4019+
const traced = <A, E>(effect: Effect.Effect<A, E>) =>
4020+
Effect.gen(function* () {
4021+
spans.length = 0;
4022+
const exit = yield* effect.pipe(Effect.withTracer(tracer), Effect.exit);
4023+
const failedSpans = spans.flatMap((span) =>
4024+
span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [],
4025+
);
4026+
return { exit, failedSpans };
4027+
});
4028+
4029+
const status = yield* traced(driver.statusDetailsRemote(cwd));
4030+
assert.isTrue(Exit.isSuccess(status.exit));
4031+
assert.deepStrictEqual(status.failedSpans, []);
4032+
4033+
// A caller that needs a remote still fails, in its own span.
4034+
const fetch = yield* traced(driver.fetchRefCommit({ cwd, ref: "refs/pull/1/head" }));
4035+
assert.include(
4036+
Exit.isFailure(fetch.exit) ? Cause.pretty(fetch.exit.cause) : "",
4037+
"No git remote is configured for this repository.",
4038+
);
4039+
assert.deepStrictEqual(fetch.failedSpans, ["GitVcsDriver.fetchRefCommit"]);
4040+
}),
4041+
);
4042+
40044043
it.effect("can read cached remote divergence without fetching upstream", () =>
40054044
Effect.gen(function* () {
40064045
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,25 +1744,32 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17441744
return parsedRemoteRef?.branchName ?? branchName;
17451745
});
17461746

1747-
const resolvePrimaryRemoteName = Effect.fn("resolvePrimaryRemoteName")(function* (cwd: string) {
1747+
// Local-only repositories are normal and status polls them, so the span succeeds with null.
1748+
// Callers that need a remote fail in their own span.
1749+
const findPrimaryRemoteName = Effect.fn("resolvePrimaryRemoteName")(function* (cwd: string) {
17481750
if (yield* originRemoteExists(cwd)) {
17491751
return "origin";
17501752
}
1751-
const remotes = yield* listRemoteNames(cwd);
1752-
const [firstRemote] = remotes;
1753-
if (firstRemote) {
1754-
return firstRemote;
1755-
}
1756-
return yield* new GitCommandError({
1757-
...gitCommandContext({
1758-
operation: "GitVcsDriver.resolvePrimaryRemoteName",
1759-
cwd,
1760-
args: ["remote"],
1761-
}),
1762-
detail: "No git remote is configured for this repository.",
1763-
});
1753+
const [firstRemote] = yield* listRemoteNames(cwd);
1754+
return firstRemote ?? null;
17641755
});
17651756

1757+
const resolvePrimaryRemoteName = (cwd: string) =>
1758+
findPrimaryRemoteName(cwd).pipe(
1759+
Effect.filterOrFail(
1760+
(remoteName): remoteName is string => remoteName !== null,
1761+
() =>
1762+
new GitCommandError({
1763+
...gitCommandContext({
1764+
operation: "GitVcsDriver.resolvePrimaryRemoteName",
1765+
cwd,
1766+
args: ["remote"],
1767+
}),
1768+
detail: "No git remote is configured for this repository.",
1769+
}),
1770+
),
1771+
);
1772+
17661773
const resolvePushRemoteName = Effect.fn("resolvePushRemoteName")(function* (
17671774
cwd: string,
17681775
refName: string,

0 commit comments

Comments
 (0)