File size: 28,586 Bytes
253a5d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
{
  "generation": {
    "digest": "36c265b7880d88aef196b0c79becf66867e7b36635adb870c6d308f5610c2b31",
    "manifest": {
      "approvals": [
        {
          "authorization_ref": "local-web-delegation-v1:user-c3adb31fc78c4d59970af883326ccff5",
          "digest": "2185bc60b2d41acb5bc706360467db1a6a92ca1b6bffa32d3f11dd924c165f01",
          "increment": true,
          "mechanism": "delegated_local_validation",
          "node": "design_confirm",
          "scope": "design",
          "user_id": "user-c3adb31fc78c4d59970af883326ccff5"
        },
        {
          "authorization_ref": "local-web-delegation-v1:user-c3adb31fc78c4d59970af883326ccff5",
          "digest": "38db1a18ea15453d78e47350e8d23fadabbe2966d3b4476d1382dd63b558db82",
          "increment": true,
          "mechanism": "delegated_local_validation",
          "node": "execution_confirm",
          "scope": "execution",
          "user_id": "user-c3adb31fc78c4d59970af883326ccff5"
        },
        {
          "authorization_ref": "local-web-delegation-v1:user-c3adb31fc78c4d59970af883326ccff5",
          "digest": "edf9d2f157a0fc72ca9e42ec5c9f26331ac60b480e8b3f1cde13ccd498f98b40",
          "increment": false,
          "mechanism": "delegated_local_validation",
          "node": "repair-execution",
          "scope": "execution",
          "user_id": "user-c3adb31fc78c4d59970af883326ccff5"
        }
      ],
      "candidate": {
        "classes_digest": "31888e310a086e6807cc096b7bdb06164ae9a556c8f582228d9e9d7b43b0b6cf",
        "config_digest": "af40be185fe8b9dd8ecdd495a0785520aaebb54ebbabe97f18813d611f001e9f",
        "container": "zk-run-4e2329b555864957bc5b477ae1432717",
        "execution_mode": "qemu",
        "image": "zkcoding-qemu@sha256:5c866338b848ec50afbbcb7f0827f562c2aced18638922dd72ae73eaa6bc15ec",
        "isolation": {
          "disposable": true,
          "host_mounts": [],
          "memory_mb": 1024,
          "network": "none",
          "vcpu": 1
        },
        "passed": true,
        "receipt_digest": "4dd3a2513810493814d30734778f363391f33f14915fc48ee7b5e694be63ef2d",
        "receipt_ref": "run-4e2329b555864957bc5b477ae1432717-1026975a6b7245aeb6e369a5fc51c7a7",
        "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
        "stage": "build",
        "suite_digest": "05e353f239f8919946d419e91e63fedccbf62b02386fa12f39ad8795b6a4de4d",
        "tool_receipt": {
          "input_digest": "31692445e2704451320643e524b2f5001058816b7a4ca7fd9eada1444c66e9b4",
          "operation": "AO08",
          "result_digest": "0d207246d95b5b06b3832196f880cba8e0fcdbaa11276f5b8162752cf5188d8d",
          "run_id": "run-4e2329b555864957bc5b477ae1432717"
        }
      },
      "deployment": "not_performed",
      "development": {
        "design": {
          "summary": "Implement demo.App using Java 17 com.sun.net.httpserver.HttpServer on port 8080. Single-threaded bounded executor. Root handler routes: /health (GET->200 {\"status\":\"ok\"}), /api/calculate (GET only, else 405). Calculate requires Authorization header 'Bearer demo-calculator' (else 401). Query param expression64 must be exactly one non-empty key; value is unpadded base64url of UTF-8 expression. Validate encoded length <=256 and decoded length <=128. Use CharsetDecoder REPORT for strict UTF-8. Recursive descent parser: sum=product((+|-)product)*, product=unary((*|/)unary)*, unary=(+|-)*atom, atom=number|(sum). Numbers: digits(.digits+)? or .digits+. Allow spaces between tokens. Enforce limits: depth<=16, ops<=64, literal digits<=24, abs(value)<=1e24. Evaluate with BigDecimal DECIMAL128. Division by zero -> 400 DIVISION_BY_ZERO. Parse/Limit errors -> 400 INVALID_EXPRESSION or 422 LIMIT_EXCEEDED. Final result: round HALF_UP scale 12, strip trailing zeros, toPlainString. Return JSON {\"expression\":\"...\",\"result\":\"...\"}. Close exchanges."
        },
        "requirement": "# DEMO-CALC-01:可操作的网页计算器\n\n## 背景与用户\n员工需要在内网快速核算公式,现有简单输入框不能解释优先级或处理错误。本场景交付可直接使用的计算器网站,运算由Java服务执行,页面负责输入和结果展示。\n\n## 页面与交互\n标题“工程计算器”,主卡片包含表达式输入框、结果显示区、数字键盘0–9、小数点、加减乘除、左右括号、退格、清空和等号;旁边显示最近10条成功计算记录,窄屏放到下方。默认示例(12.5+7.5)*3,等于60。历史记录点击后回填输入,不自动重新执行。\n物理键盘可输入公式,Enter计算,Escape清空;每个按钮有明确标签,焦点可见。计算时按钮显示忙碌且防止重复请求;服务返回后再显示结果,不演示虚假延迟。除零或非法表达式在结果区给可理解错误并保留输入。成功结果可作为下次运算起点;结果字符串可复制。\n修改输入、历史回填或清空后,旧结果与复制状态立即失效,重新计算后才能复制。应用只展示输入、结果、历史和业务错误,不显示原始接口JSON、源码摘要、沙箱步骤或代码下载;开发证据保留在工作台。预览准备由平台内部完成,成果页面使用独立端口。\n\n## 编程需求与验收\n- CALC-01:Java17标准库HttpServer,GET /health。GET /api/calculate的唯一参数expression64为UTF-8表达式的无填充base64url;公开凭据demo-calculator,不接受任意脚本、eval或脚本引擎。\n- CALC-02:实现真正的表达式解析,支持+-*/、括号、空格、一元正负。乘除优先于加减,括号优先。2+3*4=14,(2+3)*4=20,-3+5=2。\n- CALC-03:用BigDecimal和DECIMAL128处理中间运算,最终最多12位小数,HALF_UP,去除尾零,不用科学记数法。0.1+0.2=0.3;1/3显示0.333333333333;连续运算可使用上次结果。\n- CALC-04:除零400 DIVISION_BY_ZERO;缺括号、连续非法运算、字母等400 INVALID_EXPRESSION;1+-2、--1属于合法一元符号。缺失、重复、未知参数及非法编码400 INVALID_INPUT。\n- CALC-05:表达式最多128字符、括号16层、64次运算;单个数字字面量最多24位(不含小数点),数值绝对值≤1e24;超限422 LIMIT_EXCEEDED。编码参数最多256字符,超限400 INVALID_INPUT。无身份401、非GET405、未知路径404,线程与输入有界。\n- CALC-06:独立HTTP系统测试覆盖算术、精度、结合顺序、负号、边界和错误;网页测试点击键盘与Enter、历史回填、连续运算、除零展示、窄屏布局。\n\n### 接口与Java实现补充约束\n\n成功和失败都必须返回UTF-8 JSON对象,不能直接返回错误码文本或HttpServer默认HTML。成功包络为`{\"expression\":\"原始表达式(保留空格)\",\"result\":\"结果字符串\"}`,错误包络统一为`{\"error\":\"对应错误码\"}`;未知路径也返回404 `{\"error\":\"NOT_FOUND\"}`。可注册统一根处理器,再精确匹配路径和方法,避免默认路由漏出HTML。\n\n数字语法为`digits ('.' digits+)?`或`'.' digits+`;`.5`合法,`1.`非法。允许标记之间的ASCII空格,保留原输入;` 12 + ( 3 * 2 ) `等于18,`1 2`仍非法,不能简单删除全部空白。严格UTF-8解码须使用CharsetDecoder的REPORT模式,不能用会替换非法字节的默认字符串构造。需要ByteBuffer/CharBuffer时应显式导入`java.nio.ByteBuffer`和`java.nio.CharBuffer`,或使用完整类名,确保Java17实际编译。此处是公开接口和编程约束,不允许修改保护测试。\n\n## 交付与完成条件\n交付Java源码、配套HTML/CSS/JS页面、需求与技术说明、差异、测试对应表、实际沙箱编译和测试证据、可下载ZIP及本地网站。生成源码限定src/main/java/demo/App.java及可选docs,不引入框架或修改保护测试;受控网页模板作为独立交付文件明确来源。失败必须留存诊断并修复复测,不以静态数字冒充Java执行结果。\n\n\nHF验收批次 20261024T043922Z calculator。完整实现上述需求;模型、框架和权限仍由服务端冻结契约决定。"
      },
      "human_acceptance": false,
      "model_calls": [
        {
          "charged": 5039,
          "id": 4,
          "metadata": {
            "finish_reason": "stop",
            "model": "qwen3.8-flash",
            "policy_version": "bailian-task-routing-v2",
            "request_id": "chatcmpl-c7b411d6-6d06-9c14-ad89-5ac8aed95611",
            "requested_output_tokens": 2048,
            "retry_of": null,
            "route_reason": "technical-design",
            "stage": "design"
          },
          "prompt_digest": "f850c544aa2dbee7d723a05f19fc7af1aa1ca9c7b09a679bd1bb6a3ff24ae74a",
          "provider": "bailian-qwen3.8-flash",
          "reservation": 18638,
          "run_id": "run-4e2329b555864957bc5b477ae1432717",
          "state": "settled"
        },
        {
          "charged": 4570,
          "id": 5,
          "metadata": {
            "finish_reason": "stop",
            "model": "qwen3.8-max",
            "policy_version": "bailian-task-routing-v2",
            "request_id": "chatcmpl-1dbf5d69-b11a-9c84-b24e-c4c36e18b516",
            "requested_output_tokens": 8192,
            "retry_of": null,
            "route_reason": "java-code",
            "stage": "code"
          },
          "prompt_digest": "ab6c2a18422f46dda202f1cc58889f3936a8f0c587dd88d6a5f009ea182245f4",
          "provider": "bailian-qwen3.8-max",
          "reservation": 18111,
          "run_id": "run-4e2329b555864957bc5b477ae1432717",
          "state": "settled"
        },
        {
          "charged": 8183,
          "id": 6,
          "metadata": {
            "finish_reason": "stop",
            "model": "qwen3.8-max",
            "policy_version": "bailian-task-routing-v2",
            "request_id": "chatcmpl-f2995fff-4705-9edf-9072-766d3dcfb34c",
            "requested_output_tokens": 11849,
            "retry_of": null,
            "route_reason": "diagnostic-repair",
            "stage": "repair"
          },
          "prompt_digest": "ce8167361acb92254e3de1a1a1b6a1d64976042c3f2a12deed177c18f7294bca",
          "provider": "bailian-qwen3.8-max",
          "reservation": 32000,
          "run_id": "run-4e2329b555864957bc5b477ae1432717",
          "state": "settled"
        }
      ],
      "preview": {
        "cases": 1,
        "classes_digest": "31888e310a086e6807cc096b7bdb06164ae9a556c8f582228d9e9d7b43b0b6cf",
        "config_digest": "af40be185fe8b9dd8ecdd495a0785520aaebb54ebbabe97f18813d611f001e9f",
        "container": "zk-run-4e2329b555864957bc5b477ae1432717",
        "execution_mode": "qemu",
        "image": "zkcoding-qemu@sha256:5c866338b848ec50afbbcb7f0827f562c2aced18638922dd72ae73eaa6bc15ec",
        "isolation": {
          "disposable": true,
          "host_mounts": [],
          "memory_mb": 1024,
          "network": "none",
          "vcpu": 1
        },
        "passed": true,
        "passed_cases": 1,
        "preview_scope": "disposable-vm-loopback-http",
        "receipt_digest": "4dd3a2513810493814d30734778f363391f33f14915fc48ee7b5e694be63ef2d",
        "receipt_ref": "run-4e2329b555864957bc5b477ae1432717-1026975a6b7245aeb6e369a5fc51c7a7",
        "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
        "stage": "preview",
        "suite_digest": "05e353f239f8919946d419e91e63fedccbf62b02386fa12f39ad8795b6a4de4d",
        "tool_receipt": {
          "input_digest": "9095d3cf2d02a31d5379192aec8c3b3fce2d66a9998f864076c84b5097d63b9b",
          "operation": "AO10",
          "result_digest": "78ff00ddbdbaa345213f56545909e832b9e410230b0d1936dc0c8168a2de9857",
          "run_id": "run-4e2329b555864957bc5b477ae1432717"
        }
      },
      "repairs": 1,
      "run_id": "run-4e2329b555864957bc5b477ae1432717",
      "sandbox_cleaned": true,
      "snapshot": {
        "budget": {
          "max_model_calls": 6,
          "max_repairs": 2,
          "max_seconds": 1800,
          "max_tokens": 120000
        },
        "execution_order": [
          "start",
          "requirements",
          "knowledge",
          "context",
          "design",
          "design_confirm",
          "execution_confirm",
          "code",
          "patch",
          "policy",
          "build",
          "test",
          "preview",
          "acceptance",
          "evidence",
          "end"
        ],
        "execution_status": "not_started",
        "framework": {
          "allowed_paths": [
            "src/main/",
            "src/test/",
            "docs/"
          ],
          "build_tool": "jdk",
          "dependencies": {},
          "evidence_refs": [
            "local-toolchain:zkcoding-qemu@sha256:5c866338b848ec50afbbcb7f0827f562c2aced18638922dd72ae73eaa6bc15ec",
            "user-authorized-local-validation"
          ],
          "frontend": [
            "html",
            "javascript",
            "css"
          ],
          "java_release": 17,
          "language": "java",
          "profile_id": "java17-standard-web",
          "state": "approved",
          "version": "0.1.0"
        },
        "knowledge": [
          {
            "collection_id": "java-basics",
            "digest": "6de6f354ff0e845da78ad210164775f51d9a4c5f01a1e5e355911423bd6a5b5c",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-6de6f354ff0e845da78ad210",
            "scope": "reference"
          },
          {
            "collection_id": "java-patterns",
            "digest": "803bd1aef5f0764242a56a8c85a3eca81b26cebbe4ec3e6b53d3c4da8864aa2d",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-803bd1aef5f0764242a56a8c",
            "scope": "reference"
          },
          {
            "collection_id": "web-development",
            "digest": "84c82986259278c89a30d2660f66454f0a5bcb10f871c96c7ec4ea9ebb47e02a",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-84c82986259278c89a30d266",
            "scope": "reference"
          },
          {
            "collection_id": "java-frameworks",
            "digest": "28b65fe6ced6682555c8b32b676faf14020011ea525eeee57f17562acd17da4c",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-28b65fe6ced6682555c8b32b",
            "scope": "reference"
          },
          {
            "collection_id": "java-persistence",
            "digest": "972ee7e1f0072e413bec262b67b8af46364ff8aac445a9faeeeb8c041eb07f92",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-972ee7e1f0072e413bec262b",
            "scope": "reference"
          },
          {
            "collection_id": "java-testing",
            "digest": "8af9017057c130eef9f9a1617a2654859ba80ed4f108b28054aecf14a3d39c45",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-8af9017057c130eef9f9a161",
            "scope": "reference"
          },
          {
            "collection_id": "java-integration",
            "digest": "befde1177fa13476703d89a8df3902d90ad01cb7d497d0583cfe15620348c7b1",
            "enterprise_approved": false,
            "quality_status": "imported_unreviewed",
            "revision": "corpus-befde1177fa13476703d89a8",
            "scope": "reference"
          }
        ],
        "operations_lock": {
          "AO01@0.1.0": "6f2a89d1624450c6e4afd8f776f23c7df4bf402976a82d0992dfd6cfdc643bf2",
          "AO02@0.1.0": "6a4491053f9a3f55d900f3f907f81a0cfc44f09a1e2f1e770248287bc0b8d7f6",
          "AO03@0.1.0": "8a1387e065674c2987930ad865a2bdb4ab7346cb589505c350c6bb1907a7eb6d",
          "AO04@0.1.0": "3ef3f1be1b0f9240f066fa6d0b3b1430026d55763d15b5fc584a801c64be688b",
          "AO05@0.2.0": "eeac70849a9d8bebd00b1d2111545f9376cc6901f6aa611412b1cb73238e47a7",
          "AO06@0.1.0": "2b369879ba0cd2847c173cfb7cb583c1dc051553d3d3ea80f954c81c21f1f233",
          "AO07@0.1.0": "69e1e824b4c5129f62595ac3df578eec7b083411cd391a72d47303eec3843baa",
          "AO08@0.1.0": "1d75566610ac000990fd15b9fd18a6518de8af12a329b3c56d51ff29c0c30623",
          "AO09@0.1.0": "2e4bf4b3fcdfce184b8dea9ffebd18ffe91af7320b0ef3ce430edb3b5cc15c52",
          "AO10@0.1.0": "d05863bea57e94ad860696bd6ac85e072034f89f6f038f132c65b854dd366e9f",
          "AO11@0.1.0": "43b910a51da7a58810d3890eb2305d80663db6a1c187b51466f8e396a94956f0"
        },
        "project_id": "calculator-demo",
        "release_digest": "cd0772c131d61fe2a56f9905133408aa95fcce60b217d653046d8dde0ac4df77",
        "release_ref": "calculator-java-development@local-cd0772c131d61fe2",
        "snapshot_digest": "782fa08215f6847af85df3ff07d156838854a1bd8a8f5d714c45acfb744eaf91",
        "snapshot_id": "snapshot-495b318d58424852a48358285fd9d075",
        "source_digest": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
        "tenant_id": "demo-tenant",
        "user_id": "user-c3adb31fc78c4d59970af883326ccff5"
      },
      "source": {
        "files": {
          "src/main/java/demo/App.java": "package demo;\n\nimport com.sun.net.httpserver.HttpServer;\nimport com.sun.net.httpserver.HttpExchange;\nimport java.io.*;\nimport java.math.*;\nimport java.net.InetSocketAddress;\nimport java.nio.ByteBuffer;\nimport java.nio.CharBuffer;\nimport java.nio.charset.*;\nimport java.util.Base64;\nimport java.util.concurrent.Executors;\n\npublic class App {\n    static final BigDecimal LIM = new BigDecimal(\"1e24\");\n    static int ops, depth;\n\n    public static void main(String[] args) throws Exception {\n        HttpServer s = HttpServer.create(new InetSocketAddress(8080), 0);\n        s.setExecutor(Executors.newFixedThreadPool(1));\n        s.createContext(\"/\", App::handle);\n        s.start();\n    }\n\n    static void handle(HttpExchange x) throws IOException {\n        try {\n            String p = x.getRequestURI().getPath();\n            if (\"/health\".equals(p)) {\n                if (!\"GET\".equals(x.getRequestMethod())) { send(x,405,\"{\\\"error\\\":\\\"METHOD_NOT_ALLOWED\\\"}\"); return; }\n                send(x,200,\"{\\\"status\\\":\\\"ok\\\"}\"); return;\n            }\n            if (\"/api/calculate\".equals(p)) {\n                if (!\"GET\".equals(x.getRequestMethod())) { send(x,405,\"{\\\"error\\\":\\\"METHOD_NOT_ALLOWED\\\"}\"); return; }\n                String auth = x.getRequestHeaders().getFirst(\"Authorization\");\n                if (!\"Bearer demo-calculator\".equals(auth)) { send(x,401,\"{\\\"error\\\":\\\"UNAUTHORIZED\\\"}\"); return; }\n                calc(x); return;\n            }\n            send(x,404,\"{\\\"error\\\":\\\"NOT_FOUND\\\"}\");\n        } finally { x.close(); }\n    }\n\n    static void calc(HttpExchange x) throws IOException {\n        String q = x.getRequestURI().getRawQuery();\n        if (q == null || q.isEmpty()) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n        String[] parts = q.split(\"&\");\n        String enc = null;\n        for (String part : parts) {\n            int eq = part.indexOf('=');\n            String key = eq >= 0 ? part.substring(0, eq) : part;\n            if (!\"expression64\".equals(key)) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n            if (enc != null) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n            enc = eq >= 0 ? part.substring(eq + 1) : \"\";\n        }\n        if (enc == null || enc.isEmpty() || enc.length() > 256 || !enc.matches(\"[A-Za-z0-9_-]+\")) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n        byte[] b;\n        try { b = Base64.getUrlDecoder().decode(enc); } catch (Exception e) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n        CharsetDecoder d = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);\n        CharBuffer cb;\n        try { cb = d.decode(ByteBuffer.wrap(b)); } catch (Exception e) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n        String expr = cb.toString();\n        if (expr.length() > 128) { send(x,422,\"{\\\"error\\\":\\\"LIMIT_EXCEEDED\\\"}\"); return; }\n        if (expr.isEmpty()) { send(x,400,\"{\\\"error\\\":\\\"INVALID_EXPRESSION\\\"}\"); return; }\n        for (int i = 0; i < expr.length(); i++) {\n            char c = expr.charAt(i);\n            if (!((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '*' || c == '/' || c == '(' || c == ')' || c == '.' || c == ' ')) {\n                send(x,400,\"{\\\"error\\\":\\\"INVALID_EXPRESSION\\\"}\"); return;\n            }\n        }\n        ops = 0; depth = 0;\n        try {\n            int[] pos = {0};\n            BigDecimal r = parseSum(expr, pos);\n            skip(expr, pos);\n            if (pos[0] < expr.length()) throw new RuntimeException(\"X\");\n            r = r.setScale(12, RoundingMode.HALF_UP).stripTrailingZeros();\n            String rs = r.compareTo(BigDecimal.ZERO) == 0 ? \"0\" : r.toPlainString();\n            send(x,200,\"{\\\"expression\\\":\\\"\" + jesc(expr) + \"\\\",\\\"result\\\":\\\"\" + rs + \"\\\"}\");\n        } catch (RuntimeException e) {\n            String m = e.getMessage();\n            if (\"D\".equals(m)) send(x,400,\"{\\\"error\\\":\\\"DIVISION_BY_ZERO\\\"}\");\n            else if (\"L\".equals(m)) send(x,422,\"{\\\"error\\\":\\\"LIMIT_EXCEEDED\\\"}\");\n            else send(x,400,\"{\\\"error\\\":\\\"INVALID_EXPRESSION\\\"}\");\n        }\n    }\n\n    static void skip(String s, int[] p) { while (p[0] < s.length() && s.charAt(p[0]) == ' ') p[0]++; }\n\n    static BigDecimal parseSum(String s, int[] p) {\n        BigDecimal l = parseProd(s, p);\n        while (true) {\n            skip(s, p);\n            if (p[0] >= s.length()) break;\n            char c = s.charAt(p[0]);\n            if (c != '+' && c != '-') break;\n            p[0]++; if (++ops > 64) throw new RuntimeException(\"L\");\n            BigDecimal r = parseProd(s, p);\n            l = c == '+' ? l.add(r, MathContext.DECIMAL128) : l.subtract(r, MathContext.DECIMAL128);\n            chk(l);\n        }\n        return l;\n    }\n\n    static BigDecimal parseProd(String s, int[] p) {\n        BigDecimal l = parseUnary(s, p);\n        while (true) {\n            skip(s, p);\n            if (p[0] >= s.length()) break;\n            char c = s.charAt(p[0]);\n            if (c != '*' && c != '/') break;\n            p[0]++; if (++ops > 64) throw new RuntimeException(\"L\");\n            BigDecimal r = parseUnary(s, p);\n            if (c == '*') { l = l.multiply(r, MathContext.DECIMAL128); chk(l); }\n            else { if (r.signum() == 0) throw new RuntimeException(\"D\"); l = l.divide(r, MathContext.DECIMAL128); chk(l); }\n        }\n        return l;\n    }\n\n    static BigDecimal parseUnary(String s, int[] p) {\n        skip(s, p); if (p[0] >= s.length()) throw new RuntimeException(\"X\");\n        char c = s.charAt(p[0]);\n        if (c == '+' || c == '-') {\n            p[0]++; if (++ops > 64) throw new RuntimeException(\"L\");\n            BigDecimal v = parseUnary(s, p);\n            return c == '-' ? v.negate(MathContext.DECIMAL128) : v;\n        }\n        return parseAtom(s, p);\n    }\n\n    static BigDecimal parseAtom(String s, int[] p) {\n        skip(s, p); if (p[0] >= s.length()) throw new RuntimeException(\"X\");\n        if (s.charAt(p[0]) == '(') {\n            p[0]++; if (++depth > 16) throw new RuntimeException(\"L\");\n            BigDecimal v = parseSum(s, p);\n            skip(s, p); if (p[0] >= s.length() || s.charAt(p[0]) != ')') throw new RuntimeException(\"X\");\n            p[0]++; depth--; return v;\n        }\n        return parseNum(s, p);\n    }\n\n    static BigDecimal parseNum(String s, int[] p) {\n        skip(s, p); int st = p[0], dots = 0, digits = 0;\n        if (p[0] >= s.length()) throw new RuntimeException(\"X\");\n        char first = s.charAt(p[0]);\n        if (first == '.') {\n            dots++; p[0]++;\n            if (p[0] >= s.length() || s.charAt(p[0]) < '0' || s.charAt(p[0]) > '9') throw new RuntimeException(\"X\");\n            while (p[0] < s.length() && s.charAt(p[0]) >= '0' && s.charAt(p[0]) <= '9') { digits++; p[0]++; }\n        } else if (first >= '0' && first <= '9') {\n            while (p[0] < s.length() && s.charAt(p[0]) >= '0' && s.charAt(p[0]) <= '9') { digits++; p[0]++; }\n            if (p[0] < s.length() && s.charAt(p[0]) == '.') {\n                dots++; p[0]++;\n                if (p[0] >= s.length() || s.charAt(p[0]) < '0' || s.charAt(p[0]) > '9') throw new RuntimeException(\"X\");\n                while (p[0] < s.length() && s.charAt(p[0]) >= '0' && s.charAt(p[0]) <= '9') { digits++; p[0]++; }\n            }\n        } else { throw new RuntimeException(\"X\"); }\n        if (digits > 24) throw new RuntimeException(\"L\");\n        String ns = s.substring(st, p[0]);\n        BigDecimal v = new BigDecimal(ns); chk(v); return v;\n    }\n\n    static void chk(BigDecimal v) { if (v.abs().compareTo(LIM) > 0) throw new RuntimeException(\"L\"); }\n    static String jesc(String s) { return s.replace(\"\\\\\",\"\\\\\\\\\").replace(\"\\\"\",\"\\\\\\\"\"); }\n    static void send(HttpExchange x, int c, String b) throws IOException {\n        byte[] d = b.getBytes(StandardCharsets.UTF_8);\n        x.getResponseHeaders().set(\"Content-Type\",\"application/json;charset=utf-8\");\n        x.sendResponseHeaders(c, d.length);\n        x.getResponseBody().write(d);\n    }\n}"
        },
        "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798"
      },
      "status": "verified_pending_user_acceptance",
      "test": {
        "cases": 39,
        "classes_digest": "31888e310a086e6807cc096b7bdb06164ae9a556c8f582228d9e9d7b43b0b6cf",
        "config_digest": "af40be185fe8b9dd8ecdd495a0785520aaebb54ebbabe97f18813d611f001e9f",
        "container": "zk-run-4e2329b555864957bc5b477ae1432717",
        "execution_mode": "qemu",
        "image": "zkcoding-qemu@sha256:5c866338b848ec50afbbcb7f0827f562c2aced18638922dd72ae73eaa6bc15ec",
        "isolation": {
          "disposable": true,
          "host_mounts": [],
          "memory_mb": 1024,
          "network": "none",
          "vcpu": 1
        },
        "passed": true,
        "passed_cases": 39,
        "preview_scope": "disposable-vm-loopback-http",
        "receipt_digest": "4dd3a2513810493814d30734778f363391f33f14915fc48ee7b5e694be63ef2d",
        "receipt_ref": "run-4e2329b555864957bc5b477ae1432717-1026975a6b7245aeb6e369a5fc51c7a7",
        "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
        "stage": "test",
        "suite_digest": "05e353f239f8919946d419e91e63fedccbf62b02386fa12f39ad8795b6a4de4d",
        "tool_receipt": {
          "input_digest": "9095d3cf2d02a31d5379192aec8c3b3fce2d66a9998f864076c84b5097d63b9b",
          "operation": "AO09",
          "result_digest": "df2dd27fa2866791431bf5710d250ef934be1726082e2402b0090bc001fd6f6a",
          "run_id": "run-4e2329b555864957bc5b477ae1432717"
        }
      }
    }
  },
  "local_replay": {
    "generation_run": "run-4e2329b555864957bc5b477ae1432717",
    "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
    "lease": "22cb0f942ecf446c833abff754e1a6cf",
    "receipt": {
      "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
      "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
      "config_digest": "ec1c941302d1f0bf34512b9b524f7c8dc5bfd523f22fe50093f8cd757cdfc848",
      "classes_digest": "31888e310a086e6807cc096b7bdb06164ae9a556c8f582228d9e9d7b43b0b6cf",
      "tests": 39,
      "network": "none",
      "host_mounts": []
    }
  },
  "human_acceptance": false
}