interplane.Get Omega
Read in your language

benchmarks-mv

Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.

Brought by drakestapleton

branch main Branches Tags History

benchmarks-mv / tests / gates / provenance-check.om

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