Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/om/serve/test.om # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / om / serve / test.om` 465 lines ยท 12878 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note core/sovereign-core/om/serve/test.om 3 note Comprehensive behavioral test suite with negative/refusal controls for the 4 note pure-Omega HTTP inference server, constant-time bearer auth, read caps, and CLI router. 5 note Compose with: 6 note si/directives/om2.om core/sovereign-core/om/serve/http_auth.om 7 note core/sovereign-core/om/serve/router.om core/sovereign-core/om/serve/cli.om 8 note core/sovereign-core/om/serve/test.om 9 10 text t_pass "PASS " 11 text t_fail "FAIL " 12 text t_nl "\n" 13 text t_all_ok "SOVEREIGN-CORE SERVE TEST SUITE PASS\n" 14 text t_all_bad "SOVEREIGN-CORE SERVE TEST SUITE FAIL\n" 15 16 text t_n1 "auth_fail_closed_and_constant_time" 17 text t_n2 "http_parse_negative_caps_and_smuggling" 18 text t_n3 "router_health_and_models_auth" 19 text t_n4 "router_chat_completions_json_and_sse" 20 text t_n5 "router_chat_negative_auth_and_json" 21 text t_n6 "cli_dispatch_valid_and_negative" 22 text t_n7 "http_parse_transfer_encoding_and_content_length_smuggling" 23 24 text tok_good "omega_secret_bearer_token_012345" 25 text tok_short "too_short" 26 text tok_space "omega_secret bearer_token_012345" 27 text hdr_good "Bearer omega_secret_bearer_token_012345" 28 text hdr_flip "Bearer omega_secret_bearer_token_012344" 29 text hdr_basic "Basic omega_secret_bearer_token_012345" 30 text hdr_extra "Bearer omega_secret_bearer_token_012345x" 31 32 note Request fixtures use LF; t_handle_lf expands LF -> CRLF for wire HTTP/1.1. 33 text req_health_get "GET /health HTTP/1.1\nHost: localhost\n\n" 34 text req_health_post "POST /health HTTP/1.1\nHost: localhost\n\n" 35 text req_models_noauth "GET /v1/models HTTP/1.1\nHost: localhost\n\n" 36 text req_models_auth "GET /v1/models HTTP/1.1\nHost: localhost\nAuthorization: Bearer omega_secret_bearer_token_012345\n\n" 37 text req_unknown_rt "GET /v1/nonexistent HTTP/1.1\nHost: localhost\n\n" 38 text req_trav "GET /v1/../health HTTP/1.1\nHost: localhost\n\n" 39 text req_bad_method "DELETE /health HTTP/1.1\nHost: localhost\n\n" 40 text req_no_term "GET /health HTTP/1.1\nHost: localhost" 41 text req_dup_cl "POST /v1/chat/completions HTTP/1.1\nContent-Length: 2\nContent-Length: 2\n\n{}" 42 text req_dup_auth "GET /v1/models HTTP/1.1\nAuthorization: Bearer omega_secret_bearer_token_012345\nAuthorization: Bearer omega_secret_bearer_token_012345\n\n" 43 text req_cl_mismatch "POST /v1/chat/completions HTTP/1.1\nContent-Length: 10\n\n{}" 44 note Transfer-Encoding is never accepted (the body is framed by Content-Length alone): TE alone, TE with CL in 45 note either order, odd casing, tab/space padding, empty value, space before the colon; duplicate/conflicting CL. 46 text req_te_alone "GET /health HTTP/1.1\nHost: localhost\nTransfer-Encoding: chunked\n\n" 47 text req_te_alone_body "POST /v1/chat/completions HTTP/1.1\nTransfer-Encoding: chunked\n\n2\n{}\n0\n\n" 48 text req_te_cl "GET /health HTTP/1.1\nContent-Length: 0\nTransfer-Encoding: chunked\n\n" 49 text req_cl_te "GET /health HTTP/1.1\nTransfer-Encoding: chunked\nContent-Length: 0\n\n" 50 text req_te_case "GET /health HTTP/1.1\ntRANSFER-encoding: identity \n\n" 51 text req_te_tab "GET /health HTTP/1.1\nTRANSFER-ENCODING:\tgzip, chunked\t\n\n" 52 text req_te_empty "GET /health HTTP/1.1\nTransfer-Encoding:\n\n" 53 text req_te_spcolon "GET /health HTTP/1.1\nTransfer-Encoding : chunked\n\n" 54 text req_cl_spcolon "GET /health HTTP/1.1\nContent-Length : 0\n\n" 55 text req_cl_conflict "POST /v1/chat/completions HTTP/1.1\nContent-Length: 2\nContent-Length: 3\n\n{}" 56 text req_cl_dup_case "GET /health HTTP/1.1\nContent-Length: 0\ncontent-LENGTH: 0\n\n" 57 text req_cl_list "POST /v1/chat/completions HTTP/1.1\nContent-Length: 2, 2\n\n{}" 58 text req_te_lookalike "GET /health HTTP/1.1\nX-Transfer-Encoding-Note: chunked\nTransfer-Encodings: x\n\n" 59 text req_cl_huge "POST /v1/chat/completions HTTP/1.1\nContent-Length: 9999\n\n" 60 61 text req_chat_ok "POST /v1/chat/completions HTTP/1.1\nHost: localhost\nAuthorization: Bearer omega_secret_bearer_token_012345\nContent-Length: 71\n\n{\"model\":\"qwen-native-om\",\"messages\":[{\"role\":\"user\"}],\"max_tokens\":64}" 62 text req_chat_sse "POST /v1/chat/completions HTTP/1.1\nHost: localhost\nAuthorization: Bearer omega_secret_bearer_token_012345\nContent-Length: 69\n\n{\"model\":\"qwen-native-om\",\"messages\":[{\"role\":\"user\"}],\"stream\":true}" 63 text req_chat_badtok "POST /v1/chat/completions HTTP/1.1\nHost: localhost\nAuthorization: Bearer omega_secret_bearer_token_012344\nContent-Length: 55\n\n{\"model\":\"qwen-native-om\",\"messages\":[{\"role\":\"user\"}]}" 64 text req_chat_nomodel "POST /v1/chat/completions HTTP/1.1\nAuthorization: Bearer omega_secret_bearer_token_012345\nContent-Length: 30\n\n{\"messages\":[{\"role\":\"user\"}]}" 65 text req_chat_nomsgs "POST /v1/chat/completions HTTP/1.1\nAuthorization: Bearer omega_secret_bearer_token_012345\nContent-Length: 26\n\n{\"model\":\"qwen-native-om\"}" 66 text req_chat_unbal "POST /v1/chat/completions HTTP/1.1\nAuthorization: Bearer omega_secret_bearer_token_012345\nContent-Length: 25\n\n{\"model\":\"qwen-native-om\"" 67 text req_chat_badmax "POST /v1/chat/completions HTTP/1.1\nAuthorization: Bearer omega_secret_bearer_token_012345\nContent-Length: 70\n\n{\"model\":\"qwen-native-om\",\"messages\":[{\"role\":\"user\"}],\"max_tokens\":0}" 68 text req_chat_get "GET /v1/chat/completions HTTP/1.1\nAuthorization: Bearer omega_secret_bearer_token_012345\n\n" 69 70 text s_ok_engine "\"omega-sovereign-core\"" 71 text s_model_id "\"qwen-native-om\"" 72 text s_chat_obj "\"chat.completion\"" 73 text s_sse_done "data: [DONE]" 74 75 text cli_v1 "serve --port 9090 --max-tokens 1024 --model qwen-native-om" 76 text cli_v2 "chat --model qwen-native-om --max-tokens 256" 77 text cli_v3 "models" 78 text cli_v4 "health" 79 text cli_v5 "version" 80 text cli_b1 "" 81 text cli_b2 "rmrf --port 80" 82 text cli_b3 "serve --port 0" 83 text cli_b4 "serve --port 70000" 84 text cli_b5 "serve --max-tokens 0" 85 text cli_b6 "serve --max-tokens 99999" 86 text cli_b7 "chat --max-tokens 128" 87 text cli_b8 "serve --evil 1" 88 text cli_b9 "serve --port 8080 --port 8081" 89 90 global t_fails ulong 1 91 92 fn t_w s view uchar * to void 93 n = len s 94 off = ulong 0 95 while lt off n bound 256 96 k = write 1 s off sub n off 97 if le k 0 98 break 99 end 100 off = add off ulong k 101 end 102 end 103 104 fn t_report name view uchar * ok bool to void 105 if ok 106 t_w t_pass 107 else 108 t_w t_fail 109 put t_fails 0 add get t_fails 0 1 110 end 111 t_w name 112 t_w t_nl 113 end 114 115 note Expand LF -> CRLF into a local wire buffer and invoke srv_handle_http. 116 fn t_handle_lf src view uchar * to ulong 117 buf = new uchar 512 0 118 n = len src 119 w = ulong 0 120 for i ulong n bound 512 121 b = get src i 122 if eq b uchar 10 123 if lt add w 1 512 124 put buf w uchar 13 125 put buf add w 1 uchar 10 126 w = add w 2 127 end 128 else 129 if lt w 512 130 put buf w b 131 w = add w 1 132 end 133 end 134 end 135 ret srv_handle_http part buf 0 w 136 end 137 138 fn t_resp_contains needle view uchar * to bool 139 rlen = srv_resp_len 140 nlen = len needle 141 if or eq nlen 0 gt nlen rlen 142 ret false 143 end 144 lim = add sub rlen nlen 1 145 for i ulong lim bound 2048 146 ok = true 147 for j ulong nlen bound 64 148 if ne get srv_resp_buf add i j get needle j 149 ok = false 150 break 151 end 152 end 153 if ok 154 ret true 155 end 156 end 157 ret false 158 end 159 160 note Test 1: Fail-closed unconfigured auth + constant-time Bearer token checks. 161 fn test_auth to bool 162 srv_auth_reset 163 if srv_auth_is_configured 164 ret false 165 end 166 if srv_auth_verify_header hdr_good 167 ret false 168 end 169 if srv_auth_set_token tok_short 170 ret false 171 end 172 if srv_auth_set_token tok_space 173 ret false 174 end 175 if not srv_auth_set_token tok_good 176 ret false 177 end 178 if not srv_auth_verify_header hdr_good 179 ret false 180 end 181 if srv_auth_verify_header hdr_flip 182 ret false 183 end 184 if srv_auth_verify_header hdr_basic 185 ret false 186 end 187 if srv_auth_verify_header hdr_extra 188 ret false 189 end 190 if or ne srv_auth_allow_count 1 ne srv_auth_deny_count 4 191 ret false 192 end 193 ret true 194 end 195 196 note Test 2 (NEGATIVE): Read caps, header-too-large, Content-Length mismatch, smuggling, traversal. 197 fn test_http_parse_negative to bool 198 srv_auth_reset 199 ok_cfg = srv_auth_set_token tok_good 200 if not ok_cfg 201 ret false 202 end 203 if ne t_handle_lf req_trav 400 204 ret false 205 end 206 if ne t_handle_lf req_bad_method 405 207 ret false 208 end 209 if ne t_handle_lf req_no_term 400 210 ret false 211 end 212 if ne t_handle_lf req_dup_cl 400 213 ret false 214 end 215 if ne t_handle_lf req_dup_auth 400 216 ret false 217 end 218 if ne t_handle_lf req_cl_mismatch 400 219 ret false 220 end 221 if ne t_handle_lf req_cl_huge 413 222 ret false 223 end 224 note Build an oversized header block (> 1024 bytes) -> must return 431 225 big_hdr = new uchar 1200 65 226 put big_hdr 0 uchar 71 227 put big_hdr 1 uchar 69 228 put big_hdr 2 uchar 84 229 put big_hdr 3 uchar 32 230 put big_hdr 4 uchar 47 231 put big_hdr 5 uchar 32 232 put big_hdr 1196 uchar 13 233 put big_hdr 1197 uchar 10 234 put big_hdr 1198 uchar 13 235 put big_hdr 1199 uchar 10 236 if ne srv_handle_http big_hdr 431 237 ret false 238 end 239 ret true 240 end 241 242 note Test 3: /health public probe, /v1/models bearer-gated, 405 & 404. 243 fn test_router_health_models to bool 244 srv_auth_reset 245 ok_cfg = srv_auth_set_token tok_good 246 if not ok_cfg 247 ret false 248 end 249 if ne t_handle_lf req_health_get 200 250 ret false 251 end 252 if not t_resp_contains s_ok_engine 253 ret false 254 end 255 if ne t_handle_lf req_health_post 405 256 ret false 257 end 258 if ne t_handle_lf req_models_noauth 401 259 ret false 260 end 261 if ne t_handle_lf req_models_auth 200 262 ret false 263 end 264 if not t_resp_contains s_model_id 265 ret false 266 end 267 if ne t_handle_lf req_unknown_rt 404 268 ret false 269 end 270 ret true 271 end 272 273 note Test 4: /v1/chat/completions JSON and SSE streaming paths. 274 fn test_router_chat_ok to bool 275 srv_auth_reset 276 ok_cfg = srv_auth_set_token tok_good 277 if not ok_cfg 278 ret false 279 end 280 if ne t_handle_lf req_chat_ok 200 281 ret false 282 end 283 if not t_resp_contains s_chat_obj 284 ret false 285 end 286 if ne get srv_resp_meta 3 64 287 ret false 288 end 289 if ne t_handle_lf req_chat_sse 200 290 ret false 291 end 292 if not t_resp_contains s_sse_done 293 ret false 294 end 295 ret true 296 end 297 298 note Test 5 (NEGATIVE): /v1/chat/completions bad auth, malformed JSON, missing fields, bad max_tokens, wrong method. 299 fn test_router_chat_negative to bool 300 srv_auth_reset 301 ok_cfg = srv_auth_set_token tok_good 302 if not ok_cfg 303 ret false 304 end 305 if ne t_handle_lf req_chat_badtok 401 306 ret false 307 end 308 if ne t_handle_lf req_chat_nomodel 400 309 ret false 310 end 311 if ne t_handle_lf req_chat_nomsgs 400 312 ret false 313 end 314 if ne t_handle_lf req_chat_unbal 400 315 ret false 316 end 317 if ne t_handle_lf req_chat_badmax 400 318 ret false 319 end 320 if ne t_handle_lf req_chat_get 405 321 ret false 322 end 323 note Also verify fail-closed when token is unconfigured 324 srv_auth_reset 325 if ne t_handle_lf req_chat_ok 401 326 ret false 327 end 328 ret true 329 end 330 331 note Test 6: CLI dispatch valid commands and fail-closed negative flag checks. 332 fn test_cli_dispatch to bool 333 if ne cli_dispatch cli_v1 CLI_OK 334 ret false 335 end 336 if or ne cli_cmd CLI_CMD_SERVE or ne cli_port 9090 or ne cli_max_tokens 1024 ne cli_model_len 14 337 ret false 338 end 339 if ne cli_dispatch cli_v2 CLI_OK 340 ret false 341 end 342 if or ne cli_cmd CLI_CMD_CHAT ne cli_max_tokens 256 343 ret false 344 end 345 if ne cli_dispatch cli_v3 CLI_OK 346 ret false 347 end 348 if ne cli_cmd CLI_CMD_MODELS 349 ret false 350 end 351 if ne cli_dispatch cli_v4 CLI_OK 352 ret false 353 end 354 if ne cli_cmd CLI_CMD_HEALTH 355 ret false 356 end 357 if ne cli_dispatch cli_v5 CLI_OK 358 ret false 359 end 360 if ne cli_cmd CLI_CMD_VERSION 361 ret false 362 end 363 note NEGATIVE controls 364 if ne cli_dispatch part cli_b1 0 0 CLI_ERR_EMPTY 365 ret false 366 end 367 if ne cli_dispatch cli_b2 CLI_ERR_UNKNOWN_CMD 368 ret false 369 end 370 if ne cli_dispatch cli_b3 CLI_ERR_BAD_PORT 371 ret false 372 end 373 if ne cli_dispatch cli_b4 CLI_ERR_BAD_PORT 374 ret false 375 end 376 if ne cli_dispatch cli_b5 CLI_ERR_BAD_MAX_TOKENS 377 ret false 378 end 379 if ne cli_dispatch cli_b6 CLI_ERR_BAD_MAX_TOKENS 380 ret false 381 end 382 if ne cli_dispatch cli_b7 CLI_ERR_MISSING_MODEL 383 ret false 384 end 385 if ne cli_dispatch cli_b8 CLI_ERR_UNKNOWN_FLAG 386 ret false 387 end 388 if ne cli_dispatch cli_b9 CLI_ERR_DUP_FLAG 389 ret false 390 end 391 ret true 392 end 393 394 note NEGATIVE: every Transfer-Encoding shape and duplicate/conflicting Content-Length is 400. POSITIVE 395 note controls: header names that only contain or extend "transfer-encoding" still route (200), as does plain GET. 396 fn test_http_te_cl to bool 397 srv_auth_reset 398 if not srv_auth_set_token tok_good 399 ret false 400 end 401 ok = true 402 if ne t_handle_lf req_te_alone 400 403 ok = false 404 end 405 if ne t_handle_lf req_te_alone_body 400 406 ok = false 407 end 408 if ne t_handle_lf req_te_cl 400 409 ok = false 410 end 411 if ne t_handle_lf req_cl_te 400 412 ok = false 413 end 414 if ne t_handle_lf req_te_case 400 415 ok = false 416 end 417 if ne t_handle_lf req_te_tab 400 418 ok = false 419 end 420 if ne t_handle_lf req_te_empty 400 421 ok = false 422 end 423 if ne t_handle_lf req_te_spcolon 400 424 ok = false 425 end 426 if ne t_handle_lf req_cl_spcolon 400 427 ok = false 428 end 429 if ne t_handle_lf req_dup_cl 400 430 ok = false 431 end 432 if ne t_handle_lf req_cl_conflict 400 433 ok = false 434 end 435 if ne t_handle_lf req_cl_dup_case 400 436 ok = false 437 end 438 if ne t_handle_lf req_cl_list 400 439 ok = false 440 end 441 if ne t_handle_lf req_te_lookalike 200 442 ok = false 443 end 444 if ne t_handle_lf req_health_get 200 445 ok = false 446 end 447 ret ok 448 end 449 450 fn main to int 451 put t_fails 0 0 452 t_report t_n1 test_auth 453 t_report t_n2 test_http_parse_negative 454 t_report t_n3 test_router_health_models 455 t_report t_n4 test_router_chat_ok 456 t_report t_n5 test_router_chat_negative 457 t_report t_n6 test_cli_dispatch 458 t_report t_n7 test_http_te_cl 459 if eq get t_fails 0 0 460 t_w t_all_ok 461 ret 0 462 end 463 t_w t_all_bad 464 ret 1 465 end