Skip to content

arch: migrate EventBus tests from layer() to per-test Layer.build #281

Description

@cursor

Problem

.agents/rules/stack.md requires per-test Layer.build inside it.effect bodies. Using @effect/vitest layer(...) memoizes the Layer graph across tests in a suite, which can leak stateful services between tests.

Current violations:

  • packages/server/test/events.test.ts — layer(EventBusLayer)("EventBus", ...)
  • packages/server/test/harness/session.test.ts — module-scoped const layer = SessionServiceLayer.pipe(Layer.provide(EventBusLayer)) with a shared run() helper

packages/server/test/observability/turn-log.test.ts already documents the correct pattern with an inline comment explaining why layer(EventBusLayer) is wrong.

Why it matters

Stateful services (EventBus, session instances) can leak between tests, producing order-dependent failures that are hard to reproduce.

Suggested fix

Migrate these suites to @effect/vitest it.effect with Layer.build (or scoped Effect.gen) per test, matching turn-log.test.ts and launcher.test.ts.

Related

Severity

P2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions