Files
Tristan 52b3358f7e fix(limits): report details.limit for pyc budget refusals (#14386)
* fix(limits): report details.limit for pyc budget refusals

Rebased onto main; the devicetree and NuGet parts were dropped here (landed via #14622 and #14629). This commit now carries only the pyc part.

Refusals of the per-call budgets on inspect_devicetree, inspect_nuget_nupkg
and inspect_python_pyc carried recovery only in remediation prose. Each
owner now keeps one bounds object that feeds both its input schema and a
structured details.limit (parameter, effective value, unit, range, default).

A pyc limit that depends on max_objects and max_depth together reports
related_parameters instead of a single range. The fixed decoded devicetree
allowance is reported as a fixed ceiling and registered as pending.

Refs #14234

* test(python): expect field-only pyc recovery text and the CLI limit flag
2026-11-30 13:18:51 +08:00

90 lines
3.4 KiB
TypeScript

import { symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createPythonPycService } from "../../../src/composition/pythonPyc.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { pythonPycFixture } from "../../../src/python/PythonPyc.fixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { expectFileSelectionErrors } from "../../support/expectFileSelectionErrors.js";
describe("Python pyc stable filesystem boundary", () => {
it("reports non-file and missing selections as caller input errors", async () => {
const root = await createTestTempDirectory("rea-python-pyc-files-");
const path = join(root, "sample.pyc");
const alias = join(root, "alias.pyc");
await writeFile(path, pythonPycFixture());
await symlink(path, alias);
const service = createPythonPycService();
await expectFileSelectionErrors(
service,
"inspect_python_pyc",
{ root, alias, path },
".pyc",
);
});
it("reports each selected pyc limit and reopens the same artifact successfully", async () => {
const root = await createTestTempDirectory("rea-python-pyc-budget-");
const path = join(root, "sample.pyc");
const bytes = pythonPycFixture("py311", { nested: true });
await writeFile(path, bytes);
const service = createPythonPycService();
// Expected ranges are the published schema bounds, written out literally.
const ranges = {
max_file_bytes: {
minimum: 16,
maximum: 67108864,
default_value: 16777216,
},
max_objects: { minimum: 1, maximum: 65536, default_value: 16384 },
max_depth: { minimum: 1, maximum: 256, default_value: 64 },
max_string_bytes: {
minimum: 1,
maximum: 8388608,
default_value: 1048576,
},
} as const;
for (const [field, maximum, resource, unit] of [
["max_file_bytes", 16, "file-size", "bytes"],
["max_objects", 1, "memory", "count"],
["max_depth", 1, "capacity", "count"],
["max_string_bytes", 2, "memory", "bytes"],
] as const) {
const refused = await service.inspect({ path, [field]: maximum });
if (refused.ok) throw new Error(`Expected ${field} refusal`);
expect(projectAnalysisError(refused.error)).toMatchObject({
code: "resource_constraint",
retryable: false,
details: {
resource,
reported_limits:
field === "max_file_bytes"
? { max_file_bytes: maximum }
: { boundary: field, maximum },
limit: {
control_kind: "parameter",
parameter: field,
effective_value: maximum,
unit,
...ranges[field],
applies_at: "next_call",
},
},
remediation: {
action: expect.stringContaining(`Raise ${field} above`),
},
});
// Contract fields only; the CLI adds its own flag spelling.
expect(
JSON.stringify(projectAnalysisError(refused.error).remediation),
).not.toContain("--");
}
const control = await service.inspect({ path });
if (!control.ok) throw control.error;
expect(control.value.normalized_result).toMatchObject({
artifact: { path, bytes: bytes.length },
coverage: { status: "complete", code_objects: 2 },
});
});
});