diff --git a/src/firmware/vectorTable/FirmwareVectorTableProvider.test.ts b/src/firmware/vectorTable/FirmwareVectorTableProvider.test.ts index 2db264c6cf..01f48e1468 100644 --- a/src/firmware/vectorTable/FirmwareVectorTableProvider.test.ts +++ b/src/firmware/vectorTable/FirmwareVectorTableProvider.test.ts @@ -1,3 +1,4 @@ +import { expectXmlElementDepthRefusal } from "../../../tests/support/expectXmlElementDepthRefusal.js"; import { createHash } from "node:crypto"; import { lstat, open, realpath, writeFile } from "node:fs/promises"; import { join } from "node:path"; @@ -11,10 +12,7 @@ import { } from "../../domain/analysisErrorCore.js"; import { projectAnalysisError } from "../../domain/analysisErrorProjection.js"; import { inspectFirmwareVectorTableInputSchema } from "../../domain/firmware/firmwareVectorTable.js"; -import { - XML_ELEMENT_DEPTH_ALLOWANCE, - XML_ELEMENT_DEPTH_LIMIT, -} from "../../domain/xmlDocument.js"; +import { XML_ELEMENT_DEPTH_LIMIT } from "../../domain/xmlDocument.js"; import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js"; import { FirmwareVectorTableProvider } from "./FirmwareVectorTableProvider.js"; import { @@ -305,28 +303,10 @@ describe("FirmwareVectorTableProvider", () => { !(result.error instanceof AnalysisResourceConstraintError) ) throw new Error("expected the XML depth ceiling"); - expect(projectAnalysisError(result.error)).toMatchObject({ - code: "resource_constraint", - retryable: false, - details: { - reason: `XML element depth exceeds ${String(XML_ELEMENT_DEPTH_LIMIT)}. This release has no runtime override for this ceiling.`, - reported_limits: { - boundary: "xml-element-depth", - maximum: XML_ELEMENT_DEPTH_LIMIT, - required: XML_ELEMENT_DEPTH_LIMIT + 1, - }, - refusal: { - kind: "fixed_ceiling", - allowance: XML_ELEMENT_DEPTH_ALLOWANCE.name, - allowance_kind: "parser", - limit: XML_ELEMENT_DEPTH_LIMIT, - unit: "levels", - }, - }, - remediation: { - action: expect.stringContaining("no runtime override"), - }, - }); + expectXmlElementDepthRefusal( + result.error, + `XML element depth exceeds ${String(XML_ELEMENT_DEPTH_LIMIT)}. This release has no runtime override for this ceiling.`, + ); } finally { await provider.close(); } diff --git a/src/java/MavenGradleMetadataParser.test.ts b/src/java/MavenGradleMetadataParser.test.ts index b84f97fa55..601e664dfb 100644 --- a/src/java/MavenGradleMetadataParser.test.ts +++ b/src/java/MavenGradleMetadataParser.test.ts @@ -1,3 +1,4 @@ +import { expectXmlElementDepthRefusal } from "../../tests/support/expectXmlElementDepthRefusal.js"; import { ParseFailureError } from "../domain/parseFailure.js"; import { createHash } from "node:crypto"; import { writeFile } from "node:fs/promises"; @@ -13,10 +14,7 @@ import { } from "./MavenGradleMetadata.fixture.js"; import { MavenGradleMetadataProvider } from "./MavenGradleMetadataProvider.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; -import { - XML_ELEMENT_DEPTH_ALLOWANCE, - XML_ELEMENT_DEPTH_LIMIT, -} from "../domain/xmlDocument.js"; +import { XML_ELEMENT_DEPTH_LIMIT } from "../domain/xmlDocument.js"; import { parseMavenGradleMetadata } from "./MavenGradleMetadataParser.js"; const parse = (source: string, path = "/artifacts/pom.xml") => { @@ -1163,27 +1161,7 @@ it("reports XML element depth from the provider instead of an I/O failure", asyn max_file_bytes: 1024 * 1024, }); if (result.ok) throw new Error("expected the XML depth ceiling"); - expect(projectAnalysisError(result.error)).toMatchObject({ - code: "resource_constraint", - retryable: false, - details: { - reported_limits: { - boundary: "xml-element-depth", - maximum: XML_ELEMENT_DEPTH_LIMIT, - required: XML_ELEMENT_DEPTH_LIMIT + 1, - }, - refusal: { - kind: "fixed_ceiling", - allowance: XML_ELEMENT_DEPTH_ALLOWANCE.name, - allowance_kind: "parser", - limit: XML_ELEMENT_DEPTH_LIMIT, - unit: "levels", - }, - }, - remediation: { - action: expect.stringContaining("no runtime override"), - }, - }); + expectXmlElementDepthRefusal(result.error); } finally { await provider.close(); } diff --git a/src/nuget/NugetNupkgParser.test.ts b/src/nuget/NugetNupkgParser.test.ts index 37876a413a..3b7482bd33 100644 --- a/src/nuget/NugetNupkgParser.test.ts +++ b/src/nuget/NugetNupkgParser.test.ts @@ -1,3 +1,4 @@ +import { expectXmlElementDepthRefusal } from "../../tests/support/expectXmlElementDepthRefusal.js"; import { ParseFailureError } from "../domain/parseFailure.js"; import { expect, it, vi } from "vitest"; import { createHash } from "node:crypto"; @@ -25,11 +26,7 @@ import { import { ArtifactReaderFailure } from "../resources/index.js"; import { NUPKG_LIMITATIONS, parseNugetNupkg } from "./NugetNupkgParser.js"; import { bufferByteSource } from "../domain/byteSource.js"; -import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; -import { - XML_ELEMENT_DEPTH_ALLOWANCE, - XML_ELEMENT_DEPTH_LIMIT, -} from "../domain/xmlDocument.js"; +import { XML_ELEMENT_DEPTH_LIMIT } from "../domain/xmlDocument.js"; import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js"; import { NugetNupkgProvider } from "./NugetNupkgProvider.js"; @@ -331,27 +328,7 @@ it.each([ inspectNugetNupkgInputSchema.parse({ path }), ); if (result.ok) throw new Error("expected the XML depth ceiling"); - expect(projectAnalysisError(result.error)).toMatchObject({ - code: "resource_constraint", - retryable: false, - details: { - reported_limits: { - boundary: "xml-element-depth", - maximum: XML_ELEMENT_DEPTH_LIMIT, - required: XML_ELEMENT_DEPTH_LIMIT + 1, - }, - refusal: { - kind: "fixed_ceiling", - allowance: XML_ELEMENT_DEPTH_ALLOWANCE.name, - allowance_kind: "parser", - limit: XML_ELEMENT_DEPTH_LIMIT, - unit: "levels", - }, - }, - remediation: { - action: expect.stringContaining("no runtime override"), - }, - }); + expectXmlElementDepthRefusal(result.error); } finally { await provider.close(); } diff --git a/src/vsix/VsixPackageParser.test.ts b/src/vsix/VsixPackageParser.test.ts index 78669e8ed6..8ac53f6e4c 100644 --- a/src/vsix/VsixPackageParser.test.ts +++ b/src/vsix/VsixPackageParser.test.ts @@ -1,8 +1,6 @@ +import { expectXmlElementDepthRefusal } from "../../tests/support/expectXmlElementDepthRefusal.js"; import { ParseFailureError } from "../domain/parseFailure.js"; -import { - XML_ELEMENT_DEPTH_ALLOWANCE, - XML_ELEMENT_DEPTH_LIMIT, -} from "../domain/xmlDocument.js"; +import { XML_ELEMENT_DEPTH_LIMIT } from "../domain/xmlDocument.js"; import { expect, it, vi } from "vitest"; import { createHash } from "node:crypto"; import { writeFile } from "node:fs/promises"; @@ -870,27 +868,7 @@ it("reports a deep vsixmanifest as the XML element-depth ceiling", async () => { ); expect(result.ok).toBe(false); if (result.ok) return; - expect(projectAnalysisError(result.error)).toMatchObject({ - code: "resource_constraint", - retryable: false, - details: { - reported_limits: { - boundary: "xml-element-depth", - maximum: XML_ELEMENT_DEPTH_LIMIT, - required: XML_ELEMENT_DEPTH_LIMIT + 1, - }, - refusal: { - kind: "fixed_ceiling", - allowance: XML_ELEMENT_DEPTH_ALLOWANCE.name, - allowance_kind: "parser", - limit: XML_ELEMENT_DEPTH_LIMIT, - unit: "levels", - }, - }, - remediation: { - action: expect.stringContaining("no runtime override"), - }, - }); + expectXmlElementDepthRefusal(result.error); } finally { await provider.close(); } diff --git a/tests/support/expectXmlElementDepthRefusal.ts b/tests/support/expectXmlElementDepthRefusal.ts new file mode 100644 index 0000000000..f8d9bbfbb3 --- /dev/null +++ b/tests/support/expectXmlElementDepthRefusal.ts @@ -0,0 +1,34 @@ +import { expect } from "vitest"; +import { projectAnalysisError } from "../../src/domain/analysisErrorProjection.js"; +import { + XML_ELEMENT_DEPTH_ALLOWANCE, + XML_ELEMENT_DEPTH_LIMIT, +} from "../../src/domain/xmlDocument.js"; + +export const expectXmlElementDepthRefusal = ( + error: Parameters[0], + reason?: string, +): void => { + expect(projectAnalysisError(error)).toMatchObject({ + code: "resource_constraint", + retryable: false, + details: { + ...(reason === undefined ? {} : { reason }), + reported_limits: { + boundary: "xml-element-depth", + maximum: XML_ELEMENT_DEPTH_LIMIT, + required: XML_ELEMENT_DEPTH_LIMIT + 1, + }, + refusal: { + kind: "fixed_ceiling", + allowance: XML_ELEMENT_DEPTH_ALLOWANCE.name, + allowance_kind: "parser", + limit: XML_ELEMENT_DEPTH_LIMIT, + unit: "levels", + }, + }, + remediation: { + action: expect.stringContaining("no runtime override"), + }, + }); +};