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 continuation-progress.unit.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';import { CONTINUATION_MARKER, FEEDBACK_PREFIX,} from './continuation-depth.ts';import { hasRunningBackgroundTask, recordCarriesToolUse, workedSinceLastForcedContinuation,} from './continuation-progress.ts';
/** Transcript line standing for one forced-continuation feedback record. */const BLOCK_LINE = `{"type":"user","message":{"content":"${FEEDBACK_PREFIX}:\\n${CONTINUATION_MARKER}."}}`;
/** Assistant record that issued a tool call. */const TOOL_LINE = '{"type":"assistant","message":{"content":[{"type":"tool_use","name":"Bash"}]}}';
/** Assistant record that only produced prose. */const TEXT_LINE = '{"type":"assistant","message":{"content":[{"type":"text","text":"still blocked on run 008"}]}}';
await describe({ name: 'forced-continuation progress release', children: [ describe({ name: workedSinceLastForcedContinuation.name, children: [ it({ name: 'allows the first block, since nothing has been pushed yet', fn: async () => { expect(workedSinceLastForcedContinuation([TEXT_LINE,],),).toBe(true,); }, },), it({ name: 'reports work when the pushed turn issued a tool call', fn: async () => { expect(workedSinceLastForcedContinuation([BLOCK_LINE, TOOL_LINE, TEXT_LINE,],),).toBe(true,); }, },), it({ name: 'reports no work when the pushed turn only restated the blocker', fn: async () => { // The real failure: a session waiting on an external process, where every // forced turn produces another restatement and no work at all. expect(workedSinceLastForcedContinuation([BLOCK_LINE, TEXT_LINE,],),).toBe(false,); }, },), it({ name: 'looks only at the most recent push, not at earlier productive ones', fn: async () => { expect( workedSinceLastForcedContinuation([BLOCK_LINE, TOOL_LINE, BLOCK_LINE, TEXT_LINE,],), ).toBe(false,); }, },), it({ name: 'counts a read-only tool as work, since orienting is not idleness', fn: async () => { const readLine = '{"type":"assistant","message":{"content":[{"type":"tool_use","name":"Read"}]}}';
expect(workedSinceLastForcedContinuation([BLOCK_LINE, readLine,],),).toBe(true,); }, },), it({ name: 'reports work for an empty transcript rather than suppressing the first block', fn: async () => { expect(workedSinceLastForcedContinuation([],),).toBe(true,); }, },), it({ name: 'errs toward blocking when the block itself fell outside the tail', fn: async () => { // The opposite direction from the task-list release, which refuses to read a // truncated tail because its absence reads as finished. Here an unseen block // reads as work, so the hook keeps pushing, which the depth guard bounds. expect(workedSinceLastForcedContinuation([TEXT_LINE,],),).toBe(true,); }, },), it({ name: 'skips a truncated final line rather than throwing', fn: async () => { expect(workedSinceLastForcedContinuation([BLOCK_LINE, '{"type":"assist',],),).toBe(false,); }, },), ], },),
describe({ name: hasRunningBackgroundTask.name, children: [ it({ name: 'reports no wait when the session has no background tasks', fn: async () => { expect(hasRunningBackgroundTask([],),).toBe(false,); expect(hasRunningBackgroundTask(),).toBe(false,); }, },), it({ name: 'reports a wait while a shell task is running', fn: async () => { // Shape captured from a live Stop payload on Claude Code 2.1.224. expect(hasRunningBackgroundTask([ { id: 'b6ldjvy2v', type: 'shell', status: 'running', description: 'Sleep for 60 seconds in background', command: 'sleep 60', }, ],),).toBe(true,); }, },), it({ name: 'reports no wait once every task has left the running state', fn: async () => { expect(hasRunningBackgroundTask([ { id: 'a', type: 'shell', status: 'completed', }, { id: 'b', type: 'shell', status: 'failed', }, ],),).toBe(false,); }, },), it({ name: 'reports a wait when only one of several tasks is still running', fn: async () => { expect(hasRunningBackgroundTask([ { id: 'a', type: 'shell', status: 'completed', }, { id: 'b', type: 'shell', status: 'running', }, ],),).toBe(true,); }, },), ], },),
describe({ name: recordCarriesToolUse.name, children: [ it({ name: 'ignores a user record that happens to carry tool_use blocks', fn: async () => { expect( recordCarriesToolUse({ type: 'user', message: { content: [{ type: 'tool_use', },], }, },), ).toBe(false,); }, },), it({ name: 'ignores an assistant record whose content is a plain string', fn: async () => { expect(recordCarriesToolUse({ type: 'assistant', message: { content: 'done', }, },),).toBe(false,); }, },), it({ name: 'ignores a record with no message at all', fn: async () => { expect(recordCarriesToolUse({ type: 'assistant', },),).toBe(false,); }, },), ], },), ],},);