0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
88 lines
3.1 KiB
Python
88 lines
3.1 KiB
Python
"""Smoke tests for the PR4 lossless-first default behavior.
|
|
|
|
Verifies that `SmartCrusher()` (default constructor, no args) produces
|
|
the lossless compaction output for cleanly tabular input — the
|
|
user-visible win from PR4. Complements the legacy parity fixtures in
|
|
`test_smart_crusher_rust_parity.py` which exercise `without_compaction()`.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
|
|
def _build_extension() -> None:
|
|
try:
|
|
from headroom._core import SmartCrusher # noqa: F401
|
|
except ImportError:
|
|
pytest.skip(
|
|
"headroom._core not built — run `bash scripts/build_rust_extension.sh`",
|
|
allow_module_level=True,
|
|
)
|
|
|
|
|
|
_build_extension()
|
|
|
|
|
|
def test_default_lossless_wins_on_uniform_tabular() -> None:
|
|
"""50 uniform tabular dicts → CSV+schema beats threshold (>=30%)
|
|
by a wide margin. Default `SmartCrusher()` ships the compacted
|
|
string in place of the array."""
|
|
from headroom._core import SmartCrusher
|
|
|
|
items = [{"id": i, "level": "info", "msg": "ok"} for i in range(50)]
|
|
content = json.dumps(items)
|
|
crusher = SmartCrusher()
|
|
result = crusher.crush(content, "", 1.0)
|
|
|
|
# Output should be SHORTER than input (lossless win).
|
|
assert len(result.compressed) < len(content), (
|
|
f"compressed not smaller: {len(result.compressed)} >= {len(content)}"
|
|
)
|
|
# Strategy string surfaces the lossless tag.
|
|
assert result.strategy.startswith("lossless:table"), (
|
|
f"expected lossless:table, got {result.strategy!r}"
|
|
)
|
|
# was_modified flips because the JSON has a string where the
|
|
# array used to be.
|
|
assert result.was_modified
|
|
|
|
|
|
def test_default_falls_through_to_lossy_when_below_threshold() -> None:
|
|
"""Heterogeneous / non-tabular input → compactor declines (or
|
|
savings below threshold) → lossy path runs."""
|
|
from headroom._core import SmartCrusher
|
|
|
|
# 30 unique-id objects with no schema redundancy → not enough
|
|
# tabular signal for lossless to clear 30% by itself.
|
|
items = [{"id": i, "user_unique_field_name": f"u_{i}"} for i in range(30)]
|
|
content = json.dumps(items)
|
|
crusher = SmartCrusher()
|
|
result = crusher.crush(content, "", 1.0)
|
|
|
|
# Either lossless wins (above threshold), OR lossy ran. Both are
|
|
# acceptable; what we're guarding against is "nothing happened."
|
|
# If the strategy is `passthrough` something is wrong.
|
|
assert result.strategy != "passthrough", (
|
|
f"expected some compression, got passthrough: {result.compressed[:80]!r}"
|
|
)
|
|
|
|
|
|
def test_without_compaction_preserves_pre_pr4_behavior() -> None:
|
|
"""Opt-out constructor matches the legacy parity path."""
|
|
from headroom._core import SmartCrusher
|
|
|
|
items = [{"id": i, "level": "info", "msg": "ok"} for i in range(50)]
|
|
content = json.dumps(items)
|
|
crusher = SmartCrusher.without_compaction()
|
|
result = crusher.crush(content, "", 1.0)
|
|
|
|
# No lossless attempt → output stays JSON-array-shaped
|
|
# (pre-PR4 contract).
|
|
parsed = json.loads(result.compressed)
|
|
assert isinstance(parsed, list), (
|
|
f"expected JSON array, got {type(parsed).__name__}: {result.compressed[:80]!r}"
|
|
)
|