Files
reverse-engineering-anything/src/firmware/FirmwareStagingBudget.test.ts
T
吴佳浩Alben 2e86294c86 fix(firmware): stop recommending a raise at the staging budget ceiling (#6971)
The staging refusal told callers to increase max_output_files or max_output_bytes within its schema maximum. At the schema ceiling that recovery does not exist, so the refusal was unactionable exactly where the least room remains.

firmwareStagingBudgetRemediation now branches on the selected value against the schema maximum: below the ceiling it names the room and the control, at the ceiling it states that a further raise is unsupported and points at a smaller firmware byte range. The schema maxima move into named constants so the advice and the accepted range cannot drift apart.

Verified with a module test for both budgets at the ceiling and one below it (red on the previous single-form remediation), plus the existing firmware suites.
2026-10-24 21:35:30 +09:00

59 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
MAX_FIRMWARE_STAGING_BYTES,
MAX_FIRMWARE_STAGING_ENTRIES,
} from "../domain/firmware/firmwareAnalysis.js";
import { firmwareStagingBudgetRemediation } from "./FirmwareFiles.js";
describe("firmware staging budget recovery", () => {
it("offers room to raise a budget that is below its supported maximum", () => {
const remediation = firmwareStagingBudgetRemediation("max_output_files", 1);
expect(remediation).toContain(
`supported maximum ${String(MAX_FIRMWARE_STAGING_ENTRIES)}`,
);
expect(remediation).toContain("Increase max_output_files up to");
expect(remediation).not.toContain("not supported");
});
it("does not recommend raising a budget already at its supported maximum", () => {
const entries = firmwareStagingBudgetRemediation(
"max_output_files",
MAX_FIRMWARE_STAGING_ENTRIES,
);
const bytes = firmwareStagingBudgetRemediation(
"max_output_bytes",
MAX_FIRMWARE_STAGING_BYTES,
);
for (const remediation of [entries, bytes]) {
// Raising a value the schema already caps is not an available recovery.
expect(remediation).toContain("not supported");
expect(remediation).not.toContain("Increase");
expect(remediation).toContain("smaller firmware byte range");
}
});
it("names the exhausted budget, the selected value and the ceiling", () => {
expect(firmwareStagingBudgetRemediation("max_output_bytes", 4)).toContain(
"max_output_bytes=4",
);
expect(
firmwareStagingBudgetRemediation(
"max_output_bytes",
MAX_FIRMWARE_STAGING_BYTES,
),
).toContain(`maximum ${String(MAX_FIRMWARE_STAGING_BYTES)}`);
});
it("keeps the ceiling advice off the schema limit for both budgets", () => {
for (const [budget, maximum] of [
["max_output_files", MAX_FIRMWARE_STAGING_ENTRIES],
["max_output_bytes", MAX_FIRMWARE_STAGING_BYTES],
] as const)
expect(firmwareStagingBudgetRemediation(budget, maximum - 1)).toContain(
`Increase ${budget} up to`,
);
});
});