instinct-cli 0.3.7

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
// generated by hxc 1.0.0-acgt-compiler from src/check/receipt.hlx -- do not edit by hand

#[cfg(windows)]
#[allow(dead_code)]
const SYS_CURL: &str = "C:\\Windows\\System32\\curl.exe";
#[cfg(not(windows))]
#[allow(dead_code)]
const SYS_CURL: &str = "curl";
#[allow(dead_code)]
fn _helix_allowed(var: &str, what: &str) -> bool {
    let ok = std::env::var(var).map(|v| v == "1").unwrap_or(false);
    if !ok {
        eprintln!("helix: BLOCKED {} -- permission denied (set {}=1 to allow; `hxc run` allows by default, a `hxc build`/`export-rust` binary does not)", what, var);
    }
    ok
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_exec(mut c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
        std::process::exit(13);
    }
    use std::os::windows::process::CommandExt;
    c.creation_flags(0x08000000);
    c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_exec(c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
        std::process::exit(13);
    }
    c
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_net(mut c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
        std::process::exit(13);
    }
    use std::os::windows::process::CommandExt;
    c.creation_flags(0x08000000);
    c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_net(c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
        std::process::exit(13);
    }
    c
}

// hlx:2
// Pure receipt creation and replay (docs/check-receipt-wire.md). Byte identity of a supplied-fact decision only:
// hlx:3
// no ledger, no I/O, no environment, no signature, no authority. The kernel and strict parser decide everything.
// hlx:4
use super::digest::{hex, sha256};
// hlx:5
use super::json::{self, J};
// hlx:6
use super::kernel::{error_json, evaluate, Mode};
// hlx:7
const RECEIPT_SCHEMA: &str = "instinct.check-receipt/v1";
// hlx:8
const VERIFIER: &str = "instinct.check-kernel/v1";
// hlx:9
const INPUT_DOMAIN: &[u8] = b"instinct.check-input/v1\0";
// hlx:10
const RESULT_DOMAIN: &[u8] = b"instinct.check-result-core/v1\0";
// hlx:11
const MEANING: &str = "matches_recomputed_supplied_facts_not_world_truth";
// hlx:12
const MAX_OUTPUT_BYTES: usize = 65536;
// hlx:13
struct Expected {
    // hlx:14
    check_id: String,
    // hlx:15
    revision: String,
    // hlx:16
    input_sha256: String,
    // hlx:17
    result_sha256: String,
    // hlx:18
    verdict: String,
    // hlx:19
}
// hlx:20
fn get<'a>(o: &'a [(String, J)], k: &str) -> Option<&'a J> {
    // hlx:21
    o.iter().find(|(key, _)| key == k).map(|(_, v)| v)
    // hlx:22
}
// hlx:23
fn sorted_obj(o: &[(String, J)]) -> J {
    // hlx:24
    let mut kv: Vec<(String, J)> = o.iter().map(|(k, v)| (k.clone(), sort_keys(v))).collect();
    // hlx:25
    kv.sort_by(|a, b| a.0.cmp(&b.0));
    // hlx:26
    J::Obj(kv)
    // hlx:27
}
// hlx:28
/// Object keys in Unicode scalar order; arrays keep their order (ordered expression arrays are semantic).
// hlx:29
fn sort_keys(j: &J) -> J {
    // hlx:30
    match j {
        // hlx:31
        J::Obj(o) => sorted_obj(o),
        // hlx:32
        J::Arr(a) => J::Arr(a.iter().map(sort_keys).collect()),
        // hlx:33
        other => other.clone(),
        // hlx:34
    }
    // hlx:35
}
// hlx:36
fn sorted_strings(j: &J) -> J {
    // hlx:37
    match j {
        // hlx:38
        J::Arr(a) => {
            // hlx:39
            let mut v: Vec<J> = a.clone();
            // hlx:40
            v.sort_by(|x, y| match (x, y) {
                // hlx:41
                (J::Str(p), J::Str(q)) => p.cmp(q),
                // hlx:42
                _ => std::cmp::Ordering::Equal,
                // hlx:43
            });
            // hlx:44
            J::Arr(v)
            // hlx:45
        }
        // hlx:46
        other => other.clone(),
        // hlx:47
    }
    // hlx:48
}
// hlx:49
fn empty_obj() -> J {
    // hlx:50
    J::Obj(Vec::new())
    // hlx:51
}
// hlx:52
/// The validated request with documented defaults filled in, sorted keys, and nonsemantic set orders sorted.
// hlx:53
fn canonical_request(top: &[(String, J)]) -> Result<J, String> {
    // hlx:54
    let check = match get(top, "check") {
        // hlx:55
        Some(J::Obj(c)) => c,
        // hlx:56
        _ => return Err("malformed_definition: check must be an object".to_string()),
        // hlx:57
    };
    // hlx:58
    let mut set_facts: Vec<&str> = Vec::new();
    // hlx:59
    if let Some(J::Obj(inputs)) = get(check, "inputs") {
        // hlx:60
        for (k, v) in inputs {
            // hlx:61
            if matches!(v, J::Str(t) if t == "set<string>") {
                // hlx:62
                set_facts.push(k);
                // hlx:63
            }
            // hlx:64
        }
        // hlx:65
    }
    // hlx:66
    let mut c: Vec<(String, J)> = Vec::new();
    // hlx:67
    for (k, v) in check {
        // hlx:68
        match k.as_str() {
            // hlx:69
            "required_conditions" => c.push((k.clone(), sorted_strings(v))),
            // hlx:70
            _ => c.push((k.clone(), sort_keys(v))),
            // hlx:71
        }
        // hlx:72
    }
    // hlx:73
    if get(check, "required_conditions").is_none() {
        // hlx:74
        c.push(("required_conditions".to_string(), J::Arr(Vec::new())));
        // hlx:75
    }
    // hlx:76
    if get(check, "scope").is_none() {
        // hlx:77
        c.push(("scope".to_string(), empty_obj()));
        // hlx:78
    }
    // hlx:79
    c.sort_by(|a, b| a.0.cmp(&b.0));
    // hlx:80
    let facts = match get(top, "facts") {
        // hlx:81
        Some(J::Obj(f)) => {
            // hlx:82
            let mut kv: Vec<(String, J)> = f
                // hlx:83
                .iter()
                // hlx:84
                .map(|(k, v)| {
                    (
                        k.clone(),
                        if set_facts.contains(&k.as_str()) {
                            sorted_strings(v)
                        } else {
                            v.clone()
                        },
                    )
                })
                // hlx:85
                .collect();
            // hlx:86
            kv.sort_by(|a, b| a.0.cmp(&b.0));
            // hlx:87
            J::Obj(kv)
            // hlx:88
        }
        // hlx:89
        _ => empty_obj(),
        // hlx:90
    };
    // hlx:91
    let plain = |k: &str| match get(top, k) {
        // hlx:92
        Some(v) => sort_keys(v),
        // hlx:93
        None => empty_obj(),
        // hlx:94
    };
    // hlx:95
    let mut out = vec![
        // hlx:96
        ("check".to_string(), J::Obj(c)),
        // hlx:97
        ("conditions".to_string(), plain("conditions")),
        // hlx:98
        ("facts".to_string(), facts),
        // hlx:99
        ("scope".to_string(), plain("scope")),
        // hlx:100
    ];
    // hlx:101
    out.sort_by(|a, b| a.0.cmp(&b.0));
    // hlx:102
    Ok(J::Obj(out))
    // hlx:103
}
// hlx:104
fn put_len(n: usize, out: &mut Vec<u8>) {
    // hlx:105
    out.extend_from_slice(&(n as u64).to_be_bytes());
    // hlx:106
}
// hlx:107
fn put_text(tag: u8, s: &str, out: &mut Vec<u8>) {
    // hlx:108
    out.push(tag);
    // hlx:109
    put_len(s.len(), out);
    // hlx:110
    out.extend_from_slice(s.as_bytes());
    // hlx:111
}
// hlx:112
/// Typed, length-framed binary form: Null 0, Bool 1, Number 2, String 3, Array 4, Object 5.
// hlx:113
fn encode(j: &J, out: &mut Vec<u8>) {
    // hlx:114
    match j {
        // hlx:115
        J::Null => out.push(0),
        // hlx:116
        J::Bool(b) => {
            // hlx:117
            out.push(1);
            // hlx:118
            out.push(u8::from(*b));
            // hlx:119
        }
        // hlx:120
        J::Num(n) => put_text(2, n, out),
        // hlx:121
        J::Str(s) => put_text(3, s, out),
        // hlx:122
        J::Arr(a) => {
            // hlx:123
            out.push(4);
            // hlx:124
            put_len(a.len(), out);
            // hlx:125
            for x in a {
                // hlx:126
                encode(x, out);
                // hlx:127
            }
            // hlx:128
        }
        // hlx:129
        J::Obj(o) => {
            // hlx:130
            out.push(5);
            // hlx:131
            put_len(o.len(), out);
            // hlx:132
            for (k, v) in o {
                // hlx:133
                put_text(3, k, out);
                // hlx:134
                encode(v, out);
                // hlx:135
            }
            // hlx:136
        } // hlx:137
    }
    // hlx:138
}
// hlx:139
fn digest(domain: &[u8], tree: &J) -> String {
    // hlx:140
    let mut buf = domain.to_vec();
    // hlx:141
    encode(tree, &mut buf);
    // hlx:142
    hex(&sha256(&buf))
    // hlx:143
}
// hlx:144
fn expected(request: &[u8]) -> Result<Expected, String> {
    // hlx:145
    let (res, is_err) = evaluate(Mode::Run, request);
    // hlx:146
    if is_err {
        // hlx:147
        return Err(res);
        // hlx:148
    }
    // hlx:149
    let tree = json::parse(request).map_err(|e| error_json(&e))?;
    // hlx:150
    let top = match &tree {
        // hlx:151
        J::Obj(o) => o,
        // hlx:152
        _ => {
            return Err(error_json(
                "malformed_definition: the request must be a JSON object",
            ))
        } // hlx:153
    };
    // hlx:154
    let canon = canonical_request(top).map_err(|e| error_json(&e))?;
    // hlx:155
    let check = match get(top, "check") {
        // hlx:156
        Some(J::Obj(c)) => c,
        // hlx:157
        _ => return Err(error_json("malformed_definition: check must be an object")),
        // hlx:158
    };
    // hlx:159
    let (check_id, revision) = match (get(check, "id"), get(check, "revision")) {
        // hlx:160
        (Some(J::Str(i)), Some(J::Num(r))) => (i.clone(), r.clone()),
        // hlx:161
        _ => {
            return Err(error_json(
                "malformed_definition: check id or revision is missing",
            ))
        } // hlx:162
    };
    // hlx:163
    let result = json::parse(res.as_bytes()).map_err(|e| error_json(&e))?;
    // hlx:164
    let core: Vec<(String, J)> = match &result {
        // hlx:165
        J::Obj(o) => o.iter().filter(|(k, _)| k != "steps").cloned().collect(),
        // hlx:166
        _ => return Err(error_json("internal: kernel result is not an object")),
        // hlx:167
    };
    // hlx:168
    let verdict = match get(&core, "verdict") {
        // hlx:169
        Some(J::Str(v)) => v.clone(),
        // hlx:170
        _ => return Err(error_json("internal: kernel result has no verdict")),
        // hlx:171
    };
    // hlx:172
    Ok(Expected {
        // hlx:173
        check_id,
        // hlx:174
        revision,
        // hlx:175
        input_sha256: digest(INPUT_DOMAIN, &canon),
        // hlx:176
        result_sha256: digest(RESULT_DOMAIN, &sort_keys(&J::Obj(core))),
        // hlx:177
        verdict,
        // hlx:178
    })
    // hlx:179
}
// hlx:180
fn jstr(s: &str) -> String {
    // hlx:181
    let mut o = String::with_capacity(s.len() + 2);
    // hlx:182
    o.push('"');
    // hlx:183
    for ch in s.chars() {
        // hlx:184
        match ch {
            // hlx:185
            '"' => o.push_str("\\\""),
            // hlx:186
            '\\' => o.push_str("\\\\"),
            // hlx:187
            '\n' => o.push_str("\\n"),
            // hlx:188
            '\r' => o.push_str("\\r"),
            // hlx:189
            '\t' => o.push_str("\\t"),
            // hlx:190
            '\u{8}' => o.push_str("\\b"),
            // hlx:191
            '\u{c}' => o.push_str("\\f"),
            // hlx:192
            c if (c as u32) < 0x20 => o.push_str(&format!("\\u{:04x}", c as u32)),
            // hlx:193
            c => o.push(c),
            // hlx:194
        }
        // hlx:195
    }
    // hlx:196
    o.push('"');
    // hlx:197
    o
    // hlx:198
}
// hlx:199
pub(super) fn ser(j: &J, out: &mut String) {
    // hlx:200
    match j {
        // hlx:201
        J::Null => out.push_str("null"),
        // hlx:202
        J::Bool(b) => out.push_str(if *b { "true" } else { "false" }),
        // hlx:203
        J::Num(n) => out.push_str(n),
        // hlx:204
        J::Str(s) => out.push_str(&jstr(s)),
        // hlx:205
        J::Arr(a) => {
            // hlx:206
            out.push('[');
            // hlx:207
            for (i, x) in a.iter().enumerate() {
                // hlx:208
                if i > 0 {
                    // hlx:209
                    out.push(',');
                    // hlx:210
                }
                // hlx:211
                ser(x, out);
                // hlx:212
            }
            // hlx:213
            out.push(']');
            // hlx:214
        }
        // hlx:215
        J::Obj(o) => {
            // hlx:216
            out.push('{');
            // hlx:217
            for (i, (k, v)) in o.iter().enumerate() {
                // hlx:218
                if i > 0 {
                    // hlx:219
                    out.push(',');
                    // hlx:220
                }
                // hlx:221
                out.push_str(&jstr(k));
                // hlx:222
                out.push(':');
                // hlx:223
                ser(v, out);
                // hlx:224
            }
            // hlx:225
            out.push('}');
            // hlx:226
        } // hlx:227
    }
    // hlx:228
}
// hlx:229
fn bounded(out: String) -> (String, bool) {
    // hlx:230
    if out.len() > MAX_OUTPUT_BYTES {
        // hlx:231
        return (
            error_json("limit_exceeded: result would exceed 64 KiB"),
            true,
        );
        // hlx:232
    }
    // hlx:233
    (out, false)
    // hlx:234
}
// hlx:235
fn receipt_json(e: &Expected) -> String {
    // hlx:236
    format!(
// hlx:237
"{{\"schema\":\"{RECEIPT_SCHEMA}\",\"verifier\":\"{VERIFIER}\",\"check_id\":{},\"revision\":{},\"input_sha256\":\"{}\",\"result_sha256\":\"{}\",\"verdict\":\"{}\",\"authorization\":\"not_evaluated\",\"evidence_origin\":\"caller_reported\"}}",
// hlx:238
jstr(&e.check_id),
// hlx:239
e.revision,
// hlx:240
e.input_sha256,
// hlx:241
e.result_sha256,
// hlx:242
e.verdict
// hlx:243
)
    // hlx:244
}
// hlx:245
/// `check receipt`: evaluate a pure check request and return its receipt, or the kernel's structured error.
// hlx:246
pub fn create(input: &[u8]) -> (String, bool) {
    // hlx:247
    match expected(input) {
        // hlx:248
        Ok(e) => bounded(receipt_json(&e)),
        // hlx:249
        Err(err) => (err, true),
        // hlx:250
    }
    // hlx:251
}
// hlx:252
/// Same grammar as the kernel's check id: 1-128 ASCII letters, digits or `._-`, starting with a letter.
// hlx:253
fn is_ident(s: &str) -> bool {
    // hlx:254
    let b = s.as_bytes();
    // hlx:255
    !b.is_empty()
        && b.len() <= 128
        && b[0].is_ascii_alphabetic()
        && b.iter()
            .all(|c| c.is_ascii_alphanumeric() || matches!(c, b'.' | b'_' | b'-'))
    // hlx:256
}
// hlx:257
fn is_hex64(s: &str) -> bool {
    // hlx:258
    s.len() == 64
        && s.bytes()
            .all(|c| c.is_ascii_digit() || (b'a'..=b'f').contains(&c))
    // hlx:259
}
// hlx:260
struct Supplied {
    // hlx:261
    check_id: String,
    // hlx:262
    revision: String,
    // hlx:263
    input_sha256: String,
    // hlx:264
    result_sha256: String,
    // hlx:265
    verdict: String,
    // hlx:266
}
// hlx:267
fn read_receipt(j: &J) -> Result<Supplied, String> {
    // hlx:268
    let o = match j {
        // hlx:269
        J::Obj(o) => o,
        // hlx:270
        _ => return Err("malformed_receipt: receipt must be an object".to_string()),
        // hlx:271
    };
    // hlx:272
    const KEYS: [&str; 9] = [
        "schema",
        "verifier",
        "check_id",
        "revision",
        "input_sha256",
        "result_sha256",
        "verdict",
        "authorization",
        "evidence_origin",
    ];
    // hlx:273
    for (k, _) in o {
        // hlx:274
        if !KEYS.contains(&k.as_str()) {
            // hlx:275
            return Err("malformed_receipt: unknown receipt field".to_string());
            // hlx:276
        }
        // hlx:277
    }
    // hlx:278
    let text = |k: &str| -> Result<&str, String> {
        // hlx:279
        match get(o, k) {
            // hlx:280
            Some(J::Str(s)) => Ok(s),
            // hlx:281
            Some(_) => Err(format!("malformed_receipt: {k} must be a string")),
            // hlx:282
            None => Err(format!("malformed_receipt: {k} is required")),
            // hlx:283
        }
        // hlx:284
    };
    // hlx:285
    if text("schema")? != RECEIPT_SCHEMA {
        // hlx:286
        return Err("malformed_receipt: unsupported receipt schema".to_string());
        // hlx:287
    }
    // hlx:288
    if text("verifier")? != VERIFIER {
        // hlx:289
        return Err(
            "unsupported_verifier: receipt was not made by this check kernel version".to_string(),
        );
        // hlx:290
    }
    // hlx:291
    if text("authorization")? != "not_evaluated" || text("evidence_origin")? != "caller_reported" {
        // hlx:292
        return Err("malformed_receipt: authorization must be not_evaluated and evidence_origin caller_reported".to_string());
        // hlx:293
    }
    // hlx:294
    let revision = match get(o, "revision") {
        // hlx:295
        Some(J::Num(n)) => match n.parse::<u32>() {
            // hlx:296
            Ok(v)
                if (1..=2147483647).contains(&v)
                    && n.bytes().all(|c| c.is_ascii_digit())
                    && !n.starts_with('0') =>
            {
                n.clone()
            }
            // hlx:297
            _ => return Err(
                "unsupported_revision: receipt revision must be an integer from 1 to 2147483647"
                    .to_string(),
            ),
            // hlx:298
        },
        // hlx:299
        Some(_) => return Err("malformed_receipt: revision must be an integer literal".to_string()),
        // hlx:300
        None => return Err("malformed_receipt: revision is required".to_string()),
        // hlx:301
    };
    // hlx:302
    let check_id = text("check_id")?;
    // hlx:303
    if !is_ident(check_id) {
        // hlx:304
        return Err("malformed_receipt: check_id must be 1-128 ASCII letters, digits or ._- starting with a letter".to_string());
        // hlx:305
    }
    // hlx:306
    let (i, r) = (text("input_sha256")?, text("result_sha256")?);
    // hlx:307
    if !is_hex64(i) || !is_hex64(r) {
        // hlx:308
        return Err("malformed_receipt: digests must be 64 lowercase hex characters".to_string());
        // hlx:309
    }
    // hlx:310
    let verdict = text("verdict")?;
    // hlx:311
    if !matches!(verdict, "pass" | "fail" | "abstain") {
        // hlx:312
        return Err("malformed_receipt: verdict must be pass, fail or abstain".to_string());
        // hlx:313
    }
    // hlx:314
    Ok(Supplied {
        // hlx:315
        check_id: check_id.to_string(),
        // hlx:316
        revision,
        // hlx:317
        input_sha256: i.to_string(),
        // hlx:318
        result_sha256: r.to_string(),
        // hlx:319
        verdict: verdict.to_string(),
        // hlx:320
    })
    // hlx:321
}
// hlx:322
/// `check replay`: input is exactly {"request": ..., "receipt": ...}. Recompute from the supplied request and compare
// hlx:323
/// every field; a supplied receipt is never trusted. A forged receipt over changed facts can be consistent: no authentication.
// hlx:324
pub fn replay(input: &[u8]) -> (String, bool) {
    // hlx:325
    let tree = match json::parse_with_limits(
        input,
        json::MAX_BYTES + json::REPLAY_EXTRA_BYTES,
        json::REPLAY_MAX_DEPTH,
    ) {
        // hlx:326
        Ok(t) => t,
        // hlx:327
        Err(e) => return (error_json(&e), true),
        // hlx:328
    };
    // hlx:329
    let o = match &tree {
        // hlx:330
        J::Obj(o) => o,
        // hlx:331
        _ => {
            return (
                error_json("malformed_receipt: replay input must be an object"),
                true,
            )
        } // hlx:332
    };
    // hlx:333
    if o.len() != 2 || get(o, "request").is_none() || get(o, "receipt").is_none() {
        // hlx:334
        return (
            error_json(
                "malformed_receipt: replay input must be exactly {\"request\", \"receipt\"}",
            ),
            true,
        );
        // hlx:335
    }
    // hlx:336
    let supplied = match read_receipt(get(o, "receipt").unwrap_or(&J::Null)) {
        // hlx:337
        Ok(s) => s,
        // hlx:338
        Err(e) => return (error_json(&e), true),
        // hlx:339
    };
    // hlx:340
    let mut request = String::new();
    // hlx:341
    ser(get(o, "request").unwrap_or(&J::Null), &mut request);
    // hlx:342
    let want = match expected(request.as_bytes()) {
        // hlx:343
        Ok(w) => w,
        // hlx:344
        Err(err) => return (err, true),
        // hlx:345
    };
    // hlx:346
    let same = supplied.check_id == want.check_id
// hlx:347
&& supplied.revision == want.revision
// hlx:348
&& supplied.input_sha256 == want.input_sha256
// hlx:349
&& supplied.result_sha256 == want.result_sha256
// hlx:350
&& supplied.verdict == want.verdict;
    // hlx:351
    let out = if same {
        // hlx:352
        format!(
// hlx:353
"{{\"schema\":\"instinct.check-replay/v1\",\"status\":\"consistent\",\"verdict\":\"{}\",\"input_sha256\":\"{}\",\"result_sha256\":\"{}\",\"authorization\":\"not_evaluated\",\"evidence_origin\":\"caller_reported\",\"meaning\":\"{MEANING}\"}}",
// hlx:354
want.verdict, want.input_sha256, want.result_sha256
// hlx:355
)
    // hlx:356
    } else {
        // hlx:357
        format!(
// hlx:358
"{{\"schema\":\"instinct.check-replay/v1\",\"status\":\"mismatch\",\"verdict\":\"abstain\",\"reason\":\"receipt_mismatch\",\"authorization\":\"not_evaluated\",\"evidence_origin\":\"caller_reported\",\"meaning\":\"{MEANING}\"}}"
// hlx:359
)
        // hlx:360
    };
    // hlx:361
    bounded(out)
    // hlx:362
}
// hlx:363
#[cfg(test)]
// hlx:364
mod tests {
    // hlx:365
    use super::*;
    // hlx:366
    fn req(inputs_a: &str, allowed: &str, extra_check: &str, top_extra: &str) -> String {
        // hlx:367
        format!(
// hlx:368
"{{\"check\":{{\"schema\":\"instinct.check/v1\",\"id\":\"m\",\"revision\":1,\"inputs\":{{\"a\":\"set<string>\",\"b\":\"set<string>\"}},\"claim\":{{\"op\":\"subset\",\"left\":{{\"fact\":\"a\"}},\"right\":{{\"fact\":\"b\"}}}}{extra_check}}},\"facts\":{{\"a\":{inputs_a},\"b\":{allowed}}}{top_extra}}}"
// hlx:369
)
        // hlx:370
    }
    // hlx:371
    fn rec(request: &str) -> String {
        // hlx:372
        let (o, e) = create(request.as_bytes());
        // hlx:373
        assert!(!e, "{o}");
        // hlx:374
        o
        // hlx:375
    }
    // hlx:376
    fn field(receipt: &str, k: &str) -> String {
        // hlx:377
        let p = format!("\"{k}\":\"");
        // hlx:378
        let s = receipt.find(&p).unwrap() + p.len();
        // hlx:379
        receipt[s..s + 64].to_string()
        // hlx:380
    }
    // hlx:381
    #[test]
    // hlx:382
    fn encoding_is_typed_and_length_framed() {
        // hlx:383
        let j = J::Obj(vec![(
            "a".to_string(),
            J::Arr(vec![
                J::Bool(true),
                J::Num("12".to_string()),
                J::Null,
                J::Str("x".to_string()),
            ]),
        )]);
        // hlx:384
        let mut b = Vec::new();
        // hlx:385
        encode(&j, &mut b);
        // hlx:386
        let mut want = vec![5u8];
        // hlx:387
        want.extend_from_slice(&1u64.to_be_bytes());
        // hlx:388
        want.push(3);
        // hlx:389
        want.extend_from_slice(&1u64.to_be_bytes());
        // hlx:390
        want.push(b'a');
        // hlx:391
        want.push(4);
        // hlx:392
        want.extend_from_slice(&4u64.to_be_bytes());
        // hlx:393
        want.extend_from_slice(&[1, 1]);
        // hlx:394
        want.push(2);
        // hlx:395
        want.extend_from_slice(&2u64.to_be_bytes());
        // hlx:396
        want.extend_from_slice(b"12");
        // hlx:397
        want.push(0);
        // hlx:398
        want.push(3);
        // hlx:399
        want.extend_from_slice(&1u64.to_be_bytes());
        // hlx:400
        want.push(b'x');
        // hlx:401
        assert_eq!(b, want);
        // hlx:402
    }
    // hlx:403
    #[test]
    // hlx:404
    fn receipts_are_deterministic_fixed_shape_and_carry_no_inputs() {
        // hlx:405
        let r = req(
            "[\"secret-fact-1\",\"b\"]",
            "[\"b\"]",
            "",
            ",\"scope\":{\"project\":\"private-project\"}",
        );
        // hlx:406
        let one = rec(&r);
        // hlx:407
        assert_eq!(one, rec(&r));
        // hlx:408
        assert!(one.starts_with("{\"schema\":\"instinct.check-receipt/v1\",\"verifier\":\"instinct.check-kernel/v1\",\"check_id\":\"m\",\"revision\":1,\"input_sha256\":\""));
        // hlx:409
        assert!(one.ends_with("\"verdict\":\"fail\",\"authorization\":\"not_evaluated\",\"evidence_origin\":\"caller_reported\"}"));
        // hlx:410
        assert!(!one.contains("secret-fact-1") && !one.contains("private-project"));
        // hlx:411
    }
    // hlx:412
    #[test]
    // hlx:413
    fn key_order_set_order_defaults_and_condition_order_keep_the_digests() {
        // hlx:414
        let base = rec(&req("[\"x\",\"y\"]", "[\"y\"]", "", ""));
        // hlx:415
        let permuted = rec(&req("[\"y\",\"x\"]", "[\"y\"]", "", ""));
        // hlx:416
        assert_eq!(
            field(&base, "input_sha256"),
            field(&permuted, "input_sha256")
        );
        // hlx:417
        assert_eq!(
            field(&base, "result_sha256"),
            field(&permuted, "result_sha256")
        );
        // hlx:418
        let explicit = rec(&req(
            "[\"x\",\"y\"]",
            "[\"y\"]",
            ",\"required_conditions\":[],\"scope\":{}",
            ",\"conditions\":{},\"scope\":{}",
        ));
        // hlx:419
        assert_eq!(
            field(&base, "input_sha256"),
            field(&explicit, "input_sha256")
        );
        // hlx:420
        let reordered = "{\"facts\":{\"b\":[\"y\"],\"a\":[\"y\",\"x\"]},\"check\":{\"claim\":{\"right\":{\"fact\":\"b\"},\"left\":{\"fact\":\"a\"},\"op\":\"subset\"},\"inputs\":{\"b\":\"set<string>\",\"a\":\"set<string>\"},\"revision\":1,\"id\":\"m\",\"schema\":\"instinct.check/v1\"}}";
        // hlx:421
        assert_eq!(
            field(&base, "input_sha256"),
            field(&rec(reordered), "input_sha256")
        );
        // hlx:422
        let c1 = req(
            "[\"x\"]",
            "[\"x\"]",
            ",\"required_conditions\":[\"p\",\"q\"]",
            ",\"conditions\":{\"p\":true,\"q\":true}",
        );
        // hlx:423
        let c2 = req(
            "[\"x\"]",
            "[\"x\"]",
            ",\"required_conditions\":[\"q\",\"p\"]",
            ",\"conditions\":{\"q\":true,\"p\":true}",
        );
        // hlx:424
        assert_eq!(
            field(&rec(&c1), "input_sha256"),
            field(&rec(&c2), "input_sha256")
        );
        // hlx:425
    }
    // hlx:426
    #[test]
    // hlx:427
    fn semantic_changes_alter_input_identity_even_when_the_verdict_stays() {
        // hlx:428
        let base = rec(&req("[\"x\"]", "[\"x\"]", "", ""));
        // hlx:429
        let scope_added = rec(&req(
            "[\"x\"]",
            "[\"x\"]",
            "",
            ",\"scope\":{\"project\":\"p\"}",
        ));
        // hlx:430
        let revised =
            rec(&req("[\"x\"]", "[\"x\"]", "", "").replace("\"revision\":1", "\"revision\":2"));
        // hlx:431
        let other_fact = rec(&req("[\"x\"]", "[\"x\",\"z\"]", "", ""));
        // hlx:432
        let missing_b = rec("{\"check\":{\"schema\":\"instinct.check/v1\",\"id\":\"m\",\"revision\":1,\"inputs\":{\"a\":\"set<string>\",\"b\":\"set<string>\"},\"claim\":{\"op\":\"subset\",\"left\":{\"fact\":\"a\"},\"right\":{\"fact\":\"b\"}}},\"facts\":{\"a\":[\"x\"]}}");
        // hlx:433
        let h = field(&base, "input_sha256");
        // hlx:434
        for other in [&scope_added, &revised, &other_fact, &missing_b] {
            // hlx:435
            assert_ne!(h, field(other, "input_sha256"));
            // hlx:436
        }
        // hlx:437
        assert!(missing_b.contains("\"verdict\":\"abstain\""));
        // hlx:438
        let any_ab = "{\"op\":\"any\",\"args\":[{\"op\":\"subset\",\"left\":{\"fact\":\"a\"},\"right\":{\"fact\":\"b\"}},{\"op\":\"subset\",\"left\":{\"fact\":\"b\"},\"right\":{\"fact\":\"a\"}}]}";
        // hlx:439
        let any_ba = "{\"op\":\"any\",\"args\":[{\"op\":\"subset\",\"left\":{\"fact\":\"b\"},\"right\":{\"fact\":\"a\"}},{\"op\":\"subset\",\"left\":{\"fact\":\"a\"},\"right\":{\"fact\":\"b\"}}]}";
        // hlx:440
        let one = req("[\"x\"]", "[\"x\"]", "", "").replace(
            "{\"op\":\"subset\",\"left\":{\"fact\":\"a\"},\"right\":{\"fact\":\"b\"}}",
            any_ab,
        );
        // hlx:441
        let two = req("[\"x\"]", "[\"x\"]", "", "").replace(
            "{\"op\":\"subset\",\"left\":{\"fact\":\"a\"},\"right\":{\"fact\":\"b\"}}",
            any_ba,
        );
        // hlx:442
        assert_ne!(
            field(&rec(&one), "input_sha256"),
            field(&rec(&two), "input_sha256")
        );
        // hlx:443
        assert_eq!(
            field(&rec(&one), "result_sha256"),
            field(&rec(&two), "result_sha256")
        );
        // hlx:444
    }
    // hlx:445
    #[test]
    // hlx:446
    fn invalid_requests_are_errors_never_hashed() {
        // hlx:447
        let (o, e) = create(b"{\"check\":{\"a\":1,\"a\":2}}");
        // hlx:448
        assert!(e && o.contains("check-error"));
        // hlx:449
        let (o, e) = create(b"[]");
        // hlx:450
        assert!(e && o.contains("check-error"));
        // hlx:451
    }
    // hlx:452
    fn replay_of(request: &str, receipt: &str) -> (String, bool) {
        // hlx:453
        replay(format!("{{\"request\":{request},\"receipt\":{receipt}}}").as_bytes())
        // hlx:454
    }
    // hlx:455
    #[test]
    // hlx:456
    fn replay_is_consistent_for_permutations_and_mismatches_every_mutation() {
        // hlx:457
        let r = req("[\"x\",\"y\"]", "[\"y\"]", "", "");
        // hlx:458
        let receipt = rec(&r);
        // hlx:459
        let (o, e) = replay_of(&r, &receipt);
        // hlx:460
        assert!(
            !e && o.contains("\"status\":\"consistent\"") && o.contains("\"verdict\":\"fail\""),
            "{o}"
        );
        // hlx:461
        assert!(o.contains("\"authorization\":\"not_evaluated\"") && o.contains("not_world_truth"));
        // hlx:462
        let (o, _) = replay_of(&req("[\"y\",\"x\"]", "[\"y\"]", "", ""), &receipt);
        // hlx:463
        assert!(o.contains("consistent"), "{o}");
        // hlx:464
        let flipped = receipt.replacen(&field(&receipt, "input_sha256"), &"0".repeat(64), 1);
        // hlx:465
        let forged_verdict = receipt.replace("\"verdict\":\"fail\"", "\"verdict\":\"pass\"");
        // hlx:466
        let forged_id = receipt.replace("\"check_id\":\"m\"", "\"check_id\":\"n\"");
        // hlx:467
        let forged_rev = receipt.replace("\"revision\":1", "\"revision\":2");
        // hlx:468
        for bad in [flipped, forged_verdict, forged_id, forged_rev] {
            // hlx:469
            let (o, e) = replay_of(&r, &bad);
            // hlx:470
            assert!(
                !e && o.contains("\"status\":\"mismatch\"")
                    && o.contains("\"verdict\":\"abstain\"")
                    && o.contains("receipt_mismatch"),
                "{o}"
            );
            // hlx:471
            assert!(!o.contains("input_sha256"));
            // hlx:472
        }
        // hlx:473
        let (o, _) = replay_of(&req("[\"x\",\"y\"]", "[\"x\",\"y\"]", "", ""), &receipt);
        // hlx:474
        assert!(o.contains("mismatch"));
        // hlx:475
        let mut last = receipt.clone();
        // hlx:476
        let p = last.find(&field(&receipt, "result_sha256")).unwrap() + 63;
        // hlx:477
        last.replace_range(p..p + 1, if &receipt[p..p + 1] == "0" { "1" } else { "0" });
        // hlx:478
        assert!(replay_of(&r, &last).0.contains("mismatch"));
        // hlx:479
    }
    // hlx:480
    #[test]
    // hlx:481
    fn malformed_receipts_and_replay_inputs_are_errors() {
        // hlx:482
        let r = req("[\"x\"]", "[\"x\"]", "", "");
        // hlx:483
        let receipt = rec(&r);
        // hlx:484
        let cases = [
            // hlx:485
            receipt.replace("}", ",\"extra\":1}"),
            // hlx:486
            receipt.replace(
                "\"schema\":\"instinct.check-receipt/v1\",",
                "\"schema\":\"instinct.check-receipt/v1\",\"schema\":\"x\",",
            ),
            // hlx:487
            receipt.replace("instinct.check-kernel/v1", "instinct.check-kernel/v9"),
            // hlx:488
            receipt.replace("\"revision\":1", "\"revision\":0"),
            // hlx:489
            receipt.replace("\"revision\":1", "\"revision\":\"1\""),
            // hlx:490
            receipt.replace("\"verdict\":\"pass\"", "\"verdict\":\"maybe\""),
            // hlx:491
            receipt.replace("not_evaluated", "granted"),
            // hlx:492
            receipt.replacen(&field(&receipt, "input_sha256"), &"A".repeat(64), 1),
            // hlx:493
            "[]".to_string(),
            // hlx:494
        ];
        // hlx:495
        for bad in cases {
            // hlx:496
            let (o, e) = replay_of(&r, &bad);
            // hlx:497
            assert!(e && o.contains("check-error"), "{bad} => {o}");
            // hlx:498
        }
        // hlx:499
        assert!(replay(b"{\"request\":{}}").1);
        // hlx:500
        assert!(replay(b"{\"request\":{},\"receipt\":{},\"x\":1}").1);
        // hlx:501
        assert!(replay_of("{\"check\":1}", &receipt).1);
        // hlx:502
    }
    // hlx:503
    #[test]
    // hlx:504
    fn missing_evidence_gives_an_abstain_receipt_not_pass() {
        // hlx:505
        let r = "{\"check\":{\"schema\":\"instinct.check/v1\",\"id\":\"m\",\"revision\":1,\"inputs\":{\"p\":\"bool\"},\"claim\":{\"op\":\"eq\",\"left\":{\"fact\":\"p\"},\"right\":{\"fact\":\"p\"}},\"required_conditions\":[\"c\"]}}";
        // hlx:506
        let receipt = rec(r);
        // hlx:507
        assert!(receipt.contains("\"verdict\":\"abstain\""));
        // hlx:508
        let r2 = format!("{},\"conditions\":{{\"c\":false}}}}", &r[..r.len() - 1]);
        // hlx:509
        let false_receipt = rec(&r2);
        // hlx:510
        assert!(false_receipt.contains("\"verdict\":\"abstain\""));
        // hlx:511
        assert_ne!(
            field(&receipt, "input_sha256"),
            field(&false_receipt, "input_sha256")
        );
        // hlx:512
    }
    // hlx:513
    fn nested_all(levels: usize) -> String {
        // hlx:514
        let mut claim =
            "{\"op\":\"eq\",\"left\":{\"fact\":\"p\"},\"right\":{\"fact\":\"p\"}}".to_string();
        // hlx:515
        for _ in 0..levels {
            // hlx:516
            claim = format!("{{\"op\":\"all\",\"args\":[{claim}]}}");
            // hlx:517
        }
        // hlx:518
        format!("{{\"check\":{{\"schema\":\"instinct.check/v1\",\"id\":\"m\",\"revision\":1,\"inputs\":{{\"p\":\"bool\"}},\"claim\":{claim}}},\"facts\":{{\"p\":true}}}}")
        // hlx:519
    }
    // hlx:520
    #[test]
    // hlx:521
    fn a_request_at_the_nesting_limit_round_trips_through_replay() {
        // hlx:522
        for levels in [29usize, 30] {
            // hlx:523
            let r = nested_all(levels);
            // hlx:524
            let receipt = rec(&r);
            // hlx:525
            let (o, e) = replay_of(&r, &receipt);
            // hlx:526
            assert!(
                !e && o.contains("\"status\":\"consistent\""),
                "{levels}: {o}"
            );
            // hlx:527
        }
        // hlx:528
        let (o, e) = create(nested_all(31).as_bytes());
        // hlx:529
        assert!(e && o.contains("nesting deeper than 64"), "{o}");
        // hlx:530
    }
    // hlx:531
    #[test]
    // hlx:532
    fn an_inner_request_beyond_the_ordinary_limits_still_errors_inside_the_larger_envelope() {
        // hlx:533
        let receipt = rec(&nested_all(30));
        // hlx:534
        let (o, e) = replay_of(&nested_all(31), &receipt);
        // hlx:535
        assert!(e && o.contains("nesting deeper than"), "{o}");
        // hlx:536
    }
    // hlx:537
    fn big_request(total: usize) -> String {
        // hlx:538
        let head = "{\"check\":{\"schema\":\"instinct.check/v1\",\"id\":\"m\",\"revision\":1,\"inputs\":{\"s\":\"string\"},\"claim\":{\"op\":\"eq\",\"left\":{\"fact\":\"s\"},\"right\":{\"fact\":\"s\"}}},\"facts\":{\"s\":\"";
        // hlx:539
        let tail = "\"}}";
        // hlx:540
        format!(
            "{head}{}{tail}",
            "x".repeat(total - head.len() - tail.len())
        )
        // hlx:541
    }
    // hlx:542
    #[test]
    // hlx:543
    fn a_request_of_exactly_one_mib_fits_the_replay_envelope() {
        // hlx:544
        let r = big_request(json::MAX_BYTES);
        // hlx:545
        assert_eq!(r.len(), json::MAX_BYTES);
        // hlx:546
        let receipt = rec(&r);
        // hlx:547
        let (o, e) = replay_of(&r, &receipt);
        // hlx:548
        assert!(!e && o.contains("\"status\":\"consistent\""), "{o}");
        // hlx:549
        let (o, e) = create(big_request(json::MAX_BYTES + 1).as_bytes());
        // hlx:550
        assert!(e && o.contains("input_too_large"), "{o}");
        // hlx:551
    }
    // hlx:552
    #[test]
    // hlx:553
    fn an_inner_request_over_one_mib_errors_even_when_the_envelope_fits() {
        // hlx:554
        let receipt = rec(&big_request(json::MAX_BYTES));
        // hlx:555
        let (o, e) = replay_of(&big_request(json::MAX_BYTES + 100), &receipt);
        // hlx:556
        assert!(e && o.contains("input_too_large"), "{o}");
        // hlx:557
    }
    // hlx:558
    #[test]
    // hlx:559
    fn a_replay_envelope_beyond_its_own_cap_errors_without_panicking() {
        // hlx:560
        let cap = json::MAX_BYTES + json::REPLAY_EXTRA_BYTES;
        // hlx:561
        let pad = " ".repeat(cap);
        // hlx:562
        let (o, e) = replay(format!("{{\"request\":{{}},\"receipt\":{{}}}}{pad}").as_bytes());
        // hlx:563
        assert!(e && o.contains("replay envelope exceeds"), "{o}");
        // hlx:564
        let deep = format!("{}{}", "[".repeat(66), "]".repeat(66));
        // hlx:565
        let (o, e) = replay(deep.as_bytes());
        // hlx:566
        assert!(e && o.contains("nesting deeper than 65"), "{o}");
        // hlx:567
    }
    // hlx:568
    #[test]
    // hlx:569
    fn receipt_check_id_uses_the_kernel_id_grammar() {
        // hlx:570
        let r = req("[\"x\"]", "[\"x\"]", "", "");
        // hlx:571
        let receipt = rec(&r);
        // hlx:572
        for bad in ["1abc", "has space", "a/b", ""] {
            // hlx:573
            let forged = receipt.replace("\"check_id\":\"m\"", &format!("\"check_id\":\"{bad}\""));
            // hlx:574
            let (o, e) = replay_of(&r, &forged);
            // hlx:575
            assert!(e && o.contains("check_id"), "{bad}: {o}");
            // hlx:576
        }
        // hlx:577
    }
    // hlx:578
}