diff --git a/docs/adr/0070-explicit-stdlib-bundle-build-input.md b/docs/adr/0070-explicit-stdlib-bundle-build-input.md new file mode 100644 index 0000000..c0d8e3d --- /dev/null +++ b/docs/adr/0070-explicit-stdlib-bundle-build-input.md @@ -0,0 +1,123 @@ +# ADR-0070 — One explicit stdlib Bundle build input (Phase A) + +Status: **Accepted for implementation on the 3.0 prerelease line** (2026-11-26). +Relates to: issue +[#11](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11), ADR-0028 (bundled +stdlib and `std:` imports), ADR-0039 (deferred extraction), ADR-0058 (public +aliases), ADR-0062 (resource ownership), ADR-0068 (single current public +contracts). +Evidence: +[`docs/evidence/2026-11-26-stdlib-source-coupling-inventory.md`](../evidence/2026-11-26-stdlib-source-coupling-inventory.md). + +## Context + +Issue #11 starts the extraction that ADR-0039 deferred: the CLI and the +Provider Worker must build and run on their own, while a release is assembled +from one explicitly provided, verifiable stdlib Bundle. The extraction trigger +listed by ADR-0039 is now real: an ecosystem repository pins component commits +and assembles the production Bundle, and nine component repositories own module +sources. + +At the implementation baseline `4bbefc92449ee480c8a2c89b0308feb4cda8d0e7` the +stdlib source directory is implicit in four different ways, documented in the +inventory linked above: + +* both packaging entry points read the checkout's `stdlib/` with no build + argument (`tools/pack-stdlib.py`, `tools/release/package.py`); +* product tests, the semantic harness and the P2 closure lane rebuild + `repo_root()/stdlib` independently; +* the performance runner silently falls back to `ROOT / "stdlib"` when the + binary has no sibling bundle; +* the debug CLI resolves a compile-time source tree + (`CARGO_MANIFEST_DIR/../../stdlib`) after the explicit override and the + sibling directory. + +Separating compile, package and product-test lanes later requires changing all +of them at once, and none of them records which Bundle commit produced a test +run. The runtime contracts themselves — `stdlib.json`, the +`marqdo.stdlib-package` descriptor, Analysis `project.stdlib` and Observation +identity — are not the problem and must not change. + +## Decision + +### 1. Explicit build input + +`tools/pack-stdlib.py` and `tools/release/package.py` accept the same required +`--stdlib-dir PATH` argument. It names an unpacked Bundle root that contains +`stdlib.json`. There is no implicit default: a missing path, a missing manifest, +a tree-digest mismatch, an alias-digest mismatch or a missing required module +fails the command before any archive is written. Both entry points keep the +existing deterministic archive layout, descriptor fields, digest algorithms +and checksums. + +Both entry points also accept an optional `--bundle-pin PATH`. When given, the +input must match the pinned identity and the release record names the pinned +source commit; the pin is not a substitute for verifying the Bundle's own +manifest. + +### 2. One pinned Bundle identity + +`tools/stdlib/bundle-pin.json` records the Bundle name, version, source +repository and commit, tree digest and alias digest. `tools/stdlib/bundle.py` +is the single resolver and verifier for source-side consumers: tests, the +performance runner and release CI resolve the Bundle through it instead of +concatenating `stdlib/`. + +An explicit `MARQDO_TEST_STDLIB_BUNDLE` (tests) or `--stdlib-dir` (tools) takes +precedence over the pin's default location, but the input must still verify +against the pin's digests. An invalid explicit input fails even when a valid +sibling Bundle exists; silent fallback is forbidden. Phase B updates the pin to +the Bundle assembled by the ecosystem repository; the algorithm does not change. + +### 3. Runtime contract unchanged + +`MARQDO_STDLIB_DIR` remains the explicit runtime override (invalid values fail +hard), followed by `stdlib/` next to the executable. The debug-only +compile-time source fallback remains in Phase A so the development loop keeps +working; it is removed in Phase B together with the in-repo production sources. +`stdlib.json`, `marqdo.stdlib-package`, Analysis `project.stdlib`, module ids +and Observation identity keep their current shapes and values. + +### 4. Separated test lanes + +The lanes become explicit: + +* **independent compilation** — `cargo build --locked -p marqdo-cli + -p marqdo-provider-worker` in a copy without `stdlib/`, then a language-only + program through the real CLI; +* **loader unit tests** — small synthetic bundles built in a temporary + directory, so loader logic does not depend on the product tree; +* **product tests** — the whole pinned Bundle through `std:` and the real CLI; +* **conformance** — the frozen, independent fixture corpus, unchanged. + +### 5. Phase B gate + +Phase B (switch to the ecosystem-assembled Bundle, delete the in-repo +production sources, the debug source fallback and the replaced `std:` entries) +requires the accepted component commits of ecosystem issue #2 and the extension +replacement evidence named by issue #11. This ADR records the Phase A input +boundary only; it does not authorize deleting sources or changing `std:` +semantics. + +## Consequences + +* A packaging run can be pointed at a downloaded or separately built Bundle and + still produce the same deterministic archive and `RELEASE_INFO.json` record. +* Every product/perf CI run names the Bundle commit and digest it used; a + stale Bundle is visible instead of implicit. +* Phase B becomes a pin/CI change plus source removal, not a simultaneous + rewrite of the test lanes. +* The repository still carries the Bundle in Phase A, so the extraction is not + claimed as complete. `docs/STATUS.md` must record the Phase A state, not the + final externalized state. + +## Non-goals + +* Changing `std:` spelling, digest algorithms, module ids, public aliases or + the `stdlib.json`/descriptor shapes. +* Fetching a Bundle over the network, adding a package registry or a signature + scheme. +* Removing the debug source fallback, the in-repo `stdlib/` sources or any + `std:` entry in Phase A. +* Declaring the extraction, the external Conformance suite or the ecosystem + switch done before their evidence exists. diff --git a/docs/adr/README.md b/docs/adr/README.md index 5bd2204..b29dc33 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -70,3 +70,6 @@ Files: `0001`–`0050`, plus: pre-stable public boundary, replaced in place; * [0069](0069-public-analysis-boundary.md) — one public Analysis projection for independent document, lint and knowledge consumers. +* [0070](0070-explicit-stdlib-bundle-build-input.md) — Phase A of the stdlib + extraction: one required `--stdlib-dir` build input, one pinned Bundle + identity for tests/perf/release CI; runtime contracts unchanged. diff --git a/docs/evidence/2026-11-26-stdlib-source-coupling-inventory.md b/docs/evidence/2026-11-26-stdlib-source-coupling-inventory.md new file mode 100644 index 0000000..a566e1e --- /dev/null +++ b/docs/evidence/2026-11-26-stdlib-source-coupling-inventory.md @@ -0,0 +1,72 @@ +# Stdlib source-directory coupling inventory (issue #11, Phase A) + +Date: 2026-11-26. +Implementation baseline: `4bbefc92449ee480c8a2c89b0308feb4cda8d0e7` (current +`master`). Bundle source commit: `2cbde54602c07f62a62f341400bc9cb4764a93f8` +(the last commit that touched `stdlib/` at the baseline). Pinned Bundle: +`marqdo-stdlib` `0.1.0`, tree digest +`sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713`, +alias digest +`sha256:5f513c0fdbb3c1e9829be3c9fa23a2d1e89cb8510073fb5eb1e8e2f5265a83bb`. + +This file inventories every direct reference to the checkout's stdlib source +directory found for issue #11 Phase A, before the explicit build-input change. +It is an inventory, not a claim that Phase A is finished; the executed evidence +is recorded separately when the work lands. Decision: +[ADR-0070](../adr/0070-explicit-stdlib-bundle-build-input.md). + +## Packaging and release tooling + +| Entry point | Reference | Phase A disposition | +|---|---|---| +| `tools/pack-stdlib.py` | `STDLIB = ROOT / "stdlib"` (line 17); used by the tree digest, manifest read, file list, archive and descriptor (lines 37–97) | required `--stdlib-dir`, optional `--bundle-pin`; shared digest/verify helper | +| `tools/release/package.py` | `STDLIB = ROOT / "stdlib"` (line 37); `verify_stdlib` (lines 110–141), staging copy (line 229), `RELEASE_INFO.stdlib` (lines 245–264) | required `--stdlib-dir`, optional `--bundle-pin`; `RELEASE_INFO.stdlib.source` records the pinned commit | +| `tools/release/smoke.py` | reads only the extracted archive's `install/stdlib` (lines 81–116) | unchanged; it stays an independent verifier of the shipped bytes | +| `tools/perf/runner.py` | pops `MARQDO_STDLIB_DIR`, then falls back to `ROOT / "stdlib"` when the binary has no sibling bundle (lines 327–330) | resolve the pinned Bundle explicitly and always export `MARQDO_STDLIB_DIR`; no silent repo fallback | +| `tools/ci/test_release_archive.py` | reads `ROOT/stdlib/stdlib.json` and `ROOT/stdlib` (lines 33, 40, 54) | pass the explicit/pinned path; add failure-path assertions | +| `.github/workflows/ci.yml` | `package.py` invocation without a Bundle argument (line 224); product lane (lines 44–45) | pass `--stdlib-dir` + `--bundle-pin`; verify the pin in the product lane | +| `.woodpecker/main.yml` | product lane (line 51), `package.py` invocation (line 80) | same as above | +| `.woodpecker/performance.yml` | `package.py` invocation (line 25) | pass `--stdlib-dir` + `--bundle-pin`; perf runner resolves the pin | +| `docs/releasing.md` | release command without a Bundle argument (line 119) | document the required input and the pin | + +## Runtime and development discovery + +| Entry point | Reference | Phase A disposition | +|---|---|---| +| `crates/cli/src/stdlib.rs` | debug-only `CARGO_MANIFEST_DIR/../../stdlib` fallback after `MARQDO_STDLIB_DIR` and the sibling directory (lines 73–82) | keep for the development loop; remove in Phase B | +| `crates/cli/src/stdlib.rs` unit tests | `dev_bundle()` loads the whole in-repo tree (lines 457–492) | replace with synthetic small bundles so loader tests do not depend on the product tree | + +## Test harnesses that rebuild `repo_root()/stdlib` + +| Harness | Reference | Role | Phase A disposition | +|---|---|---|---| +| `crates/cli/tests/stdlib_product.rs` | `stdlib_dir()` (lines 35–37), fixtures (line 48), cwd/`MARQDO_STDLIB_DIR` (lines 130–138) | product | pinned resolver | +| `crates/cli/tests/stdlib_bundle.rs` | `stdlib_dir()` (lines 19–20) | product | pinned resolver | +| `crates/cli/tests/stdlib_http.rs` | cwd and `MARQDO_STDLIB_DIR` (lines 22–23) | product | pinned resolver | +| `crates/cli/tests/stdlib_table.rs` | cwd and `MARQDO_STDLIB_DIR` (lines 21–22) | product | pinned resolver | +| `crates/cli/tests/stdlib_alias_routing.rs` | copies `repo()/stdlib` (lines 64–65) | product | pinned resolver | +| `crates/cli/tests/p2_closure.rs` | table self-test path, cwd and env (lines 112, 122–123) | product | pinned resolver | +| `crates/cli/tests/conformance_semantics.rs` | alias binding (line 294), entry `std:` imports (line 431) | conformance | pinned resolver | +| `crates/cli/tests/architecture_boundaries.rs` | in-repo digest/import gates (lines 90–114, 442–477) | architecture gate | pinned resolver plus the Phase A in-repo assertion | + +## References that are intentionally not build inputs + +* `crates/cli/src/analysis/*`, `crates/cli/src/loader.rs` and + `crates/cli/src/commands.rs` consume the verified `StdlibBundle` identity at + run time; they do not read the source directory. +* `crates/marqdo-runtime/src/builtins_impl.rs` and + `crates/marqdo-sandbox/*` mention stdlib only in diagnostics/tests. +* `docs/evidence/*` and historical ADRs keep their recorded paths; they are + decision history, not executable inputs. + +## Acceptance for Phase A + +1. A clean copy without `stdlib/` and without an ecosystem checkout builds + `marqdo-cli` and `marqdo-provider-worker` with `--locked`. +2. Both packaging entries fail without `--stdlib-dir`, and fail on a missing + directory, a missing `stdlib.json`, a tree-digest mismatch, an alias-digest + mismatch or a pin mismatch. +3. Product tests, the performance runner and release CI resolve the Bundle + through `tools/stdlib/bundle.py` and name its pinned commit and digest. +4. The frozen Conformance corpus and the independent `tools/release/smoke.py` + checks stay in place.