mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
test(api-contract): share retained view fixture calls (#16335)
This commit is contained in:
1 parent
20230a138d
commit
aef3fb790d
1 file changed
+55
-87
@@ -31,21 +31,22 @@ const retained = (evidence: Evidence) => ({
|
||||
evidence_id: evidence.evidence_id,
|
||||
});
|
||||
|
||||
const inspectRetainedView = async (
|
||||
call: McpCall,
|
||||
source: ReturnType<typeof retained>,
|
||||
view: Record<string, unknown>,
|
||||
) => asView(await call("inspect_analysis_view", { source, view }));
|
||||
|
||||
const checkRetainedPages = async (call: McpCall, parent: Evidence) => {
|
||||
const report = apiContractSchema.parse(parent.normalized_result);
|
||||
const rows = [];
|
||||
for (let offset = 0; offset < 19; offset += 5) {
|
||||
const page = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source: retained(parent),
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
offset,
|
||||
limit: 5,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const page = await inspectRetainedView(call, retained(parent), {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
offset,
|
||||
limit: 5,
|
||||
});
|
||||
expect(page.kind).toBe("api-contract");
|
||||
if (page.kind !== "api-contract")
|
||||
throw new Error("Expected operation page");
|
||||
@@ -54,18 +55,13 @@ const checkRetainedPages = async (call: McpCall, parent: Evidence) => {
|
||||
expect(page.coverage.exhausted).toBe(offset + 5 >= 19);
|
||||
}
|
||||
expect(rows).toEqual(report.operations);
|
||||
const selected = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source: retained(parent),
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
paths: ["/pet/{petId}"],
|
||||
methods: ["GET"],
|
||||
fields: [],
|
||||
},
|
||||
}),
|
||||
);
|
||||
const selected = await inspectRetainedView(call, retained(parent), {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
paths: ["/pet/{petId}"],
|
||||
methods: ["GET"],
|
||||
fields: [],
|
||||
});
|
||||
expect(selected.kind).toBe("api-contract");
|
||||
if (selected.kind !== "api-contract")
|
||||
throw new Error("Expected selected page");
|
||||
@@ -91,30 +87,24 @@ const checkRetainedPages = async (call: McpCall, parent: Evidence) => {
|
||||
{ paths: [] },
|
||||
{ declared_ids: [] },
|
||||
]) {
|
||||
const empty = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source: retained(parent),
|
||||
view: { kind: "api-contract", collection: "operations", ...filter },
|
||||
}),
|
||||
);
|
||||
const empty = await inspectRetainedView(call, retained(parent), {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
...filter,
|
||||
});
|
||||
expect(empty).toMatchObject({
|
||||
items: [],
|
||||
coverage: { total: 0, exhausted: true },
|
||||
source_coverage: report.source_coverage,
|
||||
});
|
||||
}
|
||||
const batch = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source: retained(parent),
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
operation_keys: report.operations
|
||||
.slice(0, 2)
|
||||
.map((row) => row.operation_key),
|
||||
},
|
||||
}),
|
||||
);
|
||||
const batch = await inspectRetainedView(call, retained(parent), {
|
||||
kind: "api-contract",
|
||||
collection: "operations",
|
||||
operation_keys: report.operations
|
||||
.slice(0, 2)
|
||||
.map((row) => row.operation_key),
|
||||
});
|
||||
expect(batch).toMatchObject({
|
||||
items: report.operations.slice(0, 2),
|
||||
coverage: { total: 2 },
|
||||
@@ -351,12 +341,10 @@ cliTest(
|
||||
declared: 3,
|
||||
unresolved_path_items: 0,
|
||||
});
|
||||
const referencePage = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source: retained(parent),
|
||||
view: { kind: "api-contract", collection: "path-item-references" },
|
||||
}),
|
||||
);
|
||||
const referencePage = await inspectRetainedView(call, retained(parent), {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
});
|
||||
expect(referencePage).toMatchObject({
|
||||
items: [
|
||||
{
|
||||
@@ -368,16 +356,11 @@ cliTest(
|
||||
});
|
||||
// Unresolved references stay findable without paging resolved ones.
|
||||
expect(
|
||||
asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source: retained(parent),
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
states: ["unresolved", "malformed"],
|
||||
},
|
||||
}),
|
||||
),
|
||||
await inspectRetainedView(call, retained(parent), {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
states: ["unresolved", "malformed"],
|
||||
}),
|
||||
).toMatchObject({ items: [], coverage: { total: 0, exhausted: true } });
|
||||
const cliResult = await cli.run({
|
||||
arguments: ["inspect-api-contract", path, "--json"],
|
||||
@@ -440,32 +423,22 @@ cliTest(
|
||||
diagnostics: 1,
|
||||
});
|
||||
const source = retained(parent);
|
||||
const refs = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source,
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
limit: 64,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const refs = await inspectRetainedView(call, source, {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
limit: 64,
|
||||
});
|
||||
expect(refs).toMatchObject({
|
||||
items: [{ reference: "#/paths/~1pet" }, { reference }],
|
||||
coverage: { exhausted: true },
|
||||
source_coverage: { status: "partial" },
|
||||
});
|
||||
for (const fields of [[], ["reference"]]) {
|
||||
const narrow = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source,
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
fields,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const narrow = await inspectRetainedView(call, source, {
|
||||
kind: "api-contract",
|
||||
collection: "path-item-references",
|
||||
fields,
|
||||
});
|
||||
expect(narrow).toMatchObject({
|
||||
items: report.path_item_references.map(({ reference_id, reason }) => ({
|
||||
reference_id,
|
||||
@@ -473,16 +446,11 @@ cliTest(
|
||||
})),
|
||||
});
|
||||
}
|
||||
const diagnostics = asView(
|
||||
await call("inspect_analysis_view", {
|
||||
source,
|
||||
view: {
|
||||
kind: "api-contract",
|
||||
collection: "diagnostics",
|
||||
codes: ["invalid-operation"],
|
||||
},
|
||||
}),
|
||||
);
|
||||
const diagnostics = await inspectRetainedView(call, source, {
|
||||
kind: "api-contract",
|
||||
collection: "diagnostics",
|
||||
codes: ["invalid-operation"],
|
||||
});
|
||||
expect(diagnostics).toMatchObject({
|
||||
items: [
|
||||
{ code: "invalid-operation", source_pointer: "/paths/~1broken/get" },
|
||||
|
||||
Reference in new issue
Block a user