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/omega-mv/blob/main/si/benchmarks/tests/gates/provenance-check.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / benchmarks / tests / gates / provenance-check.om` 1591 lines ยท 27099 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note provenance-check: the native policy checks of tests/gates/pre-review.sh. 3 note usage: provenance-check MODE [ARGUMENT...] < INPUT 4 note exit 0 accepted, 1 refused (one diagnostic on stderr), 2 usage or I/O failure. 5 note modes: line NEEDLE, contains NEEDLE, doc, block, identity URL RAWSIZE, raw URL, provider URL, ci, manifest. 6 note Every buffer below is sized from a measured machine boundary: one argument is at most 7 note 131071 bytes on Linux (32 pages), so a quote, needle or URL never exceeds that, a stored 8 note document or projection line is 524288 bytes (a row cannot be longer than its quote plus a 9 note fixed head), and a file name is at most 255 bytes (NAME_MAX). A longer row is refused 10 note with a diagnostic; a longer free line (Unchecked or heading) is read to its end without 11 note being stored in full. The document projection streams each such line into the unchecked log. 12 om2 13 global chunk uchar 65536 14 global line uchar 524288 15 global aux uchar 524288 16 global exp uchar 524288 17 global argb uchar 131072 18 global prev uchar 256 19 global kmp ulong 131073 20 note st: 0 line number, 1 in fence, 2 fences, 3 scope lines, 4 public rows, 5 local rows, 21 note 6 copy rows, 7 provider rows, 8 replay rows, 9 external rows, 10 unchecked rows, 22 note 11 write failed, 12 stored length, 13 total length, 14 control byte seen, 23 note 15 mode (0 doc, 1 block, 2 provider, 3 ci, 4 manifest), 16 code lines in fence, 24 note 17 argument length, 18 prev name length, 19 lfs entries, 20 plain entries, 25 note 21 expected length, 22 ci checkout name seen, 23 emitted rows, 24 cursor, 25 streaming an unchecked line 26 global st ulong 32 27 note ur: 0 owner start, 1 owner end, 2 repo start, 3 repo end, 4 commit start, 5 path start, 28 note 6 url end, 8 hex start, 9 quote start 29 global ur ulong 16 30 31 text t_scope "Scope: input identities only. Evaluation status: NOT_RUN." 32 text t_fence "```bash pre-review" 33 text t_fence_end "```" 34 text t_checked "Checked " 35 text t_public "public " 36 text t_local "local " 37 text t_copy "Copy " 38 text t_prov "Provider capture " 39 text t_replay "Replay " 40 text t_input "Input " 41 text t_inputp "PREFLIGHT_INPUT_" 42 text t_ext "External-control " 43 text t_unch "Unchecked: " 44 text t_sha " sha256 " 45 text t_sep " :: " 46 text t_eq " == " 47 text t_curl " curl -fsS '" 48 text t_ip "https://interplane.io/" 49 text t_blob "blob/" 50 text t_hf "https://huggingface.co/api/models/" 51 text t_rev "/revision/" 52 text t_blobs "?blobs=true" 53 text t_schema "forge/blob/1" 54 text t_tab "\t" 55 text t_nl "\n" 56 text t_slash "/" 57 text t_sp " " 58 text t_runpipe_line "run: |" 59 text t_commit "\tcommit\t" 60 text t_raw "/raw/" 61 text t_k_pub "public\t" 62 text t_k_loc "local\t" 63 text t_k_cpy "copy\t" 64 text t_k_prv "provider\t" 65 text t_k_rep "replay\t" 66 text t_k_inp "input\t" 67 text t_k_ext "external\t" 68 text t_k_unc "unchecked\t" 69 text t_name "- name: " 70 text t_checkout "Checkout Source" 71 text t_run "run:" 72 text t_rungate "run: tests/gates/run.sh " 73 text t_runnopy "run: sh scripts/check-no-python.sh" 74 text t_runfetch "run: cargo fetch --locked" 75 text t_rundiff "run: git diff --exit-code" 76 text t_args " args: [\"" 77 text t_args_end "\"]" 78 text t_m_prefix "provenance-check: " 79 text t_m_line "line " 80 text t_m_colon ": " 81 text t_mode_line "line" 82 text t_mode_contains "contains" 83 text t_mode_doc "doc" 84 text t_mode_block "block" 85 text t_mode_identity "identity" 86 text t_mode_raw "raw" 87 text t_mode_provider "provider" 88 text t_mode_ci "ci" 89 text t_mode_manifest "manifest" 90 91 text m_ctl "control character in a document line" 92 text m_grammar "line is not in the evidence grammar" 93 text m_long "row longer than the stored line limit" 94 text m_url "expected a canonical immutable Interplane blob URL" 95 text m_name "expected a flat evidence file name" 96 text m_sha "expected sha256 followed by 64 lowercase hex digits" 97 text m_quote "a checked row needs a nonempty quoted whole line after the double-colon separator" 98 text m_copy "malformed copy row" 99 text m_prov "malformed provider capture row" 100 text m_time "provider capture time is not a valid UTC time in the past" 101 text m_replay "malformed replay row" 102 text m_inputv "malformed input row" 103 text m_extrow "malformed external control row" 104 text m_unch "unchecked row has no text" 105 text m_fence "only the pre-review fence is allowed" 106 text m_fence_open "unterminated pre-review fence" 107 text m_scope "expected exactly one input-provenance scope line" 108 text m_blocks "expected exactly one complete bash pre-review block with a command" 109 text m_pub "no public source row" 110 text m_provn "no provider capture row" 111 text m_payload "expected replay rows or one external control row, not both and not neither" 112 text m_ident "public blob identity mismatch" 113 text m_idsize "raw size argument is not a decimal number" 114 text m_pjson "provider projection is malformed" 115 text m_pdup "provider siblings must be unique, flat and in ascending order" 116 text m_pkind "provider archive needs one ordinary entry and one LFS entry" 117 text m_purl "provider capture URL differs from the archive identity" 118 text m_ci "unrecognised CI run step" 119 text m_nci "no gate step found" 120 121 note ---- output 122 fn outv a view uchar * to void 123 e = len a 124 p = ulong 0 125 while lt p e bound `9223372036854775807` 126 k = write 1 a p sub e p 127 if le k 0 128 put st 11 1 129 ret 130 end 131 p = add p ulong k 132 end 133 end 134 fn outl s ulong e ulong to void 135 p = s 136 while lt p e bound `9223372036854775807` 137 k = write 1 line p sub e p 138 if le k 0 139 put st 11 1 140 ret 141 end 142 p = add p ulong k 143 end 144 end 145 fn errv a view uchar * to void 146 e = len a 147 p = ulong 0 148 while lt p e bound `9223372036854775807` 149 k = write 2 a p sub e p 150 if le k 0 151 ret 152 end 153 p = add p ulong k 154 end 155 end 156 fn errn v ulong to void 157 b = new uchar 24 0 158 i = ulong 23 159 n = v 160 while true bound 20 161 put b i uchar add rem n 10 48 162 n = div n 10 163 if eq n 0 164 break 165 end 166 i = sub i 1 167 end 168 p = i 169 while lt p 24 bound 24 170 k = write 2 b p sub 24 p 171 if le k 0 172 ret 173 end 174 p = add p ulong k 175 end 176 end 177 note refuse: one diagnostic with the current line number, then status 1 178 fn refuse m view uchar * to int 179 errv t_m_prefix 180 n = get st 0 181 if gt n 0 182 errv t_m_line 183 errn n 184 errv t_m_colon 185 end 186 errv m 187 errv t_nl 188 ret 1 189 end 190 191 note ---- character classes 192 fn is_digit c uchar to bool 193 ret and ge c 48 le c 57 194 end 195 fn is_alpha c uchar to bool 196 if and ge c 65 le c 90 197 ret true 198 end 199 ret and ge c 97 le c 122 200 end 201 fn is_hex c uchar to bool 202 if is_digit c 203 ret true 204 end 205 ret and ge c 97 le c 102 206 end 207 fn owner_char c uchar to bool 208 if is_digit c 209 ret true 210 end 211 if is_alpha c 212 ret true 213 end 214 if eq c 95 215 ret true 216 end 217 ret eq c 45 218 end 219 fn name_char c uchar to bool 220 if owner_char c 221 ret true 222 end 223 ret eq c 46 224 end 225 226 note ---- scanning the stored line 227 fn lit_at p ulong lit view uchar * to bool 228 n = get st 12 229 l = len lit 230 if gt add p l n 231 ret false 232 end 233 i = ulong 0 234 while lt i l bound `9223372036854775807` 235 if ne get line add p i get lit i 236 ret false 237 end 238 i = add i 1 239 end 240 ret true 241 end 242 fn line_is lit view uchar * to bool 243 if ne get st 12 len lit 244 ret false 245 end 246 ret lit_at 0 lit 247 end 248 note tok_end: the first space at or after p, or the end of the line 249 fn tok_end p ulong to ulong 250 n = get st 12 251 q = p 252 while lt q n bound `9223372036854775807` 253 if eq get line q 32 254 ret q 255 end 256 q = add q 1 257 end 258 ret n 259 end 260 fn tab_end p ulong to ulong 261 n = get st 12 262 q = p 263 while lt q n bound `9223372036854775807` 264 if eq get line q 9 265 ret q 266 end 267 q = add q 1 268 end 269 ret n 270 end 271 note hexrun: exactly cnt lowercase hex digits at s, inside the stored line 272 fn hexrun s ulong cnt ulong to bool 273 if gt add s cnt get st 12 274 ret false 275 end 276 i = ulong 0 277 while lt i cnt bound `9223372036854775807` 278 if not is_hex get line add s i 279 ret false 280 end 281 i = add i 1 282 end 283 ret true 284 end 285 note name_ok: a flat file name of 1..255 name characters that is neither . nor .. 286 fn name_ok s ulong e ulong to bool 287 if ge s e 288 ret false 289 end 290 w = sub e s 291 if gt w 255 292 ret false 293 end 294 q = s 295 while lt q e bound 255 296 if not name_char get line q 297 ret false 298 end 299 q = add q 1 300 end 301 if eq get line s 46 302 if eq w 1 303 ret false 304 end 305 if and eq w 2 eq get line add s 1 46 306 ret false 307 end 308 end 309 ret true 310 end 311 note path_ok: slash-separated flat names, none empty, none . or .. 312 fn path_ok s ulong e ulong to bool 313 a = s 314 q = s 315 while true bound `9223372036854775807` 316 if eq q e 317 ret name_ok a q 318 end 319 if eq get line q 47 320 if not name_ok a q 321 ret false 322 end 323 a = add q 1 324 end 325 q = add q 1 326 end 327 ret false 328 end 329 note url_ok: the canonical immutable blob URL in line[s,e); the parts go to ur 330 fn url_ok s ulong e ulong to bool 331 if not lit_at s t_ip 332 ret false 333 end 334 p = add s len t_ip 335 q = p 336 while lt q e bound `9223372036854775807` 337 if not owner_char get line q 338 break 339 end 340 q = add q 1 341 end 342 if or le q p ge q e 343 ret false 344 end 345 if ne get line q 47 346 ret false 347 end 348 put ur 0 p 349 put ur 1 q 350 p = add q 1 351 q = p 352 while lt q e bound `9223372036854775807` 353 if not name_char get line q 354 break 355 end 356 q = add q 1 357 end 358 if or le q p ge q e 359 ret false 360 end 361 if ne get line q 47 362 ret false 363 end 364 if not name_ok p q 365 ret false 366 end 367 put ur 2 p 368 put ur 3 q 369 p = add q 1 370 if not lit_at p t_blob 371 ret false 372 end 373 p = add p len t_blob 374 if not hexrun p 40 375 ret false 376 end 377 put ur 4 p 378 p = add p 40 379 if ge p e 380 ret false 381 end 382 if ne get line p 47 383 ret false 384 end 385 p = add p 1 386 if not path_ok p e 387 ret false 388 end 389 put ur 5 p 390 put ur 6 e 391 ret true 392 end 393 fn digits s ulong e ulong to bool 394 if ge s e 395 ret false 396 end 397 q = s 398 while lt q e bound `9223372036854775807` 399 if not is_digit get line q 400 ret false 401 end 402 q = add q 1 403 end 404 ret true 405 end 406 note num: the value of the w decimal digits at s 407 fn num s ulong w ulong to ulong 408 v = ulong 0 409 i = ulong 0 410 while lt i w bound `9223372036854775807` 411 v = add mul v 10 ulong sub get line add s i 48 412 i = add i 1 413 end 414 ret v 415 end 416 note sep_at: the byte at p is the separator c 417 fn sep_at p ulong c uchar to bool 418 ret eq get line p c 419 end 420 note ts_shape: YYYY-MM-DDTHH:MM:SSZ and nothing else, ending the stored line at s plus 20 421 fn ts_shape s ulong to bool 422 if ne get st 12 add s 20 423 ret false 424 end 425 if not digits s add s 4 426 ret false 427 end 428 if not digits add s 5 add s 7 429 ret false 430 end 431 if not digits add s 8 add s 10 432 ret false 433 end 434 if not digits add s 11 add s 13 435 ret false 436 end 437 if not digits add s 14 add s 16 438 ret false 439 end 440 if not digits add s 17 add s 19 441 ret false 442 end 443 if not sep_at add s 4 45 444 ret false 445 end 446 if not sep_at add s 7 45 447 ret false 448 end 449 if not sep_at add s 10 84 450 ret false 451 end 452 if not sep_at add s 13 58 453 ret false 454 end 455 if not sep_at add s 16 58 456 ret false 457 end 458 ret sep_at add s 19 90 459 end 460 note dim_of: days in month mo of year y, the Gregorian rule 461 fn dim_of y ulong mo ulong to ulong 462 if or eq mo 4 or eq mo 6 or eq mo 9 eq mo 11 463 ret 30 464 end 465 if ne mo 2 466 ret 31 467 end 468 if eq rem y 400 0 469 ret 29 470 end 471 if eq rem y 100 0 472 ret 28 473 end 474 if eq rem y 4 0 475 ret 29 476 end 477 ret 28 478 end 479 note civil_days: days since 1970-01-01 of a valid date from 1970 on (Howard Hinnant) 480 fn civil_days y ulong mo ulong d ulong to ulong 481 yy = y 482 mp = add mo 9 483 if gt mo 2 484 mp = sub mo 3 485 else 486 yy = sub y 1 487 end 488 era = div yy 400 489 yoe = sub yy mul era 400 490 doy = div add mul 153 mp 2 5 491 doy = add doy sub d 1 492 doe = mul yoe 365 493 doe = add doe div yoe 4 494 doe = sub doe div yoe 100 495 doe = add doe doy 496 days = mul era 146097 497 ret sub add days doe 719468 498 end 499 note ts_ok: a real calendar time from 1970 that is not after the host clock 500 fn ts_ok s ulong to bool 501 if not ts_shape s 502 ret false 503 end 504 y = num s 4 505 mo = num add s 5 2 506 d = num add s 8 2 507 if lt y 1970 508 ret false 509 end 510 if or lt mo 1 gt mo 12 511 ret false 512 end 513 if or lt d 1 gt d dim_of y mo 514 ret false 515 end 516 hh = num add s 11 2 517 mi = num add s 14 2 518 ss = num add s 17 2 519 if or ge hh 24 or ge mi 60 ge ss 60 520 ret false 521 end 522 secs = mul civil_days y mo d 86400 523 secs = add secs mul hh 3600 524 secs = add secs add mul mi 60 ss 525 now = div ulong realns `1000000000` 526 ret le secs now 527 end 528 529 note ---- row handlers; each returns 0 accepted or 1 refused 530 note tail: after the source token ending at e, expect sha256 HEX and the quoted line 531 fn tail e ulong to int 532 if not lit_at e t_sha 533 ret refuse m_sha 534 end 535 h = add e len t_sha 536 if not hexrun h 64 537 ret refuse m_sha 538 end 539 p = add h 64 540 if not lit_at p t_sep 541 ret refuse m_quote 542 end 543 q = add p len t_sep 544 if ge q get st 12 545 ret refuse m_quote 546 end 547 put ur 8 h 548 put ur 9 q 549 ret 0 550 end 551 fn checked_row to int 552 t = len t_checked 553 n = get st 12 554 if lit_at t t_public 555 s = add t len t_public 556 e = tok_end s 557 if not url_ok s e 558 ret refuse m_url 559 end 560 if ne tail e 0 561 ret 1 562 end 563 outv t_k_pub 564 outl s e 565 outv t_tab 566 h = get ur 8 567 outl h add h 64 568 outv t_tab 569 outl get ur 9 n 570 outv t_nl 571 put st 4 add get st 4 1 572 ret 0 573 end 574 if lit_at t t_local 575 s = add t len t_local 576 e = tok_end s 577 if not name_ok s e 578 ret refuse m_name 579 end 580 if ne tail e 0 581 ret 1 582 end 583 outv t_k_loc 584 outl s e 585 outv t_tab 586 h = get ur 8 587 outl h add h 64 588 outv t_tab 589 outl get ur 9 n 590 outv t_nl 591 put st 5 add get st 5 1 592 ret 0 593 end 594 ret refuse m_grammar 595 end 596 fn copy_row to int 597 s = len t_copy 598 e = tok_end s 599 if not url_ok s e 600 ret refuse m_url 601 end 602 if not lit_at e t_sha 603 ret refuse m_sha 604 end 605 h = add e len t_sha 606 if not hexrun h 64 607 ret refuse m_sha 608 end 609 p = add h 64 610 if not lit_at p t_eq 611 ret refuse m_copy 612 end 613 f = add p len t_eq 614 n = get st 12 615 if not name_ok f n 616 ret refuse m_name 617 end 618 outv t_k_cpy 619 outl s e 620 outv t_tab 621 outl h add h 64 622 outv t_tab 623 outl f n 624 outv t_nl 625 put st 6 add get st 6 1 626 ret 0 627 end 628 fn provider_row to int 629 s = len t_prov 630 e = tok_end s 631 if not name_ok s e 632 ret refuse m_name 633 end 634 p = add e 1 635 if not lit_at e t_sp 636 ret refuse m_prov 637 end 638 if not ts_ok_at p 639 ret refuse m_time 640 end 641 if not lit_at add p 20 t_curl 642 ret refuse m_prov 643 end 644 u = add add p 20 len t_curl 645 n = get st 12 646 if or ge u n ne get line sub n 1 39 647 ret refuse m_prov 648 end 649 v = sub n 1 650 if le v u 651 ret refuse m_prov 652 end 653 q = u 654 while lt q v bound `9223372036854775807` 655 c = get line q 656 if or eq c 39 or eq c 32 lt c 33 657 ret refuse m_prov 658 end 659 q = add q 1 660 end 661 outv t_k_prv 662 outl s e 663 outv t_tab 664 outl p add p 20 665 outv t_tab 666 outl u v 667 outv t_nl 668 put st 7 add get st 7 1 669 ret 0 670 end 671 fn ts_ok_at p ulong to bool 672 note the timestamp must end where the curl text starts, not at the end of the line 673 n = get st 12 674 put st 12 add p 20 675 ok = ts_ok p 676 put st 12 n 677 ret ok 678 end 679 fn replay_row to int 680 s = len t_replay 681 n = get st 12 682 if not name_ok s n 683 ret refuse m_replay 684 end 685 outv t_k_rep 686 outl s n 687 outv t_nl 688 put st 8 add get st 8 1 689 ret 0 690 end 691 fn input_row to int 692 s = len t_input 693 n = get st 12 694 if not lit_at s t_inputp 695 ret refuse m_inputv 696 end 697 q = add s len t_inputp 698 if ge q n 699 ret refuse m_inputv 700 end 701 p = q 702 while lt p n bound `9223372036854775807` 703 c = get line p 704 if not or is_digit c or and ge c 65 le c 90 eq c 95 705 ret refuse m_inputv 706 end 707 p = add p 1 708 end 709 outv t_k_inp 710 outl s n 711 outv t_nl 712 ret 0 713 end 714 fn external_row to int 715 s = len t_ext 716 e = tok_end s 717 if not name_ok s e 718 ret refuse m_name 719 end 720 if not lit_at e t_sha 721 ret refuse m_sha 722 end 723 h = add e len t_sha 724 if not hexrun h 64 725 ret refuse m_sha 726 end 727 if ne add h 64 get st 12 728 ret refuse m_extrow 729 end 730 outv t_k_ext 731 outl s e 732 outv t_tab 733 outl h add h 64 734 outv t_nl 735 put st 9 add get st 9 1 736 ret 0 737 end 738 fn unchecked_from s ulong to int 739 n = get st 12 740 if ge s n 741 ret refuse m_unch 742 end 743 outv t_k_unc 744 outl s n 745 outv t_nl 746 put st 10 add get st 10 1 747 ret 0 748 end 749 fn heading to bool 750 p = ulong 0 751 n = get st 12 752 while lt p n bound `9223372036854775807` 753 if ne get line p 35 754 break 755 end 756 p = add p 1 757 end 758 if or eq p 0 gt p 6 759 ret false 760 end 761 if ge p n 762 ret false 763 end 764 ret eq get line p 32 765 end 766 767 note ---- the document grammar: every line is one of a closed set of forms 768 fn code_line to bool 769 p = ulong 0 770 n = get st 12 771 while lt p n bound `9223372036854775807` 772 c = get line p 773 if and ne c 32 ne c 9 774 ret ne c 35 775 end 776 p = add p 1 777 end 778 ret false 779 end 780 fn doc_line to int 781 n = get st 12 782 mode = get st 15 783 if eq get st 1 1 784 if gt get st 13 n 785 ret refuse m_long 786 end 787 if line_is t_fence_end 788 put st 1 0 789 ret 0 790 end 791 if code_line 792 put st 16 add get st 16 1 793 end 794 if eq mode 1 795 outl 0 n 796 outv t_nl 797 ret 0 798 end 799 if gt n 0 800 ret unchecked_from 0 801 end 802 ret 0 803 end 804 if eq mode 1 805 if line_is t_fence 806 put st 1 1 807 put st 2 add get st 2 1 808 end 809 ret 0 810 end 811 loose = or lit_at 0 t_unch heading 812 if gt get st 13 n 813 if not loose 814 ret refuse m_long 815 end 816 end 817 if eq get st 14 1 818 ret refuse m_ctl 819 end 820 if eq get st 25 1 821 outv t_nl 822 put st 10 add get st 10 1 823 ret 0 824 end 825 if eq n 0 826 ret 0 827 end 828 if line_is t_fence 829 put st 1 1 830 put st 2 add get st 2 1 831 ret 0 832 end 833 if lit_at 0 t_fence_end 834 ret refuse m_fence 835 end 836 if line_is t_scope 837 put st 3 add get st 3 1 838 ret 0 839 end 840 if heading 841 ret unchecked_from 0 842 end 843 if lit_at 0 t_unch 844 ret unchecked_from len t_unch 845 end 846 if lit_at 0 t_checked 847 ret checked_row 848 end 849 if lit_at 0 t_copy 850 ret copy_row 851 end 852 if lit_at 0 t_prov 853 ret provider_row 854 end 855 if lit_at 0 t_replay 856 ret replay_row 857 end 858 if lit_at 0 t_input 859 ret input_row 860 end 861 if lit_at 0 t_ext 862 ret external_row 863 end 864 ret refuse m_grammar 865 end 866 fn doc_end to int 867 put st 0 0 868 mode = get st 15 869 if eq get st 1 1 870 ret refuse m_fence_open 871 end 872 if or ne get st 2 1 lt get st 16 1 873 ret refuse m_blocks 874 end 875 if eq mode 1 876 ret 0 877 end 878 if ne get st 3 1 879 ret refuse m_scope 880 end 881 pub = add get st 4 get st 6 882 if lt pub 1 883 ret refuse m_pub 884 end 885 if lt get st 7 1 886 ret refuse m_provn 887 end 888 rep = gt get st 8 0 889 ext = gt get st 9 0 890 if or and rep ext not or rep ext 891 ret refuse m_payload 892 end 893 if gt get st 9 1 894 ret refuse m_payload 895 end 896 ret 0 897 end 898 899 note ---- provider projection: id TAB sha, then one sorted line per sibling 900 fn ap_lit lit view uchar * to void 901 c = get st 24 902 i = ulong 0 903 l = len lit 904 while lt i l bound `9223372036854775807` 905 put exp add c i get lit i 906 i = add i 1 907 end 908 put st 24 add c l 909 end 910 fn ap_line s ulong e ulong to void 911 c = get st 24 912 i = s 913 while lt i e bound `9223372036854775807` 914 put exp add c sub i s get line i 915 i = add i 1 916 end 917 put st 24 add c sub e s 918 end 919 fn id_ok s ulong e ulong to bool 920 q = s 921 while lt q e bound `9223372036854775807` 922 if eq get line q 47 923 break 924 end 925 q = add q 1 926 end 927 if ge q e 928 ret false 929 end 930 if not name_ok s q 931 ret false 932 end 933 ret name_ok add q 1 e 934 end 935 fn prev_less s ulong e ulong to bool 936 note true when prev < line[s,e) bytewise 937 pl = get st 18 938 w = sub e s 939 i = ulong 0 940 while true bound `9223372036854775807` 941 if eq i pl 942 ret lt i w 943 end 944 if eq i w 945 ret false 946 end 947 a = get prev i 948 b = get line add s i 949 if ne a b 950 ret lt a b 951 end 952 i = add i 1 953 end 954 ret false 955 end 956 fn prov_first to int 957 e1 = tab_end 0 958 if not id_ok 0 e1 959 ret refuse m_pjson 960 end 961 p = add e1 1 962 e2 = tab_end p 963 if or ne e2 get st 12 not hexrun p 40 964 ret refuse m_pjson 965 end 966 put st 24 0 967 ap_lit t_hf 968 ap_line 0 e1 969 ap_lit t_rev 970 ap_line p e2 971 ap_lit t_blobs 972 put st 21 get st 24 973 ret 0 974 end 975 note prov_size: 1..18 decimal digits, no leading zero 976 fn prov_size s ulong e ulong to bool 977 if not digits s e 978 ret false 979 end 980 if gt sub e s 18 981 ret false 982 end 983 if gt sub e s 1 984 ret ne get line s 48 985 end 986 ret true 987 end 988 note prov_same: line[s1,e1) and line[s2,e2) are the same bytes 989 fn prov_same s1 ulong e1 ulong s2 ulong e2 ulong to bool 990 w = sub e1 s1 991 if ne w sub e2 s2 992 ret false 993 end 994 j = ulong 0 995 while lt j w bound `9223372036854775807` 996 if ne get line add s1 j get line add s2 j 997 ret false 998 end 999 j = add j 1 1000 end 1001 ret true 1002 end 1003 note prov_name: the name must be flat and strictly after the previous one; remember it 1004 fn prov_name e1 ulong to int 1005 if not name_ok 0 e1 1006 ret refuse m_pdup 1007 end 1008 if not prev_less 0 e1 1009 ret refuse m_pdup 1010 end 1011 i = ulong 0 1012 while lt i e1 bound `9223372036854775807` 1013 put prev i get line i 1014 i = add i 1 1015 end 1016 put st 18 e1 1017 ret 0 1018 end 1019 fn prov_sibling to int 1020 e1 = tab_end 0 1021 if ne prov_name e1 0 1022 ret 1 1023 end 1024 e2 = tab_end add e1 1 1025 if not prov_size add e1 1 e2 1026 ret refuse m_pjson 1027 end 1028 e3 = tab_end add e2 1 1029 if ne sub e3 add e2 1 40 1030 ret refuse m_pjson 1031 end 1032 if not hexrun add e2 1 40 1033 ret refuse m_pjson 1034 end 1035 e4 = tab_end add e3 1 1036 e5 = tab_end add e4 1 1037 if ne e5 get st 12 1038 ret refuse m_pjson 1039 end 1040 if eq e4 add e3 1 1041 if ne e5 add e4 1 1042 ret refuse m_pjson 1043 end 1044 put st 20 add get st 20 1 1045 ret 0 1046 end 1047 if ne sub e4 add e3 1 64 1048 ret refuse m_pjson 1049 end 1050 if not hexrun add e3 1 64 1051 ret refuse m_pjson 1052 end 1053 if not prov_same add e4 1 e5 add e1 1 e2 1054 ret refuse m_pjson 1055 end 1056 put st 19 add get st 19 1 1057 ret 0 1058 end 1059 fn provider_line to int 1060 if eq get st 0 1 1061 ret prov_first 1062 end 1063 ret prov_sibling 1064 end 1065 fn provider_end to int 1066 put st 0 0 1067 if lt add get st 19 get st 20 1 1068 ret refuse m_pjson 1069 end 1070 if or eq get st 19 0 eq get st 20 0 1071 ret refuse m_pkind 1072 end 1073 al = get st 17 1074 if ne al get st 21 1075 ret refuse m_purl 1076 end 1077 i = ulong 0 1078 while lt i al bound `9223372036854775807` 1079 if ne get exp i get argb i 1080 ret refuse m_purl 1081 end 1082 i = add i 1 1083 end 1084 ret 0 1085 end 1086 1087 note ---- CI workflow and gate manifests 1088 fn ci_line to int 1089 n = get st 12 1090 p = ulong 0 1091 while lt p n bound `9223372036854775807` 1092 if ne get line p 32 1093 break 1094 end 1095 p = add p 1 1096 end 1097 note the shifted view of the line starts at p: copy it down so the literals match at 0 1098 i = p 1099 while lt i n bound `9223372036854775807` 1100 put line sub i p get line i 1101 i = add i 1 1102 end 1103 put st 12 sub n p 1104 if lit_at 0 t_name 1105 put st 22 0 1106 if eq get st 12 add len t_name len t_checkout 1107 if lit_at len t_name t_checkout 1108 put st 22 1 1109 end 1110 end 1111 ret 0 1112 end 1113 if not lit_at 0 t_run 1114 ret 0 1115 end 1116 if lit_at 0 t_rungate 1117 w = len t_rungate 1118 m = get st 12 1119 if ge w m 1120 ret refuse m_ci 1121 end 1122 q = w 1123 while lt q m bound `9223372036854775807` 1124 c = get line q 1125 if not or and ge c 97 le c 122 eq c 45 1126 ret refuse m_ci 1127 end 1128 q = add q 1 1129 end 1130 outl w m 1131 outv t_nl 1132 put st 23 add get st 23 1 1133 ret 0 1134 end 1135 ret ci_other 1136 end 1137 note the run lines that are not gate steps: the exact CI commands this driver covers 1138 fn ci_other to int 1139 if or line_is t_runnopy line_is t_runfetch 1140 ret 0 1141 end 1142 if line_is t_rundiff 1143 ret 0 1144 end 1145 if and line_is t_runpipe_line eq get st 22 1 1146 ret 0 1147 end 1148 ret refuse m_ci 1149 end 1150 fn manifest_line to int 1151 n = get st 12 1152 if not lit_at 0 t_args 1153 ret 0 1154 end 1155 w = len t_args 1156 if lt n add add len t_args len t_args_end 1 1157 ret 0 1158 end 1159 if not lit_at sub n len t_args_end t_args_end 1160 ret 0 1161 end 1162 e = sub n len t_args_end 1163 if ge w e 1164 ret 0 1165 end 1166 q = w 1167 while lt q e bound `9223372036854775807` 1168 c = get line q 1169 if not or and ge c 97 le c 122 eq c 45 1170 ret 0 1171 end 1172 q = add q 1 1173 end 1174 outl w e 1175 outv t_nl 1176 put st 23 add get st 23 1 1177 ret 0 1178 end 1179 1180 note ---- the line stream: every mode reads stdin line by line 1181 fn dispatch to int 1182 mode = get st 15 1183 if le mode 1 1184 ret doc_line 1185 end 1186 if eq mode 2 1187 ret provider_line 1188 end 1189 if eq mode 3 1190 ret ci_line 1191 end 1192 ret manifest_line 1193 end 1194 note The first buffer identifies the row. Continuations are written one chunk at a time. 1195 fn start_unchecked_stream to bool 1196 if or ne get st 15 0 eq get st 1 1 1197 ret false 1198 end 1199 s = ulong 0 1200 if lit_at 0 t_unch 1201 s = len t_unch 1202 else 1203 if not heading 1204 ret false 1205 end 1206 end 1207 outv t_k_unc 1208 outl s get st 12 1209 put st 25 1 1210 ret true 1211 end 1212 fn stream_part p ulong e ulong to void 1213 while lt p e bound 65536 1214 k = write 1 chunk p sub e p 1215 if le k 0 1216 put st 11 1 1217 ret 1218 end 1219 p = add p ulong k 1220 end 1221 end 1222 fn scan to int 1223 put st 0 0 1224 put st 12 0 1225 put st 13 0 1226 put st 14 0 1227 while true bound `9223372036854775807` 1228 got = read 0 chunk 0 len chunk 1229 if lt got 0 1230 ret 2 1231 end 1232 if eq got 0 1233 break 1234 end 1235 i = ulong 0 1236 cnt = ulong got 1237 while lt i cnt bound 65536 1238 c = get chunk i 1239 if eq c 10 1240 put st 0 add get st 0 1 1241 rc = dispatch 1242 if ne rc 0 1243 ret rc 1244 end 1245 put st 12 0 1246 put st 13 0 1247 put st 14 0 1248 put st 25 0 1249 else 1250 if eq get st 13 len line 1251 if eq get st 25 0 1252 ignored = start_unchecked_stream 1253 end 1254 end 1255 if eq get st 25 1 1256 begin = i 1257 while lt i cnt bound 65536 1258 b = get chunk i 1259 if eq b 10 1260 break 1261 end 1262 if or lt b 32 eq b 127 1263 put st 14 1 1264 end 1265 i = add i 1 1266 end 1267 stream_part begin i 1268 put st 13 add get st 13 sub i begin 1269 continue 1270 end 1271 t = get st 13 1272 if lt t len line 1273 put line t c 1274 put st 12 add t 1 1275 end 1276 put st 13 add t 1 1277 if or lt c 32 eq c 127 1278 put st 14 1 1279 end 1280 end 1281 i = add i 1 1282 end 1283 end 1284 if gt get st 13 0 1285 put st 0 add get st 0 1 1286 rc = dispatch 1287 if ne rc 0 1288 ret rc 1289 end 1290 end 1291 mode = get st 15 1292 if le mode 1 1293 ret doc_end 1294 end 1295 if eq mode 2 1296 ret provider_end 1297 end 1298 if and eq mode 3 eq get st 23 0 1299 ret refuse m_nci 1300 end 1301 ret 0 1302 end 1303 1304 note ---- line NEEDLE and contains NEEDLE (argument in argb, length st 17) 1305 fn mode_line to int 1306 w = get st 17 1307 matched = ulong 0 1308 same = true 1309 while true bound `9223372036854775807` 1310 got = read 0 chunk 0 len chunk 1311 if lt got 0 1312 ret 2 1313 end 1314 if eq got 0 1315 if and same eq matched w 1316 ret 0 1317 end 1318 ret 1 1319 end 1320 i = ulong 0 1321 cnt = ulong got 1322 while lt i cnt bound 65536 1323 c = get chunk i 1324 if eq c 10 1325 if and same eq matched w 1326 ret 0 1327 end 1328 matched = 0 1329 same = true 1330 else 1331 if same 1332 if eq matched w 1333 same = false 1334 else 1335 if eq c get argb matched 1336 matched = add matched 1 1337 else 1338 same = false 1339 end 1340 end 1341 end 1342 end 1343 i = add i 1 1344 end 1345 end 1346 ret 2 1347 end 1348 fn mode_contains to int 1349 w = get st 17 1350 put kmp 0 0 1351 k = ulong 0 1352 i = ulong 1 1353 while lt i w bound `9223372036854775807` 1354 while gt k 0 bound `9223372036854775807` 1355 if eq get argb k get argb i 1356 break 1357 end 1358 k = get kmp sub k 1 1359 end 1360 if eq get argb k get argb i 1361 k = add k 1 1362 end 1363 put kmp i k 1364 i = add i 1 1365 end 1366 k = 0 1367 while true bound `9223372036854775807` 1368 got = read 0 chunk 0 len chunk 1369 if lt got 0 1370 ret 2 1371 end 1372 if eq got 0 1373 ret 1 1374 end 1375 j = ulong 0 1376 cnt = ulong got 1377 while lt j cnt bound 65536 1378 c = get chunk j 1379 while gt k 0 bound `9223372036854775807` 1380 if eq get argb k c 1381 break 1382 end 1383 k = get kmp sub k 1 1384 end 1385 if eq get argb k c 1386 k = add k 1 1387 end 1388 if eq k w 1389 ret 0 1390 end 1391 j = add j 1 1392 end 1393 end 1394 ret 2 1395 end 1396 1397 note ---- identity URL RAWSIZE: the public JSON projection line must be exactly what the URL implies 1398 fn mode_identity to int 1399 n = argread 2 line 0 len line 1400 if le n 0 1401 ret 2 1402 end 1403 put st 12 ulong n 1404 if not url_ok 0 ulong n 1405 ret refuse m_url 1406 end 1407 sz = argread 3 argb 0 len argb 1408 if le sz 0 1409 ret 2 1410 end 1411 put st 17 ulong sz 1412 q = ulong 0 1413 while lt q ulong sz bound `9223372036854775807` 1414 if not is_digit get argb q 1415 ret refuse m_idsize 1416 end 1417 q = add q 1 1418 end 1419 total = ulong 0 1420 while true bound `9223372036854775807` 1421 got = read 0 aux total sub len aux total 1422 if lt got 0 1423 ret 2 1424 end 1425 if eq got 0 1426 break 1427 end 1428 total = add total ulong got 1429 if ge total len aux 1430 ret refuse m_ident 1431 end 1432 end 1433 if gt total 0 1434 if eq get aux sub total 1 10 1435 total = sub total 1 1436 end 1437 end 1438 put st 24 0 1439 ap_lit t_schema 1440 ap_lit t_tab 1441 ap_line get ur 0 get ur 1 1442 ap_lit t_tab 1443 ap_line get ur 2 get ur 3 1444 ap_lit t_tab 1445 c0 = get ur 4 1446 ap_line c0 add c0 40 1447 ap_lit t_tab 1448 ap_line c0 add c0 40 1449 ap_lit t_commit 1450 ap_line get ur 5 get ur 6 1451 ap_lit t_tab 1452 ap_lit t_slash 1453 ap_line get ur 0 get ur 1 1454 ap_lit t_slash 1455 ap_line get ur 2 get ur 3 1456 ap_lit t_raw 1457 ap_line c0 add c0 40 1458 ap_lit t_slash 1459 ap_line get ur 5 get ur 6 1460 ap_lit t_tab 1461 c = get st 24 1462 i = ulong 0 1463 while lt i ulong sz bound `9223372036854775807` 1464 put exp add c i get argb i 1465 i = add i 1 1466 end 1467 el = add c ulong sz 1468 if ne el total 1469 ret refuse m_ident 1470 end 1471 i = 0 1472 while lt i total bound `9223372036854775807` 1473 if ne get exp i get aux i 1474 ret refuse m_ident 1475 end 1476 i = add i 1 1477 end 1478 ret 0 1479 end 1480 1481 note ---- raw URL: the raw-bytes route of a canonical blob URL 1482 fn mode_raw to int 1483 n = argread 2 line 0 len line 1484 if le n 0 1485 ret 2 1486 end 1487 put st 12 ulong n 1488 if not url_ok 0 ulong n 1489 ret refuse m_url 1490 end 1491 outv t_ip 1492 outl get ur 0 get ur 1 1493 outv t_slash 1494 outl get ur 2 get ur 3 1495 outv t_raw 1496 c0 = get ur 4 1497 outl c0 add c0 40 1498 outv t_slash 1499 outl get ur 5 get ur 6 1500 outv t_nl 1501 ret 0 1502 end 1503 1504 note ---- main: the first argument picks the mode 1505 fn arg_is lit view uchar * k ulong to bool 1506 if ne len lit k 1507 ret false 1508 end 1509 i = ulong 0 1510 while lt i k bound `9223372036854775807` 1511 if ne get argb i get lit i 1512 ret false 1513 end 1514 i = add i 1 1515 end 1516 ret true 1517 end 1518 fn run to int 1519 if lt argcnt 2 1520 ret 2 1521 end 1522 k = argread 1 argb 0 len argb 1523 if le k 0 1524 ret 2 1525 end 1526 w = ulong k 1527 if arg_is t_mode_doc w 1528 put st 15 0 1529 ret scan 1530 end 1531 if arg_is t_mode_block w 1532 put st 15 1 1533 ret scan 1534 end 1535 if arg_is t_mode_ci w 1536 put st 15 3 1537 ret scan 1538 end 1539 if arg_is t_mode_manifest w 1540 put st 15 4 1541 ret scan 1542 end 1543 if arg_is t_mode_identity w 1544 if ne argcnt 4 1545 ret 2 1546 end 1547 ret mode_identity 1548 end 1549 if arg_is t_mode_raw w 1550 if ne argcnt 3 1551 ret 2 1552 end 1553 ret mode_raw 1554 end 1555 if arg_is t_mode_provider w 1556 if ne argcnt 3 1557 ret 2 1558 end 1559 n = argread 2 argb 0 len argb 1560 if le n 0 1561 ret 2 1562 end 1563 put st 17 ulong n 1564 put st 15 2 1565 ret scan 1566 end 1567 if ne argcnt 3 1568 ret 2 1569 end 1570 is_line = arg_is t_mode_line w 1571 is_contains = arg_is t_mode_contains w 1572 if not or is_line is_contains 1573 ret 2 1574 end 1575 n = argread 2 argb 0 len argb 1576 if le n 0 1577 ret 2 1578 end 1579 put st 17 ulong n 1580 if is_line 1581 ret mode_line 1582 end 1583 ret mode_contains 1584 end 1585 fn main to int 1586 rc = run 1587 if eq get st 11 1 1588 ret 2 1589 end 1590 ret rc 1591 end