fix(gradle): disclose unfamiliar metadata revisions (#12648)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 01:22:36 +00:00
1 parent 17ada289ac
commit 78fdc7ecf7
3 files changed
+23 -6

No files matched your search

+5
View File
@@ -75,6 +75,11 @@ userinfo credentials in `available_at.url` are removed and
`url_credentials_redacted` is `true`; when the credential span cannot be
located, `url` is `null`.
For unfamiliar Gradle format versions with a recognizable metadata structure,
REA interprets familiar fields using the 1.1 rules and reports the limitation.
Complete byte coverage means the whole file was examined. Declarations specific
to an unfamiliar format version may still be unreported.
`unresolved` names every property reference in the coordinates, packaging, and
each dependency's scope, type, classifier, and optional, plus missing
coordinates that a parent would normally supply and other missing coordinates. These are explicit
+8 -5
View File
@@ -33,6 +33,8 @@ const BASE_LIMITATIONS = [
"Requested versions, ranges, and property spellings are recorded as written; interpolation and parent/BOM inheritance are not performed.",
] as const;
const GRADLE_MODULE_METADATA_VERSION = "1.1";
const isElement = (node: Node | null): node is Element =>
node !== null && node.nodeType === 1;
@@ -498,11 +500,8 @@ const parseGradle = (
);
const component = gradleObject(parsed.component, "component");
const variantsValue = parsed.variants;
if (
parsed.formatVersion !== "1.1" &&
component === null &&
!Array.isArray(variantsValue)
)
const knownVersion = parsed.formatVersion === GRADLE_MODULE_METADATA_VERSION;
if (!knownVersion && component === null && !Array.isArray(variantsValue))
throw unsupportedInput(
MAVEN_GRADLE_METADATA_FORMAT,
"Unrecognized Gradle module metadata formatVersion without component or variants.",
@@ -512,6 +511,10 @@ const parseGradle = (
"Gradle variant attributes other than category and usage are not decoded.",
"available-at coordinates are recorded as spelled; the named module file was not fetched.",
];
if (!knownVersion)
limitations.push(
`Recognized fields in this unfamiliar format version were interpreted using Gradle module metadata ${GRADLE_MODULE_METADATA_VERSION}. Version-specific declarations may be unreported.`,
);
const unresolved = new MavenGradleUnresolvedCollector();
const coordinates = {
group_id: component === null ? null : textOf(component.group),
@@ -26,6 +26,9 @@ describe("Maven POM and Gradle module metadata stable filesystem boundary", () =
dependencies: [],
coverage: { status: "complete" },
});
expect(minimal.value.limitations).not.toContainEqual(
expect.stringContaining("interpreted using Gradle module metadata 1.1"),
);
for (const invalid of [
'{"variants":[],"formatVersion":"1.1"}',
'{"formatVersion":"1.1","component":null,"variants":[]}',
@@ -39,11 +42,17 @@ describe("Maven POM and Gradle module metadata stable filesystem boundary", () =
error: { issues: [{ reason: "invalid_format" }] },
});
}
const unfamiliar = await inspect('{"formatVersion":"2.0","variants":[]}');
const unfamiliar = await inspect(
'{"formatVersion":"2.0","component":{"module":"demo"},"variants":[]}',
);
if (!unfamiliar.ok) throw unfamiliar.error;
expect(unfamiliar.value.normalized_result).toMatchObject({
coordinates: { artifact_id: "demo" },
gradle: { format_version: "2.0", variants: [] },
});
expect(unfamiliar.value.limitations).toContainEqual(
expect.stringContaining("interpreted using Gradle module metadata 1.1"),
);
} finally {
await service.close();
}