--- id: 01-wire-use-case-helper epic: binder-wrap-helper title: wireUseCase helper + tests in core-shared/conformance type: technical-story status: in-progress feature: core-shared depends-on: [] blocks: [ 02-migrate-auth-binders, 03-migrate-blog-binders, 04-migrate-media-binders, 05-migrate-marketing-pages-binders, 06-migrate-navigation-binders, 07-update-feature-generator, ] --- ## Goal Create `packages/core-shared/src/conformance/wire-use-case.ts` exporting a `wireUseCase(...)` helper that encapsulates the `withSpan + withCapture (+ optional withAudit)` composition and performs the container bind step, then unit-test every branch. ## Why This is the prerequisite for all migration stories. Without the helper, binders have no shared point to delegate to, and each migration story would be writing its own abstraction. The helper must land first so migration stories can be validated independently. ## Done when - `packages/core-shared/src/conformance/wire-use-case.ts` exists with the helper and all supporting types. - `packages/core-shared/src/conformance/wire-use-case.test.ts` is green and covers: - no-audit path: Instrumented + Captured brands present on the wired value. - with-audit path: Instrumented + Captured + Audited brands present. - span name derivation: `.` matches existing binder convention. - capture tags: `{ feature, layer, name }` correctly applied. - container binding idempotency: calling `wireUseCase` twice on the same symbol unbinds then rebinds without error. - `wireUseCase` (and its companion types) exported from `packages/core-shared/src/conformance/index.ts`. - `pnpm test --filter @repo/core-shared -- --coverage` green; new file hits 100%. - `pnpm typecheck --filter @repo/core-shared` green. ## In scope - `wire-use-case.ts`: helper function + TypeScript generics for factory shape, deps tuple, and brand-stacked return type. - `wire-use-case.test.ts`: unit tests using `RecordingTracer`, `RecordingLogger`, and mock audit emitter from `core-testing` (mirror the pattern in `core-shared/instrumentation/` tests). - Export through `conformance/index.ts`. - `layer: "use-case" | "controller"` discriminator on the options object per the PRD open-question recommendation (Q1). - Idempotent bind logic inside the helper per Q3 recommendation. ## Out of scope - Controller-specific helper (`wireController`) — handled via the `layer` discriminator on the single helper. - Repository / service binding patterns — those stay as direct `.toConstantValue()` calls. - Changing `withSpan`, `withCapture`, `withAudit` internals — the helper only composes them. - Modifying the manifest schema. ## Tasks - [ ] Read `packages/core-shared/src/instrumentation/with-span.ts`, `with-capture.ts`, and `packages/core-audit/src/with-audit.ts` to capture exact signatures and brand attachment behaviour - [ ] Read `packages/core-shared/src/conformance/brands.ts` and `brand-runtime.ts` for `isInstrumented` / `isCaptured` / `isAudited` runtime helpers - [ ] Read `packages/core-shared/src/conformance/production-use-case.ts` for existing brand-stacking type reference - [ ] Write `packages/core-shared/src/conformance/wire-use-case.ts` — helper + options type + return type (no-audit and with-audit paths, `layer` discriminator, idempotent bind) - [ ] Write `packages/core-shared/src/conformance/wire-use-case.test.ts` — all branches: no-audit brands, with-audit brands, span name derivation, capture tags, idempotent rebind - [ ] Export `wireUseCase` and option/return types from `packages/core-shared/src/conformance/index.ts` - [ ] Run `pnpm typecheck --filter @repo/core-shared` — fix any type errors - [ ] Run `pnpm test --filter @repo/core-shared -- --coverage` — verify green + 100% on `wire-use-case.ts`