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
GitHub aien-dev/omega-mv#392 (code only)
Apply it
git checkout -b patch-a3ad15f9341d202b 56643b03b043225393727e2f9808fdc4592153c3 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/a3ad15f9341d202b.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
392
e12a67c455cf97b825f43440344e605619dc3e83
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":392,"url":"https://github.com/aien-dev/omega-mv/pull/392","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:41Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 9af859d6c..5347bf4d4 100644 --- a/.crumb +++ b/.crumb @@ -87,14 +87,14 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "81c465bd45aafe66e9828a3b54323563dd3a72593e381f373d2d007cee28dfb2", - "last_commit": "d650a897", + "digest": "6cc8a37d1405d58a7e23506d19364e68b870a254c94c74e922cac923518c8ce8", + "last_commit": "2f93d2d0", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "fd6417d3ee731e5b90b56a4cb38020034328a6c6a746b9feea671fb3d6275f84", - "last_commit": "dbfc8aea", + "digest": "9b685c0445e3dfb80ea33118ce501b38e78296e9e09aa8e284129fa75e7759c3", + "last_commit": "2f93d2d0", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -105,15 +105,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:c26462bd24b6bd4492c419d692807426f2a4c2c48dad4f1bf3167e87e68fc1d0", - "compiled_at": "2026-10-10T08:01:55Z", + "children_root": "sha256:fcf5e929bf877830e27b401778779199ba18c15a8a9c282ece0147741731467a", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:17c76d590b0f86ced8f87099d66c4bb06e4d0fbfab63a66a0683d2969f52431e", + "digest": "sha256:d42aa2ff63fe9eb748b78efe111f14ba915ed89608dc2b59f731489481d0ffc0", "evidence_files": 6829, "evidence_root": "sha256:d430e46c9eac00396e5c58c2c8e60eb961500973312cc5eee25cf9d37e75bea2", "files": 9236, - "generated_at_commit": "dbfc8aea517bf35d71a70a5cb1371cfad051d097", - "source_tree": "sha256:8d702ff29f1c84f5611ec258175bb7a6b7f6dd18954684cf2c65c9444157dcc5" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:71880454345585ea168f82e9639edcd7491ea789b7b74b44ef07e9e5b12ebc73" }, "owner_lane": "", "provenance": { diff --git a/src/.crumb b/src/.crumb index e512f6084..4c75be2db 100644 --- a/src/.crumb +++ b/src/.crumb @@ -115,8 +115,8 @@ "purpose": "Directory src/language. Purpose not yet described by a human." }, { - "digest": "f292900401c59fe21e55b2d83f01e2dc4bc1d16b2f4a90519fe3325534c34f18", - "last_commit": "ad2deba1", + "digest": "5b7ed01407c21b01b66bb4420c3970d5be863fc025cdd8a676ff82876bad591b", + "last_commit": "2f93d2d0", "name": "osh", "purpose": "osh (Omega-native shell, arch#158) lexer unit: layout list, generator, osh_lex.osc, C reference " }, @@ -175,15 +175,15 @@ "purpose": "Directory src/visor. Purpose not yet described by a human." } ], - "children_root": "sha256:357a40230e26404bf5f877318da0b70108a5ad2721029459767f8f84fb2413b5", - "compiled_at": "2026-10-10T07:48:24Z", + "children_root": "sha256:99e5a0ca5639d0470c4efd7030f2f6d389cedb152afe767da29c4219b97c107b", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:81c465bd45aafe66e9828a3b54323563dd3a72593e381f373d2d007cee28dfb2", + "digest": "sha256:6cc8a37d1405d58a7e23506d19364e68b870a254c94c74e922cac923518c8ce8", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 445, - "generated_at_commit": "ad2deba162c8d30b31e1e829b9cd58aa5513b1fd", - "source_tree": "sha256:c9b7f02b3ca1b83de33415f110466c5eeafded672cac9f29703693604ff24e02" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:b38482563d404a2e1f4182842dac10cac43f8b9077780e079b2907f7d7b0f630" }, "owner_lane": "", "provenance": { diff --git a/src/osh/.crumb b/src/osh/.crumb index bce35eb96..43a2ba03e 100644 --- a/src/osh/.crumb +++ b/src/osh/.crumb @@ -3,21 +3,21 @@ "generated": { "children": [ { - "digest": "656126a21229ac434420f7f00f0f7133925d87f6719a704d37437a6464d3b8d1", - "last_commit": "ad2deba1", + "digest": "d057727aa808c45ef47c25b8c463fa019dec4fe8b34510e4c311687aadcc92df", + "last_commit": "2f93d2d0", "name": "host", "purpose": "osh Linux host: execution service (request decoder, resolution, builtins, redirections, pipeline" } ], - "children_root": "sha256:67270aa2cd0e85d3861f60a2b3d9665e42302d03c952e1ef029956b6c3a2a0ec", - "compiled_at": "2026-10-10T07:48:24Z", + "children_root": "sha256:dbc2cd0ef8a9f4f7a95465a7ae9dec9b2156648abb768d43d425fc3c4e775843", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:f292900401c59fe21e55b2d83f01e2dc4bc1d16b2f4a90519fe3325534c34f18", + "digest": "sha256:5b7ed01407c21b01b66bb4420c3970d5be863fc025cdd8a676ff82876bad591b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 31, - "generated_at_commit": "ad2deba162c8d30b31e1e829b9cd58aa5513b1fd", - "source_tree": "sha256:075fc4a95f2878a4356755046f293d825f999a80988d0095f77abc4cd3c07b1d" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:69e0bf997046ac181c8cc85a3ed96254229ddec91c5f1d1284e87f446b354825" } }, "name": "osh", diff --git a/src/osh/host/.crumb b/src/osh/host/.crumb index 15926fbf5..feb855ac7 100644 --- a/src/osh/host/.crumb +++ b/src/osh/host/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-10T07:48:24Z", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:656126a21229ac434420f7f00f0f7133925d87f6719a704d37437a6464d3b8d1", + "digest": "sha256:d057727aa808c45ef47c25b8c463fa019dec4fe8b34510e4c311687aadcc92df", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 16, - "generated_at_commit": "ad2deba162c8d30b31e1e829b9cd58aa5513b1fd", - "source_tree": "sha256:048a7ecae865ea459512f8f51434504cf10d2a48a4bee33fd9b6bdc78cde2977" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:ac15ceccf8b70131c6e01de81b970b50b03221431801d8445d27bd8fc01a8cd6" } }, "name": "host", diff --git a/src/osh/host/osh_builtin.c b/src/osh/host/osh_builtin.c index ef391f7f1..5772ffe6a 100644 --- a/src/osh/host/osh_builtin.c +++ b/src/osh/host/osh_builtin.c @@ -158,7 +158,7 @@ static int bi_cd(OshSession *s, const OshCmd *c, const int io[3], int in_parent) } /* A child context keeps its own copy of the table, so setting here is safe in both cases. */ (void)in_parent; - osh_var_set(s, "OLDPWD", old); + osh_var_export(s, "OLDPWD", old); /* bash exports OLDPWD */ osh_var_set(s, "PWD", cur); if (show) { char line[PATH_MAX + 1]; diff --git a/src/osh/host/osh_vars.c b/src/osh/host/osh_vars.c index c0f860f80..06617a95e 100644 --- a/src/osh/host/osh_vars.c +++ b/src/osh/host/osh_vars.c @@ -2,12 +2,16 @@ * osh_vars.c -- the shell's variable table and the fresh-per-exec environment (ABI section 4.5, 7.2, 9.1). * The environment of a child is built from this table only; the process-global environ is read once, at * osh_session_init, and never again. Names and values are raw bytes without NUL. + * Bookkeeping as bash 5.2 does it: PWD per POSIX; SHLVL = inherited level + 1 (non-numeric counts as 0, never below 0, + * above 1000 resets to 1 with a warning); OLDPWD exported, kept only when the inherited value names a directory and + * set by cd. `_` (bash's last argument) is not maintained. */ #include "osh_host.h" #include "osh_priv.h" #include <errno.h> #include <limits.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> @@ -129,9 +133,23 @@ int osh_session_init(OshSession *s, char *const *envp) } if (!pwd_names_cwd(osh_var_get(s, "PWD"))) { char cwd[PATH_MAX]; - if (getcwd(cwd, sizeof cwd) && osh_var_export(s, "PWD", cwd) == 0) return 0; - osh_session_free(s); - return -1; + if (!getcwd(cwd, sizeof cwd) || osh_var_export(s, "PWD", cwd)) { osh_session_free(s); return -1; } + } + const char *lv = osh_var_get(s, "SHLVL"); + long level = (lv ? strtol(lv, NULL, 10) : 0) + 1; /* atoi semantics: junk counts as 0 */ + if (level < 0) level = 0; + if (level >= 1000) { + osh_diag(s->fd[2], "osh: warning: shell level (%ld) too high, resetting to 1", level); + level = 1; + } + char lvbuf[24]; + snprintf(lvbuf, sizeof lvbuf, "%ld", level); + if (osh_var_export(s, "SHLVL", lvbuf)) { osh_session_free(s); return -1; } + const char *op = osh_var_get(s, "OLDPWD"); + struct stat st; + if (!op || stat(op, &st) != 0 || !S_ISDIR(st.st_mode)) { + osh_var_unset(s, "OLDPWD"); + if (osh_var_export(s, "OLDPWD", NULL)) { osh_session_free(s); return -1; } } return 0; } diff --git a/tests/.crumb b/tests/.crumb index b2a8da642..b9781e081 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -199,8 +199,8 @@ "purpose": "Simulated M16 driver for numeric resource-lifecycle tests. No device execution or numeric parity" }, { - "digest": "72d601d7cc0bbf3b87e7dc8100fd2fcddcc0cb9c214c78a437b4552513a33ce5", - "last_commit": "dbfc8aea", + "digest": "48d32158b5b7f5ae704d3a462d51dad4c4ab5e6b94e8118a7cd8e59f4fa21be2", + "last_commit": "2f93d2d0", "name": "osh", "purpose": "osh lexer host driver, vendored aien-protocols PR#16 draft vectors (5ae5292)" }, @@ -289,15 +289,15 @@ "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], - "children_root": "sha256:23b3cdb89428091be44feb9387e124ccf7608269b34f353b09829a15eaddf8a2", - "compiled_at": "2026-10-10T08:01:55Z", + "children_root": "sha256:446d54c91485acc65c5927c911cadff768ebe250aa357c3dc9ebcdcb078e9d3d", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:fd6417d3ee731e5b90b56a4cb38020034328a6c6a746b9feea671fb3d6275f84", + "digest": "sha256:9b685c0445e3dfb80ea33118ce501b38e78296e9e09aa8e284129fa75e7759c3", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", "files": 948, - "generated_at_commit": "dbfc8aea517bf35d71a70a5cb1371cfad051d097", - "source_tree": "sha256:539816a6bb6f53a4bb9667c214374fd58c9756a8f9745e752e8166a13281e2ee" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:d1793ce9716df5dc2a33985098584ad53ce8794c2e4ad8c125405e9bf056c7fb" }, "owner_lane": "", "provenance": { diff --git a/tests/osh/.crumb b/tests/osh/.crumb index 78fb19c24..a4d4a7cf8 100644 --- a/tests/osh/.crumb +++ b/tests/osh/.crumb @@ -9,8 +9,8 @@ "purpose": "end-to-end tests of the osh program: argprint helper plus a runner comparing native and OSH_INTE" }, { - "digest": "2e87e86c072dbe5ab65f8189c69ad617166e2157e6816804930cbe5551a251a3", - "last_commit": "dbfc8aea", + "digest": "d0f42501a21a18f494990b88f370ef66e89265cde98d55a6ab6a93880d7ec9fb", + "last_commit": "2f93d2d0", "name": "host", "purpose": "tests for the osh Linux host adapter execution service (hand-built request records, helper-mode " }, @@ -21,15 +21,15 @@ "purpose": "Core-only step traces of the osh shell units over fixture scripts (OSH-AIENOS-0 differential fix" } ], - "children_root": "sha256:354c97f143b139892c7712cbde7744da9a15c1d226d897931cc7a3bd54c85ca5", - "compiled_at": "2026-10-10T08:01:55Z", + "children_root": "sha256:241feb8a2f188c8542457a158587a5382360916abaf958e03884644df77e573f", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:72d601d7cc0bbf3b87e7dc8100fd2fcddcc0cb9c214c78a437b4552513a33ce5", + "digest": "sha256:48d32158b5b7f5ae704d3a462d51dad4c4ab5e6b94e8118a7cd8e59f4fa21be2", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 93, - "generated_at_commit": "dbfc8aea517bf35d71a70a5cb1371cfad051d097", - "source_tree": "sha256:9f7775d87e43be2884ca47c4cc0b014a8fa20339567791d104ddd0ea8ae45ba8" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:3cc71e1cbdeec81e3a15989fe1a2cef93684efa323772e07ad278eed3b0c58ce" } }, "name": "osh-tests", diff --git a/tests/osh/host/.crumb b/tests/osh/host/.crumb index f8ab4fd22..a94c09df1 100644 --- a/tests/osh/host/.crumb +++ b/tests/osh/host/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-10T08:01:55Z", + "compiled_at": "2026-10-10T08:08:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:2e87e86c072dbe5ab65f8189c69ad617166e2157e6816804930cbe5551a251a3", + "digest": "sha256:d0f42501a21a18f494990b88f370ef66e89265cde98d55a6ab6a93880d7ec9fb", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 3, - "generated_at_commit": "dbfc8aea517bf35d71a70a5cb1371cfad051d097", - "source_tree": "sha256:a124ea0e7d00acd3665c6338aa22c051fb5f1e26e51a9b61252f516c40272d0e" + "generated_at_commit": "2f93d2d05ba362934a51dcef7225c6729c281cdc", + "source_tree": "sha256:ec569f66e8fcff2185d6033fde16f520eb962d5d61be641b45b8c1446d88d358" } }, "name": "host-tests", diff --git a/tests/osh/host/test_osh_host.c b/tests/osh/host/test_osh_host.c index fa55eadd0..2db22ff99 100644 --- a/tests/osh/host/test_osh_host.c +++ b/tests/osh/host/test_osh_host.c @@ -379,6 +379,17 @@ static void test_builtins(void) CHECK(go(&t, b, &r) == 0, "cd ok"); CHECK(osh_var_get(&t.s, "PWD") && strcmp(osh_var_get(&t.s, "PWD"), P("d1")) == 0, "PWD=%s", osh_var_get(&t.s, "PWD")); CHECK(osh_var_get(&t.s, "OLDPWD") && strcmp(osh_var_get(&t.s, "OLDPWD"), cwd0) == 0, "OLDPWD"); + { /* bash exports OLDPWD, so a child sees the previous directory */ + t_clear(&t); + OshBuilder *b2 = nb(0, 0); + helper(b2, "env", "OLDPWD", NULL); + go(&t, b2, &r); + char *o2 = t_out(&t), w2[PATH_MAX + 2]; + snprintf(w2, sizeof w2, "%s\n", cwd0); + CHECK(strcmp(o2, w2) == 0, "OLDPWD reaches children, got '%s'", o2); + free(o2); + t_clear(&t); + } b = nb(0, 0); cmd(b, OSH_B_CD, "cd", "sub/../sub/.", NULL); CHECK(go(&t, b, &r) == 0, "relative cd"); @@ -1521,8 +1532,14 @@ static void test_session_env(void) int a = 0, z = 0, n = 0, raw = 0; for (char **p = e; *p; p++) { n++; a += !strcmp(*p, "A=9"); z += !strcmp(*p, "Z=z"); raw += !strcmp(*p, "9x=1") + !strcmp(*p, "A B=1") + !strcmp(*p, "BASH_FUNC_f%%=() { echo hi; }"); } - CHECK(a == 1 && z == 1 && n == 8, "fresh envp with override (n=%d)", n); + CHECK(a == 1 && z == 1 && n == 9, "fresh envp with override plus SHLVL (n=%d)", n); CHECK(raw == 3, "non-identifier entries reach children verbatim, as bash does (%d/3)", raw); + /* bash 5.2: SHLVL is the inherited level plus one; OLDPWD is exported, valueless unless inherited naming a directory */ + int shl = 0, oldpwd_valueless = 0; + for (char **p = e; *p; p++) shl += !strcmp(*p, "SHLVL=1"); + for (size_t k = 0; k < s.nvars; k++) + if (!strcmp(s.vars[k].name, "OLDPWD")) oldpwd_valueless = s.vars[k].exported && !s.vars[k].value; + CHECK(shl == 1 && oldpwd_valueless, "no SHLVL inherited: SHLVL=1 exported; OLDPWD exported without a value (%d %d)", shl, oldpwd_valueless); osh_envp_free(e); CHECK(osh_var_set(&s, "bad name", "x") < 0 && osh_var_export(&s, "", NULL) < 0, "invalid names refused"); osh_var_set(&s, "U", "u"); @@ -1534,6 +1551,35 @@ static void test_session_env(void) osh_session_free(&s); } +/* bash 5.2.21 (measured): SHLVL=3 -> 4; abc -> 1; -2 -> 0; 999 -> 1 (too high, reset); inherited OLDPWD kept only when it + * names a directory. */ +static void test_session_levels(void) +{ + static const struct { const char *in, *want; } lv[] = {{"SHLVL=3", "4"}, {"SHLVL=abc", "1"}, {"SHLVL=-2", "0"}, {"SHLVL=999", "1"}, {"SHLVL=0", "1"}}; + for (size_t k = 0; k < sizeof lv / sizeof lv[0]; k++) { + OshSession s; + char in[32]; + snprintf(in, sizeof in, "%s", lv[k].in); + char *env[] = {in, NULL}; + CHECK(osh_session_init(&s, env) == 0, "init %s", lv[k].in); + const char *v = osh_var_get(&s, "SHLVL"); + CHECK(v && strcmp(v, lv[k].want) == 0, "%s -> SHLVL=%s (got %s)", lv[k].in, lv[k].want, v ? v : "(null)"); + osh_session_free(&s); + } + OshSession s; + char *env1[] = {"OLDPWD=/usr", NULL}; + CHECK(osh_session_init(&s, env1) == 0, "init oldpwd dir"); + CHECK(osh_var_get(&s, "OLDPWD") && strcmp(osh_var_get(&s, "OLDPWD"), "/usr") == 0, "inherited OLDPWD naming a directory is kept"); + osh_session_free(&s); + char *env2[] = {"OLDPWD=/nonexistent-dir-osh", NULL}; + CHECK(osh_session_init(&s, env2) == 0, "init oldpwd bogus"); + int valueless = 0; + for (size_t k = 0; k < s.nvars; k++) + if (!strcmp(s.vars[k].name, "OLDPWD")) valueless = s.vars[k].exported && !s.vars[k].value; + CHECK(valueless, "inherited OLDPWD not naming a directory becomes a valueless export"); + osh_session_free(&s); +} + /* ================= review fixes (PR 337): isolation helper ================= */ /* Results of a test that ran in its own process (so a hang or a signal storm cannot take the suite with it). */ @@ -2226,7 +2272,7 @@ int main(int argc, char **argv) if (argc > 2 && !strcmp(argv[1], "--only")) { g_only_set = 1; g_only = argv[2]; } alarm(300); /* watchdog: a hang must fail the run, not stall it */ - if (want("env")) { test_session_env(); test_raw_env(); } + if (want("env")) { test_session_env(); test_raw_env(); test_session_levels(); } if (want("simple")) test_simple_and_path(); if (want("builtins")) test_builtins(); if (want("printf")) { test_printf(); test_printf_review(); }