feat(core-shared): add Analyzed brand check to assertFeatureConformance

Mirrors the existing Audited check: when a use case declares
analyticsEvents.length > 0 and the bound function lacks the __analyzed
brand, assertFeatureConformance throws ConformanceError at boot time.

Adds three synthetic conformance tests: passes when brand present +
events declared, throws naming Analyzed when events declared + brand
missing, passes when events empty + brand absent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 15:19:29 +00:00
parent 81f75f756e
commit 92b17f7d64
3 changed files with 132 additions and 7 deletions

View File

@@ -1,6 +1,11 @@
import type { Container } from "inversify";
import type { FeatureManifest } from "./define-feature";
import { isInstrumented, isCaptured, isAudited } from "./brand-runtime";
import {
isInstrumented,
isCaptured,
isAudited,
isAnalyzed,
} from "./brand-runtime";
import { ConformanceError } from "./conformance-error";
import type { BindContext } from "../di/bind-context";
@@ -58,5 +63,12 @@ export function assertFeatureConformance(
);
}
}
if ((useCase.analyticsEvents?.length ?? 0) > 0) {
if (!isAnalyzed(bound)) {
throw new ConformanceError(
`${manifest.name}.${name}: declares analyticsEvents but binding is missing __analyzed brand — was withAnalytics applied at bind time?`,
);
}
}
}
}