Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2import {
3 ProviderDriverKind,
4 ProviderInstanceId,
5 ProviderSessionId,
6 ProviderSetupError,
7 ProviderThreadId,
8 ThreadId,
9 type OrchestrationV2ProviderSession,
10 type OrchestrationV2ThreadShell,
11 type ProviderAuthState,
12} from "@t3tools/contracts";
13import * as DateTime from "effect/DateTime";
14import * as Effect from "effect/Effect";
15import * as Deferred from "effect/Deferred";
16import * as Fiber from "effect/Fiber";
17import * as Layer from "effect/Layer";
18import * as PubSub from "effect/PubSub";
19import * as Queue from "effect/Queue";
20import * as Stream from "effect/Stream";
21import * as SubscriptionRef from "effect/SubscriptionRef";
22
23import {
24 ProjectionStoreReadError,
25 ProjectionStoreV2,
26} from "../../orchestration-v2/ProjectionStore.ts";
27import {
28 ProviderSessionManagerV2,
29 ProviderSessionReleaseError,
30} from "../../orchestration-v2/ProviderSessionManager.ts";
31import { AcpProviderCapabilitiesV2 } from "../../orchestration-v2/Adapters/AcpAdapterV2.ts";
32import type { ProviderInstance } from "../ProviderDriver.ts";
33import type { ProviderAuthController } from "../Services/ProviderAuthService.ts";
34import { ProviderInstanceRegistry } from "../Services/ProviderInstanceRegistry.ts";
35import { makeProviderAuthService } from "./ProviderAuthService.ts";
36
37const instanceId = ProviderInstanceId.make("antigravity-personal");
38const otherInstanceId = ProviderInstanceId.make("antigravity-work");
39const unsupportedInstanceId = ProviderInstanceId.make("codex");
40const driverKind = ProviderDriverKind.make("antigravity");
41const owner = "paired-client-owner";
42const otherOwner = "paired-client-other";
43const flowId = "test-sign-in-flow";
44const callbackUrl = "http://127.0.0.1:48123/?state=test-state&code=test-code";
45const now = "2026-09-02T00:00:00.000Z";
46const idleAuthState: ProviderAuthState = {
47 instanceId,
48 phase: "idle",
49 flowId: null,
50 authorizationUrl: null,
51 expiresAt: null,
52 message: null,
53};
54const waitingAuthState: ProviderAuthState = {
55 ...idleAuthState,
56 phase: "waiting",
57 flowId,
58 authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth?state=test-state",
59 expiresAt: "2026-09-02T00:05:00.000Z",
60};
61
62function makeInstance(input: {
63 instanceId: ProviderInstanceId;
64 enabled: boolean;
65 auth?: ProviderAuthController;
66}): ProviderInstance {
67 return {
68 ...input,
69 driverKind,
70 displayName: undefined,
71 continuationIdentity: { driverKind, continuationKey: input.instanceId },
72 get snapshot(): never {
73 throw new Error("Auth routing must not refresh the provider snapshot.");
74 },
75 get orchestrationAdapter(): never {
76 throw new Error("Auth routing must not start an adapter session.");
77 },
78 get textGeneration(): never {
79 throw new Error("Auth routing must not generate text.");
80 },
81 };
82}
83
84const nowUtc = DateTime.makeUnsafe(now);
85
86/**
87 * A thread bound to a provider instance with (or without) a live native
88 * thread. The auth service reads only the routing fields, so the rest of the
89 * shell row is left out.
90 */
91function makeThread(
92 thread: string,
93 input: { readonly providerInstanceId?: ProviderInstanceId; readonly active?: boolean } = {},
94): OrchestrationV2ThreadShell {
95 const shell: Pick<
96 OrchestrationV2ThreadShell,
97 "id" | "providerInstanceId" | "activeProviderThreadId"
98 > = {
99 id: ThreadId.make(thread),
100 providerInstanceId: input.providerInstanceId ?? instanceId,
101 activeProviderThreadId:
102 input.active === false ? null : ProviderThreadId.make(`${thread}:native`),
103 };
104 return shell as unknown as OrchestrationV2ThreadShell;
105}
106
107function makeSession(
108 session: string,
109 status: OrchestrationV2ProviderSession["status"] = "ready",
110 providerInstanceId = instanceId,
111): OrchestrationV2ProviderSession {
112 return {
113 id: ProviderSessionId.make(session),
114 driver: driverKind,
115 providerInstanceId,
116 status,
117 cwd: "/workspace",
118 model: null,
119 capabilities: AcpProviderCapabilitiesV2,
120 createdAt: nowUtc,
121 updatedAt: nowUtc,
122 lastError: null,
123 };
124}
125
126const makeHarness = Effect.fn("ProviderAuthService.test.makeHarness")(function* (
127 input: {
128 enabled?: boolean;
129 threads?: ReadonlyArray<OrchestrationV2ThreadShell>;
130 sessions?: ReadonlyMap<ThreadId, ReadonlyArray<OrchestrationV2ProviderSession>>;
131 shellError?: boolean;
132 stopError?: boolean;
133 logoutError?: ProviderSetupError;
134 } = {},
135) {
136 const actions: string[] = [];
137 const registryChanges = yield* PubSub.unbounded<void>();
138 const threads = input.threads ?? [];
139 const sessions = new Map(
140 [...(input.sessions?.entries() ?? [])].map(([threadId, list]) => [threadId, [...list]]),
141 );
142 const released: string[] = [];
143 const idle = idleAuthState;
144 let state = idle;
145 let flowOwner: string | undefined;
146 let gateClosed = false;
147
148 const checkOwner = Effect.fn("ProviderAuthService.test.checkOwner")(function* (
149 ownerSessionId: string,
150 requestedFlowId: string,
151 operation: string,
152 ) {
153 if (ownerSessionId !== flowOwner || requestedFlowId !== state.flowId) {
154 return yield* new ProviderSetupError({
155 instanceId,
156 operation,
157 detail: "This sign-in belongs to another client or has expired.",
158 });
159 }
160 });
161
162 const auth: ProviderAuthController = {
163 start: Effect.fn(function* (ownerSessionId, stopSessions) {
164 gateClosed = true;
165 actions.push("close-gate");
166 yield* stopSessions ?? Effect.void;
167 flowOwner = ownerSessionId;
168 state = waitingAuthState;
169 actions.push("start-sign-in");
170 return state;
171 }),
172 complete: Effect.fn(function* (ownerSessionId, request) {
173 yield* checkOwner(ownerSessionId, request.flowId, "complete");
174 if (request.callbackUrl !== callbackUrl) {
175 return yield* new ProviderSetupError({
176 instanceId,
177 operation: "complete",
178 detail: "The redirect URL does not match this sign-in.",
179 });
180 }
181 state = { ...idle, flowId, phase: "succeeded" };
182 return state;
183 }),
184 cancel: Effect.fn(function* (ownerSessionId, requestedFlowId) {
185 yield* checkOwner(ownerSessionId, requestedFlowId, "cancel");
186 state = { ...idle, flowId, phase: "cancelled" };
187 return state;
188 }),
189 logout: Effect.fn(function* (stopSessions) {
190 gateClosed = true;
191 actions.push("close-gate");
192 yield* stopSessions;
193 if (input.logoutError) return yield* input.logoutError;
194 actions.push("native-logout");
195 state = idle;
196 flowOwner = undefined;
197 return state;
198 }),
199 subscribe: (ownerSessionId) =>
200 Stream.fromEffect(Effect.sync(() => (ownerSessionId === flowOwner ? state : idle))),
201 isLogoutPrompt: (text, hasAttachments) => !hasAttachments && text.trim() === "/logout",
202 };
203 const instances = [
204 makeInstance({ instanceId, enabled: input.enabled ?? true, auth }),
205 makeInstance({ instanceId: unsupportedInstanceId, enabled: true }),
206 ];
207 const service = yield* makeProviderAuthService.pipe(
208 Effect.provide(
209 Layer.mergeAll(
210 Layer.mock(ProviderInstanceRegistry)({
211 getInstance: (id) =>
212 Effect.succeed(instances.find((instance) => instance.instanceId === id)),
213 subscribeChanges: PubSub.subscribe(registryChanges),
214 }),
215 Layer.mock(ProjectionStoreV2)({
216 getRecoveryThreadIds: () =>
217 Effect.suspend(() => {
218 assert.isTrue(gateClosed);
219 actions.push("list-threads");
220 return input.shellError
221 ? Effect.fail(
222 new ProjectionStoreReadError({
223 threadId: ThreadId.make("shell"),
224 cause: new Error("private database diagnostics"),
225 }),
226 )
227 : Effect.succeed(threads.map((thread) => thread.id));
228 }),
229 getThreadProjection: (threadId) =>
230 Effect.sync(() => {
231 actions.push(`sessions:${threadId}`);
232 return {
233 providerSessions: sessions.get(threadId) ?? [],
234 } as never;
235 }),
236 }),
237 Layer.mock(ProviderSessionManagerV2)({
238 release: ({ providerSessionId, reason }) =>
239 Effect.suspend(() => {
240 assert.isTrue(gateClosed);
241 actions.push(`stop:${providerSessionId}`);
242 if (input.stopError) {
243 return Effect.fail(
244 new ProviderSessionReleaseError({
245 providerSessionId,
246 reason,
247 cause: new Error("private process diagnostics"),
248 }),
249 );
250 }
251 released.push(providerSessionId);
252 return Effect.void;
253 }),
254 }),
255 ),
256 ),
257 );
258 return { service, actions, released };
259});
260
261const makeStreamingController = Effect.fn("ProviderAuthService.test.makeStreamingController")(
262 function* (flowOwner: string) {
263 const state = yield* SubscriptionRef.make(idleAuthState);
264 const close = yield* Deferred.make<void>();
265 const closedSubscriptions = yield* Queue.unbounded<string>();
266 const unused = () => Effect.die("Unexpected auth operation in a subscription test.");
267 const auth: ProviderAuthController = {
268 start: unused,
269 complete: unused,
270 cancel: unused,
271 logout: unused,
272 subscribe: (ownerSessionId) =>
273 SubscriptionRef.changes(state).pipe(
274 Stream.map((current) => (ownerSessionId === flowOwner ? current : idleAuthState)),
275 Stream.interruptWhen(Deferred.await(close)),
276 Stream.ensuring(Queue.offer(closedSubscriptions, ownerSessionId)),
277 ),
278 };
279 return {
280 auth,
281 state,
282 closedSubscriptions,
283 close: Deferred.succeed(close, undefined),
284 };
285 },
286);
287
288const makeSubscriptionHarness = Effect.fn("ProviderAuthService.test.makeSubscriptionHarness")(
289 function* (initial: ProviderInstance, replaceDuringFirstLookup?: ProviderInstance) {
290 const changes = yield* PubSub.unbounded<void>();
291 let current: ProviderInstance | undefined = initial;
292 let pendingReplacement = replaceDuringFirstLookup;
293 let subscribed = false;
294 const service = yield* makeProviderAuthService.pipe(
295 Effect.provide(
296 Layer.mergeAll(
297 Layer.mock(ProviderInstanceRegistry)({
298 subscribeChanges: Effect.gen(function* () {
299 const subscription = yield* PubSub.subscribe(changes);
300 subscribed = true;
301 return subscription;
302 }),
303 getInstance: () =>
304 Effect.gen(function* () {
305 const instance = current;
306 if (pendingReplacement) {
307 assert.isTrue(subscribed, "Registry changes must be subscribed before lookup.");
308 current = pendingReplacement;
309 pendingReplacement = undefined;
310 yield* PubSub.publish(changes, undefined);
311 }
312 return instance;
313 }),
314 }),
315 Layer.mock(ProjectionStoreV2)({}),
316 Layer.mock(ProviderSessionManagerV2)({}),
317 ),
318 ),
319 );
320 return {
321 service,
322 replace: Effect.fn(function* (replacement: ProviderInstance | undefined) {
323 current = replacement;
324 yield* PubSub.publish(changes, undefined);
325 }),
326 };
327 },
328);
329
330const observeAuth = Effect.fn("ProviderAuthService.test.observeAuth")(function* (
331 stream: Stream.Stream<ProviderAuthState, ProviderSetupError>,
332) {
333 const states = yield* Queue.unbounded<ProviderAuthState>();
334 const fiber = yield* stream.pipe(
335 Stream.runForEach((state) => Queue.offer(states, state)),
336 Effect.forkScoped,
337 );
338 return { states, fiber };
339});
340
341describe("ProviderAuthService", () => {
342 it.effect("stops routed sessions before sign-in, including for a disabled instance", () =>
343 Effect.gen(function* () {
344 const { service, actions, released } = yield* makeHarness({
345 enabled: false,
346 threads: [makeThread("active")],
347 sessions: new Map([[ThreadId.make("active"), [makeSession("active-session")]]]),
348 });
349 const state = yield* service.start({ instanceId }, owner);
350
351 assert.strictEqual(state.instanceId, instanceId);
352 assert.strictEqual(state.phase, "waiting");
353 assert.deepStrictEqual(released, ["active-session"]);
354 assert.deepStrictEqual(actions, [
355 "close-gate",
356 "list-threads",
357 "sessions:active",
358 "stop:active-session",
359 "start-sign-in",
360 ]);
361 }),
362 );
363
364 it.effect("keeps sign-in state private and accepts the owner's redirect URL", () =>
365 Effect.gen(function* () {
366 const { service } = yield* makeHarness();
367 const waiting = yield* service.start({ instanceId }, owner);
368 const ownerStates = yield* service
369 .subscribe({ instanceId }, owner)
370 .pipe(Stream.take(1), Stream.runCollect);
371 const otherStates = yield* service
372 .subscribe({ instanceId }, otherOwner)
373 .pipe(Stream.take(1), Stream.runCollect);
374
375 assert.deepStrictEqual(ownerStates, [waiting]);
376 assert.strictEqual(otherStates[0]?.authorizationUrl, null);
377 assert.strictEqual(otherStates[0]?.flowId, null);
378
379 const otherError = yield* Effect.flip(
380 service.complete({ instanceId, flowId, callbackUrl }, otherOwner),
381 );
382 assert.strictEqual(otherError.operation, "complete");
383 const complete = yield* service.complete({ instanceId, flowId, callbackUrl }, owner);
384 assert.strictEqual(complete.phase, "succeeded");
385 assert.strictEqual(complete.authorizationUrl, null);
386 }),
387 );
388
389 it.effect("lets only the flow owner cancel sign-in", () =>
390 Effect.gen(function* () {
391 const { service } = yield* makeHarness();
392 yield* service.start({ instanceId }, owner);
393 const error = yield* Effect.flip(service.cancel({ instanceId, flowId }, otherOwner));
394 assert.strictEqual(error.operation, "cancel");
395
396 const cancelled = yield* service.cancel({ instanceId, flowId }, owner);
397 assert.strictEqual(cancelled.phase, "cancelled");
398 assert.strictEqual(cancelled.authorizationUrl, null);
399 }),
400 );
401
402 it.effect.each([
403 { change: "enable", initialEnabled: false, closeBeforeReplacement: true },
404 { change: "config", initialEnabled: true, closeBeforeReplacement: false },
405 ])(
406 "keeps private auth subscriptions current after an instance $change change",
407 ({ initialEnabled, closeBeforeReplacement }) =>
408 Effect.gen(function* () {
409 const first = yield* makeStreamingController(owner);
410 const replacement = yield* makeStreamingController(otherOwner);
411 yield* SubscriptionRef.set(first.state, waitingAuthState);
412 const { service, replace } = yield* makeSubscriptionHarness(
413 makeInstance({ instanceId, enabled: initialEnabled, auth: first.auth }),
414 );
415 const firstClient = yield* observeAuth(service.subscribe({ instanceId }, owner));
416 const secondClient = yield* observeAuth(service.subscribe({ instanceId }, otherOwner));
417 assert.deepStrictEqual(yield* Queue.take(firstClient.states), waitingAuthState);
418 assert.deepStrictEqual(yield* Queue.take(secondClient.states), idleAuthState);
419
420 if (closeBeforeReplacement) {
421 yield* first.close;
422 const closed = yield* Queue.takeN(first.closedSubscriptions, 2);
423 assert.deepStrictEqual(new Set(closed), new Set([owner, otherOwner]));
424 }
425 yield* replace(makeInstance({ instanceId, enabled: true, auth: replacement.auth }));
426 assert.deepStrictEqual(yield* Queue.take(firstClient.states), idleAuthState);
427 assert.deepStrictEqual(yield* Queue.take(secondClient.states), idleAuthState);
428 if (!closeBeforeReplacement) {
429 const closed = yield* Queue.takeN(first.closedSubscriptions, 2);
430 assert.deepStrictEqual(new Set(closed), new Set([owner, otherOwner]));
431 }
432
433 const staleState: ProviderAuthState = { ...idleAuthState, phase: "cancelled" };
434 yield* SubscriptionRef.set(first.state, staleState);
435 const newWaiting: ProviderAuthState = {
436 ...waitingAuthState,
437 flowId: "replacement-flow",
438 authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth?state=replacement-state",
439 };
440 yield* SubscriptionRef.set(replacement.state, newWaiting);
441 assert.deepStrictEqual(yield* Queue.take(firstClient.states), idleAuthState);
442 assert.deepStrictEqual(yield* Queue.take(secondClient.states), newWaiting);
443 }),
444 );
445
446 it.effect("does not miss a replacement during the first instance lookup", () =>
447 Effect.gen(function* () {
448 const first = yield* makeStreamingController(owner);
449 const replacement = yield* makeStreamingController(owner);
450 yield* SubscriptionRef.set(replacement.state, waitingAuthState);
451 const { service } = yield* makeSubscriptionHarness(
452 makeInstance({ instanceId, enabled: false, auth: first.auth }),
453 makeInstance({ instanceId, enabled: true, auth: replacement.auth }),
454 );
455
456 const states = yield* service.subscribe({ instanceId }, owner).pipe(
457 Stream.filter((state) => state.phase === "waiting"),
458 Stream.take(1),
459 Stream.runCollect,
460 );
461
462 assert.deepStrictEqual(states, [waitingAuthState]);
463 }),
464 );
465
466 it.effect("ends the subscription with a setup error when the instance is removed", () =>
467 Effect.gen(function* () {
468 const controller = yield* makeStreamingController(owner);
469 const { service, replace } = yield* makeSubscriptionHarness(
470 makeInstance({ instanceId, enabled: true, auth: controller.auth }),
471 );
472 const { states, fiber } = yield* observeAuth(service.subscribe({ instanceId }, owner));
473 assert.deepStrictEqual(yield* Queue.take(states), idleAuthState);
474
475 yield* replace(undefined);
476 const error = yield* Effect.flip(Fiber.join(fiber));
477
478 assert.instanceOf(error, ProviderSetupError);
479 assert.strictEqual(error.instanceId, instanceId);
480 assert.strictEqual(error.operation, "subscribe");
481 assert.include(error.detail, "no longer available");
482 assert.strictEqual(yield* Queue.take(controller.closedSubscriptions), owner);
483 }),
484 );
485
486 it.effect.each([
487 { id: ProviderInstanceId.make("missing"), detail: "no longer available" },
488 { id: unsupportedInstanceId, detail: "does not support sign-in" },
489 ])("rejects setup for unavailable or unsupported instance $id", ({ id, detail }) =>
490 Effect.gen(function* () {
491 const { service, actions } = yield* makeHarness();
492 const operations: Effect.Effect<
493 ProviderAuthState | ReadonlyArray<ProviderAuthState>,
494 ProviderSetupError
495 >[] = [
496 service.start({ instanceId: id }, owner),
497 service.complete({ instanceId: id, flowId, callbackUrl }, owner),
498 service.cancel({ instanceId: id, flowId }, owner),
499 service.logout({ instanceId: id }),
500 Stream.runCollect(service.subscribe({ instanceId: id }, owner)),
501 ];
502 for (const operation of operations) {
503 const error = yield* Effect.flip(operation);
504 assert.instanceOf(error, ProviderSetupError);
505 assert.strictEqual(error.instanceId, id);
506 assert.include(error.detail, detail);
507 }
508 assert.deepStrictEqual(actions, []);
509 }),
510 );
511
512 it.effect("stops every live session on the instance before native logout", () =>
513 Effect.gen(function* () {
514 const { service, actions, released } = yield* makeHarness({
515 threads: [
516 makeThread("running"),
517 makeThread("starting"),
518 makeThread("idle", { active: false }),
519 makeThread("other-instance", { providerInstanceId: otherInstanceId }),
520 ],
521 sessions: new Map([
522 [
523 ThreadId.make("running"),
524 [
525 makeSession("running-session", "running"),
526 makeSession("stopped-session", "stopped"),
527 makeSession("errored-session", "error"),
528 makeSession("foreign-session", "ready", otherInstanceId),
529 ],
530 ],
531 [ThreadId.make("starting"), [makeSession("starting-session", "starting")]],
532 [ThreadId.make("idle"), [makeSession("idle-session")]],
533 [
534 ThreadId.make("other-instance"),
535 [makeSession("other-session", "ready", otherInstanceId)],
536 ],
537 ]),
538 });
539 const state = yield* service.logout({ instanceId });
540
541 assert.strictEqual(state.phase, "idle");
542 assert.deepStrictEqual(actions, [
543 "close-gate",
544 "list-threads",
545 "sessions:running",
546 "stop:running-session",
547 "sessions:starting",
548 "stop:starting-session",
549 "sessions:idle",
550 "stop:idle-session",
551 "sessions:other-instance",
552 "native-logout",
553 ]);
554 assert.deepStrictEqual(released, ["running-session", "starting-session", "idle-session"]);
555 }),
556 );
557
558 it.effect(
559 "releases a shared native session once after a thread's selected provider changes",
560 () =>
561 Effect.gen(function* () {
562 const shared = makeSession("shared-native-session");
563 const { service, released } = yield* makeHarness({
564 threads: [
565 makeThread("changed-selection", { providerInstanceId: otherInstanceId }),
566 makeThread("same-session"),
567 ],
568 sessions: new Map([
569 [ThreadId.make("changed-selection"), [shared]],
570 [ThreadId.make("same-session"), [shared]],
571 ]),
572 });
573
574 yield* service.logout({ instanceId });
575
576 assert.deepStrictEqual(released, [shared.id]);
577 }),
578 );
579
580 it.effect.each([
581 { text: "/logout", hasAttachments: false, handled: true },
582 { text: " \n/logout\t", hasAttachments: false, handled: true },
583 { text: "/logout", hasAttachments: true, handled: false },
584 { text: "/logout please", hasAttachments: false, handled: false },
585 { text: "Explain /logout", hasAttachments: false, handled: false },
586 { text: "/Logout", hasAttachments: false, handled: false },
587 ])("handles only a standalone logout command %#", ({ text, hasAttachments, handled }) =>
588 Effect.gen(function* () {
589 const { service, actions } = yield* makeHarness();
590 const result = yield* service.tryHandlePromptCommand({ instanceId, text, hasAttachments });
591
592 assert.strictEqual(result, handled);
593 assert.deepStrictEqual(
594 actions,
595 handled ? ["close-gate", "list-threads", "native-logout"] : [],
596 );
597 }),
598 );
599
600 it.effect("does not intercept commands for providers without an auth controller", () =>
601 Effect.gen(function* () {
602 const { service, actions } = yield* makeHarness();
603 for (const id of [unsupportedInstanceId, ProviderInstanceId.make("missing")]) {
604 assert.isFalse(
605 yield* service.tryHandlePromptCommand({
606 instanceId: id,
607 text: "/logout",
608 hasAttachments: false,
609 }),
610 );
611 }
612 assert.deepStrictEqual(actions, []);
613 }),
614 );
615
616 it.effect("does not log out when the thread shell cannot be read", () =>
617 Effect.gen(function* () {
618 const { service, actions } = yield* makeHarness({ shellError: true });
619 const error = yield* Effect.flip(service.logout({ instanceId }));
620
621 assert.instanceOf(error, ProviderSetupError);
622 assert.strictEqual(error.instanceId, instanceId);
623 assert.strictEqual(error.operation, "stopSessions");
624 assert.notInclude(error.detail, "private database diagnostics");
625 assert.deepStrictEqual(actions, ["close-gate", "list-threads"]);
626 }),
627 );
628
629 it.effect("does not log out or consume the command when stopping a session fails", () =>
630 Effect.gen(function* () {
631 const { service, actions, released } = yield* makeHarness({
632 threads: [makeThread("active")],
633 sessions: new Map([[ThreadId.make("active"), [makeSession("active-session")]]]),
634 stopError: true,
635 });
636 const error = yield* Effect.flip(
637 service.tryHandlePromptCommand({ instanceId, text: "/logout", hasAttachments: false }),
638 );
639
640 assert.instanceOf(error, ProviderSetupError);
641 assert.strictEqual(error.operation, "stopSessions");
642 assert.notInclude(error.detail, "private process diagnostics");
643 assert.deepStrictEqual(released, []);
644 assert.deepStrictEqual(actions, [
645 "close-gate",
646 "list-threads",
647 "sessions:active",
648 "stop:active-session",
649 ]);
650 }),
651 );
652
653 it.effect("returns native logout failures to the command caller", () =>
654 Effect.gen(function* () {
655 const logoutError = new ProviderSetupError({
656 instanceId,
657 operation: "logout",
658 detail: "Native sign-out failed. Try again.",
659 });
660 const { service } = yield* makeHarness({ logoutError });
661 const error = yield* Effect.flip(
662 service.tryHandlePromptCommand({ instanceId, text: "/logout", hasAttachments: false }),
663 );
664
665 assert.strictEqual(error, logoutError);
666 }),
667 );
668});