test: add bus fallback and recovery flow tests #32

Merged
FO
5mo ago
+322-0

Summary

Adds test/fallback-recovery.test.ts with 10 test cases validating the bus fallback and recovery flow that underpins useServiceBus (src/tui-hooks.ts).

Test Cases

TestDescription
MemoryBusTui standaloneIn-process pub/sub via MemoryBus singleton
BusTui.connect() throwsWhen port file missing (Go bus unavailable)
BusTui.connect() recoverySucceeds after Go bus starts
Last-value cache on recoveryMessages published before subscribe arrive via cache
ScopedBusTui.forProject()forService().forProject() chaining (P1 bug #10 regression)
BusClient scoped compositionforService().forProject() on BusClient
useServiceBus recovery simMemoryBusTui fallback → retry → real BusTui
MemoryBusTui isolationClosing MemoryBusTui does not affect real BusTui

References

  • Issue: #32
  • src/tui-hooks.ts — useServiceBus hook (lines 46-59: MemoryBusTui fallback + 5s retry)
  • src/bus-tui.ts — BusTui.connect(), MemoryBusTui, ScopedBusTui
  • test/scoped-close.test.ts — scoped bus regression test (P1 bug #10)

Note: test/integration.test.ts has a pre-existing failure — the bus binary at /home/robby/four-opencode-plugin-bus/bus does not exist. The scoped-close test uses ~/.local/bin/four-local-bus which is correct.


Summary by cubic

Add test/fallback-recovery.test.ts to verify fallback to MemoryBusTui and recovery to BusTui used by useServiceBus. Confirms connect failure handling, last-value cache on subscribe, scoped chaining (forService().forProject()), BusClient composition, and isolation between memory and real buses; addresses Linear #32 and protects the P1 bug #10 regression.

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite validating plugin bus fallback and recovery mechanisms, including in-memory and real bus modes, connection failure scenarios, message caching behavior, and service chaining operations.