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

53 lines
2.1 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it, vi } from "vitest";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { pythonPycFixture } from "../../../src/python/PythonPyc.fixture.js";
import { pythonPycLimit } from "../../../src/python/PythonPyc.errors.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
// The nested-code allowances are max_objects * max_depth, and no marshal
// fixture can spend them: each code object costs dozens of objects, so the
// object and depth budgets refuse first. The parser is therefore replaced
// here so the provider's real classification and projection run on the
// refusal it would raise.
const parser = vi.hoisted(() => ({ limit: undefined as unknown }));
vi.mock("../../../src/python/PythonPycParser.js", () => ({
parsePythonPyc: () => {
throw parser.limit;
},
}));
const { createPythonPycService } =
await import("../../../src/composition/pythonPyc.js");
describe("pyc nested-code limits", () => {
it.each(["nested_code_steps", "nested_code_references"] as const)(
"reports %s as a product of two controls, not one range",
async (name) => {
parser.limit = pythonPycLimit(
name,
4096,
"Nested code walk is too large.",
);
const root = await createTestTempDirectory("rea-pyc-nested-limit-");
const path = join(root, "sample.pyc");
await writeFile(path, pythonPycFixture("py311"));
const refused = await createPythonPycService().inspect({
path,
max_objects: 64,
max_depth: 64,
});
if (refused.ok) throw new Error(`Expected ${name} refusal`);
const { details, remediation } = projectAnalysisError(refused.error);
expect(details).toMatchObject({
resource: "memory",
related_parameters: ["max_objects", "max_depth"],
});
expect(details).not.toHaveProperty("limit");
expect(remediation?.action).toContain("Raise max_objects above 64");
expect(remediation?.action).toContain("Raise max_depth above 64");
},
);
});