{"record":{"id":"d6e063e5a04600b8","repo":"Hmbown/CodeWhale","slug":"missing-marker-rstrip-marker-from-exact-librar","errorCode":null,"errorMessage":"missing {marker.rstrip()} marker from exact library metric test {metric_test_name(test_name)}","messagePattern":"missing (.+?) marker from exact library metric test (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/measure-runtime-contract.py","lineNumber":60,"sourceCode":"    cmd = metric_command(test_name)\n    proc = subprocess.run(cmd, text=True, capture_output=True, check=False)\n    sys.stderr.write(proc.stderr)\n    if proc.returncode != 0:\n        sys.stdout.write(proc.stdout)\n        proc.check_returncode()\n\n    combined = proc.stdout.splitlines() + proc.stderr.splitlines()\n    if re.search(r\"\\brunning\\s+0\\s+tests?\\b\", \"\\n\".join(combined)):\n        sys.stdout.write(proc.stdout)\n        raise RuntimeError(\n            f\"exact library metric test {metric_test_name(test_name)} ran zero tests\"\n        )\n    for line in combined:\n        if marker in line:\n            return json.loads(line.split(marker, 1)[1])\n\n    sys.stdout.write(proc.stdout)\n    raise RuntimeError(\n        f\"missing {marker.rstrip()} marker from exact library metric test \"\n        f\"{metric_test_name(test_name)}\"\n    )\n\n\ndef main() -> int:\n    tool_metrics = run_metric(\n        \"print_mode_tool_catalog_metrics\",\n        \"TOOL_CATALOG_METRICS \",\n    )\n    prompt_metrics = run_metric(\n        \"print_mode_runtime_contract_metrics\",\n        \"RUNTIME_CONTRACT_METRICS \",\n    )\n    representative_context_metrics = run_metric(\n        \"print_representative_runtime_context_metrics\",\n        \"REPRESENTATIVE_CONTEXT_METRICS \",\n    )","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/measure-runtime-contract.py#L42-L78","documentation":"run_metric() ran the metric test to a zero exit code but no line of combined stdout/stderr contained the expected marker string (e.g. 'TOOL_CATALOG_METRICS ') followed by JSON. The script extracts the metrics object by splitting each line on the marker, so a missing marker makes the receipt impossible to build and the run aborts after dumping the test stdout for inspection.","triggerScenarios":"The marker literal printed by the test drifted from the string passed to run_metric() (renamed, or the trailing space in 'TOOL_CATALOG_METRICS ' was dropped); the print statement was made conditional or moved behind an early return; the marker is emitted by a different test than the one named; output went to a stream the script does not combine (it does combine stdout and stderr, so this is rare).","commonSituations":"Renaming the metrics printer or its marker constant on one side (test vs script) only; refactoring the test so the marker prints only on some code paths; a new metric added to the test without updating main()'s marker argument.","solutions":["Grep both sides for the marker and align them exactly, including the trailing space: rg \"TOOL_CATALOG_METRICS\" crates/tui scripts/measure-runtime-contract.py","Run the cargo command by hand with --nocapture and confirm the marker line actually appears in the output","Ensure the test prints the marker unconditionally (println!(\"TOOL_CATALOG_METRICS {json}\")) after computing metrics"],"exampleFix":"// crates/tui test: before\nprintln!(\"TOOLCAT_METRICS {}\", serde_json::to_string(&metrics)?);\n\n// after (matches the marker argument in main())\nprintln!(\"TOOL_CATALOG_METRICS {}\", serde_json::to_string(&metrics)?);","handlingStrategy":"validation","validationCode":"# Before running, assert the test source prints the exact marker (incl. trailing space):\nimport re, subprocess\n\nsource = subprocess.run(\n    [\"rg\", \"-l\", \"core::engine::tests\"], capture_output=True, text=True\n)  # or read the known test file\nmarker = \"TOOL_CATALOG_METRICS \"\ntest_src = open(\"crates/tui/src/engine.rs\").read()  # path of the metric test\nassert marker.strip() in test_src, f\"test no longer prints {marker.strip()}\"","typeGuard":null,"tryCatchPattern":"try:\n    metrics = run_metric(test_name, marker)\nexcept RuntimeError as e:\n    if \"missing\" in str(e) and \"marker\" in str(e):\n        # marker drift between script and test; align the literals, then re-run\n        ...","preventionTips":["Define the marker string once (a shared constant) instead of duplicating the literal in the script and the test","Keep the marker println! unconditional and last in the test so it always reaches stdout under --nocapture","Include the trailing space convention in the marker constant on both sides"],"tags":["python","cargo","string-matching","metrics","ci"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}