headroom/tests/parity/fixtures/code_aware_compressor/d72fde8ea01cb782.json
Ruben A. e530de5ad2
feat(rust): port CodeCompressor AST compressor to Rust (parity-only) (#1154)
Adds crates/headroom-core/src/transforms/code_compressor.rs (1,882 lines): the
AST-aware CodeCompressor ported to Rust on tree-sitter, with grammars for
Python, JavaScript, TypeScript, Go, Rust, Java, C and C++.

Parity-only, like #1153. Nothing calls it: the only references outside the
module are the pub mod / pub use declarations in transforms/mod.rs, and
live_zone.rs still routes SourceCode to a no-op. The pyo3 bridge is untouched
and no Python source changes, so the engine is unreachable from the shipped
package. #1155 wires it into live-zone dispatch.

Every grammar is pinned with '=' to the exact version of the corresponding
Python tree-sitter-<lang> PyPI wheel. Same version on crates.io and PyPI means
the same grammar.js, hence the same generated parser.c, hence node-for-node
identical ASTs — the precondition for byte-parity. A canary over 9 samples x 8
languages confirmed identical node-type and line-span trees at these pins;
bumping any pin requires re-running it and re-recording the fixtures.

Ships 30 recorded parity fixtures, a CodeCompressorComparator in
headroom-parity, and scripts/record_code_compressor_fixtures.py.

Verified byte-identical to the recorded Python output:

  [code_aware_compressor] total=30 matched=30 skipped=0 diffed=0

Full harness on the merge result: 227 fixtures, 182 matched, 45 skipped
(cache_aligner + ccr stubs), 0 diffed, exit 0 — with kompress at 21/21 under
ONNX Runtime 1.24.4 (see #2591).

Also verified cargo check -p headroom-core --no-default-features passes, so the
static-musl path stays intact.
2026-07-27 09:21:57 -07:00

40 lines
3.4 KiB
JSON

{
"config": {
"ccr_ttl": 300,
"compress_comments": true,
"docstring_mode": "full",
"enable_ccr": false,
"fallback_to_kompress": false,
"language_hint": null,
"max_body_lines": 5,
"min_tokens_for_compression": 100,
"preserve_decorators": true,
"preserve_imports": true,
"preserve_signatures": true,
"preserve_type_annotations": true,
"semantic_analysis": true,
"target_compression_rate": 0.2
},
"input": "import logging\n\n\ndef configure(level, handlers, fmt, propagate, capture_warnings):\n \"\"\"Configure logging for the whole application.\n\n Sets up the root logger with the given level and handler list,\n applies the format string to every handler, and toggles warning\n capture so library warnings are routed through the logger too.\n \"\"\"\n logger = logging.getLogger()\n logger.setLevel(level)\n formatter = logging.Formatter(fmt)\n for handler in handlers:\n handler.setFormatter(formatter)\n logger.addHandler(handler)\n logger.propagate = propagate\n logging.captureWarnings(capture_warnings)\n logger.info(\"logging configured at level %s\", level)\n return logger\n\n\ndef teardown(logger):\n for handler in list(logger.handlers):\n handler.flush()\n handler.close()\n logger.removeHandler(handler)\n return logger\n",
"input_sha256": "d72fde8ea01cb782c6e3de2e9d8322b40cc5e27593eefbd1049b64ad4467c154",
"output": {
"cache_key": null,
"compressed": "import logging\n\ndef configure(level, handlers, fmt, propagate, capture_warnings):\n \"\"\"Configure logging for the whole application.\n\n Sets up the root logger with the given level and handler list,\n applies the format string to every handler, and toggles warning\n capture so library warnings are routed through the logger too.\n \"\"\"\n logger = logging.getLogger()\n # [9 lines omitted]\n pass\ndef teardown(logger):\n for handler in list(logger.handlers):\n handler.flush()\n handler.close()\n logger.removeHandler(handler)\n # [1 lines omitted]\n pass",
"compressed_bodies": 0,
"compressed_tokens": 148,
"compression_ratio": 0.6788990825688074,
"language": "python",
"language_confidence": 1.0,
"original": "import logging\n\n\ndef configure(level, handlers, fmt, propagate, capture_warnings):\n \"\"\"Configure logging for the whole application.\n\n Sets up the root logger with the given level and handler list,\n applies the format string to every handler, and toggles warning\n capture so library warnings are routed through the logger too.\n \"\"\"\n logger = logging.getLogger()\n logger.setLevel(level)\n formatter = logging.Formatter(fmt)\n for handler in handlers:\n handler.setFormatter(formatter)\n logger.addHandler(handler)\n logger.propagate = propagate\n logging.captureWarnings(capture_warnings)\n logger.info(\"logging configured at level %s\", level)\n return logger\n\n\ndef teardown(logger):\n for handler in list(logger.handlers):\n handler.flush()\n handler.close()\n logger.removeHandler(handler)\n return logger\n",
"original_tokens": 218,
"preserved_imports": 1,
"preserved_signatures": 2,
"symbol_scores": {
"configure": 0.5,
"teardown": 0.5
},
"syntax_valid": true
},
"recorded_at": "2026-06-19T00:15:16.356466+00:00",
"transform": "code_aware_compressor"
}