Files
kyleandClaude Fable 5.1 dcdcf65d83 Review M1: accept with two follow-up tasks
The branch passes the checklist: seven commits, copied files unchanged,
gate and audit green. Reading and probing found that AuditRecord and
ToolCall accept unknown fields, that large Timestamps panic when
formatted, and that the dependency-direction scripts miss table-form
dependencies and pass when their inputs are missing. The last two
families were gaps in the tasks, not only in the code.

Tasks 08 and 09 carry the fixes, defined by an exhaustive unknown-field
test, a bounded-Timestamp test and an extended gate-script self-test.
All three were checked against the reference implementation and fail on
the current branch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-17 09:14:29 -07:00

103 lines
5.8 KiB
Bash

#!/bin/sh
# Self-test for the three gate scripts. It builds small fake trees in a temporary
# directory and checks that each script passes the good tree and fails the bad ones.
# Do not edit: this file defines the required behaviour of the scripts.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
fails=0
expect() { # expect pass|fail NAME SCRIPT ROOT
want="$1"; name="$2"; script="$3"; root="$4"
if sh "$here/$script" "$root" >/dev/null 2>&1; then got=pass; else got=fail; fi
if [ "$got" != "$want" ]; then
echo "test-gate-scripts: $name: expected $want, got $got" >&2
fails=$((fails + 1))
fi
}
manifest() { # manifest DIR NAME [DEPENDENCY-LINES...]
dir="$1"; name="$2"; shift 2
mkdir -p "$dir/src"
{
printf '[package]\nname = "%s"\nversion = "0.1.0"\n\n[dependencies]\n' "$name"
for line in "$@"; do printf '%s\n' "$line"; done
} > "$dir/Cargo.toml"
}
tree() { # tree ROOT: a good workspace with proto, loopd and brokerd
root="$1"
mkdir -p "$root/docs"
printf '[workspace]\nmembers = ["crates/*"]\n\n[workspace.dependencies]\nproto = { path = "crates/proto" }\nserde = { version = "1", features = ["derive"] }\n' > "$root/Cargo.toml"
printf '# Dependencies\n\n| Crate | Why |\n|---|---|\n| `serde` | types |\n' > "$root/docs/dependencies.md"
manifest "$root/crates/proto" proto 'serde.workspace = true'
manifest "$root/crates/loopd" loopd 'proto.workspace = true'
manifest "$root/crates/brokerd" brokerd 'proto = { workspace = true }' 'serde.workspace = true'
}
lines() { # lines N FILE
mkdir -p "$(dirname "$2")"
i=0; : > "$2"
while [ "$i" -lt "$1" ]; do echo "// line" >> "$2"; i=$((i + 1)); done
}
# check-lines.sh
tree "$tmp/l-ok"; lines 500 "$tmp/l-ok/crates/loopd/src/lib.rs"
expect pass "500 lines is allowed" check-lines.sh "$tmp/l-ok"
tree "$tmp/l-bad"; lines 501 "$tmp/l-bad/crates/loopd/src/deep/mod.rs"
expect fail "501 lines in a nested file" check-lines.sh "$tmp/l-bad"
tree "$tmp/l-test"; lines 501 "$tmp/l-test/crates/proto/tests/big.rs"
expect fail "501 lines in a test file" check-lines.sh "$tmp/l-test"
tree "$tmp/l-tgt"; lines 501 "$tmp/l-tgt/crates/proto/target/debug/gen.rs"
expect pass "files under target/ are ignored" check-lines.sh "$tmp/l-tgt"
# check-crate-deps.sh
tree "$tmp/c-ok"
expect pass "roles depend only on proto" check-crate-deps.sh "$tmp/c-ok"
tree "$tmp/c-role"; manifest "$tmp/c-role/crates/loopd" loopd 'proto.workspace = true' 'brokerd.workspace = true'
expect fail "role depends on another role" check-crate-deps.sh "$tmp/c-role"
tree "$tmp/c-tbl"; manifest "$tmp/c-tbl/crates/loopd" loopd 'brokerd = { path = "../brokerd" }'
expect fail "role depends on another role by path" check-crate-deps.sh "$tmp/c-tbl"
tree "$tmp/c-dev"; printf '\n[dev-dependencies]\nbrokerd.workspace = true\n' >> "$tmp/c-dev/crates/loopd/Cargo.toml"
expect fail "role dev-depends on another role" check-crate-deps.sh "$tmp/c-dev"
tree "$tmp/c-proto"; manifest "$tmp/c-proto/crates/proto" proto 'loopd.workspace = true'
expect fail "proto depends on a role" check-crate-deps.sh "$tmp/c-proto"
# A dependency can also be written as its own table: [dependencies.NAME]
tree "$tmp/c-sect"; printf '\n[dependencies.brokerd]\npath = "../brokerd"\n' >> "$tmp/c-sect/crates/loopd/Cargo.toml"
expect fail "role depends on another role, written as a table" check-crate-deps.sh "$tmp/c-sect"
tree "$tmp/c-sectw"; printf '\n[dev-dependencies.brokerd]\nworkspace = true\n' >> "$tmp/c-sectw/crates/loopd/Cargo.toml"
expect fail "role dev-depends on another role, written as a table" check-crate-deps.sh "$tmp/c-sectw"
tree "$tmp/c-dot"; manifest "$tmp/c-dot/crates/loopd" loopd 'proto.workspace = true' 'brokerd.path = "../brokerd"'
expect fail "role depends on another role, written with a dotted key" check-crate-deps.sh "$tmp/c-dot"
tree "$tmp/c-sectok"; manifest "$tmp/c-sectok/crates/loopd" loopd; printf '\n[dependencies.proto]\nworkspace = true\n' >> "$tmp/c-sectok/crates/loopd/Cargo.toml"
expect pass "role depends on proto, written as a table" check-crate-deps.sh "$tmp/c-sectok"
# check-dep-docs.sh
tree "$tmp/d-ok"
expect pass "every dependency is documented" check-dep-docs.sh "$tmp/d-ok"
tree "$tmp/d-miss"; printf 'rand = "0.9"\n' >> "$tmp/d-miss/Cargo.toml"
expect fail "workspace dependency without a docs row" check-dep-docs.sh "$tmp/d-miss"
tree "$tmp/d-prose"; printf 'rand = "0.9"\n' >> "$tmp/d-prose/Cargo.toml"; printf '\nWe do not use rand.\n' >> "$tmp/d-prose/docs/dependencies.md"
expect fail "a mention in prose is not a table row" check-dep-docs.sh "$tmp/d-prose"
tree "$tmp/d-loose"; manifest "$tmp/d-loose/crates/loopd" loopd 'proto.workspace = true' 'rand = "0.9"'
expect fail "crate declares a dependency outside the workspace table" check-dep-docs.sh "$tmp/d-loose"
tree "$tmp/d-sect"; printf '\n[dependencies.rand]\nversion = "0.9"\n' >> "$tmp/d-sect/crates/loopd/Cargo.toml"
expect fail "table-form dependency without workspace = true" check-dep-docs.sh "$tmp/d-sect"
tree "$tmp/d-sectok"; printf '\n[dependencies.serde]\nworkspace = true\nfeatures = ["derive"]\n' >> "$tmp/d-sectok/crates/loopd/Cargo.toml"
expect pass "table-form dependency with workspace = true" check-dep-docs.sh "$tmp/d-sectok"
# A check that cannot find what it checks must fail, not pass.
mkdir -p "$tmp/empty"
expect fail "check-lines without a crates directory" check-lines.sh "$tmp/empty"
expect fail "check-crate-deps without a crates directory" check-crate-deps.sh "$tmp/empty"
expect fail "check-dep-docs without a crates directory" check-dep-docs.sh "$tmp/empty"
tree "$tmp/d-nodoc"; rm "$tmp/d-nodoc/docs/dependencies.md"
expect fail "check-dep-docs without docs/dependencies.md" check-dep-docs.sh "$tmp/d-nodoc"
if [ "$fails" -ne 0 ]; then
echo "test-gate-scripts: $fails failure(s)" >&2
exit 1
fi
echo "test-gate-scripts: ok"