interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / candidate / README.md

188 lines · 13848 bytes Raw Blame History Rendered
1# tools/candidate: the candidate-manifest checkers in seeded Omega
2
3Two first-party tools of `docs/qualification/CANDIDATE.md`, rewritten from bash into seeded
4native Omega (`.om`) for the zero-legacy migration (#300, #316). They replace
5`scripts/check_candidate.sh` and `scripts/check_candidate_pins.sh` (last at 1dd84d1) with the
6same arguments, output ordering and exit codes, subject to the explicit differences below.
7
8| program | usage | exit |
9|---|---|---|
10| `check_candidate.om` | `check_candidate <manifest.toml>` | 0 valid, 1 invalid (usage error: 1) |
11| `check_pins.om` | `check_pins <manifest.toml>` | 0 every pin agrees, 1 any mismatch or read failure |
12
13Build with the pinned seed compiler (`tools/zero-legacy/omega.pin`, `omc_sha256`
14`734f0a39…6b61`): `$AIEN_OMC < check_candidate.om > check_candidate && chmod +x check_candidate`.
15Each file is one unit; Omega has no `import`, so the shared part (parser, key table, process
16spawning) is carried by both files, as `tools/zero-legacy/*.om` carry their own helpers.
17
18What they check is unchanged and documented in `docs/qualification/CANDIDATE.md`: commit pins are
1940 lowercase hex and exist (`gh api repos/aien-dev/<repo>/commits/<sha> -q .sha`, or the command in
20`CAND_SHA_CHECK` run as `$CAND_SHA_CHECK <repo> <sha>`); executable digests are 64 hex and not all
21zero, `UNBUILT` only while the status starts with `draft`; every `<stem>.amendment-<n>.toml` next to
22the manifest is checked (schema, candidate, number, date and reason, `manifest-sha256` of the frozen
23manifest computed natively, added keys only, never in `[commits]`, `[contracts]`, `[executables]`
24or `[consumed_pins]`, `*-sha256` values real). `check_pins` fetches lock files
25(`gh api -H "Accept: application/vnd.github.raw" repos/aien-dev/<repo>/contents/<path>?ref=<sha>`,
26or `$CAND_FILE_AT <repo> <sha> <path>`) and compares them with the manifest's pins and
27`[consumed_pins]`.
28
29Two additions to `check_pins` since the bash (DRA-46, CAND-5 gaps G1 and G2; tested by the
30extension cases below, never by the frozen oracle):
31
32- **`-mv` sources.** A Cargo.lock `source = "git+https://github.com/aien-dev/<name>-mv..."`
33 counts as `<name>` (issue 815; sovereign-core consumes `aien-protocols-mv` since #906 and
34 `crumb-spec-mv`). The old and the `-mv` name are one pin, so two revisions across them are
35 `several`. Any other suffix (`<name>-fork`, `<name>-mvx`) is not the repo.
36- **In-tree contracts.** `[contracts] crumb-spec-consumed = "in-tree"` or
37 `spark-crumbs-consumed = "in-tree"` states that sovereign-core builds that contract crate from
38 its own tree (spark-crumbs since sovereign-core #892), the meaning of sovereign-core's own
39 `[pins] spark-crumbs = "in-tree"` (`scripts/check-release-candidate.sh`, ce792cf5). Cargo.lock
40 must then hold a path package of that name (a `[[package]]` with that `name` and no `source`
41 line) and no git source for the repo under either name; the contract is then built at
42 `[commits] aien-sovereign-core`, and its `[contracts]` commit (still required by
43 `check_candidate`; CAND-5 keeps the archived revision CAND-4 consumed) is not compared with
44 Cargo.lock. Any other value of the key is refused. Without the key nothing changes: a contract
45 with no git revision fails as before, and when Cargo.lock holds a path package of that name the
46 FAIL line says so and names the key. There
47 is no in-tree form for `[commits] aien-protocols`. A frozen manifest cannot gain the key (an
48 amendment may not touch `[contracts]`), so CAND-5 keeps its one named difference (spark-crumbs);
49 later manifests state it.
50
51One deliberate change from the frozen bash: the key `commits.aienos` names the kernel repository,
52renamed to aien-dev/aienux, so `check_candidate` checks that pin as `<repo>` = `aienux`.
53The original oracle outputs remain unchanged; the runner asserts this exact naming delta.
54
55## The parsed TOML subset
56
57Both programs parse exactly what the bash parsed, and every manifest and amendment under
58`qualification/candidates/` and `scripts/testdata/` uses only this:
59
60- `key = "value"` with an optional trailing `# comment` after the closing quote. Whitespace
61 (space, tab, CR, VT, FF) may surround the key, the `=` and the value. The key is
62 `[A-Za-z0-9_.-]+`; the value is any bytes but `"` (so a `#` inside the quotes is kept, and a
63 quoted value cannot contain `"`).
64- `[section]` with the same name alphabet, optionally followed by a `# comment`. Keys after it
65 are stored as `section.key` until the next section line.
66- Blank lines and `# comment` lines.
67- A duplicate key keeps its last value. A final line without a newline is not read (bash
68 `while read` stops there). NUL bytes are dropped from a line (bash `read` drops them).
69
70Any other line (`key = 5`, `key = [..]`, `[[array]]`, `key = "a" "b"`, unterminated quotes) is
71ignored, exactly as the bash ignored it; a required key written that way reads as missing and is
72reported by the existing checks (`missing field`, `is not 40 lowercase hex`, `does not match its
73file name`, ...). No new refusals were added because the frozen contract is byte parity with the
74bash; the adversarial corpus below pins that behaviour (`wrong-type`, `dup-key`, `extra-section`,
75`junk-lines`, `crlf`, `trailing-space`, `no-final-newline`, `nul-byte`, ...).
76
77Keys read by `check_candidate`: `schema`, `id`, `status`, `created`, `commits.omega`,
78`commits.aienos`, `commits.aien-sovereign-core`, `commits.aien-protocols`,
79`commits.aien-architecture`, `contracts.crumb-spec`, `contracts.spark-crumbs`, optional
80`commits.physics`, `commits.interplane`, every `executables.*`; in an amendment `schema`,
81`candidate`, `amendment`, `date`, `reason`, `manifest-sha256` and the added `section.key` entries.
82Keys read by `check_pins`: `commits.aien-sovereign-core`, `commits.omega`, `commits.aienos`,
83`commits.physics`, `commits.aien-protocols`, `contracts.crumb-spec`, `contracts.spark-crumbs`,
84the optional `contracts.crumb-spec-consumed` and `contracts.spark-crumbs-consumed`, and
85every `consumed_pins.*` (`sovereign-core-omega-lock`, `sovereign-core-cargo-lock-aien-protocols`,
86`omega-physics-lock`, `omega-aienos-lock`, `omega-argus-lock` are compared; any other name is
87reported `SKIP`).
88
89## Order of lines: bash associative arrays, reproduced
90
91The bash walked `${!kv[@]}` for the `[executables]` checks, the amendment keys and the
92`[consumed_pins]` loop. That order is bash 5.2's hash order, so the .om keeps its keys in a table
93that walks the same way: FNV-1 (multiply first, offset 2166136261, prime 16777619, 32-bit) over
94the key bytes, 1024 buckets, growth x4 when the entries reach twice the buckets, a new key at the
95head of its bucket, walk buckets ascending. Verified against `bash 5.2.21` on 30 random key sets up
96to 5000 keys (including growth) and by the corpus (`many-exe-bad`: 50 FAIL lines in bash order;
97`amend-many-bad`, `many-consumed`).
98
99## Children and the environment
100
101A child (`gh`, or the `CAND_SHA_CHECK` / `CAND_FILE_AT` command, split on space, tab and newline
102as bash splits an unquoted variable) runs as `/bin/sh -c 'set -a; . "$1"; set +a; shift; exec
103"$@"' sh /proc/self/fd/N cmd args...` where fd N is a memfd holding this process's environment
104as single-quoted shell assignments. Omega's `execprog` starts a child with an empty environment
105and no PATH search; the replay gives the child the full environment (so a test's `PATH`,
106`GH_STUB_LOG`, `PARITY_FILES` reach it) and `sh` does the PATH search. Only entries whose name is a
107shell identifier are replayed. In `gh` mode `check_candidate` sends the child's stdout and stderr
108to `/dev/null` as the bash did; `check_pins` captures stdout through a pipe (trailing newlines and
109NUL bytes dropped, as `$(...)` does) and leaves stderr alone.
110
111## Oracle and parity corpus (`parity/`)
112
113`parity/run.sh <check_candidate> <check_pins> [record|record-extensions]` runs every case under `parity/cases/`
114and compares stdout+stderr (one pipe, in order) plus `rc=N` with `parity/expected/`. The expected
115files were recorded from the bash scripts at 1dd84d1 (`record`), before they were deleted; the
116.om binaries must reproduce them byte for byte except for the exact naming delta below and the
117named limits. 74 candidate cases and 43 pins cases: every
118case of the two test suites, the live `CAND-0` and `CAND-4` manifests, the gh code path with its
119argv log, and adversarial inputs (missing, duplicate and wrongly typed keys, extra sections,
120CRLF, trailing spaces, no final newline, NUL and non-ASCII bytes, empty and junk files, 50 bad
121executables, 24 bad amendment keys, three amendments, a directory where a file is expected,
122command words in `CAND_SHA_CHECK`/`CAND_FILE_AT`, empty and comment-only lock files, several and
123forked Cargo.lock revisions, an 800-package Cargo.lock). Expected result: **107 identical,
1246 exact naming deltas, 4 named limits, 0 different**. A case with a `limit` file is a documented
125difference: it is printed, not counted as a failure, and reported if it ever becomes identical.
126
127The six naming cases are `gh-404-contract`, `gh-404`, `gh-good`, `gh-live-cand0`,
128`nonexistent-sha`, and `sha-check-unset-empty`. They are not limits. For these cases only,
129the runner derives a comparison from the frozen output by changing `aienos` to `aienux` in
130complete `api repos/aien-dev/aienos/commits/<40-hex> -q .sha` and
131`FAIL: commit <40-hex> not found in aien-dev/aienos` lines. Every other byte, including
132exit status, ordering, SHA and other repository names, must match. The transformation must
133actually change the oracle: refreshing it to the new name fails, as does reverting the
134checker to the old name. Do not use `record` with the current checker to refresh the frozen
135shell oracle. PR #326's six hand-edited outputs were restored from its parent `a211260`.
136
137### Extension cases
138
139The frozen counts above do not change when `check_pins` gains behaviour the bash never had. Such
140behaviour is pinned by **extension cases**: 19 pins cases (`mv-*`, `intree-*`, `live-cand5`,
141`live-cand5-intree`, DRA-46) whose directory holds an `extension` file saying what the case pins.
142Their expected files were recorded from the .om with `run.sh <cc> <cp> record-extensions` (which
143records extension cases only and still compares every frozen case) and reviewed line by line; a
144plain `record` skips them. `run.sh` counts them on a second line, and any difference fails it:
145`extensions: 19 identical, 0 different`. The pre-extension checker (cd68086) gets 16 of them wrong
146(the three it passes, `mv-two-names-same`, `mv-prefix` and `intree-protocols-key`, pin behaviour
147that did not change). `live-cand5` runs the frozen CAND-5 manifest on byte copies of its pinned lock
148files (`scripts/testdata/cand5-locks/`: sovereign-core dffdbd19 `omega.lock` and `Cargo.lock`,
149omega f9a9a40 `aienos.lock`, `physics.lock`, `argus.lock`, the same git blobs; both live cases link
150their `files/` to it) and names exactly one
151difference, spark-crumbs; `live-cand5-intree` adds `contracts.spark-crumbs-consumed = "in-tree"`
152and agrees. `mkcases.sh` builds the extension cases too.
153
154The suites `scripts/test_check_candidate.sh` (47 checks, 7 mutants) and
155`scripts/test_check_candidate_pins.sh` (17 checks) compile the .om with `AIEN_OMC` and run it;
156their counts are the same as against the bash. The mutants are now sed edits of the .om source
157(`z = zero64 e`, `notq`, `NREQ`, `optpins`, `optpin`'s `shaex`, `mfeq`, `inmf`), recompiled.
158Since DRA-46 the pins suite also has 12 checks of `-mv` sources and in-tree contracts and 5 mutants
159(the `-mv` match, and in `itcheck`/`pathpkg` the git-source, path-package, source-line and word
160checks), 34 in all.
161`tests/gates/run.sh script-tests` refuses to run (exit 3, NOT_RUN) unless `AIEN_OMC` hashes as
162`tools/zero-legacy/omega.pin` pins, then runs the parity corpus and the four suites.
163
164## Limits (named differences from the bash)
165
1661. **Locale.** The bash ran under the caller's `LANG`; in a UTF-8 locale its regexes refused a
167 line holding invalid UTF-8 and counted any `iswspace` character (U+2003, U+3000, not U+00A0)
168 as `[[:space:]]`. The .om matches bytes and knows the six ASCII spaces only, which is the
169 bash's own behaviour under `LC_ALL=C`. Every real manifest is ASCII. Cases
170 `non-ascii-invalid`, `non-ascii-space`.
1712. **Amendment order.** The bash glob `<stem>.amendment-*.toml` sorted in the locale's
172 collation (`en_US`: 10, 1, 2); the .om walks the names in byte order (1, 10, 2; the `LC_ALL=C`
173 order). Only the order of FAIL lines when several amendments fail differs; the count, the
174 checks and the exit code do not. Case `amend-order`.
1753. **NUL warning.** When a fetched lock file holds a NUL byte, bash printed
176 `warning: command substitution: ignored null byte in input` on stderr and went on; the .om
177 drops the byte silently. Case `lock-nul`.
1784. **Diagnostics of the shell itself** are not reproduced: an unreadable manifest (bash printed
179 `Permission denied` and went on with no keys; the .om goes on with no keys silently), a
180 `CAND_SHA_CHECK` command that does not exist (`sh: not found`, exit 127, versus bash's
181 `command not found`, exit 127; both report `commit ... not found`), and glob characters in
182 `CAND_SHA_CHECK` words (bash expanded them; the .om does not).
1835. **Capacities** (exit 70 with a message, where bash had none): a manifest, amendment or fetched
184 file over 999,000 bytes; more than 4096 keys in one file; a key or section name over 8191
185 bytes; more than 1024 amendment files; more than 256 revisions of one package in a Cargo.lock;
186 a child argument list over 4096 bytes; an environment entry over 65,536 bytes is not replayed.
1876. **Binary lock files.** `grep` in a UTF-8 locale treats invalid UTF-8 as binary and prints
188 `binary file matches` instead of the line; the .om reads the bytes. Not exercised by the corpus.