interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / core / sovereign-core / om / inquisitor-exit / check.om

687 lines · 10391 bytes Raw Blame History
1om2
2note om/inquisitor-exit/check.om: exit-status contract of spark-inquisitor, report format 2 (DRA-99).
3note Usage: check BIN DIR. BIN is a built spark-inquisitor, DIR an existing writable scratch directory.
4note Each case writes a diff into DIR, runs BIN on it with stdout and stderr in DIR/CASE.out, and checks
5note the exit status and the output. Style findings (dash, buzzword) are advisory: exit 0, finding printed.
6note A planted GitHub token or AWS key, or a .env file, blocks: exit 1, and the token is never echoed.
7note Secrets and dash bytes are assembled at run time, so this file holds neither.
8note Prints PASS NAME or FAIL NAME per case, then INQEXIT PASS cases=N or INQEXIT FAIL cases=N fail=K.
9note Exit 0 every case as expected, 1 a case failed, 2 usage, 3 a host call failed.
10text tpass "PASS "
11text tfail "FAIL "
12text tnl "\n"
13text tsum "INQEXIT "
14text tok1 "PASS cases="
15text tbad "FAIL cases="
16text tfl " fail="
17text tusage "usage: check BIN DIR\n"
18text thost "check: host call failed\n"
19text tslash "/"
20text areview "review"
21text aaudit "audit"
22text aauthor "--author"
23text auser "check"
24text apr "--pr"
25text anum "1"
26text adiff "--diff"
27text hgit "diff --git a/"
28text hb " b/"
29text hplus "+"
30text hci "ci.sh"
31text hexport "export GH_TOKEN="
32text hrs "src/key.rs"
33text hconst "const KEY: &str = \""
34text hq "\";"
35text henv "deploy/.env.local"
36text hnew "new file mode 100644\n--- /dev/null\n+++ b/deploy/.env.local\n@@ -0,0 +1 @@\n+PORT=8080\n"
37text hlib "src/lib.rs"
38text hnote "// note "
39text hdashx " the dash is style only"
40text hgame "// a game-changer helper"
41text hclean "pub fn ok() -> bool { true }"
42text gp1 "gh"
43text gp2 "p_"
44text gp3 "Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2Rr1Qq0Pp9Oo8"
45text ak1 "AK"
46text ak2 "IA"
47text ak3 "QWERTYUIOPASDFGH"
48text mgh "Plaintext GitHub Personal Access Token detected"
49text maws "Plaintext AWS Access Key detected"
50text menv ".env secret file"
51text mfail "Doctrine Diff Audit: FAILED"
52text mdash "Em/En dash detected"
53text madv "Doctrine Diff Audit: PASS (style advisories)"
54text mgame "game-changer"
55text mfmt "spark-inquisitor-report/2"
56text mpass "Doctrine Diff Audit: PASS"
57text maudok "passed critical security invariants"
58text mclean "Diff is clean"
59text mafail "Doctrine audit failed"
60text mred "[line redacted: it contains a plaintext secret]"
61text c1 "token-review-blocks"
62text c2 "aws-key-audit-blocks"
63text c3 "env-file-review-blocks"
64text c4 "dash-only-review-passes-and-prints"
65text c5 "dash-only-audit-passes-and-prints"
66text c6 "buzzword-only-review-passes"
67text c7 "clean-review-passes"
68text c8 "secret-with-dash-review-blocks"
69text f1 "t1"
70text f2 "t2"
71text f3 "t3"
72text f4 "t4"
73text f5 "t5"
74text f6 "t6"
75text f7 "t7"
76text f8 "t8"
77text sdiff ".diff"
78text sout ".out"
79global bin uchar 2048
80global binl ulong 1
81global dir uchar 2048
82global dirl ulong 1
83global pth uchar 4096
84global pthl ulong 1
85global opth uchar 4096
86global opl ulong 1
87global fx uchar 8192
88global fxl ulong 1
89global tok uchar 128
90global tokl ulong 1
91global pkt uchar 4096
92global pktl ulong 1
93global obuf uchar 262144
94global obl ulong 1
95global st uchar 4
96global cnt ulong 2
97global nb uchar 32
98global nfail ulong 1
99
100fn fxadd t view uchar * to void
101n = get fxl 0
102for i ulong len t
103put fx add n i get t i
104end
105put fxl 0 add n len t
106ret
107end
108
109fn fxdash to void
110n = get fxl 0
111put fx n uchar 226
112put fx add n 1 uchar 128
113put fx add n 2 uchar 148
114put fxl 0 add n 3
115ret
116end
117
118fn fxtok to void
119n = get fxl 0
120t = get tokl 0
121for i ulong t
122put fx add n i get tok i
123end
124put fxl 0 add n t
125ret
126end
127
128fn tokadd t view uchar * to void
129n = get tokl 0
130for i ulong len t
131put tok add n i get t i
132end
133put tokl 0 add n len t
134ret
135end
136
137fn fxhead name view uchar * to void
138put fxl 0 0
139fxadd hgit
140fxadd name
141fxadd hb
142fxadd name
143fxadd tnl
144ret
145end
146
147fn dpath name view uchar * to void
148n = get dirl 0
149for i ulong n
150put pth i get dir i
151end
152put pth n get tslash 0
153n = add n 1
154for i ulong len name
155put pth add n i get name i
156end
157n = add n len name
158for i ulong len sdiff
159put pth add n i get sdiff i
160end
161put pthl 0 add n len sdiff
162ret
163end
164
165fn opath name view uchar * to void
166n = get dirl 0
167for i ulong n
168put opth i get dir i
169end
170put opth n get tslash 0
171n = add n 1
172for i ulong len name
173put opth add n i get name i
174end
175n = add n len name
176for i ulong len sout
177put opth add n i get sout i
178end
179put opl 0 add n len sout
180ret
181end
182
183fn fxwr to long
184fd = fopen pth 0 get pthl 0 577 420
185if lt fd 0
186ret fd
187end
188n = get fxl 0
189k = write int fd fx 0 n
190r = fclose int fd
191if ne k long n
192ret -1
193end
194ret 0
195end
196
197fn pkhdr to void
198n = get pktl 0
199c = add get cnt 1 1
200put cnt 1 c
201put pkt 0 uchar and c 255
202put pkt 1 uchar shr c 8
203ret
204end
205
206fn pkadd t view uchar * to void
207n = get pktl 0
208m = len t
209put pkt n uchar and m 255
210put pkt add n 1 uchar shr m 8
211n = add n 2
212for i ulong m
213put pkt add n i get t i
214end
215put pktl 0 add n m
216pkhdr
217ret
218end
219
220fn pkbin to void
221n = get pktl 0
222m = get binl 0
223put pkt n uchar and m 255
224put pkt add n 1 uchar shr m 8
225n = add n 2
226for i ulong m
227put pkt add n i get bin i
228end
229put pktl 0 add n m
230pkhdr
231ret
232end
233
234fn pkpth to void
235n = get pktl 0
236m = get pthl 0
237put pkt n uchar and m 255
238put pkt add n 1 uchar shr m 8
239n = add n 2
240for i ulong m
241put pkt add n i get pth i
242end
243put pktl 0 add n m
244pkhdr
245ret
246end
247
248fn pkstart to void
249put pktl 0 2
250put cnt 1 0
251pkbin
252ret
253end
254
255fn pkreview to void
256pkstart
257pkadd areview
258pkadd aauthor
259pkadd auser
260pkadd apr
261pkadd anum
262pkadd adiff
263pkpth
264ret
265end
266
267fn pkaudit to void
268pkstart
269pkadd aaudit
270pkadd adiff
271pkpth
272ret
273end
274
275note run: fork, child sends stdout and stderr to opth and executes the packet; returns the exit
276note status 0..255, or -1 when the child died by a signal, or -2 when a host call failed.
277fn run to long
278pid = fork
279if lt pid 0
280ret -2
281end
282if eq pid 0
283fd = fopen opth 0 get opl 0 577 420
284if lt fd 0
285exit 126
286end
287r = dupfd int fd 1 0
288r = dupfd int fd 2 0
289r = execprog pkt 0 get pktl 0
290exit 127
291end
292r = waitpid int pid st 0 4 0
293if ne r pid
294ret -2
295end
296if ne get st 0 0
297ret -1
298end
299ret long get st 1
300end
301
302fn rdout to long
303put obl 0 0
304fd = fopen opth 0 get opl 0 0 0
305if lt fd 0
306ret fd
307end
308n = ulong 0
309c = true
310while c bound 262145
311k = read int fd obuf n sub len obuf n
312if lt k 0
313r = fclose int fd
314ret k
315end
316if eq k 0
317c = false
318else
319n = add n ulong k
320if eq n len obuf
321c = false
322end
323end
324end
325r = fclose int fd
326put obl 0 n
327ret 0
328end
329
330fn matchat i ulong t view uchar * to bool
331for j ulong len t
332if ne get obuf add i j get t j
333ret false
334end
335end
336ret true
337end
338
339fn has t view uchar * to bool
340n = get obl 0
341if lt n len t
342ret false
343end
344m = add sub n len t 1
345for i ulong m
346if matchat i t
347ret true
348end
349end
350ret false
351end
352
353fn attok i ulong to bool
354t = get tokl 0
355for j ulong t
356if ne get obuf add i j get tok j
357ret false
358end
359end
360ret true
361end
362
363fn hastok to bool
364n = get obl 0
365t = get tokl 0
366if lt n t
367ret false
368end
369m = add sub n t 1
370for i ulong m
371if attok i
372ret true
373end
374end
375ret false
376end
377
378fn pnum v ulong to void
379n = ulong 0
380x = v
381c = true
382while c bound 32
383put nb sub 31 n uchar add 48 rem x 10
384n = add n 1
385x = div x 10
386if eq x 0
387c = false
388end
389end
390k = write 1 nb sub 32 n n
391ret
392end
393
394fn rep name view uchar * ok bool to void
395put cnt 0 add get cnt 0 1
396if ok
397k = write 1 tpass 0 len tpass
398else
399k = write 1 tfail 0 len tfail
400put nfail 0 add get nfail 0 1
401end
402k = write 1 name 0 len name
403k = write 1 tnl 0 len tnl
404ret
405end
406
407note go: write the fixture to DIR/F.diff, run the prepared argument kind, read DIR/F.out.
408note kind 0 is review, 1 is audit. Returns the exit status, or -3 when a host call failed.
409fn go f view uchar * kind ulong to long
410dpath f
411opath f
412r = fxwr
413if ne r 0
414ret -3
415end
416if eq kind 0
417pkreview
418else
419pkaudit
420end
421rc = run
422if lt rc -1
423ret -3
424end
425r = rdout
426if ne r 0
427ret -3
428end
429ret rc
430end
431
432fn tokgh to void
433put tokl 0 0
434tokadd gp1
435tokadd gp2
436tokadd gp3
437ret
438end
439
440fn tokaws to void
441put tokl 0 0
442tokadd ak1
443tokadd ak2
444tokadd ak3
445ret
446end
447
448fn case1 to long
449tokgh
450fxhead hci
451fxadd hplus
452fxadd hexport
453fxtok
454fxadd tnl
455rc = go f1 0
456if eq rc -3
457ret 3
458end
459ok = eq rc 1
460if eq has mgh false
461ok = false
462end
463if eq has mfail false
464ok = false
465end
466if hastok
467ok = false
468end
469rep c1 ok
470ret 0
471end
472
473fn case2 to long
474tokaws
475fxhead hrs
476fxadd hplus
477fxadd hconst
478fxtok
479fxadd hq
480fxadd tnl
481rc = go f2 1
482if eq rc -3
483ret 3
484end
485ok = eq rc 1
486if eq has maws false
487ok = false
488end
489if eq has mafail false
490ok = false
491end
492if hastok
493ok = false
494end
495rep c2 ok
496ret 0
497end
498
499fn case3 to long
500fxhead henv
501fxadd hnew
502rc = go f3 0
503if eq rc -3
504ret 3
505end
506ok = eq rc 1
507if eq has menv false
508ok = false
509end
510if eq has mfail false
511ok = false
512end
513rep c3 ok
514ret 0
515end
516
517fn dashfx to void
518fxhead hlib
519fxadd hplus
520fxadd hnote
521fxdash
522fxadd hdashx
523fxadd tnl
524ret
525end
526
527fn case4 to long
528dashfx
529rc = go f4 0
530if eq rc -3
531ret 3
532end
533ok = eq rc 0
534if eq has mdash false
535ok = false
536end
537if eq has madv false
538ok = false
539end
540if eq has mfmt false
541ok = false
542end
543if has mfail
544ok = false
545end
546rep c4 ok
547ret 0
548end
549
550fn case5 to long
551dashfx
552rc = go f5 1
553if eq rc -3
554ret 3
555end
556ok = eq rc 0
557if eq has mdash false
558ok = false
559end
560if eq has maudok false
561ok = false
562end
563if has mafail
564ok = false
565end
566rep c5 ok
567ret 0
568end
569
570fn case6 to long
571fxhead hlib
572fxadd hplus
573fxadd hgame
574fxadd tnl
575rc = go f6 0
576if eq rc -3
577ret 3
578end
579ok = eq rc 0
580if eq has mgame false
581ok = false
582end
583if eq has madv false
584ok = false
585end
586rep c6 ok
587ret 0
588end
589
590fn case7 to long
591fxhead hlib
592fxadd hplus
593fxadd hclean
594fxadd tnl
595rc = go f7 0
596if eq rc -3
597ret 3
598end
599ok = eq rc 0
600if eq has mpass false
601ok = false
602end
603if has madv
604ok = false
605end
606if has mfail
607ok = false
608end
609rep c7 ok
610ret 0
611end
612
613fn case8 to long
614tokgh
615fxhead hci
616fxadd hplus
617fxadd hexport
618fxtok
619fxadd hnote
620fxdash
621fxadd tnl
622rc = go f8 0
623if eq rc -3
624ret 3
625end
626ok = eq rc 1
627if eq has mgh false
628ok = false
629end
630if eq has mdash false
631ok = false
632end
633if eq has mred false
634ok = false
635end
636if hastok
637ok = false
638end
639rep c8 ok
640ret 0
641end
642
643fn main to int
644if ne argcnt 3
645k = write 2 tusage 0 len tusage
646ret 2
647end
648n = argread 1 bin 0 len bin
649if le n 0
650k = write 2 tusage 0 len tusage
651ret 2
652end
653put binl 0 ulong n
654n = argread 2 dir 0 len dir
655if le n 0
656k = write 2 tusage 0 len tusage
657ret 2
658end
659put dirl 0 ulong n
660put cnt 0 0
661put nfail 0 0
662r = add case1 case2
663r = add r case3
664r = add r case4
665r = add r case5
666r = add r case6
667r = add r case7
668r = add r case8
669if ne r 0
670k = write 2 thost 0 len thost
671ret 3
672end
673k = write 1 tsum 0 len tsum
674nf = get nfail 0
675if eq nf 0
676k = write 1 tok1 0 len tok1
677pnum get cnt 0
678k = write 1 tnl 0 len tnl
679ret 0
680end
681k = write 1 tbad 0 len tbad
682pnum get cnt 0
683k = write 1 tfl 0 len tfl
684pnum nf
685k = write 1 tnl 0 len tnl
686ret 1
687end