Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
skills/context-compression/tests/test_compression_evaluator.py
1import importlib.util2import unittest3from pathlib import Path456MODULE_PATH = (7Path(__file__).resolve().parents[1] / "scripts" / "compression_evaluator.py"8)9MODULE_SPEC = importlib.util.spec_from_file_location(10"compression_evaluator", MODULE_PATH11)12if MODULE_SPEC is None or MODULE_SPEC.loader is None:13raise RuntimeError(f"Unable to load compression_evaluator.py from {MODULE_PATH}")14COMPRESSION_EVALUATOR = importlib.util.module_from_spec(MODULE_SPEC)15MODULE_SPEC.loader.exec_module(COMPRESSION_EVALUATOR)161718class CompressionEvaluatorTests(unittest.TestCase):19def test_json_ground_truth_terms_score_when_response_mentions_artifacts(20self,21) -> None:22evaluator = COMPRESSION_EVALUATOR.CompressionEvaluator()2324rich_score = evaluator._heuristic_score(25{"id": "artifact_files_modified"},26"We modified src/app.py and updated README.md during the session.",27'[{"path": "src/app.py", "operation": "modified"}, {"path": "README.md", "operation": "updated"}]',28)29poor_score = evaluator._heuristic_score(30{"id": "artifact_files_modified"},31"We changed some files but I do not remember which ones.",32'[{"path": "src/app.py", "operation": "modified"}, {"path": "README.md", "operation": "updated"}]',33)3435self.assertGreater(rich_score, poor_score)36self.assertGreaterEqual(rich_score, 4.0)3738def test_plain_text_ground_truth_still_uses_substring_match(self) -> None:39evaluator = COMPRESSION_EVALUATOR.CompressionEvaluator()4041exact_score = evaluator._heuristic_score(42{"id": "continuity_work_state"},43"Next: fix the websocket timeout before rerunning tests.",44"fix the websocket timeout",45)46missing_score = evaluator._heuristic_score(47{"id": "continuity_work_state"},48"Next: inspect logs again.",49"fix the websocket timeout",50)5152self.assertGreater(exact_score, missing_score)535455if __name__ == "__main__":56unittest.main()57