@@ -62,6 +62,50 @@ defmodule CodexPooler.Gateway.RequestCompression.Strategies.JsonDocumentLossless
6262 assert Enum . count ( values , fn { key , _value } -> key == "repeat" end ) == 2
6363 end
6464
65+ test "preserves synthetic high-entropy values while keeping JSON parseable" do
66+ synthetic_high_entropy_value =
67+ "synthetic-high-entropy-placeholder-Zx9Kq3Wm7Pv2Lr8Nt4Bc6Df1Gh5Jy"
68+
69+ original = """
70+ {
71+ "metadata": {
72+ "kind": "sanitized-fixture",
73+ "nested": {
74+ "synthetic_value": "#{ synthetic_high_entropy_value } ",
75+ "description": "This verbose synthetic fixture exists to keep token reduction observable."
76+ }
77+ },
78+ "records": [
79+ {
80+ "name": "alpha",
81+ "status": "ok",
82+ "notes": "Pretty printed whitespace and repeated plain fields should disappear during minification."
83+ },
84+ {
85+ "name": "beta",
86+ "status": "ok",
87+ "notes": "The JSON document strategy must preserve values exactly instead of masking content."
88+ }
89+ ],
90+ "summary": {
91+ "line_count": 2,
92+ "safe_fixture": true
93+ }
94+ }
95+ """
96+
97+ assert { :ok , % { content: compressed , metadata: metadata } } =
98+ JsonDocumentLossless . compress ( original , model: @ model )
99+
100+ assert Jason . decode! ( compressed ) == Jason . decode! ( original )
101+ assert compressed =~ synthetic_high_entropy_value
102+ assert String . contains? ( compressed , "\n ...[compressed]...\n " ) == false
103+ assert String . contains? ( compressed , " ...[compressed]... " ) == false
104+ assert metadata . strategy == :json_document_lossless
105+ assert metadata . original_tokens > metadata . compressed_tokens
106+ refute inspect ( metadata ) =~ synthetic_high_entropy_value
107+ end
108+
65109 test "skips arrays, invalid JSON, tiny token-neutral objects, and missing tokenizers" do
66110 assert :skip = JsonDocumentLossless . compress ( ~S( [{"status":"ok"}]) , model: @ model )
67111 assert :skip = JsonDocumentLossless . compress ( ~S( {"status": "open",}) , model: @ model )
0 commit comments