feat(core-dsr): Payload impls, recording doubles, DI binders, contract tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 20:05:06 +00:00
parent 8068d1bf98
commit 6606b59d1e
35 changed files with 2375 additions and 24 deletions

View File

@@ -0,0 +1,42 @@
// Local type aliases mirroring exports from `@repo/core-dsr`.
// Kept inline to avoid a build-graph cycle between core-testing (tooling)
// and core-dsr (optional core). Same pattern used by RecordingAuditLog,
// RecordingConsent, and other recording doubles.
/** Recorded setRestriction call. */
export type RecordedRestrictionSet = {
subjectId: string;
granted: boolean;
};
/**
* Test-side recording double for IProcessingRestriction. Records all
* setRestriction / isRestricted calls for assertion while maintaining the same
* state semantics as the real impl (isRestricted returns true after
* setRestriction(true), false after setRestriction(false)).
*
* Use directly via constructor injection:
* const restriction = new RecordingProcessingRestriction();
* const uc = myUseCase(restriction);
* await uc({ ... });
* expect(restriction.sets[0]?.granted).toBe(true);
* expect(await restriction.isRestricted("alice")).toBe(true);
*/
export class RecordingProcessingRestriction {
public sets: RecordedRestrictionSet[] = [];
private readonly state = new Map<string, boolean>();
async setRestriction(subjectId: string, granted: boolean): Promise<void> {
this.sets.push({ subjectId, granted });
this.state.set(subjectId, granted);
}
async isRestricted(subjectId: string): Promise<boolean> {
return this.state.get(subjectId) ?? false;
}
reset(): void {
this.sets = [];
this.state.clear();
}
}