@alexgreensh/token-optimizer 0.0.0-stage → 5.13.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/.claude-plugin/marketplace.json +76 -0
  2. package/.claude-plugin/plugin.json +21 -0
  3. package/LICENSE +130 -0
  4. package/LICENSE-SMALL-BUSINESS.md +62 -0
  5. package/PRIVACY.md +200 -0
  6. package/README.md +13 -2
  7. package/hooks/codex-hooks.json +4 -0
  8. package/hooks/hooks.json +182 -0
  9. package/hooks/module_runner.py +448 -0
  10. package/hooks/posttooluse_runner.py +1110 -0
  11. package/hooks/python-launcher.sh +816 -0
  12. package/hooks/run.py +788 -0
  13. package/hooks/sessionstart_runner.py +629 -0
  14. package/hooks/stop_runner.py +408 -0
  15. package/hooks/userpromptsubmit_runner.py +722 -0
  16. package/hooks/windows-launcher.py +163 -0
  17. package/install-cloud.sh +23 -0
  18. package/package.json +29 -4
  19. package/skills/fleet-auditor/SKILL.md +149 -0
  20. package/skills/fleet-auditor/references/fleet-systems.md +167 -0
  21. package/skills/fleet-auditor/references/report-template.md +50 -0
  22. package/skills/fleet-auditor/references/waste-patterns.md +126 -0
  23. package/skills/fleet-auditor/scripts/fleet.py +3633 -0
  24. package/skills/fleet-auditor/scripts/shared.py +277 -0
  25. package/skills/resume-checkpoint/SKILL.md +52 -0
  26. package/skills/resume-checkpoint/scripts/pull_checkpoint.py +188 -0
  27. package/skills/token-coach/SKILL.md +141 -0
  28. package/skills/token-coach/assets/coach-dashboard-tab.html +45 -0
  29. package/skills/token-coach/examples/coaching-session-agentic.md +62 -0
  30. package/skills/token-coach/examples/coaching-session-heavy-setup.md +46 -0
  31. package/skills/token-coach/examples/coaching-session-new-project.md +38 -0
  32. package/skills/token-coach/references/agentic-systems.md +147 -0
  33. package/skills/token-coach/references/coach-patterns.md +120 -0
  34. package/skills/token-coach/references/coaching-scripts.md +146 -0
  35. package/skills/token-coach/references/deterministic-stages.md +102 -0
  36. package/skills/token-coach/references/keepwarm-consent.md +48 -0
  37. package/skills/token-coach/references/quick-reference.md +155 -0
  38. package/skills/token-dashboard/SKILL.md +93 -0
  39. package/skills/token-optimizer/SKILL.md +150 -0
  40. package/skills/token-optimizer/assets/dashboard.html +7251 -0
  41. package/skills/token-optimizer/examples/claude-md-optimized.md +40 -0
  42. package/skills/token-optimizer/examples/hooks-starter.json +179 -0
  43. package/skills/token-optimizer/examples/permissions-deny-template.json +24 -0
  44. package/skills/token-optimizer/pricing/prices.json +695 -0
  45. package/skills/token-optimizer/references/agent-prompts.md +687 -0
  46. package/skills/token-optimizer/references/cli-reference.md +92 -0
  47. package/skills/token-optimizer/references/codex-workflow.md +188 -0
  48. package/skills/token-optimizer/references/cursor-workflow.md +74 -0
  49. package/skills/token-optimizer/references/error-recovery.md +37 -0
  50. package/skills/token-optimizer/references/implementation-playbook.md +416 -0
  51. package/skills/token-optimizer/references/keepwarm-consent.md +48 -0
  52. package/skills/token-optimizer/references/opencode-workflow.md +72 -0
  53. package/skills/token-optimizer/references/optimization-checklist.md +714 -0
  54. package/skills/token-optimizer/references/phase0-setup.md +142 -0
  55. package/skills/token-optimizer/references/presentation-workflow.md +72 -0
  56. package/skills/token-optimizer/references/session-continuity.md +19 -0
  57. package/skills/token-optimizer/references/token-flow-architecture.md +629 -0
  58. package/skills/token-optimizer/scripts/activity_tracker.py +143 -0
  59. package/skills/token-optimizer/scripts/antigravity_doctor.py +548 -0
  60. package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +511 -0
  61. package/skills/token-optimizer/scripts/antigravity_install.py +379 -0
  62. package/skills/token-optimizer/scripts/antigravity_proto.py +413 -0
  63. package/skills/token-optimizer/scripts/antigravity_session.py +346 -0
  64. package/skills/token-optimizer/scripts/antigravity_state.py +486 -0
  65. package/skills/token-optimizer/scripts/archive_result.py +1725 -0
  66. package/skills/token-optimizer/scripts/bash_compress.py +2490 -0
  67. package/skills/token-optimizer/scripts/bash_compress_hook.py +766 -0
  68. package/skills/token-optimizer/scripts/bash_hook.py +61 -0
  69. package/skills/token-optimizer/scripts/bash_whitelist.py +243 -0
  70. package/skills/token-optimizer/scripts/benchmark.py +1765 -0
  71. package/skills/token-optimizer/scripts/build_output_compress.py +776 -0
  72. package/skills/token-optimizer/scripts/cloud_kit.py +1011 -0
  73. package/skills/token-optimizer/scripts/codex_command_compress.py +434 -0
  74. package/skills/token-optimizer/scripts/codex_compact_prompt.py +273 -0
  75. package/skills/token-optimizer/scripts/codex_doctor.py +454 -0
  76. package/skills/token-optimizer/scripts/codex_hook_bridge.py +311 -0
  77. package/skills/token-optimizer/scripts/codex_install.py +810 -0
  78. package/skills/token-optimizer/scripts/codex_io.py +119 -0
  79. package/skills/token-optimizer/scripts/codex_log_index.py +219 -0
  80. package/skills/token-optimizer/scripts/codex_models.py +34 -0
  81. package/skills/token-optimizer/scripts/codex_session.py +1186 -0
  82. package/skills/token-optimizer/scripts/codex_state.py +707 -0
  83. package/skills/token-optimizer/scripts/codex_statusline.py +303 -0
  84. package/skills/token-optimizer/scripts/command_filters.py +386 -0
  85. package/skills/token-optimizer/scripts/compression_backfill.py +600 -0
  86. package/skills/token-optimizer/scripts/compression_log.py +230 -0
  87. package/skills/token-optimizer/scripts/context_intel.py +331 -0
  88. package/skills/token-optimizer/scripts/context_pressure.py +115 -0
  89. package/skills/token-optimizer/scripts/copilot_doctor.py +406 -0
  90. package/skills/token-optimizer/scripts/copilot_hook_bridge.py +709 -0
  91. package/skills/token-optimizer/scripts/copilot_install.py +288 -0
  92. package/skills/token-optimizer/scripts/copilot_session.py +496 -0
  93. package/skills/token-optimizer/scripts/copilot_state.py +569 -0
  94. package/skills/token-optimizer/scripts/copilot_vscode.py +832 -0
  95. package/skills/token-optimizer/scripts/cowork_doctor.py +270 -0
  96. package/skills/token-optimizer/scripts/cowork_install.py +380 -0
  97. package/skills/token-optimizer/scripts/credential_patterns.py +1514 -0
  98. package/skills/token-optimizer/scripts/cursor_doctor.py +602 -0
  99. package/skills/token-optimizer/scripts/cursor_hook_bridge.py +843 -0
  100. package/skills/token-optimizer/scripts/cursor_install.py +426 -0
  101. package/skills/token-optimizer/scripts/cursor_session.py +303 -0
  102. package/skills/token-optimizer/scripts/cursor_state.py +348 -0
  103. package/skills/token-optimizer/scripts/delta_diff.py +110 -0
  104. package/skills/token-optimizer/scripts/detectors/__init__.py +2 -0
  105. package/skills/token-optimizer/scripts/detectors/bad_decomposition.py +78 -0
  106. package/skills/token-optimizer/scripts/detectors/cache_instability.py +504 -0
  107. package/skills/token-optimizer/scripts/detectors/looping.py +88 -0
  108. package/skills/token-optimizer/scripts/detectors/output_waste.py +143 -0
  109. package/skills/token-optimizer/scripts/detectors/overpowered.py +116 -0
  110. package/skills/token-optimizer/scripts/detectors/pdf_ingestion.py +52 -0
  111. package/skills/token-optimizer/scripts/detectors/registry.py +65 -0
  112. package/skills/token-optimizer/scripts/detectors/respond_to_bash.py +76 -0
  113. package/skills/token-optimizer/scripts/detectors/retry_churn.py +83 -0
  114. package/skills/token-optimizer/scripts/detectors/tool_cascade.py +62 -0
  115. package/skills/token-optimizer/scripts/detectors/wasteful_thinking.py +75 -0
  116. package/skills/token-optimizer/scripts/detectors/weak_model.py +55 -0
  117. package/skills/token-optimizer/scripts/detectors/websearch_routing.py +72 -0
  118. package/skills/token-optimizer/scripts/deterministic_candidates.py +1458 -0
  119. package/skills/token-optimizer/scripts/devin_compress.py +790 -0
  120. package/skills/token-optimizer/scripts/devin_doctor.py +403 -0
  121. package/skills/token-optimizer/scripts/devin_hooks.py +453 -0
  122. package/skills/token-optimizer/scripts/devin_install.py +1086 -0
  123. package/skills/token-optimizer/scripts/devin_source.py +119 -0
  124. package/skills/token-optimizer/scripts/devin_state.py +330 -0
  125. package/skills/token-optimizer/scripts/devin_verify.py +67 -0
  126. package/skills/token-optimizer/scripts/grok_doctor.py +560 -0
  127. package/skills/token-optimizer/scripts/grok_hook_bridge.py +699 -0
  128. package/skills/token-optimizer/scripts/grok_install.py +400 -0
  129. package/skills/token-optimizer/scripts/grok_session.py +317 -0
  130. package/skills/token-optimizer/scripts/grok_state.py +299 -0
  131. package/skills/token-optimizer/scripts/hermes_doctor.py +479 -0
  132. package/skills/token-optimizer/scripts/hermes_hook_bridge.py +285 -0
  133. package/skills/token-optimizer/scripts/hermes_install.py +668 -0
  134. package/skills/token-optimizer/scripts/hermes_session.py +691 -0
  135. package/skills/token-optimizer/scripts/hermes_state.py +448 -0
  136. package/skills/token-optimizer/scripts/hook_io.py +120 -0
  137. package/skills/token-optimizer/scripts/hook_runtime.py +716 -0
  138. package/skills/token-optimizer/scripts/injection.py +156 -0
  139. package/skills/token-optimizer/scripts/install_reconcile.py +952 -0
  140. package/skills/token-optimizer/scripts/measure.py +59531 -0
  141. package/skills/token-optimizer/scripts/outline.py +53 -0
  142. package/skills/token-optimizer/scripts/pipeline_analyzer.py +723 -0
  143. package/skills/token-optimizer/scripts/plugin_env.py +562 -0
  144. package/skills/token-optimizer/scripts/py_trust.py +80 -0
  145. package/skills/token-optimizer/scripts/quality_cache_gate.py +320 -0
  146. package/skills/token-optimizer/scripts/read_cache.py +2489 -0
  147. package/skills/token-optimizer/scripts/recovery_output.py +110 -0
  148. package/skills/token-optimizer/scripts/refetch_fingerprint.py +236 -0
  149. package/skills/token-optimizer/scripts/refetch_guard.py +244 -0
  150. package/skills/token-optimizer/scripts/routing_advisor.py +389 -0
  151. package/skills/token-optimizer/scripts/runtime_env.py +1923 -0
  152. package/skills/token-optimizer/scripts/session_store.py +979 -0
  153. package/skills/token-optimizer/scripts/spawn_utils.py +122 -0
  154. package/skills/token-optimizer/scripts/statusline.js +660 -0
  155. package/skills/token-optimizer/scripts/structure_map.py +2880 -0
  156. package/skills/token-optimizer/scripts/structure_map_ts.py +676 -0
  157. package/skills/token-optimizer/scripts/structure_replay.py +1556 -0
  158. package/skills/token-optimizer/scripts/thrash_guard.py +604 -0
  159. package/skills/token-optimizer/scripts/token_estimate.py +80 -0
  160. package/skills/token-optimizer/scripts/tool_search_diagnostic.py +61 -0
  161. package/skills/token-optimizer/scripts/utf8_io.py +219 -0
@@ -0,0 +1,1765 @@
1
+ #!/usr/bin/env python3
2
+ """Token Optimizer v5: Compression Benchmark Framework.
3
+
4
+ Runs fixture-based tests against compression patterns. Each fixture defines:
5
+ - raw CLI output (input)
6
+ - expected compressed output (or pattern to match)
7
+ - critical info that MUST be preserved
8
+ - critical info that MUST NOT be lost
9
+
10
+ Token counting uses bytes/4 proxy (closer to BPE than word count).
11
+ """
12
+
13
+ import json
14
+ import sys
15
+ from pathlib import Path
16
+
17
+ # ---------------------------------------------------------------------------
18
+ # Token estimation (same as measure.py _estimate_tokens)
19
+ # ---------------------------------------------------------------------------
20
+
21
+ def estimate_tokens(text):
22
+ """Estimate token count using bytes/4 proxy."""
23
+ if not text:
24
+ return 0
25
+ return len(text.encode("utf-8", errors="replace")) // 4
26
+
27
+
28
+ # ---------------------------------------------------------------------------
29
+ # Built-in fixtures (curated input/output pairs)
30
+ # ---------------------------------------------------------------------------
31
+
32
+ FIXTURES = [
33
+ # --- git status ---
34
+ {
35
+ "name": "git_status_basic",
36
+ "category": "git",
37
+ "command": "git status",
38
+ "raw_output": (
39
+ "On branch main\n"
40
+ "Your branch is ahead of 'origin/main' by 2 commits.\n"
41
+ " (use \"git push\" to publish your local commits)\n\n"
42
+ "Changes to be committed:\n"
43
+ " (use \"git restore --staged <file>...\" to unstage)\n"
44
+ "\tnew file: src/auth.py\n"
45
+ "\tmodified: src/utils.py\n\n"
46
+ "Changes not staged for commit:\n"
47
+ " (use \"git add <file>...\" to update what will be committed)\n"
48
+ "\tmodified: README.md\n\n"
49
+ "Untracked files:\n"
50
+ " (use \"git add <file>...\" to include in what will be committed)\n"
51
+ "\ttmp/debug.log\n"
52
+ ),
53
+ "must_preserve": [
54
+ "main", # branch name
55
+ "ahead", # ahead/behind status
56
+ "2 commits", # count
57
+ "src/auth.py", # staged file
58
+ "src/utils.py", # staged file
59
+ "README.md", # unstaged file
60
+ ],
61
+ "min_compression": 0.30, # must save at least 30%
62
+ },
63
+ {
64
+ "name": "git_status_clean",
65
+ "category": "git",
66
+ "command": "git status",
67
+ "raw_output": (
68
+ "On branch main\n"
69
+ "Your branch is up to date with 'origin/main'.\n\n"
70
+ "nothing to commit, working tree clean\n"
71
+ ),
72
+ "must_preserve": ["main", "clean"],
73
+ "min_compression": 0.0, # short output, may not compress
74
+ },
75
+ {
76
+ "name": "git_status_not_git",
77
+ "category": "git",
78
+ "command": "git status",
79
+ "raw_output": "fatal: not a git repository (or any of the parent directories): .git\n",
80
+ "must_preserve": ["fatal", "not a git repository"],
81
+ "min_compression": 0.0, # error, pass through
82
+ },
83
+
84
+ # --- git log ---
85
+ {
86
+ "name": "git_log_basic",
87
+ "category": "git",
88
+ "command": "git log --oneline -10",
89
+ "raw_output": (
90
+ "a1b2c3d Fix authentication bug in login flow\n"
91
+ "e4f5g6h Add user preferences API endpoint\n"
92
+ "i7j8k9l Update dependencies to latest versions\n"
93
+ "m0n1o2p Refactor database connection pooling\n"
94
+ "q3r4s5t Fix race condition in session handler\n"
95
+ ),
96
+ "must_preserve": [
97
+ "a1b2c3d", "e4f5g6h", # commit hashes
98
+ "authentication", "preferences", # key words from messages
99
+ ],
100
+ "min_compression": 0.0, # already compact
101
+ },
102
+
103
+ # --- pytest ---
104
+ {
105
+ "name": "pytest_mixed",
106
+ "category": "test_runner",
107
+ "command": "pytest tests/",
108
+ "raw_output": (
109
+ "============================= test session starts ==============================\n"
110
+ "platform darwin -- Python 3.11.5, pytest-7.4.0, pluggy-1.3.0\n"
111
+ "rootdir: /Users/dev/project\n"
112
+ "plugins: anyio-4.0.0\n"
113
+ "collected 47 items\n\n"
114
+ "tests/test_auth.py::test_login_success PASSED\n"
115
+ "tests/test_auth.py::test_login_invalid_password PASSED\n"
116
+ "tests/test_auth.py::test_login_missing_email PASSED\n"
117
+ "tests/test_auth.py::test_token_refresh PASSED\n"
118
+ "tests/test_auth.py::test_token_expired PASSED\n"
119
+ "tests/test_api.py::test_get_users PASSED\n"
120
+ "tests/test_api.py::test_get_users_pagination PASSED\n"
121
+ "tests/test_api.py::test_create_user PASSED\n"
122
+ "tests/test_api.py::test_create_user_duplicate PASSED\n"
123
+ "tests/test_api.py::test_update_user PASSED\n"
124
+ "tests/test_api.py::test_delete_user PASSED\n"
125
+ "tests/test_api.py::test_delete_user_not_found PASSED\n"
126
+ "tests/test_db.py::test_connection_pool PASSED\n"
127
+ "tests/test_db.py::test_transaction_rollback PASSED\n"
128
+ "tests/test_db.py::test_migration_up PASSED\n"
129
+ "tests/test_db.py::test_migration_down PASSED\n"
130
+ "tests/test_db.py::test_concurrent_writes PASSED\n"
131
+ "tests/test_db.py::test_deadlock_recovery PASSED\n"
132
+ "tests/test_utils.py::test_hash_password PASSED\n"
133
+ "tests/test_utils.py::test_validate_email PASSED\n"
134
+ "tests/test_utils.py::test_sanitize_input PASSED\n"
135
+ "tests/test_utils.py::test_rate_limiter PASSED\n"
136
+ "tests/test_utils.py::test_retry_decorator PASSED\n"
137
+ "tests/test_integration.py::test_full_login_flow PASSED\n"
138
+ "tests/test_integration.py::test_api_auth_required PASSED\n"
139
+ "tests/test_integration.py::test_data_consistency FAILED\n"
140
+ "tests/test_integration.py::test_cache_invalidation PASSED\n"
141
+ "\n"
142
+ "=================================== FAILURES ===================================\n"
143
+ "___________________ test_data_consistency ______________________________________\n\n"
144
+ " def test_data_consistency():\n"
145
+ " user = create_user(name='test')\n"
146
+ "> assert user.profile.settings == default_settings()\n"
147
+ "E AssertionError: assert {'theme': 'dark'} == {'theme': 'light'}\n"
148
+ "E Differing items:\n"
149
+ "E {'theme': 'dark'} != {'theme': 'light'}\n\n"
150
+ "tests/test_integration.py:42: AssertionError\n"
151
+ "=========================== short test summary info ============================\n"
152
+ "FAILED tests/test_integration.py::test_data_consistency - AssertionError: ...\n"
153
+ "========================= 26 passed, 1 failed in 3.42s ========================\n"
154
+ ),
155
+ "must_preserve": [
156
+ "26 passed",
157
+ "1 failed",
158
+ "test_data_consistency", # failed test name
159
+ "AssertionError", # error type
160
+ "theme", # error detail
161
+ ],
162
+ "min_compression": 0.50, # should compress significantly
163
+ },
164
+ {
165
+ "name": "pytest_all_pass",
166
+ "category": "test_runner",
167
+ "command": "pytest tests/ -q",
168
+ "raw_output": (
169
+ "47 passed in 2.31s\n"
170
+ ),
171
+ "must_preserve": ["47 passed"],
172
+ "min_compression": 0.0, # already minimal
173
+ },
174
+
175
+ # --- npm install ---
176
+ {
177
+ "name": "npm_install_verbose",
178
+ "category": "package_install",
179
+ "command": "npm install",
180
+ "raw_output": (
181
+ "npm warn deprecated inflight@1.0.6: This module is not supported\n"
182
+ "npm warn deprecated glob@7.2.3: See migration docs\n"
183
+ "npm warn deprecated rimraf@3.0.2: See migration docs\n"
184
+ "\n"
185
+ "added 145 packages, and audited 146 packages in 8s\n\n"
186
+ "12 packages are looking for funding\n"
187
+ " run `npm fund` for details\n\n"
188
+ "found 0 vulnerabilities\n"
189
+ ),
190
+ "must_preserve": [
191
+ "145 packages",
192
+ "0 vulnerabilities",
193
+ ],
194
+ "min_compression": 0.0, # Already compact output, compression may not exceed threshold
195
+ },
196
+
197
+ # --- Token preservation (security) ---
198
+ {
199
+ "name": "output_contains_aws_key",
200
+ "category": "security",
201
+ "command": "git log --format=%B -1",
202
+ "raw_output": (
203
+ "Fix config loading\n\n"
204
+ "Accidentally committed: AKIAIOSFODNN7EXAMPLE\n"
205
+ "Also found: sk-proj-abc123def456\n"
206
+ ),
207
+ "must_preserve": [
208
+ "AKIAIOSFODNN7EXAMPLE", # AWS key must never be stripped
209
+ "sk-proj-abc123def456", # OpenAI key must never be stripped
210
+ ],
211
+ "min_compression": 0.0,
212
+ },
213
+ {
214
+ "name": "output_contains_github_pat",
215
+ "category": "security",
216
+ "command": "env",
217
+ "raw_output": "GITHUB_TOKEN=ghp_ABCDEFghijklmnopqrstuvwxyz0123456789\nPATH=/usr/bin\n",
218
+ "must_preserve": ["ghp_ABCDEFghijklmnopqrstuvwxyz0123456789"],
219
+ "min_compression": 0.0,
220
+ },
221
+ {
222
+ "name": "output_contains_slack_token",
223
+ "category": "security",
224
+ "command": "cat .env",
225
+ "raw_output": "SLACK_TOKEN=xoxb-FAKE-TEST-FIXTURE-00000\nDEBUG=true\n",
226
+ "must_preserve": ["xoxb-FAKE-TEST-FIXTURE-00000"],
227
+ "min_compression": 0.0,
228
+ },
229
+
230
+ # --- Error preservation ---
231
+ {
232
+ "name": "command_not_found",
233
+ "category": "error",
234
+ "command": "unknowncmd --version",
235
+ "raw_output": "bash: unknowncmd: command not found\n",
236
+ "must_preserve": ["command not found", "unknowncmd"],
237
+ "min_compression": 0.0,
238
+ },
239
+ {
240
+ "name": "permission_denied",
241
+ "category": "error",
242
+ "command": "cat /etc/shadow",
243
+ "raw_output": "cat: /etc/shadow: Permission denied\n",
244
+ "must_preserve": ["Permission denied", "/etc/shadow"],
245
+ "min_compression": 0.0,
246
+ },
247
+
248
+ # --- ls / directory listing ---
249
+ {
250
+ "name": "ls_large_directory",
251
+ "category": "directory_listing",
252
+ "command": "ls -la",
253
+ "raw_output": "\n".join(
254
+ [f"-rw-r--r-- 1 user staff {1024+i*100} Apr 9 10:00 file_{i:03d}.py"
255
+ for i in range(60)]
256
+ ) + "\n",
257
+ "must_preserve": ["file_000.py"], # first entry preserved; last truncated by design
258
+ "min_compression": 0.10, # 60-entry dir truncated to 50 = ~16% savings
259
+ },
260
+
261
+ # --- tee-on-failure (Unit 1) ---
262
+ # When a command fails, the full raw output is returned verbatim so the
263
+ # user can debug. These fixtures exercise the predicate + passthrough path.
264
+ {
265
+ "name": "tee_pytest_nonzero_exit",
266
+ "category": "tee_on_failure",
267
+ "command": "pytest tests/",
268
+ # Realistic pytest failure output — would normally compress, but must
269
+ # return raw because the exit code is non-zero.
270
+ "raw_output": (
271
+ "============================= test session starts ==============================\n"
272
+ "platform darwin -- Python 3.11.0, pytest-7.4.0, pluggy-1.0.0\n"
273
+ "rootdir: /work\n"
274
+ "collected 60 items\n\n"
275
+ + "tests/test_a.py .......\n" * 40
276
+ + "tests/test_b.py F\n\n"
277
+ "=================================== FAILURES ===================================\n"
278
+ "__________________________________ test_bug _____________________________________\n"
279
+ "> assert foo == bar\n"
280
+ "E AssertionError\n"
281
+ "=========================== 1 failed, 40 passed in 1.23s ========================\n"
282
+ ),
283
+ "returncode": 1,
284
+ "stderr": "",
285
+ "expect_raw_passthrough": True,
286
+ },
287
+ {
288
+ "name": "tee_linter_stderr_error_exit_zero",
289
+ "category": "tee_on_failure",
290
+ "command": "ruff check .",
291
+ # Linter prints noisy diagnostics on stdout but exits 0 because it
292
+ # only reports warnings. An "error:" marker on stderr still means
293
+ # the user needs the raw detail.
294
+ "raw_output": (
295
+ "src/mod_a.py:10:5: F401 unused import\n"
296
+ "src/mod_b.py:22:1: E501 line too long\n"
297
+ "src/mod_c.py:44:9: W293 whitespace\n"
298
+ "src/mod_d.py:10:5: F401 unused import\n"
299
+ "src/mod_e.py:22:1: E501 line too long\n"
300
+ "src/mod_f.py:44:9: W293 whitespace\n"
301
+ "Found 6 errors.\n"
302
+ ),
303
+ "returncode": 0,
304
+ "stderr": "error: configuration file ruff.toml has a deprecated option\n",
305
+ "expect_raw_passthrough": True,
306
+ },
307
+ # --- lint handler (Unit 3a) ---
308
+ {
309
+ "name": "lint_ruff_typical",
310
+ "category": "lint",
311
+ "command": "ruff check .",
312
+ "raw_output": (
313
+ "src/auth.py:10:5: F401 [*] `os` imported but unused\n"
314
+ "src/auth.py:22:1: E501 Line too long (124 > 100)\n"
315
+ "src/auth.py:44:9: W293 Whitespace on blank line\n"
316
+ "src/api.py:12:5: F401 [*] `json` imported but unused\n"
317
+ "src/api.py:56:1: E501 Line too long (118 > 100)\n"
318
+ "src/api.py:78:1: E501 Line too long (115 > 100)\n"
319
+ "src/models.py:8:5: F401 [*] `typing.Any` imported but unused\n"
320
+ "src/models.py:33:1: E501 Line too long (108 > 100)\n"
321
+ "src/models.py:44:9: W293 Whitespace on blank line\n"
322
+ "src/views.py:14:5: F401 [*] `datetime` imported but unused\n"
323
+ "src/views.py:28:1: E501 Line too long (102 > 100)\n"
324
+ "src/views.py:99:9: W293 Whitespace on blank line\n"
325
+ "Found 12 errors.\n"
326
+ "[*] 4 fixable with the `--fix` option.\n"
327
+ ),
328
+ "must_preserve": ["F401", "E501", "Found 12 errors"],
329
+ "min_compression": 0.30,
330
+ },
331
+ {
332
+ "name": "lint_with_credential_leak",
333
+ "category": "lint",
334
+ "command": "pylint src/",
335
+ # Pylint output that accidentally echoes a GitHub PAT in a disabled
336
+ # warning message — the credential must survive compression via the
337
+ # pre-scan re-injection path.
338
+ "raw_output": (
339
+ "************* Module src.secrets_demo\n"
340
+ "src/secrets_demo.py:4:0: C0114 (missing-module-docstring)\n"
341
+ "src/secrets_demo.py:7:0: W0611 Unused variable 'token'\n"
342
+ "src/secrets_demo.py:8:0: C0103 Variable name doesn't conform: SECRET_TOKEN=ghp_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789\n"
343
+ "src/secrets_demo.py:12:0: E1101 Instance has no 'save' member\n"
344
+ "src/secrets_demo.py:18:0: W0611 Unused variable 'x'\n"
345
+ "src/secrets_demo.py:22:0: C0114 missing-module-docstring\n"
346
+ "src/secrets_demo.py:33:0: W0612 Unused import\n"
347
+ "src/secrets_demo.py:44:0: E0602 Undefined variable\n"
348
+ "src/secrets_demo.py:55:0: C0103 Bad name\n"
349
+ "src/secrets_demo.py:66:0: W0611 Unused variable\n"
350
+ "src/secrets_demo.py:77:0: W0612 Unused\n"
351
+ "Your code has been rated at 3.50/10\n"
352
+ ),
353
+ "must_preserve": ["ghp_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789"],
354
+ "min_compression": 0.0, # tolerate any ratio — credential is the priority
355
+ },
356
+ # --- logs handler (Unit 3b) ---
357
+ {
358
+ "name": "logs_tail_repeated_lines",
359
+ "category": "logs",
360
+ "command": "tail -n 200 app.log",
361
+ "raw_output": (
362
+ "[2026-04-11 10:00:01] INFO request=GET /api/users status=200\n"
363
+ + "[2026-04-11 10:00:02] INFO heartbeat ok\n" * 40
364
+ + "[2026-04-11 10:01:00] WARN slow query 812ms\n"
365
+ + "[2026-04-11 10:01:01] INFO heartbeat ok\n" * 30
366
+ + "[2026-04-11 10:02:00] ERROR connection reset\n"
367
+ ),
368
+ "must_preserve": ["slow query", "connection reset"],
369
+ "min_compression": 0.50,
370
+ },
371
+ {
372
+ "name": "logs_repeated_credential_safety",
373
+ "category": "logs",
374
+ "command": "tail -n 100 debug.log",
375
+ # 5 consecutive identical lines that EACH contain the same AWS access
376
+ # key. Compression collapses the run, but the preservation scan must
377
+ # keep at least one verbatim copy so the key survives.
378
+ "raw_output": (
379
+ "[2026-04-11 10:00:00] DEBUG worker starting\n"
380
+ + "[2026-04-11 10:00:01] DEBUG config AWS_KEY=AKIAIOSFODNN7EXAMPLE loaded\n" * 5
381
+ + "[2026-04-11 10:00:05] INFO worker ready\n"
382
+ + "[2026-04-11 10:00:06] INFO processing batch 1\n" * 30
383
+ + "[2026-04-11 10:00:40] INFO batch 1 complete\n"
384
+ ),
385
+ "must_preserve": ["AKIAIOSFODNN7EXAMPLE"],
386
+ "min_compression": 0.0, # safety is the only assertion that matters
387
+ },
388
+ # --- tree handler (Unit 3c) ---
389
+ {
390
+ "name": "tree_deep_project",
391
+ "category": "tree",
392
+ "command": "tree",
393
+ "raw_output": (
394
+ "project\n"
395
+ "├── src\n"
396
+ "│ ├── auth\n"
397
+ "│ │ ├── login.py\n"
398
+ "│ │ ├── tokens.py\n"
399
+ "│ │ └── helpers\n"
400
+ "│ │ ├── validation.py\n"
401
+ "│ │ └── crypto.py\n"
402
+ "│ ├── api\n"
403
+ "│ │ ├── routes.py\n"
404
+ "│ │ └── middleware\n"
405
+ "│ │ └── auth.py\n"
406
+ "│ └── models\n"
407
+ "│ ├── user.py\n"
408
+ "│ └── session.py\n"
409
+ "├── tests\n"
410
+ "│ ├── unit\n"
411
+ "│ │ ├── test_auth.py\n"
412
+ "│ │ └── test_api.py\n"
413
+ "│ └── integration\n"
414
+ "│ ├── conftest.py\n"
415
+ "│ └── test_flow.py\n"
416
+ "├── docs\n"
417
+ "│ ├── README.md\n"
418
+ "│ └── api\n"
419
+ "│ └── reference.md\n"
420
+ "├── scripts\n"
421
+ "│ └── deploy.sh\n"
422
+ "├── setup.py\n"
423
+ "└── README.md\n"
424
+ "\n"
425
+ "12 directories, 16 files\n"
426
+ ),
427
+ "must_preserve": ["project", "src", "tests", "docs"],
428
+ "min_compression": 0.15,
429
+ },
430
+ {
431
+ "name": "tree_with_credential_in_filename",
432
+ "category": "tree",
433
+ "command": "tree",
434
+ # A deeply nested secret file must still surface (via preservation scan)
435
+ # even if the containing directories sit beyond depth 2.
436
+ "raw_output": (
437
+ "secrets\n"
438
+ "├── tier1\n"
439
+ "│ ├── tier2\n"
440
+ "│ │ ├── tier3\n"
441
+ "│ │ │ └── ghp_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789.txt\n"
442
+ "│ │ └── other.txt\n"
443
+ "│ └── readme.md\n"
444
+ "├── tier1b\n"
445
+ "│ └── notes.md\n"
446
+ "├── tier1c\n"
447
+ "│ ├── a.txt\n"
448
+ "│ └── b.txt\n"
449
+ "├── tier1d\n"
450
+ "│ └── c.txt\n"
451
+ "├── tier1e\n"
452
+ "│ └── d.txt\n"
453
+ "├── tier1f\n"
454
+ "│ └── e.txt\n"
455
+ "├── tier1g\n"
456
+ "│ └── f.txt\n"
457
+ "├── tier1h\n"
458
+ "│ └── g.txt\n"
459
+ "├── tier1i\n"
460
+ "│ └── h.txt\n"
461
+ "├── tier1j\n"
462
+ "│ └── i.txt\n"
463
+ "├── tier1k\n"
464
+ "│ └── j.txt\n"
465
+ "└── tier1l\n"
466
+ " └── k.txt\n"
467
+ "\n"
468
+ "15 directories, 14 files\n"
469
+ ),
470
+ "must_preserve": ["ghp_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789"],
471
+ "min_compression": 0.0,
472
+ },
473
+ # --- progress handler (Unit 3d) ---
474
+ {
475
+ "name": "progress_docker_build_typical",
476
+ "category": "progress",
477
+ "command": "docker build -t myimg .",
478
+ "raw_output": (
479
+ "#1 [internal] load build definition from Dockerfile\n"
480
+ "#1 transferring dockerfile: 500B done\n"
481
+ "#1 DONE 0.0s\n"
482
+ "#2 [internal] load .dockerignore\n"
483
+ "#2 transferring context: 200B done\n"
484
+ "#2 DONE 0.0s\n"
485
+ "#3 [internal] load metadata for docker.io/library/python:3.11-slim\n"
486
+ "#3 DONE 0.3s\n"
487
+ "#4 [1/6] FROM docker.io/library/python:3.11-slim\n"
488
+ "#4 resolve docker.io/library/python:3.11-slim\n"
489
+ "#4 sha256:abc123\n"
490
+ "#4 DONE 0.1s\n"
491
+ "#5 [internal] load build context\n"
492
+ "#5 transferring context: 12.34kB done\n"
493
+ "#5 DONE 0.0s\n"
494
+ "#6 [2/6] WORKDIR /app\n"
495
+ "#6 DONE 0.0s\n"
496
+ "#7 [3/6] COPY requirements.txt .\n"
497
+ "#7 DONE 0.0s\n"
498
+ "#8 [4/6] RUN pip install -r requirements.txt\n"
499
+ "#8 Downloading flask-2.3.3-py3-none-any.whl\n"
500
+ "#8 Downloading werkzeug-2.3.7-py3-none-any.whl\n"
501
+ "#8 Collecting flask\n"
502
+ "#8 Collecting werkzeug\n"
503
+ "#8 Installing collected packages: werkzeug, flask\n"
504
+ "#8 Successfully installed flask-2.3.3 werkzeug-2.3.7\n"
505
+ "#8 DONE 5.4s\n"
506
+ "#9 [5/6] COPY . .\n"
507
+ "#9 DONE 0.0s\n"
508
+ "#10 [6/6] CMD [\"python\", \"app.py\"]\n"
509
+ "#10 DONE 0.0s\n"
510
+ "#11 exporting to image\n"
511
+ "#11 exporting layers\n"
512
+ "#11 exporting manifest sha256:def456\n"
513
+ "#11 naming to docker.io/library/myimg\n"
514
+ "#11 DONE 0.1s\n"
515
+ ),
516
+ "must_preserve": ["Successfully installed", "naming to"],
517
+ "min_compression": 0.30,
518
+ },
519
+ {
520
+ "name": "progress_docker_build_with_error",
521
+ "category": "progress",
522
+ "command": "docker build -t badimg .",
523
+ "raw_output": (
524
+ "#1 [internal] load build definition from Dockerfile\n"
525
+ "#1 DONE 0.0s\n"
526
+ "#2 [internal] load .dockerignore\n"
527
+ "#2 DONE 0.0s\n"
528
+ "#3 [internal] load metadata\n"
529
+ "#3 DONE 0.2s\n"
530
+ "#4 [1/4] FROM docker.io/library/alpine:3.18\n"
531
+ "#4 DONE 0.0s\n"
532
+ "#5 [2/4] RUN apk add --no-cache curl\n"
533
+ "#5 0.123 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz\n"
534
+ "#5 0.456 Downloading curl\n"
535
+ "#5 0.789 Installing curl\n"
536
+ "#5 1.234 ERROR: unable to select packages: curl-nonexistent\n"
537
+ "#5 ERROR: failed to solve: process \"apk add curl-nonexistent\" did not complete successfully: exit code: 1\n"
538
+ "#5 DONE 1.3s\n"
539
+ "#6 [3/4] RUN echo 'hello'\n"
540
+ "#6 DONE 0.0s\n"
541
+ "#7 [4/4] CMD [\"sh\"]\n"
542
+ "#7 DONE 0.0s\n"
543
+ "failed to solve: process did not complete successfully: exit code: 1\n"
544
+ ),
545
+ "must_preserve": ["ERROR", "curl-nonexistent", "failed to solve"],
546
+ "min_compression": 0.20,
547
+ },
548
+ # --- list handler (Unit 3e) ---
549
+ {
550
+ "name": "list_pip_large",
551
+ "category": "list",
552
+ "command": "pip list",
553
+ "raw_output": (
554
+ "Package Version\n"
555
+ "------------------ ---------\n"
556
+ + "\n".join(f"pkg_{i:03d} {i}.0.0" for i in range(40))
557
+ + "\n"
558
+ ),
559
+ "must_preserve": ["pkg_000", "Package"],
560
+ "min_compression": 0.30,
561
+ },
562
+ {
563
+ "name": "list_docker_ps_many_containers",
564
+ "category": "list",
565
+ "command": "docker ps",
566
+ "raw_output": (
567
+ "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n"
568
+ + "\n".join(
569
+ f"abc{i:09d} ubuntu:22.04 \"/bin/bash\" {i} hours ago Up {i} hours ctr_{i:02d}"
570
+ for i in range(30)
571
+ )
572
+ + "\n"
573
+ ),
574
+ "must_preserve": ["CONTAINER", "ctr_00"],
575
+ "min_compression": 0.40,
576
+ },
577
+ # --- B3 regression: Dutch error line inside npm output must survive ---
578
+ {
579
+ "name": "npm_install_dutch_fout_preserved",
580
+ "category": "npm_install",
581
+ "command": "npm install",
582
+ "raw_output": (
583
+ "npm WARN deprecated foo@1.0.0: use bar instead\n"
584
+ + "added 42 packages from 30 contributors\n" * 3
585
+ + "audited 100 packages in 1.2s\n"
586
+ + "fout: kan package niet installeren: vue-router\n"
587
+ + "found 0 vulnerabilities\n" * 2
588
+ + "some filler line\n" * 20
589
+ ),
590
+ "must_preserve": ["fout", "vue-router"],
591
+ "min_compression": 0.0,
592
+ },
593
+ # --- B4 regression: filename containing "nothing to commit" ---
594
+ {
595
+ "name": "git_status_filename_nothing_to_commit",
596
+ "category": "git",
597
+ "command": "git status",
598
+ "raw_output": (
599
+ "On branch main\n"
600
+ "Your branch is up to date with 'origin/main'.\n\n"
601
+ "Untracked files:\n"
602
+ " (use \"git add <file>...\" to include in what will be committed)\n"
603
+ "\tnothing to commit.txt\n"
604
+ "\tsecret.key\n"
605
+ "\tcredentials.json\n\n"
606
+ "nothing added to commit but untracked files present (use \"git add\" to track)\n"
607
+ ),
608
+ "must_preserve": ["nothing to commit.txt", "secret.key", "credentials.json"],
609
+ "must_not_contain": ["branch: main, clean"],
610
+ "min_compression": 0.0,
611
+ },
612
+ # --- C6 regression: "Found N errors" must be summary, not error count ---
613
+ {
614
+ "name": "build_found_n_errors_classified_as_summary",
615
+ "category": "build",
616
+ "command": "tsc --noEmit",
617
+ "raw_output": (
618
+ "src/a.ts(1,1): error TS2322: type mismatch\n" * 3
619
+ + "src/b.ts(2,1): error TS2304: unknown name\n" * 3
620
+ + "src/c.ts(3,1): error TS2322: type mismatch\n" * 3
621
+ + "src/d.ts(4,1): error TS2339: no such member\n" * 3
622
+ + "Found 12 errors in 4 files.\n"
623
+ + "Errors Files\n"
624
+ + " 3 src/a.ts\n"
625
+ + " 3 src/b.ts\n"
626
+ + " 3 src/c.ts\n"
627
+ + " 3 src/d.ts\n"
628
+ ),
629
+ "must_preserve": ["TS2322", "Found 12 errors"],
630
+ "must_not_contain": ["13 error/warning", "14 error/warning", "15 error/warning", "16 error/warning"],
631
+ "min_compression": 0.0,
632
+ },
633
+ # --- adversarial: git status porcelain v2 must route to raw ---
634
+ {
635
+ "name": "git_status_porcelain_v2_routes_to_raw",
636
+ "category": "git",
637
+ "command": "git status --porcelain=v2 --branch",
638
+ "raw_output": (
639
+ "# branch.oid 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b\n"
640
+ "# branch.head main\n"
641
+ "# branch.upstream origin/main\n"
642
+ "# branch.ab +0 -0\n"
643
+ "1 .M N... 100644 100644 100644 abcd1234 abcd1234 src/app.py\n"
644
+ "1 .M N... 100644 100644 100644 ef567890 ef567890 src/db.py\n"
645
+ "1 M. N... 100644 100644 100644 11111111 22222222 src/staged.py\n"
646
+ "? untracked.txt\n"
647
+ "? .env.new\n"
648
+ ),
649
+ "must_preserve": ["src/app.py", "src/db.py", "src/staged.py", "untracked.txt", ".env.new"],
650
+ "must_not_contain": ["branch: ?"],
651
+ "min_compression": 0.0,
652
+ },
653
+ # --- adversarial: git status -s must route to raw ---
654
+ {
655
+ "name": "git_status_short_routes_to_raw",
656
+ "category": "git",
657
+ "command": "git status -sb",
658
+ "raw_output": (
659
+ "## main...origin/main [ahead 2]\n"
660
+ " M src/handler.py\n"
661
+ "MM src/config.py\n"
662
+ "?? tmp/debug.log\n"
663
+ "?? .secrets.env\n"
664
+ ),
665
+ "must_preserve": ["src/handler.py", "src/config.py", "tmp/debug.log", ".secrets.env"],
666
+ "must_not_contain": ["branch: ?"],
667
+ "min_compression": 0.0,
668
+ },
669
+ # --- adversarial: preserved line substring of compressed line still surfaces ---
670
+ {
671
+ "name": "lint_preserved_line_inside_longer_compressed_line",
672
+ "category": "lint",
673
+ "command": "eslint .",
674
+ "raw_output": (
675
+ " 1. src/app.py E501 too long - see report: disk full\n"
676
+ " 2. src/app.py E501 too long\n"
677
+ " 3. src/app.py E501 too long\n"
678
+ " 4. src/db.py E501 too long\n"
679
+ " 5. src/api.py E501 too long\n"
680
+ " 6. src/auth.py E501 too long\n"
681
+ " 7. src/io.py E501 too long\n"
682
+ " 8. src/fs.py E501 too long\n"
683
+ " 9. src/net.py E501 too long\n"
684
+ " 10. src/log.py E501 too long\n"
685
+ " 11. src/ui.py E501 too long\n"
686
+ " 12. src/ops.py E501 too long\n"
687
+ " 13. fatal: disk full\n"
688
+ ),
689
+ # `fatal: disk full` is a preservation trigger and must land as its
690
+ # own line in the compressed output, even though the phrase happens
691
+ # to be contained in the first lint sample line.
692
+ "must_preserve": ["fatal: disk full"],
693
+ "min_compression": 0.0,
694
+ },
695
+ # --- adversarial: "no errors" substring in a real error line ---
696
+ {
697
+ "name": "build_no_errors_phrase_in_real_error_line",
698
+ "category": "build",
699
+ "command": "tsc --noEmit",
700
+ "raw_output": (
701
+ "[1/5] Compiling src/index.ts\n"
702
+ "src/index.ts(42,10): error TS2322: Expected 'no errors' but found 'undefined'.\n"
703
+ "src/index.ts(43,1): error TS2345: Argument type mismatch.\n"
704
+ "[2/5] Compiling src/auth.ts\n"
705
+ "src/auth.ts(10,5): error TS2322: Type 'string' is not assignable.\n"
706
+ "src/auth.ts(12,5): error TS2344: Constraint violation.\n"
707
+ "src/auth.ts(15,5): error TS2339: Property 'foo' does not exist.\n"
708
+ "src/auth.ts(18,5): error TS2341: Private access.\n"
709
+ "src/auth.ts(20,5): error TS2342: Index signature missing.\n"
710
+ "src/auth.ts(22,5): error TS2343: Generic type unresolved.\n"
711
+ "src/auth.ts(24,5): error TS2344: Constraint violation.\n"
712
+ "src/auth.ts(26,5): error TS2345: Argument mismatch.\n"
713
+ "src/auth.ts(28,5): error TS2346: Call signature mismatch.\n"
714
+ "src/auth.ts(30,5): error TS2347: Untyped function call.\n"
715
+ "src/auth.ts(32,5): error TS2348: Constructor signature missing.\n"
716
+ "src/auth.ts(34,5): error TS2349: Callable expected.\n"
717
+ "[3/5] Done in 0.4s\n"
718
+ "Found 14 errors in 2 files. Watching for file changes.\n"
719
+ ),
720
+ "must_preserve": ["TS2322", "Expected 'no errors'", "Found 14 errors"],
721
+ # Handler header must NOT undercount the first error line; "no
722
+ # errors" is part of a real compiler message here.
723
+ "must_not_contain": ["13 error/warning lines"],
724
+ "min_compression": 0.0,
725
+ },
726
+ # --- R3 correctness: "N0 errors" must not match the "0 errors" prefix ---
727
+ {
728
+ "name": "build_ten_errors_not_classified_as_clean",
729
+ "category": "build",
730
+ "command": "tsc --noEmit",
731
+ "raw_output": (
732
+ "src/a.ts(1,1): error TS2322: type mismatch\n" * 3
733
+ + "src/b.ts(2,1): error TS2304: unknown name\n" * 3
734
+ + "src/c.ts(3,1): error TS2322: type mismatch\n" * 2
735
+ + "src/d.ts(4,1): error TS2339: no such member\n" * 2
736
+ + "10 errors found across 4 files\n"
737
+ ),
738
+ "must_preserve": ["TS2322", "10 errors found"],
739
+ "min_compression": 0.0,
740
+ },
741
+ # --- adversarial: FOUT web-perf text must not false-trigger preservation ---
742
+ {
743
+ "name": "foreign_fout_web_perf_false_positive_avoided",
744
+ "category": "lint",
745
+ "command": "ruff check src/",
746
+ "raw_output": (
747
+ "src/perf.js:1:1: E501 line exceeds 80 characters\n"
748
+ "src/perf.js:2:1: E501 line exceeds 80 characters\n"
749
+ "src/perf.js:3:1: E501 line exceeds 80 characters\n"
750
+ "src/perf.js:4:1: E501 line exceeds 80 characters\n"
751
+ "src/perf.js:5:1: E501 line exceeds 80 characters\n"
752
+ "src/perf.js:6:1: E501 line exceeds 80 characters\n"
753
+ "src/perf.js:7:1: E501 FOUT detected 340ms unstyled window on /index.html\n"
754
+ "src/perf.js:8:1: E501 line exceeds 80 characters\n"
755
+ "src/perf.js:9:1: E501 line exceeds 80 characters\n"
756
+ "src/perf.js:10:1: E501 line exceeds 80 characters\n"
757
+ "src/perf.js:11:1: E501 line exceeds 80 characters\n"
758
+ "src/perf.js:12:1: E501 line exceeds 80 characters\n"
759
+ "Found 12 errors.\n"
760
+ ),
761
+ # FOUT (Flash Of Unstyled Text — web-perf term) appears in a real
762
+ # lint finding on line 7. The tightened foreign-error pattern
763
+ # requires a trailing colon, so `FOUT detected 340ms` does NOT
764
+ # trigger the preservation path. The lint handler groups all 12
765
+ # findings under E501, picks line 1 as the sample, and drops
766
+ # lines 2-12 including the FOUT one — so the FOUT text never
767
+ # surfaces in the compressed output.
768
+ "must_preserve": ["E501", "Found 12 errors"],
769
+ "must_not_contain": ["FOUT detected 340ms unstyled window"],
770
+ "min_compression": 0.30,
771
+ },
772
+ # --- C-R2-5 regression: blocked prefix must not shadow real lint code ---
773
+ {
774
+ "name": "lint_cve_does_not_shadow_real_code",
775
+ "category": "lint",
776
+ "command": "ruff check .",
777
+ "raw_output": (
778
+ "src/audit.py:10:5: E501 line too long (CVE2024 referenced)\n"
779
+ "src/audit.py:12:5: E501 another long line\n"
780
+ "src/audit.py:14:5: E501 third long line\n"
781
+ "src/audit.py:16:5: F401 unused import\n"
782
+ "src/audit.py:18:5: F401 unused import\n"
783
+ "src/audit.py:20:5: F401 unused import\n"
784
+ "src/audit.py:22:5: F401 unused import\n"
785
+ "src/audit.py:24:5: F401 unused import\n"
786
+ "Found 8 errors.\n"
787
+ ),
788
+ "must_preserve": ["F401", "E501"],
789
+ "must_not_contain": ["CVE2024 x"],
790
+ "min_compression": 0.0,
791
+ },
792
+ # --- C-R2-4 regression: clean tsc build must not mislabel as errors ---
793
+ {
794
+ "name": "build_tsc_clean_not_mislabeled",
795
+ "category": "build",
796
+ "command": "tsc --noEmit",
797
+ "raw_output": (
798
+ "src/a.ts:1: checking\n" * 15
799
+ + "src/b.ts:1: checking\n" * 10
800
+ + "Found 0 errors. Watching for file changes.\n"
801
+ ),
802
+ "must_preserve": ["Found 0 errors"],
803
+ # Must NOT emit a misleading "1 error/warning lines" header
804
+ "must_not_contain": ["1 error/warning lines", "2 error/warning lines"],
805
+ "min_compression": 0.0,
806
+ },
807
+
808
+ # --- B1 regression: silent build must not fabricate "no errors" ---
809
+ {
810
+ "name": "build_silent_no_error_keywords",
811
+ "category": "build",
812
+ "command": "go build -v ./...",
813
+ # Go build -v emits per-package context with no "error"/"warning"
814
+ # keywords on a silent build. The handler used to lie and return
815
+ # "[build output: no errors or warnings detected; output elided]".
816
+ # Fix: return raw so the 10% ratio gate lets it through unchanged.
817
+ "raw_output": "\n".join(
818
+ f"github.com/acme/svc/pkg_{i}" for i in range(30)
819
+ ) + "\n",
820
+ "must_preserve": ["pkg_0", "pkg_29"],
821
+ "min_compression": 0.0,
822
+ },
823
+ # --- B2 regression: non-English stderr must trigger tee passthrough ---
824
+ {
825
+ "name": "tee_german_stderr_error_exit_zero",
826
+ "category": "tee_on_failure",
827
+ "command": "eslint src/",
828
+ "raw_output": "src/foo.js:10:5 some warning that would normally compress " * 20 + "\n",
829
+ "returncode": 0,
830
+ "stderr": "Fehler: Konfigurationsdatei nicht gefunden\n",
831
+ "expect_raw_passthrough": True,
832
+ },
833
+ {
834
+ "name": "tee_chinese_stderr_error_exit_zero",
835
+ "category": "tee_on_failure",
836
+ "command": "pylint src/",
837
+ "raw_output": "src/foo.py: C0103 bad name " * 40 + "\n",
838
+ "returncode": 0,
839
+ "stderr": "错误: 配置文件损坏\n",
840
+ "expect_raw_passthrough": True,
841
+ },
842
+ # --- C2 regression: lint must not fake rule codes from CVE/HTTP/RFC ---
843
+ {
844
+ "name": "lint_must_not_treat_cve_as_rule_code",
845
+ "category": "lint",
846
+ "command": "eslint src/",
847
+ "raw_output": (
848
+ "src/audit.js:10:5 error URL https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE2024 linked no-unused-vars\n"
849
+ "src/audit.js:12:5 error See RFC7231 section 4.3 for details no-undef\n"
850
+ "src/audit.js:14:5 error HTTP404 returned on GET no-console\n"
851
+ "src/audit.js:16:5 error ISO9001 compliance check failed eqeqeq\n"
852
+ "src/audit.js:18:5 error Use MD5 or SHA256 only no-magic-numbers\n"
853
+ "src/audit.js:20:5 error plain text response no-unused-vars\n"
854
+ "src/audit.js:22:5 error event loop blocked no-console\n"
855
+ "src/audit.js:24:5 error stale cache hit prefer-const\n"
856
+ "src/audit.js:26:5 error subtle bug here curly\n"
857
+ "src/audit.js:28:5 error type coercion eqeqeq\n"
858
+ "\n✖ 10 problems (10 errors)\n"
859
+ ),
860
+ "must_preserve": ["no-unused-vars", "10 problems"],
861
+ # The handler must NOT produce lines like "CVE2024 x1", "HTTP404 x1",
862
+ # "RFC7231 x1", "ISO9001 x1", "MD5 x1", "SHA x1" — they would be
863
+ # fake rule codes. We verify via must_not_contain.
864
+ "must_not_contain": ["CVE2024 x", "HTTP404 x", "RFC7231 x", "ISO9001 x"],
865
+ "min_compression": 0.0,
866
+ },
867
+ # --- C3 regression: trailing warnings must not hide the pass count ---
868
+ {
869
+ "name": "pytest_trailing_deprecation_warnings_pass_count_survives",
870
+ "category": "test",
871
+ "command": "pytest tests/",
872
+ "raw_output": (
873
+ "============================= test session starts ==============================\n"
874
+ + "tests/test_a.py .\n" * 30
875
+ + "============================== 30 passed in 2.11s ==============================\n"
876
+ + "DeprecationWarning: future-removal 1\n" * 20
877
+ ),
878
+ "must_preserve": ["30 passed"],
879
+ "min_compression": 0.30,
880
+ },
881
+ # --- Sec-2 regression: JWT credential preservation ---
882
+ {
883
+ "name": "logs_jwt_credential_preserved",
884
+ "category": "logs",
885
+ "command": "tail -n 60 auth.log",
886
+ "raw_output": (
887
+ "[2026-04-11] INFO auth start\n"
888
+ + "[2026-04-11] INFO heartbeat ok\n" * 40
889
+ + "[2026-04-11] INFO token issued eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\n"
890
+ + "[2026-04-11] INFO heartbeat ok\n" * 10
891
+ ),
892
+ "must_preserve": ["eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"],
893
+ "min_compression": 0.0,
894
+ },
895
+ # --- Sec-2 regression: Google API key preservation ---
896
+ {
897
+ "name": "logs_google_api_key_preserved",
898
+ "category": "logs",
899
+ "command": "tail -n 60 app.log",
900
+ "raw_output": (
901
+ "[2026-04-11] DEBUG config loaded\n" * 30
902
+ + "[2026-04-11] INFO GOOGLE_API_KEY=AIzaSyBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789abc set\n"
903
+ + "[2026-04-11] DEBUG config loaded\n" * 10
904
+ ),
905
+ "must_preserve": ["AIzaSyBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789abc"],
906
+ "min_compression": 0.0,
907
+ },
908
+ # --- SEC-R2-1 regression: credential in OSC 8 hyperlink label text ---
909
+ {
910
+ "name": "logs_osc8_hyperlink_credential_preserved",
911
+ "category": "logs",
912
+ "command": "tail -n 60 audit.log",
913
+ # The AWS access key is embedded as the visible label of an OSC 8
914
+ # hyperlink. The ANSI stripper must preserve the label text so the
915
+ # preservation scan can see it before compression runs.
916
+ "raw_output": (
917
+ "[2026-04-11] INFO audit start\n" * 30
918
+ + "[2026-04-11] INFO token visit \x1b]8;;https://iam.example.com/keys\x07AKIAIOSFODNN7EXAMPLE\x1b]8;;\x07\n"
919
+ + "[2026-04-11] INFO audit continue\n" * 15
920
+ ),
921
+ "must_preserve": ["AKIAIOSFODNN7EXAMPLE"],
922
+ "min_compression": 0.0,
923
+ },
924
+
925
+ # --- Sec-2 regression: DB URI with embedded password preservation ---
926
+ {
927
+ "name": "logs_db_uri_credential_preserved",
928
+ "category": "logs",
929
+ "command": "tail -n 50 db.log",
930
+ "raw_output": (
931
+ "[2026-04-11] INFO db connect start\n" * 30
932
+ + "[2026-04-11] ERROR failed: postgres://admin:sUperS3cret@db.internal:5432/prod\n"
933
+ + "[2026-04-11] INFO retry scheduled\n" * 15
934
+ ),
935
+ "must_preserve": ["postgres://admin:sUperS3cret@db.internal:5432/prod"],
936
+ "min_compression": 0.0,
937
+ },
938
+
939
+ # --- build handler (Unit 3f) ---
940
+ {
941
+ "name": "build_tsc_with_errors",
942
+ "category": "build",
943
+ "command": "tsc --noEmit",
944
+ "raw_output": (
945
+ "src/api/users.ts(10,5): error TS2322: Type 'string' is not assignable to type 'number'.\n"
946
+ "src/api/users.ts(22,8): error TS2304: Cannot find name 'foo'.\n"
947
+ "src/api/users.ts(44,12): error TS2339: Property 'bar' does not exist on type 'User'.\n"
948
+ "src/lib/helpers.ts(5,1): error TS1005: ',' expected.\n"
949
+ "src/lib/helpers.ts(8,3): error TS2345: Argument of type '{}' is not assignable.\n"
950
+ "src/lib/helpers.ts(12,9): error TS2531: Object is possibly 'null'.\n"
951
+ "src/models/user.ts(3,1): error TS2305: Module has no exported member 'Foo'.\n"
952
+ "src/models/user.ts(15,4): error TS2307: Cannot find module 'bar'.\n"
953
+ "src/index.ts(1,1): error TS6133: 'x' is declared but its value is never read.\n"
954
+ "src/index.ts(5,5): error TS2322: Type 'null' is not assignable to type 'string'.\n"
955
+ "src/index.ts(10,8): error TS2345: Argument of wrong type.\n"
956
+ "src/utils/date.ts(3,1): error TS2300: Duplicate identifier 'parseDate'.\n"
957
+ "Found 12 errors in 5 files.\n"
958
+ "\n"
959
+ "Errors Files\n"
960
+ " 3 src/api/users.ts\n"
961
+ " 3 src/lib/helpers.ts\n"
962
+ " 2 src/models/user.ts\n"
963
+ " 3 src/index.ts\n"
964
+ " 1 src/utils/date.ts\n"
965
+ ),
966
+ "must_preserve": ["TS2322", "Found 12 errors"],
967
+ # Broken builds naturally do not compress much — we preserve every
968
+ # error line plus the summary. The value of this fixture is the
969
+ # "must_preserve" contract and the "Found N errors" aggregate being
970
+ # routed to the summary bucket (not mis-counted as an error line).
971
+ "min_compression": 0.0,
972
+ },
973
+ {
974
+ "name": "build_vite_clean",
975
+ "category": "build",
976
+ "command": "vite build",
977
+ # Clean build with asset tables — handler should drop all the asset
978
+ # chatter and emit a "no errors detected" marker.
979
+ "raw_output": (
980
+ "vite v5.0.0 building for production...\n"
981
+ "transforming...\n"
982
+ "✓ 240 modules transformed.\n"
983
+ "dist/index.html 0.47 kB │ gzip: 0.30 kB\n"
984
+ "dist/assets/index-abc.css 12.34 kB │ gzip: 3.00 kB\n"
985
+ "dist/assets/vendor-def.js 220.11 kB │ gzip: 70.50 kB\n"
986
+ "dist/assets/page-home-ghi.js 33.22 kB │ gzip: 11.10 kB\n"
987
+ "dist/assets/page-about-jkl.js 22.11 kB │ gzip: 8.01 kB\n"
988
+ "dist/assets/page-users-mno.js 44.44 kB │ gzip: 14.00 kB\n"
989
+ "dist/assets/page-posts-pqr.js 55.55 kB │ gzip: 17.00 kB\n"
990
+ "dist/assets/page-admin-stu.js 66.66 kB │ gzip: 20.00 kB\n"
991
+ "dist/assets/lib-vwx.js 77.77 kB │ gzip: 22.00 kB\n"
992
+ "dist/assets/polyfill-yz.js 11.11 kB │ gzip: 3.50 kB\n"
993
+ "dist/assets/utils-123.js 8.88 kB │ gzip: 2.50 kB\n"
994
+ "dist/assets/state-456.js 9.99 kB │ gzip: 3.00 kB\n"
995
+ "dist/assets/router-789.js 4.44 kB │ gzip: 1.50 kB\n"
996
+ "dist/assets/ui-abc.js 15.55 kB │ gzip: 5.00 kB\n"
997
+ "dist/assets/icons-def.js 7.77 kB │ gzip: 2.00 kB\n"
998
+ "dist/assets/fonts-ghi.js 3.33 kB │ gzip: 1.20 kB\n"
999
+ "dist/assets/i18n-jkl.js 10.10 kB │ gzip: 3.30 kB\n"
1000
+ "dist/assets/hooks-mno.js 5.50 kB │ gzip: 1.80 kB\n"
1001
+ "dist/assets/api-pqr.js 12.12 kB │ gzip: 4.00 kB\n"
1002
+ "dist/assets/types-stu.js 2.20 kB │ gzip: 0.80 kB\n"
1003
+ "dist/assets/test-vwx.js 1.10 kB │ gzip: 0.40 kB\n"
1004
+ "✓ built in 4.23s\n"
1005
+ ),
1006
+ "must_preserve": ["built in"],
1007
+ "min_compression": 0.40,
1008
+ },
1009
+ # --- test-runner extensions (Unit 3g) ---
1010
+ {
1011
+ "name": "test_exts_playwright_mixed",
1012
+ "category": "test_exts",
1013
+ "command": "npx playwright test",
1014
+ "raw_output": (
1015
+ "Running 40 tests using 4 workers\n\n"
1016
+ + " ok [chromium] › tests/login.spec.ts:10:3 › login works\n" * 10
1017
+ + " ok [firefox] › tests/login.spec.ts:10:3 › login works\n" * 10
1018
+ + " ok [webkit] › tests/login.spec.ts:10:3 › login works\n" * 10
1019
+ + " x [chromium] › tests/checkout.spec.ts:22:5 › checkout flow\n"
1020
+ " Error: expect(received).toBe(expected)\n"
1021
+ " Expected: 200\n"
1022
+ " Received: 500\n"
1023
+ " ok [firefox] › tests/checkout.spec.ts:22:5 › checkout flow\n"
1024
+ " x [webkit] › tests/checkout.spec.ts:22:5 › checkout flow\n"
1025
+ " Error: Timeout exceeded\n"
1026
+ " Expected: true\n"
1027
+ " Received: false\n"
1028
+ + " ok [chromium] › tests/misc.spec.ts:5:1 › smoke\n" * 7
1029
+ + "\n 38 passed (12.3s)\n 2 failed\n"
1030
+ ),
1031
+ "must_preserve": ["passed", "failed"],
1032
+ "min_compression": 0.30,
1033
+ },
1034
+ {
1035
+ "name": "test_exts_cypress_all_pass",
1036
+ "category": "test_exts",
1037
+ "command": "cypress run",
1038
+ "raw_output": (
1039
+ " Running: login.cy.ts\n\n"
1040
+ + " ✓ shows login form\n" * 15
1041
+ + " ✓ submits successfully\n" * 15
1042
+ + "\n"
1043
+ " 30 passing (4s)\n"
1044
+ ),
1045
+ "must_preserve": ["passing"],
1046
+ "min_compression": 0.20,
1047
+ },
1048
+ {
1049
+ "name": "test_exts_mocha_short_should_not_compress",
1050
+ "category": "test_exts",
1051
+ "command": "mocha test/",
1052
+ "raw_output": (
1053
+ " Array\n"
1054
+ " ✓ should return -1 when value not present\n"
1055
+ "\n"
1056
+ " 1 passing (5ms)\n"
1057
+ ),
1058
+ "must_preserve": ["passing"],
1059
+ "min_compression": 0.0,
1060
+ },
1061
+
1062
+ {
1063
+ "name": "build_short_should_not_compress",
1064
+ "category": "build",
1065
+ "command": "tsc --noEmit",
1066
+ "raw_output": "Found 0 errors. Watching for file changes.\n",
1067
+ "must_preserve": ["Found 0 errors"],
1068
+ "min_compression": 0.0,
1069
+ },
1070
+
1071
+ {
1072
+ "name": "list_short_should_not_compress",
1073
+ "category": "list",
1074
+ "command": "brew list",
1075
+ "raw_output": "git\npython@3.11\nnode\nruff\nvulture\n",
1076
+ "must_preserve": ["git", "python@3.11"],
1077
+ "min_compression": 0.0,
1078
+ },
1079
+
1080
+ {
1081
+ "name": "progress_docker_short_should_not_compress",
1082
+ "category": "progress",
1083
+ "command": "docker build -t tiny .",
1084
+ "raw_output": (
1085
+ "#1 [internal] load Dockerfile\n"
1086
+ "#1 DONE 0.0s\n"
1087
+ "#2 [1/1] FROM scratch\n"
1088
+ "#2 DONE 0.0s\n"
1089
+ "#3 exporting\n"
1090
+ "#3 DONE 0.0s\n"
1091
+ ),
1092
+ "must_preserve": ["FROM scratch"],
1093
+ "min_compression": 0.0,
1094
+ },
1095
+
1096
+ {
1097
+ "name": "tree_shallow_should_not_compress",
1098
+ "category": "tree",
1099
+ "command": "tree -L 1",
1100
+ "raw_output": (
1101
+ "project\n"
1102
+ "├── src\n"
1103
+ "├── tests\n"
1104
+ "├── docs\n"
1105
+ "├── README.md\n"
1106
+ "└── setup.py\n"
1107
+ "\n"
1108
+ "3 directories, 2 files\n"
1109
+ ),
1110
+ "must_preserve": ["src", "tests"],
1111
+ "min_compression": 0.0,
1112
+ },
1113
+
1114
+ {
1115
+ "name": "logs_mixed_no_dups_should_not_compress",
1116
+ "category": "logs",
1117
+ "command": "journalctl -u myservice",
1118
+ # 22 different lines, no adjacent duplicates — handler must bail out.
1119
+ "raw_output": "\n".join(
1120
+ f"[2026-04-11 10:{i:02d}:00] INFO unique event {i} data=foo_{i}"
1121
+ for i in range(22)
1122
+ ) + "\n",
1123
+ "must_preserve": ["event 0", "event 21"],
1124
+ "min_compression": 0.0,
1125
+ },
1126
+ {
1127
+ "name": "lint_too_short_should_not_compress",
1128
+ "category": "lint",
1129
+ "command": "eslint src/",
1130
+ "raw_output": (
1131
+ "/Users/alex/project/src/foo.js\n"
1132
+ " 2:1 error 'foo' is defined but never used no-unused-vars\n\n"
1133
+ "✖ 1 problem (1 error, 0 warnings)\n"
1134
+ ),
1135
+ "must_preserve": ["no-unused-vars", "1 error"],
1136
+ "min_compression": 0.0, # short input — fall through raw
1137
+ },
1138
+
1139
+ {
1140
+ "name": "tee_clean_run_exit_zero_no_stderr",
1141
+ "category": "tee_on_failure",
1142
+ "command": "pytest tests/",
1143
+ # Clean run — tee predicate must NOT trigger, so this output is free
1144
+ # to compress through the normal pytest handler.
1145
+ "raw_output": (
1146
+ "============================= test session starts ==============================\n"
1147
+ "platform darwin -- Python 3.11.0, pytest-7.4.0, pluggy-1.0.0\n"
1148
+ "collected 60 items\n\n"
1149
+ + "tests/test_a.py .......\n" * 40
1150
+ + "tests/test_b.py .......\n" * 20
1151
+ + "\n============================== 60 passed in 1.23s ==============================\n"
1152
+ ),
1153
+ "returncode": 0,
1154
+ "stderr": "",
1155
+ "must_preserve": ["60 passed"],
1156
+ "min_compression": 0.10,
1157
+ },
1158
+ # --- v5.8 test-runner extension fixtures ---
1159
+ {
1160
+ "name": "test_exts_unittest_verbose",
1161
+ "category": "test_exts",
1162
+ "command": "python3 -m unittest",
1163
+ "raw_output": (
1164
+ "test_01 (test_module.TestSomething) ... ok\n"
1165
+ "test_02 (test_module.TestSomething) ... ok\n"
1166
+ "test_03 (test_module.TestSomething) ... ok\n"
1167
+ "test_04 (test_module.TestSomething) ... ok\n"
1168
+ "test_05 (test_module.TestSomething) ... ok\n"
1169
+ "\n"
1170
+ "----------------------------------------------------------------------\n"
1171
+ "Ran 5 tests in 0.001s\n\n"
1172
+ "OK\n"
1173
+ ),
1174
+ "must_preserve": ["Ran 5", "OK"],
1175
+ "min_compression": 0.0,
1176
+ },
1177
+ {
1178
+ "name": "test_exts_unittest_large",
1179
+ "category": "test_exts",
1180
+ "command": "python3 -m unittest",
1181
+ "raw_output": (
1182
+ "".join(
1183
+ f"test_{i:03d} (test_module.TestSuite.test_case_{i}) ... {'ok' if i % 5 != 0 else 'FAIL'}\n"
1184
+ for i in range(60)
1185
+ )
1186
+ + "\n"
1187
+ + "======================================================================\n"
1188
+ + "FAIL: test_005 (test_module.TestSuite.test_case_5)\n"
1189
+ + "Traceback (most recent call last):\n"
1190
+ + " File test_module.py, line 10, in test_case_5\n"
1191
+ + " self.assertEqual(a, b)\n"
1192
+ + "AssertionError: 1 != 2\n"
1193
+ + "\n"
1194
+ + "----------------------------------------------------------------------\n"
1195
+ + "Ran 60 tests in 0.123s\n\n"
1196
+ + "FAILED (failures=12)\n"
1197
+ ),
1198
+ "must_preserve": ["Ran 60", "FAILED", "failures=12"],
1199
+ "min_compression": 0.30,
1200
+ },
1201
+ {
1202
+ "name": "test_exts_gradle_verbose",
1203
+ "category": "test_exts",
1204
+ "command": "gradle test",
1205
+ "raw_output": (
1206
+ "> Task :compileTestJava\n"
1207
+ "> Task :processTestResources\n"
1208
+ "> Task :testClasses\n"
1209
+ + "".join(
1210
+ f"> Task :test\n com.example.TestClass{i}.testMethod{i} PASSED\n"
1211
+ for i in range(40)
1212
+ )
1213
+ + "\nBUILD SUCCESSFUL in 5s\n"
1214
+ + "12 actionable tasks: 12 executed\n"
1215
+ ),
1216
+ "must_preserve": ["BUILD SUCCESSFUL", "PASSED"],
1217
+ "min_compression": 0.30,
1218
+ },
1219
+ {
1220
+ "name": "test_exts_ava_verbose",
1221
+ "category": "test_exts",
1222
+ "command": "npx ava",
1223
+ "raw_output": (
1224
+ "".join(
1225
+ f" ✔ test-{i} › should do something meaningful [{i}ms]\n"
1226
+ for i in range(50)
1227
+ )
1228
+ + "\n 50 tests passed\n"
1229
+ ),
1230
+ "must_preserve": ["50 tests passed"],
1231
+ "min_compression": 0.30,
1232
+ },
1233
+ {
1234
+ "name": "test_exts_deno_verbose",
1235
+ "category": "test_exts",
1236
+ "command": "deno test",
1237
+ "raw_output": (
1238
+ "running 40 tests from ./test/\n"
1239
+ + "".join(
1240
+ f"test_{i} ... ok ({i}ms)\n"
1241
+ for i in range(40)
1242
+ )
1243
+ + "\nok | 40 passed | 0 failed (120ms)\n"
1244
+ ),
1245
+ "must_preserve": ["40 passed", "0 failed"],
1246
+ "min_compression": 0.30,
1247
+ },
1248
+ {
1249
+ "name": "test_exts_bun_verbose",
1250
+ "category": "test_exts",
1251
+ "command": "bun test",
1252
+ "raw_output": (
1253
+ "".join(
1254
+ f"✓ test_{i}.test.ts > test_case_{i} [0.{i:02d}ms]\n"
1255
+ for i in range(50)
1256
+ )
1257
+ + "\n50 pass, 0 fail, 50 expect() calls\nRan all 50 tests across 1 file in 0.12s\n"
1258
+ ),
1259
+ "must_preserve": ["50 pass", "0 fail"],
1260
+ "min_compression": 0.30,
1261
+ },
1262
+ {
1263
+ "name": "test_exts_tox_verbose",
1264
+ "category": "test_exts",
1265
+ "command": "tox",
1266
+ "raw_output": (
1267
+ "py311: commands[0] > pytest\n"
1268
+ + "".join(
1269
+ f" tests/test_module_{i}.py .........\n"
1270
+ for i in range(30)
1271
+ )
1272
+ + " 300 passed in 2.34s\n\n"
1273
+ + "py310: commands[0] > pytest\n"
1274
+ + "".join(
1275
+ f" tests/test_module_{i}.py .........\n"
1276
+ for i in range(30)
1277
+ )
1278
+ + " 300 passed in 2.56s\n\n"
1279
+ + " congratulations :)\n"
1280
+ ),
1281
+ "must_preserve": ["300 passed", "congratulations"],
1282
+ "min_compression": 0.30,
1283
+ },
1284
+
1285
+ # --- JSON handler ---
1286
+ {
1287
+ "name": "json_array_tabular",
1288
+ "category": "json",
1289
+ "command": "jq .",
1290
+ "raw_output": json.dumps([
1291
+ {"id": 1, "name": "alpha", "status": "active", "value": 100},
1292
+ {"id": 2, "name": "beta", "status": "active", "value": 200},
1293
+ {"id": 3, "name": "gamma", "status": "inactive", "value": 300},
1294
+ {"id": 4, "name": "delta", "status": "active", "value": 400},
1295
+ {"id": 5, "name": "epsilon", "status": "active", "value": 500},
1296
+ ] * 10, indent=2),
1297
+ "must_preserve": ["alpha", "beta", "gamma", "id", "name", "status"],
1298
+ "min_compression": 0.40,
1299
+ },
1300
+ {
1301
+ "name": "json_array_tabular_with_credential",
1302
+ "category": "json",
1303
+ "command": "jq .",
1304
+ "raw_output": json.dumps([
1305
+ {"id": 1, "name": "alpha", "token": "sk-abc123def456ghi789jkl012mno345pqr678", "status": "active"},
1306
+ {"id": 2, "name": "beta", "token": "sk-xyz987wvu654tsr321qpo098nml765kji432", "status": "active"},
1307
+ {"id": 3, "name": "gamma", "token": "sk-test123test456test789test012test345", "status": "inactive"},
1308
+ {"id": 4, "name": "delta", "token": "sk-live111live222live333live444live555", "status": "active"},
1309
+ {"id": 5, "name": "epsilon", "token": "sk-key111key222key333key444key555key", "status": "active"},
1310
+ ] * 10, indent=2),
1311
+ "must_preserve": ["sk-abc123def456ghi789jkl012mno345pqr678", "sk-xyz987wvu654tsr321qpo098nml765kji432"],
1312
+ "min_compression": 0.30,
1313
+ },
1314
+ {
1315
+ "name": "json_too_small",
1316
+ "category": "json",
1317
+ "command": "jq .",
1318
+ "raw_output": json.dumps({"a": 1, "b": 2}),
1319
+ "must_preserve": [],
1320
+ "min_compression": 0.0,
1321
+ },
1322
+ {
1323
+ "name": "json_object_large",
1324
+ "category": "json",
1325
+ "command": "python3 -m json.tool",
1326
+ "raw_output": json.dumps({f"key_{i}": f"value_{i}_with_some_padding_to_increase_size" for i in range(50)}, indent=2),
1327
+ "must_preserve": ["key_0", "key_49"],
1328
+ "min_compression": 0.50,
1329
+ },
1330
+ # --- CSV/TSV handler ---
1331
+ {
1332
+ "name": "csv_large",
1333
+ "category": "csv",
1334
+ "command": "csvtool",
1335
+ "raw_output": "id,name,status,value\n" + "".join(
1336
+ f"{i},item_{i},active,{i * 100}\n" for i in range(100)
1337
+ ),
1338
+ "must_preserve": ["id", "name", "status", "item_0", "item_14"],
1339
+ "min_compression": 0.50,
1340
+ },
1341
+ {
1342
+ "name": "tsv_large",
1343
+ "category": "csv",
1344
+ "command": "csvtool",
1345
+ "raw_output": "id\tname\tstatus\tvalue\n" + "".join(
1346
+ f"{i}\titem_{i}\tactive\t{i * 100}\n" for i in range(100)
1347
+ ),
1348
+ "must_preserve": ["id", "name", "item_0", "item_14"],
1349
+ "min_compression": 0.50,
1350
+ },
1351
+ {
1352
+ "name": "csv_with_credential",
1353
+ "category": "csv",
1354
+ "command": "csvtool",
1355
+ "raw_output": "id,name,token,status\n" + "".join(
1356
+ f"{i},item_{i},{'sk-abc123def456ghi789jkl012mno345pqr678' if i == 5 else ''},active\n" for i in range(50)
1357
+ ),
1358
+ "must_preserve": ["sk-abc123def456ghi789jkl012mno345pqr678"],
1359
+ "min_compression": 0.30,
1360
+ },
1361
+ {
1362
+ "name": "csv_too_small",
1363
+ "category": "csv",
1364
+ "command": "csvtool",
1365
+ "raw_output": "id,name\n1,alpha\n2,beta\n",
1366
+ "must_preserve": [],
1367
+ "min_compression": 0.0,
1368
+ },
1369
+ # --- Stack trace handler ---
1370
+ {
1371
+ "name": "stack_trace_python",
1372
+ "category": "stack_trace",
1373
+ "command": "python3 app.py",
1374
+ "raw_output": (
1375
+ "Traceback (most recent call last):\n"
1376
+ + "".join(
1377
+ f' File "/app/module_{i}.py", line {i * 10}, in func_{i}\n'
1378
+ f" result = do_something_{i}()\n"
1379
+ for i in range(50)
1380
+ )
1381
+ + "ValueError: invalid configuration value\n"
1382
+ ),
1383
+ "must_preserve": ["Traceback", "ValueError", "module_0"],
1384
+ "min_compression": 0.40,
1385
+ },
1386
+ {
1387
+ "name": "stack_trace_java",
1388
+ "category": "stack_trace",
1389
+ "command": "java -jar app.jar",
1390
+ "raw_output": (
1391
+ "Exception in thread \"main\" java.lang.NullPointerException\n"
1392
+ + "".join(
1393
+ f"\tat com.example.service.Service{i}.method(Service{i}.java:{i * 20})\n"
1394
+ for i in range(60)
1395
+ )
1396
+ ),
1397
+ "must_preserve": ["NullPointerException", "Service0"],
1398
+ "min_compression": 0.40,
1399
+ },
1400
+ {
1401
+ "name": "stack_trace_with_credential",
1402
+ "category": "stack_trace",
1403
+ "command": "python3 app.py",
1404
+ "raw_output": (
1405
+ "Traceback (most recent call last):\n"
1406
+ ' File "/app/config.py", line 10, in load_config\n'
1407
+ ' token = "ghp_abcdefghijklmnopqrstuvwxyz0123456789AB"\n'
1408
+ + "".join(
1409
+ f' File "/app/module_{i}.py", line {i * 10}, in func_{i}\n'
1410
+ f" result = do_something_{i}()\n"
1411
+ for i in range(50)
1412
+ )
1413
+ + "ValueError: invalid configuration value\n"
1414
+ ),
1415
+ "must_preserve": ["ghp_abcdefghijklmnopqrstuvwxyz0123456789AB", "ValueError"],
1416
+ "min_compression": 0.30,
1417
+ },
1418
+ {
1419
+ "name": "stack_trace_too_small",
1420
+ "category": "stack_trace",
1421
+ "command": "python3 app.py",
1422
+ "raw_output": (
1423
+ "Traceback (most recent call last):\n"
1424
+ ' File "/app/main.py", line 5, in <module>\n'
1425
+ " raise ValueError('test')\n"
1426
+ "ValueError: test\n"
1427
+ ),
1428
+ "must_preserve": ["ValueError"],
1429
+ "min_compression": 0.0,
1430
+ },
1431
+ # --- Kubernetes handler ---
1432
+ {
1433
+ "name": "k8s_get_pods_large",
1434
+ "category": "k8s",
1435
+ "command": "kubectl get pods",
1436
+ "raw_output": (
1437
+ "NAME READY STATUS RESTARTS AGE\n"
1438
+ + "".join(
1439
+ f"app-pod-{i:04d} 1/1 Running 0 {i}h\n"
1440
+ for i in range(100)
1441
+ )
1442
+ ),
1443
+ "must_preserve": ["NAME", "READY", "STATUS", "app-pod-0000", "app-pod-0014"],
1444
+ "min_compression": 0.50,
1445
+ },
1446
+ {
1447
+ "name": "k8s_get_pods_with_credential",
1448
+ "category": "k8s",
1449
+ "command": "kubectl get pods",
1450
+ "raw_output": (
1451
+ "NAME READY STATUS RESTARTS AGE\n"
1452
+ + "".join(
1453
+ f"app-pod-{i:04d} 1/1 Running 0 {i}h\n"
1454
+ for i in range(50)
1455
+ )
1456
+ + "secret-pod 1/1 Running 0 1h\n"
1457
+ + "token: sk-abc123def456ghi789jkl012mno345pqr678\n"
1458
+ ),
1459
+ "must_preserve": ["sk-abc123def456ghi789jkl012mno345pqr678", "app-pod-0000"],
1460
+ "min_compression": 0.30,
1461
+ },
1462
+ {
1463
+ "name": "k8s_too_small",
1464
+ "category": "k8s",
1465
+ "command": "kubectl get pods",
1466
+ "raw_output": (
1467
+ "NAME READY STATUS RESTARTS AGE\n"
1468
+ "app-pod-0001 1/1 Running 0 1h\n"
1469
+ "app-pod-0002 1/1 Running 0 2h\n"
1470
+ ),
1471
+ "must_preserve": [],
1472
+ "min_compression": 0.0,
1473
+ },
1474
+ # --- Cloud CLI handler ---
1475
+ {
1476
+ "name": "cloud_cli_gcloud_large",
1477
+ "category": "cloud_cli",
1478
+ "command": "gcloud compute instances list",
1479
+ "raw_output": (
1480
+ "NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS\n"
1481
+ + "".join(
1482
+ f"instance-{i:04d} us-central1-a e2-medium False 10.0.{i // 256}.{i % 256} 35.{i // 1000}.{i % 1000}.{i % 256} RUNNING\n"
1483
+ for i in range(100)
1484
+ )
1485
+ ),
1486
+ "must_preserve": ["NAME", "STATUS", "instance-0000", "RUNNING"],
1487
+ "min_compression": 0.40,
1488
+ },
1489
+ {
1490
+ "name": "cloud_cli_aws_large",
1491
+ "category": "cloud_cli",
1492
+ "command": "aws ec2 describe-instances",
1493
+ "raw_output": (
1494
+ "InstanceId InstanceType State LaunchTime\n"
1495
+ + "".join(
1496
+ f"i-{i:016x} t2.micro running 2026-01-{(i % 28) + 1:02d}\n"
1497
+ for i in range(100)
1498
+ )
1499
+ ),
1500
+ "must_preserve": ["InstanceId", "running", "i-0000000000000000"],
1501
+ "min_compression": 0.40,
1502
+ },
1503
+ {
1504
+ "name": "cloud_cli_with_credential",
1505
+ "category": "cloud_cli",
1506
+ "command": "gcloud compute instances list",
1507
+ "raw_output": (
1508
+ "NAME ZONE MACHINE_TYPE STATUS\n"
1509
+ + "".join(
1510
+ f"instance-{i:04d} us-central1-a e2-medium RUNNING\n"
1511
+ for i in range(50)
1512
+ )
1513
+ + "AKIAIOSFODNN7EXAMPLE\n"
1514
+ ),
1515
+ "must_preserve": ["AKIAIOSFODNN7EXAMPLE", "instance-0000"],
1516
+ "min_compression": 0.30,
1517
+ },
1518
+ {
1519
+ "name": "cloud_cli_too_small",
1520
+ "category": "cloud_cli",
1521
+ "command": "gcloud compute instances list",
1522
+ "raw_output": "NAME ZONE STATUS\ninst1 us-a RUNNING\n",
1523
+ "must_preserve": [],
1524
+ "min_compression": 0.0,
1525
+ },
1526
+
1527
+ # --- v5.9 search results handler ---
1528
+ {
1529
+ "name": "grep_many_matches",
1530
+ "category": "search_results",
1531
+ "command": "rg --line-number 'def' src/",
1532
+ "raw_output": "\n".join(
1533
+ f"src/module_{f:03d}.py:{l}: def func_{f}_{l}(self):"
1534
+ for f in range(20)
1535
+ for l in range(1, 11)
1536
+ ),
1537
+ "must_preserve": ["module_000", "module_019"],
1538
+ "min_compression": 0.50,
1539
+ },
1540
+ {
1541
+ "name": "grep_few_matches",
1542
+ "category": "search_results",
1543
+ "command": "rg --line-number 'TODO' src/",
1544
+ "raw_output": (
1545
+ "src/main.py:42:# TODO: fix this later\n"
1546
+ "src/utils.py:15:# TODO: add error handling\n"
1547
+ "src/models.py:89:# TODO: refactor\n"
1548
+ ),
1549
+ "must_preserve": ["TODO", "main.py", "utils.py", "models.py"],
1550
+ "min_compression": 0.0,
1551
+ },
1552
+ {
1553
+ "name": "grep_with_credential",
1554
+ "category": "search_results",
1555
+ "command": "rg --line-number 'key' .",
1556
+ "raw_output": "\n".join(
1557
+ f"config_{i:03d}.py:1:api_key = 'sk-{'a' * 20}{i:03d}'"
1558
+ for i in range(40)
1559
+ ) + "\nconfig_000.py:2:token = 'AKIAIOSFODNN7EXAMPLE'",
1560
+ "must_preserve": ["AKIAIOSFODNN7EXAMPLE"],
1561
+ "min_compression": 0.30,
1562
+ },
1563
+ {
1564
+ "name": "grep_non_file_format",
1565
+ "category": "search_results",
1566
+ "command": "rg --line-number 'test' README.md",
1567
+ "raw_output": "This is a README file.\nIt has some text.\nBut no file:line format.\n" * 15,
1568
+ "must_preserve": [],
1569
+ "min_compression": 0.0,
1570
+ },
1571
+ ]
1572
+
1573
+
1574
+ # ---------------------------------------------------------------------------
1575
+ # Benchmark runner
1576
+ # ---------------------------------------------------------------------------
1577
+
1578
+ def run_single_fixture(fixture, compressor=None):
1579
+ """Run a single fixture. Returns (passed, result_dict)."""
1580
+ name = fixture["name"]
1581
+ raw = fixture["raw_output"]
1582
+ must_preserve = fixture.get("must_preserve", [])
1583
+ min_compression = fixture.get("min_compression", 0.0)
1584
+
1585
+ raw_tokens = estimate_tokens(raw)
1586
+
1587
+ # If no compressor provided, just validate the fixture structure
1588
+ if compressor is None:
1589
+ return True, {
1590
+ "name": name,
1591
+ "category": fixture.get("category", "unknown"),
1592
+ "raw_tokens": raw_tokens,
1593
+ "compressed_tokens": raw_tokens,
1594
+ "ratio": 0.0,
1595
+ "preserved_all": True,
1596
+ "status": "no_compressor",
1597
+ }
1598
+
1599
+ # Optional tee-on-failure kwargs (Unit 1): let fixtures simulate the
1600
+ # subprocess outcome without actually running a real command.
1601
+ compressor_kwargs = {}
1602
+ if "returncode" in fixture:
1603
+ compressor_kwargs["returncode"] = fixture["returncode"]
1604
+ if "stderr" in fixture:
1605
+ compressor_kwargs["stderr"] = fixture["stderr"]
1606
+
1607
+ try:
1608
+ compressed = compressor(fixture["command"], raw, **compressor_kwargs)
1609
+ except Exception as e:
1610
+ return False, {
1611
+ "name": name,
1612
+ "error": str(e),
1613
+ "status": "compressor_error",
1614
+ }
1615
+
1616
+ compressed_tokens = estimate_tokens(compressed)
1617
+ ratio = 1.0 - compressed_tokens / max(raw_tokens, 1)
1618
+
1619
+ # Tee-on-failure check: raw output must pass through verbatim.
1620
+ if fixture.get("expect_raw_passthrough"):
1621
+ if compressed != raw:
1622
+ return False, {
1623
+ "name": name,
1624
+ "category": fixture.get("category", "unknown"),
1625
+ "raw_tokens": raw_tokens,
1626
+ "compressed_tokens": compressed_tokens,
1627
+ "ratio": round(ratio, 4),
1628
+ "preserved_all": False,
1629
+ "missing_items": ["raw_passthrough"],
1630
+ "status": "FAIL",
1631
+ }
1632
+ return True, {
1633
+ "name": name,
1634
+ "category": fixture.get("category", "unknown"),
1635
+ "command": fixture.get("command", ""),
1636
+ "raw_tokens": raw_tokens,
1637
+ "compressed_tokens": compressed_tokens,
1638
+ "ratio": 0.0,
1639
+ "preserved_all": True,
1640
+ "status": "pass",
1641
+ }
1642
+
1643
+ # Check preservation
1644
+ missing = []
1645
+ for item in must_preserve:
1646
+ if item not in compressed:
1647
+ missing.append(item)
1648
+
1649
+ preserved_all = len(missing) == 0
1650
+
1651
+ # Check minimum compression ratio
1652
+ meets_ratio = ratio >= min_compression
1653
+
1654
+ # Negative assertion: certain strings must NOT appear in the output
1655
+ # (used to catch fake lint rule codes like CVE2024).
1656
+ must_not_contain = fixture.get("must_not_contain", [])
1657
+ forbidden_found = []
1658
+ for item in must_not_contain:
1659
+ if item in compressed:
1660
+ forbidden_found.append(item)
1661
+ no_forbidden = len(forbidden_found) == 0
1662
+
1663
+ passed = preserved_all and meets_ratio and no_forbidden
1664
+
1665
+ return passed, {
1666
+ "name": name,
1667
+ "category": fixture.get("category", "unknown"),
1668
+ "command": fixture.get("command", ""),
1669
+ "raw_tokens": raw_tokens,
1670
+ "compressed_tokens": compressed_tokens,
1671
+ "ratio": round(ratio, 4),
1672
+ "min_required": min_compression,
1673
+ "meets_ratio": meets_ratio,
1674
+ "preserved_all": preserved_all,
1675
+ "missing_items": missing,
1676
+ "forbidden_found": forbidden_found,
1677
+ "status": "pass" if passed else "FAIL",
1678
+ }
1679
+
1680
+
1681
+ def run_benchmarks(compressor=None, as_json=False):
1682
+ """Run all benchmark fixtures. Returns True if all pass."""
1683
+ results = []
1684
+ all_passed = True
1685
+
1686
+ # Load external fixtures if any exist
1687
+ fixtures = list(FIXTURES)
1688
+ fixture_dir = Path(__file__).resolve().parent / "fixtures"
1689
+ if fixture_dir.is_dir():
1690
+ for fp in sorted(fixture_dir.glob("*.json")):
1691
+ try:
1692
+ with open(fp, "r", encoding="utf-8") as f:
1693
+ external = json.load(f)
1694
+ if isinstance(external, list):
1695
+ fixtures.extend(external)
1696
+ elif isinstance(external, dict):
1697
+ fixtures.append(external)
1698
+ except (json.JSONDecodeError, OSError) as e:
1699
+ print(f" [WARN] Skipping malformed fixture {fp.name}: {e}", file=sys.stderr)
1700
+
1701
+ for fixture in fixtures:
1702
+ passed, result = run_single_fixture(fixture, compressor=compressor)
1703
+ results.append(result)
1704
+ if not passed:
1705
+ all_passed = False
1706
+
1707
+ if as_json:
1708
+ summary = {
1709
+ "total": len(results),
1710
+ "passed": sum(1 for r in results if r.get("status") in ("pass", "no_compressor")),
1711
+ "failed": sum(1 for r in results if r.get("status") == "FAIL"),
1712
+ "errors": sum(1 for r in results if r.get("status") == "compressor_error"),
1713
+ "results": results,
1714
+ }
1715
+ print(json.dumps(summary, indent=2))
1716
+ else:
1717
+ total_raw = sum(r.get("raw_tokens", 0) for r in results)
1718
+ total_comp = sum(r.get("compressed_tokens", 0) for r in results)
1719
+
1720
+ print(f"\n Compression Benchmark ({len(results)} fixtures)")
1721
+ print(f" {'=' * 60}")
1722
+
1723
+ for r in results:
1724
+ status = r.get("status", "?")
1725
+ if status == "no_compressor":
1726
+ marker = "[ ]"
1727
+ elif status == "pass":
1728
+ marker = "[OK]"
1729
+ elif status == "FAIL":
1730
+ marker = "[!!]"
1731
+ else:
1732
+ marker = "[ER]"
1733
+
1734
+ name = r.get("name", "?")
1735
+ raw_t = r.get("raw_tokens", 0)
1736
+ comp_t = r.get("compressed_tokens", 0)
1737
+ ratio = r.get("ratio", 0)
1738
+
1739
+ print(f" {marker} {name:35s} {raw_t:>6} -> {comp_t:>6} tokens ({ratio:>5.1%})")
1740
+
1741
+ if r.get("missing_items"):
1742
+ for item in r["missing_items"]:
1743
+ print(f" MISSING: {item!r}")
1744
+ if r.get("forbidden_found"):
1745
+ for item in r["forbidden_found"]:
1746
+ print(f" FORBIDDEN: {item!r}")
1747
+
1748
+ print(f"\n Total: {total_raw:,} raw tokens, {total_comp:,} compressed")
1749
+ if total_raw > 0:
1750
+ print(f" Overall ratio: {1.0 - total_comp / total_raw:.1%}")
1751
+
1752
+ passed_count = sum(1 for r in results if r.get("status") in ("pass", "no_compressor"))
1753
+ failed_count = sum(1 for r in results if r.get("status") == "FAIL")
1754
+ print(f"\n {passed_count} passed, {failed_count} failed")
1755
+ if not compressor:
1756
+ print(" (No compressor provided -- fixture validation only)")
1757
+ print()
1758
+
1759
+ return all_passed
1760
+
1761
+
1762
+ if __name__ == "__main__":
1763
+ as_json = "--json" in sys.argv
1764
+ ok = run_benchmarks(as_json=as_json)
1765
+ sys.exit(0 if ok else 1)