Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cortex/blob/main/tests/parity/pcmp.om # cortex aien-dev/cortex Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `cortex / tests / parity / pcmp.om` 913 lines ยท 16301 bytes Raw Blame History 1 note pcmp.om: parity comparator. usage: pcmp CORPUS ORACLE.out OMEGA.out REPORT SINCE 2 note Reads the two answer streams written by pdrive for the same corpus and decides, record by 3 note record, whether the Omega answer equals the oracle answer under the rule in spec/PARITY.md: 4 note - same status line; 5 note - same header lines as a multiset, ignoring `date`; `content-length` must also be equal unless 6 note the body needed one of the masks below; 7 note - same body bytes, except: an `elapsedMs` number; a `committedAt`/`createdAt`/`updatedAt` string 8 note when both values are fresh (at or after SINCE, compared on the first 19 bytes) and have the 9 note same shape (digits as 9, fraction ignored); and server-generated UUIDs, which must follow one 10 note consistent one-to-one renaming learned only from `targetId`, receipt `id` and `spaceId`. 11 note REPORT gets "PASS " or "FAIL " per record and a summary. 12 note Exit 0 only when every record passes and both streams hold one record per corpus line. 13 global pa uchar 4096 14 global cb uchar `16777216` 15 global ra uchar `16777216` 16 global rs uchar `16777216` 17 global hb uchar 64 18 global ob uchar 256 19 global sn uchar 32 20 note hl: header lines (offset, length) of the oracle (0..127) and Omega (128..255) answers 21 global hl ulong 256 22 global hu uchar 64 23 note uuid renaming: mo (oracle) and ms (Omega) 36 bytes each, mc count 24 global mo uchar 589824 25 global ms uchar 589824 26 note cv: 0 corpus len, 1 ofd, 2 sfd, 3 o pos, 4 s pos, 5 o len, 6 s len, 7 report fd, 8 masked, 27 note 9 pass, 10 fail, 11 masks, 12 mc, 13 o err, 14 s err, 15 o body, 16 s body, 17 o hdrs, 18 s hdrs 28 global cv ulong 24 29 global ls ulong `1000000` 30 const NONE ulong `18446744073709551615` 31 text u_use "usage: pcmp CORPUS ORACLE.out OMEGA.out REPORT SINCE\n" 32 text u_open "pcmp: cannot open a file\n" 33 text u_big "pcmp: input too large\n" 34 text r_pass "PASS " 35 text r_fail "FAIL " 36 text f_err " transport-error" 37 text f_stat " status-line" 38 text f_hdr " headers" 39 text f_cl " content-length" 40 text f_body " body@" 41 text f_cnt " record-count" 42 text s_tot "TOTAL records=" 43 text s_pass " pass=" 44 text s_fail " fail=" 45 text s_mask " masked-values=" 46 text s_map " renamed-uuids=" 47 text k_el "elapsedMs" 48 text k_ca "committedAt" 49 text k_cr "createdAt" 50 text k_up "updatedAt" 51 text k_ti "targetId" 52 text k_id "id" 53 text k_sp "spaceId" 54 text k_rc "\"receipt\":{\"id\":" 55 text k_rt "runtime" 56 text v_rto "native-arm64-rust" 57 text v_rts "native-arm64-omega" 58 text h_date "date:" 59 text h_cl "content-length:" 60 61 fn say t view uchar * to void 62 w = write 2 t 0 len t 63 if lt w 0 64 ret 65 end 66 end 67 fn argp i ulong to ulong 68 n = argread i pa 0 len pa 69 if lt n 0 70 ret 0 71 end 72 ret ulong n 73 end 74 fn opnr n ulong to int 75 f = fopen pa 0 n 524288 0 76 ret int f 77 end 78 fn rdall fd int to bool 79 n = ulong 0 80 while true bound 999999 81 if ge n len cb 82 say u_big 83 ret false 84 end 85 r = pread fd cb n sub len cb n long n 86 if lt r 0 87 ret false 88 end 89 if eq r 0 90 put cv 0 n 91 ret true 92 end 93 n = add n ulong r 94 end 95 ret false 96 end 97 98 note ---- report output ---- 99 fn obt o ulong t view uchar * to ulong 100 for i ulong len t 101 put ob add o i get t i 102 end 103 ret add o len t 104 end 105 fn obdec o ulong v ulong to ulong 106 k = o 107 if ge v 10 108 k = obdec o div v 10 109 end 110 put ob k uchar add rem v 10 48 111 ret add k 1 112 end 113 fn flush n ulong to void 114 put ob n 10 115 w = write int get cv 7 ob 0 add n 1 116 if lt w 0 117 ret 118 end 119 end 120 note " " of corpus line ix (bytes up to the first tab), using the line starts in ls 121 fn obcls o ulong ix ulong to ulong 122 i = ulong 0 123 if lt ix len ls 124 i = get ls ix 125 end 126 put ob o 32 127 r = add o 1 128 for j ulong 40 129 c = get cb add i j 130 if or eq c 9 eq c 10 131 break 132 end 133 put ob r c 134 r = add r 1 135 end 136 ret r 137 end 138 139 note ---- answer records ---- 140 note header line of the next record at file offset p into hb; returns its length (0 = none) 141 fn rhead fd int p ulong to ulong 142 for i ulong 64 143 put hb i 0 144 end 145 r = pread fd hb 0 64 long p 146 if le r 0 147 ret 0 148 end 149 for i ulong ulong r 150 if eq get hb i 10 151 ret add i 1 152 end 153 end 154 ret 0 155 end 156 note byte count named in hb ("# \n"); NONE for ERR 157 fn hcount to ulong 158 i = ulong 1 159 while ne get hb i 32 bound 64 160 i = add i 1 161 end 162 i = add i 1 163 if eq get hb i 69 164 ret NONE 165 end 166 v = ulong 0 167 while ne get hb i 10 bound 64 168 v = add mul v 10 ulong sub get hb i 48 169 i = add i 1 170 end 171 ret v 172 end 173 fn rdo n ulong p ulong to bool 174 k = ulong 0 175 while lt k n bound 999999 176 r = pread int get cv 1 ra k sub n k long add p k 177 if le r 0 178 ret false 179 end 180 k = add k ulong r 181 end 182 ret true 183 end 184 fn rds n ulong p ulong to bool 185 k = ulong 0 186 while lt k n bound 999999 187 r = pread int get cv 2 rs k sub n k long add p k 188 if le r 0 189 ret false 190 end 191 k = add k ulong r 192 end 193 ret true 194 end 195 note load the next oracle record; 0 none left, 1 loaded, 2 ERR record, 3 bad stream 196 fn nexto to ulong 197 p = get cv 3 198 h = rhead int get cv 1 p 199 if eq h 0 200 ret 0 201 end 202 n = hcount 203 if eq n NONE 204 put cv 3 add p h 205 put cv 5 0 206 ret 2 207 end 208 if gt n len ra 209 ret 3 210 end 211 if not rdo n add p h 212 ret 3 213 end 214 put cv 3 add add p h add n 1 215 put cv 5 n 216 ret 1 217 end 218 fn nexts to ulong 219 p = get cv 4 220 h = rhead int get cv 2 p 221 if eq h 0 222 ret 0 223 end 224 n = hcount 225 if eq n NONE 226 put cv 4 add p h 227 put cv 6 0 228 ret 2 229 end 230 if gt n len rs 231 ret 3 232 end 233 if not rds n add p h 234 ret 3 235 end 236 put cv 4 add add p h add n 1 237 put cv 6 n 238 ret 1 239 end 240 241 note ---- head comparison ---- 242 note split the oracle answer: header lines into hl[0..), count cv 17, body start cv 15 243 fn splito to void 244 n = get cv 5 245 put cv 17 0 246 put cv 15 n 247 s = ulong 0 248 c = ulong 0 249 for i ulong n 250 if and eq get ra i 13 eq get ra add i 1 10 251 if eq i s 252 put cv 15 add i 2 253 break 254 end 255 if and gt s 0 lt c 63 256 put hl mul c 2 s 257 put hl add mul c 2 1 sub i s 258 c = add c 1 259 end 260 s = add i 2 261 end 262 end 263 put cv 17 c 264 end 265 fn splits to void 266 n = get cv 6 267 put cv 18 0 268 put cv 16 n 269 s = ulong 0 270 c = ulong 0 271 for i ulong n 272 if and eq get rs i 13 eq get rs add i 1 10 273 if eq i s 274 put cv 16 add i 2 275 break 276 end 277 if and gt s 0 lt c 63 278 put hl add 128 mul c 2 s 279 put hl add 128 add mul c 2 1 sub i s 280 c = add c 1 281 end 282 s = add i 2 283 end 284 end 285 put cv 18 c 286 end 287 note status lines equal 288 fn stateq to bool 289 for i ulong get cv 5 290 if ne get ra i get rs i 291 ret false 292 end 293 if eq get ra i 13 294 ret true 295 end 296 end 297 ret false 298 end 299 fn ohas p ulong t view uchar * to bool 300 for i ulong len t 301 if ne get ra add p i get t i 302 ret false 303 end 304 end 305 ret true 306 end 307 fn shas p ulong t view uchar * to bool 308 for i ulong len t 309 if ne get rs add p i get t i 310 ret false 311 end 312 end 313 ret true 314 end 315 note oracle header line i equals Omega header line j 316 fn lneq i ulong j ulong to bool 317 oo = get hl mul i 2 318 ol = get hl add mul i 2 1 319 so = get hl add 128 mul j 2 320 if ne ol get hl add 128 add mul j 2 1 321 ret false 322 end 323 for k ulong ol 324 if ne get ra add oo k get rs add so k 325 ret false 326 end 327 end 328 ret true 329 end 330 note skip-class of a header: 0 compare, 1 date (ignored), 2 content-length 331 fn okind i ulong to ulong 332 p = get hl mul i 2 333 if ohas p h_date 334 ret 1 335 end 336 if ohas p h_cl 337 ret 2 338 end 339 ret 0 340 end 341 fn skind j ulong to ulong 342 p = get hl add 128 mul j 2 343 if shas p h_date 344 ret 1 345 end 346 if shas p h_cl 347 ret 2 348 end 349 ret 0 350 end 351 note 0 equal, 1 headers differ, 2 content-length differs 352 fn hdreq to ulong 353 no = get cv 17 354 ns = get cv 18 355 for j ulong 64 356 put hu j 0 357 end 358 for j ulong ns 359 if eq skind j 1 360 put hu j 1 361 end 362 end 363 r = ulong 0 364 for i ulong no 365 ki = okind i 366 if eq ki 1 367 continue 368 end 369 f = false 370 for j ulong ns 371 if and eq get hu j 0 lneq i j 372 put hu j 1 373 f = true 374 break 375 end 376 end 377 if not f 378 if eq ki 2 379 r = 2 380 continue 381 end 382 ret 1 383 end 384 end 385 ret hdrrest r 386 end 387 note every Omega line must have been matched (content-length mismatches report 2) 388 fn hdrrest r ulong to ulong 389 for j ulong get cv 18 390 if eq get hu j 0 391 if ne skind j 2 392 ret 1 393 end 394 ret 2 395 end 396 end 397 ret r 398 end 399 400 note ---- body comparison with masks ---- 401 note key ending just before oracle offset p (p points at the byte after `":`) equals t 402 fn keyis p ulong t view uchar * to bool 403 n = len t 404 if lt p add n 3 405 ret false 406 end 407 s = sub sub p 2 n 408 if ne get ra sub s 1 34 409 ret false 410 end 411 for i ulong n 412 if ne get ra add s i get t i 413 ret false 414 end 415 end 416 ret true 417 end 418 note oracle offset of the value start that contains the mismatch at io, or NONE (the scan stays 419 note after the last resync point lo) 420 fn valat io ulong lo ulong to ulong 421 k = io 422 while gt k lo bound 999999 423 if and eq get ra sub k 1 58 eq get ra sub k 2 34 424 ret k 425 end 426 c = get ra sub k 1 427 opn = false 428 if and eq c 34 gt sub k 1 lo 429 opn = eq get ra sub k 2 58 430 end 431 if and not opn or eq c 44 or eq c 123 eq c 34 432 if ne k io 433 ret NONE 434 end 435 end 436 k = sub k 1 437 end 438 ret NONE 439 end 440 fn oend p ulong n ulong str bool to ulong 441 for j ulong sub n p 442 c = get ra add p j 443 if str 444 if eq c 34 445 ret add p j 446 end 447 else 448 if or eq c 44 or eq c 125 eq c 93 449 ret add p j 450 end 451 end 452 end 453 ret n 454 end 455 fn send2 p ulong n ulong str bool to ulong 456 for j ulong sub n p 457 c = get rs add p j 458 if str 459 if eq c 34 460 ret add p j 461 end 462 else 463 if or eq c 44 or eq c 125 eq c 93 464 ret add p j 465 end 466 end 467 end 468 ret n 469 end 470 note fresh timestamp: at least SINCE on the first 19 bytes, and the same shape in both 471 fn tseq a ulong ae ulong b ulong be ulong to bool 472 if or lt sub ae a 19 lt sub be b 19 473 ret false 474 end 475 for i ulong 19 476 if ne isdig get ra add a i isdig get rs add b i 477 ret false 478 end 479 end 480 ret and tfresh a true tfresh b false 481 end 482 fn isdig c uchar to bool 483 ret and ge c 48 le c 57 484 end 485 fn tfresh p ulong o bool to bool 486 for i ulong 19 487 c = get rs add p i 488 if o 489 c = get ra add p i 490 end 491 s = get sn i 492 if gt c s 493 ret true 494 end 495 if lt c s 496 ret false 497 end 498 end 499 ret true 500 end 501 fn uuidok p ulong o bool to bool 502 for i ulong 36 503 c = get rs add p i 504 if o 505 c = get ra add p i 506 end 507 if or eq i 8 or eq i 13 or eq i 18 eq i 23 508 if ne c 45 509 ret false 510 end 511 continue 512 end 513 if not or isdig c and ge c 97 le c 102 514 ret false 515 end 516 end 517 ret true 518 end 519 fn meqo m ulong a ulong to bool 520 b = mul m 36 521 for i ulong 36 522 if ne get mo add b i get ra add a i 523 ret false 524 end 525 end 526 ret true 527 end 528 fn meqs m ulong a ulong to bool 529 b = mul m 36 530 for i ulong 36 531 if ne get ms add b i get rs add a i 532 ret false 533 end 534 end 535 ret true 536 end 537 note renaming lookup: 1 pair known, 2 conflict, 0 both unknown 538 fn mfind a ulong b ulong to ulong 539 for m ulong get cv 12 540 fo = meqo m a 541 fs = meqs m b 542 if and fo fs 543 ret 1 544 end 545 if or fo fs 546 ret 2 547 end 548 end 549 ret 0 550 end 551 fn madd a ulong b ulong to bool 552 m = get cv 12 553 if ge m 16384 554 ret false 555 end 556 for i ulong 36 557 put mo add mul m 36 i get ra add a i 558 put ms add mul m 36 i get rs add b i 559 end 560 put cv 12 add m 1 561 ret true 562 end 563 note uuid pair at oracle a / Omega b may differ: learnable keys add a renaming 564 fn uuideq a ulong b ulong learn bool to bool 565 if not and uuidok a true uuidok b false 566 ret false 567 end 568 f = mfind a b 569 if eq f 1 570 ret true 571 end 572 if eq f 2 573 ret false 574 end 575 if not learn 576 ret false 577 end 578 ret madd a b 579 end 580 note the one /health field that differs by design (spec/PARITY.md): runtime is native-arm64-rust in the 581 note oracle and native-arm64-omega here, exactly 582 fn rtmask a ulong ae ulong b ulong be ulong to bool 583 if or ne sub ae a len v_rto ne sub be b len v_rts 584 ret false 585 end 586 for i ulong len v_rto 587 if ne get ra add a i get v_rto i 588 ret false 589 end 590 end 591 for i ulong len v_rts 592 if ne get rs add b i get v_rts i 593 ret false 594 end 595 end 596 ret true 597 end 598 note decimal value of a content-length header line at p (length n) of the oracle (o) or Omega answer 599 fn clval p ulong n ulong o bool to ulong 600 v = ulong 0 601 for i ulong sub n len h_cl 602 c = get rs add add p len h_cl i 603 if o 604 c = get ra add add p len h_cl i 605 end 606 if isdig c 607 v = add mul v 10 sub ulong c 48 608 end 609 end 610 ret v 611 end 612 note HEAD answers carry no body, so a masked value shows only in content-length: the runtime value 613 note of /health and /status makes Omega's exactly one larger; the elapsedMs number of a search or 614 note recall answer may differ in length by less than 24 bytes (the longest JSON f64 text, 615 note -2.`2250738585072014e`-308, is 24 bytes). Accepted only when both bodies are empty. 616 fn headcl ix ulong to bool 617 if or ne get cv 15 get cv 5 ne get cv 16 get cv 6 618 ret false 619 end 620 vo = NONE 621 vs = NONE 622 for i ulong get cv 17 623 if eq okind i 2 624 vo = clval get hl mul i 2 get hl add mul i 2 1 true 625 end 626 end 627 for j ulong get cv 18 628 if eq skind j 2 629 p = get hl add 128 mul j 2 630 n = get hl add add 128 mul j 2 1 631 vs = clval p n false 632 end 633 end 634 if or eq vo NONE eq vs NONE 635 ret false 636 end 637 if eq vs add vo 1 638 ret true 639 end 640 if not hdtim ix 641 ret false 642 end 643 if gt vo vs 644 ret le sub vo vs 24 645 end 646 ret le sub vs vo 24 647 end 648 text t_hs "HEAD\t/api/cortex/search" 649 text t_hr "HEAD\t/api/cortex/recall" 650 note corpus line ix is a HEAD of /api/cortex/search or /api/cortex/recall (answers with elapsedMs) 651 fn hdtim ix ulong to bool 652 if ge ix len ls 653 ret false 654 end 655 i = get ls ix 656 for j ulong 64 657 if eq get cb add i j 9 658 ret or cbhas add add i j 1 t_hs cbhas add add i j 1 t_hr 659 end 660 end 661 ret false 662 end 663 fn cbhas p ulong t view uchar * to bool 664 for k ulong len t 665 if ne get cb add p k get t k 666 ret false 667 end 668 end 669 ret true 670 end 671 note one masked value at oracle vo / Omega vs; returns false when the mismatch is not maskable; 672 note on success cv 19 / cv 20 hold the oracle / Omega offsets after the value 673 fn maskv vo ulong vs ulong to bool 674 no = get cv 5 675 ns = get cv 6 676 if keyis vo k_el 677 put cv 19 oend vo no false 678 put cv 20 send2 vs ns false 679 ret true 680 end 681 if or ne get ra vo 34 ne get rs vs 34 682 ret false 683 end 684 ae = oend add vo 1 no true 685 be = send2 add vs 1 ns true 686 put cv 19 add ae 1 687 put cv 20 add be 1 688 a = add vo 1 689 b = add vs 1 690 if keyis vo k_rt 691 ret rtmask a ae b be 692 end 693 if or keyis vo k_ca or keyis vo k_cr keyis vo k_up 694 ret tseq a ae b be 695 end 696 if or ne sub ae a 36 ne sub be b 36 697 ret false 698 end 699 rc = false 700 if ge vo len k_rc 701 rc = ohas sub vo len k_rc k_rc 702 end 703 lr = or rc or keyis vo k_ti keyis vo k_sp 704 ret uuideq a b lr 705 end 706 note count of equal bytes of ra from io and rs from is (c at most 65536), then the chunked run 707 fn eqchunk io ulong is ulong c ulong to ulong 708 for j ulong c 709 if ne get ra add io j get rs add is j 710 ret j 711 end 712 end 713 ret c 714 end 715 fn eqrun io ulong is ulong no ulong ns ulong to ulong 716 lim = sub no io 717 if lt sub ns is lim 718 lim = sub ns is 719 end 720 r = ulong 0 721 while lt r lim bound 999999 722 c = sub lim r 723 if gt c 65536 724 c = 65536 725 end 726 m = eqchunk add io r add is r c 727 r = add r m 728 if lt m c 729 break 730 end 731 end 732 ret r 733 end 734 note 0 equal (cv 8 = 1 when a mask was used), else 1 + oracle offset of the first difference 735 fn bodyeq to ulong 736 io = get cv 15 737 is = get cv 16 738 no = get cv 5 739 ns = get cv 6 740 lo = io 741 put cv 8 0 742 while true bound 999999 743 if or ge io no ge is ns 744 if and eq io no eq is ns 745 ret 0 746 end 747 ret add io 1 748 end 749 m = eqrun io is no ns 750 io = add io m 751 is = add is m 752 if or ge io no ge is ns 753 continue 754 end 755 vo = valat io lo 756 if eq vo NONE 757 ret add io 1 758 end 759 vs = sub is sub io vo 760 if not maskv vo vs 761 ret add io 1 762 end 763 put cv 8 1 764 put cv 11 add get cv 11 1 765 io = get cv 19 766 is = get cv 20 767 lo = io 768 end 769 ret add io 1 770 end 771 772 note ---- per record ---- 773 fn verdict ix ulong t view uchar * extra ulong to void 774 o = obt 0 r_fail 775 o = obcls obdec o ix ix 776 o = obt o t 777 if ne extra NONE 778 o = obdec o extra 779 end 780 flush o 781 put cv 10 add get cv 10 1 782 end 783 fn passed ix ulong to void 784 o = obt 0 r_pass 785 o = obcls obdec o ix ix 786 flush o 787 put cv 9 add get cv 9 1 788 end 789 fn onerec ix ulong a ulong b ulong to void 790 if or ne a 1 ne b 1 791 verdict ix f_err NONE 792 ret 793 end 794 splito 795 splits 796 if not stateq 797 verdict ix f_stat NONE 798 ret 799 end 800 h = hdreq 801 if eq h 1 802 verdict ix f_hdr NONE 803 ret 804 end 805 d = bodyeq 806 if ne d 0 807 verdict ix f_body sub d get cv 15 808 ret 809 end 810 if eq h 2 811 if or ne get cv 8 0 headcl ix 812 passed ix 813 ret 814 end 815 verdict ix f_cl NONE 816 ret 817 end 818 passed ix 819 end 820 note loops run in 65536-byte chunks: one loop may pass at most `1000000` times (trap 4 beyond) 821 fn linesb b ulong e ulong k0 ulong to ulong 822 k = k0 823 for j ulong sub e b 824 if eq get cb add b j 10 825 k = add k 1 826 if lt k len ls 827 put ls k add add b j 1 828 end 829 end 830 end 831 ret k 832 end 833 fn lines to ulong 834 k = ulong 0 835 n = get cv 0 836 put ls 0 0 837 b = ulong 0 838 while lt b n bound 999999 839 e = add b 65536 840 if gt e n 841 e = n 842 end 843 k = linesb b e k 844 b = e 845 end 846 ret k 847 end 848 fn summary nl ulong ix ulong to void 849 o = obdec obt 0 s_tot ix 850 o = obdec obt o s_pass get cv 9 851 o = obdec obt o s_fail get cv 10 852 o = obdec obt o s_mask get cv 11 853 o = obdec obt o s_map get cv 12 854 flush o 855 if ne nl ix 856 flush obt 0 f_cnt 857 put cv 10 add get cv 10 1 858 end 859 end 860 fn runall to int 861 nl = lines 862 ix = ulong 0 863 while true bound 999999 864 a = nexto 865 b = nexts 866 if and eq a 0 eq b 0 867 break 868 end 869 if or eq a 3 eq b 3 870 say u_big 871 ret 3 872 end 873 onerec ix a b 874 ix = add ix 1 875 end 876 summary nl ix 877 if ne get cv 10 0 878 ret 1 879 end 880 ret 0 881 end 882 fn main to int 883 if ne ulong argcnt 6 884 say u_use 885 ret 2 886 end 887 fd = opnr argp 1 888 if lt fd 0 889 say u_open 890 ret 3 891 end 892 if not rdall fd 893 ret 3 894 end 895 x = fclose fd 896 put cv 1 ulong opnr argp 2 897 put cv 2 ulong opnr argp 3 898 n = argp 4 899 f = fopen pa 0 n 524865 420 900 put cv 7 ulong f 901 if or lt int get cv 1 0 or lt int get cv 2 0 lt f 0 902 say u_open 903 ret 3 904 end 905 if ne argp 5 19 906 say u_use 907 ret 2 908 end 909 for i ulong 19 910 put sn i get pa i 911 end 912 ret runall 913 end