mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 10:04:50 +00:00
* feat(metadata)!: give NTFS, Maven report and NuGet budgets typed per-call controls inspect_ntfs_journal refused acquisitions above a fixed 64 MiB allowance; it now takes max_file_bytes (default 64 MiB) and re-admits a retained acquisition under the call's budget, so lowering it cannot reuse a larger cached read. inspect_maven_gradle_metadata refused at six fixed report allowances; they are now report_limits fields (CLI --report-limits JSON) with today's values as defaults. Maven max_file_bytes and NuGet max_file_bytes, max_entries and max_nuspec_bytes refusals now report details.limit from the same bounds objects the schemas use. The Ghidra installation-properties read allowance is registered as a protocol bound: it reads the provider's own short installation descriptor, not analysis input. BREAKING CHANGE: NTFS and Maven report refusals report details.limit instead of a fixed_ceiling refusal, and parseMavenGradleMetadata and the inspect_ntfs_journal input contract gain the new controls. * fix(metadata): keep omitted NTFS budgets omitted and type host and maximum recovery inspect_ntfs_journal recorded the default max_file_bytes as if the caller had chosen it; the field is now optional and resolved for execution only, so Evidence keeps omission. A host allocation failure while holding an admitted acquisition is reported as measured memory exhaustion instead of generic I/O. A Maven report refusal whose need exceeds the control's maximum no longer suggests raising it. A public CLI/MCP test covers report_limits refusal and recovery for a POM.
158 lines
5.8 KiB
TypeScript
158 lines
5.8 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createMavenGradleMetadataService } from "../../../src/composition/mavenGradleMetadata.js";
|
|
import { mavenGradleMetadataSchema } from "../../../src/domain/java/mavenGradleMetadata.js";
|
|
import { mavenPomFixture } from "../../../src/java/MavenGradleMetadata.fixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
describe("Maven POM and Gradle module metadata stable filesystem boundary", () => {
|
|
it("admits a minimal Gradle document by its first decoded member", async () => {
|
|
const root = await createTestTempDirectory("rea-gradle-format-order-");
|
|
const path = join(root, "module.json");
|
|
const service = createMavenGradleMetadataService();
|
|
const inspect = async (source: string) => {
|
|
await writeFile(path, source);
|
|
return service.inspect({ path });
|
|
};
|
|
try {
|
|
// JSON object enumeration promotes numeric keys ahead of string keys.
|
|
const minimal = await inspect(
|
|
String.raw`{"f\u006frmatVersion":"1.1","0":null}`,
|
|
);
|
|
if (!minimal.ok) throw minimal.error;
|
|
expect(minimal.value.normalized_result).toMatchObject({
|
|
format: "gradle-module",
|
|
gradle: { format_version: "1.1", variants: [] },
|
|
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":[]}',
|
|
'{"formatVersion":"1.1","createdBy":[]}',
|
|
'{"formatVersion":"1.1","createdBy":{"gradle":false}}',
|
|
'{"formatVersion":"1.1","variants":[{"name":"runtime","attributes":[]}]}',
|
|
]) {
|
|
const result = await inspect(invalid);
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "AnalysisTargetFailureError" },
|
|
});
|
|
}
|
|
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();
|
|
}
|
|
});
|
|
|
|
it("uses exact Gradle variant names to identify their dependency rows", async () => {
|
|
const root = await createTestTempDirectory("rea-gradle-variant-identity-");
|
|
const path = join(root, "demo.module");
|
|
const service = createMavenGradleMetadataService();
|
|
const inspect = async (names: readonly unknown[]) => {
|
|
const variants = names.map((name, index) => ({
|
|
name,
|
|
dependencies: [{ group: "example", module: `dep-${String(index)}` }],
|
|
dependencyConstraints: [{ group: "example", module: "shared" }],
|
|
}));
|
|
await writeFile(path, JSON.stringify({ formatVersion: "1.1", variants }));
|
|
return service.inspect({ path });
|
|
};
|
|
try {
|
|
const whitespaceOnlyName = " \t ";
|
|
const distinct = await inspect([
|
|
"runtime",
|
|
" runtime ",
|
|
"",
|
|
undefined,
|
|
whitespaceOnlyName,
|
|
"",
|
|
undefined,
|
|
]);
|
|
if (!distinct.ok) throw distinct.error;
|
|
const report = mavenGradleMetadataSchema.parse(
|
|
distinct.value.normalized_result,
|
|
);
|
|
const expectedNames = [
|
|
"runtime",
|
|
" runtime ",
|
|
null,
|
|
null,
|
|
whitespaceOnlyName,
|
|
null,
|
|
null,
|
|
];
|
|
expect(report.gradle?.variants.map((row) => row.name)).toEqual(
|
|
expectedNames,
|
|
);
|
|
expect(report.dependencies.map((row) => row.variant)).toEqual(
|
|
expectedNames,
|
|
);
|
|
expect(report.dependency_management.map((row) => row.variant)).toEqual(
|
|
expectedNames,
|
|
);
|
|
expect(await inspect(["runtime", "runtime"])).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisTargetFailureError",
|
|
failure: {
|
|
detail: expect.stringContaining("duplicate variant name"),
|
|
},
|
|
},
|
|
});
|
|
expect(await inspect([false])).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisTargetFailureError",
|
|
failure: { detail: expect.stringContaining("variant.name") },
|
|
},
|
|
});
|
|
} finally {
|
|
await service.close();
|
|
}
|
|
});
|
|
|
|
it("returns typed resource and cancellation failures", async () => {
|
|
const root = await createTestTempDirectory("rea-maven-gradle-budget-");
|
|
const path = join(root, "pom.xml");
|
|
await writeFile(path, mavenPomFixture);
|
|
const service = createMavenGradleMetadataService();
|
|
try {
|
|
const tooSmall = await service.inspect({ path, max_file_bytes: 16 });
|
|
if (tooSmall.ok) throw new Error("Expected resource budget failure");
|
|
expect(tooSmall.error._tag).toBe("AnalysisResourceConstraintError");
|
|
expect(tooSmall.error.limit).toMatchObject({
|
|
control_kind: "parameter",
|
|
parameter: "max_file_bytes",
|
|
effective_value: 16,
|
|
maximum: 16 * 1024 * 1024,
|
|
default_value: 1024 * 1024,
|
|
});
|
|
const cancelled = await service.inspect(
|
|
{ path },
|
|
{ signal: AbortSignal.abort() },
|
|
);
|
|
if (cancelled.ok) throw new Error("Expected cancellation");
|
|
expect(cancelled.error._tag).toBe("AnalysisCancelledError");
|
|
const control = await service.inspect({ path });
|
|
if (!control.ok) throw control.error;
|
|
} finally {
|
|
await service.close();
|
|
}
|
|
});
|
|
});
|