Skip to content

Commit 498688d

Browse files
only21milclaude
andcommitted
fix(server): a symlink add or open says which project owns the folder
The workspace conflict this branch adds reached clients as "Failed to mutate project.". The WebSocket handler now passes ProjectConflictError's message through, as it already does for ProjectNotEmptyError. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4b3a523 commit 498688d

3 files changed

Lines changed: 78 additions & 2 deletions

File tree

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { assert, it } from "@effect/vitest";
33
import {
44
AuthSessionId,
5+
CommandId,
56
EnvironmentId,
67
ProjectId,
78
ThreadId,
89
WS_METHODS,
10+
WsProjectsMutateRpc,
911
WsSubscribeServerConfigRpc,
1012
type OrchestrationV2StoredEvent,
1113
type OrchestrationProjectShell,
@@ -14,6 +16,7 @@ import {
1416
} from "@t3tools/contracts";
1517
import * as Deferred from "effect/Deferred";
1618
import * as Effect from "effect/Effect";
19+
import * as Exit from "effect/Exit";
1720
import * as Layer from "effect/Layer";
1821
import * as PubSub from "effect/PubSub";
1922
import * as Queue from "effect/Queue";
@@ -536,6 +539,79 @@ it.effect(
536539
),
537540
);
538541

542+
it.effect("projects.mutate tells the client which project already owns the folder", () =>
543+
Effect.gen(function* () {
544+
const conflict = new ProjectService.ProjectConflictError({
545+
projectId: ProjectId.make("project:alias"),
546+
workspaceRoot: "/srv/link/app",
547+
conflictingProjectId: ProjectId.make("project:owner"),
548+
});
549+
const exits = yield* Queue.unbounded<Exit.Exit<unknown, unknown>>();
550+
const mutateRpcServices = Layer.mergeAll(
551+
layerUnusedConfigRpcServices,
552+
Layer.mock(ProjectService.ProjectService)({ create: () => Effect.fail(conflict) }),
553+
Layer.mock(ServerRuntimeStartup.ServerRuntimeStartup)({ enqueueCommand: (effect) => effect }),
554+
Layer.mock(ExternalLauncher.ExternalLauncher)({}),
555+
Layer.mock(ProviderRegistry.ProviderRegistry)({}),
556+
Layer.mock(UsageLimitSources.UsageLimitSources)({}),
557+
Layer.mock(RemoteOpenTargets.RemoteOpenTargets)({}),
558+
Layer.mock(DirectEndpoints.DirectEndpoints)({}),
559+
Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({ namedProjectsRoot: "/unused" }),
560+
Layer.mock(ServerEnvironment.ServerEnvironment)({}),
561+
Layer.mock(EnvironmentAuth.EnvironmentAuth)({}),
562+
);
563+
const server = yield* RpcServer.makeNoSerialization(RpcGroup.make(WsProjectsMutateRpc), {
564+
...WS_RPC_SERVER_OPTIONS,
565+
onFromServer: (response) =>
566+
response._tag === "Exit" ? Queue.offer(exits, response.exit) : Effect.void,
567+
}).pipe(
568+
Effect.provide(
569+
layerWsRpc(
570+
{
571+
sessionId: AuthSessionId.make("mutate-test"),
572+
subject: "mutate-test",
573+
method: "browser-session-cookie",
574+
scopes: [],
575+
},
576+
{},
577+
{},
578+
yield* PreviewAutomationBroker.PreviewAutomationBroker,
579+
yield* ServerBrowser.ServerBrowser,
580+
).pipe(Layer.provide(mutateRpcServices)),
581+
),
582+
);
583+
yield* server.write(0, {
584+
_tag: "Request",
585+
id: RpcMessage.RequestId("mutate"),
586+
tag: WS_METHODS.projectsMutate,
587+
payload: {
588+
type: "project.create",
589+
commandId: CommandId.make("command:project:alias"),
590+
projectId: conflict.projectId,
591+
title: "app",
592+
workspaceRoot: conflict.workspaceRoot,
593+
},
594+
headers: Headers.empty,
595+
});
596+
const exit = yield* Queue.take(exits);
597+
assert.isTrue(Exit.isFailure(exit));
598+
if (!Exit.isFailure(exit)) return;
599+
const [error] = exit.cause.reasons.flatMap((reason) =>
600+
reason._tag === "Fail" ? [reason.error] : [],
601+
);
602+
assert.equal((error as { message?: unknown } | undefined)?.message, conflict.message);
603+
}).pipe(
604+
Effect.provide(
605+
Layer.mergeAll(
606+
Layer.fresh(layerConfigSources),
607+
Layer.mock(PreviewAutomationBroker.PreviewAutomationBroker)({}),
608+
Layer.mock(ServerBrowser.ServerBrowser)({}),
609+
),
610+
),
611+
Effect.scoped,
612+
),
613+
);
614+
539615
// Compaction keeps the oldest and newest event per message, so a cursor older
540616
// than the deleted rows still replays each message where the client would
541617
// first have seen it (reducers append on first sight) and reaches the same

‎apps/server/src/ws.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ export const layerWsRpc = (
27402740
new ProjectMutationError({
27412741
commandId: mutation.commandId,
27422742
message:
2743-
cause._tag === "ProjectNotEmptyError"
2743+
cause._tag === "ProjectNotEmptyError" || cause._tag === "ProjectConflictError"
27442744
? cause.message
27452745
: "Failed to mutate project.",
27462746
cause,

‎packages/contracts/src/rpc.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ const WsProjectsWriteFileRpc = Rpc.make(WS_METHODS.projectsWriteFile, {
12491249
error: Schema.Union([ProjectWriteFileError, EnvironmentAuthorizationError]),
12501250
});
12511251

1252-
const WsProjectsMutateRpc = Rpc.make(WS_METHODS.projectsMutate, {
1252+
export const WsProjectsMutateRpc = Rpc.make(WS_METHODS.projectsMutate, {
12531253
payload: ProjectMutation,
12541254
success: Project,
12551255
error: Schema.Union([ProjectMutationError, EnvironmentAuthorizationError]),

0 commit comments

Comments
 (0)