mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 06:21:12 +00:00
fix(artifacts): omit required_value where reader limits know only a lower bound (#14646)
* fix(artifacts): omit required_value where reader limits know only a lower bound A reader-limit refusal reports required_value only when a retry at that value is admitted. Deno specifier text and remote body totals, VFS entry and name-unit counts, Deno and wxapkg plaintext totals, and the shared path registry's part and node counts stop at the first crossing, so those refusals now omit it. Declared lengths and table counts keep it. * test(resources): assert path budget refusals omit required_value Capture the path_nodes and path_parts refusals and check readerLimit has no required_value, so restoring the lower-bound value fails.
This commit is contained in:
1 parent
49187f1ab3
commit
b41399d8a6
7 files changed
+55
-24
No files matched your search
@@ -156,7 +156,7 @@ export class DenoStandaloneArtifactReader extends PositionalArtifactReader<
|
||||
"artifact_limits.expanded_bytes",
|
||||
Number(expansionBudget),
|
||||
"bytes",
|
||||
declaredPlaintext,
|
||||
// Entries after this one are not counted: a lower bound only.
|
||||
);
|
||||
}
|
||||
paths.reservePath(entry.path);
|
||||
|
||||
@@ -205,7 +205,8 @@ export class WxapkgArtifactReader implements ArtifactReader {
|
||||
"artifact_limits.expanded_bytes",
|
||||
budget,
|
||||
"bytes",
|
||||
declaredBytes,
|
||||
// Later members are not counted, so the total is a lower bound.
|
||||
undefined,
|
||||
"memory",
|
||||
);
|
||||
const adapterKey = `wxapkg-entry:${String(index)}`;
|
||||
|
||||
@@ -215,7 +215,7 @@ export const parseDenoSection = async (
|
||||
const range = takeRange(BigInt(length), "specifier text");
|
||||
textBytes += length;
|
||||
if (textBytes > limits.specifier_text_bytes)
|
||||
throw denoByteLimit("specifier_text_bytes", textBytes, limits);
|
||||
throw denoByteLimit("specifier_text_bytes", undefined, limits);
|
||||
const bytes = await readExact(range.sectionOffset, range.length);
|
||||
const id = await u32();
|
||||
if (specifierText.has(id))
|
||||
@@ -377,7 +377,7 @@ const addRemoteBody = (
|
||||
): bigint => {
|
||||
const next = total + BigInt(length);
|
||||
if (next > BigInt(limits.remote_body_bytes))
|
||||
throw denoByteLimit("remote_body_bytes", next, limits);
|
||||
throw denoByteLimit("remote_body_bytes", undefined, limits);
|
||||
return next;
|
||||
};
|
||||
|
||||
@@ -540,7 +540,11 @@ const denoByteLimit = (
|
||||
| "vfs_header_json_bytes"
|
||||
| "specifier_text_bytes"
|
||||
| "remote_body_bytes",
|
||||
claimed: number | bigint,
|
||||
/**
|
||||
* A declared length is the complete need. A running total stops at the
|
||||
* first crossing, a lower bound, and is passed as undefined.
|
||||
*/
|
||||
claimed: number | bigint | undefined,
|
||||
limits: DenoReaderLimits,
|
||||
): ArtifactReaderFailure =>
|
||||
artifactReaderLimitFailure(
|
||||
|
||||
@@ -182,12 +182,15 @@ it("refuses an entry count above the selected allowance", () => {
|
||||
readerLimit: {
|
||||
parameter: "artifact_limits.deno.vfs_entries",
|
||||
effective_value: 2,
|
||||
required_value: 3,
|
||||
can_increase: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
// The walk stops at the first entry past the allowance; the total is unknown.
|
||||
expect((failure as ArtifactReaderFailure).readerLimit).not.toHaveProperty(
|
||||
"required_value",
|
||||
);
|
||||
expect(
|
||||
walkDenoVirtualFs(entries, 0, undefined, {
|
||||
...limits,
|
||||
|
||||
@@ -212,7 +212,7 @@ const walkEntries = (
|
||||
if (tagged === undefined) throw new UnsupportedVfsShape();
|
||||
const index = state.count;
|
||||
if (index >= state.limits.vfs_entries)
|
||||
throw denoVfsEntryLimit(state.limits, index + 1);
|
||||
throw denoVfsEntryLimit(state.limits);
|
||||
state.count += 1;
|
||||
const name = tagged.body.n;
|
||||
if (typeof name !== "string") throw new UnsupportedVfsShape();
|
||||
@@ -456,7 +456,8 @@ const retainText = (state: WalkState, text: string | null): string | null => {
|
||||
"artifact_limits.deno.vfs_name_units",
|
||||
state.limits.vfs_name_units,
|
||||
"count",
|
||||
next,
|
||||
// The walk stops here, so the units counted so far are only a lower bound.
|
||||
undefined,
|
||||
"memory",
|
||||
);
|
||||
state.retainedUnits = next;
|
||||
@@ -513,15 +514,12 @@ const asRecord = (value: unknown): Record<string, unknown> | undefined => {
|
||||
return Object.fromEntries(Object.entries(value));
|
||||
};
|
||||
|
||||
const denoVfsEntryLimit = (
|
||||
limits: DenoReaderLimits,
|
||||
count: number,
|
||||
): ArtifactReaderFailure =>
|
||||
/** The walk stops at the first entry past the allowance; the total is unknown. */
|
||||
const denoVfsEntryLimit = (limits: DenoReaderLimits): ArtifactReaderFailure =>
|
||||
artifactReaderLimitFailure(
|
||||
"artifact_limits.deno.vfs_entries",
|
||||
limits.vfs_entries,
|
||||
"count",
|
||||
count,
|
||||
);
|
||||
|
||||
const denoVfsDepthLimit = (depth: number): ArtifactReaderFailure =>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ArtifactReaderFailure } from "./ArtifactReader.js";
|
||||
|
||||
import {
|
||||
ArtifactPathRegistry,
|
||||
@@ -191,6 +192,32 @@ it.each([["app.js", "App.js"], ["other.js"]])(
|
||||
},
|
||||
);
|
||||
|
||||
/** The reader failure a registry call throws. */
|
||||
const pathFailure = (run: () => void): ArtifactReaderFailure => {
|
||||
try {
|
||||
run();
|
||||
} catch (cause) {
|
||||
if (cause instanceof ArtifactReaderFailure) return cause;
|
||||
throw cause;
|
||||
}
|
||||
throw new Error("Expected a path budget refusal");
|
||||
};
|
||||
|
||||
it("refuses a deeper path at path_parts without claiming a required value", () => {
|
||||
const registry = new ArtifactPathRegistry({
|
||||
group: "deno",
|
||||
maxParts: 2,
|
||||
maxNodes: 100,
|
||||
});
|
||||
// A later path may be deeper still, so this one's depth is a lower bound.
|
||||
const failure = pathFailure(() => registry.reservePath("a/b/c"));
|
||||
expect(failure.readerLimit).toMatchObject({
|
||||
parameter: "artifact_limits.deno.path_parts",
|
||||
effective_value: 2,
|
||||
});
|
||||
expect(failure.readerLimit).not.toHaveProperty("required_value");
|
||||
});
|
||||
|
||||
it("reserves prefix capacity atomically without declaring destination kinds", () => {
|
||||
const registry = new ArtifactPathRegistry({
|
||||
group: "deno",
|
||||
@@ -198,15 +225,13 @@ it("reserves prefix capacity atomically without declaring destination kinds", ()
|
||||
maxNodes: 3,
|
||||
});
|
||||
registry.reservePath("a/b");
|
||||
expect(() => registry.reservePath("a/c/d")).toThrow(
|
||||
expect.objectContaining({
|
||||
readerLimit: expect.objectContaining({
|
||||
parameter: "artifact_limits.deno.path_nodes",
|
||||
effective_value: 3,
|
||||
required_value: 4,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
// Unvisited paths may add nodes, so no required value is claimed.
|
||||
const failure = pathFailure(() => registry.reservePath("a/c/d"));
|
||||
expect(failure.readerLimit).toMatchObject({
|
||||
parameter: "artifact_limits.deno.path_nodes",
|
||||
effective_value: 3,
|
||||
});
|
||||
expect(failure.readerLimit).not.toHaveProperty("required_value");
|
||||
expect(() => registry.reservePath("z")).not.toThrow();
|
||||
expect(() => registry.reservePath("a/b")).not.toThrow();
|
||||
registry.add("a/b", "file");
|
||||
|
||||
@@ -143,7 +143,7 @@ export class ArtifactPathRegistry {
|
||||
`artifact_limits.${budget.group}.path_parts`,
|
||||
budget.maxParts,
|
||||
"count",
|
||||
parts.length,
|
||||
// A later, deeper path may need more; this path is a lower bound.
|
||||
);
|
||||
if (budget !== undefined) {
|
||||
let observed = this.#root;
|
||||
@@ -155,7 +155,7 @@ export class ArtifactPathRegistry {
|
||||
`artifact_limits.${budget.group}.path_nodes`,
|
||||
budget.maxNodes,
|
||||
"count",
|
||||
this.#nodeCount + parts.length - index,
|
||||
// Paths not yet visited add nodes; the count is a lower bound.
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user