feat(profile): add the manual candidate profile contract and storage

This commit is contained in:
shira committed 2026-10-06 21:10:04 +03:00
1 parent d21fd49a42
commit e52ffe7bcb
97 files changed
+20442 -63

No files matched your search

+21 -5
View File
@@ -13,7 +13,8 @@
// src/shared/api/mock-pattern.ts. The bounds come from the OpenAPI document:
// the call's enclosing object property and the pattern identify the schema.
// The rewrite fails when a call has an unexpected form, when no schema
// matches, or when schemas that match disagree on the bounds, so a contract
// matches, or when the bounds of schemas that match have no common value;
// schemas that match with different bounds share their intersection, so a contract
// change cannot silently produce invalid mocks. Running it again on its own
// output changes nothing.
//
@@ -207,14 +208,29 @@ function findBounds(
`${location}: no schema property "${property}" with pattern ${JSON.stringify(pattern)} in the OpenAPI document.`,
);
}
if (candidates.length > 1) {
if (candidates.length === 1) {
return bounds;
}
// The generated mock does not say which schema owns the call, so schemas
// that share a property name and a pattern share one set of bounds: the
// intersection. A value inside it satisfies every one of those schemas.
const minLength = Math.max(...candidates.map((item) => item.minLength ?? 0));
const maxima = candidates.flatMap((item) =>
item.maxLength === undefined ? [] : [item.maxLength],
);
const maxLength = maxima.length === 0 ? undefined : Math.min(...maxima);
if (maxLength !== undefined && minLength > maxLength) {
throw new Error(
`${location}: properties named "${property}" with pattern ${JSON.stringify(pattern)} have different length bounds (${candidates
`${location}: properties named "${property}" with pattern ${JSON.stringify(pattern)} have length bounds (${candidates
.map(describeBounds)
.join("; ")}), so the mock bounds are ambiguous.`,
.join("; ")}) that no value satisfies together, so the mock bounds are ambiguous.`,
);
}
return bounds;
const anyMin = candidates.some((item) => item.minLength !== undefined);
return {
...(anyMin ? { minLength } : {}),
...(maxLength === undefined ? {} : { maxLength }),
};
}
/**