Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
Monochromatic package claude-code-plugin source src handler stop-reminder auto-continue.unit.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231import type { StopInput, } from '@monochromatic-dev/claude-code-plugin-hook-type/ts';import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';import { AUTO_CONTINUE_ENV, autoContinueActive, autoContinueEnabled, autoContinueReason, ENABLING_VALUES, UNSET_SETTING,} from './auto-continue.ts';import { stopRemindersDecision, stopRemindersHandler,} from './index.ts';
/** Fields a test varies on the built stop event; anything omitted keeps its default. */type StopEventOverrides = { readonly stop_hook_active?: boolean; readonly last_assistant_message?: string;};
/** Stop event with every field the handler reads, so each test varies one thing. @param overrides - fields replacing defaults on built event @returns event shaped like Claude Code's `Stop` payload @example ```ts stopEvent({ stop_hook_active: true }); ``` */function stopEvent(overrides: StopEventOverrides = {},): StopInput { return { session_id: 'test-session', transcript_path: '/dev/null', cwd: '/tmp', permission_mode: 'default', hook_event_name: 'Stop', stop_hook_active: false, last_assistant_message: 'Done.', ...overrides, };}
await describe({ name: 'stop-reminder forced continuation', children: [ describe({ name: autoContinueEnabled.name, children: [ it({ name: 'defaults to disabled when the opt-in switch is unset', fn: async () => { expect(autoContinueEnabled(UNSET_SETTING,),).toBe(false,); }, },), it({ name: 'stays disabled for an unrecognized value', fn: async () => { expect(autoContinueEnabled('off',),).toBe(false,); }, },), it({ name: 'enables on every documented enabling value', fn: async () => { for (const value of ENABLING_VALUES) { expect(autoContinueEnabled(value,),).toBe(true,); } }, },), it({ name: 'normalizes surrounding space and letter case', fn: async () => { expect(autoContinueEnabled(' ON ',),).toBe(true,); }, },), it({ name: 'names the opt-in switch with the repository environment prefix', fn: async () => { expect(AUTO_CONTINUE_ENV,).toBe('MONOCHROMATIC_STOP_AUTO_CONTINUE',); }, },), it({ name: 'reads the opt-in switch from this process without re-deciding it', fn: async () => { expect(autoContinueActive(),).toBe( autoContinueEnabled(process.env[AUTO_CONTINUE_ENV] ?? UNSET_SETTING,), ); }, },), ], },),
describe({ name: autoContinueReason.name, children: [ it({ name: 'instructs the agent to keep status prose rather than suppress it', fn: async () => { expect(autoContinueReason() .join(' ',),).toContain('do not delete, shorten, or rephrase it',); }, },), it({ name: 'offers a blocker path so a genuine stop can be explained', fn: async () => { expect(autoContinueReason() .join(' ',),).toContain('name the concrete blocker',); }, },), it({ name: 'routes a decision-blocked agent to AskUserQuestion rather than to a stop', fn: async () => { // That tool waits for the user, so it is the one exit that gets the agent // what stopping was reaching for, and the hook has nothing to refuse. expect(autoContinueReason() .join(' ',),).toContain('AskUserQuestion',); }, },), ], },),
describe({ name: stopRemindersDecision.name, children: [ it({ name: "blocks a clean response that would otherwise have been allowed", fn: async () => { expect(stopRemindersDecision({ event: stopEvent(), forcedContinuationAllowed: true, },).decision,) .toBe("block",); }, },), it({ name: "still blocks inside a chain, where the quality detectors no longer apply", fn: async () => { const output = stopRemindersDecision({ event: stopEvent({ stop_hook_active: true, last_assistant_message: "This probably works.", },), forcedContinuationAllowed: true, },);
expect(output.decision,).toBe("block",); expect(output.reason,).not.toContain("uncertain language",); }, },), it({ name: "reports hedging on the first stop of a chain", fn: async () => { expect(stopRemindersDecision({ event: stopEvent({ last_assistant_message: "This probably works.", },), forcedContinuationAllowed: true, },).reason,).toContain("uncertain language",); }, },), it({ name: "allows a clean stop once forced continuation is disallowed", fn: async () => { expect(stopRemindersDecision({ event: stopEvent(), forcedContinuationAllowed: false, },),) .toEqual({},); }, },), it({ name: "still reports hedging while forced continuation is disallowed", fn: async () => { const output = stopRemindersDecision({ event: stopEvent({ last_assistant_message: "This probably works.", },), forcedContinuationAllowed: false, },);
expect(output.decision,).toBe("block",); expect(output.reason,).toContain("uncertain language",); }, },), it({ name: "reports an uncited dismissal on the first stop of a chain", fn: async () => { expect(stopRemindersDecision({ event: stopEvent({ last_assistant_message: "This project doesn't use that.", },), forcedContinuationAllowed: true, },).reason,).toContain("categorical dismissal",); }, },), it({ name: "suppresses the dismissal report inside a chain, leaving only continuation", fn: async () => { const output = stopRemindersDecision({ event: stopEvent({ stop_hook_active: true, last_assistant_message: "This project doesn't use that.", },), forcedContinuationAllowed: true, },);
expect(output.decision,).toBe("block",); expect(output.reason,).not.toContain("categorical dismissal",); expect(output.reason,).toContain("Resume the next item now",); }, },), it({ name: "yields precedence to a trailing question instead of contradicting it", fn: async () => { const output = stopRemindersDecision({ event: stopEvent({ last_assistant_message: "Which package should I migrate first?", },), forcedContinuationAllowed: true, },);
expect(output.reason,).toContain("AskUserQuestion",); expect(output.reason,).not.toContain("Resume the next item now",); }, },), it({ name: "wires the handler through to the opt-in switch on a live event", fn: async () => { // Reading the ambient switch instead of mutating it keeps this test from racing // the others; the built-bundle suite drives both switch states explicitly. expect((await stopRemindersHandler(stopEvent(),)).decision,).toBe( autoContinueActive() ? "block" : undefined, ); }, },), ], },), ],},);