Skip to content

Commit d3e25c3

Browse files
errors +49 to 976 patterns; tests +22 workflow extras
Errors round 4 — fills remaining niches: cli: --test/--check/--bench/--fmt argument requirements, Unknown flag, install package not found, file read failure match: no arm matched, type tag mismatch, invalid range heal: heal_pass rewrites, heal budget exceeded VM: unknown opcode, stack underflow/overflow JIT: lowering failed, dispatch boundary L1.6 tokenizer: malformed ID 0, escape bug substrate: out of range, resonance type mismatch, HBit malformed safe: safe_divide / safe_arr_get / safe_arr_set Singularity returns closures: capture missing, shared state, recursive type, frame leak imports: module export shadow, symbol redefinition, reverse-FFI not registered test_runner: state outside test fn, assertion failed format reentrancy: builtin / dict / array reentrancy during iteration Tests +22 (test_workflow_extras.omc): 9 cheatsheet topic tests (arrays / dicts / strings / math / io / regex / python / code_intel / introspection) 4 change_report cases (unchanged / added / removed / action msg) 2 omc_id properties (different code → different, format check) 3 bootstrap_pack content checks (substrate / Python / attractor) 2 builtin_index format checks 2 python_translation content checks Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 8b67ea0 commit d3e25c3

2 files changed

Lines changed: 179 additions & 0 deletions

File tree

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# More workflow / introspection tests.
2+
3+
fn assert_eq(actual, expected, msg) {
4+
if actual != expected {
5+
test_record_failure(msg + ": expected " + to_string(expected) + " got " + to_string(actual));
6+
}
7+
}
8+
9+
fn assert_true(cond, msg) { if !cond { test_record_failure(msg); } }
10+
11+
# Cheatsheets across multiple topics
12+
fn test_cheatsheet_arrays() {
13+
h s = omc_cheatsheet("arrays");
14+
assert_true(str_len(s) > 100, "arrays cheatsheet substantive");
15+
}
16+
17+
fn test_cheatsheet_dicts() {
18+
h s = omc_cheatsheet("dicts");
19+
assert_true(str_len(s) > 100, "dicts cheatsheet substantive");
20+
}
21+
22+
fn test_cheatsheet_strings() {
23+
h s = omc_cheatsheet("strings");
24+
assert_true(str_len(s) > 100, "strings cheatsheet substantive");
25+
}
26+
27+
fn test_cheatsheet_math() {
28+
h s = omc_cheatsheet("math");
29+
assert_true(str_len(s) > 100, "math cheatsheet");
30+
}
31+
32+
fn test_cheatsheet_io() {
33+
h s = omc_cheatsheet("io");
34+
assert_true(str_len(s) > 50, "io cheatsheet");
35+
}
36+
37+
fn test_cheatsheet_regex() {
38+
h s = omc_cheatsheet("regex");
39+
assert_true(str_len(s) > 50, "regex cheatsheet");
40+
}
41+
42+
fn test_cheatsheet_python() {
43+
h s = omc_cheatsheet("python");
44+
assert_true(str_len(s) > 50, "python cheatsheet");
45+
}
46+
47+
fn test_cheatsheet_code_intel() {
48+
h s = omc_cheatsheet("code_intel");
49+
assert_true(str_len(s) > 100, "code_intel cheatsheet");
50+
}
51+
52+
fn test_cheatsheet_introspection() {
53+
h s = omc_cheatsheet("introspection");
54+
assert_true(str_len(s) > 100, "introspection cheatsheet");
55+
}
56+
57+
# omc_change_report content
58+
fn test_change_report_unchanged() {
59+
h r = omc_change_report("fn f(x) { return x; }", "fn f(x) { return x; }");
60+
h unchanged = dict_get(r, "unchanged");
61+
assert_true(re_match("f", unchanged) == 1, "f unchanged");
62+
}
63+
64+
fn test_change_report_added() {
65+
h r = omc_change_report("fn f() {}", "fn f() {} fn g() {}");
66+
h added = dict_get(r, "added");
67+
assert_true(re_match("g", added) == 1, "g added");
68+
}
69+
70+
fn test_change_report_removed() {
71+
h r = omc_change_report("fn f() {} fn g() {}", "fn f() {}");
72+
h removed = dict_get(r, "removed");
73+
assert_true(re_match("g", removed) == 1, "g removed");
74+
}
75+
76+
fn test_change_report_action_modified() {
77+
h r = omc_change_report("fn f() { return 1; }", "fn f() { return 2; }");
78+
h action = dict_get(r, "suggested_action");
79+
assert_true(re_match("Modified", action) == 1, "modified suggestion");
80+
}
81+
82+
# omc_id properties
83+
fn test_omc_id_different_for_different_code() {
84+
h a = omc_id("fn a() {}");
85+
h b = omc_id("fn b() {}");
86+
assert_true(a != b, "different fn names → different ids");
87+
}
88+
89+
fn test_omc_id_format_check() {
90+
h a = omc_id("h x = 1;");
91+
assert_true(re_match("^omcid-[0-9]+-[a-f0-9]+$", a) == 1, "format matches");
92+
}
93+
94+
# Bootstrap content
95+
fn test_bootstrap_has_substrate() {
96+
h s = omc_bootstrap_pack();
97+
assert_true(re_match("substrate", s) == 1, "mentions substrate");
98+
}
99+
100+
fn test_bootstrap_has_python() {
101+
h s = omc_bootstrap_pack();
102+
assert_true(re_match("Python", s) == 1, "mentions Python");
103+
}
104+
105+
fn test_bootstrap_has_attractor() {
106+
h s = omc_bootstrap_pack();
107+
assert_true(re_match("attractor", s) == 1, "mentions attractor");
108+
}
109+
110+
# Builtin index format
111+
fn test_builtin_index_has_arrays() {
112+
h s = omc_builtin_index_markdown();
113+
assert_true(re_match("## arrays", s) == 1, "arrays section");
114+
}
115+
116+
fn test_builtin_index_has_substrate() {
117+
h s = omc_builtin_index_markdown();
118+
assert_true(re_match("## substrate", s) == 1, "substrate section");
119+
}
120+
121+
# Python translation table
122+
fn test_translation_has_numpy_dot() {
123+
h s = omc_python_translation();
124+
assert_true(re_match("numpy.dot", s) == 1, "numpy.dot row");
125+
}
126+
127+
fn test_translation_has_torch_backward() {
128+
h s = omc_python_translation();
129+
assert_true(re_match("backward", s) == 1, "torch backward row");
130+
}

omnimcode-core/src/errors.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,55 @@ pub const ERROR_PATTERNS: &[ErrorPattern] = &[
12381238
ErrorPattern { pattern: "arr_get: bound check", category: "runtime", explanation: "`arr_get` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
12391239
ErrorPattern { pattern: "str_slice: bound check", category: "runtime", explanation: "`str_slice` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
12401240
ErrorPattern { pattern: "arr_slice: bound check", category: "runtime", explanation: "`arr_slice` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
1241+
ErrorPattern { pattern: "Unknown flag:", category: "cli", explanation: "Command-line flag not recognised.", typical_cause: "Typo or feature removed.", fix: "Run `omc --help` for valid flags." },
1242+
ErrorPattern { pattern: "--test requires", category: "cli", explanation: "--test mode needs a file argument.", typical_cause: "Forgot the path.", fix: "Run as `omc --test path/to/file.omc`." },
1243+
ErrorPattern { pattern: "--check requires", category: "cli", explanation: "--check mode needs a file argument.", typical_cause: "Forgot the path.", fix: "Run as `omc --check path/to/file.omc`." },
1244+
ErrorPattern { pattern: "--bench requires", category: "cli", explanation: "--bench mode needs a file argument.", typical_cause: "Forgot the path.", fix: "Run as `omc --bench path/to/file.omc`." },
1245+
ErrorPattern { pattern: "--fmt requires", category: "cli", explanation: "--fmt mode needs a file argument.", typical_cause: "Forgot the path.", fix: "Run as `omc --fmt path/to/file.omc`." },
1246+
ErrorPattern { pattern: "Failed to read file", category: "io", explanation: "Couldn't open / read the source file.", typical_cause: "Path wrong or perms.", fix: "Check the path and read permissions." },
1247+
ErrorPattern { pattern: "install: unknown package", category: "cli", explanation: "Package not found in any registry.", typical_cause: "Typo or removed.", fix: "Run `omc --list` to see installed packages." },
1248+
ErrorPattern { pattern: "Match: no arm matched", category: "runtime", explanation: "No match arm fired and no default.", typical_cause: "Missing wildcard.", fix: "Add `_ => ...` last." },
1249+
ErrorPattern { pattern: "Match: type tag", category: "types", explanation: "Type-tag pattern doesn't match value's runtime type.", typical_cause: "Wrong tag in arm.", fix: "Check type_of(value); valid tags: int, float, string, bool, array, dict, function, null." },
1250+
ErrorPattern { pattern: "Pattern: invalid range", category: "parser", explanation: "Range pattern lo..hi with lo > hi.", typical_cause: "Swapped bounds.", fix: "Ensure lo <= hi." },
1251+
ErrorPattern { pattern: "heal_pass: ", category: "runtime", explanation: "Self-healing pass made a rewrite.", typical_cause: "Source had a fixable issue.", fix: "Inspect what was healed; if undesirable, add @no_heal pragma." },
1252+
ErrorPattern { pattern: "heal budget exceeded", category: "runtime", explanation: "Too many heal-pass rewrites in one program.", typical_cause: "Source is significantly malformed.", fix: "Fix manually; budget is a safety cap." },
1253+
ErrorPattern { pattern: "VM: unknown opcode", category: "runtime", explanation: "Bytecode contains an opcode the VM doesn't recognise.", typical_cause: "Stale bytecode after VM update.", fix: "Recompile from source." },
1254+
ErrorPattern { pattern: "VM: stack underflow", category: "runtime", explanation: "Pop on empty stack.", typical_cause: "Bytecode bug.", fix: "Recompile from source; file issue if persists." },
1255+
ErrorPattern { pattern: "VM: stack overflow", category: "runtime", explanation: "Operand stack exceeded budget.", typical_cause: "Pathological code.", fix: "Refactor to use fewer intermediates." },
1256+
ErrorPattern { pattern: "JIT: lowering failed", category: "runtime", explanation: "Codegen couldn't lower this function.", typical_cause: "Unsupported op or shape.", fix: "Fall back to tree-walk; file issue with the failing fn." },
1257+
ErrorPattern { pattern: "JIT: dispatch boundary", category: "runtime", explanation: "Crossing tree-walk ↔ JIT boundary with incompatible type.", typical_cause: "Array-from-JIT not bridged yet (L1.6 pending).", fix: "Stay tree-walk for now, or restructure to scalar-only ops." },
1258+
ErrorPattern { pattern: "Tokenizer: ID 0", category: "tokenizer", explanation: "Stream contains an unescaped ID 0 — encoder bug.", typical_cause: "Manual ID array.", fix: "Use omc_token_encode to produce streams." },
1259+
ErrorPattern { pattern: "Tokenizer: malformed escape", category: "tokenizer", explanation: "Escape byte missing after ID 0.", typical_cause: "Truncated stream.", fix: "Verify the encoded array is intact." },
1260+
ErrorPattern { pattern: "Substrate: out of range", category: "substrate", explanation: "Value past supported attractor table extent.", typical_cause: "n > 6.3e7.", fix: "Mod-reduce or use HInt::new which extends supported range." },
1261+
ErrorPattern { pattern: "Resonance: invalid input", category: "substrate", explanation: "Resonance call expected numeric.", typical_cause: "Passed array/string.", fix: "Use arr_resonance_vec for arrays." },
1262+
ErrorPattern { pattern: "HBit: malformed dual", category: "substrate", explanation: "Dual-band representation has wrong arity.", typical_cause: "Manual construction.", fix: "Use hbit_dual to build." },
1263+
ErrorPattern { pattern: "safe_divide", category: "runtime", explanation: "Safe-divide produced Singularity result.", typical_cause: "Division by zero in `safe` context.", fix: "is_singularity check on result." },
1264+
ErrorPattern { pattern: "safe_arr_get", category: "runtime", explanation: "Safe array-get returned a Singularity.", typical_cause: "Out-of-bounds index in `safe` context.", fix: "is_singularity check on result." },
1265+
ErrorPattern { pattern: "safe_arr_set", category: "runtime", explanation: "Safe array-set was a no-op.", typical_cause: "Out-of-bounds index in `safe` context.", fix: "is_singularity check or pre-grow." },
1266+
ErrorPattern { pattern: "Lambda capture missing", category: "runtime", explanation: "Lambda referenced an unbound name from outer scope.", typical_cause: "Variable doesn't exist when lambda is defined.", fix: "Define the variable first." },
1267+
ErrorPattern { pattern: "Closure shared state", category: "runtime", explanation: "Two sibling lambdas mutating shared state observe each other.", typical_cause: "Capture-by-reference semantics.", fix: "Use distinct closures or use immutable values." },
1268+
ErrorPattern { pattern: "Recursive type", category: "runtime", explanation: "Self-referential structure detected.", typical_cause: "Class field references its own class.", fix: "Avoid cycles or use dict-based representation." },
1269+
ErrorPattern { pattern: "Stack frame leak", category: "runtime", explanation: "Frame not released across calls.", typical_cause: "Wrong scope management.", fix: "File an issue; should be impossible from user code." },
1270+
ErrorPattern { pattern: "Symbol redefinition", category: "runtime", explanation: "Same name registered twice as host_builtin.", typical_cause: "Embedder called register_builtin twice.", fix: "De-register first or use a different name." },
1271+
ErrorPattern { pattern: "Reverse-FFI not initialized", category: "runtime", explanation: "Calling a name that's neither user-defined nor a builtin.", typical_cause: "Expected a host_builtin registration.", fix: "Register the function before calling it from OMC." },
1272+
ErrorPattern { pattern: "Module export shadowed", category: "imports", explanation: "Module exports a name that shadows a builtin.", typical_cause: "Module author chose conflicting name.", fix: "Rename in the module or use a prefix import." },
1273+
ErrorPattern { pattern: "Test runner state", category: "test_runner", explanation: "Test runner can't record failure outside a test function.", typical_cause: "Called assert outside test_*.", fix: "Wrap in fn test_xxx() {}." },
1274+
ErrorPattern { pattern: "Reentrancy", category: "runtime", explanation: "Builtin re-entered itself.", typical_cause: "Cycle through host or callback.", fix: "Break the cycle." },
1275+
ErrorPattern { pattern: "Reentrancy: dict", category: "runtime", explanation: "Dict mutation during iteration.", typical_cause: "Inserting into dict you're iterating.", fix: "Collect keys first, then mutate." },
1276+
ErrorPattern { pattern: "Reentrancy: array", category: "runtime", explanation: "Array mutation during iteration.", typical_cause: "Inserting into array you're iterating.", fix: "Use slice/copy first." },
1277+
ErrorPattern { pattern: "expected", category: "test_runner", explanation: "Test assertion failed — actual didn't match expected.", typical_cause: "Bug in code under test or in test.", fix: "Re-read the assertion's labeled message; print actual/expected for inspection." },
1278+
ErrorPattern { pattern: "test_record_failure called outside test", category: "test_runner", explanation: "Manual failure recording without test context.", typical_cause: "Forgot test_set_current().", fix: "Call inside a test_* function, or set name first." },
1279+
ErrorPattern { pattern: "str_", category: "core", explanation: "Error originating from str_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"str_\") for related operations." },
1280+
ErrorPattern { pattern: "arr_", category: "core", explanation: "Error originating from arr_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"arr_\") for related operations." },
1281+
ErrorPattern { pattern: "dict_", category: "core", explanation: "Error originating from dict_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"dict_\") for related operations." },
1282+
ErrorPattern { pattern: "tape_", category: "core", explanation: "Error originating from tape_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"tape_\") for related operations." },
1283+
ErrorPattern { pattern: "dual_", category: "core", explanation: "Error originating from dual_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"dual_\") for related operations." },
1284+
ErrorPattern { pattern: "gen_", category: "core", explanation: "Error originating from gen_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"gen_\") for related operations." },
1285+
ErrorPattern { pattern: "py_", category: "core", explanation: "Error originating from py_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"py_\") for related operations." },
1286+
ErrorPattern { pattern: "omc_", category: "core", explanation: "Error originating from omc_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"omc_\") for related operations." },
1287+
ErrorPattern { pattern: "is_", category: "core", explanation: "Error originating from is_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"is_\") for related operations." },
1288+
ErrorPattern { pattern: "hbit_", category: "core", explanation: "Error originating from hbit_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"hbit_\") for related operations." },
1289+
ErrorPattern { pattern: "harmonic_", category: "core", explanation: "Error originating from harmonic_* family.", typical_cause: "Refer to specific message for context.", fix: "Filter omc_search_builtins(\"harmonic_\") for related operations." },
12411290
];
12421291

12431292
/// Best-matching pattern for an error message. Returns None if no

0 commit comments

Comments
 (0)