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

next
ts 65 lines 2.31 KB
Raw
1 import { describe, expect, it } from '@effect/vitest';
2 import { Effect, Exit } from 'effect';
3 import { makeSinkFailures } from 'src/commands/triggers/sink-failures';
4 import { TerminalUI } from 'src/services/terminal-ui';
5 import { redirectedTerminalUI } from 'test/__utils__/services/redirected-terminal-ui';
6
7 const recordOneFailure = (failFast: boolean) =>
8 Effect.gen(function* () {
9 const ui = yield* TerminalUI;
10 let stopped = false;
11 const failures = makeSinkFailures({
12 ui,
13 failFast,
14 stop: Effect.sync(() => {
15 stopped = true;
16 }),
17 summary: count => `${count} failed`,
18 });
19 const exit = yield* Effect.exit(failures.record('write failed'));
20 return { exit, stopped };
21 }).pipe(Effect.provide(redirectedTerminalUI().layer));
22
23 describe('makeSinkFailures', () => {
24 // The event must not reach a later sink, e.g. a forward after a failed --out append.
25 it.effect('[Given] --fail-fast [Then] a failure stops the listener and ends the event', () =>
26 Effect.gen(function* () {
27 const { exit, stopped } = yield* recordOneFailure(true);
28
29 expect(stopped).toBe(true);
30 expect(Exit.hasInterrupts(exit)).toBe(true);
31 })
32 );
33
34 it.effect('[Given] no --fail-fast [Then] the event goes on to its next sink', () =>
35 Effect.gen(function* () {
36 const { exit, stopped } = yield* recordOneFailure(false);
37
38 expect(stopped).toBe(false);
39 expect(Exit.isSuccess(exit)).toBe(true);
40 })
41 );
42
43 it.effect(
44 '[Given] a failure message quoting remote text [Then] its warn is one escaped line',
45 () =>
46 Effect.gen(function* () {
47 const terminal = redirectedTerminalUI({ decoratedStderr: true });
48 yield* Effect.gen(function* () {
49 const failures = makeSinkFailures({
50 ui: yield* TerminalUI,
51 failFast: false,
52 stop: Effect.void,
53 summary: count => `${count} failed`,
54 });
55 // Formatting fixture: a BEL and CR/LF, as a remote error message could carry them.
56 yield* failures.record('Forwarding failed: busy\u0007\r\nretry later');
57 }).pipe(Effect.provide(terminal.layer));
58
59 expect(terminal.stderr()).toContain(
60 'Forwarding failed: busy\\u0007\\u000d\\u000aretry later'
61 );
62 expect(terminal.stderr()).not.toMatch(/[\u0007\r]/u);
63 })
64 );
65 });