Release Schema Tools v0.1.1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
SCHEMA_LIMITS,
|
||||
compareSchemas,
|
||||
generateSample,
|
||||
inspectWorkspace,
|
||||
@@ -60,6 +61,51 @@ describe("schema workspace", () => {
|
||||
expect(invalid.diagnostics[0]?.message).toContain("required");
|
||||
});
|
||||
|
||||
it("bounds repeated large literal samples reached through local references", () => {
|
||||
const properties = Object.fromEntries(
|
||||
Array.from({ length: 100 }, (_, index) => [
|
||||
`value${index}`,
|
||||
{ $ref: "literal.json#/$defs/large" },
|
||||
]),
|
||||
);
|
||||
const workspace = inspectWorkspace([
|
||||
{
|
||||
name: "root.json",
|
||||
source: JSON.stringify({
|
||||
type: "object",
|
||||
required: Object.keys(properties),
|
||||
properties,
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "literal.json",
|
||||
source: JSON.stringify({
|
||||
$defs: { large: { default: "x".repeat(100_000) } },
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
const sample = generateSample(workspace);
|
||||
const values = Object.values(JSON.parse(sample.output) as object);
|
||||
expect(sample.output.length).toBeLessThanOrEqual(
|
||||
SCHEMA_LIMITS.sampleOutputChars,
|
||||
);
|
||||
expect(values).toHaveLength(100);
|
||||
expect(
|
||||
values.every(
|
||||
(value) => String(value).length <= SCHEMA_LIMITS.sampleValueChars,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(sample.notices.join("\n")).toMatch(/truncated.*safety bound/iu);
|
||||
});
|
||||
|
||||
it("refuses to claim a sample for the always-invalid false schema", () => {
|
||||
const workspace = inspectWorkspace([
|
||||
{ name: "impossible.json", source: "false" },
|
||||
]);
|
||||
expect(() => generateSample(workspace)).toThrow(/no valid sample/iu);
|
||||
});
|
||||
|
||||
it("blocks remote and missing references without attempting resolution", () => {
|
||||
const workspace = inspectWorkspace([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user