fix(02-12): reject divergent shared-record state

- Verify the active record matches its canonical switcher entry\n- Skip the owner OCR probe in delegated Labs records
This commit is contained in:
Marc-André Bombeck committed 2026-08-06 13:39:37 +02:00
1 parent 358bb39465
commit b844d04676
6 files changed
+129 -3

No files matched your search

@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest";
import { shouldProbeOcrCapability } from "../use-ocr-extract";
describe("shouldProbeOcrCapability", () => {
it("runs the owner-only capability probe only when the scan control can render", () => {
const ownerControl = {
isAuthenticated: true,
isLoading: false,
labsEnabled: true,
mounted: true,
canManage: true,
};
expect(shouldProbeOcrCapability(ownerControl)).toBe(true);
expect(
shouldProbeOcrCapability({ ...ownerControl, isAuthenticated: false }),
).toBe(false);
expect(
shouldProbeOcrCapability({ ...ownerControl, canManage: false }),
).toBe(false);
expect(
shouldProbeOcrCapability({ ...ownerControl, labsEnabled: false }),
).toBe(false);
expect(shouldProbeOcrCapability({ ...ownerControl, mounted: false })).toBe(
false,
);
});
});
+17
View File
@@ -40,6 +40,23 @@ export interface OcrCommitResult extends OcrCommitResponseDto {
inserted: LabResultDto[];
}
/** The capability route resolves the caller's own provider configuration. */
export function shouldProbeOcrCapability({
isAuthenticated,
isLoading,
labsEnabled,
mounted,
canManage,
}: {
isAuthenticated: boolean;
isLoading: boolean;
labsEnabled: boolean;
mounted: boolean;
canManage: boolean;
}): boolean {
return isAuthenticated && !isLoading && labsEnabled && mounted && canManage;
}
/** Capability probe — refetched when the scan dialog opens. */
export function useOcrCapability(enabled: boolean) {
return useQuery<OcrCapabilityDto>({