48 lines
11 KiB
Markdown
48 lines
11 KiB
Markdown
# CONTRACT — R0 correction: native Rust toolchain on the Ubuntu development server (for the fresh verifier)
|
|
- date: 2026-10-13 | flow: ad-hoc correction (owner brief 2026-10-13, after R0 delivery) | branch: feature/rust-r0-foundation (R0 closed at bd9c7d1; this delta on top)
|
|
- status: closed 2026-10-13 — pass 2 CONFORME 11/11, security pass 2 PASS; post-pass fix 496f549 (fail-closed drift step) verified by execution (oracles 6, 9, 10 amended before dispatch after a dry run by the orchestrator; pass 1: verifier ECARTS(2) = two floor STUB hits on doc prose "(not implemented)" → reworded; security PASS with 1 MEDIUM + 6 LOW → fixes: warn-only advisories stage and porcelain drift gate in check-all.sh and ci.yml, PATH guard appends an absolute dir only, literal rm path, prctl unused arguments as unsigned long with an honest comment; evidence of pass 2 = check-all-2.log)
|
|
- spec: owner brief (REQUEST below), docs/development/RUST.md §1 and §4 (what the correction builds), docs/development/RUST_ARCHITECTURE_REVIEW.md Annex C.1
|
|
- evidence logs (runs made by the orchestrator on this host, readable): <session scratchpad>/{toolchain-install.log,warm-build.log,native-check.log,native-check-2.log,docker-alt.log,check-all.log,check-all-2.log}
|
|
- the verifier never installs, uninstalls or updates anything on the host; cargo commands below run the native toolchain already installed (rustup in ~/.cargo); `~/.cargo/bin` may be absent from a non-interactive PATH: prefix commands with `PATH="$HOME/.cargo/bin:$PATH"` when `cargo` is not found. Docker commands are not re-run (read check-all.log).
|
|
|
|
## REQUEST (owner brief 2026-10-13, condensed — IMMUTABLE)
|
|
Development machine = self-hosted Ubuntu server (native, not WSL, not the VPS) with Docker rootless. Install a native user-level Rust toolchain (rustup, rustc, cargo, rustfmt, clippy, wasm32-unknown-unknown, wasm/bindings tools) at the pinned 1.99.0, no sudo, no global package, no sensitive system change. Daily Rust development = native cargo commands; wasm build native too; pinned toolchain + existing Cargo.lock. Adapt the monorepo scripts so the main path is native; keep the Docker commands as the reproducible alternative without imposing them; short compile times, reuse of Cargo artefacts. Docker stays for Supabase, the worker's execution, integration tests, untrusted-file isolation, seccomp/Linux protections, deployment images, production-like tests; the R0 builder is kept; the worker's isolation is not degraded. No CI/CD is operational: workflow files may stay, never claimed as run, no secrets/runner/auto-publication, no mandatory dependency on a pipeline; one simple command runs every technical check before a merge, reusable by a future Gitea runner. Verification: versions, native tests, lint, core build, wasm build, TS/WASM compatibility tests, Docker builds of R0 still work, monorepo tests, comparison with the R0 proofs; seccomp and container protections stay in Docker; no regression. Re-examine the worker's unsafe blocks: precise, verifiable technical justification, SAFETY comments never presented as the owner's approval; sandbox protections and tests kept. Update RUST.md and the associated docs (Ubuntu native dev, Docker services/isolated tests, separate VPS). No out-of-scope change; no R1, no deploy, no release 0.2.0.
|
|
|
|
## ACCEPTANCE CRITERIA
|
|
1. Native toolchain pinned and complete, user-level only.
|
|
CHECK: cd $HOME/Documents/faunosteo && "$HOME/.cargo/bin/rustup" show active-toolchain | cut -d' ' -f1; "$HOME/.cargo/bin/rustup" component list --installed --toolchain 1.99.0 | grep -c "rustfmt\|clippy"; "$HOME/.cargo/bin/rustup" target list --installed --toolchain 1.99.0 | grep -c "^wasm32-unknown-unknown$"; "$HOME/.cargo/bin/wasm-bindgen" --version; "$HOME/.cargo/bin/cargo-deny" --version; dpkg-query -W rustc cargo 2>&1 | grep -c "no packages found"
|
|
EXPECT: 1.99.0-x86_64-unknown-linux-gnu ; 2 ; 1 ; wasm-bindgen 0.2.129 ; cargo-deny 0.20.2 ; 2
|
|
2. Scripts: the two Rust scripts live under scripts/ (not docker/), source the PATH guard, and the root scripts make native the primary path with `:docker` alternatives and a single pre-merge gate.
|
|
CHECK: ls scripts | tr '\n' ' '; ls docker | grep -c "rust-check.sh\|wasm-build.sh"; grep -c "^\. scripts/rust-env.sh" scripts/rust-check.sh scripts/wasm-build.sh; grep -c '"rust:check": "bash scripts/rust-check.sh"' package.json; grep -c '"rust:check:docker": "bash docker/rust-run.sh bash scripts/rust-check.sh"' package.json; grep -c '"wasm:build": "bash scripts/wasm-build.sh"' package.json; grep -c '"wasm:build:docker": "bash docker/rust-run.sh bash scripts/wasm-build.sh"' package.json; grep -c '"check:all": "bash scripts/check-all.sh"' package.json
|
|
EXPECT: check-all.sh rust-check.sh rust-env.sh wasm-build.sh ; 0 ; scripts/rust-check.sh:1 and scripts/wasm-build.sh:1 ; 1 ; 1 ; 1 ; 1 ; 1
|
|
3. The native check covers the worker's unit tests; the sandbox tests stay feature-gated and Docker-only; the pre-merge gate runs them through the worker image.
|
|
CHECK: grep -c "cargo test --workspace --locked" scripts/rust-check.sh; grep -c "exclude faunosteo-worker" scripts/rust-check.sh; grep -c "git status --porcelain -- packages/core-wasm/types" scripts/check-all.sh .gitea/workflows/ci.yml | tr '\n' ' '; grep -c "cargo deny check advisories" scripts/check-all.sh; grep -c '#!\[cfg(all(feature = "test-hooks", target_os = "linux"))\]' crates/worker/tests/sandbox.rs; grep -c "pnpm worker:test" scripts/check-all.sh; grep -c "pnpm worker:image" scripts/check-all.sh; grep -c "read-only --cap-drop ALL" scripts/check-all.sh
|
|
EXPECT: 1 ; 0 ; both files at :1 (any order) ; 1 ; 1 ; 1 ; 1 ; 1
|
|
4. The Docker path is intact: rust-run.sh and the builder Dockerfile changed in comments only; the worker Dockerfile, the application Dockerfile, compose and nginx are untouched.
|
|
CHECK: git diff HEAD -- docker/rust-run.sh | grep -E "^[-+]" | grep -vE "^(\+\+\+|---)" | grep -vc "^[-+]#"; git diff HEAD -- docker/rust-builder.Dockerfile | grep -E "^[-+]" | grep -vE "^(\+\+\+|---)" | grep -vc "^[-+]#"; git diff --stat HEAD -- crates/worker/Dockerfile Dockerfile docker-compose.yml docker/nginx.conf docker/entrypoint.sh | wc -l
|
|
EXPECT: 0 ; 0 ; 0
|
|
5. Workflow files kept (three), each marked prepared / never executed, script paths updated, nothing added that configures a runner, a secret or an automatic publication.
|
|
CHECK: ls .gitea/workflows | wc -l; grep -c "PREPARED, NEVER EXECUTED" .gitea/workflows/ci.yml; grep -c "prepared, never executed" .gitea/workflows/rust-advisories.yml .gitea/workflows/release-images.yml; grep -rc "docker/rust-check.sh\|docker/wasm-build.sh" .gitea/workflows | grep -vc ":0$"; git diff HEAD -- .gitea | grep -E "^\+" | grep -vE "^\+\+\+" | grep -vc "^\+ *#\|^\+ *run: bash docker/rust-run.sh bash scripts/\|^\+ *run: docker build -f docker/rust-builder.Dockerfile"
|
|
EXPECT: 3 ; 1 ; rust-advisories.yml:1 and release-images.yml:1 ; 0 ; 0
|
|
6. Worker unsafe blocks: every `unsafe {` in crates/worker/src is preceded by a `// SAFETY:` comment stating invariants the surrounding code establishes (read them: encode_webp checks `rgba.len() == w*h*4` and computes the stride with checked arithmetic; from_raw_parts after `size != 0 && !output.is_null()`; WebPFree once; prctl integer arguments with the return code checked; the two negative hooks compiled with `test-hooks` only); no `[gated …]` approval marker remains; no unsafe outside the worker.
|
|
CHECK: grep -c "gated" crates/worker/src/decode.rs crates/worker/src/sandbox.rs; grep -c "unsafe {" crates/worker/src/decode.rs; grep -c "// SAFETY:" crates/worker/src/decode.rs; grep -c "unsafe {" crates/worker/src/sandbox.rs; grep -c "// SAFETY:" crates/worker/src/sandbox.rs; grep -rc "unsafe {" crates/core/src crates/wasm/src | grep -vc ":0$"; grep -c "width.checked_mul(4)" crates/worker/src/decode.rs; grep -c "c_int::try_from(width \* 4)" crates/worker/src/decode.rs; grep -c 'unsafe_code = "forbid"' Cargo.toml; grep -c 'unsafe_code = "deny"' crates/worker/Cargo.toml
|
|
EXPECT: decode.rs:0 and sandbox.rs:0 ; 6 ; 6 ; 2 ; 2 ; 0 ; 1 ; 0 ; 1 ; 1
|
|
7. The native Rust gate is green and the committed ts-rs types do not drift.
|
|
CHECK: cd $HOME/Documents/faunosteo && PATH="$HOME/.cargo/bin:$PATH" bash scripts/rust-check.sh > /tmp/claude-1000/verify-rust-check.log 2>&1; echo rc=$?; grep -E "^test result" /tmp/claude-1000/verify-rust-check.log | grep -c "ok\."; grep -E "^test result" /tmp/claude-1000/verify-rust-check.log | grep -c " 10 passed\| 9 passed\| 14 passed"; grep -c "bans ok, licenses ok, sources ok" /tmp/claude-1000/verify-rust-check.log; git diff --exit-code -- packages/core-wasm/types > /dev/null && echo SAME
|
|
EXPECT: rc=0 ; 12 ; 3 ; 1 ; SAME
|
|
8. The native wasm build and the TypeScript/WASM proofs pass on the module it produces; the size stays within 1 KB of the R0 builder figure (224 713 B raw).
|
|
CHECK: cd $HOME/Documents/faunosteo && PATH="$HOME/.cargo/bin:$PATH" bash scripts/wasm-build.sh 2>&1 | grep "faunosteo_wasm_bg.wasm:"; corepack pnpm --filter @faunosteo/core-wasm test:run 2>&1 | grep -E "Tests "
|
|
EXPECT: a line "faunosteo_wasm_bg.wasm: NNNNNN bytes raw, …" with 223713 <= NNNNNN <= 225713 ; "Tests 14 passed (14)"
|
|
9. The single pre-merge gate passed end to end on this host (native stages, Node pipeline, application image, worker sandbox tests + seccomp derivation, worker runtime read-only), read from the evidence log.
|
|
CHECK: L=<session scratchpad>/check-all-2.log; grep -c "^== all checks passed" "$L"; grep -c "DONE rc=0" "$L"; grep -c "== allowlist covers the trace" "$L"; grep -E "Tests [0-9]+ passed" "$L"; grep -c "test result: ok. 16 passed" "$L"
|
|
EXPECT: 1 ; 1 ; 1 ; six per-package lines (domain 194, core-wasm 14, supabase 24, anatomy 130, pdf 137, app 278 = 777, every one "passed") ; 1
|
|
10. Documentation reflects the three environments and the CI status; no doc still claims a Docker-only or CI-run toolchain.
|
|
CHECK: grep -c "native on the development machine" docs/development/RUST.md; grep -c "prepared, no CI active" docs/development/RUST.md; grep -c "### 5.8 Native toolchain run" docs/development/RUST.md; grep -c "C.1 Addendum 2026-10-13" docs/development/RUST_ARCHITECTURE_REVIEW.md; for f in CLAUDE.md README.md CHANGELOG.md docs/development/RUST.md docs/development/TEST_STRATEGY.md; do grep -c "check:all" $f; done | tr '\n' ' '; grep -c "no toolchain on the host\|never on the host\|all through the builder image" CLAUDE.md docs/development/RUST.md docs/development/WORKSPACE.md | grep -vc ":0$"; grep -c "(not implemented" docs/development/RUST.md docs/development/RUST_ARCHITECTURE_REVIEW.md | grep -vc ":0$"; grep -c "No CI/CD\|no CI active\|No CI runs" DEPLOY.md CLAUDE.md README.md | grep -vc ":0$"
|
|
EXPECT: 1 ; 1 ; 1 ; 1 ; five numbers all >= 1 ; 0 ; 0 ; 3
|
|
11. Scope held: no change under apps/, packages/, supabase/, no new dependency, Cargo.lock and pnpm-lock.yaml untouched.
|
|
CHECK: git diff --stat HEAD -- apps packages supabase Cargo.lock pnpm-lock.yaml | wc -l; git status --short | grep -c "^??" ; git status --short | grep "^??" | grep -vc "^?? scripts/\|^?? .claude/tasks/contracts/"
|
|
EXPECT: 0 ; >= 0 ; 0
|
|
|
|
## OUT OF SCOPE (do not report as gaps)
|
|
R1 (job loop), any deployment, release 0.2.0, runner / registry / secrets on the forge, `--remap-path-prefix` for bit-identical native vs Docker modules (documented in RUST.md §5.8), prettier conformance of Markdown files already non-conformant at HEAD, the `rust-docs` component installed by rustup's default profile.
|