Docs native: pin the host's production fuel allowance
Review finding 3 (#146): the only pin on the production bound was MAX_FUEL < 20G; the mutation case touched the test hook. The test now asserts the exact allowance for representative memory and request sizes, that memory past the cap earns nothing, and MAX_FUEL itself, and a new mutation (doubling the per-byte memory allowance) is caught by it. native/host/src/lib.rs is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+9
−0
native/host/tests/sandbox.rs+8 −0native/scripts/check-mutations.py+1 −0
diff --git a/native/host/tests/sandbox.rs b/native/host/tests/sandbox.rs| index 1103337..72420fb 100644 |
| --- a/native/host/tests/sandbox.rs |
| +++ b/native/host/tests/sandbox.rs |
| @@ -71,6 +71,14 @@ fn fuel_budget_grows_with_the_instance_but_stays_bounded() { |
| // Memory and requests are capped, so the budget is too, whatever is asked. |
| assert_eq!(fuel_budget(usize::MAX, usize::MAX), MAX_FUEL); |
| assert!(MAX_FUEL < 20_000_000_000, "the ceiling is what bounds a runaway call: {MAX_FUEL}"); |
| + // The production allowance itself, pinned: 40M, plus 128 per byte of |
| + // memory, plus 1,024 per request byte; capped at 64 MiB and 8 MiB + 1. |
| + assert_eq!(fuel_budget(1 << 20, 0), 40_000_000 + 128 * (1 << 20)); |
| + assert_eq!(fuel_budget(1 << 20, 64), 40_000_000 + 128 * (1 << 20) + 1_024 * 64); |
| + assert_eq!(fuel_budget(16 << 20, 1 << 20), 40_000_000 + 128 * (16 << 20) + 1_024 * (1 << 20)); |
| + assert_eq!(fuel_budget(64 << 20, 8 << 20), 40_000_000 + 128 * (64 << 20) + 1_024 * (8 << 20)); |
| + assert_eq!(fuel_budget(1 << 30, 0), fuel_budget(64 << 20, 0), "memory past the cap earns nothing"); |
| + assert_eq!(MAX_FUEL, 40_000_000 + 128 * (64 << 20) + 1_024 * ((8 << 20) + 1)); |
| } |
| #[test] |
diff --git a/native/scripts/check-mutations.py b/native/scripts/check-mutations.py| index 97bddb5..04ad65d 100644 |
| --- a/native/scripts/check-mutations.py |
| +++ b/native/scripts/check-mutations.py |
| @@ -22,6 +22,7 @@ cases = [ |
| ('crdt/src/structure.rs', 'copy.attributes.insert("level".into(), number(&request["level"])?.clamp(1,6).to_string());', 'copy.attributes.insert("level".into(), "1".into());', 'changing_block_preserves_existing_inline_formatting'), |
| ('host/src/lib.rs', 'if self.failed || request.len() > MAX_BYTES', 'if request.len() > MAX_BYTES', 'failed_replica_cannot_be_reused'), |
| ('host/src/lib.rs', 'request.len()).min(self.ceiling)', 'request.len())', 'running_out_of_fuel_is_a_clean_failure_that_discards_the_instance'), |
| + ('host/src/lib.rs', 'BASE_FUEL + FUEL_PER_MEMORY_BYTE * memory + FUEL_PER_REQUEST_BYTE * request', 'BASE_FUEL + 2 * FUEL_PER_MEMORY_BYTE * memory + FUEL_PER_REQUEST_BYTE * request', 'fuel_budget_grows_with_the_instance_but_stays_bounded'), |
| ] |
| for relative, old, new, test in cases: |
| path = root / relative |