Files
ruflo/plugins/ruflo-console/tests/loops.test.ts
T
rUvandr 45bf52cd86 feat(mods): adopt Claude Code 2.1.290-2.1.318 mod API changes (mods 0.16.0, console 0.49.11, swarm 0.3.8) (#4702)
- ruflo-mods guard (tool.check): read-only fast path on e.isReadOnly (2.1.304)
  that skips the policy-projection stat while a full check found none in the
  last 2 s (web tools excluded so the research ask still fires); a chain deny
  returns without file reads; decider "person" on every ask ruflo raises;
  agentId names the subagent on ruflo's reason; the chain's ceiling survives a
  tightening; .catch documented for 2.1.301 semantics, still fails closed.
- ruflo-console: console_state and console_run registered with
  isDeferred: false (2.1.293); console_open/console_set stay deferred.
- console + swarm: Text bold -> weight (2.1.299 deprecation), codemodded;
  bold: true -> weight: "semibold" (what the host already maps bold to).
  Engines before 2.1.299 refuse a tree with an unknown Text prop, so the kit
  maps weight back to bold there (text-weight.ts, via $.session.version()).
- tests for 2.1.318's kit: $.tool.call now raises tool.check first
  (guidance test); stub answers are validated (swarm prompt.fill stub);
  stale expectations fixed (probe session.compact, learning-loop handshake).
- console kit tests: timeoutMs 30_000 (the 5 s default timed out 19-58
  end-to-end tests under load, on 2.1.289 and 2.1.318 alike), and the mock
  clock advanced past runner.ts's VERIFY_RETRY_MS in actions/settings tests.

Co-authored-by: r <r@x>
2026-11-04 15:49:08 -06:00

86 lines
3.9 KiB
TypeScript

/**
* The Loop Manager in the Automation page: a folded section, presets by tier, a configurator that shows the exact /loop, a launcher
* whose confirm sits under the Start button, and one visible /loop prompt only after yes.
*/
import { describe, expect, mock, test } from 'claude-code/testing'
import { RUFLO_FILES } from './fixtures/ruflo-run'
import { command, elementsOf, keyOf, paneAt, PLUGIN, SESSION, textOf, worldOf } from './fixtures/world'
const keys = (tree: Parameters<typeof elementsOf>[0]) => elementsOf(tree, 'Button').map(keyOf)
describe('loop manager', () => {
test('automation: a folded Loop Manager; open it, pick a preset, see the exact /loop, start it: the confirm sits under Start and yes sends one prompt', { timeoutMs: 30_000, options: { boot: false } }, async ($, on) => {
const world = worldOf(on, RUFLO_FILES, { commands: ['ruflo-loop-workers:ruflo-loop'] })
const clock = mock.clock(on)
await $.session.start(SESSION)
await $.command.run(command('automate'))
const pane = await $.ui.mount({ ...paneAt(150), surface: 'terminal' as const, plugin: PLUGIN })
await pane.drawn()
const folded = await pane.drawn()
expect(textOf(folded)).toContain('LOOP MANAGER')
expect(keys(folded)).toContain('sec-loops')
expect(keys(folded)).not.toContain('loop-start')
await pane.press({ key: 'sec-loops' })
const open = await pane.drawn()
expect(keys(open)).toEqual(expect.arrayContaining(['loop-tier-practical', 'loop-tier-steady', 'loop-tier-exotic', 'loop-pick-ci-watch', 'loop-start', 'loop-manage']))
expect(textOf(open)).toContain('not ready: pick a preset or type what the loop should do')
await pane.press({ key: 'loop-tier-exotic' })
expect(keys(await pane.drawn())).toContain('loop-pick-dream-cycle')
await pane.press({ key: 'loop-tier-practical' })
await pane.press({ key: 'loop-pick-ci-watch' })
const picked = await pane.drawn()
expect(textOf(picked)).toContain('will send: /loop 5m Check CI for the current branch')
expect(keys(picked)).toEqual(expect.arrayContaining(['loop-int-5m', 'loop-int-self-paced']))
await pane.press({ key: 'loop-start' })
const asked = await pane.drawn()
// The confirm sits right under the Start button that raised it, not at the top of the page.
expect(textOf(asked)).toContain('CONFIRM NEEDED')
expect(keys(asked).indexOf('confirm')).toBe(keys(asked).indexOf('loop-manage') + 1)
expect(textOf(asked)).toContain('Confirm: start a loop in the main Claude UI')
expect(textOf(asked)).toContain('/loop 5m Check CI')
expect(world.prompts).toEqual([])
await $.command.run(command('yes'))
for (let i = 0; i < 6; i++) await clock.advance(5)
// A /loop prompt is the engine's to run as a typed command (the unit spec checks the exact text); here the ask is answered and nothing failed.
const after = textOf(await pane.drawn())
expect(after).not.toContain('Confirm: start a loop')
expect(after).not.toContain('Claude did not take it')
await pane.unmount()
})
test('a worker preset needs its plugin: with the command not listed it says so and asks nothing', { timeoutMs: 30_000, options: { boot: false } }, async ($, on) => {
const world = worldOf(on, RUFLO_FILES, { commands: [] })
mock.clock(on)
await $.session.start(SESSION)
await $.command.run(command('automate'))
const pane = await $.ui.mount({ ...paneAt(150), surface: 'terminal' as const, plugin: PLUGIN })
await pane.drawn()
await pane.press({ key: 'sec-loops' })
await pane.press({ key: 'loop-pick-worker-audit' })
expect(textOf(await pane.drawn())).toContain('not ready: /ruflo-loop-workers:ruflo-loop is not offered by this session')
await pane.press({ key: 'loop-start' })
expect(textOf(await pane.drawn())).not.toContain('Confirm: start a loop')
expect(world.prompts).toEqual([])
await pane.unmount()
})
})