mirror of
https://github.com/morluto/rea.git
synced 2026-11-06 14:56:32 +00:00
* fix(firmware): keep producer reports writable under small staging budgets extract_firmware passed max_output_bytes straight to prlimit --fsize. RLIMIT_FSIZE applies to every regular file the producer writes, including the mandatory report.json and unblob.log outside the staging tree, so a staging budget smaller than the report truncated it and failed the extraction even when every staged file fit. Derive the per-file ceiling as the larger of the staging budget and the 8 MiB report budget; polling and the final inventory still enforce the aggregate staging budget. Fixes #3888 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(firmware): keep files stopped at the size ceiling over budget The per-file RLIMIT_FSIZE ceiling equalled the largest size its readers accept, and both the staging inventory and the report reader accept a file of exactly their budget. A write the kernel stopped at the ceiling therefore left a truncated file that passed as complete. Raise the ceiling by one byte so such a file exceeds its budget and is rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(firmware): report the effective file-size ceiling on limit failures The exit path re-derived the staging budget for SIGXFSZ and process-limit recovery, so a small-budget run killed at the 8 MiB + 1 ceiling reported file_size_bytes 64 and said the cap was max_output_bytes. Pass the ceiling runFirmwareCommand installs and describe how it is derived. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(firmware): reject staged files cut off at the per-file limit RLIMIT_FSIZE stops a write at the limit without extending the file, and the staging inventory admits a file of exactly max_output_bytes. With a budget of 8 MiB or more the producer limit equalled the budget, so a staged file the kernel cut short published as a complete extraction; an inherited ceiling below the budget did the same. Derive the per-run limit once in firmwareFileSizeLimit as one byte above the largest budget, still capped by the inherited ceiling, so a file stopped at the limit exceeds its budget. When the inherited ceiling removes that byte, both staging inventories refuse a regular file that reaches the installed limit with a nonretryable file-size constraint naming the inherited limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(firmware): derive limit adjustability from the per-run limit The one byte of headroom makes the per-run file limit equal an inherited ceiling of exactly max_output_bytes + 1, but adjustability still compared that ceiling with the raw budget. A SIGXFSZ then advised raising max_output_bytes, which the same ceiling clamps back to the same limit. Decide adjustability in firmwareFileSizeAdjustable from firmwareFileSizeLimit itself: recommend a larger budget only when it raises that limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(firmware): compare file-size recovery with its owners The SIGXFSZ adjustability cases and the inherited-ceiling workflow matched fragments of remediation prose, so a harmless rewrite would fail them. Compare the emitted guidance with firmwareSignalLimitError for the expected branch, check that the two branches stay distinct, and compare the inventory refusal with firmwareFileSizeLimitReached. The selected limit, resource and retryability stay asserted as structured facts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
60 lines
2.3 KiB
TypeScript
60 lines
2.3 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { access, readFile } from "node:fs/promises";
|
|
import { promisify } from "node:util";
|
|
import { expect, it, onTestFinished } from "vitest";
|
|
import { firmwareFileSizeLimitReached } from "../../src/firmware/FirmwareFiles.js";
|
|
import { FIRMWARE_LIMITS } from "../../src/firmware/FirmwareRelease.js";
|
|
import { firmwareFileSizeService } from "../fixtures/firmware/fileSizeProducer.js";
|
|
import { assertFirmwareCleanup } from "../fixtures/firmware/provider.js";
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
const budget = 16 * 1024 * 1024;
|
|
|
|
// Lowers this isolated fork's soft RLIMIT_FSIZE to the staging budget, which
|
|
// removes the one byte of headroom the producer limit normally keeps.
|
|
it.skipIf(process.platform !== "linux")(
|
|
"rejects a staged file that reaches an inherited file-size ceiling",
|
|
async () => {
|
|
const limits = await readFile("/proc/self/limits", "utf8");
|
|
const soft = /^Max file size\s+(\S+)/mu.exec(limits)?.[1];
|
|
if (soft === undefined) throw new Error("No inherited file-size limit");
|
|
const setSoftLimit = async (value: string): Promise<void> => {
|
|
await execFileAsync("prlimit", [
|
|
"--pid",
|
|
String(process.pid),
|
|
`--fsize=${value}:`,
|
|
]);
|
|
};
|
|
await setSoftLimit(String(budget));
|
|
onTestFinished(() => setSoftLimit(soft));
|
|
const fixture = await firmwareFileSizeService({
|
|
attemptedBytes: budget + 4096,
|
|
probeFileBytes: FIRMWARE_LIMITS.reportBytes + 1,
|
|
extractionFileBytes: budget,
|
|
});
|
|
const outcome = await fixture.service.execute("extract_firmware", {
|
|
path: fixture.path,
|
|
output_directory: fixture.output,
|
|
max_output_bytes: budget,
|
|
});
|
|
expect(outcome).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisResourceConstraintError",
|
|
resource: "file-size",
|
|
reportedLimits: { file_size_bytes: budget },
|
|
retryable: false,
|
|
// The inventory refusal, not the producer's SIGXFSZ recovery, owns this.
|
|
remediationAction: firmwareFileSizeLimitReached(
|
|
"extract_firmware",
|
|
budget,
|
|
).remediationAction,
|
|
},
|
|
});
|
|
await expect(access(fixture.output)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
await assertFirmwareCleanup(fixture.launches);
|
|
},
|
|
);
|