.f0rge/ci/steps/04_shape.sh 9.4 KiB 195 lines Raw
1 #!/usr/bin/env sh2 # 04 shape — the rules that a review keeps forgetting.3 #4 # Every check here is one line of shell over files that are in the tree. A rule5 # that needs a compiler belongs in 02 or 03; a rule that needs a runtime belongs6 # in a test.7 set -eu8 9 fail() {10     printf 'shape: %s\n' "$1" >&211     exit 112 }13 14 # 1. No unsafe. Spec section 20.3.15 if grep -rn 'unsafe' crates/ --include='*.rs' |16     grep -v 'unsafe_code' |17     grep -v '^[^:]*:[0-9]*: *//' | grep -q .; then18     grep -rn 'unsafe' crates/ --include='*.rs' |19         grep -v 'unsafe_code' |20         grep -v '^[^:]*:[0-9]*: *//' >&221     fail "an unsafe expression is in the tree"22 fi23 24 # 2. An engine crate takes the workspace lints. A bundle is a standalone25 #    workspace (D19): it declares its own lints, because a kernel or FFI bundle26 #    may opt out of unsafe_code there with a stated reason.27 for manifest in crates/*/*/Cargo.toml; do28     grep -A1 '^\[lints\]' "$manifest" | grep -q 'workspace = true' ||29         fail "$manifest does not take the workspace lints"30 done31 for manifest in plugins/*/*/Cargo.toml; do32     grep -q '^\[lints' "$manifest" || fail "$manifest does not set [lints]"33     grep -q '^\[workspace\]$' "$manifest" ||34         fail "$manifest is not its own workspace"35 done36 # The root workspace owns the engine crates and no bundle (D19).37 grep -q '^members = \["crates/\*/\*"\]$' Cargo.toml ||38     fail "the root workspace members include a bundle"39 40 # 3. The wire crate never panics on input.41 if grep -rn 'unwrap()\|expect(\|panic!' crates/edge/proto/src | grep -q .; then42     grep -rn 'unwrap()\|expect(\|panic!' crates/edge/proto/src >&243     fail "the wire crate can panic on input"44 fi45 46 # 4. The core is a library, not a web adapter. Spec section 18 and D9.47 if grep -qE '^inf3r-(api|plugin-sdk)[[:space:]]*=' crates/run/core/Cargo.toml; then48     fail "inf3r-core depends on a crate above the protocol"49 fi50 51 # 5. No API version in a client-facing route. Only OpenAI's frozen namespace.52 if grep -rn '"/v1/\|/chat/v1\|/embeddings/v1' crates/ --include='*.rs' |53     grep -v '/openai/v1' | grep -q .; then54     fail "a client-facing route carries a version"55 fi56 57 # 6. Capability pages: twelve, written, no golden, no forbidden word.58 pages=.f0rge/wiki/docs/capabilities59 count=$(ls "$pages"/*.v1.md 2>/dev/null | wc -l)60 [ "$count" -eq 12 ] || fail "expected 12 capability pages, found $count"61 if grep -rn '^Golden:' "$pages" --include='*.v1.md' | grep -q .; then62     fail "a capability page carries a golden line"63 fi64 for page in "$pages"/*.v1.md; do65     grep -q '^## Parts in' "$page" || fail "$page has no input table"66     grep -q '^## Channels out' "$page" || fail "$page has no output table"67     grep -q '^## Parameters' "$page" || fail "$page has no parameters"68 done69 70 # 7. A published shape is a committed artifact. The page is the source; the71 #    generator reads its four tables and CI fails when the artifact drifted.72 python3 .f0rge/ci/shape_goldens.py --check >/dev/null ||73     fail "a capability shape golden differs from its page"74 75 # 8. The cache is host policy. A bundle may not name a path, a quota, or a76 #    tier; the binder owns the one private exchange directory.77 if grep -nE -- '--slot-save-path|--cache-idle-slots|cache_quota|cache_ttl|\[node\.cache' plugins/*/*/bundle.toml plugins/*/*/target.toml plugins/*/*/models/*.toml 2>/dev/null | grep -q .; then78     fail "a bundle declares cache-owned state"79 fi80 if grep -nE -- '--slot-save-path|--cache-idle-slots' plugins/*/*/engine/* 2>/dev/null | grep -q .; then81     fail "a bundle engine names a cache path"82 fi83 # A policy in bundle source is the same violation as a flag in a manifest.84 if grep -rnE -- 'cache_quota|cache_ttl|eviction_policy|CACHE_FORMAT_VERSION|kvcache_proxy|lla''ma-swap-kv|prefix-cache'     plugins/*/*/src plugins/*/*/engine 2>/dev/null | grep -vE '\.(md|json)$' | grep -q .; then85     fail "a bundle source declares host cache policy"86 fi87 88 # 9. The cache crate stays below the core. It may not depend on the wire, the89 #    web, or an HTTP client.90 if grep -qE '^inf3r-(api|proto|server|bind|plugin-sdk)[[:space:]]*=' crates/state/cache/Cargo.toml; then91     fail "inf3r-cache depends on a crate above it"92 fi93 94 # 10. Wire 2 reserves the cache range and names it in the grammar.95 grep -q '^wire = 2$' spec/protocol.cddl || fail "the grammar is not wire 2"96 for hex in 20 21 22 23 24 25 26 27; do97     grep -q "0x$hex" .f0rge/wiki/docs/protocol.md || fail "wire 2 lacks frame 0x$hex"98 done99 100 # 11. The compatibility binder is engine-neutral (D14). It may not inject a101 #     vendor flag, name a vendor runtime, or call a vendor route. A first-class102 #     engine belongs in its own direct bundle, not in this shim.103 if grep -rnE -- '--slot-save-path|--cache-idle-slots|--slots|/slots/|lla''ma-server' crates/edge/bind |104     grep -v '^[^:]*:[0-9]*: *//' | grep -q .; then105     grep -rnE -- '--slot-save-path|--cache-idle-slots|--slots|/slots/|lla''ma-server' crates/edge/bind >&2106     fail "the binder names a vendor flag, route, or runtime"107 fi108 109 # 12. CI never names an external engine on a host execution path. The fixtures110 #     are the only bundles whose tests run on the CI host; every other bundle111 #     is compiled but judged through its container image.112 for dir in plugins/*/*; do113     case "$dir" in114         plugins/mock/*|plugins/toy/*|plugins/echo/*|plugins/fixtures/*) continue ;;115     esac116     if grep -R -n -- "$dir" .f0rge/ci/steps 2>/dev/null |117         grep -qE 'cargo test|verify --program|inf3r-[a-z0-9_/-]+ '; then118         fail "CI names external engine $dir on a host execution path"119     fi120 done121 122 # 13. The image pipeline compiles only inside Docker. A host cargo, rustc, or123 #     native build here would put an engine library on the CI host.124 if grep -nE -- '^[[:space:]]*(cargo[[:space:]]+(build|test|check|clippy)|rustc|cmake|make|ninja)([[:space:]]|$)' ops/images.sh; then125     fail "ops/images.sh compiles on the host"126 fi127 128 # 14. Every control-image base is digest-pinned and agrees with the lock.129 if grep -nE '^[[:space:]]*FROM[[:space:]]+' docker/Containerfile |130     grep -vE '\$\{(RUST|DEBIAN|UV)_IMAGE\}|@sha256:[0-9a-f]{64}' | grep -q .; then131     fail "docker/Containerfile has a control base that is not digest-pinned"132 fi133 for base in rust debian uv; do134     case "$base" in135         rust) arg=$(sed -n 's/^ARG RUST_IMAGE=//p' docker/Containerfile) ;;136         debian) arg=$(sed -n 's/^ARG DEBIAN_IMAGE=//p' docker/Containerfile) ;;137         uv) arg=$(sed -n 's/^ARG UV_IMAGE=//p' docker/Containerfile) ;;138     esac139     printf '%s' "$arg" | grep -Eq '@sha256:[0-9a-f]{64}$' ||140         fail "control base $base is not digest-pinned"141     locked=$(awk -F '\t' -v b="$base" '!/^#/ && $1 == b { print $2; exit }' docker/control.lock)142     [ "$arg" = "$locked" ] || fail "control base $base differs from docker/control.lock"143 done144 145 # 15. The corrected container claims stay out of the docs, and the tests that146 #     back the remaining claims stay in the tree.147 if grep -R -nE 'Deploy refuses a missing or mismatched image|probe is needed only for CUDA|two checks that need' \148     .f0rge/wiki/docs docker/README.md 2>/dev/null | grep -q .; then149     fail "a stale container claim is in the docs"150 fi151 grep -q 'INF3R_BUNDLE_DIR' .f0rge/wiki/docs/spec.md ||152     fail "the bundle-root claim is missing"153 grep -q 'Every container bind requires it' .f0rge/wiki/docs/spec.md ||154     fail "the probe claim is missing"155 grep -q 'a_container_launch_names_the_bundle_root_inside_the_image' crates/edge/server/src/main.rs ||156     fail "the bundle-root test is missing"157 grep -q 'a_cpu_container_bind_also_needs_a_probe' crates/state/deploy/tests/deploy.rs ||158     fail "the CPU probe test is missing"159 grep -q 'a_content_tag_matches_its_source_label' crates/run/container/src/lib.rs ||160     fail "the image provenance test is missing"161 162 # 16. Bundle images are self-contained. There is no central engine registry,163 #     shared engine base, or host-side Cargo/engine lookup. Each bundle owns164 #     its recipe inside its own directory.165 [ ! -e docker/engines.map ] || fail "docker/engines.map is a central engine registry"166 [ ! -e docker/engines ] || fail "docker/engines holds shared engine bases"167 [ ! -e docker/bundle.Dockerfile ] || fail "docker/bundle.Dockerfile assumes one shared build shape"168 if grep -R -nE 'inf3r/engine-|ENGINE_PIN|engines\.map|docker/engines' \169     docker ops crates \170     --include='*.sh' --include='*.rs' --include='Dockerfile' --include='Containerfile' \171     2>/dev/null | grep -q .; then172     fail "host tooling still names a shared engine base or lookup"173 fi174 if grep -R -nE '(^|[^A-Za-z0-9_])CARGO_BIN([^A-Za-z0-9_]|$)' \175     docker ops 2>/dev/null | grep -q .; then176     fail "host tooling still has a Cargo binary lookup"177 fi178 if grep -R -nEi 'lla''ma|stable''-diffusion|audio''\.cpp|audio''cpp|nemo''_toolkit|koko''ro' \179     docker ops 2>/dev/null | grep -q .; then180     fail "the generic image tooling names an inference engine"181 fi182 # A tokenizer family is a file format, not an engine binding. These names are183 # engine integration surface and belong only inside a bundle.184 if grep -R -nE 'liblla''ma|libstable''-diffusion|libaudio|libaudio''cpp|lla''ma-server|lla''ma_context|lla''ma_model|lla''ma_decode|lla''ma_sampler|nemo''_toolkit|koko''ro_onnx|sd\.cpp' \185     crates --include='*.rs' --include='*.in' 2>/dev/null | grep -q .; then186     fail "a host crate names an inference engine"187 fi188 for recipe in plugins/*/*/Dockerfile; do189     [ -e "$recipe" ] || continue190     if grep -nE 'inf3r/engine-|docker/engines' "$recipe" | grep -q .; then191         fail "$recipe depends on a shared engine base or lookup"192     fi193 done194 195 printf 'shape: ok\n'