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