feat(turbo): turbo gen feature generator (Phase 1, single-entity)
Adds `pnpm turbo gen feature` to scaffold a Lazar-conformant feature package matching the navigation reference shape: entity + Zod schema, single use case (`get<Entity>`), controller, mock + Payload-stub real repository (with span + capture), DI module/container/symbols, and tRPC router with full BAD_REQUEST/NOT_FOUND error mapping. The generated `bind-production.ts` and `bind-dev-seed.ts` compose the post-R44 `withSpan(tracer, opts, withCapture(logger, tags, factory(deps)))` sandwich at bind time. Verified by generating a sample `packages/example/` feature and running `pnpm --filter @repo/example lint typecheck test` — all three pass (9 test files, 25 tests). Cleaned up after verification so no example package is committed. Phase-1 limitations (documented in `docs/guides/scaffolding-a-feature.md` and printed by the generator on success): no Payload CMS templates, no React Query helpers, faker-driven factories left as stubs, single entity / single use case, and aggregator wiring (core-api/root, apps/web-next bindAll) is left as a manual checklist. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { it, expect, beforeEach, describe } from "vitest";
|
||||
import { defineContractSuite } from "@repo/core-testing/contract";
|
||||
import type { I{{pascalCase entity}}Repository } from "../application/repositories/{{kebabCase entity}}.repository.interface.js";
|
||||
import type { {{pascalCase entity}} } from "../entities/models/{{kebabCase entity}}.js";
|
||||
|
||||
/**
|
||||
* Known fixtures every implementation's `buildSubject` must pre-seed.
|
||||
* Exported so test files can pass them to `Mock{{pascalCase entity}}Repository` or the
|
||||
* Payload stub without duplicating definitions.
|
||||
*/
|
||||
export const CONTRACT_{{constantCase entity}}_SEED: ReadonlyArray<readonly [string, {{pascalCase entity}}]> = [
|
||||
["seed-1", { id: "seed-1", name: "Seed One" }],
|
||||
["seed-2", { id: "seed-2", name: "Seed Two" }],
|
||||
];
|
||||
|
||||
/**
|
||||
* Contract for I{{pascalCase entity}}Repository.
|
||||
*
|
||||
* The interface exposes only `get{{pascalCase entity}}(id)`. The contract verifies
|
||||
* found vs missing behaviour and span emission.
|
||||
*/
|
||||
export const {{camelCase entity}}RepositoryContract = defineContractSuite<I{{pascalCase entity}}Repository>(
|
||||
"I{{pascalCase entity}}Repository",
|
||||
({ buildSubject, getTracer }) => {
|
||||
let repo: I{{pascalCase entity}}Repository;
|
||||
|
||||
beforeEach(async () => {
|
||||
repo = await buildSubject();
|
||||
});
|
||||
|
||||
it("get{{pascalCase entity}} returns the seeded {{camelCase entity}} when id exists", async () => {
|
||||
const result = await repo.get{{pascalCase entity}}("seed-1");
|
||||
expect(result).not.toBeNull();
|
||||
expect(result?.id).toBe("seed-1");
|
||||
expect(typeof result?.name).toBe("string");
|
||||
});
|
||||
|
||||
it("get{{pascalCase entity}} returns null for an unknown id", async () => {
|
||||
const result = await repo.get{{pascalCase entity}}("does-not-exist");
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
describe("span emission", () => {
|
||||
it("get{{pascalCase entity}} emits span '{{camelCase entity}}.get{{pascalCase entity}}' with op=repository", async () => {
|
||||
if (!getTracer) return;
|
||||
const tracer = getTracer();
|
||||
tracer.reset();
|
||||
await repo.get{{pascalCase entity}}("seed-1");
|
||||
const span = tracer.findSpan("{{camelCase entity}}.get{{pascalCase entity}}");
|
||||
expect(span).toBeDefined();
|
||||
expect(span!.op).toBe("repository");
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user