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

424 lines · 9387 bytes Raw Blame History
1note core/dream/test.om: comprehensive positive and negative/refusal tests for spark-dream.
2note Covers all 4 upstream markdown layouts, malformed frontmatter recovery, idle gate,
3note decay scoring, zero-safe cosine similarity, clustering/dedup, promotion, and refusals.
4note Compose: si/directives/om2.om core/dream/lib.om core/dream/test.om
5
6text dt_p_fm "/tmp/note_frontmatter.md"
7text dt_c_fm "---\ntitle: NVFP4 Checkpoint Loader Fix\ntype: learned_procedure\ntags: [vllm, max, quantization]\nsubsystem: neural_weights\n---\n# Implementation Overview\nDirectly map fp4 quantized tensor blocks without conversion overhead."
8text dt_e_fm "NVFP4 Checkpoint Loader Fix"
9
10text dt_p_hd "/tmp/note_heading.md"
11text dt_c_hd "# Discovery: Grace Blackwell GB10 Topology\nDiscovered unified 128GB LPDDR5X bus between CPU and dual Blackwell GPUs."
12text dt_e_hd "Grace Blackwell GB10 Topology"
13
14text dt_p_les "/tmp/note_lesson.md"
15text dt_c_les "# Lesson: Guard Bounds Before Load\nNever index without checking length."
16text dt_e_les "Guard Bounds Before Load"
17
18text dt_p_bl "/tmp/note_bullet.md"
19text dt_c_bl "- Finding: SQLite WAL checkpoint stalls under massive bulk insert\n- Solution: Run PRAGMA wal_checkpoint(TRUNCATE)"
20text dt_e_bl "SQLite WAL checkpoint stalls under massive bulk insert"
21
22text dt_p_rw "/tmp/parked-hotfix-123.md"
23text dt_c_rw "Fixed zero-length embedding cosine calculation crash."
24text dt_e_rw "parked-parked-hotfix-123"
25
26text dt_p_mf "/tmp/malformed.md"
27text dt_c_mf "---\nunclosed frontmatter fence without closing delimiter\n# Actual Title Here\nValid body content that must not be discarded."
28text dt_e_mf "Actual Title Here"
29
30text dt_p_txt "/tmp/random.txt"
31text dt_p_png "/tmp/diagram.png"
32text dt_p_emp "/tmp/empty.md"
33text dt_c_emp ""
34text dt_c_ws " \n\t \n "
35text dt_c_any "non-markdown content"
36
37text dt_ok_md "PASS markdown layouts + malformed recovery (6/6)\n"
38text dt_ok_id "PASS idle thresholds (7/7)\n"
39text dt_ok_dc "PASS recency + importance decay scoring\n"
40text dt_ok_cs "PASS cosine/dot similarity + zero-vector guard\n"
41text dt_ok_cy "PASS clustering, deduplication & threshold promotion\n"
42text dt_ok_ng "PASS negative/refusal controls (9/9 refused)\n"
43text dt_all "ALL PASS spark-dream\n"
44text dt_fail "FAIL spark-dream code="
45
46fn dt_fail_ret code int to int
47dm_ob_reset
48dm_ob_str dt_fail
49dm_ob_i64 long code
50dm_ob_str td_nl
51dm_ob_flush
52ret code
53end
54
55fn test_markdown_layouts to int
56dream_reset
57
58if ne dream_ingest_markdown dt_p_fm dt_c_fm 0 0.9f64 DREAM_OK
59ret 1
60end
61if ne get dm_layout 0 DREAM_LAYOUT_FRONTMATTER
62ret 2
63end
64if ne get dm_itype 0 DREAM_TYPE_PROCEDURE
65ret 3
66end
67if ne get dm_tags 0 3
68ret 4
69end
70if not dream_name_eq 0 dt_e_fm
71ret 5
72end
73
74if ne dream_ingest_markdown dt_p_hd dt_c_hd 0 0.8f64 DREAM_OK
75ret 6
76end
77if ne get dm_layout 1 DREAM_LAYOUT_HEADING
78ret 7
79end
80if ne get dm_itype 1 DREAM_TYPE_DISCOVERY
81ret 8
82end
83if not dream_name_eq 1 dt_e_hd
84ret 9
85end
86
87if ne dream_ingest_markdown dt_p_les dt_c_les 0 0.8f64 DREAM_OK
88ret 10
89end
90if ne get dm_itype 2 DREAM_TYPE_LESSON
91ret 11
92end
93if not dream_name_eq 2 dt_e_les
94ret 12
95end
96
97if ne dream_ingest_markdown dt_p_bl dt_c_bl 0 0.7f64 DREAM_OK
98ret 13
99end
100if ne get dm_layout 3 DREAM_LAYOUT_BULLET
101ret 14
102end
103if not dream_name_eq 3 dt_e_bl
104ret 15
105end
106
107if ne dream_ingest_markdown dt_p_rw dt_c_rw 0 0.6f64 DREAM_OK
108ret 16
109end
110if ne get dm_layout 4 DREAM_LAYOUT_RAW
111ret 17
112end
113if not dream_name_eq 4 dt_e_rw
114ret 18
115end
116
117if ne dream_ingest_markdown dt_p_mf dt_c_mf 0 0.7f64 DREAM_OK
118ret 19
119end
120if ne get dm_layout 5 DREAM_LAYOUT_HEADING
121ret 20
122end
123if not dream_name_eq 5 dt_e_mf
124ret 21
125end
126
127ret 0
128end
129
130fn test_idle_thresholds to int
131if dream_is_idle 6 1200 900
132ret 30
133end
134if dream_is_idle 99 1200 900
135ret 31
136end
137if dream_is_idle 0 300 900
138ret 32
139end
140if dream_is_idle 2 899 900
141ret 33
142end
143if not dream_is_idle 0 900 900
144ret 34
145end
146if not dream_is_idle 3 1500 900
147ret 35
148end
149if not dream_is_idle 5 3600 900
150ret 36
151end
152ret 0
153end
154
155fn test_decay_scoring to int
156s0 = dream_decay_score 0.8f64 0 3600
157if gt fabs sub s0 0.8f64 0.000001f64
158ret 40
159end
160s1 = dream_decay_score 0.8f64 3600 3600
161if gt fabs sub s1 0.4f64 0.00001f64
162ret 41
163end
164s2 = dream_decay_score 0.8f64 7200 3600
165if gt fabs sub s2 0.2f64 0.00001f64
166ret 42
167end
168if not and gt s0 s1 gt s1 s2
169ret 43
170end
171ret 0
172end
173
174fn test_cosine_and_zero_guard to int
175dream_reset
176if ne dream_ingest_markdown dt_p_hd dt_c_hd 0 0.9f64 DREAM_OK
177ret 50
178end
179if ne dream_ingest_markdown dt_p_bl dt_c_bl 0 0.9f64 DREAM_OK
180ret 51
181end
182if ne dream_ingest_markdown dt_p_rw dt_c_rw 0 0.9f64 DREAM_OK
183ret 52
184end
185
186v0 = new f64 8 0.0f64
187put v0 0 1.0f64
188put v0 1 0.0f64
189v1 = new f64 8 0.0f64
190put v1 0 0.0f64
191put v1 1 1.0f64
192vz = new f64 8 0.0f64
193
194dream_set_embedding 0 view v0
195dream_set_embedding 1 view v1
196dream_set_embedding 2 view vz
197
198if gt fabs sub dream_cosine 0 0 1.0f64 0.000001f64
199ret 53
200end
201if gt fabs dream_cosine 0 1 0.000001f64
202ret 54
203end
204note Zero-length embedding cosine must cleanly return 0.0 (no NaN / crash)
205c_zero = dream_cosine 0 2
206if or ne c_zero 0.0f64 ne dream_cosine 2 2 0.0f64
207ret 55
208end
209
210note Text-derived signed feature embeddings: identical notes -> cosine ~1.0, distinct notes -> cosine < 0.85
211dream_reset
212if ne dream_ingest_markdown dt_p_fm dt_c_fm 0 0.9f64 DREAM_OK
213ret 56
214end
215if ne dream_ingest_markdown dt_p_fm dt_c_fm 60 0.8f64 DREAM_OK
216ret 57
217end
218if ne dream_ingest_markdown dt_p_bl dt_c_bl 0 0.9f64 DREAM_OK
219ret 58
220end
221if lt dream_cosine 0 1 0.9999f64
222ret 59
223end
224if ge dream_cosine 0 2 0.85f64
225ret 59
226end
227ret 0
228end
229
230fn test_clustering_and_promotion to int
231dream_reset
232note Episode 0: fresh, high importance -> score 0.90 -> COMMITTED representative
233if ne dream_ingest_markdown dt_p_fm dt_c_fm 0 0.90f64 DREAM_OK
234ret 60
235end
236note Episode 1: near-duplicate embedding of Ep 0 -> DEDUPED into Ep 0
237if ne dream_ingest_markdown dt_p_hd dt_c_hd 100 0.80f64 DREAM_OK
238ret 61
239end
240note Episode 2: orthogonal embedding, medium decayed score (0.50) -> STAGED
241if ne dream_ingest_markdown dt_p_bl dt_c_bl 3600 1.00f64 DREAM_OK
242ret 62
243end
244note Episode 3: orthogonal embedding, stale low decayed score (0.10) -> REJECTED
245if ne dream_ingest_markdown dt_p_rw dt_c_rw 10800 0.80f64 DREAM_OK
246ret 63
247end
248
249e0 = new f64 8 0.0f64
250put e0 0 1.0f64
251e1 = new f64 8 0.0f64
252put e1 0 0.98f64
253put e1 1 0.199f64
254e2 = new f64 8 0.0f64
255put e2 2 1.0f64
256e3 = new f64 8 0.0f64
257put e3 3 1.0f64
258
259dream_set_embedding 0 view e0
260dream_set_embedding 1 view e1
261dream_set_embedding 2 view e2
262dream_set_embedding 3 view e3
263
264cfg = new DreamConfig 0 0 0 true 3600 0.85f64 0.65f64 0.35f64 0.15f64
265dream_default_config edit cfg
266st = new DreamState false 0 0 0 0 0 0 0 0
267rc = dream_run_cycle view cfg edit st
268if ne rc DREAM_OK
269ret 64
270end
271if not get st ok
272ret 65
273end
274if ne get st ingested 4
275ret 66
276end
277if ne get st clusters 3
278ret 67
279end
280if ne get st deduped 1
281ret 68
282end
283if ne get st committed 1
284ret 69
285end
286if ne get st staged 1
287ret 70
288end
289if ne get st rejected 1
290ret 71
291end
292if ne get dm_status 0 DREAM_ST_COMMITTED
293ret 72
294end
295if ne get dm_status 1 DREAM_ST_DEDUPED
296ret 73
297end
298if ne get dm_rep 1 0
299ret 74
300end
301if ne get dm_csize 0 2
302ret 75
303end
304if ne get dm_status 2 DREAM_ST_STAGED
305ret 76
306end
307if ne get dm_status 3 DREAM_ST_REJECTED
308ret 77
309end
310ret 0
311end
312
313fn test_negative_refusals to int
314dream_reset
315
316note 1. Reject non-markdown .txt
317if ne dream_ingest_markdown dt_p_txt dt_c_any 0 0.8f64 DREAM_ERR_NON_MD
318ret 80
319end
320note 2. Reject non-markdown .png
321if ne dream_ingest_markdown dt_p_png dt_c_any 0 0.8f64 DREAM_ERR_NON_MD
322ret 81
323end
324note 3. Reject empty .md
325if ne dream_ingest_markdown dt_p_emp part dt_c_emp 0 0 0 0.8f64 DREAM_ERR_EMPTY
326ret 82
327end
328note 4. Reject whitespace-only .md
329if ne dream_ingest_markdown dt_p_emp dt_c_ws 0 0.8f64 DREAM_ERR_EMPTY
330ret 83
331end
332note 5. Reject out-of-range importance (> 1.0 and < 0.0)
333if ne dream_ingest_markdown dt_p_hd dt_c_hd 0 1.2f64 DREAM_ERR_BAD_IMP
334ret 84
335end
336if ne dream_ingest_markdown dt_p_hd dt_c_hd 0 -0.1f64 DREAM_ERR_BAD_IMP
337ret 85
338end
339
340note 6. Refuse cycle when GPU is busy (> 5%)
341cfg = new DreamConfig 0 0 0 true 3600 0.85f64 0.65f64 0.35f64 0.15f64
342dream_default_config edit cfg
343put cfg gpu_util 42
344st = new DreamState false 0 0 0 0 0 0 0 0
345if ne dream_run_cycle view cfg edit st DREAM_ERR_NOT_IDLE
346ret 86
347end
348
349note 7. Refuse cycle when operator active (< idle_thresh)
350dream_default_config edit cfg
351put cfg idle_secs 300
352if ne dream_run_cycle view cfg edit st DREAM_ERR_NOT_IDLE
353ret 87
354end
355
356note 8. Refuse invalid stage_thr > commit_thr
357dream_default_config edit cfg
358put cfg stage_thr 0.80f64
359put cfg commit_thr 0.60f64
360if ne dream_run_cycle view cfg edit st DREAM_ERR_BAD_CONFIG
361ret 88
362end
363
364note 9. Refuse zero half_life
365dream_default_config edit cfg
366put cfg half_life 0
367if ne dream_run_cycle view cfg edit st DREAM_ERR_BAD_CONFIG
368ret 89
369end
370
371ret 0
372end
373
374fn main to int
375c1 = test_markdown_layouts
376if ne c1 0
377ret dt_fail_ret c1
378end
379dm_ob_reset
380dm_ob_str dt_ok_md
381dm_ob_flush
382
383c2 = test_idle_thresholds
384if ne c2 0
385ret dt_fail_ret c2
386end
387dm_ob_reset
388dm_ob_str dt_ok_id
389dm_ob_flush
390
391c3 = test_decay_scoring
392if ne c3 0
393ret dt_fail_ret c3
394end
395dm_ob_reset
396dm_ob_str dt_ok_dc
397dm_ob_flush
398
399c4 = test_cosine_and_zero_guard
400if ne c4 0
401ret dt_fail_ret c4
402end
403dm_ob_reset
404dm_ob_str dt_ok_cs
405dm_ob_flush
406
407c5 = test_clustering_and_promotion
408if ne c5 0
409ret dt_fail_ret c5
410end
411dm_ob_reset
412dm_ob_str dt_ok_cy
413dm_ob_flush
414
415c6 = test_negative_refusals
416if ne c6 0
417ret dt_fail_ret c6
418end
419dm_ob_reset
420dm_ob_str dt_ok_ng
421dm_ob_str dt_all
422dm_ob_flush
423ret 0
424end