Skip to content

Commit 92ad79f

Browse files
saphidclaude
authored andcommitted
fix(server): a git action that fails partway refreshes the Git panel
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 30084f0 commit 92ad79f

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

‎apps/server/src/ws.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { assert, it } from "@effect/vitest";
44
import {
55
AuthSessionId,
6+
AuthSourceControlWriteScope,
67
EnvironmentId,
8+
GitManagerError,
79
ProjectId,
810
ThreadId,
911
ProviderDriverKind,
1012
ProviderInstanceId,
1113
WS_METHODS,
14+
WsRpcGroup,
1215
WsServerRefreshProvidersRpc,
1316
WsSubscribeServerConfigRpc,
1417
type OrchestrationV2StoredEvent,
@@ -58,6 +61,7 @@ import * as ModelManifest from "./provider/ModelManifest.ts";
5861
import * as Orchestrator from "./orchestration-v2/Orchestrator.ts";
5962
import * as OtlpEndpointCheck from "./observability/OtlpEndpointCheck.ts";
6063
import * as PairingGrantStore from "./auth/PairingGrantStore.ts";
64+
import * as RpcAuthorization from "./auth/RpcAuthorization.ts";
6165
import * as PeerLinkRequests from "./peer/PeerLinkRequests.ts";
6266
import * as PeerLinks from "./peer/PeerLinks.ts";
6367
import * as PortScanner from "./preview/PortScanner.ts";
@@ -1035,6 +1039,73 @@ it.effect("on-demand clients get provider config without workspace snapshots", (
10351039
),
10361040
);
10371041

1042+
it.effect("a git action that fails partway still refreshes the repository status", () =>
1043+
Effect.gen(function* () {
1044+
const failure = new GitManagerError({ operation: "test", cwd: "/repo", detail: "push failed" });
1045+
const refreshed = yield* Deferred.make<string>();
1046+
const exits = yield* Queue.unbounded<string>();
1047+
const services = Layer.mergeAll(
1048+
layerUnusedConfigRpcServices,
1049+
Layer.mock(GitWorkflowService.GitWorkflowService)({
1050+
runStackedAction: () => Effect.fail(failure),
1051+
}),
1052+
Layer.mock(VcsStatusBroadcaster.VcsStatusBroadcaster)({
1053+
refreshStatus: (cwd) =>
1054+
Deferred.succeed(refreshed, cwd).pipe(Effect.andThen(Effect.fail(failure))),
1055+
}),
1056+
Layer.mock(ExternalLauncher.ExternalLauncher)({}),
1057+
Layer.mock(ProviderRegistry.ProviderRegistry)({}),
1058+
Layer.mock(UsageLimitSources.UsageLimitSources)({}),
1059+
Layer.mock(RemoteOpenTargets.RemoteOpenTargets)({}),
1060+
Layer.mock(DirectEndpoints.DirectEndpoints)({}),
1061+
Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({ namedProjectsRoot: "/unused" }),
1062+
Layer.mock(ScratchThreadPromotion.ScratchThreadPromotion)({}),
1063+
Layer.mock(ServerEnvironment.ServerEnvironment)({}),
1064+
Layer.mock(EnvironmentAuth.EnvironmentAuth)({}),
1065+
);
1066+
const server = yield* RpcServer.makeNoSerialization(WsRpcGroup, {
1067+
...WS_RPC_SERVER_OPTIONS,
1068+
onFromServer: (response) =>
1069+
response._tag === "Exit" ? Queue.offer(exits, response.exit._tag) : Effect.void,
1070+
}).pipe(
1071+
Effect.provide(
1072+
layerWsRpc(
1073+
{
1074+
sessionId: AuthSessionId.make("git-test"),
1075+
subject: "git-test",
1076+
method: "browser-session-cookie",
1077+
scopes: [AuthSourceControlWriteScope],
1078+
},
1079+
{},
1080+
yield* ServerBrowser.ServerBrowser,
1081+
() => Effect.void,
1082+
).pipe(
1083+
Layer.provide(services),
1084+
Layer.merge(RpcAuthorization.layer([AuthSourceControlWriteScope])),
1085+
),
1086+
),
1087+
);
1088+
yield* server.write(0, {
1089+
_tag: "Request",
1090+
id: RpcMessage.RequestId("git"),
1091+
tag: WS_METHODS.gitRunStackedAction,
1092+
payload: { actionId: "action", cwd: "/repo", action: "commit_push" },
1093+
headers: Headers.empty,
1094+
});
1095+
assert.equal(yield* Queue.take(exits), "Failure");
1096+
assert.equal(yield* Deferred.await(refreshed), "/repo");
1097+
}).pipe(
1098+
Effect.provide(
1099+
Layer.mergeAll(
1100+
Layer.fresh(layerConfigSources),
1101+
Layer.mock(PreviewAutomationBroker.PreviewAutomationBroker)({}),
1102+
Layer.mock(ServerBrowser.ServerBrowser)({}),
1103+
),
1104+
),
1105+
Effect.scoped,
1106+
),
1107+
);
1108+
10381109
// Compaction keeps the oldest and newest event per message, so a cursor older
10391110
// than the deleted rows still replays each message where the client would
10401111
// first have seen it (reducers append on first sight) and reaches the same

‎apps/server/src/ws.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,9 @@ export const layerWsRpc = (
30313031
})
30323032
.pipe(
30333033
Effect.matchCauseEffect({
3034-
onFailure: (cause) => Queue.failCause(queue, cause),
3034+
// Earlier steps (branch, commit) may have landed before the failing one.
3035+
onFailure: (cause) =>
3036+
refreshGitStatus(input.cwd).pipe(Effect.andThen(Queue.failCause(queue, cause))),
30353037
onSuccess: (result) =>
30363038
(input.threadId === undefined
30373039
? Effect.void

0 commit comments

Comments
 (0)