Skip to content

Commit 37f9134

Browse files
saphidclaudemaria-rcks
authored
fix(server): a publish whose first push fails still shows the new remote (pingdotgg#29688)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent cedaa0d commit 37f9134

2 files changed

Lines changed: 98 additions & 2 deletions

File tree

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
44
import { assert, it } from "@effect/vitest";
55
import {
66
AuthSessionId,
7+
AuthSourceControlWriteScope,
78
EnvironmentId,
89
ProjectId,
910
ThreadId,
1011
ProviderDriverKind,
1112
ProviderInstanceId,
13+
SourceControlRepositoryError,
1214
WS_METHODS,
15+
WsRpcGroup,
1316
WsServerRefreshProvidersRpc,
1417
WsSubscribeServerConfigRpc,
1518
type OrchestrationV2StoredEvent,
@@ -63,6 +66,7 @@ import * as ModelManifest from "./provider/ModelManifest.ts";
6366
import * as Orchestrator from "./orchestration-v2/Orchestrator.ts";
6467
import * as OtlpEndpointCheck from "./observability/OtlpEndpointCheck.ts";
6568
import * as PairingGrantStore from "./auth/PairingGrantStore.ts";
69+
import * as RpcAuthorization from "./auth/RpcAuthorization.ts";
6670
import * as PeerLinkRequests from "./peer/PeerLinkRequests.ts";
6771
import * as PeerLinks from "./peer/PeerLinks.ts";
6872
import * as PortScanner from "./preview/PortScanner.ts";
@@ -1240,6 +1244,94 @@ it.effect("on-demand clients get provider config without workspace snapshots", (
12401244
),
12411245
);
12421246

1247+
it.effect("a publish whose push fails still refreshes the new remote", () =>
1248+
Effect.gen(function* () {
1249+
const refreshes = yield* Queue.unbounded<string>();
1250+
const exits = yield* Queue.unbounded<string>();
1251+
const services = Layer.mergeAll(
1252+
layerUnusedConfigRpcServices,
1253+
Layer.mock(SourceControlRepositoryService.SourceControlRepositoryService)({
1254+
publishRepository: (input) =>
1255+
Effect.fail(
1256+
new SourceControlRepositoryError({
1257+
provider: input.provider,
1258+
operation: "publishRepository",
1259+
detail: 'Created owner/repo and added it as remote "origin", but the push failed.',
1260+
}),
1261+
),
1262+
}),
1263+
Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({
1264+
resolve: (cwd, options) =>
1265+
Queue.offer(refreshes, `identity ${cwd} refresh=${options?.refresh === true}`).pipe(
1266+
Effect.as(null),
1267+
),
1268+
}),
1269+
Layer.mock(VcsStatusBroadcaster.VcsStatusBroadcaster)({
1270+
refreshStatus: (cwd) =>
1271+
Queue.offer(refreshes, `status ${cwd}`).pipe(Effect.andThen(Effect.die("unused"))),
1272+
}),
1273+
Layer.mock(ExternalLauncher.ExternalLauncher)({}),
1274+
Layer.mock(ProviderRegistry.ProviderRegistry)({}),
1275+
Layer.mock(UsageLimitSources.UsageLimitSources)({}),
1276+
Layer.mock(RemoteOpenTargets.RemoteOpenTargets)({}),
1277+
Layer.mock(DirectEndpoints.DirectEndpoints)({}),
1278+
Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({ namedProjectsRoot: "/unused" }),
1279+
Layer.mock(ScratchThreadPromotion.ScratchThreadPromotion)({}),
1280+
Layer.mock(ServerEnvironment.ServerEnvironment)({}),
1281+
Layer.mock(EnvironmentAuth.EnvironmentAuth)({}),
1282+
);
1283+
const server = yield* RpcServer.makeNoSerialization(WsRpcGroup, {
1284+
...WS_RPC_SERVER_OPTIONS,
1285+
onFromServer: (response) =>
1286+
response._tag === "Exit" ? Queue.offer(exits, response.exit._tag) : Effect.void,
1287+
}).pipe(
1288+
Effect.provide(
1289+
layerWsRpc(
1290+
{
1291+
sessionId: AuthSessionId.make("publish-test"),
1292+
subject: "publish-test",
1293+
method: "browser-session-cookie",
1294+
scopes: [AuthSourceControlWriteScope],
1295+
},
1296+
{},
1297+
yield* ServerBrowser.ServerBrowser,
1298+
() => Effect.void,
1299+
{ secretReferences: true },
1300+
).pipe(
1301+
Layer.provide(services),
1302+
Layer.merge(RpcAuthorization.layer([AuthSourceControlWriteScope])),
1303+
),
1304+
),
1305+
);
1306+
yield* server.write(0, {
1307+
_tag: "Request",
1308+
id: RpcMessage.RequestId("publish"),
1309+
tag: WS_METHODS.sourceControlPublishRepository,
1310+
payload: {
1311+
cwd: "/repo",
1312+
provider: "github",
1313+
repository: "owner/repo",
1314+
visibility: "private",
1315+
},
1316+
headers: Headers.empty,
1317+
});
1318+
assert.equal(yield* Queue.take(exits), "Failure");
1319+
assert.deepEqual(
1320+
[yield* Queue.take(refreshes), yield* Queue.take(refreshes)],
1321+
["identity /repo refresh=true", "status /repo"],
1322+
);
1323+
}).pipe(
1324+
Effect.provide(
1325+
Layer.mergeAll(
1326+
Layer.fresh(layerConfigSources),
1327+
Layer.mock(PreviewAutomationBroker.PreviewAutomationBroker)({}),
1328+
Layer.mock(ServerBrowser.ServerBrowser)({}),
1329+
),
1330+
),
1331+
Effect.scoped,
1332+
),
1333+
);
1334+
12431335
// Pruned history cannot be replayed: a cursor below the boundary must resync from a snapshot.
12441336
it.effect.each(["thread", "shell"] as const)(
12451337
"%s resume from a cursor below the pruned boundary loads a snapshot",

‎apps/server/src/ws.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,8 +2921,12 @@ export const layerWsRpc = (
29212921
[WS_METHODS.subscribeProjectClones]: () => projectCloneTracker.stream,
29222922
[WS_METHODS.sourceControlPublishRepository]: (input) =>
29232923
sourceControlRepositories.publishRepository(input).pipe(
2924-
Effect.tap(() => repositoryIdentityResolver.resolve(input.cwd, { refresh: true })),
2925-
Effect.tap(() => refreshGitStatus(input.cwd)),
2924+
// A failed push still leaves the new remote added.
2925+
Effect.ensuring(
2926+
repositoryIdentityResolver
2927+
.resolve(input.cwd, { refresh: true })
2928+
.pipe(Effect.andThen(refreshGitStatus(input.cwd))),
2929+
),
29262930
),
29272931
[WS_METHODS.projectsSearchEntries]: (input) =>
29282932
workspaceEntries.search(input).pipe(

0 commit comments

Comments
 (0)