Skip to content

Commit f2931a7

Browse files
test(server): verify missing workspace diagnostics across session paths
1 parent 0416d48 commit f2931a7

4 files changed

Lines changed: 127 additions & 8 deletions

File tree

‎apps/server/integration/providerService.integration.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ const makeIntegrationFixture = (options?: { readonly analytics?: Layer.Layer<Ana
100100
Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers),
101101
).pipe(Layer.provide(SqlitePersistenceMemory));
102102

103-
const layer = makeProviderServiceLive().pipe(Layer.provide(shared));
103+
const layer = makeProviderServiceLive().pipe(
104+
Layer.provide(NodeServices.layer),
105+
Layer.provide(shared),
106+
);
104107

105108
return {
106109
cwd,

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
3939

4040
import { deriveServerPaths, ServerConfig } from "../../config.ts";
4141
import { TextGenerationError } from "@t3tools/contracts";
42-
import { ProviderAdapterRequestError } from "../../provider/Errors.ts";
42+
import {
43+
ProviderAdapterRequestError,
44+
ProviderWorkspaceMissingError,
45+
type ProviderServiceError,
46+
} from "../../provider/Errors.ts";
4347
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
4448
import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
4549
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
@@ -181,7 +185,7 @@ describe("ProviderCommandReactor", () => {
181185
readonly stopSessionEffect?: () => Effect.Effect<void, ProviderAdapterRequestError>;
182186
readonly startSessionEffect?: (
183187
session: ProviderSession,
184-
) => Effect.Effect<ProviderSession, ProviderAdapterRequestError>;
188+
) => Effect.Effect<ProviderSession, ProviderServiceError>;
185189
readonly tryHandlePromptCommandEffect?: ProviderAuthService["Service"]["tryHandlePromptCommand"];
186190
}) {
187191
const now = "2026-01-01T00:00:00.000Z";
@@ -1217,6 +1221,58 @@ describe("ProviderCommandReactor", () => {
12171221
}),
12181222
);
12191223

1224+
effectIt.effect("shows the missing workspace message without a provider stack trace", () =>
1225+
Effect.gen(function* () {
1226+
const attempted = yield* Deferred.make<void>();
1227+
const missingCwd = "/missing/project/worktree";
1228+
const missingWorkspace = new ProviderWorkspaceMissingError({
1229+
threadId: ThreadId.make("thread-1"),
1230+
cwd: missingCwd,
1231+
});
1232+
const harness = yield* Effect.promise(() =>
1233+
createHarness({
1234+
startSessionEffect: () =>
1235+
Deferred.succeed(attempted, undefined).pipe(
1236+
Effect.andThen(Effect.fail(missingWorkspace)),
1237+
),
1238+
}),
1239+
);
1240+
1241+
yield* harness.engine.dispatch({
1242+
type: "thread.turn.start",
1243+
commandId: CommandId.make("cmd-turn-start-missing-workspace"),
1244+
threadId: ThreadId.make("thread-1"),
1245+
message: {
1246+
messageId: asMessageId("user-message-missing-workspace"),
1247+
role: "user",
1248+
text: "continue",
1249+
attachments: [],
1250+
},
1251+
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
1252+
runtimeMode: "approval-required",
1253+
createdAt: "2026-01-01T00:00:00.000Z",
1254+
});
1255+
yield* Deferred.await(attempted);
1256+
yield* Effect.promise(() => harness.drain());
1257+
1258+
const thread = (yield* Effect.promise(() => harness.readModel())).threads.find(
1259+
(entry) => entry.id === ThreadId.make("thread-1"),
1260+
);
1261+
expect(thread?.session).toMatchObject({
1262+
status: "error",
1263+
activeTurnId: null,
1264+
lastError: missingWorkspace.message,
1265+
});
1266+
const failure = thread?.activities.find(
1267+
(activity) => activity.kind === "provider.turn.start.failed",
1268+
);
1269+
expect(failure?.payload).toMatchObject({ detail: missingWorkspace.message });
1270+
expect(harness.runtimeSessions).toEqual([]);
1271+
expect(harness.sendTurn).not.toHaveBeenCalled();
1272+
expect(yield* Effect.promise(() => harness.readPendingTurnStarts())).toEqual([]);
1273+
}),
1274+
);
1275+
12201276
effectIt.effect("settles a failed provider startup and allows a clean retry", () =>
12211277
Effect.gen(function* () {
12221278
let failStartup = true;

‎apps/server/src/provider/Errors.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class ProviderWorkspaceMissingError extends Schema.TaggedErrorClass<Provi
9797
},
9898
) {
9999
override get message(): string {
100-
return `This thread's workspace folder no longer exists: ${this.cwd}. Move the folder back to this path, or add the project again from its new location.`;
100+
return `This thread's workspace folder no longer exists or is not a directory: ${this.cwd}. Restore the folder at this path before retrying.`;
101101
}
102102
}
103103

‎apps/server/src/provider/Layers/ProviderService.test.ts‎

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from "@t3tools/shared/assistantCitations";
3333
import { createModelSelection } from "@t3tools/shared/model";
3434
import { it, assert, describe, vi } from "@effect/vitest";
35+
import { afterAll } from "vite-plus/test";
3536

3637
import * as Cause from "effect/Cause";
3738
import * as Deferred from "effect/Deferred";
@@ -83,6 +84,7 @@ const serverConfigTestLayer = ServerConfig.layerTest(process.cwd(), process.cwd(
8384
// startSession verifies the workspace folder exists before dispatching to an
8485
// adapter, so session cwd fixtures must be real directories.
8586
const fixtureCwdRoot = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "provider-service-test-"));
87+
afterAll(() => NodeFS.rmSync(fixtureCwdRoot, { recursive: true, force: true }));
8688
function fixtureCwd(name: string): string {
8789
const dir = NodePath.join(fixtureCwdRoot, name);
8890
NodeFS.mkdirSync(dir, { recursive: true });
@@ -488,6 +490,7 @@ for (const [enabled, completed] of [
488490
const scope = yield* Scope.make();
489491
const services = yield* Layer.build(
490492
makeProviderServiceLive().pipe(
493+
Layer.provide(NodeServices.layer),
491494
Layer.provide(
492495
Layer.succeed(ProviderSessionDirectory.ProviderSessionDirectory, directory),
493496
),
@@ -650,6 +653,7 @@ it.effect("ProviderServiceLive flushes deferred completions during shutdown", ()
650653
const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
651654
const providerLayer = Layer.mergeAll(
652655
makeProviderServiceLive().pipe(
656+
Layer.provide(NodeServices.layer),
653657
Layer.provide(providerAdapterLayer),
654658
Layer.provide(directoryLayer),
655659
Layer.provide(defaultServerSettingsLayer),
@@ -1059,7 +1063,7 @@ unsupportedRollback.layer("ProviderServiceLive unsupported rewind", (it) => {
10591063
yield* provider.startSession(threadId, {
10601064
providerInstanceId: codexInstanceId,
10611065
threadId,
1062-
cwd: "/tmp/project",
1066+
cwd: fixtureCwd("project"),
10631067
runtimeMode: "approval-required",
10641068
});
10651069
if (!active) {
@@ -1113,6 +1117,7 @@ it.effect(
11131117
Layer.provide(runtimeRepositoryLayer),
11141118
);
11151119
const providerLayer = makeProviderServiceLive().pipe(
1120+
Layer.provide(NodeServices.layer),
11161121
Layer.provide(Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, registry)),
11171122
Layer.provide(directoryLayer),
11181123
Layer.provide(defaultServerSettingsLayer),
@@ -1412,6 +1417,61 @@ it.effect(
14121417
);
14131418

14141419
routing.layer("ProviderServiceLive routing", (it) => {
1420+
it.effect.each([CODEX_DRIVER, CLAUDE_AGENT_DRIVER, CURSOR_DRIVER])(
1421+
"rejects missing, file, and saved workspace paths before starting %s",
1422+
(driver) =>
1423+
Effect.gen(function* () {
1424+
const provider = yield* ProviderService.ProviderService;
1425+
const adapter =
1426+
driver === CODEX_DRIVER
1427+
? routing.codex
1428+
: driver === CLAUDE_AGENT_DRIVER
1429+
? routing.claude
1430+
: routing.cursor;
1431+
const cwd = fixtureCwd(`missing-workspace-${driver}`);
1432+
const movedCwd = `${cwd}-moved`;
1433+
const threadId = asThreadId(`missing-workspace-${driver}`);
1434+
const input = {
1435+
provider: driver,
1436+
providerInstanceId: ProviderInstanceId.make(driver),
1437+
threadId,
1438+
runtimeMode: "full-access" as const,
1439+
cwd,
1440+
};
1441+
1442+
yield* provider.startSession(threadId, input);
1443+
yield* provider.stopSession({ threadId });
1444+
adapter.startSession.mockClear();
1445+
NodeFS.renameSync(cwd, movedCwd);
1446+
1447+
const failure = yield* provider.startSession(threadId, input).pipe(Effect.flip);
1448+
assert.instanceOf(failure, ProviderWorkspaceMissingError);
1449+
assert.include(failure.message, cwd);
1450+
assert.equal(adapter.startSession.mock.calls.length, 0);
1451+
1452+
const { cwd: _cwd, ...savedInput } = input;
1453+
const savedFailure = yield* provider.startSession(threadId, savedInput).pipe(Effect.flip);
1454+
assert.instanceOf(savedFailure, ProviderWorkspaceMissingError);
1455+
assert.include(savedFailure.message, cwd);
1456+
assert.equal(adapter.startSession.mock.calls.length, 0);
1457+
1458+
NodeFS.writeFileSync(cwd, "not a directory");
1459+
const fileFailure = yield* provider.startSession(threadId, input).pipe(Effect.flip);
1460+
assert.instanceOf(fileFailure, ProviderWorkspaceMissingError);
1461+
assert.include(fileFailure.message, cwd);
1462+
assert.equal(adapter.startSession.mock.calls.length, 0);
1463+
1464+
NodeFS.unlinkSync(cwd);
1465+
NodeFS.renameSync(movedCwd, cwd);
1466+
const restored = yield* provider.startSession(threadId, savedInput);
1467+
assert.equal(restored.cwd, cwd);
1468+
assert.equal(adapter.startSession.mock.calls.length, 1);
1469+
yield* provider.stopSession({ threadId });
1470+
adapter.startSession.mockClear();
1471+
adapter.stopSession.mockClear();
1472+
}),
1473+
);
1474+
14151475
it.effect("allows promptless continuation only for capable providers", () =>
14161476
Effect.gen(function* () {
14171477
const provider = yield* ProviderService.ProviderService;
@@ -1817,7 +1877,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
18171877
provider: CODEX_DRIVER,
18181878
providerInstanceId: codexInstanceId,
18191879
threadId,
1820-
cwd: "/tmp/feedback-project",
1880+
cwd: fixtureCwd("feedback-project"),
18211881
runtimeMode: "full-access",
18221882
});
18231883
yield* routing.codex.stopSession(threadId);
@@ -1880,7 +1940,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
18801940
provider: ProviderDriverKind.make("codex"),
18811941
providerInstanceId: codexInstanceId,
18821942
threadId: asThreadId("thread-attach"),
1883-
cwd: "/tmp/project",
1943+
cwd: fixtureCwd("project"),
18841944
runtimeMode: "full-access",
18851945
});
18861946

@@ -4226,7 +4286,7 @@ boundedListing.layer("ProviderServiceLive session listing", (it) => {
42264286
provider: CODEX_DRIVER,
42274287
providerInstanceId: codexInstanceId,
42284288
threadId: activeSessionThreadId,
4229-
cwd: "/tmp/project-active-session",
4289+
cwd: fixtureCwd("project-active-session"),
42304290
runtimeMode: "full-access",
42314291
});
42324292
listThreadIds.mockClear();

0 commit comments

Comments
 (0)