@devries-cameron20 / composio-1 / commits / aecf75852
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(cli): auto-stop spinner on error and add TerminalUI tests

- Add `useMakeSpinner` to TerminalUI that auto-stops the spinner via `Effect.acquireUseRelease` when the wrapped effect fails or is interrupted - Migrate ts/py generate and upgrade commands from `makeSpinner` to `useMakeSpinner` so spinners don't keep animating after errors - Replace remaining `Effect.log` calls with `ui.log.step` in generate commands - Add 13 dedicated TerminalUI tests covering log text capture, spinner lifecycle, error auto-cleanup, and no double-stop on user-initiated stop

jkomyno committed Feb 18, 2026 at 11:53 UTC aecf75852cf0c8807bba738e419416162ed81961
6 files changed +419 -159
ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
+82 -73
@@ -67,7 +67,7 @@ export function generatePythonTypeStubs({
67 })
68 );
69
70 - yield* Effect.log(`Writing type stubs to ${outputDir}...`);
70 + yield* ui.log.step(`Writing type stubs to ${outputDir}`);
71 yield* fs.makeDirectory(outputDir, { recursive: true });
72
73 // Read toolkit version overrides from environment variables
@@ -84,83 +84,92 @@ export function generatePythonTypeStubs({
84 client,
85 });
86
87 - const spinner = yield* ui.makeSpinner('Fetching data from Composio API...');
88 -
89 - // Validate toolkit slugs if specified (separate from version validation)
90 - const validatedToolkitSlugs = hasToolkitsFilter
91 - ? yield* client
92 - .validateToolkits(toolkitsOpt)
93 - .pipe(
94 - Effect.catchTag('services/InvalidToolkitsError', error =>
95 - Effect.fail(
96 - new Error(
97 - `Invalid toolkit(s): ${error.invalidToolkits.join(', ')}. ` +
98 - `Available toolkits: ${error.availableToolkits.slice(0, 10).join(', ')}${error.availableToolkits.length > 10 ? '...' : ''}`
87 + // Fetch, generate, and write with a spinner that auto-cleans up on error
88 + yield* ui.useMakeSpinner('Fetching data from Composio API...', spinner =>
89 + Effect.gen(function* () {
90 + // Validate toolkit slugs if specified (separate from version validation)
91 + const validatedToolkitSlugs = hasToolkitsFilter
92 + ? yield* client
93 + .validateToolkits(toolkitsOpt)
94 + .pipe(
95 + Effect.catchTag('services/InvalidToolkitsError', error =>
96 + Effect.fail(
97 + new Error(
98 + `Invalid toolkit(s): ${error.invalidToolkits.join(', ')}. ` +
99 + `Available toolkits: ${error.availableToolkits.slice(0, 10).join(', ')}${error.availableToolkits.length > 10 ? '...' : ''}`
100 + )
101 + )
102 )
103 )
101 - )
102 - )
103 - : [];
104 -
105 - const [allToolkits, tools, triggerTypes] = yield* Effect.all(
106 - [
107 - Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
108 - Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getToolsAsEnums())),
109 - Effect.logDebug('Fetching trigger types...').pipe(
110 - Effect.flatMap(() => client.getTriggerTypes())
111 - ),
112 - ],
113 - { concurrency: 'unbounded' }
114 - );
104 + : [];
105 +
106 + const [allToolkits, tools, triggerTypes] = yield* Effect.all(
107 + [
108 + Effect.logDebug('Fetching toolkits...').pipe(
109 + Effect.flatMap(() => client.getToolkits())
110 + ),
111 + Effect.logDebug('Fetching tools...').pipe(
112 + Effect.flatMap(() => client.getToolsAsEnums())
113 + ),
114 + Effect.logDebug('Fetching trigger types...').pipe(
115 + Effect.flatMap(() => client.getTriggerTypes())
116 + ),
117 + ],
118 + { concurrency: 'unbounded' }
119 + );
120 +
121 + // Filter toolkits if --toolkits was specified
122 + const toolkits = hasToolkitsFilter
123 + ? client.filterToolkitsBySlugs(allToolkits, validatedToolkitSlugs)
124 + : allToolkits;
125 +
126 + if (hasToolkitsFilter) {
127 + yield* spinner.message(
128 + `Found ${toolkits.length} toolkit(s): ${toolkits.map(t => t.slug).join(', ')}`
129 + );
130 + }
131 +
132 + // Build version map for toolkits being generated (using validated overrides)
133 + const versionMap: ToolkitVersionOverrides = new Map();
134 + for (const toolkit of toolkits) {
135 + const version = validatedOverrides.get(toolkit.slug.toLowerCase() as Lowercase<string>);
136 + if (version && version !== 'latest') {
137 + versionMap.set(toolkit.slug.toLowerCase() as Lowercase<string>, version);
138 + }
139 + }
140 +
141 + const typeableTools = { withTypes: false as const, tools };
142 +
143 + yield* spinner.message('Generating Python type stubs...');
144 + const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes, versionMap });
145 +
146 + // Generate Python sources
147 + const sources = generatePythonSources({
148 + banner: BANNER,
149 + outputDir,
150 + })(index);
151 +
152 + yield* spinner.message('Writing files to disk...');
153 +
154 + // Write all generated files
155 + yield* pipe(
156 + Effect.all(
157 + sources.map(([filePath, content]) =>
158 + fs
159 + .writeFileString(filePath, content)
160 + .pipe(
161 + Effect.mapError(error => new Error(`Failed to write file ${filePath}: ${error}`))
162 + )
163 + ),
164 + { concurrency: 1 }
165 + ),
166 + Effect.mapError(error => new Error(`Failed to write generated files: ${error}`))
167 + );
168
116 - // Filter toolkits if --toolkits was specified
117 - const toolkits = hasToolkitsFilter
118 - ? client.filterToolkitsBySlugs(allToolkits, validatedToolkitSlugs)
119 - : allToolkits;
120 -
121 - if (hasToolkitsFilter) {
122 - yield* spinner.message(
123 - `Found ${toolkits.length} toolkit(s): ${toolkits.map(t => t.slug).join(', ')}`
124 - );
125 - }
126 -
127 - // Build version map for toolkits being generated (using validated overrides)
128 - const versionMap: ToolkitVersionOverrides = new Map();
129 - for (const toolkit of toolkits) {
130 - const version = validatedOverrides.get(toolkit.slug.toLowerCase() as Lowercase<string>);
131 - if (version && version !== 'latest') {
132 - versionMap.set(toolkit.slug.toLowerCase() as Lowercase<string>, version);
133 - }
134 - }
135 -
136 - const typeableTools = { withTypes: false as const, tools };
137 -
138 - yield* spinner.message('Generating Python type stubs...');
139 - const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes, versionMap });
140 -
141 - // Generate Python sources
142 - const sources = generatePythonSources({
143 - banner: BANNER,
144 - outputDir,
145 - })(index);
146 -
147 - yield* spinner.message('Writing files to disk...');
148 -
149 - // Write all generated files
150 - yield* pipe(
151 - Effect.all(
152 - sources.map(([filePath, content]) =>
153 - fs
154 - .writeFileString(filePath, content)
155 - .pipe(Effect.mapError(error => new Error(`Failed to write file ${filePath}: ${error}`)))
156 - ),
157 - { concurrency: 1 }
158 - ),
159 - Effect.mapError(error => new Error(`Failed to write generated files: ${error}`))
169 + yield* spinner.stop('Type stubs generated successfully');
170 + })
171 );
172
162 - yield* spinner.stop('Type stubs generated successfully');
163 -
173 yield* Option.isNone(outputOpt)
174 ? ui.note(
175 'from composio.generated.<toolkit_name> import <TOOLKIT_NAME>',
ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+50 -45
@@ -374,7 +374,7 @@ export function generateTypescriptTypeStubs({
374 })
375 );
376
377 - yield* Effect.log(`Writing type stubs to ${outputDir}...`);
377 + yield* ui.log.step(`Writing type stubs to ${outputDir}`);
378 yield* fs.makeDirectory(outputDir, { recursive: true });
379
380 // Read toolkit version overrides from environment variables
@@ -393,51 +393,56 @@ export function generateTypescriptTypeStubs({
393 client,
394 });
395
396 - // Fetch data using a spinner for progress
397 - const spinner = yield* ui.makeSpinner('Fetching data from Composio API...');
398 -
399 - const { toolkits, triggerTypes, typeableTools, versionMap } = yield* toolkitSlugsFilter !== null
400 - ? fetchFilteredData(client, toolkitSlugsFilter, typeTools, validatedOverrides, spinner)
401 - : fetchAllData(client, typeTools, validatedOverrides, spinner);
402 -
403 - yield* spinner.message('Generating TypeScript type stubs...');
404 - const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes, versionMap });
405 -
406 - // Generate TypeScript sources
407 - const sources = yield* generateTypeScriptSources({
408 - outputDir,
409 - emitSingleFile: Boolean(compact), // Ensure boolean type
410 - banner: BANNER,
411 - importExtension: 'js',
412 - })(index);
413 -
414 - yield* spinner.message('Writing files to disk...');
415 -
416 - // Write all generated files
417 - yield* pipe(
418 - Effect.all(
419 - sources.map(([filePath, content]) =>
420 - fs
421 - .writeFileString(filePath, content)
422 - .pipe(Effect.mapError(error => new Error(`Failed to write file ${filePath}: ${error}`)))
423 - ),
424 - { concurrency: 'unbounded' }
425 - ),
426 - Effect.mapError(error => new Error(`Failed to write generated files: ${error}`))
427 - );
428 -
429 - // Compile TypeScript to JavaScript if needed
430 - if (transpiled) {
431 - yield* spinner.message('Transpiling to JavaScript...');
432 - yield* pipe(
433 - transpileTypeScriptSources({ sources, outputDir }),
434 - Effect.catchAll(error =>
435 - Effect.logWarning(`Failed to compile TypeScript files: ${error.message}`)
436 - )
437 - );
438 - }
396 + // Fetch, generate, and write with a spinner that auto-cleans up on error
397 + yield* ui.useMakeSpinner('Fetching data from Composio API...', spinner =>
398 + Effect.gen(function* () {
399 + const { toolkits, triggerTypes, typeableTools, versionMap } = yield* toolkitSlugsFilter !==
400 + null
401 + ? fetchFilteredData(client, toolkitSlugsFilter, typeTools, validatedOverrides, spinner)
402 + : fetchAllData(client, typeTools, validatedOverrides, spinner);
403 +
404 + yield* spinner.message('Generating TypeScript type stubs...');
405 + const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes, versionMap });
406 +
407 + // Generate TypeScript sources
408 + const sources = yield* generateTypeScriptSources({
409 + outputDir,
410 + emitSingleFile: Boolean(compact), // Ensure boolean type
411 + banner: BANNER,
412 + importExtension: 'js',
413 + })(index);
414 +
415 + yield* spinner.message('Writing files to disk...');
416 +
417 + // Write all generated files
418 + yield* pipe(
419 + Effect.all(
420 + sources.map(([filePath, content]) =>
421 + fs
422 + .writeFileString(filePath, content)
423 + .pipe(
424 + Effect.mapError(error => new Error(`Failed to write file ${filePath}: ${error}`))
425 + )
426 + ),
427 + { concurrency: 'unbounded' }
428 + ),
429 + Effect.mapError(error => new Error(`Failed to write generated files: ${error}`))
430 + );
431 +
432 + // Compile TypeScript to JavaScript if needed
433 + if (transpiled) {
434 + yield* spinner.message('Transpiling to JavaScript...');
435 + yield* pipe(
436 + transpileTypeScriptSources({ sources, outputDir }),
437 + Effect.catchAll(error =>
438 + Effect.logWarning(`Failed to compile TypeScript files: ${error.message}`)
439 + )
440 + );
441 + }
442
440 - yield* spinner.stop('Type stubs generated successfully');
443 + yield* spinner.stop('Type stubs generated successfully');
444 + })
445 + );
446
447 yield* Option.isNone(outputOpt)
448 ? ui.note(
ts/packages/cli/src/services/terminal-ui.ts
+42 -5
@@ -59,8 +59,23 @@ export interface TerminalUI {
59 /**
60 * Create a controllable spinner for multi-step flows (e.g., login polling).
61 * The caller is responsible for calling `stop()` or `error()`.
62 + *
63 + * WARNING: If the surrounding Effect fails, this spinner will NOT be cleaned up.
64 + * Use `useMakeSpinner` instead for automatic cleanup on error.
65 */
66 readonly makeSpinner: (message: string) => Effect.Effect<SpinnerHandle>;
67 +
68 + /**
69 + * Create a controllable spinner that is automatically stopped on error or interruption.
70 + * The `use` function receives a SpinnerHandle and must return an Effect.
71 + * On success: the caller should call `spinner.stop(...)` inside `use`.
72 + * On failure: the spinner is automatically stopped with an error message.
73 + * On interruption: the spinner is automatically cancelled.
74 + */
75 + readonly useMakeSpinner: <A, E, R>(
76 + message: string,
77 + use: (spinner: SpinnerHandle) => Effect.Effect<A, E, R>
78 + ) => Effect.Effect<A, E, R>;
79 }
80
81 export const TerminalUI = Context.GenericTag<TerminalUI>('services/TerminalUI');
@@ -69,6 +84,14 @@ export const TerminalUI = Context.GenericTag<TerminalUI>('services/TerminalUI');
84 // TerminalUILive — production layer using @clack/prompts
85 // ---------------------------------------------------------------------------
86
87 +function createClackSpinnerHandle(s: p.SpinnerResult, defaultMessage: string): SpinnerHandle {
88 + return {
89 + message: (msg: string) => Effect.sync(() => s.message(msg)),
90 + stop: (msg?: string) => Effect.sync(() => s.stop(msg ?? defaultMessage)),
91 + error: (msg?: string) => Effect.sync(() => s.error(msg ?? defaultMessage)),
92 + };
93 +}
94 +
95 const makeLive: TerminalUI = {
96 intro: title => Effect.sync(() => p.intro(title)),
97 outro: message => Effect.sync(() => p.outro(message)),
@@ -110,12 +133,26 @@ const makeLive: TerminalUI = {
133 Effect.sync(() => {
134 const s = p.spinner();
135 s.start(message);
113 - return {
114 - message: (msg: string) => Effect.sync(() => s.message(msg)),
115 - stop: (msg?: string) => Effect.sync(() => s.stop(msg ?? message)),
116 - error: (msg?: string) => Effect.sync(() => s.error(msg ?? message)),
117 - };
136 + return createClackSpinnerHandle(s, message);
137 }),
138 +
139 + useMakeSpinner: (message, use) =>
140 + Effect.acquireUseRelease(
141 + Effect.sync(() => {
142 + const s = p.spinner();
143 + s.start(message);
144 + return { raw: s, handle: createClackSpinnerHandle(s, message) };
145 + }),
146 + ({ handle }) => use(handle),
147 + ({ raw }, exit) =>
148 + Effect.sync(() => {
149 + // Only clean up if the spinner is still active (user didn't call stop/error)
150 + // Clack spinners have an internal `isCancelled` state after stop/error/cancel
151 + if (Exit.isFailure(exit) && !raw.isCancelled) {
152 + raw.error(message);
153 + }
154 + })
155 + ),
156 };
157
158 export const TerminalUILive = Layer.succeed(TerminalUI, makeLive);
ts/packages/cli/src/services/upgrade-binary.ts
+36 -35
@@ -328,43 +328,44 @@ export class UpgradeBinary extends Effect.Service<UpgradeBinary>()('services/Upg
328 return;
329 }
330
331 - const spinner = yield* ui.makeSpinner('Checking for updates...');
332 -
333 - const release = yield* fetchLatestRelease();
334 - const updateAvailable = yield* isUpdateAvailable(release);
335 - if (!updateAvailable) {
336 - yield* spinner.stop('You are already running the latest version!');
337 - yield* ui.outro('');
338 - return;
339 - }
331 + yield* ui.useMakeSpinner('Checking for updates...', spinner =>
332 + Effect.gen(function* () {
333 + const release = yield* fetchLatestRelease();
334 + const updateAvailable = yield* isUpdateAvailable(release);
335 + if (!updateAvailable) {
336 + yield* spinner.stop('You are already running the latest version!');
337 + return;
338 + }
339 +
340 + yield* spinner.message(
341 + `New version available: ${release.tag_name} (current: ${APP_VERSION}). Downloading...`
342 + );
343
341 - yield* spinner.message(
342 - `New version available: ${release.tag_name} (current: ${APP_VERSION}). Downloading...`
344 + const platformArch = yield* detectPlatform;
345 + const { name, data } = yield* downloadBinary(release, platformArch);
346 +
347 + yield* spinner.message('Extracting...');
348 +
349 + // The temporary directory is automatically cleaned up
350 + const tmpDir = yield* fs
351 + .makeTempDirectoryScoped({ prefix: `${CLI_BINARY_NAME}-upgrade}` })
352 + .pipe(
353 + Effect.catchAll(error =>
354 + Effect.fail(
355 + new UpgradeBinaryError({
356 + cause: error as Error,
357 + message: 'Failed to create temporary directory',
358 + })
359 + )
360 + )
361 + );
362 +
363 + const extractedBinaryPath = yield* extractBinary({ name, data }, tmpDir);
364 + yield* replaceBinary(extractedBinaryPath, currentPath);
365 +
366 + yield* spinner.stop('Upgrade completed!');
367 + })
368 );
344 -
345 - const platformArch = yield* detectPlatform;
346 - const { name, data } = yield* downloadBinary(release, platformArch);
347 -
348 - yield* spinner.message('Extracting...');
349 -
350 - // The temporary directory is automatically cleaned up
351 - const tmpDir = yield* fs
352 - .makeTempDirectoryScoped({ prefix: `${CLI_BINARY_NAME}-upgrade}` })
353 - .pipe(
354 - Effect.catchAll(error =>
355 - Effect.fail(
356 - new UpgradeBinaryError({
357 - cause: error as Error,
358 - message: 'Failed to create temporary directory',
359 - })
360 - )
361 - )
362 - );
363 -
364 - const extractedBinaryPath = yield* extractBinary({ name, data }, tmpDir);
365 - yield* replaceBinary(extractedBinaryPath, currentPath);
366 -
367 - yield* spinner.stop('Upgrade completed!');
369 yield* ui.outro('Restart your terminal to use the new version.');
370 });
371
ts/packages/cli/test/__utils__/services/terminal-ui-test.ts
+24 -1
@@ -1,4 +1,4 @@
1 -import { Console, Effect, Layer } from 'effect';
1 +import { Console, Effect, Exit, Layer } from 'effect';
2 import { TerminalUI } from 'src/services/terminal-ui';
3
4 /**
@@ -44,5 +44,28 @@ export const TerminalUITest = Layer.succeed(
44 error: (msg?: string) => (msg ? Console.error(msg) : Effect.void),
45 };
46 }),
47 +
48 + useMakeSpinner: (message, use) =>
49 + Effect.gen(function* () {
50 + let stopped = false;
51 + const handle = {
52 + message: (_msg: string) => Effect.void,
53 + stop: (msg?: string) =>
54 + Effect.gen(function* () {
55 + stopped = true;
56 + if (msg) yield* Console.log(msg);
57 + }),
58 + error: (msg?: string) =>
59 + Effect.gen(function* () {
60 + stopped = true;
61 + if (msg) yield* Console.error(msg);
62 + }),
63 + };
64 + const exit = yield* Effect.exit(use(handle));
65 + if (Exit.isFailure(exit) && !stopped) {
66 + yield* Console.error(message);
67 + }
68 + return yield* exit;
69 + }),
70 })
71 );
ts/packages/cli/test/src/services/terminal-ui.test.ts new
+185
@@ -0,0 +1,185 @@
1 +import { describe, expect, layer } from '@effect/vitest';
2 +import { Effect } from 'effect';
3 +import { TerminalUI } from 'src/services/terminal-ui';
4 +import { TestLive, MockConsole } from 'test/__utils__';
5 +
6 +describe('TerminalUI', () => {
7 + layer(TestLive())(it => {
8 + // -----------------------------------------------------------------------
9 + // Log text capture
10 + // -----------------------------------------------------------------------
11 +
12 + it.scoped('log.info writes text capturable by MockConsole', () =>
13 + Effect.gen(function* () {
14 + const ui = yield* TerminalUI;
15 + yield* ui.log.info('hello from info');
16 +
17 + const lines = yield* MockConsole.getLines();
18 + expect(lines).toContain('hello from info');
19 + })
20 + );
21 +
22 + it.scoped('log.success writes text capturable by MockConsole', () =>
23 + Effect.gen(function* () {
24 + const ui = yield* TerminalUI;
25 + yield* ui.log.success('operation succeeded');
26 +
27 + const lines = yield* MockConsole.getLines();
28 + expect(lines).toContain('operation succeeded');
29 + })
30 + );
31 +
32 + it.scoped('log.warn writes text capturable by MockConsole', () =>
33 + Effect.gen(function* () {
34 + const ui = yield* TerminalUI;
35 + yield* ui.log.warn('something is off');
36 +
37 + const lines = yield* MockConsole.getLines();
38 + expect(lines).toContain('something is off');
39 + })
40 + );
41 +
42 + it.scoped('log.error writes text capturable by MockConsole', () =>
43 + Effect.gen(function* () {
44 + const ui = yield* TerminalUI;
45 + yield* ui.log.error('something broke');
46 +
47 + const lines = yield* MockConsole.getLines();
48 + expect(lines).toContain('something broke');
49 + })
50 + );
51 +
52 + it.scoped('log.step writes text capturable by MockConsole', () =>
53 + Effect.gen(function* () {
54 + const ui = yield* TerminalUI;
55 + yield* ui.log.step('step completed');
56 +
57 + const lines = yield* MockConsole.getLines();
58 + expect(lines).toContain('step completed');
59 + })
60 + );
61 +
62 + it.scoped('note writes title and message capturable by MockConsole', () =>
63 + Effect.gen(function* () {
64 + const ui = yield* TerminalUI;
65 + yield* ui.note('api_key_123', 'API Key');
66 +
67 + const lines = yield* MockConsole.getLines();
68 + const output = lines.join('\n');
69 + expect(output).toContain('api_key_123');
70 + expect(output).toContain('API Key');
71 + })
72 + );
73 +
74 + it.scoped('intro and outro write text capturable by MockConsole', () =>
75 + Effect.gen(function* () {
76 + const ui = yield* TerminalUI;
77 + yield* ui.intro('my command');
78 + yield* ui.outro('all done');
79 +
80 + const lines = yield* MockConsole.getLines();
81 + const output = lines.join('\n');
82 + expect(output).toContain('my command');
83 + expect(output).toContain('all done');
84 + })
85 + );
86 +
87 + // -----------------------------------------------------------------------
88 + // withSpinner lifecycle
89 + // -----------------------------------------------------------------------
90 +
91 + it.scoped('withSpinner captures success message', () =>
92 + Effect.gen(function* () {
93 + const ui = yield* TerminalUI;
94 + const result = yield* ui.withSpinner('loading', Effect.succeed(42), {
95 + successMessage: 'loaded 42 items',
96 + });
97 +
98 + expect(result).toBe(42);
99 + const lines = yield* MockConsole.getLines();
100 + expect(lines).toContain('loaded 42 items');
101 + })
102 + );
103 +
104 + it.scoped('withSpinner propagates errors', () =>
105 + Effect.gen(function* () {
106 + const ui = yield* TerminalUI;
107 + const exit = yield* Effect.exit(
108 + ui.withSpinner('loading', Effect.fail(new Error('network error')))
109 + );
110 +
111 + expect(exit._tag).toBe('Failure');
112 + })
113 + );
114 +
115 + // -----------------------------------------------------------------------
116 + // useMakeSpinner — auto-cleanup on error
117 + // -----------------------------------------------------------------------
118 +
119 + it.scoped('useMakeSpinner auto-stops spinner on error', () =>
120 + Effect.gen(function* () {
121 + const ui = yield* TerminalUI;
122 +
123 + const exit = yield* Effect.exit(
124 + ui.useMakeSpinner('fetching data', _spinner => Effect.fail(new Error('API returned 400')))
125 + );
126 +
127 + expect(exit._tag).toBe('Failure');
128 +
129 + // The spinner error message should be captured
130 + const lines = yield* MockConsole.getLines();
131 + expect(lines).toContain('fetching data');
132 + })
133 + );
134 +
135 + it.scoped('useMakeSpinner does NOT double-stop if user already stopped', () =>
136 + Effect.gen(function* () {
137 + const ui = yield* TerminalUI;
138 +
139 + yield* ui.useMakeSpinner('processing', spinner =>
140 + Effect.gen(function* () {
141 + yield* spinner.stop('done processing');
142 + })
143 + );
144 +
145 + const lines = yield* MockConsole.getLines();
146 + // Should see the user's stop message, not the auto-cleanup
147 + expect(lines).toContain('done processing');
148 + // Should NOT see the default message as an error (which would happen with double-stop)
149 + expect(lines.filter(l => l === 'processing')).toHaveLength(0);
150 + })
151 + );
152 +
153 + it.scoped('useMakeSpinner allows message updates before stop', () =>
154 + Effect.gen(function* () {
155 + const ui = yield* TerminalUI;
156 +
157 + yield* ui.useMakeSpinner('starting', spinner =>
158 + Effect.gen(function* () {
159 + yield* spinner.message('step 1');
160 + yield* spinner.message('step 2');
161 + yield* spinner.stop('finished');
162 + })
163 + );
164 +
165 + const lines = yield* MockConsole.getLines();
166 + expect(lines).toContain('finished');
167 + })
168 + );
169 +
170 + it.scoped('useMakeSpinner returns the value from the use callback', () =>
171 + Effect.gen(function* () {
172 + const ui = yield* TerminalUI;
173 +
174 + const result = yield* ui.useMakeSpinner('computing', spinner =>
175 + Effect.gen(function* () {
176 + yield* spinner.stop('computed');
177 + return 99;
178 + })
179 + );
180 +
181 + expect(result).toBe(99);
182 + })
183 + );
184 + });
185 +});