mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
feat(errors): project fixed native and producer input allowances as typed refusals (#11623)
* feat(errors): project fixed native and producer input allowances as typed refusals
fixedNativeAllowance wrote its allowance and value only into the remediation
sentence, and fixedProducerInputAllowance put the byte count into the
allowance name. Both now build fixedAllowanceOptions with limit and unit, so
the native command output capture, PE resource metadata, Ghidra
installation-properties and artifact analysis input refusals project
details.refusal {kind: fixed_ceiling, allowance_kind, limit, unit}. The
fixed-ceiling remediation renders the value from those facts for every
ceiling that carries them.
Refs #10508
* test(errors): check the rendered allowance value, not its sentence
This commit is contained in:
1 parent
3f4953bfae
commit
d4a7c17b38
9 files changed
+36
-27
No files matched your search
@@ -101,7 +101,7 @@ it("refuses an oversized acquisition as a fixed ceiling, not host memory", async
|
||||
},
|
||||
});
|
||||
// Recovery comes from the fixed-allowance owner, not host-memory advice.
|
||||
expect(projected.remediation.action).toBe(
|
||||
expect(projected.remediation.action).toContain(
|
||||
fixedAllowanceRemediation("The NTFS journal file allowance", "input"),
|
||||
);
|
||||
} finally {
|
||||
|
||||
@@ -50,6 +50,8 @@ describe("typed refusals", () => {
|
||||
expect(projected.remediation.action).toMatch(
|
||||
/^The GraphQL nesting allowance is a fixed allowance\..*Select a shallower document\.$/u,
|
||||
);
|
||||
// The value comes from the ceiling's facts, so a producer need not write it into the name.
|
||||
expect(projected.remediation.action).toMatch(/\b128 levels\b/u);
|
||||
expect(projected.remediation.action).not.toMatch(/worker memory|doctor/u);
|
||||
expect(projected.details?.refusal).toEqual({
|
||||
kind: "fixed_ceiling",
|
||||
|
||||
@@ -102,9 +102,13 @@ export const analysisRefusalRemediation = (
|
||||
case "fixed_ceiling": {
|
||||
const { ceiling } = refusal;
|
||||
const base = fixedAllowanceRemediation(ceiling.name, ceiling.kind);
|
||||
const value =
|
||||
ceiling.limit === undefined || ceiling.unit === undefined
|
||||
? ""
|
||||
: ` The allowance is ${String(ceiling.limit)} ${ceiling.unit}; this release has no runtime override.`;
|
||||
return ceiling.narrowing === undefined
|
||||
? base
|
||||
: `${base} ${ceiling.narrowing}`;
|
||||
? `${base}${value}`
|
||||
: `${base}${value} ${ceiling.narrowing}`;
|
||||
}
|
||||
case "adjustable_budget":
|
||||
return adjustableBudgetRemediation(
|
||||
|
||||
@@ -78,7 +78,4 @@ export const fixedProducerInputAllowance = (
|
||||
bytes: number,
|
||||
allowance: string,
|
||||
): { readonly retryable: false; readonly fixedAllowance: FixedAllowance } =>
|
||||
fixedAllowanceOptions(
|
||||
`${allowance} of ${String(bytes)} bytes (this release has no runtime override)`,
|
||||
"input",
|
||||
);
|
||||
fixedAllowanceOptions(allowance, "input", { limit: bytes, unit: "bytes" });
|
||||
@@ -6,7 +6,8 @@ import {
|
||||
|
||||
import type { AnalysisControlLimit } from "../analysisSettings.js";
|
||||
import {
|
||||
fixedAllowanceRemediation,
|
||||
fixedAllowanceOptions,
|
||||
type FixedAllowance,
|
||||
type FixedAllowanceKind,
|
||||
} from "../fixedAllowanceRemediation.js";
|
||||
|
||||
@@ -100,12 +101,11 @@ export const nativeDeadlineRecovery = (input: {
|
||||
};
|
||||
};
|
||||
|
||||
/** Fixed native allowance the agent can see, with the value and no override. */
|
||||
/** Fixed native allowance projected as `details.refusal`, with its value and unit. */
|
||||
export const fixedNativeAllowance = (
|
||||
allowance: string,
|
||||
kind: FixedAllowanceKind,
|
||||
valueWithUnits: string,
|
||||
): { readonly retryable: false; readonly remediationAction: string } => ({
|
||||
retryable: false,
|
||||
remediationAction: `${fixedAllowanceRemediation(allowance, kind)} This release has no runtime override. The allowance is ${valueWithUnits}.`,
|
||||
});
|
||||
limit: number,
|
||||
unit: string,
|
||||
): { readonly retryable: false; readonly fixedAllowance: FixedAllowance } =>
|
||||
fixedAllowanceOptions(allowance, kind, { limit, unit });
|
||||
@@ -218,7 +218,8 @@ export const translateNativeCommandFailure = (
|
||||
...fixedNativeAllowance(
|
||||
"The native command output capture allowance",
|
||||
"capture",
|
||||
`${String(NATIVE_COMMAND_OUTPUT_BUDGET_BYTES)} bytes`,
|
||||
NATIVE_COMMAND_OUTPUT_BUDGET_BYTES,
|
||||
"bytes",
|
||||
),
|
||||
},
|
||||
),
|
||||
|
||||
@@ -180,8 +180,12 @@ it("names the fixed PE metadata allowance instead of host memory", async () => {
|
||||
});
|
||||
const projected = projectAnalysisError(error);
|
||||
expect(projected.retryable).toBe(false);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"PE resource metadata allowance",
|
||||
);
|
||||
expect(projected.remediation.action).not.toMatch(/available host memory/u);
|
||||
expect(projected.details).toMatchObject({
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
allowance_kind: "parser",
|
||||
limit: 8 * 1024 * 1024,
|
||||
unit: "bytes",
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -153,7 +153,8 @@ const peResourcesFailurePrimary = (
|
||||
? fixedNativeAllowance(
|
||||
"The PE resource metadata allowance",
|
||||
"parser",
|
||||
`${String(PE_RESOURCE_METADATA_BYTES)} bytes (8 MiB)`,
|
||||
PE_RESOURCE_METADATA_BYTES,
|
||||
"bytes",
|
||||
)
|
||||
: {
|
||||
retryable: false as const,
|
||||
|
||||
@@ -173,15 +173,15 @@ it("refuses an oversized descriptor before reading file bytes", async () => {
|
||||
expect(projectAnalysisError(failure)).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable: false,
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"Ghidra installation-properties read allowance of 1048576 bytes (this release has no runtime override)",
|
||||
),
|
||||
details: {
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
allowance_kind: "input",
|
||||
limit: MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES,
|
||||
unit: "bytes",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(projectAnalysisError(failure).remediation.action).toContain(
|
||||
"Increasing an evidence-reply file-size allowance does not admit this input",
|
||||
);
|
||||
expect(reads).toBe(0);
|
||||
} finally {
|
||||
await resources.close();
|
||||
|
||||
Reference in new issue
Block a user