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 / si / harvester / test.om

1150 lines · 21329 bytes Raw Blame History
1om2
2note si/harvester/test.om: Standalone OM-2 behavioral test suite for zero-telemetry harvester.
3note Tests markdown heading/code-fence/metadata/link extraction, <think>/<thought> reasoning & scoring,
4note telemetry domain rejection, tracking query parameter stripping, unsafe scheme refusal,
5note SHA-256 link deduplication, and RFC 8259 JSONL escaping.
6
7global inbuf uchar 32768
8global outbuf uchar 32768
9global urlbuf uchar 512
10global cleanurl uchar 512
11global decbuf uchar 32
12global stats ulong 16
13global shastate uint 8
14global shak uint 64
15global shaw uint 64
16global shablk uchar 64
17global shadig uchar 32
18global shahex uchar 64
19global seenfp uchar 4096
20
21const st_inlen ulong 0
22const st_outlen ulong 1
23const st_heads ulong 2
24const st_blocks ulong 3
25const st_links ulong 4
26const st_telrej ulong 5
27const st_strip ulong 6
28const st_meta ulong 7
29const st_reas ulong 8
30const st_qual ulong 9
31const st_clen ulong 10
32const st_seencnt ulong 11
33const st_dedup ulong 12
34
35text khex "0123456789abcdef"
36text j_head1 "{\"type\":\"heading\",\"level\":"
37text j_text ",\"text\":\""
38text j_link1 "{\"type\":\"link\",\"text\":\""
39text j_url "\",\"url\":\""
40text j_meta1 "{\"type\":\"meta\",\"key\":\""
41text j_val "\",\"value\":\""
42text j_reas1 "{\"type\":\"reasoning\",\"tokens\":"
43text j_qm ",\"quality_milli\":"
44text j_sum1 "{\"type\":\"summary\",\"headings\":"
45text j_sum2 ",\"code_blocks\":"
46text j_sum3 ",\"links\":"
47text j_sum4 ",\"telemetry_rejected\":"
48text j_sum5 ",\"tracking_stripped\":"
49text j_sum6 ",\"meta\":"
50text j_sum7 ",\"reasoning\":"
51text j_sum8 ",\"quality_milli\":"
52text j_sum9 ",\"sha256\":\""
53text j_end "\"}\n"
54
55text t_fence "```"
56text t_think_o "<think>"
57text t_think_c "</think>"
58text t_thought_o "<thought>"
59text t_thought_c "</thought>"
60text t_kw_step "step"
61text t_kw_ver "verify"
62text t_kw_bigo "O("
63
64text mk_title "title:"
65text mk_author "author:"
66text mk_lic "license:"
67text mk_pin "pin:"
68text mk_src "source:"
69text mk_date "date:"
70text mk_ver "version:"
71text mk_prov "provider:"
72text mk_mod "model:"
73
74text td_ga "google-analytics.com"
75text td_gtm "googletagmanager.com"
76text td_dc "doubleclick.net"
77text td_mp "mixpanel.com"
78text td_sg1 "segment.io"
79text td_sg2 "segment.com"
80text td_amp "amplitude.com"
81text td_hj "hotjar.com"
82text td_fb "facebook.com/tr"
83text td_tel "telemetry."
84text td_ana "analytics."
85text td_pix "pixel."
86text td_bea "beacon."
87text td_js "javascript:"
88text td_dat "data:"
89
90text qp_utm "utm_"
91text qp_fb "fbclid="
92text qp_gc "gclid="
93text qp_mc "mc_eid="
94
95note Test inputs
96text doc_pos_a "title: Omega Pure Stack\nlicense: Apache-2.0\n# Main Title\n## Section Two\nSee [Omega](https://interplane.io/omega/).\n```omega\n# Not a heading\n[Ignored](https://interplane.io/ignored)\n```\n"
97text doc_pos_b "### Section Three\n```\ncode block two\n```\n<think>Step 1: verify O(N) extraction with deterministic zero-telemetry output.</think>\n"
98
99text doc_tel "[A](https://www.google-analytics.com/collect?v=1)\n[B](https://api.segment.io/v1/t)\n[C](https://mixpanel.com/track)\n[D](https://telemetry.example.com/ping)\n"
100text doc_strip "[Keep](https://interplane.io/docs?id=42&utm_source=x&fbclid=y)\n[Pure](https://interplane.io/clean?utm_campaign=z&gclid=w)\n"
101text doc_unsafe "[X](javascript:alert(1))\n[Y](data:text/html,hi)\n"
102text doc_dedup "[One](https://interplane.io/Omega?utm_source=a)\n[Two](https://INTERPLANE.IO/omega?fbclid=b)\n"
103text doc_esc "# Say \"Hi\" \\ Now\n"
104text doc_short_thought "<thought>short</thought>\n"
105
106text exp_clean1 "\"url\":\"https://interplane.io/docs?id=42\""
107text exp_clean2 "\"url\":\"https://interplane.io/clean\""
108text exp_esc "\"text\":\"Say \\\"Hi\\\" \\\\ Now\""
109
110text p_1 "PASS pos_markdown_headings_fences_meta_reasoning\n"
111text p_2 "PASS neg_telemetry_domains_rejected\n"
112text p_3 "PASS neg_tracking_query_params_stripped\n"
113text p_4 "PASS neg_unsafe_url_schemes_rejected\n"
114text p_5 "PASS dedup_sha256_case_and_tracking_invariant\n"
115text p_6 "PASS jsonl_quote_and_backslash_escaping\n"
116text p_7 "PASS reasoning_quality_scoring_boundaries\n"
117text p_all "HARVESTER TEST SUITE PASS (7/7)\n"
118text f_msg "FAIL test case "
119text t_nl "\n"
120
121fn write_all fd int src view uchar * off ulong n ulong to void
122p = ulong 0
123while lt p n bound 4096
124k = write fd src add off p sub n p
125if le k 0
126exit 2
127end
128p = add p ulong k
129end
130end
131
132fn wstr fd int s view uchar * to void
133write_all fd s 0 len s
134end
135
136fn wdec fd int v ulong to void
137i = ulong 32
138n = v
139while true bound 24
140i = sub i 1
141put decbuf i uchar add rem n 10 48
142n = div n 10
143if eq n 0
144break
145end
146end
147p = i
148while lt p 32 bound 32
149k = write fd decbuf p sub 32 p
150if le k 0
151exit 2
152end
153p = add p ulong k
154end
155end
156
157fn fail_case id ulong to void
158wstr 2 f_msg
159wdec 2 id
160wstr 2 t_nl
161exit 1
162end
163
164fn to_lower c uchar to uchar
165if and ge c 65 le c 90
166ret add c 32
167end
168ret c
169end
170
171fn in_reset to void
172put stats st_inlen 0
173end
174
175fn in_append s view uchar * to void
176tot = get stats st_inlen
177n = len s
178i = ulong 0
179while lt i n bound 4096
180put inbuf add tot i get s i
181i = add i 1
182end
183put stats st_inlen add tot n
184end
185
186fn out_push_ch c uchar to void
187p = get stats st_outlen
188if lt p 32768
189put outbuf p c
190put stats st_outlen add p 1
191end
192end
193
194fn out_push_lit s view uchar * to void
195sl = len s
196i = ulong 0
197while lt i sl bound 1024
198out_push_ch get s i
199i = add i 1
200end
201end
202
203fn out_push_dec v ulong to void
204i = ulong 32
205n = v
206while true bound 24
207i = sub i 1
208put decbuf i uchar add rem n 10 48
209n = div n 10
210if eq n 0
211break
212end
213end
214p = i
215while lt p 32 bound 32
216out_push_ch get decbuf p
217p = add p 1
218end
219end
220
221fn out_push_json_ch c uchar to void
222if eq c 34
223out_push_ch 92
224out_push_ch 34
225ret
226end
227if eq c 92
228out_push_ch 92
229out_push_ch 92
230ret
231end
232if eq c 10
233out_push_ch 92
234out_push_ch 110
235ret
236end
237if eq c 13
238out_push_ch 92
239out_push_ch 114
240ret
241end
242if eq c 9
243out_push_ch 92
244out_push_ch 116
245ret
246end
247if ge c 32
248out_push_ch c
249end
250end
251
252fn out_push_in_json off ulong n ulong to void
253i = ulong 0
254while lt i n bound 32768
255if lt add off i 32768
256out_push_json_ch get inbuf add off i
257end
258i = add i 1
259end
260end
261
262fn out_push_cleanurl_json to void
263n = get stats st_clen
264i = ulong 0
265while lt i n bound 512
266out_push_json_ch get cleanurl i
267i = add i 1
268end
269end
270
271fn out_push_shahex to void
272for i ulong 64
273out_push_ch get shahex i
274end
275end
276
277fn out_starts_at pos ulong needle view uchar * to bool
278nl = len needle
279tot = get stats st_outlen
280if gt add pos nl tot
281ret false
282end
283i = ulong 0
284while lt i nl bound 256
285if ne get outbuf add pos i get needle i
286ret false
287end
288i = add i 1
289end
290ret true
291end
292
293fn out_contains needle view uchar * to bool
294nl = len needle
295tot = get stats st_outlen
296if gt nl tot
297ret false
298end
299lim = add sub tot nl 1
300i = ulong 0
301while lt i lim bound 32768
302if out_starts_at i needle
303ret true
304end
305i = add i 1
306end
307ret false
308end
309
310fn sha_kinit to void
311put shak 0 0x428a2f98
312put shak 1 0x71374491
313put shak 2 0xb5c0fbcf
314put shak 3 0xe9b5dba5
315put shak 4 0x3956c25b
316put shak 5 0x59f111f1
317put shak 6 0x923f82a4
318put shak 7 0xab1c5ed5
319put shak 8 0xd807aa98
320put shak 9 0x12835b01
321put shak 10 0x243185be
322put shak 11 0x550c7dc3
323put shak 12 0x72be5d74
324put shak 13 0x80deb1fe
325put shak 14 0x9bdc06a7
326put shak 15 0xc19bf174
327put shak 16 0xe49b69c1
328put shak 17 0xefbe4786
329put shak 18 0x0fc19dc6
330put shak 19 0x240ca1cc
331put shak 20 0x2de92c6f
332put shak 21 0x4a7484aa
333put shak 22 0x5cb0a9dc
334put shak 23 0x76f988da
335put shak 24 0x983e5152
336put shak 25 0xa831c66d
337put shak 26 0xb00327c8
338put shak 27 0xbf597fc7
339put shak 28 0xc6e00bf3
340put shak 29 0xd5a79147
341put shak 30 0x06ca6351
342put shak 31 0x14292967
343put shak 32 0x27b70a85
344put shak 33 0x2e1b2138
345put shak 34 0x4d2c6dfc
346put shak 35 0x53380d13
347put shak 36 0x650a7354
348put shak 37 0x766a0abb
349put shak 38 0x81c2c92e
350put shak 39 0x92722c85
351put shak 40 0xa2bfe8a1
352put shak 41 0xa81a664b
353put shak 42 0xc24b8b70
354put shak 43 0xc76c51a3
355put shak 44 0xd192e819
356put shak 45 0xd6990624
357put shak 46 0xf40e3585
358put shak 47 0x106aa070
359put shak 48 0x19a4c116
360put shak 49 0x1e376c08
361put shak 50 0x2748774c
362put shak 51 0x34b0bcb5
363put shak 52 0x391c0cb3
364put shak 53 0x4ed8aa4a
365put shak 54 0x5b9cca4f
366put shak 55 0x682e6ff3
367put shak 56 0x748f82ee
368put shak 57 0x78a5636f
369put shak 58 0x84c87814
370put shak 59 0x8cc70208
371put shak 60 0x90befffa
372put shak 61 0xa4506ceb
373put shak 62 0xbef9a3f7
374put shak 63 0xc67178f2
375end
376
377fn sha_iv to void
378put shastate 0 0x6a09e667
379put shastate 1 0xbb67ae85
380put shastate 2 0x3c6ef372
381put shastate 3 0xa54ff53a
382put shastate 4 0x510e527f
383put shastate 5 0x9b05688c
384put shastate 6 0x1f83d9ab
385put shastate 7 0x5be0cd19
386end
387
388fn sha_sched to void
389for i ulong 16
390q = mul i 4
391x = uint get shablk q
392x = or shl x 8 uint get shablk add q 1
393x = or shl x 8 uint get shablk add q 2
394put shaw i or shl x 8 uint get shablk add q 3
395end
396for i ulong 48
397x = get shaw add i 1
398y = get shaw add i 14
399s0 = xor xor rotr x 7 rotr x 18 shr x 3
400s1 = xor xor rotr y 17 rotr y 19 shr y 10
401put shaw add i 16 add add get shaw i get shaw add i 9 add s0 s1
402end
403end
404
405fn sha_compress to void
406sha_sched
407a = get shastate 0
408b = get shastate 1
409c = get shastate 2
410d = get shastate 3
411e = get shastate 4
412f = get shastate 5
413g = get shastate 6
414h = get shastate 7
415t = uint 0
416for i ulong 64
417h = add h get shak i
418h = add h get shaw i
419t = xor rotr e 6 rotr e 11
420t = xor t rotr e 25
421h = add h t
422h = add h xor g and e xor f g
423d = add d h
424t = xor rotr a 2 rotr a 13
425t = xor t rotr a 22
426h = add h t
427h = add h or and a b and c or a b
428t = h
429h = g
430g = f
431f = e
432e = d
433d = c
434c = b
435b = a
436a = t
437end
438put shastate 0 add get shastate 0 a
439put shastate 1 add get shastate 1 b
440put shastate 2 add get shastate 2 c
441put shastate 3 add get shastate 3 d
442put shastate 4 add get shastate 4 e
443put shastate 5 add get shastate 5 f
444put shastate 6 add get shastate 6 g
445put shastate 7 add get shastate 7 h
446end
447
448fn sha_finalize_hex to void
449for i ulong 8
450w = get shastate i
451q = mul i 4
452put shadig q uchar and shr w 24 255
453put shadig add q 1 uchar and shr w 16 255
454put shadig add q 2 uchar and shr w 8 255
455put shadig add q 3 uchar and w 255
456end
457for i ulong 32
458bv = ulong get shadig i
459put shahex mul i 2 get khex shr bv 4
460put shahex add mul i 2 1 get khex and bv 15
461end
462end
463
464fn sha256_inbuf to void
465dlen = get stats st_inlen
466sha_kinit
467sha_iv
468off = ulong 0
469while ge sub dlen off 64 bound 1024
470for j ulong 64
471put shablk j get inbuf add off j
472end
473sha_compress
474off = add off 64
475end
476remn = sub dlen off
477for j ulong 64
478if lt j remn
479put shablk j get inbuf add off j
480else
481put shablk j 0
482end
483end
484put shablk remn 0x80
485if gt remn 55
486sha_compress
487for j ulong 64
488put shablk j 0
489end
490end
491bits = mul dlen 8
492put shablk 56 uchar and shr bits 56 255
493put shablk 57 uchar and shr bits 48 255
494put shablk 58 uchar and shr bits 40 255
495put shablk 59 uchar and shr bits 32 255
496put shablk 60 uchar and shr bits 24 255
497put shablk 61 uchar and shr bits 16 255
498put shablk 62 uchar and shr bits 8 255
499put shablk 63 uchar and bits 255
500sha_compress
501sha_finalize_hex
502end
503
504fn sha256_cleanurl to void
505dlen = get stats st_clen
506sha_kinit
507sha_iv
508off = ulong 0
509while ge sub dlen off 64 bound 16
510for j ulong 64
511put shablk j to_lower get cleanurl add off j
512end
513sha_compress
514off = add off 64
515end
516remn = sub dlen off
517for j ulong 64
518if lt j remn
519put shablk j to_lower get cleanurl add off j
520else
521put shablk j 0
522end
523end
524put shablk remn 0x80
525if gt remn 55
526sha_compress
527for j ulong 64
528put shablk j 0
529end
530end
531bits = mul dlen 8
532put shablk 56 uchar and shr bits 56 255
533put shablk 57 uchar and shr bits 48 255
534put shablk 58 uchar and shr bits 40 255
535put shablk 59 uchar and shr bits 32 255
536put shablk 60 uchar and shr bits 24 255
537put shablk 61 uchar and shr bits 16 255
538put shablk 62 uchar and shr bits 8 255
539put shablk 63 uchar and bits 255
540sha_compress
541sha_finalize_hex
542end
543
544fn dedup_insert_cleanurl to bool
545sha256_cleanurl
546cnt = get stats st_seencnt
547k = ulong 0
548while lt k cnt bound 64
549base = mul k 64
550same = true
551for i ulong 64
552if ne get seenfp add base i get shahex i
553same = false
554end
555end
556if same
557put stats st_dedup add get stats st_dedup 1
558ret false
559end
560k = add k 1
561end
562if lt cnt 64
563base2 = mul cnt 64
564for i ulong 64
565put seenfp add base2 i get shahex i
566end
567put stats st_seencnt add cnt 1
568end
569ret true
570end
571
572fn in_starts_ci off ulong lim ulong pat view uchar * to bool
573pl = len pat
574if gt add off pl lim
575ret false
576end
577i = ulong 0
578while lt i pl bound 64
579if ne to_lower get inbuf add off i to_lower get pat i
580ret false
581end
582i = add i 1
583end
584ret true
585end
586
587fn in_contains_ci off ulong lim ulong pat view uchar * to bool
588pl = len pat
589if lt sub lim off pl
590ret false
591end
592endp = add sub lim pl 1
593p = off
594while lt p endp bound 32768
595if in_starts_ci p lim pat
596ret true
597end
598p = add p 1
599end
600ret false
601end
602
603fn url_starts_ci pos ulong ulen ulong pat view uchar * to bool
604pl = len pat
605if gt add pos pl ulen
606ret false
607end
608i = ulong 0
609while lt i pl bound 64
610if ne to_lower get urlbuf add pos i to_lower get pat i
611ret false
612end
613i = add i 1
614end
615ret true
616end
617
618fn url_contains_ci ulen ulong pat view uchar * to bool
619pl = len pat
620if gt pl ulen
621ret false
622end
623lim = add sub ulen pl 1
624i = ulong 0
625while lt i lim bound 512
626if url_starts_ci i ulen pat
627ret true
628end
629i = add i 1
630end
631ret false
632end
633
634fn is_telemetry_url ulen ulong to bool
635if url_starts_ci 0 ulen td_js
636ret true
637end
638if url_starts_ci 0 ulen td_dat
639ret true
640end
641if url_contains_ci ulen td_ga
642ret true
643end
644if url_contains_ci ulen td_gtm
645ret true
646end
647if url_contains_ci ulen td_dc
648ret true
649end
650if url_contains_ci ulen td_mp
651ret true
652end
653if url_contains_ci ulen td_sg1
654ret true
655end
656if url_contains_ci ulen td_sg2
657ret true
658end
659if url_contains_ci ulen td_amp
660ret true
661end
662if url_contains_ci ulen td_hj
663ret true
664end
665if url_contains_ci ulen td_fb
666ret true
667end
668if url_contains_ci ulen td_tel
669ret true
670end
671if url_contains_ci ulen td_ana
672ret true
673end
674if url_contains_ci ulen td_pix
675ret true
676end
677ret url_contains_ci ulen td_bea
678end
679
680fn is_tracking_param pos ulong lim ulong to bool
681if url_starts_ci pos lim qp_utm
682ret true
683end
684if url_starts_ci pos lim qp_fb
685ret true
686end
687if url_starts_ci pos lim qp_gc
688ret true
689end
690ret url_starts_ci pos lim qp_mc
691end
692
693fn strip_tracking_params ulen ulong to void
694qpos = ulen
695i = ulong 0
696while lt i ulen bound 512
697if eq get urlbuf i 63
698qpos = i
699break
700end
701i = add i 1
702end
703cl = ulong 0
704j = ulong 0
705while lt j qpos bound 512
706put cleanurl cl get urlbuf j
707cl = add cl 1
708j = add j 1
709end
710if eq qpos ulen
711put stats st_clen cl
712ret
713end
714first_q = true
715pos = add qpos 1
716while lt pos ulen bound 512
717ps = pos
718while lt pos ulen bound 512
719if eq get urlbuf pos 38
720break
721end
722pos = add pos 1
723end
724if is_tracking_param ps pos
725put stats st_strip add get stats st_strip 1
726else
727if gt pos ps
728if first_q
729put cleanurl cl 63
730cl = add cl 1
731first_q = false
732else
733put cleanurl cl 38
734cl = add cl 1
735end
736k = ps
737while lt k pos bound 512
738if lt cl 512
739put cleanurl cl get urlbuf k
740cl = add cl 1
741end
742k = add k 1
743end
744end
745end
746if lt pos ulen
747pos = add pos 1
748end
749end
750put stats st_clen cl
751end
752
753fn extract_links_on_line ls ulong le_pos ulong to void
754p = ls
755while lt p le_pos bound 32768
756if eq get inbuf p 91
757ts = add p 1
758te = ts
759while lt te le_pos bound 32768
760if eq get inbuf te 93
761break
762end
763te = add te 1
764end
765if and lt add te 2 le_pos eq get inbuf add te 1 40
766us = add te 2
767ue = us
768while lt ue le_pos bound 32768
769if eq get inbuf ue 41
770break
771end
772ue = add ue 1
773end
774if and lt ue le_pos gt ue us
775ul = sub ue us
776if gt ul 511
777ul = ulong 511
778end
779k = ulong 0
780while lt k ul bound 512
781put urlbuf k get inbuf add us k
782k = add k 1
783end
784if is_telemetry_url ul
785put stats st_telrej add get stats st_telrej 1
786else
787strip_tracking_params ul
788if dedup_insert_cleanurl
789put stats st_links add get stats st_links 1
790out_push_lit j_link1
791out_push_in_json ts sub te ts
792out_push_lit j_url
793out_push_cleanurl_json
794out_push_lit j_end
795end
796end
797p = ue
798end
799end
800end
801p = add p 1
802end
803end
804
805fn try_meta_key ls ulong le_pos ulong key view uchar * to bool
806kl = len key
807if not in_starts_ci ls le_pos key
808ret false
809end
810vs = add ls kl
811while lt vs le_pos bound 32768
812if ne get inbuf vs 32
813break
814end
815vs = add vs 1
816end
817ve = le_pos
818while gt ve vs bound 32768
819if ne get inbuf sub ve 1 32
820break
821end
822ve = sub ve 1
823end
824if eq ve vs
825ret false
826end
827put stats st_meta add get stats st_meta 1
828out_push_lit j_meta1
829out_push_in_json ls sub kl 1
830out_push_lit j_val
831out_push_in_json vs sub ve vs
832out_push_lit j_end
833ret true
834end
835
836fn check_meta_line ls ulong le_pos ulong to bool
837if try_meta_key ls le_pos mk_title
838ret true
839end
840if try_meta_key ls le_pos mk_author
841ret true
842end
843if try_meta_key ls le_pos mk_lic
844ret true
845end
846if try_meta_key ls le_pos mk_pin
847ret true
848end
849if try_meta_key ls le_pos mk_src
850ret true
851end
852if try_meta_key ls le_pos mk_date
853ret true
854end
855if try_meta_key ls le_pos mk_ver
856ret true
857end
858if try_meta_key ls le_pos mk_prov
859ret true
860end
861ret try_meta_key ls le_pos mk_mod
862end
863
864fn check_heading_line ls ulong le_pos ulong to bool
865ll = sub le_pos ls
866if lt ll 3
867ret false
868end
869if ne get inbuf ls 35
870ret false
871end
872lvl = ulong 0
873while and lt lvl 3 lt add ls lvl le_pos bound 4
874if ne get inbuf add ls lvl 35
875break
876end
877lvl = add lvl 1
878end
879if eq lvl 0
880ret false
881end
882if ge add ls lvl le_pos
883ret false
884end
885if ne get inbuf add ls lvl 32
886ret false
887end
888ts = add add ls lvl 1
889while lt ts le_pos bound 32768
890if ne get inbuf ts 32
891break
892end
893ts = add ts 1
894end
895ve = le_pos
896while gt ve ts bound 32768
897if ne get inbuf sub ve 1 32
898break
899end
900ve = sub ve 1
901end
902put stats st_heads add get stats st_heads 1
903out_push_lit j_head1
904out_push_dec lvl
905out_push_lit j_text
906out_push_in_json ts sub ve ts
907out_push_lit j_end
908ret true
909end
910
911fn extract_reasoning_blocks to void
912tot = get stats st_inlen
913has_code = gt get stats st_blocks 0
914base_q = ulong 500
915if has_code
916base_q = add base_q 100
917end
918put stats st_qual base_q
919pos = ulong 0
920while lt pos tot bound 32768
921rs = ulong 0
922re = ulong 0
923found = false
924if in_starts_ci pos tot t_think_o
925rs = add pos 7
926q = rs
927while lt q tot bound 32768
928if in_starts_ci q tot t_think_c
929re = q
930found = true
931pos = add q 8
932break
933end
934q = add q 1
935end
936else
937if in_starts_ci pos tot t_thought_o
938rs = add pos 9
939q = rs
940while lt q tot bound 32768
941if in_starts_ci q tot t_thought_c
942re = q
943found = true
944pos = add q 10
945break
946end
947q = add q 1
948end
949end
950end
951if found
952rlen = sub re rs
953qm = ulong 500
954if gt rlen 0
955qm = add qm 200
956end
957if gt rlen 50
958qm = add qm 100
959end
960if or in_contains_ci rs re t_kw_step or in_contains_ci rs re t_kw_ver in_contains_ci rs re t_kw_bigo
961qm = add qm 100
962end
963if has_code
964qm = add qm 100
965end
966if gt qm 1000
967qm = ulong 1000
968end
969if gt qm get stats st_qual
970put stats st_qual qm
971end
972put stats st_reas add get stats st_reas 1
973out_push_lit j_reas1
974out_push_dec div tot 4
975out_push_lit j_qm
976out_push_dec qm
977out_push_lit j_text
978out_push_in_json rs rlen
979out_push_lit j_end
980else
981pos = add pos 1
982end
983end
984end
985
986fn harvest_loaded to void
987tot = get stats st_inlen
988for i ulong 13
989if ne i st_inlen
990put stats i 0
991end
992end
993in_fence = false
994pos = ulong 0
995while lt pos tot bound 32768
996ls = pos
997while lt pos tot bound 32768
998if eq get inbuf pos 10
999break
1000end
1001pos = add pos 1
1002end
1003if in_starts_ci ls pos t_fence
1004if not in_fence
1005in_fence = true
1006put stats st_blocks add get stats st_blocks 1
1007else
1008in_fence = false
1009end
1010else
1011if not in_fence
1012if not check_heading_line ls pos
1013is_m = check_meta_line ls pos
1014if not is_m
1015extract_links_on_line ls pos
1016end
1017end
1018end
1019end
1020if lt pos tot
1021pos = add pos 1
1022end
1023end
1024extract_reasoning_blocks
1025sha256_inbuf
1026out_push_lit j_sum1
1027out_push_dec get stats st_heads
1028out_push_lit j_sum2
1029out_push_dec get stats st_blocks
1030out_push_lit j_sum3
1031out_push_dec get stats st_links
1032out_push_lit j_sum4
1033out_push_dec get stats st_telrej
1034out_push_lit j_sum5
1035out_push_dec get stats st_strip
1036out_push_lit j_sum6
1037out_push_dec get stats st_meta
1038out_push_lit j_sum7
1039out_push_dec get stats st_reas
1040out_push_lit j_sum8
1041out_push_dec get stats st_qual
1042out_push_lit j_sum9
1043out_push_shahex
1044out_push_lit j_end
1045end
1046
1047fn main to int
1048note Test 1: positive full markdown + metadata + 2 code blocks + reasoning
1049in_reset
1050in_append doc_pos_a
1051in_append doc_pos_b
1052harvest_loaded
1053if ne get stats st_heads 3
1054fail_case 1
1055end
1056if ne get stats st_blocks 2
1057fail_case 1
1058end
1059if ne get stats st_links 1
1060fail_case 1
1061end
1062if ne get stats st_meta 2
1063fail_case 1
1064end
1065if ne get stats st_reas 1
1066fail_case 1
1067end
1068if ne get stats st_qual 1000
1069fail_case 1
1070end
1071wstr 1 p_1
1072
1073note Test 2: negative control - telemetry domains rejected
1074in_reset
1075in_append doc_tel
1076harvest_loaded
1077if ne get stats st_telrej 4
1078fail_case 2
1079end
1080if ne get stats st_links 0
1081fail_case 2
1082end
1083wstr 1 p_2
1084
1085note Test 3: negative control - tracking query params stripped while preserving clean params
1086in_reset
1087in_append doc_strip
1088harvest_loaded
1089if ne get stats st_links 2
1090fail_case 3
1091end
1092if ne get stats st_strip 4
1093fail_case 3
1094end
1095if not out_contains exp_clean1
1096fail_case 3
1097end
1098if not out_contains exp_clean2
1099fail_case 3
1100end
1101wstr 1 p_3
1102
1103note Test 4: negative control - unsafe schemes (javascript:, data:) rejected
1104in_reset
1105in_append doc_unsafe
1106harvest_loaded
1107if ne get stats st_telrej 2
1108fail_case 4
1109end
1110if ne get stats st_links 0
1111fail_case 4
1112end
1113wstr 1 p_4
1114
1115note Test 5: SHA-256 link deduplication invariant to case & stripped tracking params
1116in_reset
1117in_append doc_dedup
1118harvest_loaded
1119if ne get stats st_links 1
1120fail_case 5
1121end
1122if ne get stats st_dedup 1
1123fail_case 5
1124end
1125wstr 1 p_5
1126
1127note Test 6: RFC 8259 JSON escaping of quotes and backslashes
1128in_reset
1129in_append doc_esc
1130harvest_loaded
1131if not out_contains exp_esc
1132fail_case 6
1133end
1134wstr 1 p_6
1135
1136note Test 7: <thought> reasoning scoring boundary (short thought, no code, no keywords = 700)
1137in_reset
1138in_append doc_short_thought
1139harvest_loaded
1140if ne get stats st_reas 1
1141fail_case 7
1142end
1143if ne get stats st_qual 700
1144fail_case 7
1145end
1146wstr 1 p_7
1147
1148wstr 1 p_all
1149ret 0
1150end