{"record":{"id":"8e3b872bf2d98fdb","repo":"Hmbown/CodeWhale","slug":"exact-library-measurement-test-test-name-emitted","errorCode":null,"errorMessage":"exact library measurement test {TEST_NAME} emitted no valid receipt: {error}","messagePattern":"exact library measurement test (.+?) emitted no valid receipt: (.+?)","errorType":"exception","errorClass":"PersistenceBacklogMeasurementError","httpStatus":null,"severity":"error","filePath":"scripts/measure-persistence-backlog.py","lineNumber":70,"sourceCode":"        text=True,\n        capture_output=True,\n        check=False,\n    )\n    sys.stderr.write(result.stderr)\n    if result.returncode != 0:\n        sys.stdout.write(result.stdout)\n        result.check_returncode()\n\n    combined = \"\\n\".join(result.stdout.splitlines() + result.stderr.splitlines())\n    if re.search(r\"\\brunning\\s+0\\s+tests?\\b\", combined):\n        sys.stdout.write(result.stdout)\n        raise PersistenceBacklogMeasurementError(\n            f\"exact library measurement test {TEST_NAME} ran zero tests\"\n        )\n    try:\n        return json.loads(receipt_path.read_text(encoding=\"utf-8\"))\n    except (OSError, json.JSONDecodeError) as error:\n        raise PersistenceBacklogMeasurementError(\n            f\"exact library measurement test {TEST_NAME} emitted no valid receipt: {error}\"\n        ) from error\n\n\ndef main() -> int:\n    source_sha = subprocess.run(\n        [\"git\", \"rev-parse\", \"HEAD\"],\n        cwd=ROOT,\n        text=True,\n        capture_output=True,\n        check=True,\n    ).stdout.strip()\n    source_dirty = bool(\n        subprocess.run(\n            [\"git\", \"status\", \"--porcelain\", \"--untracked-files=normal\"],\n            cwd=ROOT,\n            text=True,\n            capture_output=True,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/measure-persistence-backlog.py#L52-L88","documentation":"After the measurement test runs, the script json.loads the receipt at CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH (a temp file it created and exported into the cargo env). OSError (missing/unreadable file) or JSONDecodeError (empty/truncated/corrupt JSON) raises this: the test executed but did not emit a trustworthy receipt. Causes: the test skips writing under some condition, the env-var name changed on one side only, or the write is incomplete when the test process exits.","triggerScenarios":"The test returns early (cfg/skip logic) without writing the receipt; RECEIPT_ENV renamed in the Rust test or the Python script but not both; the test writes partial JSON then panics; the tempdir is cleaned before the read.","commonSituations":"Editing the receipt-writing helper; changing env-var names; adding skip conditions to the measurement test.","solutions":["Make the test unconditionally write complete, valid JSON to the env-var path as its final step (write-temp-then-rename for atomicity)","Keep RECEIPT_ENV ('CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH') identical in scripts/measure-persistence-backlog.py:15 and the Rust test","Reproduce locally: 'CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH=/tmp/r.json cargo test --locked -p codewhale-tui --lib -- --exact --ignored --test-threads=1 <TEST_NAME>' then inspect /tmp/r.json"],"exampleFix":"// before (Rust test)\nif backlog.is_empty() { return; } // receipt silently skipped\nstd::fs::write(path, json)?;\n\n// after\nlet tmp = path.with_extension(\"tmp\");\nstd::fs::write(&tmp, json)?;\nstd::fs::rename(&tmp, path)?; // always emit a complete receipt","handlingStrategy":"try-catch","validationCode":"import os\nfrom pathlib import Path\n# Before running: confirm the env contract the test expects\nassert \"CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH\" in os.environ\nassert Path(os.environ[\"CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH\"]).parent.is_dir(), \"receipt dir missing\"","typeGuard":"def is_backlog_measurement_error(exc: BaseException) -> bool:\n    return isinstance(exc, RuntimeError) and type(exc).__name__ == \"PersistenceBacklogMeasurementError\"","tryCatchPattern":"try:\n    receipt = run_measurement(receipt_path, env)\nexcept PersistenceBacklogMeasurementError as error:\n    sys.stderr.write(f\"invalid persistence backlog receipt: {error}\\n\")\n    return 1","preventionTips":["Make the test unconditionally write a complete JSON receipt as its final statement (write-temp-then-rename)","Keep the RECEIPT_ENV variable name identical in the Python script and the Rust test","Never add early returns or cfg skips inside the measurement test"],"tags":["python","ci","rust","json","measurement","environment-variables"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}