Files
ruflo/plugins/ruflo-console/tests/setup.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

93 lines
4.5 KiB
TypeScript

import { describe, expect, mock, test } from 'claude-code/testing'
import { RUFLO_FILES } from './fixtures/ruflo-run'
import { cliAnswer, command, HOME, paneAt, PLUGIN, SESSION, textOf, worldOf } from './fixtures/world'
describe('first-time setup', () => {
test('an empty offline CLI cache shows an explicit install command and never retries online', { timeoutMs: 30_000, options: { boot: false } }, async ($, on) => {
const world = worldOf(on, RUFLO_FILES)
world.respond = argv => argv[0] === 'npx'
? { exitCode: 1, stdout: '', stderr: 'npm warn unrelated warning\nnpm error code ENOTCACHED' }
: cliAnswer(argv)
mock.clock(on)
await $.session.start(SESSION)
await $.command.run(command('overview'))
const pane = await $.ui.mount({ ...paneAt(160), plugin: PLUGIN })
const text = textOf(await pane.drawn())
expect(text).toContain('ruflo CLI not cached')
expect(text).toContain('npx -y @claude-flow/cli@latest --version')
expect(text).not.toContain('npm error code ENOTCACHED')
const runs = world.runs.filter(argv => argv[0] === 'npx')
expect(runs.length).toBeGreaterThan(0)
expect(runs.every(argv => argv.includes('--offline'))).toBe(true)
await pane.unmount()
})
for (const present of [true, false]) {
test(`a confirmed federation join verifies key presence ${present} once while background federation is off`, { timeoutMs: 30_000, options: { boot: false } }, async ($, on) => {
const world = worldOf(on, RUFLO_FILES, { home: present ? { '.ruflo/nostr.key': 'never read this private key' } : {} })
world.respond = argv => argv.includes('federation') && argv.includes('join')
? { exitCode: 0, stdout: 'joined', stderr: '' }
: cliAnswer(argv)
mock.clock(on)
await $.session.start(SESSION)
await $.command.run(command('run federation-join'))
const keyStats = () => world.stats.filter(path => path === `${HOME}/.ruflo/nostr.key`)
const joins = () => world.runs.filter(argv => argv.includes('federation') && argv.includes('join'))
expect(keyStats()).toEqual([])
expect(joins()).toEqual([])
await $.command.run(command('yes'))
expect(joins()).toHaveLength(1)
expect(keyStats()).toHaveLength(1)
const pane = await $.ui.mount({ ...paneAt(160), plugin: PLUGIN })
const text = textOf(await pane.drawn())
expect(text).toContain(present ? ' · on disk' : ' · not on disk yet')
expect(world.reads).not.toContain(`${HOME}/.ruflo/nostr.key`)
await $.command.run(command('status'))
expect(keyStats()).toHaveLength(1)
if (present) {
await $.command.run(command('federation'))
const federation = textOf(await pane.drawn())
expect(federation).toContain('confirmed by JOIN')
expect(federation).not.toMatch(/Start here: Join the federation/i)
expect(keyStats()).toHaveLength(1)
// A receipt is display evidence, not proof the key still exists: a later read may create it again.
world.files.delete(`${HOME}/.ruflo/nostr.key`)
await $.command.run(command('status'))
await $.command.run(command('xruv'))
expect(textOf(await pane.drawn())).toContain('confirmed by JOIN')
await $.command.run(command('run x-read pub:general'))
expect(textOf(await pane.drawn())).toContain('Confirm: read x.ruv.io channel pub:general?')
expect(world.runs.some(argv => argv.includes('x_federation_channel_read'))).toBe(false)
expect(keyStats()).toHaveLength(1)
await $.command.run(command('no'))
}
await pane.unmount()
})
}
test('cancelled and failed joins never inspect the private key', { timeoutMs: 30_000, options: { boot: false } }, async ($, on) => {
const world = worldOf(on, RUFLO_FILES, { home: { '.ruflo/nostr.key': 'never read this private key' } })
world.respond = argv => argv.includes('federation') && argv.includes('join')
? { exitCode: 1, stdout: '', stderr: 'relay unavailable' }
: cliAnswer(argv)
mock.clock(on)
await $.session.start(SESSION)
await $.command.run(command('run federation-join'))
await $.command.run(command('no'))
expect(world.runs.some(argv => argv.includes('join'))).toBe(false)
await $.command.run(command('run federation-join'))
await $.command.run(command('yes'))
expect(world.runs.filter(argv => argv.includes('join'))).toHaveLength(1)
expect(world.stats.some(path => path.endsWith('nostr.key'))).toBe(false)
expect(world.reads.some(path => path.endsWith('nostr.key'))).toBe(false)
})
})