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 / apps / omega-projects / test.om
| 1 | note omega-projects unit tests: positive cases and negative/refusal controls. |
| 2 | note Compose: si/directives/om2.om + apps/omega-projects/lib.om + apps/omega-projects/test.om |
| 3 | |
| 4 | text op_ts_pass "PASS " |
| 5 | text op_ts_fail "FAIL " |
| 6 | text op_ts_nl "\n" |
| 7 | text op_ts_summary_ok "SUMMARY omega-projects PASS all=10 fail=0\n" |
| 8 | text op_ts_summary_bad "SUMMARY omega-projects FAIL\n" |
| 9 | |
| 10 | text op_tn_1 "valid_slugs" |
| 11 | text op_tn_2 "refuse_bad_slugs" |
| 12 | text op_tn_3 "valid_and_bad_handles" |
| 13 | text op_tn_4 "valid_and_bad_paths" |
| 14 | text op_tn_5 "secret_and_external_checks" |
| 15 | text op_tn_6 "tsv_parse_valid" |
| 16 | text op_tn_7 "tsv_parse_refusals" |
| 17 | text op_tn_8 "html_escape_xss" |
| 18 | text op_tn_9 "html_escape_refuse_ctrl" |
| 19 | text op_tn_10 "emit_card_and_refuse_invalid" |
| 20 | |
| 21 | text op_v_s1 "a" |
| 22 | text op_v_s2 "hello-world-2026" |
| 23 | text op_v_s3 "a12345678901234567890123456789012345678z" |
| 24 | text op_b_s1 "" |
| 25 | text op_b_s2 "a1234567890123456789012345678901234567890" |
| 26 | text op_b_s3 "../etc/passwd" |
| 27 | text op_b_s4 "a/b" |
| 28 | text op_b_s5 "-leading" |
| 29 | text op_b_s6 "trailing-" |
| 30 | text op_b_s7 "UpperCase" |
| 31 | text op_b_s8 "xss<script>" |
| 32 | |
| 33 | text op_v_h1 "alice-01234567" |
| 34 | text op_v_h2 "anon-0123456789" |
| 35 | text op_v_h3 "dev-box-deadbeef" |
| 36 | text op_b_h1 "Alice-01234567" |
| 37 | text op_b_h2 "bad--dash-01234567" |
| 38 | text op_b_h3 "anon-012345678g" |
| 39 | text op_b_h4 "../evil-01234567" |
| 40 | |
| 41 | text op_v_p1 "projects/alice-01234567/hello-world/index.html" |
| 42 | text op_v_p2 "projects/anon-0123456789/calc/main.om" |
| 43 | text op_b_p1 "projects/alice-01234567/../secret/index.html" |
| 44 | text op_b_p2 "projects/alice-01234567/calc/sub/main.om" |
| 45 | text op_b_p3 "projects/alice-01234567/calc/evil.exe" |
| 46 | text op_b_p4 "other/alice-01234567/calc/index.html" |
| 47 | |
| 48 | text op_sec_bad1 "token ghp_123456789012345678901234" |
| 49 | text op_sec_bad2 "key sk-abc1234567890123456789" |
| 50 | text op_sec_clean "pure omega calculator app" |
| 51 | text op_ext_bad1 "<script src=\"https://evil.example/x.js\"></script>" |
| 52 | text op_ext_bad2 "fetch('/api')" |
| 53 | text op_ext_clean "<h1>Local App</h1><p>No external calls.</p>" |
| 54 | |
| 55 | text op_tsv_ok "alice-01234567\tprime-calc\tPrime & <Fast>\tComputes \"primes\" 'fast'\t2026-11-18\n" |
| 56 | text op_tsv_bad_cols "alice-01234567\tprime-calc\tonly-three\n" |
| 57 | text op_tsv_bad_handle "BAD-01234567\tprime-calc\tTitle\tDesc\t2026-11-18\n" |
| 58 | text op_tsv_bad_slug "alice-01234567\t../escape\tTitle\tDesc\t2026-11-18\n" |
| 59 | text op_tsv_secret "alice-01234567\tprime-calc\tTitle\tghp_secretvalue1234567890\t2026-11-18\n" |
| 60 | |
| 61 | text op_xss_in "<script>alert(\"x\"&'y')</script>" |
| 62 | text op_xss_exp "<script>alert("x"&'y')</script>" |
| 63 | text op_card_exp "<li class=\"project-card\" data-handle=\"alice-01234567\" data-slug=\"prime-calc\"><a href=\"projects/alice-01234567/prime-calc/\"><strong>Prime & <Fast></strong></a> <span class=\"meta\">by alice-01234567 (2026-11-18)</span><p>Computes "primes" 'fast'</p></li>\n" |
| 64 | |
| 65 | fn op_t_print s view uchar * to void |
| 66 | k = write 1 s 0 len s |
| 67 | if lt k 0 |
| 68 | exit 2 |
| 69 | end |
| 70 | end |
| 71 | |
| 72 | fn op_t_report name view uchar * ok bool to int |
| 73 | if ok |
| 74 | op_t_print op_ts_pass |
| 75 | op_t_print name |
| 76 | op_t_print op_ts_nl |
| 77 | ret 0 |
| 78 | end |
| 79 | op_t_print op_ts_fail |
| 80 | op_t_print name |
| 81 | op_t_print op_ts_nl |
| 82 | ret 1 |
| 83 | end |
| 84 | |
| 85 | fn op_test_valid_slugs to bool |
| 86 | if not op_valid_slug op_v_s1 0 len op_v_s1 |
| 87 | ret false |
| 88 | end |
| 89 | if not op_valid_slug op_v_s2 0 len op_v_s2 |
| 90 | ret false |
| 91 | end |
| 92 | if not op_valid_slug op_v_s3 0 len op_v_s3 |
| 93 | ret false |
| 94 | end |
| 95 | ret true |
| 96 | end |
| 97 | |
| 98 | fn op_test_bad_slugs to bool |
| 99 | if op_valid_slug part op_b_s1 0 0 0 0 |
| 100 | ret false |
| 101 | end |
| 102 | if op_valid_slug op_b_s2 0 len op_b_s2 |
| 103 | ret false |
| 104 | end |
| 105 | if op_valid_slug op_b_s3 0 len op_b_s3 |
| 106 | ret false |
| 107 | end |
| 108 | if op_valid_slug op_b_s4 0 len op_b_s4 |
| 109 | ret false |
| 110 | end |
| 111 | if op_valid_slug op_b_s5 0 len op_b_s5 |
| 112 | ret false |
| 113 | end |
| 114 | if op_valid_slug op_b_s6 0 len op_b_s6 |
| 115 | ret false |
| 116 | end |
| 117 | if op_valid_slug op_b_s7 0 len op_b_s7 |
| 118 | ret false |
| 119 | end |
| 120 | if op_valid_slug op_b_s8 0 len op_b_s8 |
| 121 | ret false |
| 122 | end |
| 123 | nul_slug = new uchar 4 97 |
| 124 | put nul_slug 2 uchar 0 |
| 125 | if op_valid_slug nul_slug 0 4 |
| 126 | ret false |
| 127 | end |
| 128 | ret true |
| 129 | end |
| 130 | |
| 131 | fn op_test_handles to bool |
| 132 | if not op_valid_handle op_v_h1 0 len op_v_h1 |
| 133 | ret false |
| 134 | end |
| 135 | if not op_valid_handle op_v_h2 0 len op_v_h2 |
| 136 | ret false |
| 137 | end |
| 138 | if not op_valid_handle op_v_h3 0 len op_v_h3 |
| 139 | ret false |
| 140 | end |
| 141 | if op_valid_handle op_b_h1 0 len op_b_h1 |
| 142 | ret false |
| 143 | end |
| 144 | if op_valid_handle op_b_h2 0 len op_b_h2 |
| 145 | ret false |
| 146 | end |
| 147 | if op_valid_handle op_b_h3 0 len op_b_h3 |
| 148 | ret false |
| 149 | end |
| 150 | if op_valid_handle op_b_h4 0 len op_b_h4 |
| 151 | ret false |
| 152 | end |
| 153 | ret true |
| 154 | end |
| 155 | |
| 156 | fn op_test_paths to bool |
| 157 | if not op_valid_project_path op_v_p1 0 len op_v_p1 |
| 158 | ret false |
| 159 | end |
| 160 | if not op_valid_project_path op_v_p2 0 len op_v_p2 |
| 161 | ret false |
| 162 | end |
| 163 | if op_valid_project_path op_b_p1 0 len op_b_p1 |
| 164 | ret false |
| 165 | end |
| 166 | if op_valid_project_path op_b_p2 0 len op_b_p2 |
| 167 | ret false |
| 168 | end |
| 169 | if op_valid_project_path op_b_p3 0 len op_b_p3 |
| 170 | ret false |
| 171 | end |
| 172 | if op_valid_project_path op_b_p4 0 len op_b_p4 |
| 173 | ret false |
| 174 | end |
| 175 | ret true |
| 176 | end |
| 177 | |
| 178 | fn op_test_sec_ext to bool |
| 179 | if not op_has_secret op_sec_bad1 0 len op_sec_bad1 |
| 180 | ret false |
| 181 | end |
| 182 | if not op_has_secret op_sec_bad2 0 len op_sec_bad2 |
| 183 | ret false |
| 184 | end |
| 185 | if op_has_secret op_sec_clean 0 len op_sec_clean |
| 186 | ret false |
| 187 | end |
| 188 | if not op_has_external_web op_ext_bad1 0 len op_ext_bad1 |
| 189 | ret false |
| 190 | end |
| 191 | if not op_has_external_web op_ext_bad2 0 len op_ext_bad2 |
| 192 | ret false |
| 193 | end |
| 194 | if op_has_external_web op_ext_clean 0 len op_ext_clean |
| 195 | ret false |
| 196 | end |
| 197 | ret true |
| 198 | end |
| 199 | |
| 200 | fn op_test_tsv_valid to bool |
| 201 | meta = new OpMeta 0 0 0 0 0 0 0 0 0 0 0 |
| 202 | rc = op_parse_tsv_line op_tsv_ok 0 len op_tsv_ok meta |
| 203 | if ne rc 0 |
| 204 | ret false |
| 205 | end |
| 206 | if ne get meta valid ulong 1 |
| 207 | ret false |
| 208 | end |
| 209 | if ne get meta h_len ulong 14 |
| 210 | ret false |
| 211 | end |
| 212 | if ne get meta s_len ulong 10 |
| 213 | ret false |
| 214 | end |
| 215 | ret true |
| 216 | end |
| 217 | |
| 218 | fn op_test_tsv_refusals to bool |
| 219 | meta = new OpMeta 0 0 0 0 0 0 0 0 0 0 0 |
| 220 | if ne op_parse_tsv_line op_tsv_bad_cols 0 len op_tsv_bad_cols meta -1 |
| 221 | ret false |
| 222 | end |
| 223 | if ne op_parse_tsv_line op_tsv_bad_handle 0 len op_tsv_bad_handle meta -2 |
| 224 | ret false |
| 225 | end |
| 226 | if ne op_parse_tsv_line op_tsv_bad_slug 0 len op_tsv_bad_slug meta -3 |
| 227 | ret false |
| 228 | end |
| 229 | if ne op_parse_tsv_line op_tsv_secret 0 len op_tsv_secret meta -7 |
| 230 | ret false |
| 231 | end |
| 232 | ret true |
| 233 | end |
| 234 | |
| 235 | fn op_test_html_escape to bool |
| 236 | dst = new uchar 256 0 |
| 237 | n = op_escape_html dst 0 op_xss_in |
| 238 | if lt n 0 |
| 239 | ret false |
| 240 | end |
| 241 | ret op_slice_eq dst 0 ulong n op_xss_exp |
| 242 | end |
| 243 | |
| 244 | fn op_test_escape_ctrl to bool |
| 245 | bad = new uchar 4 65 |
| 246 | put bad 1 uchar 7 |
| 247 | dst = new uchar 32 0 |
| 248 | n = op_escape_html dst 0 bad |
| 249 | if ne n -2 |
| 250 | ret false |
| 251 | end |
| 252 | small = new uchar 4 0 |
| 253 | ov = op_escape_html small 0 op_xss_in |
| 254 | if ne ov -1 |
| 255 | ret false |
| 256 | end |
| 257 | ret true |
| 258 | end |
| 259 | |
| 260 | fn op_test_emit_card to bool |
| 261 | meta = new OpMeta 0 0 0 0 0 0 0 0 0 0 0 |
| 262 | rc = op_parse_tsv_line op_tsv_ok 0 len op_tsv_ok meta |
| 263 | if ne rc 0 |
| 264 | ret false |
| 265 | end |
| 266 | dst = new uchar 1024 0 |
| 267 | n = op_emit_card dst 0 op_tsv_ok meta |
| 268 | if lt n 0 |
| 269 | ret false |
| 270 | end |
| 271 | if not op_slice_eq dst 0 ulong n op_card_exp |
| 272 | ret false |
| 273 | end |
| 274 | note Negative control: mutate slug to invalid path and confirm op_emit_card refuses it. |
| 275 | bad_meta = new OpMeta 0 0 0 0 0 0 0 0 0 0 0 |
| 276 | put bad_meta h_off ulong 0 |
| 277 | put bad_meta h_len ulong 14 |
| 278 | put bad_meta s_off ulong 0 |
| 279 | put bad_meta s_len ulong 13 |
| 280 | put bad_meta valid ulong 1 |
| 281 | r2 = op_emit_card dst 0 op_b_s3 bad_meta |
| 282 | if ge r2 0 |
| 283 | ret false |
| 284 | end |
| 285 | ret true |
| 286 | end |
| 287 | |
| 288 | fn main to int |
| 289 | fails = int 0 |
| 290 | fails = add fails op_t_report op_tn_1 op_test_valid_slugs |
| 291 | fails = add fails op_t_report op_tn_2 op_test_bad_slugs |
| 292 | fails = add fails op_t_report op_tn_3 op_test_handles |
| 293 | fails = add fails op_t_report op_tn_4 op_test_paths |
| 294 | fails = add fails op_t_report op_tn_5 op_test_sec_ext |
| 295 | fails = add fails op_t_report op_tn_6 op_test_tsv_valid |
| 296 | fails = add fails op_t_report op_tn_7 op_test_tsv_refusals |
| 297 | fails = add fails op_t_report op_tn_8 op_test_html_escape |
| 298 | fails = add fails op_t_report op_tn_9 op_test_escape_ctrl |
| 299 | fails = add fails op_t_report op_tn_10 op_test_emit_card |
| 300 | if eq fails 0 |
| 301 | op_t_print op_ts_summary_ok |
| 302 | ret 0 |
| 303 | end |
| 304 | op_t_print op_ts_summary_bad |
| 305 | ret 1 |
| 306 | end |