mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 04:34:13 +00:00
Inspect local Maven/Gradle metadata as Evidence with bounded report/XML admission, preserved caller choices and owned cleanup. Refs #8828; broader comparison and resolution work remains outside this change. Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning) Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
156 lines
5.2 KiB
TypeScript
156 lines
5.2 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import {
|
|
inspectMavenGradleMetadataInputSchema,
|
|
mavenGradleMetadataSchema,
|
|
mavenPropertyOccurrences,
|
|
requestedVersionKind,
|
|
} from "./mavenGradleMetadata.js";
|
|
import { absoluteLocalPathStringSchema } from "../localPath.js";
|
|
|
|
const jsonSchema = (schema: {
|
|
readonly "~standard": {
|
|
readonly jsonSchema: {
|
|
readonly input: (options: {
|
|
readonly target: "draft-2020-12";
|
|
}) => unknown;
|
|
};
|
|
};
|
|
}): Record<string, unknown> =>
|
|
schema["~standard"].jsonSchema.input({
|
|
target: "draft-2020-12",
|
|
}) as Record<string, unknown>;
|
|
|
|
it("applies the shared absolute local-path policy to the public input", () => {
|
|
expect(
|
|
inspectMavenGradleMetadataInputSchema.safeParse({ path: "pom.xml" })
|
|
.success,
|
|
).toBe(false);
|
|
expect(
|
|
inspectMavenGradleMetadataInputSchema.safeParse({ path: "" }).success,
|
|
).toBe(false);
|
|
expect(
|
|
inspectMavenGradleMetadataInputSchema.safeParse({
|
|
path: "/artifacts/pom\0.xml",
|
|
}).success,
|
|
).toBe(false);
|
|
expect(
|
|
inspectMavenGradleMetadataInputSchema.safeParse({
|
|
path: "/artifacts/pom.xml",
|
|
}).success,
|
|
).toBe(true);
|
|
|
|
const shared = jsonSchema(absoluteLocalPathStringSchema);
|
|
const advertised = jsonSchema(inspectMavenGradleMetadataInputSchema);
|
|
const path = (
|
|
advertised.properties as Record<string, Record<string, unknown>>
|
|
).path;
|
|
const {
|
|
$schema: _schema,
|
|
description: _sharedDescription,
|
|
...sharedPolicy
|
|
} = shared;
|
|
const { description: _pathDescription, ...pathPolicy } = path ?? {};
|
|
expect(pathPolicy).toEqual(sharedPolicy);
|
|
expect(path?.description).toBe(
|
|
"Absolute filesystem path to a Maven pom.xml or Gradle .module metadata file",
|
|
);
|
|
});
|
|
|
|
it("rejects extra caller arguments", () => {
|
|
expect(
|
|
inspectMavenGradleMetadataInputSchema.safeParse({
|
|
path: "/artifacts/pom.xml",
|
|
extra: true,
|
|
}).success,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("classifies requested versions without interpolating properties", () => {
|
|
expect([...mavenPropertyOccurrences("${revision}")]).toEqual(["${revision}"]);
|
|
expect([
|
|
...mavenPropertyOccurrences("${revision}${sha1}${changelist}"),
|
|
]).toEqual(["${revision}", "${sha1}", "${changelist}"]);
|
|
expect([...mavenPropertyOccurrences("1.2.3")]).toEqual([]);
|
|
expect([...mavenPropertyOccurrences("${}${a${b}")]).toEqual(["${a${b}"]);
|
|
expect([...mavenPropertyOccurrences("${a".repeat(100_000))]).toEqual([]);
|
|
expect(requestedVersionKind("${jackson.version}", "maven-pom")).toBe(
|
|
"property",
|
|
);
|
|
expect(requestedVersionKind("[5.10,6.0)", "maven-pom")).toBe("range");
|
|
expect(requestedVersionKind("(,1.0]", "maven-pom")).toBe("range");
|
|
expect(requestedVersionKind("2.17.2", "maven-pom")).toBe("literal");
|
|
expect(requestedVersionKind(null, "maven-pom")).toBe("missing");
|
|
expect(requestedVersionKind("]1.0,2.0]", "gradle-module")).toBe("range");
|
|
expect(requestedVersionKind("[1.0,2.0[", "gradle-module")).toBe("range");
|
|
expect(requestedVersionKind("1.0]", "maven-pom")).toBe("literal");
|
|
expect(requestedVersionKind("1.+", "gradle-module")).toBe("dynamic");
|
|
expect(requestedVersionKind("+", "gradle-module")).toBe("dynamic");
|
|
expect(requestedVersionKind("latest.release", "gradle-module")).toBe(
|
|
"dynamic",
|
|
);
|
|
expect(requestedVersionKind("latest.integration", "gradle-module")).toBe(
|
|
"dynamic",
|
|
);
|
|
expect(requestedVersionKind("1.2.3", "gradle-module")).toBe("literal");
|
|
expect(requestedVersionKind("1.+", "maven-pom")).toBe("literal");
|
|
});
|
|
|
|
it("offers property occurrences lazily without retaining or deduplicating a collection", () => {
|
|
const occurrences = mavenPropertyOccurrences("${first}${first}${second}");
|
|
expect(occurrences.next()).toEqual({ value: "${first}", done: false });
|
|
expect(occurrences.next()).toEqual({ value: "${first}", done: false });
|
|
expect(occurrences.next()).toEqual({ value: "${second}", done: false });
|
|
expect(occurrences.next().done).toBe(true);
|
|
});
|
|
|
|
it("admits a complete POM report with unresolved parent and property references", () => {
|
|
const report = mavenGradleMetadataSchema.parse({
|
|
artifact: {
|
|
path: "/artifacts/pom.xml",
|
|
sha256: "a".repeat(64),
|
|
bytes: 16,
|
|
},
|
|
format: "maven-pom",
|
|
coordinates: {
|
|
group_id: null,
|
|
artifact_id: "demo",
|
|
version: "${revision}",
|
|
packaging: "jar",
|
|
},
|
|
parent: {
|
|
group_id: "com.example",
|
|
artifact_id: "demo-parent",
|
|
version: "9.0.0",
|
|
packaging: null,
|
|
relative_path: "../pom.xml",
|
|
relative_path_declared: true,
|
|
},
|
|
properties: [
|
|
{ name: "revision", value: "1.2.3", value_credentials_redacted: false },
|
|
],
|
|
dependencies: [],
|
|
dependency_management: [],
|
|
gradle: null,
|
|
unresolved: [
|
|
{
|
|
kind: "parent-coordinate",
|
|
reference: "parent.group_id",
|
|
field: "group_id",
|
|
owner: "project",
|
|
index: null,
|
|
},
|
|
{
|
|
kind: "property",
|
|
reference: "${revision}",
|
|
field: "version",
|
|
owner: "project",
|
|
index: null,
|
|
},
|
|
],
|
|
coverage: { status: "complete", examined_bytes: 16 },
|
|
limitations: ["No Maven or Gradle execution was performed."],
|
|
});
|
|
expect(report.coordinates.artifact_id).toBe("demo");
|
|
expect(report.unresolved).toHaveLength(2);
|
|
});
|