feat(core-shared): add rate-limit type primitives and manifest field
Adds IRateLimit, RateLimitBudget, RateLimitDecision to a new rate-limit sub-module; adds RateLimited<F> brand and isRateLimited predicate following the Captured/ConsentChecked pattern; extends UseCaseManifest with rateLimit?: readonly RateLimitBudget[] so features can declare rate-limit gates in their manifests. Exports new types from @repo/core-shared/rate-limit and @repo/core-shared/conformance. Blocks stories 02, 03, and 04. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,9 @@ import { describe, it, expect, expectTypeOf } from "vitest";
|
||||
import {
|
||||
defineFeature,
|
||||
type FeatureManifest,
|
||||
type UseCaseManifest,
|
||||
} from "@/conformance/define-feature";
|
||||
import type { RateLimitBudget } from "@/rate-limit/rate-limit.interface";
|
||||
import {
|
||||
DEFAULT_COVERAGE_BANDS,
|
||||
DEFAULT_MUTATION_SCORE,
|
||||
@@ -58,6 +60,41 @@ describe("defineFeature", () => {
|
||||
expectTypeOf(manifest).toMatchTypeOf<FeatureManifest>();
|
||||
});
|
||||
|
||||
it("accepts an optional rateLimit array on a use case", () => {
|
||||
const manifest = defineFeature({
|
||||
name: "auth",
|
||||
requiredCores: [],
|
||||
useCases: {
|
||||
signIn: {
|
||||
mutates: false,
|
||||
audits: [],
|
||||
publishes: [],
|
||||
consumes: [],
|
||||
rateLimit: [{ name: "login", window: "1m", budget: 5 }],
|
||||
},
|
||||
},
|
||||
realtimeChannels: [],
|
||||
jobs: [],
|
||||
} as const);
|
||||
|
||||
expectTypeOf(manifest).toMatchTypeOf<FeatureManifest>();
|
||||
expectTypeOf(manifest.useCases.signIn.rateLimit).toMatchTypeOf<
|
||||
readonly RateLimitBudget[] | undefined
|
||||
>();
|
||||
});
|
||||
|
||||
it("use case without rateLimit satisfies UseCaseManifest", () => {
|
||||
const uc: UseCaseManifest = {
|
||||
mutates: false,
|
||||
audits: [],
|
||||
publishes: [],
|
||||
consumes: [],
|
||||
};
|
||||
expectTypeOf(uc.rateLimit).toEqualTypeOf<
|
||||
readonly RateLimitBudget[] | undefined
|
||||
>();
|
||||
});
|
||||
|
||||
it("accepts an optional coverage section", () => {
|
||||
const manifest = defineFeature({
|
||||
name: "auth",
|
||||
|
||||
Reference in New Issue
Block a user