📌 Description
The bus.Bus interface in internal/bus/bus.go has only one implementation (internal/bus/natsbus/natsbus.go) and no tests. Handlers that publish events (e.g. internal/handlers/github_webhooks.go) can only be exercised against a real NATS server, making them hard to test. There is no in-memory/fake Bus.
💡 Why it matters: A fake bus unblocks fast, hermetic tests for every publisher and documents the contract the real NATS bus must satisfy.
🧩 Requirements and context
- Add an in-memory
Bus implementation (e.g. internal/bus/membus) recording published subjects/payloads and supporting Close.
- Cover
natsbus.Publish behavior: nil-connection guard and context-cancellation handling, using a connection stub or nats-server test helper.
- Document when to use the fake vs the real bus in
PATCHWORK_BACKEND_ARCHITECTURE.md.
- Keep the
Bus interface unchanged.
- Wire the fake into at least one handler test to prove the seam.
Non-functional requirements
- Must be secure, tested, and documented.
- Should be efficient and easy to review.
🛠️ Suggested execution
1. Fork the repo and create a branch
git checkout -b test/in-memory-bus
2. Implement changes
- Write/modify the relevant source: new
internal/bus/membus/membus.go
- Write comprehensive tests:
internal/bus/membus/membus_test.go, internal/bus/natsbus/natsbus_test.go
- Add documentation: architecture doc note on testing the bus
- Include GoDoc comments on the fake
- Validate security assumptions: fake must not be selectable in production builds
3. Test and commit
go test ./internal/bus/...
- Cover edge cases: publish after close, cancelled context, nil conn
- Include test output and security notes in the PR description.
Example commit message
test(bus): add in-memory bus and cover natsbus publish/close
✅ Acceptance criteria
🔒 Security notes
Ensure the in-memory bus is test-only and cannot be accidentally wired into cmd/api/cmd/worker.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
The
bus.Businterface ininternal/bus/bus.gohas only one implementation (internal/bus/natsbus/natsbus.go) and no tests. Handlers that publish events (e.g.internal/handlers/github_webhooks.go) can only be exercised against a real NATS server, making them hard to test. There is no in-memory/fakeBus.🧩 Requirements and context
Busimplementation (e.g.internal/bus/membus) recording published subjects/payloads and supportingClose.natsbus.Publishbehavior: nil-connection guard and context-cancellation handling, using a connection stub ornats-servertest helper.PATCHWORK_BACKEND_ARCHITECTURE.md.Businterface unchanged.Non-functional requirements
🛠️ Suggested execution
1. Fork the repo and create a branch
2. Implement changes
internal/bus/membus/membus.gointernal/bus/membus/membus_test.go,internal/bus/natsbus/natsbus_test.go3. Test and commit
go test ./internal/bus/...Example commit message
✅ Acceptance criteria
Busimplementation added and testednatsbusnil-conn and context-cancel paths coveredBusinterface unchanged🔒 Security notes
Ensure the in-memory bus is test-only and cannot be accidentally wired into
cmd/api/cmd/worker.📋 Guidelines