Artifact b6aa8820c5a56c3ff905128ec5906f45db5a8f8fe7aad39fb2cbb8e0ba94596b:
- File
test/place.sh
— part of check-in
[75c8fde976]
at
2026-11-18 23:06:52
on branch trunk
— Instructions join per harness, and an upstream can be a local folder
A harness's instruction file is now joined from up to four suppliers, ranked: the shared one, the harness's own (an outfit with only = HARNESS), the one limited to this machine, and the machine's own for that harness. Each rank has at most one supplier; more than one rank is joined in that order, each source as it is in the store, separated by a blank line. One supplier still links straight to the store's file. So every harness can read a shared file and one harness an extra one, where an only outfit's instructions used to clash with the shared ones. The same rule holds at personal scope.
An upstream whose url is file:// and an absolute path is a local upstream. suit upstream NAME take with no FOLDER takes from it. The hourly suit tend takes every local upstream whose folder changed since its last take, and accepts it when trust = auto, so a skill whose home is one of the owner's own repositories is placed without a copy kept by hand. Changed is decided by a stamp of the folder kept in suit's home folder (path, size, mtime, inode and executable bit of each entry): an unchanged hour costs one lstat per entry and opens no file of the upstream. As with the no-change run, an edit that keeps a file's size and mtime is not seen until the next one that does not. A missing folder is one attention item that clears when it is back. The take comment names the folder, and the pin when there is one.
Three upstream usage cases changed their expected text, because take no longer needs a FOLDER.
3828 unit checks (was 3792), 625 shell cases, 1258 store cases (was 1153), 1032 placement cases (was 985), 382 project cases (was 378), 237 usage cases (was 236), 288 curate cases, 376 curate-apply cases and 172 https cases, under clang, under gcc 16, with no user name set and umask 002, and under umask 027, in one run of make gate (77 minutes). 100% coverage in all 34 source files. (user: dmestas, size: 119672) [annotate] [blame] [check-ins using]
#!/bin/sh # Shell tests for the User scope: plan, apply, status, off and run. Each case # works in a scratch HOME and SUIT_HOME under build/tmp; nothing touches the # real ~/.claude, ~/.codex or ~/.pi. # SUIT names the binary under test (default build/dev/suit). SUIT=${SUIT:-build/dev/suit} case $SUIT in /*) ;; *) SUIT=$PWD/$SUIT ;; esac ROOT=$PWD FIX=$ROOT/test/fixtures/wear WEAR_FOSSIL=$ROOT/test/fixtures/wear.fossil mkdir -p build/tmp T=$(mktemp -d "$ROOT/build/tmp/place.XXXXXX") || exit 1 trap 'rm -rf "$T"' EXIT INT TERM total=0 failed=0 pass() { total=$((total + 1)); echo "ok $1"; } bad() { total=$((total + 1)); failed=$((failed + 1)) echo "FAIL $1${2:+: $2}" } export USER=tester # world: a new scratch HOME and SUIT_HOME with the fixture as the store of "mine" world() { rm -rf "$T/home" "$T/sh" mkdir -p "$T/home" "$T/sh/store" cp -R "$FIX" "$T/sh/store/mine" export HOME="$T/home" SUIT_HOME="$T/sh" } store=$T/sh/store/mine # check NAME WANT_RC [STDERR_SUBSTRING] -- COMMAND... (output in $T/out, $T/err) check() { cname=$1; cwant=$2; cmsg=$3; shift 4 "$@" >"$T/out" 2>"$T/err"; crc=$? if [ "$crc" != "$cwant" ]; then bad "$cname" "exit $crc, want $cwant: $(cat "$T/err")" elif [ -n "$cmsg" ] && ! grep -qF -- "$cmsg" "$T/err"; then bad "$cname" "want '$cmsg' in: $(cat "$T/err")" else pass "$cname"; fi } # has NAME PATTERN: $T/out holds a line matching the fixed string has() { if grep -qF -- "$2" "$T/out"; then pass "$1"; else bad "$1" "no '$2' in: $(sed "s|$T||g" "$T/out" | head -8)"; fi; } # snap DIR: every path with its type, size, mode and, for a link, its target snap() { (cd "$1" && find . | sort | while read -r f; do if [ -L "$f" ]; then printf 'link %s -> %s\n' "$f" "$(readlink "$f")" elif [ "$(uname -s)" = Darwin ]; then stat -f '%HT %z %Sp %N' "$f" else stat -c '%F %s %A %n' "$f"; fi done) } # same NAME FILE_A FILE_B same() { if cmp -s "$2" "$3"; then pass "$1"; else bad "$1" "$2 differs from $3"; fi; } # ---- apply puts every asset where each harness reads it ------------------------ world snap "$T/home" > "$T/home-before" check apply-succeeds 0 "" -- "$SUIT" apply for h in .claude .codex .pi/agent; do for s in doppler norman ousterhout tdd-red tdd-green; do same "apply-skill-$s-in-$h" "$T/home/$h/skills/$s/SKILL.md" "$store/skills/$s/SKILL.md" done done same apply-claude-agent-reviewer "$T/home/.claude/agents/reviewer.md" "$store/agents/reviewer.md" same apply-claude-agent-implementer "$T/home/.claude/agents/implementer.md" "$store/agents/implementer.md" same apply-claude-command "$T/home/.claude/commands/review.md" "$store/commands/review.md" same apply-codex-prompt "$T/home/.codex/prompts/review.md" "$store/commands/review.md" same apply-pi-prompt "$T/home/.pi/agent/prompts/review.md" "$store/commands/review.md" same apply-claude-instructions "$T/home/.claude/CLAUDE.md" "$store/instructions/user.md" same apply-codex-instructions "$T/home/.codex/AGENTS.md" "$store/instructions/user.md" same apply-pi-instructions "$T/home/.pi/agent/AGENTS.md" "$store/instructions/user.md" [ ! -e "$T/home/.claude/skills/unused" ] && pass apply-skips-an-asset-no-outfit-wears || bad apply-skips-an-asset-no-outfit-wears [ ! -e "$T/home/.codex/agents" ] && [ ! -e "$T/home/.pi/agent/agents" ] && pass apply-makes-no-folder-for-a-kind-a-harness-lacks || bad apply-makes-no-folder-for-a-kind-a-harness-lacks [ -L "$T/home/.claude/skills/doppler" ] && [ "$(readlink "$T/home/.claude/skills/doppler")" = "$store/skills/doppler" ] && pass apply-links-a-skill-to-its-folder || bad apply-links-a-skill-to-its-folder "$SUIT" apply > "$T/out" 2>&1 sed "s|$T/home|~|g; s|$T/sh|S|g" "$T/out" > "$T/out.rel" if grep -q '^+ link' "$T/out.rel"; then bad apply-again-makes-no-links; else pass apply-again-makes-no-links; fi has apply-again-still-lists-the-skipped "~ skipped codex agents reviewer (no folder)" # -- one edit, visible through every harness with no command run printf 'one more line\n' >> "$store/instructions/user.md" for f in .claude/CLAUDE.md .codex/AGENTS.md .pi/agent/AGENTS.md; do tail -1 "$T/home/$f" | grep -qx "one more line" && pass "edit-visible-through-$f" || bad "edit-visible-through-$f" done # -- off leaves HOME as it was check off-succeeds 0 "" -- "$SUIT" off snap "$T/home" > "$T/home-after" if cmp -s "$T/home-before" "$T/home-after"; then pass off-leaves-home-as-it-was; else bad off-leaves-home-as-it-was "$(diff "$T/home-before" "$T/home-after" | head -5)"; fi [ ! -s "$T/sh/ledger" ] && pass off-empties-the-ledger || bad off-empties-the-ledger [ ! -e "$T/sh/stamp" ] && pass off-removes-the-stamp || bad off-removes-the-stamp [ ! -e "$T/sh/lock" ] && pass off-releases-the-lock || bad off-releases-the-lock check off-again-has-nothing-to-do 0 "" -- "$SUIT" off # ---- clashes ------------------------------------------------------------------ world mkdir -p "$T/home/.claude" "$T/home/.codex/skills" "$T/home/.pi/agent/skills/doppler" printf 'my own CLAUDE.md\n' > "$T/home/.claude/CLAUDE.md" printf 'in the way\n' > "$T/home/.pi/agent/skills/doppler/mine.txt" ln -s /elsewhere "$T/home/.codex/skills/norman" printf 'other\n' > "$T/home/.codex/AGENTS.md" snap "$T/home" > "$T/clash-before" "$SUIT" plan > "$T/out" 2>&1 sed "s|$T/home|~|g" "$T/out" > "$T/out.rel" grep -qF "! clash ~/.claude/CLAUDE.md (a real file)" "$T/out.rel" && pass plan-reports-a-real-file-clash || bad plan-reports-a-real-file-clash grep -qF "! clash ~/.pi/agent/skills/doppler (a real folder)" "$T/out.rel" && pass plan-reports-a-real-folder-clash || bad plan-reports-a-real-folder-clash grep -qF "! clash ~/.codex/skills/norman (someone else's link)" "$T/out.rel" && pass plan-reports-someone-elses-link-clash || bad plan-reports-someone-elses-link-clash snap "$T/home" > "$T/plan-after" cmp -s "$T/clash-before" "$T/plan-after" && pass plan-changes-nothing || bad plan-changes-nothing [ ! -e "$T/sh/ledger" ] && pass plan-writes-no-ledger || bad plan-writes-no-ledger check apply-with-clashes 0 "" -- "$SUIT" apply [ "$(cat "$T/home/.claude/CLAUDE.md")" = "my own CLAUDE.md" ] && [ ! -L "$T/home/.claude/CLAUDE.md" ] && pass real-file-left-byte-identical || bad real-file-left-byte-identical [ "$(cat "$T/home/.pi/agent/skills/doppler/mine.txt")" = "in the way" ] && [ ! -L "$T/home/.pi/agent/skills/doppler" ] && pass real-folder-left-alone || bad real-folder-left-alone [ "$(readlink "$T/home/.codex/skills/norman")" = "/elsewhere" ] && pass someone-elses-link-left-alone || bad someone-elses-link-left-alone [ "$(cat "$T/home/.codex/AGENTS.md")" = "other" ] && pass second-real-file-left-alone || bad second-real-file-left-alone grep -q "$T/home/.claude/CLAUDE.md" "$T/sh/ledger" && bad clash-is-not-in-the-ledger || pass clash-is-not-in-the-ledger [ -L "$T/home/.claude/skills/doppler" ] && pass the-rest-is-placed-around-the-clashes || bad the-rest-is-placed-around-the-clashes "$SUIT" apply > "$T/out" 2>&1 sed "s|$T/home|~|g" "$T/out" | grep -qF "! clash ~/.claude/CLAUDE.md (a real file)" && pass apply-reports-the-clash-again || bad apply-reports-the-clash-again check off-with-clashes 0 "" -- "$SUIT" off has off-reports-nothing-it-did-not-make "- link" snap "$T/home" > "$T/clash-after" cmp -s "$T/clash-before" "$T/clash-after" && pass off-leaves-home-as-it-was-with-clashes || bad off-leaves-home-as-it-was-with-clashes "$(diff "$T/clash-before" "$T/clash-after" | head -5)" # ---- removing an asset removes its link and nothing else ------------------------ world "$SUIT" apply >/dev/null 2>&1 snap "$T/home" > "$T/all-links" sed 's/^agents = reviewer implementer/agents = reviewer/' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" check apply-after-removing-an-agent 0 "" -- "$SUIT" apply has apply-prints-the-removal "- link $T/home/.claude/agents/implementer.md" [ ! -e "$T/home/.claude/agents/implementer.md" ] && [ -L "$T/home/.claude/agents/reviewer.md" ] && pass removed-asset-link-is-gone-and-the-rest-stays || bad removed-asset-link-is-gone-and-the-rest-stays snap "$T/home" > "$T/one-less" if [ "$(diff "$T/all-links" "$T/one-less" | grep -c '^[<>] link')" = 1 ]; then pass only-that-link-changed; else bad only-that-link-changed "$(diff "$T/all-links" "$T/one-less")"; fi # A link someone else changed is not ours to remove. sed 's/^agents = reviewer$/agents = reviewer implementer/' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" "$SUIT" apply >/dev/null 2>&1 rm "$T/home/.claude/agents/implementer.md"; ln -s /not/ours "$T/home/.claude/agents/implementer.md" sed 's/^agents = reviewer implementer/agents = reviewer/' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" "$SUIT" apply > "$T/out" 2>&1 sed "s|$T/home|~|g" "$T/out" | grep -qF "! clash ~/.claude/agents/implementer.md (someone else's link)" && pass stale-entry-someone-replaced-is-a-clash || bad stale-entry-someone-replaced-is-a-clash "$(cat "$T/out" | head -3)" [ "$(readlink "$T/home/.claude/agents/implementer.md")" = "/not/ours" ] && pass stale-clash-leaves-the-disk-alone || bad stale-clash-leaves-the-disk-alone grep -q "agents/implementer.md" "$T/sh/ledger" && bad stale-clash-drops-the-ledger-entry || pass stale-clash-drops-the-ledger-entry # ---- only, include, globs, skipped, and the same destination -------------------- world cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills agents.user = ~/.claude/agents [harness codex] skills.user = ~/.codex/skills [outfit base] skills = ousterhout [outfit mid] include = base skills = tdd-* [outfit claude-only] only = claude include = mid agents = reviewer skills = doppler [wear user] outfits = claude-only EOF "$SUIT" plan > "$T/out" 2>&1 sed -i.bak "s|$T/home|~|g; s|$T/sh/store/mine|S|g" "$T/out" for want in "+ link ~/.claude/skills/doppler -> S/skills/doppler" "+ link ~/.claude/skills/tdd-red -> S/skills/tdd-red" "+ link ~/.claude/skills/tdd-green -> S/skills/tdd-green" "+ link ~/.claude/skills/ousterhout -> S/skills/ousterhout" "+ link ~/.claude/agents/reviewer.md -> S/agents/reviewer.md" "+ link ~/.codex/skills/ousterhout -> S/skills/ousterhout" "+ link ~/.codex/skills/tdd-red -> S/skills/tdd-red"; do grep -qxF -- "$want" "$T/out" && pass "plan-has-[$want]" || bad "plan-has-[$want]" "$(cat "$T/out")" done # The outfit named by the wear says only = claude; what it includes does not # inherit that, so codex still gets what base and mid give it, but not doppler. grep -q "codex/skills/doppler" "$T/out" && bad only-keeps-codex-from-the-claude-only-skill || pass only-keeps-codex-from-the-claude-only-skill grep -q "^~ skipped codex agents" "$T/out" && bad only-outfit-agents-are-not-skipped-for-codex || pass only-outfit-agents-are-not-skipped-for-codex cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o [outfit o] skills = zzz-* EOF check glob-matching-nothing-is-an-error 1 "outfit o: skills 'zzz-*' matches nothing in the store" -- "$SUIT" plan cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o [outfit o] skills = nosuch EOF check missing-name-is-an-error 1 "outfit o: skills 'nosuch' matches nothing in the store" -- "$SUIT" plan cat > "$store/suit.conf" <<'EOF' [harness claude] instructions.user = ~/.claude/CLAUDE.md [wear user] outfits = a b [outfit a] instructions = instructions/user.md [outfit b] instructions = files/tts/voices.json EOF check same-destination-two-sources-is-an-error 1 "two assets want $T/home/.claude/CLAUDE.md: $store/files/tts/voices.json and $store/instructions/user.md" -- "$SUIT" plan cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = a b [outfit a] skills = doppler [outfit b] skills = doppler EOF "$SUIT" plan > "$T/out" 2>&1; [ "$(grep -c '^+ link' "$T/out")" = 1 ] && pass same-source-twice-is-one-placement || bad same-source-twice-is-one-placement "$(cat "$T/out")" cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o [outfit o] instructions = nosuch.md file ~/f = files/missing EOF check an-asset-the-store-lacks-is-an-error 1 "which is not in the store" -- "$SUIT" plan cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o [outfit o] slot hook/Stop = files/tts/announce.sh file ~/.claude/tts-voices.json = files/tts/voices.json EOF check slot-and-file-apply 0 "" -- "$SUIT" apply [ "$(readlink "$T/sh/slots/hook/Stop")" = "$store/files/tts/announce.sh" ] && [ "$(readlink "$T/home/.claude/tts-voices.json")" = "$store/files/tts/voices.json" ] && pass slot-and-file-are-linked || bad slot-and-file-are-linked "$SUIT" off >/dev/null 2>&1 [ ! -e "$T/sh/slots" ] && [ ! -e "$T/home/.claude" ] && pass off-removes-the-folders-it-made || bad off-removes-the-folders-it-made "$(ls -R "$T/sh" "$T/home" | head)" # ---- a reader never sees a link missing while it is replaced -------------------- world mkdir -p "$store/files" printf 'A\n' > "$store/files/a" printf 'B\n' > "$store/files/b" { printf '[harness h]\nskills.user = ~/s\n[wear user]\noutfits = o\n[outfit o]\n' i=0; while [ $i -lt 120 ]; do printf 'file ~/links/f%d = files/a\n' $i; i=$((i + 1)); done; } > "$store/suit.conf" "$SUIT" apply >/dev/null 2>&1 sed 's|= files/a$|= files/b|' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" SUIT_FAULT=symlink:1:delay "$SUIT" apply >/dev/null 2>&1 & updater=$! missing=0; looks=0; flips=0 while kill -0 "$updater" 2>/dev/null; do i=0 while [ $i -lt 120 ]; do got=$(cat "$T/home/links/f$i" 2>/dev/null) looks=$((looks + 1)) case $got in A|B) ;; *) missing=$((missing + 1)) ;; esac i=$((i + 7)) done done wait "$updater"; urc=$? if [ "$urc" -eq 0 ] && [ "$missing" -eq 0 ] && [ "$looks" -gt 20 ]; then pass reader-never-sees-a-link-missing; else bad reader-never-sees-a-link-missing "apply $urc, $missing of $looks looks found nothing"; fi echo " (a reader looked $looks times)" [ "$(cat "$T/home/links/f0")" = B ] && [ "$(cat "$T/home/links/f119")" = B ] && pass replaced-links-point-at-the-new-source || bad replaced-links-point-at-the-new-source # ---- two suits at once ------------------------------------------------------------ world SUIT_FAULT=symlink:1:delay "$SUIT" apply >/dev/null 2>&1 & first=$! i=0; while [ ! -e "$T/sh/lock" ] && [ $i -lt 200 ]; do sleep 0.05; i=$((i + 1)); done check second-suit-waits-then-finds-nothing-to-do 0 "" -- "$SUIT" apply wait "$first"; frc=$? [ "$frc" -eq 0 ] && pass first-suit-finishes || bad first-suit-finishes "exit $frc" [ ! -e "$T/sh/lock" ] && pass lock-is-released || bad lock-is-released "$SUIT" plan > "$T/out" 2>&1 [ "$(grep -c '^[+!-]' "$T/out")" = 0 ] && pass ledger-is-intact-after-two-suits || bad ledger-is-intact-after-two-suits "$(cat "$T/out" | head -3)" world printf '%s\n' "$$" > "$T/sh/lock" check lock-held-by-a-live-process-is-busy 20 "another suit holds the lock" -- "$SUIT" apply [ ! -e "$T/home/.claude" ] && pass busy-apply-changes-nothing || bad busy-apply-changes-nothing check off-while-locked-is-busy 20 "another suit holds the lock" -- "$SUIT" off printf 'garbage\n' > "$T/sh/lock" check lock-with-garbage-is-busy 20 "another suit holds the lock" -- "$SUIT" apply dead=$(sh -c 'echo $$') printf '%s\n' "$dead" > "$T/sh/lock" check stale-lock-is-taken-over 0 "" -- "$SUIT" apply [ ! -e "$T/sh/lock" ] && pass stale-lock-taken-over-is-then-released || bad stale-lock-taken-over-is-then-released printf '%s\n' "$dead" > "$T/sh/lock" check lock-owner-unreadable-is-retried 0 "" -- env SUIT_FAULT=open:2 "$SUIT" off rm -f "$T/sh/lock" check lock-open-fails 1 "cannot take the lock" -- env SUIT_FAULT=open:1:EACCES "$SUIT" apply check lock-write-fails 1 "cannot write the lock" -- env SUIT_FAULT=write:1 "$SUIT" apply [ ! -e "$T/sh/lock" ] && pass failed-lock-write-leaves-no-lock || bad failed-lock-write-leaves-no-lock # ---- status and run, on a store opened from the fixture wardrobe ---------------- # fworld: like world, but the store is a real working copy of wear.fossil fworld() { rm -rf "$T/home" "$T/sh" mkdir -p "$T/home" "$T/sh/wardrobes" cp "$WEAR_FOSSIL" "$T/sh/wardrobes/mine.fossil" export HOME="$T/home" SUIT_HOME="$T/sh" "$SUIT" store open mine >/dev/null 2>&1 } FRONT=$(dirname "$SUIT")/suit-run fworld check apply-on-an-opened-store 0 "" -- "$SUIT" apply check status-succeeds 0 "" -- "$SUIT" status has status-names-the-store-version "store mine at " has status-counts-skill-links "links claude skills 5" has status-counts-codex-prompts "links codex commands 1" has status-counts-pi-instructions "links pi instructions 1" has status-lists-what-was-skipped "skipped codex agents reviewer (no folder)" grep -q '^clash\|^missing' "$T/out" && bad status-has-no-clash-or-missing-when-clean "$(grep '^clash\|^missing' "$T/out")" || pass status-has-no-clash-or-missing-when-clean rm "$T/home/.claude/commands/review.md" "$SUIT" status > "$T/out" 2>&1 has status-lists-a-missing-link "missing $T/home/.claude/commands/review.md" "$SUIT" apply >/dev/null 2>&1 [ -L "$T/home/.claude/commands/review.md" ] && pass apply-puts-a-missing-link-back || bad apply-puts-a-missing-link-back rm "$T/home/.codex/AGENTS.md"; printf 'mine\n' > "$T/home/.codex/AGENTS.md" "$SUIT" status > "$T/out" 2>&1 has status-lists-a-clash "clash $T/home/.codex/AGENTS.md (a real file)" # run: nothing changed is silent; a change in the store is applied fworld check run-with-no-stamp-says-so 11 "no stamp" -- "$SUIT" run "$SUIT" apply >/dev/null 2>&1 check run-unchanged-exits-0 0 "" -- "$SUIT" run [ ! -s "$T/out" ] && pass run-unchanged-is-silent || bad run-unchanged-is-silent "$(cat "$T/out")" printf 'one more line\n' >> "$T/sh/store/mine/instructions/user.md" sed 's/^agents = reviewer implementer/agents = reviewer/' "$T/sh/store/mine/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$T/sh/store/mine/suit.conf" check run-after-an-edit-applies-and-exits-0 0 "" -- "$SUIT" run [ ! -e "$T/home/.claude/agents/implementer.md" ] && pass run-applied-the-change || bad run-applied-the-change check run-again-is-unchanged 0 "" -- "$SUIT" compare sed 's/^agents = reviewer$/agents = reviewer implementer/' "$T/sh/store/mine/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$T/sh/store/mine/suit.conf" check timer-program-applies-a-change 0 "" -- "$FRONT" [ -L "$T/home/.claude/agents/implementer.md" ] && pass timer-program-put-the-link-back || bad timer-program-put-the-link-back check timer-program-then-finds-nothing 0 "" -- "$FRONT" "$SUIT" off >/dev/null 2>&1 check run-after-off-says-no-stamp 11 "no stamp" -- "$SUIT" run # a store that cannot be applied is reported, and the disk is left alone fworld rm "$T/sh/store/mine/suit.conf" check apply-with-no-config 1 "store:0: no wardrobe with a suit.conf" -- "$SUIT" apply check status-with-no-config 1 "store:0: no wardrobe with a suit.conf" -- "$SUIT" status [ ! -e "$T/home/.claude" ] && pass no-config-changes-nothing || bad no-config-changes-nothing cp "$FIX/suit.conf" "$T/sh/store/mine/suit.conf" printf 'garbage\n' > "$T/sh/ledger" check a-bad-ledger-is-reported 1 "ledger:1: expected 'link DEST SOURCE', 'dir DEST', 'file DEST' or 'block DEST'" -- "$SUIT" plan check off-refuses-a-ledger-it-cannot-read 1 "ledger:1:" -- "$SUIT" off [ ! -e "$T/home/.claude" ] && pass a-bad-ledger-changes-nothing || bad a-bad-ledger-changes-nothing : > "$T/sh/ledger" touch "$T/sh/mine.journal" check a-journal-stops-plan 15 "" -- "$SUIT" plan check a-journal-stops-apply 15 "" -- "$SUIT" apply check a-journal-stops-status 15 "" -- "$SUIT" status rm -f "$T/sh/mine.journal" # ---- paths, limits and failed calls the commands must report -------------------- # longstr N: N letters a longstr() { awk -v n="$1" 'BEGIN { for (i = 0; i < n; i++) printf "a" }'; } world check plan-without-home 1 "HOME is not set, or too long" -- env -u HOME "$SUIT" plan check apply-without-home 1 "HOME is not set, or too long" -- env -u HOME "$SUIT" apply check off-without-home 1 "HOME is not set, or too long" -- env -u HOME "$SUIT" off check plan-with-long-home 1 "HOME is not set, or too long" -- env HOME="/$(longstr 4100)" "$SUIT" plan check plan-with-long-suit-home 1 "SUIT_HOME is longer than 3456 bytes" -- env SUIT_HOME="/$(longstr 3600)" "$SUIT" plan check off-with-too-long-suit-home 1 "home path is longer than" -- env SUIT_HOME="/$(longstr 4090)" "$SUIT" off check off-with-empty-home-and-no-suit-home 1 "neither SUIT_HOME nor HOME is set" -- env -u SUIT_HOME HOME= "$SUIT" off # the store holds things that are not assets world mkdir "$store/skills/.hidden-skill" "$store/agents/.hidden.md" : > "$store/agents/.hidden-agent.md" : > "$store/skills/loose-file" mkdir "$store/agents/folder-not-file.md" : > "$store/agents/notes.txt" : > "$store/agents/ab" check store-with-other-entries-plans 0 "" -- "$SUIT" plan has other-entries-agent-still-placed "agents/reviewer.md" if grep -qE 'hidden|loose-file|folder-not-file|notes\.txt|agents/ab' "$T/out"; then bad other-entries-are-not-assets "$(grep -E 'hidden|loose-file|folder-not|notes|ab$' "$T/out" | head -3)"; else pass other-entries-are-not-assets; fi # the store holds more than the limits world (cd "$store/skills" && awk 'BEGIN { for (i = 0; i < 2049; i++) print "s" i }' | xargs mkdir) check too-many-assets 1 "the store has too many skills (limit 2048" -- "$SUIT" plan world (cd "$store/agents" && awk 'BEGIN { n = sprintf("%240s", ""); gsub(/ /, "n", n); for (i = 0; i < 600; i++) printf "%s%04d.md\n", n, i }' | xargs touch) check too-many-bytes-of-asset-names 1 "bytes of names)" -- "$SUIT" plan # a folder that cannot be read world rm -rf "$store/commands" check store-without-a-folder-of-assets 1 "commands 'review' matches nothing in the store" -- "$SUIT" plan check store-folder-unreadable 1 "cannot read $store/skills" -- env SUIT_FAULT=listdir:2:EACCES "$SUIT" plan check store-folder-unreadable-on-apply 1 "cannot read $store/agents" -- env SUIT_FAULT=listdir:3:EACCES "$SUIT" apply # the ledger world : > "$T/sh/ledger" check ledger-open-fails 1 "ledger:0: cannot open" -- env SUIT_FAULT=open:3:EACCES "$SUIT" plan # The C library words errno 5 its own way. Ask the binary under test. EIO=$(SUIT_FAULT=open:1 "$SUIT" check test/fixtures/example.conf 2>&1 | sed -n 's/.*cannot open: //p') [ -n "$EIO" ] || { echo "FAIL cannot learn the errno wording"; exit 1; } check ledger-read-fails 1 "ledger:0: cannot read" -- env SUIT_FAULT=read:3 "$SUIT" plan check ledger-read-interrupted-is-retried 0 "" -- env SUIT_FAULT=read:3:EINTR "$SUIT" plan awk 'BEGIN { for (i = 0; i < 1048577; i++) printf "#"; }' > "$T/sh/ledger" check ledger-over-the-limit 1 "file is over the limit of 1048576 bytes" -- "$SUIT" plan rm "$T/sh/ledger" # what the no-change run watches, and the limits on it world check apply-before-watch-cases 0 "" -- "$SUIT" apply check stamp-write-fails 1 "cannot write $T/sh/stamp" -- env SUIT_FAULT=rename:3 "$SUIT" apply check watched-folder-unreadable 1 "cannot read $store" -- env SUIT_FAULT=listdir:6:EACCES "$SUIT" apply mkdir -p "$store/sub/deeper" : > "$store/.suit-tmp.leftover" check watch-skips-a-checkout-leftover 0 "" -- "$SUIT" apply mkdir "$store/many" (cd "$store/many" && awk 'BEGIN { for (i = 0; i < 8200; i++) print "f" i }' | xargs touch) check too-many-files-to-watch 0 "" -- "$SUIT" apply grep -q "$store/many/" "$T/sh/stamp" && bad many-files-are-not-watched || pass many-files-are-not-watched rm -rf "$store/many" mkdir "$store/long" (cd "$store/long" && awk 'BEGIN { n = sprintf("%250s", ""); gsub(/ /, "n", n); for (i = 0; i < 7000; i++) printf "%s%04d\n", n, i }' | xargs touch) check too-many-bytes-to-watch 0 "" -- "$SUIT" apply grep -q "$store/long/" "$T/sh/stamp" && bad long-names-are-not-watched || pass long-names-are-not-watched rm -rf "$store/long" deep=$store/d i=0 while [ $i -lt 66 ]; do deep=$deep/d; i=$((i + 1)); done mkdir -p "$deep" check folders-nested-too-deep 0 "" -- "$SUIT" apply rm -rf "$store/d" # config files that reach every corner of resolve world cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills instructions.user = ~/.claude/CLAUDE.md [harness codex] skills.user = ~/.codex/skills instructions.user = ~/.codex/AGENTS.md [outfit abc] skills = norman [outfit ab] include = abc [outfit a] include = abc only = claude instructions = instructions/user.md [outfit b] include = abc [wear user] outfits = a b a ab [wear shared example.com:team/repo] outfits = b EOF check outfits-prefix-repeat-and-other-scopes 0 "" -- "$SUIT" plan has instructions-only-for-the-claude-outfit "$T/home/.claude/CLAUDE.md" if grep -q 'AGENTS.md' "$T/out"; then bad instructions-skip-the-other-harness; else pass instructions-skip-the-other-harness; fi has skill-placed-once-for-codex "$T/home/.codex/skills/norman" cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [outfit a] file ~x/voices.json = files/tts/voices.json [wear user] outfits = a EOF check a-tilde-name-is-not-the-home-folder 1 "~x/voices.json is not an absolute path" -- "$SUIT" plan cat > "$store/suit.conf" <<'EOF' [harness claude] instructions.user = ~/.claude/CLAUDE.md [outfit a] instructions = instructions/my file.md [wear user] outfits = a EOF check an-instructions-path-with-a-space 1 "a space in" -- "$SUIT" plan # ---- status --------------------------------------------------------------------- # real_world: a world whose store is a real working copy made by `store open` real_world() { rm -rf "$T/home" "$T/sh" mkdir -p "$T/home" "$T/sh/wardrobes" cp "$WEAR_FOSSIL" "$T/sh/wardrobes/mine.fossil" export HOME="$T/home" SUIT_HOME="$T/sh" "$SUIT" store open mine >/dev/null 2>&1 } real_world check status-before-apply 0 "" -- "$SUIT" status grep -q '^store mine at [0-9a-f]\{12\}$' "$T/out" && pass status-says-the-store-version || bad status-says-the-store-version "$(head -2 "$T/out")" "$SUIT" apply >/dev/null 2>&1 check status-after-apply 0 "" -- "$SUIT" status for want in "links claude skills 5" "links claude agents 2" "links claude commands 1" "links claude instructions 1" "links codex skills 5" "links codex commands 1" "links codex instructions 1" "links pi skills 5" "links pi commands 1" "links pi instructions 1" "skipped codex agents reviewer (no folder)" "skipped pi agents implementer (no folder)" "machine studio: not this machine (this machine has no name)"; do has "status-has-[$want]" "$want" done grep -q '^clash\|^missing' "$T/out" && bad status-with-nothing-wrong-reports-no-clash-or-missing || pass status-with-nothing-wrong-reports-no-clash-or-missing rm "$T/home/.claude/skills/norman" rm -r "$T/home/.codex/skills"; printf 'a file where a folder was\n' > "$T/home/.codex/skills" mv "$T/home/.pi/agent/AGENTS.md" "$T/home/pi-agents-moved"; printf 'mine\n' > "$T/home/.pi/agent/AGENTS.md" check status-with-trouble 0 "" -- "$SUIT" status has status-lists-a-missing-link "missing $T/home/.claude/skills/norman" grep -q "^missing $T/home/.codex/skills/" "$T/out" && bad status-does-not-call-a-blocked-path-missing || pass status-does-not-call-a-blocked-path-missing has status-lists-a-clash "clash $T/home/.pi/agent/AGENTS.md (a real file)" has status-counts-fewer-links "links claude skills 4" real_world rm -f "$T/sh/store/mine/.fslckout" check status-without-an-open-store 1 "open the working copy failed" -- "$SUIT" status touch "$T/sh/mine.journal" check status-with-an-unfinished-update 15 "store mine has an unfinished update" -- "$SUIT" status check plan-with-an-unfinished-update 15 "unfinished update" -- "$SUIT" plan check apply-with-an-unfinished-update 15 "unfinished update" -- "$SUIT" apply rm -f "$T/sh/mine.journal" # ---- run ------------------------------------------------------------------------ world check run-with-no-stamp 11 "no stamp at" -- "$SUIT" run "$SUIT" apply >/dev/null 2>&1 check run-with-nothing-changed 0 "" -- "$SUIT" run [ ! -s "$T/out" ] && [ ! -s "$T/err" ] && pass run-with-nothing-changed-is-silent || bad run-with-nothing-changed-is-silent snap "$T/home" > "$T/run-before" check compare-with-nothing-changed 0 "" -- "$SUIT" compare mkdir "$store/skills/tdd-blue"; printf 'blue\n' > "$store/skills/tdd-blue/SKILL.md" check compare-sees-a-new-skill-folder 10 "" -- "$SUIT" compare has compare-names-the-changed-path "changed: $store/skills" check run-applies-what-changed 0 "" -- "$SUIT" run has run-prints-what-it-did "+ link $T/home/.claude/skills/tdd-blue" [ -L "$T/home/.claude/skills/tdd-blue" ] && [ -L "$T/home/.pi/agent/skills/tdd-blue" ] && pass run-linked-the-new-skill-everywhere || bad run-linked-the-new-skill-everywhere check run-again-has-nothing-to-do 0 "" -- "$SUIT" run [ ! -s "$T/out" ] && pass run-again-is-silent || bad run-again-is-silent printf 'edited\n' >> "$store/agents/reviewer.md" check compare-sees-an-edited-file 0 "" -- "$SUIT" compare check run-after-an-edit 0 "" -- "$SUIT" run "$SUIT" compare >/dev/null 2>&1; [ $? -eq 0 ] && pass run-restamps-after-applying || bad run-restamps-after-applying sed 's/^commands = review$/commands = review\nfile ~\/note = files\/tts\/voices.json/' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" "$SUIT" run >/dev/null 2>&1; [ -L "$T/home/note" ] && pass run-sees-a-config-change || bad run-sees-a-config-change rm "$T/sh/ledger" check compare-sees-the-ledger-go 10 "" -- "$SUIT" compare # ---- what the no-change run watches ---------------------------------------------- # The stamp lists what can change what apply places (docs/decisions.md, # 2026-11-17), not each file in the store: an edit the placed link already shows # is no reason to apply. # changes NAME: suit compare says something changed; suit-run then applies, and # the compare after it finds nothing changes() { check "$1-is-a-change" 10 "" -- "$SUIT" compare check "$1-suit-run-applies" 0 "" -- "$FRONT" check "$1-then-no-change" 0 "" -- "$SUIT" compare } # unchanged NAME: suit compare finds nothing to apply unchanged() { check "$1-is-no-change" 0 "" -- "$SUIT" compare; } # shows NAME LINK TEXT: the file at LINK, read through the placed link, holds TEXT shows() { if grep -qxF -- "$3" "$2"; then pass "$1"; else bad "$1" "no '$3' in $2"; fi; } is() { if [ -L "$2" ] && [ "$(readlink "$2")" = "$3" ]; then pass "$1"; else bad "$1" "$2 -> $(readlink "$2" 2>/dev/null)"; fi; } world "$SUIT" machine studio >/dev/null 2>&1 mkdir -p "$store/needs"; printf 'do it\n' > "$store/needs/n1.md" printf '[need claude n1]\nprompt = needs/n1.md\ndone = /nonexistent-file exists\n' >> "$store/suit.conf" check watch-apply 0 "" -- "$SUIT" apply [ "$(head -1 "$T/sh/stamp")" = "suit stamp 2" ] && pass watch-stamp-starts-with-its-format || bad watch-stamp-starts-with-its-format "$(head -1 "$T/sh/stamp")" grep -q "^[-0-9 ]* $store/skills/." "$T/sh/stamp" && bad watch-stamp-lists-nothing-inside-the-skills-folder "$(grep "$store/skills/." "$T/sh/stamp" | head -3)" || pass watch-stamp-lists-nothing-inside-the-skills-folder for want in "$T/sh/store" "$store" "$store/suit.conf" "$store/skills" "$store/agents" "$store/commands" "$store/instructions/user.md" "$store/files/tts/announce.sh" "$store/files/tts/voices.json" "$store/needs/n1.md" "$T/sh/ledger" "$T/sh/machine" "$T/sh/projects"; do grep -q " $want\$" "$T/sh/stamp" && pass "watch-stamp-lists-[${want#"$T"/}]" || bad "watch-stamp-lists-[${want#"$T"/}]" done n=$(grep -vc '^suit stamp ' "$T/sh/stamp") [ "$n" -lt 30 ] && pass watch-stamp-is-short || bad watch-stamp-is-short "$n paths" unchanged watch-nothing-done # edits the placed links already show printf 'more red\n' >> "$store/skills/tdd-red/SKILL.md" unchanged watch-skill-edited-in-place shows watch-skill-edit-shows-through-the-link "$T/home/.claude/skills/tdd-red/SKILL.md" "more red" printf 'extra\n' > "$store/skills/tdd-red/extra.md" unchanged watch-file-added-inside-a-skill shows watch-added-file-shows-through-the-link "$T/home/.claude/skills/tdd-red/extra.md" extra rm "$store/skills/tdd-red/extra.md" unchanged watch-file-removed-inside-a-skill [ ! -e "$T/home/.claude/skills/tdd-red/extra.md" ] && pass watch-removed-file-is-gone-through-the-link || bad watch-removed-file-is-gone-through-the-link mkdir "$store/skills/tdd-red/sub"; printf 'deep\n' > "$store/skills/tdd-red/sub/deep.md" unchanged watch-subfolder-added-inside-a-skill shows watch-subfolder-shows-through-the-link "$T/home/.claude/skills/tdd-red/sub/deep.md" deep printf 'saved\n' > "$store/skills/tdd-red/.suit-tmp.save"; mv "$store/skills/tdd-red/.suit-tmp.save" "$store/skills/tdd-red/SKILL.md" unchanged watch-atomic-save-inside-a-skill shows watch-atomic-save-shows-through-the-link "$T/home/.claude/skills/tdd-red/SKILL.md" saved printf 'elsewhere\n' > "$T/elsewhere.md"; ln -s "$T/elsewhere.md" "$store/skills/tdd-red/ref.md" unchanged watch-link-added-inside-a-skill printf 'elsewhere two\n' >> "$T/elsewhere.md" unchanged watch-target-of-a-link-inside-a-skill-edited shows watch-link-inside-a-skill-shows-the-edit "$T/home/.claude/skills/tdd-red/ref.md" "elsewhere two" printf 'more review\n' >> "$store/agents/reviewer.md" unchanged watch-agent-edited-in-place shows watch-agent-edit-shows-through-the-link "$T/home/.claude/agents/reviewer.md" "more review" printf 'draft\n' > "$store/instructions/draft.md" unchanged watch-a-file-no-config-names-appears rm "$store/instructions/draft.md" unchanged watch-a-file-no-config-names-goes # changes apply acts on printf '# an edit\n' >> "$store/suit.conf" changes watch-config-edited mkdir "$store/skills/tdd-blue"; printf 'blue\n' > "$store/skills/tdd-blue/SKILL.md" changes watch-skill-folder-added is watch-skills-star-places-the-new-folder "$T/home/.claude/skills/tdd-blue" "$store/skills/tdd-blue" rm -r "$store/skills/tdd-blue" changes watch-skill-folder-removed [ ! -L "$T/home/.claude/skills/tdd-blue" ] && pass watch-removed-skill-is-unlinked || bad watch-removed-skill-is-unlinked rm -r "$store/skills/tdd-red"; printf 'not a folder\n' > "$store/skills/tdd-red" changes watch-skill-folder-replaced-by-a-file [ ! -L "$T/home/.claude/skills/tdd-red" ] && pass watch-skill-that-became-a-file-is-unlinked || bad watch-skill-that-became-a-file-is-unlinked rm "$store/skills/tdd-red"; mkdir "$store/skills/tdd-red"; printf 'red\n' > "$store/skills/tdd-red/SKILL.md" changes watch-skill-folder-back printf 'new agent\n' > "$store/agents/extra.md" changes watch-agent-added mv "$store/agents/extra.md" "$store/agents/extra2.md" changes watch-agent-renamed rm "$store/agents/extra2.md" changes watch-agent-removed cp "$store/agents/reviewer.md" "$store/agents/.suit-tmp.save"; printf 'saved\n' >> "$store/agents/.suit-tmp.save" mv "$store/agents/.suit-tmp.save" "$store/agents/reviewer.md" changes watch-agent-saved-by-rename-is-a-harmless-change shows watch-agent-saved-by-rename-shows-through-the-link "$T/home/.claude/agents/reviewer.md" saved mkdir -p "$T/outside/tdd-ext"; printf 'ext\n' > "$T/outside/tdd-ext/SKILL.md" ln -s "$T/outside/tdd-ext" "$store/skills/tdd-ext" changes watch-linked-skill-added is watch-linked-skill-is-placed "$T/home/.claude/skills/tdd-ext" "$store/skills/tdd-ext" grep -q " $store/skills/tdd-ext\$" "$T/sh/stamp" && pass watch-stamp-lists-a-linked-skill || bad watch-stamp-lists-a-linked-skill rm -r "$T/outside/tdd-ext" changes watch-linked-skill-target-gone [ ! -L "$T/home/.claude/skills/tdd-ext" ] && pass watch-dangling-skill-is-unlinked || bad watch-dangling-skill-is-unlinked mkdir -p "$T/outside/tdd-ext"; printf 'ext\n' > "$T/outside/tdd-ext/SKILL.md" changes watch-linked-skill-target-back rm "$store/skills/tdd-ext" changes watch-linked-skill-removed printf 'base two\n' >> "$store/instructions/user.md" changes watch-instructions-source-edited printf 'studio\n' > "$store/instructions/studio.md" sed -e 's/^outfits = voice$/outfits = voice notes/' "$store/suit.conf" > "$T/conf.new" printf '\n[outfit notes]\ninstructions = instructions/studio.md\n' >> "$T/conf.new" cp "$T/conf.new" "$store/suit.conf" changes watch-instructions-joined printf 'studio two\n' >> "$store/instructions/studio.md" changes watch-joined-source-edited shows watch-joined-file-has-the-edit "$T/sh/joined/claude" "studio two" rm "$store/files/tts/voices.json" check watch-file-source-removed-is-a-change 10 "" -- "$SUIT" compare check watch-file-source-removed-suit-run-says-so 1 "which is not in the store" -- "$FRONT" printf '{}\n' > "$store/files/tts/voices.json" changes watch-file-source-created is watch-file-source-placed-again "$T/home/.claude/tts-voices.json" "$store/files/tts/voices.json" mv "$store/files/tts/announce.sh" "$T/announce.sh" check watch-slot-source-removed-is-a-change 10 "" -- "$SUIT" compare check watch-slot-source-removed-suit-run-says-so 1 "which is not in the store" -- "$FRONT" # put back as it was (same inode and time): the failed apply changed nothing, so neither does this mv "$T/announce.sh" "$store/files/tts/announce.sh" unchanged watch-slot-source-put-back-unchanged rm "$store/files/tts/announce.sh"; printf '#!/bin/sh\n' > "$store/files/tts/announce.sh" changes watch-slot-source-created rm "$store/needs/n1.md" check watch-need-prompt-removed-is-a-change 10 "" -- "$SUIT" compare check watch-need-prompt-removed-suit-run-says-so 1 "cannot read the prompt" -- "$FRONT" printf 'do it\n' > "$store/needs/n1.md" changes watch-need-prompt-back cp "$T/sh/ledger" "$T/ledger.copy"; cat "$T/ledger.copy" > "$T/sh/ledger" changes watch-ledger-edited mkdir -p "$T/sh/store/second/skills/s2"; printf 's2\n' > "$T/sh/store/second/skills/s2/SKILL.md" printf '[outfit second-o]\nskills = *\n' > "$T/sh/store/second/suit.conf" sed 's/^outfits = core$/outfits = core second-o/' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" changes watch-second-wardrobe-appears is watch-second-wardrobe-skill-placed "$T/home/.claude/skills/s2" "$T/sh/store/second/skills/s2" mkdir "$T/sh/store/second/skills/s3"; printf 's3\n' > "$T/sh/store/second/skills/s3/SKILL.md" changes watch-skills-star-sees-a-new-folder is watch-skills-star-places-it "$T/home/.claude/skills/s3" "$T/sh/store/second/skills/s3" printf '# second\n' >> "$T/sh/store/second/suit.conf" changes watch-second-wardrobe-config-edited printf 'second edit\n' >> "$T/sh/store/second/skills/s2/SKILL.md" unchanged watch-second-wardrobe-skill-edited-in-place # a stamp the previous format wrote: a change, and the apply writes the new one tail -n +2 "$T/sh/stamp" > "$T/old-stamp"; cp "$T/old-stamp" "$T/sh/stamp" check watch-old-stamp-is-a-change 10 "" -- "$SUIT" compare has watch-old-stamp-is-named "changed: $T/sh/stamp" check watch-old-stamp-run-applies 0 "" -- "$SUIT" run [ "$(head -1 "$T/sh/stamp")" = "suit stamp 2" ] && pass watch-old-stamp-is-rewritten || bad watch-old-stamp-is-rewritten unchanged watch-after-the-old-stamp cp "$T/old-stamp" "$T/sh/stamp" changes watch-old-stamp-timer # the bound on what the stamp lists { printf '\n[outfit many]\n'; i=0; while [ $i -lt 130 ]; do printf 'file ~/many%d = files/many%d\n' $i $i; i=$((i + 1)); done; } >> "$store/suit.conf" cp "$T/sh/stamp" "$T/stamp-before" check watch-too-many-paths 1 "more than 128 paths for the no-change run to watch" -- "$SUIT" apply same watch-too-many-paths-keeps-the-old-stamp "$T/sh/stamp" "$T/stamp-before" # a listing folder that cannot be read when the stamp is written world check watch-listing-apply 0 "" -- "$SUIT" apply check watch-listing-unreadable 1 "cannot read $store/agents:" -- env SUIT_FAULT=listdir:7:EACCES "$SUIT" apply check watch-commands-listing-unreadable 1 "cannot read $store/commands:" -- env SUIT_FAULT=listdir:8:EACCES "$SUIT" apply # ---- the ledger and the config are strict --------------------------------------- world "$SUIT" apply >/dev/null 2>&1 cp "$T/sh/ledger" "$T/ledger.good" printf 'link /only-one-path\n' > "$T/sh/ledger" check bad-ledger-line-is-an-error 1 "ledger:1: link needs DEST and SOURCE" -- "$SUIT" plan check bad-ledger-stops-apply 1 "ledger:1:" -- "$SUIT" apply [ ! -e "$T/sh/lock" ] && pass bad-ledger-leaves-no-lock || bad bad-ledger-leaves-no-lock printf 'link /a /b\nlink /a /c\n' > "$T/sh/ledger" check duplicate-ledger-entry-is-an-error 1 "ledger:2: duplicate link /a" -- "$SUIT" plan check bad-ledger-stops-off 1 "ledger:2:" -- "$SUIT" off cp "$T/ledger.good" "$T/sh/ledger" check ledger-open-fails 1 "cannot open: Permission denied" -- env SUIT_FAULT=open:3:EACCES "$SUIT" plan check ledger-read-fails 1 "cannot read: $EIO" -- env SUIT_FAULT=read:3 "$SUIT" plan check ledger-read-interrupted-retries 0 "" -- env SUIT_FAULT=read:3:EINTR "$SUIT" plan head -c 1048577 /dev/zero | tr '\0' '\n' > "$T/sh/ledger" check oversized-ledger-is-an-error 1 "file is over the limit" -- "$SUIT" plan cp "$T/ledger.good" "$T/sh/ledger" printf '[harness h]\nthis is not a pair\n' > "$store/suit.conf" check bad-config-is-an-error 1 "suit.conf:2: expected KEY = VALUE" -- "$SUIT" plan rm "$store/suit.conf" check missing-config-is-an-error 1 "store:0: no wardrobe with a suit.conf" -- "$SUIT" plan check missing-config-stops-status-too 1 "" -- "$SUIT" status check plan-without-home 1 "HOME is not set" -- env -u HOME "$SUIT" plan check plan-with-empty-home 1 "neither SUIT_HOME nor HOME is set" -- env -u SUIT_HOME HOME= "$SUIT" plan longhome=$(awk 'BEGIN { for (i = 0; i < 3600; i++) printf "h" }') check suit-home-too-long 1 "SUIT_HOME is longer than" -- env SUIT_HOME="/$longhome" "$SUIT" plan check suit-home-unusable 1 "" -- env -u SUIT_HOME -u HOME "$SUIT" plan check apply-without-suit-home-or-home 1 "neither SUIT_HOME nor HOME is set" -- env -u SUIT_HOME -u HOME "$SUIT" apply check off-without-home 1 "HOME is not set" -- env -u HOME "$SUIT" off # ---- failures part way leave the ledger describing the disk ----------------------- # ledger_matches_disk: every ledger line is true, and every link that points into # the store is in the ledger. ledger_matches_disk() { ok=0 while read -r kind a b; do case $kind in link) [ "$(readlink "$a")" = "$b" ] || ok=1 ;; dir) [ -d "$a" ] || ok=1 ;; esac done < "$T/sh/ledger" on_disk=$(find "$T/home" -type l | wc -l | tr -d ' ') in_ledger=$(grep -c '^link' "$T/sh/ledger") [ "$on_disk" = "$in_ledger" ] || ok=1 return $ok } for spec in symlink:1 symlink:3 symlink:20 rename:2 rename:5 mkdir:1 mkdir:3; do world check "apply-fails-at-$spec" 1 "suit: cannot" -- env SUIT_FAULT=$spec "$SUIT" apply if ledger_matches_disk; then pass "ledger-matches-the-disk-after-$spec"; else bad "ledger-matches-the-disk-after-$spec" "$(cat "$T/sh/ledger" | sed "s|$T||g" | head -4)"; fi if find "$T/home" -name '.suit-tmp.*' | grep -q .; then bad "no-temp-link-left-after-$spec"; else pass "no-temp-link-left-after-$spec"; fi check "apply-finishes-after-$spec" 0 "" -- "$SUIT" apply "$SUIT" plan > "$T/out" 2>&1 [ "$(grep -c '^[+!-]' "$T/out")" = 0 ] && pass "apply-after-$spec-completes-the-plan" || bad "apply-after-$spec-completes-the-plan" "$(sed "s|$T||g" "$T/out" | head -3)" done world "$SUIT" plan > "$T/out" 2>&1 links=$(grep -c '^+ link' "$T/out") check ledger-intent-write-fails 1 "cannot write the ledger" -- env SUIT_FAULT=rename:1 "$SUIT" apply [ ! -e "$T/home/.claude" ] && pass failed-intent-write-changes-nothing || bad failed-intent-write-changes-nothing check ledger-final-write-fails 1 "cannot write the ledger" -- env SUIT_FAULT=rename:$((links + 2)) "$SUIT" apply world check stat-fails-while-planning-folders 1 "cannot look at" -- env SUIT_FAULT=stat:12:EACCES "$SUIT" plan check lstat-fails-while-planning 1 "cannot look at" -- env SUIT_FAULT=lstat:24:EACCES "$SUIT" plan check lstat-fails-while-checking-sources 1 "which is not in the store" -- env SUIT_FAULT=lstat:1 "$SUIT" plan "$SUIT" apply >/dev/null 2>&1 check readlink-fails-while-planning 1 "cannot read the link" -- env SUIT_FAULT=readlink:1 "$SUIT" plan check store-folder-unreadable 1 "cannot read $store/skills" -- env SUIT_FAULT=listdir:2:EACCES "$SUIT" plan check store-watch-unreadable 1 "cannot read $store" -- env SUIT_FAULT=listdir:6 "$SUIT" apply # a removal that fails world "$SUIT" apply >/dev/null 2>&1 sed 's/^agents = reviewer implementer/agents = reviewer/' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" check removal-fails 1 "cannot remove $T/home/.claude/agents/implementer.md" -- env SUIT_FAULT=unlink:1 "$SUIT" apply if ledger_matches_disk; then pass ledger-matches-the-disk-after-a-failed-removal; else bad ledger-matches-the-disk-after-a-failed-removal; fi grep -q "agents/implementer.md" "$T/sh/ledger" && pass failed-removal-keeps-the-ledger-entry || bad failed-removal-keeps-the-ledger-entry # off, failing world "$SUIT" apply >/dev/null 2>&1 check off-lstat-fails 1 "cannot look at" -- env SUIT_FAULT=lstat:1:EACCES "$SUIT" off check off-readlink-fails 1 "cannot read the link" -- env SUIT_FAULT=readlink:1 "$SUIT" off check off-unlink-fails 1 "cannot remove" -- env SUIT_FAULT=unlink:1 "$SUIT" off [ -s "$T/sh/ledger" ] && pass failed-off-keeps-the-ledger || bad failed-off-keeps-the-ledger check off-ledger-write-fails 1 "cannot write the ledger" -- env SUIT_FAULT=rename:1 "$SUIT" off check off-rmdir-fails 1 "cannot remove the folder" -- env SUIT_FAULT=rmdir:1 "$SUIT" off world "$SUIT" apply >/dev/null 2>&1 printf 'precious\n' > "$T/home/.claude/skills/extra.txt" rm -rf "$T/home/.codex" check off-with-an-unrelated-file-in-a-folder-it-made 0 "" -- "$SUIT" off has off-leaves-a-folder-with-someone-elses-file "left $T/home/.claude/skills (not empty)" [ "$(cat "$T/home/.claude/skills/extra.txt")" = precious ] && pass off-keeps-the-other-file || bad off-keeps-the-other-file check off-after-off-with-folders-gone 0 "" -- "$SUIT" off # ---- what the store may hold -------------------------------------------------------- world i=0; while [ $i -lt 2049 ]; do mkdir "$store/skills/many$i"; i=$((i + 1)); done check too-many-skills 1 "the store has too many skills" -- "$SUIT" plan world long=$(awk 'BEGIN { for (i = 0; i < 120; i++) printf "n" }') i=0; while [ $i -lt 1100 ]; do mkdir "$store/skills/$long$i"; i=$((i + 1)); done check too-many-bytes-of-skill-names 1 "the store has too many skills" -- "$SUIT" plan world mkdir -p "$store/many" i=0; while [ $i -lt 8200 ]; do : > "$store/many/f$i"; i=$((i + 1)); done check too-many-files-to-watch 0 "" -- "$SUIT" apply world mkdir -p "$store/many" name=$(awk 'BEGIN { for (i = 0; i < 240; i++) printf "w" }') i=0; while [ $i -lt 7900 ]; do : > "$store/many/$name$i"; i=$((i + 1)); done check too-many-bytes-to-watch 0 "" -- "$SUIT" apply world deep=$store/deep i=0; while [ $i -lt 70 ]; do deep=$deep/d; i=$((i + 1)); done mkdir -p "$deep" check store-nested-too-deep 0 "" -- "$SUIT" apply world rm -rf "$store/agents" "$store/commands" check store-without-agent-folders 1 "agents 'reviewer' matches nothing" -- "$SUIT" plan world mkdir "$store/.hidden-skill"; : > "$store/agents/.hidden.md"; : > "$store/agents/notes.txt"; ln -s ../agents "$store/skills/linked" "$SUIT" plan > "$T/out" 2>&1; grep -q hidden "$T/out" && bad hidden-names-are-not-assets || pass hidden-names-are-not-assets check apply-sets-the-stamp-over-the-store 0 "" -- "$SUIT" apply sleep 1; printf 'x\n' >> "$store/agents/notes.txt" check an-edit-to-any-store-file-changes-the-stamp 0 "" -- "$SUIT" compare # ---- a small store for the fault and edge cases --------------------------------- # Counts in SUIT_FAULT below (rename:2 and so on) are the Nth call of that kind in # one command on this store, so the store stays this small. tiny_conf() { # SKILL: which skill ~/a/b/s gets; empty for none { printf '[harness h]\nskills.user = ~/a/b/s\n[wear user]\noutfits = o\n[outfit o]\n' [ -n "$1" ] && printf 'skills = %s\n' "$1" printf 'file ~/x/y = files/f\n'; } > "$store/suit.conf" } # tiny STATE: fresh, applied, replace (s1 -> s2 wanted), remove (s1 no longer wanted) tiny() { rm -rf "$T/home" "$T/sh" mkdir -p "$T/home" "$T/sh/store/mine/skills/s1" "$T/sh/store/mine/skills/s2" "$T/sh/store/mine/files" export HOME="$T/home" SUIT_HOME="$T/sh" echo a > "$store/skills/s1/SKILL.md"; echo b > "$store/skills/s2/SKILL.md"; echo f > "$store/files/f" tiny_conf s1 case $1 in applied|replace|remove) "$SUIT" apply >/dev/null 2>&1 ;; esac case $1 in replace) tiny_conf s2 ;; remove) tiny_conf "" ;; esac } # covers: every link under HOME that points into the store is in the ledger. # exact: the ledger also holds nothing that is not on disk as it says. covers() { for l in $(find "$T/home" -type l); do grep -qxF "link $l $(readlink "$l")" "$T/sh/ledger" 2>/dev/null || { echo "$l is not in the ledger" >&2; return 1; } done } exact() { covers || return 1 [ -f "$T/sh/ledger" ] || return 0 while read -r k d s; do if [ "$k" = file ]; then [ -f "$d" ] || { echo "ledger says file $d" >&2; return 1; }; continue; fi [ "$k" = link ] || continue [ "$(readlink "$d" 2>/dev/null)" = "$s" ] || { echo "ledger says $d -> $s" >&2; return 1; } done < "$T/sh/ledger" } # fault NAME STATE COMMAND SPEC WANT_RC MESSAGE exact|covers # One command with one call made to fail. Then: the ledger describes the disk, and # the same command without the fault finishes the job (the second run leaves nothing to do). fault() { fname=$1; tiny "$2" "$SUIT" plan > "$T/before-plan" 2>&1 check "$fname" "$5" "$6" -- env SUIT_FAULT="$4" "$SUIT" "$3" if "$7"; then pass "$fname-ledger-$7"; else bad "$fname-ledger-$7"; fi if [ "$3" = apply ] || [ "$3" = off ]; then "$SUIT" "$3" > "$T/out" 2>"$T/err" && pass "$fname-then-it-finishes" || bad "$fname-then-it-finishes" "$(cat "$T/err")" fi } # -- apply on a fresh store fault apply-lock-owner-write fresh apply write:1 1 "cannot write the lock" covers fault apply-conf-open fresh apply open:2 1 "suit.conf:0: cannot open" covers fault apply-ledger-open fresh apply open:4 1 "ledger:0: cannot open" covers fault apply-ledger-temp-open fresh apply open:5 1 "cannot write the ledger" covers fault apply-ledger-first-rename fresh apply rename:1 1 "cannot write the ledger" covers fault apply-first-symlink fresh apply symlink:1 1 "cannot link $T/home/a/b/s/s1" exact fault apply-second-symlink fresh apply symlink:2 1 "cannot link $T/home/x/y" exact fault apply-first-link-rename fresh apply rename:2 1 "cannot link $T/home/a/b/s/s1" exact fault apply-final-ledger-rename fresh apply rename:4 1 "cannot write the ledger" covers fault apply-stamp-write fresh apply open:6 1 "cannot write" exact fault apply-mkdir-first fresh apply mkdir:1 1 "cannot make the folder $T/home/a" exact fault apply-mkdir-third fresh apply mkdir:3 1 "cannot make the folder $T/home/a/b/s" exact fault apply-lstat-of-a-destination fresh apply lstat:3 1 "cannot look at $T/home/a/b/s/s1" exact fault apply-stat-of-a-parent fresh apply stat:5 1 "cannot look at" exact fault plan-lstat-of-a-destination fresh plan lstat:3 1 "cannot look at $T/home/a/b/s/s1" exact fault plan-lstat-of-a-source fresh plan lstat:1 1 "which is not in the store" exact fault plan-listing-fails fresh plan listdir:2 1 "cannot read $T/sh/store/mine/skills" exact fault plan-ledger-read fresh plan open:3 1 "ledger:0: cannot open" exact # -- apply when links exist fault apply-readlink applied apply readlink:1 1 "cannot read the link" exact fault plan-ledger-read-fails applied plan read:3 1 "ledger:0: cannot read" exact fault plan-ledger-read-interrupted applied plan read:3:EINTR 0 "" exact fault replace-first-lstat replace apply lstat:5 1 "cannot look at $T/home/a/b/s/s1" exact fault replace-unlink-of-the-old-link replace apply unlink:1 1 "cannot remove $T/home/a/b/s/s1" exact fault replace-rename-of-the-new-link replace apply rename:2 1 "cannot link $T/home/a/b/s/s2" exact fault replace-final-ledger-rename replace apply rename:3 1 "cannot write the ledger" covers fault remove-unlink remove apply unlink:1 1 "cannot remove $T/home/a/b/s/s1" exact fault remove-lstat-of-the-stale-link remove apply lstat:3 1 "cannot look at $T/home/a/b/s/s1" exact fault remove-readlink-of-the-stale-link remove apply readlink:2 1 "cannot read the link $T/home/a/b/s/s1" exact # -- off fault off-lstat applied off lstat:1 1 "cannot look at $T/home/a/b/s/s1" exact fault off-readlink applied off readlink:1 1 "cannot read the link $T/home/a/b/s/s1" exact fault off-unlink applied off unlink:1 1 "cannot remove $T/home/a/b/s/s1" exact fault off-unlink-second applied off unlink:2 1 "cannot remove $T/home/x/y" exact fault off-rmdir applied off rmdir:1 1 "cannot remove the folder $T/home/x" exact fault off-rmdir-last applied off rmdir:4 1 "cannot remove the folder $T/home/a" exact fault off-ledger-rename applied off rename:1 1 "cannot write the ledger" covers fault off-ledger-read applied off open:2 1 "ledger:0: cannot open" exact # -- the destination's parent is a file: the link cannot go there tiny fresh mkdir -p "$T/home/a"; printf 'a file where a folder should be\n' > "$T/home/a/b" "$SUIT" plan > "$T/out" 2>&1 grep -qF "! clash $T/home/a/b/s/s1 (something in the way)" "$T/out" && pass plan-reports-a-parent-that-is-a-file || bad plan-reports-a-parent-that-is-a-file "$(cat "$T/out")" check apply-places-the-rest-around-it 0 "" -- "$SUIT" apply [ "$(cat "$T/home/a/b")" = "a file where a folder should be" ] && [ -L "$T/home/x/y" ] && pass the-parent-file-is-untouched-and-the-rest-placed || bad the-parent-file-is-untouched-and-the-rest-placed # -- a link someone else put where suit's link was is a clash, and is dropped from the ledger tiny applied rm "$T/home/x/y"; ln -s /not/ours "$T/home/x/y" "$SUIT" apply > "$T/out" 2>&1 grep -qF "! clash $T/home/x/y (someone else's link)" "$T/out" && pass wanted-link-someone-replaced-is-a-clash || bad wanted-link-someone-replaced-is-a-clash "$(cat "$T/out")" [ "$(readlink "$T/home/x/y")" = "/not/ours" ] && pass the-replaced-link-is-left-alone || bad the-replaced-link-is-left-alone grep -qF "$T/home/x/y" "$T/sh/ledger" && bad the-clash-is-dropped-from-the-ledger || pass the-clash-is-dropped-from-the-ledger # a link left by a crash between making it and writing the ledger is suit's own tiny applied rm "$T/home/x/y"; ln -s "$store/files/f" "$T/home/x/y" grep -v " $T/home/x/y " "$T/sh/ledger" > "$T/ledger.new"; cp "$T/ledger.new" "$T/sh/ledger" "$SUIT" plan > "$T/out" 2>&1 grep -q '^!' "$T/out" && pass an-unrecorded-link-at-the-right-source-is-a-clash || bad an-unrecorded-link-at-the-right-source-is-a-clash "$(cat "$T/out")" # -- a link whose asset left the outfit: gone from disk already, a real file or folder, or still ours tiny remove rm "$T/home/a/b/s/s1" "$SUIT" apply > "$T/out" 2>&1 # The full path, not the bare name: the scratch folder's random name can hold "s1". [ ! -s "$T/out" ] && ! grep -qF "$T/home/a/b/s/s1" "$T/sh/ledger" && pass a-link-already-gone-is-dropped-quietly || bad a-link-already-gone-is-dropped-quietly "$(cat "$T/out")" tiny remove rm "$T/home/a/b/s/s1"; printf 'mine\n' > "$T/home/a/b/s/s1" "$SUIT" apply > "$T/out" 2>&1 grep -qF "! clash $T/home/a/b/s/s1 (a real file)" "$T/out" && [ "$(cat "$T/home/a/b/s/s1")" = mine ] && pass a-stale-entry-that-is-now-a-real-file-is-a-clash || bad a-stale-entry-that-is-now-a-real-file-is-a-clash "$(cat "$T/out")" tiny remove rm "$T/home/a/b/s/s1"; mkdir "$T/home/a/b/s/s1" "$SUIT" apply > "$T/out" 2>&1 grep -qF "! clash $T/home/a/b/s/s1 (a real folder)" "$T/out" && pass a-stale-entry-that-is-now-a-real-folder-is-a-clash || bad a-stale-entry-that-is-now-a-real-folder-is-a-clash "$(cat "$T/out")" # -- off: what it leaves tiny applied rm "$T/home/x/y" check off-with-a-link-already-gone 0 "" -- "$SUIT" off tiny applied rm "$T/home/x/y"; printf 'mine\n' > "$T/home/x/y" check off-with-a-real-file-where-a-link-was 0 "" -- "$SUIT" off has off-says-it-left-the-real-file "left $T/home/x/y (a real file)" [ "$(cat "$T/home/x/y")" = mine ] && has off-keeps-the-folder-the-file-is-in "left $T/home/x (not empty)" || bad off-keeps-the-folder-the-file-is-in tiny applied rm "$T/home/x/y"; ln -s /not/ours "$T/home/x/y" "$SUIT" off > "$T/out" 2>&1 has off-says-it-left-someone-elses-link "left $T/home/x/y (someone else's link)" [ "$(readlink "$T/home/x/y")" = /not/ours ] && pass off-leaves-someone-elses-link || bad off-leaves-someone-elses-link tiny applied rm -rf "$T/home/x" check off-with-a-folder-already-gone 0 "" -- "$SUIT" off # a hand-edited ledger with the folders out of order tiny fresh mkdir -p "$T/home/d/e" "$T/home/d/f" printf 'dir %s/d/f\ndir %s/d/e\ndir %s/d\n' "$T/home" "$T/home" "$T/home" > "$T/sh/ledger" check off-takes-folders-in-any-order 0 "" -- "$SUIT" off [ ! -e "$T/home/d" ] && pass off-removed-all-three-folders || bad off-removed-all-three-folders # -- the stamp needs somewhere to go tiny fresh mkdir -p "$T/sh/stamp" check apply-with-a-stamp-that-cannot-be-written 1 "cannot write" -- "$SUIT" apply rmdir "$T/sh/stamp" # -- the lock tiny fresh : > "$T/sh/lock" check an-empty-lock-is-busy 20 "another suit holds the lock" -- "$SUIT" apply printf '1\n' > "$T/sh/lock" check an-owner-that-cannot-be-checked-is-busy 20 "another suit holds the lock" -- "$SUIT" apply rm -f "$T/sh/lock" # -- the store's folders tiny fresh rm -rf "$store/skills"; printf 'not a folder\n' > "$store/skills" check a-skills-file-is-not-a-folder 1 "cannot read $store/skills" -- "$SUIT" plan rm "$store/skills"; mkdir -p "$store/skills/s1" "$store/skills/.hidden" echo a > "$store/skills/s1/SKILL.md" mkdir -p "$store/agents" "$store/commands" : > "$store/agents/notes.txt"; : > "$store/agents/a"; : > "$store/agents/.md"; mkdir "$store/agents/folder.md"; : > "$store/agents/real.md" : > "$store/skills/a-file" printf '[harness h]\nagents.user = ~/ag\nskills.user = ~/sk\n[wear user]\noutfits = o\n[outfit o]\nagents = *\nskills = *\n' > "$store/suit.conf" "$SUIT" plan > "$T/out" 2>&1 sed -i.bak "s|$T/home|~|g; s|$T/sh/store/mine|S|g" "$T/out" for want in "+ link ~/ag/real.md -> S/agents/real.md" "+ link ~/sk/s1 -> S/skills/s1"; do grep -qxF -- "$want" "$T/out" && pass "listing-has-[$want]" || bad "listing-has-[$want]" "$(cat "$T/out")"; done [ "$(grep -c '^+ link' "$T/out")" = 4 ] && pass listing-skips-dotfiles-and-the-wrong-type || bad listing-skips-dotfiles-and-the-wrong-type "$(cat "$T/out")" # a store with more than the limit of skills, and more than the limit of names' text tiny fresh rm -rf "$store/skills"; mkdir -p "$store/skills" i=0; while [ $i -le 2048 ]; do mkdir "$store/skills/k$i"; i=$((i + 1)); done check too-many-skills 1 "the store has too many skills (limit 2048" -- "$SUIT" plan rm -rf "$store/skills"; mkdir -p "$store/skills" long=$(awk 'BEGIN { for (i = 0; i < 120; i++) printf "n" }') i=0; while [ $i -lt 1100 ]; do mkdir "$store/skills/$long$i"; i=$((i + 1)); done check skill-names-too-long-in-all 1 "the store has too many skills" -- "$SUIT" plan # more files in the store than the stamp can watch; and folders nested too deep tiny fresh mkdir -p "$store/bulk" i=0; while [ $i -lt 8200 ]; do : > "$store/bulk/f$i"; i=$((i + 1)); done check too-many-files-to-watch 0 "" -- "$SUIT" apply grep -q "$store/bulk/" "$T/sh/stamp" && bad bulk-files-are-not-watched || pass bulk-files-are-not-watched rm -rf "$store/bulk" d=$store/deep; i=0; while [ $i -lt 66 ]; do d=$d/d; i=$((i + 1)); done mkdir -p "$d" check folders-nested-too-deep 0 "" -- "$SUIT" apply rm -rf "$store/deep" # a ledger already near the limit, and one more link to add tiny fresh i=0; while [ $i -lt 4096 ]; do printf 'dir %s/d%d\n' "$T/home" $i; i=$((i + 1)); done > "$T/sh/ledger" check the-ledger-would-hold-too-many 1 "the ledger would hold more than 4096 entries" -- "$SUIT" apply [ ! -e "$T/home/a" ] && pass too-big-ledger-changes-nothing || bad too-big-ledger-changes-nothing # -- HOME and SUIT_HOME tiny fresh check no-home 1 "HOME is not set" -- env -u HOME "$SUIT" plan longhome=$(awk 'BEGIN { for (i = 0; i < 4100; i++) printf "h" }') check home-too-long 1 "HOME is not set, or too long" -- env HOME=/$longhome "$SUIT" plan longsuit=$(awk 'BEGIN { for (i = 0; i < 3600; i++) printf "s" }') check suit-home-too-long 1 "longer than" -- env SUIT_HOME=/$longsuit "$SUIT" plan check no-suit-home-or-home-for-the-paths 1 "neither SUIT_HOME nor HOME" -- env SUIT_FAULT=getenv:1,getenv:2 "$SUIT" plan # ---- phase 4a: the machine's name and the machine limit ------------------------ mfile=$T/sh/machine real_world check machine-shows-none-with-no-file 1 "this machine has no name" -- "$SUIT" machine check machine-set 0 "" -- "$SUIT" machine desk printf 'desk\n' > "$T/want"; same machine-file-is-the-name-and-a-newline "$mfile" "$T/want" check machine-show 0 "" -- "$SUIT" machine [ "$(cat "$T/out")" = desk ] && pass machine-show-prints-the-name || bad machine-show-prints-the-name "$(cat "$T/out")" check machine-set-again 0 "" -- "$SUIT" machine laptop-2.b_c printf 'laptop-2.b_c\n' > "$T/want"; same machine-file-holds-the-new-name "$mfile" "$T/want" long64=$(awk 'BEGIN { for (i = 0; i < 64; i++) printf "n" }') check machine-name-of-64-bytes-is-fine 0 "" -- "$SUIT" machine "$long64" check machine-name-of-64-bytes-reads-back 0 "" -- "$SUIT" machine [ "$(cat "$T/out")" = "$long64" ] && pass machine-64-bytes-shown || bad machine-64-bytes-shown check machine-set-desk 0 "" -- "$SUIT" machine desk for bad_name in "" "a b" "a/b" "x$long64" "a b" "é"; do check "machine-refuses-[$(printf %s "$bad_name" | head -c 12 | tr '\n' '|')]" 2 "is not a machine name" -- "$SUIT" machine "$bad_name" done printf 'desk\n' > "$T/want"; same machine-refusals-leave-the-file "$mfile" "$T/want" check machine-takes-one-name 2 "usage:" -- "$SUIT" machine a b printf 'desk' > "$mfile" check machine-file-without-a-newline-is-fine 0 "" -- "$SUIT" machine # a malformed file is an error that names the file bad_file() { # NAME CONTENT printf "$2" > "$mfile" check "machine-file-$1-is-an-error" 1 "$mfile: not a machine name" -- "$SUIT" machine check "plan-with-a-$1-machine-file-stops" 1 "$mfile: not a machine name" -- "$SUIT" plan check "status-with-a-$1-machine-file-stops" 1 "$mfile: not a machine name" -- "$SUIT" status } bad_file empty '' bad_file blank '\n' bad_file spaced 'a b\n' bad_file two-lines 'a\nb\n' bad_file slashed 'a/b\n' bad_file too-long "${long64}n\n" bad_file name-then-more "${long64}\nx" printf 'desk\n' > "$mfile" check machine-open-fails 1 "cannot open $mfile" -- env SUIT_FAULT=open:1:EACCES "$SUIT" machine check machine-read-fails 1 "cannot read $mfile: $EIO" -- env SUIT_FAULT=read:1 "$SUIT" machine check machine-read-interrupted-is-retried 0 "" -- env SUIT_FAULT=read:1:EINTR "$SUIT" machine check plan-machine-open-fails 1 "cannot open $mfile" -- env SUIT_FAULT=open:2:EACCES "$SUIT" plan for spec in open:1 write:1 fsync:1 rename:1; do check "machine-write-fails-at-$spec" 1 "cannot write $mfile" -- env SUIT_FAULT=$spec "$SUIT" machine other printf 'desk\n' > "$T/want"; same "machine-write-fails-at-$spec-keeps-the-file" "$mfile" "$T/want" [ "$(ls -A "$T/sh" | grep -c 'suit-tmp')" = 0 ] && pass "machine-write-fails-at-$spec-leaves-no-temp" || bad "machine-write-fails-at-$spec-leaves-no-temp" done # mworld: the fixture plus a machine-limited outfit "notes" that adds instructions, # and an unlimited and a limited outfit that supply one file from different places. mworld() { if [ -n "$REAL" ]; then real_world; else world; fi printf 'base\n' > "$store/instructions/user.md" printf 'studio\n' > "$store/instructions/studio.md" sed -e 's/^outfits = voice$/outfits = voice notes pref-m/' -e 's/^outfits = core$/outfits = core pref-u/' \ "$store/suit.conf" > "$T/conf.new" cat >> "$T/conf.new" <<'EOF' [outfit notes] instructions = instructions/studio.md [outfit pref-u] file ~/.claude/pref.json = files/tts/voices.json [outfit pref-m] file ~/.claude/pref.json = files/tts/announce.sh [wear personal github.com/o/n machine=other] outfits = notes EOF mv "$T/conf.new" "$store/suit.conf" printf 'base\n\nstudio\n' > "$T/want-joined" } ledger_ok() { if exact; then pass "$1"; else bad "$1" "$(sed "s|$T||g" "$T/sh/ledger" | head -6)"; fi; } tts=$T/home/.claude/tts-voices.json pref=$T/home/.claude/pref.json joined=$T/sh/joined sh_names() { (cd "$T/sh" && find . | sort | grep -v -e '^./ledger$' -e '^./stamp$' -e '^./lock$' -e '^./machine$'); } # Worlds in which a joined file is about to be written, rewritten or removed. setup_new() { mworld; "$SUIT" apply >/dev/null 2>&1; "$SUIT" machine studio >/dev/null 2>&1; } setup_rewrite() { mworld; "$SUIT" machine studio >/dev/null 2>&1; "$SUIT" apply >/dev/null 2>&1; printf 'more\n' >> "$store/instructions/user.md"; } setup_remove() { setup_rewrite; printf 'base\n' > "$store/instructions/user.md"; rm "$mfile"; } setup_applied() { mworld; "$SUIT" machine studio >/dev/null 2>&1; "$SUIT" apply >/dev/null 2>&1; } # sfail NAME SETUP CALL ERRNO MESSAGE COMMAND...: in a world SETUP makes, fail the Nth # CALL for N = 1, 2, ... until COMMAND exits 1 and says MESSAGE. Leaves that world. sfail() { sname=$1; ssetup=$2; scall=$3; serr=$4; smsg=$5; shift 5 sn=1 while [ $sn -le 60 ]; do $ssetup env SUIT_FAULT="$scall:$sn${serr:+:$serr}" "$@" >"$T/out" 2>"$T/err"; sr=$? if [ $sr = 1 ] && grep -qF -- "$smsg" "$T/err"; then pass "$sname"; return 0; fi sn=$((sn + 1)) done bad "$sname" "no $scall failure made it say '$smsg'" return 1 } check machine-without-home 1 "HOME is not set" -- env -u HOME "$SUIT" machine # -- no name, another name, the right name REAL=1; mworld; REAL= snap "$T/home" > "$T/m-home-0" sh_names > "$T/m-sh-0" check apply-with-no-machine-name 0 "" -- "$SUIT" apply [ ! -e "$tts" ] && [ ! -e "$T/sh/slots" ] && pass limited-outfit-does-not-apply-with-no-name || bad limited-outfit-does-not-apply-with-no-name [ "$(readlink "$pref")" = "$store/files/tts/voices.json" ] && pass unlimited-file-is-linked-with-no-name || bad unlimited-file-is-linked-with-no-name [ "$(readlink "$T/home/.claude/CLAUDE.md")" = "$store/instructions/user.md" ] && pass one-instruction-file-links-to-the-store || bad one-instruction-file-links-to-the-store [ ! -e "$joined" ] && pass no-joined-folder-with-one-supplier || bad no-joined-folder-with-one-supplier check status-with-no-name 0 "" -- "$SUIT" status has status-says-the-machine-has-no-name "machine studio: not this machine (this machine has no name)" snap "$T/home" > "$T/m-home-1" check set-another-machine 0 "" -- "$SUIT" machine desk check run-after-naming-the-machine 0 "" -- "$SUIT" run check status-on-another-machine 0 "" -- "$SUIT" status has status-says-which-machine-this-is "machine studio: not this machine (this is desk)" [ ! -e "$tts" ] && pass limited-outfit-does-not-apply-on-another-machine || bad limited-outfit-does-not-apply-on-another-machine [ ! -e "$joined" ] && pass no-join-on-another-machine || bad no-join-on-another-machine snap "$T/home" > "$T/m-home-2" same another-machine-changes-nothing-in-home "$T/m-home-1" "$T/m-home-2" "$SUIT" plan > "$T/out" 2>&1 if grep -q -e 'skipped wear' -e studio "$T/out"; then bad plan-does-not-list-an-ignored-section "$(head -3 "$T/out")"; else pass plan-does-not-list-an-ignored-section; fi # -- on the machine: the limited file wins and the instructions are joined check set-the-machine 0 "" -- "$SUIT" machine studio "$SUIT" plan > "$T/out" 2>&1 sed "s|$T/home|~|g; s|$T/sh|S|g" "$T/out" > "$T/out.rel" grep -qF "+ link ~/.claude/pref.json -> S/store/mine/files/tts/announce.sh" "$T/out.rel" && pass plan-shows-the-limited-file-as-the-winner || bad plan-shows-the-limited-file-as-the-winner "$(head -5 "$T/out.rel")" if [ "$(grep -c 'pref.json' "$T/out.rel")" != 1 ]; then bad plan-shows-the-winner-only "$(cat "$T/out.rel")"; else pass plan-shows-the-winner-only; fi grep -qF "+ link ~/.claude/CLAUDE.md -> S/joined/claude" "$T/out.rel" && pass plan-links-instructions-to-the-joined-file || bad plan-links-instructions-to-the-joined-file "$(cat "$T/out.rel")" grep -qF "+ file S/joined/claude" "$T/out.rel" && pass plan-lists-the-joined-file-it-will-write || bad plan-lists-the-joined-file-it-will-write [ ! -e "$joined" ] && pass plan-writes-no-joined-file || bad plan-writes-no-joined-file check run-on-the-machine 0 "" -- "$SUIT" run [ -L "$tts" ] && pass limited-outfit-applies-on-the-named-machine || bad limited-outfit-applies-on-the-named-machine [ "$(readlink "$pref")" = "$store/files/tts/announce.sh" ] && pass limited-source-wins-in-the-user-scope || bad limited-source-wins-in-the-user-scope "$(readlink "$pref")" for h in claude:.claude/CLAUDE.md codex:.codex/AGENTS.md pi:.pi/agent/AGENTS.md; do n=${h%%:*}; f=$T/home/${h#*:} [ "$(readlink "$f")" = "$joined/$n" ] && pass "joined-link-for-$n" || bad "joined-link-for-$n" "$(readlink "$f")" same "joined-content-for-$n-is-both-files-and-one-blank-line" "$joined/$n" "$T/want-joined" same "joined-content-is-visible-through-$n-path" "$f" "$T/want-joined" grep -qxF "file $joined/$n" "$T/sh/ledger" && pass "ledger-has-the-joined-file-for-$n" || bad "ledger-has-the-joined-file-for-$n" done grep -qxF "dir $joined" "$T/sh/ledger" && pass ledger-has-the-joined-folder || bad ledger-has-the-joined-folder ledger_ok ledger-true-after-joining check status-on-the-machine 0 "" -- "$SUIT" status # only the personal wear limited to another machine is said, none for the machine this is if [ "$(grep -c '^machine ' "$T/out")" = 1 ] && grep -qxF 'machine other: not this machine (this is studio)' "$T/out"; then pass status-says-only-the-personal-wear-for-another-machine; else bad status-says-only-the-personal-wear-for-another-machine "$(grep '^machine ' "$T/out")"; fi ino=$(ls -i "$joined/claude" | awk '{print $1}') check apply-again-with-joined 0 "" -- "$SUIT" apply if grep -q '^[+-]' "$T/out"; then bad apply-again-changes-nothing "$(head -3 "$T/out")"; else pass apply-again-changes-nothing; fi [ "$(ls -i "$joined/claude" | awk '{print $1}')" = "$ino" ] && pass unchanged-joined-file-is-not-rewritten || bad unchanged-joined-file-is-not-rewritten # -- an edit to either source shows only after suit runs printf 'base two\n' >> "$store/instructions/user.md" same edit-is-not-visible-through-the-joined-link-yet "$T/home/.claude/CLAUDE.md" "$T/want-joined" check run-after-editing-the-first-source 0 "" -- "$SUIT" run printf 'base\nbase two\n\nstudio\n' > "$T/want2" for n in claude codex pi; do same "first-source-edit-reaches-joined-$n" "$joined/$n" "$T/want2"; done printf 'studio two\n' >> "$store/instructions/studio.md" check run-after-editing-the-second-source 0 "" -- "$SUIT" run printf 'base\nbase two\n\nstudio\nstudio two\n' > "$T/want3" same second-source-edit-reaches-joined "$joined/claude" "$T/want3" same second-source-edit-is-visible-through-the-link "$T/home/.claude/CLAUDE.md" "$T/want3" # a joined file edited or deleted by hand is put right by apply, which compares content printf 'tampered\n' > "$joined/claude" sed 's/studio/STUDIO/' "$joined/codex" > "$T/tamper"; cat "$T/tamper" > "$joined/codex" rm "$joined/pi" check apply-rewrites-a-changed-and-a-missing-joined-file 0 "" -- "$SUIT" apply same apply-restores-the-shorter-joined-file "$joined/claude" "$T/want3" same apply-restores-the-joined-file-changed-in-place "$joined/codex" "$T/want3" same apply-restores-the-missing-joined-file "$joined/pi" "$T/want3" ledger_ok ledger-true-after-restoring # -- the name goes: the link is the store's file again and the joined file is gone printf 'base\n' > "$store/instructions/user.md" rm "$mfile" check run-after-the-name-goes 0 "" -- "$SUIT" run [ "$(readlink "$pref")" = "$store/files/tts/voices.json" ] && pass unlimited-source-comes-back-without-the-name || bad unlimited-source-comes-back-without-the-name "$(readlink "$pref")" [ "$(readlink "$T/home/.claude/CLAUDE.md")" = "$store/instructions/user.md" ] && pass link-goes-back-to-the-store-file || bad link-goes-back-to-the-store-file if [ -e "$joined/claude" ] || [ -e "$joined/codex" ] || [ -e "$joined/pi" ]; then bad joined-files-are-gone; else pass joined-files-are-gone; fi if grep -q '^file' "$T/sh/ledger"; then bad ledger-has-no-file-lines-left; else pass ledger-has-no-file-lines-left; fi [ ! -e "$tts" ] && pass limited-link-is-gone-without-the-name || bad limited-link-is-gone-without-the-name ledger_ok ledger-true-after-the-name-goes # -- off removes the joined files and the folder, and leaves the scratch home as it was check set-the-machine-again 0 "" -- "$SUIT" machine studio check run-on-the-machine-again 0 "" -- "$SUIT" run [ -f "$joined/claude" ] && pass joined-again || bad joined-again check off-after-joining 0 "" -- "$SUIT" off has off-says-it-removed-a-joined-file "- file $joined/claude" snap "$T/home" > "$T/m-home-3" same off-leaves-home-as-it-was-before-the-first-apply "$T/m-home-0" "$T/m-home-3" sh_names > "$T/m-sh-1" if cmp -s "$T/m-sh-0" "$T/m-sh-1"; then pass off-leaves-the-suit-home-as-it-was; else bad off-leaves-the-suit-home-as-it-was "$(diff "$T/m-sh-0" "$T/m-sh-1" | head -5)"; fi [ ! -s "$T/sh/ledger" ] && pass off-empties-the-ledger-of-files-too || bad off-empties-the-ledger-of-files-too check off-again-after-joining 0 "" -- "$SUIT" off # -- a joined file gone by hand: nothing to remove, and off copes setup_applied rm "$joined/claude" rm "$mfile" check apply-with-a-stale-joined-file-already-gone 0 "" -- "$SUIT" apply if grep -q "file $joined/claude" "$T/sh/ledger"; then bad stale-gone-file-leaves-the-ledger; else pass stale-gone-file-leaves-the-ledger; fi setup_applied rm "$joined/pi" check off-when-a-joined-file-is-already-gone 0 "" -- "$SUIT" off [ ! -e "$joined" ] && pass off-removes-the-joined-folder || bad off-removes-the-joined-folder # -- a failed write leaves the old link and a true ledger for spec in rename:2 rename:3; do setup_new check "joined-write-fails-at-$spec" 1 "cannot write $joined/" -- env SUIT_FAULT=$spec "$SUIT" apply [ "$(readlink "$T/home/.claude/CLAUDE.md")" = "$store/instructions/user.md" ] && pass "old-link-stays-after-$spec" || bad "old-link-stays-after-$spec" "$(readlink "$T/home/.claude/CLAUDE.md")" ledger_ok "ledger-true-after-joined-write-fails-at-$spec" check "apply-finishes-after-joined-$spec" 0 "" -- "$SUIT" apply same "joined-is-right-after-$spec" "$joined/claude" "$T/want-joined" done for call in open write fsync; do if sfail "joined-write-fails-at-$call" setup_new "$call" "" "cannot write $joined/" "$SUIT" apply; then [ "$(readlink "$T/home/.claude/CLAUDE.md")" = "$store/instructions/user.md" ] && pass "old-link-stays-after-$call" || bad "old-link-stays-after-$call" ledger_ok "ledger-true-after-joined-write-fails-at-$call" fi done # a failure rewriting a joined file that exists: the link still reaches the old content setup_rewrite check joined-rewrite-fails 1 "cannot write $joined/" -- env SUIT_FAULT=rename:2 "$SUIT" apply same old-joined-content-stays "$joined/claude" "$T/want-joined" grep -qxF "file $joined/claude" "$T/sh/ledger" && pass ledger-keeps-the-joined-file-it-could-not-rewrite || bad ledger-keeps-the-joined-file-it-could-not-rewrite ledger_ok ledger-true-after-a-failed-rewrite check joined-rewrite-finishes 0 "" -- "$SUIT" apply printf 'base\nmore\n\nstudio\n' > "$T/want"; same joined-rewrite-has-the-new-content "$joined/claude" "$T/want" # the joined folder is blocked by a file mworld "$SUIT" machine studio >/dev/null 2>&1 printf 'in the way\n' > "$joined" check joined-folder-blocked 1 "cannot write $joined/claude" -- "$SUIT" apply [ "$(readlink "$T/home/.claude/CLAUDE.md")" != "$joined/claude" ] && pass blocked-join-makes-no-link || bad blocked-join-makes-no-link # removing a joined file fails; the ledger keeps it if sfail joined-removal-fails setup_remove unlink "" "cannot remove $joined/" "$SUIT" apply; then if grep -q '^file' "$T/sh/ledger"; then pass ledger-keeps-a-joined-file-it-could-not-remove; else bad ledger-keeps-a-joined-file-it-could-not-remove; fi ledger_ok ledger-true-after-a-failed-removal check joined-removal-finishes 0 "" -- "$SUIT" apply [ ! -e "$joined/claude" ] && pass joined-removal-completes || bad joined-removal-completes fi # off fails to remove a joined file if sfail off-cannot-remove-a-joined-file setup_applied unlink "" "cannot remove $joined/" "$SUIT" off; then check off-finishes-after-a-failed-file-removal 0 "" -- "$SUIT" off fi # the joined folder cannot be looked at sfail joined-folder-that-cannot-be-looked-at-stops-plan setup_new stat EACCES "cannot look at $joined" "$SUIT" plan # a joined file that nothing wants any more cannot be looked at sfail stale-joined-file-that-cannot-be-looked-at-stops-plan setup_remove lstat EACCES "cannot look at $joined/" "$SUIT" plan # -- sources that cannot be joined mworld "$SUIT" machine studio >/dev/null 2>&1 rm "$store/instructions/studio.md" check join-second-source-missing 1 "$joined/claude wants $store/instructions/studio.md, which is not in the store" -- "$SUIT" plan printf 'studio\n' > "$store/instructions/studio.md" rm "$store/instructions/user.md" check join-first-source-missing 1 "$joined/claude wants $store/instructions/user.md, which is not in the store" -- "$SUIT" plan printf 'base\n' > "$store/instructions/user.md" awk 'BEGIN { for (i = 0; i < 600000; i++) printf "x" }' > "$store/instructions/studio.md" check join-source-too-long 1 "too long to join" -- "$SUIT" plan check join-source-too-long-stops-apply 1 "too long to join" -- "$SUIT" apply [ ! -e "$joined" ] && pass too-long-source-changes-nothing || bad too-long-source-changes-nothing awk 'BEGIN { for (i = 0; i < 524288; i++) printf "x" }' > "$store/instructions/studio.md" awk 'BEGIN { for (i = 0; i < 524288; i++) printf "y" }' > "$store/instructions/user.md" check join-of-the-largest-sources 0 "" -- "$SUIT" apply [ "$(wc -c < "$joined/claude" | tr -d ' ')" = 1048578 ] && pass joined-largest-has-both-and-the-blank-line || bad joined-largest-size "$(wc -c < "$joined/claude")" printf 'base' > "$store/instructions/user.md" printf 'studio' > "$store/instructions/studio.md" check join-of-files-with-no-final-newline 0 "" -- "$SUIT" apply printf 'base\n\nstudio' > "$T/want"; same joined-adds-the-newline-the-first-lacks "$joined/claude" "$T/want" : > "$store/instructions/user.md" check join-with-an-empty-first-file 0 "" -- "$SUIT" apply printf '\n\nstudio' > "$T/want"; same joined-empty-first-file "$joined/claude" "$T/want" # read failures on the sources while planning, and interruptions that are retried setup_rewrite sfail join-first-source-open-failure setup_rewrite open EACCES "cannot read $store/instructions/user.md" "$SUIT" plan sfail join-second-source-read-failure setup_rewrite read "" "cannot read $store/instructions/studio.md: $EIO" "$SUIT" plan setup_rewrite eintr_bad=0 for n in $(seq 1 40); do SUIT_FAULT=read:$n:EINTR "$SUIT" plan >"$T/out" 2>"$T/err" || eintr_bad=$n done [ $eintr_bad = 0 ] && pass reads-interrupted-while-joining-are-retried || bad reads-interrupted-while-joining-are-retried "read $eintr_bad" # the current joined file cannot be opened: it is planned for a rewrite setup_applied got_cur=0 for n in $(seq 1 40); do SUIT_FAULT=open:$n:EACCES "$SUIT" plan >"$T/out" 2>"$T/err"; r=$? if [ $r = 0 ] && grep -q "^+ file $joined/claude" "$T/out"; then got_cur=1; fi done [ $got_cur = 1 ] && pass unreadable-joined-file-is-planned-for-rewrite || bad unreadable-joined-file-is-planned-for-rewrite # -- two limited sources, or two unlimited ones, for one destination are still an error mworld "$SUIT" machine studio >/dev/null 2>&1 cat >> "$store/suit.conf" <<'EOF' [outfit pref-m2] file ~/.claude/pref.json = instructions/studio.md EOF sed -i.bak 's/^outfits = voice notes pref-m$/outfits = voice notes pref-m pref-m2/' "$store/suit.conf" rm -f "$store/suit.conf.bak" check two-limited-sources-are-an-error 1 "two assets want $pref: $store/files/tts/announce.sh and $store/instructions/studio.md" -- "$SUIT" plan mworld sed -i.bak 's/^outfits = core pref-u$/outfits = core pref-u pref-m/' "$store/suit.conf" rm -f "$store/suit.conf.bak" check two-unlimited-sources-are-an-error 1 "two assets want $pref:" -- "$SUIT" plan # ---- instructions joined for each harness: shared, the harness's own, the machine's ------- # jworld USER_OUTFITS MACHINE_OUTFITS: a store with four instruction files, the outfits # shared (no only), extra (only = claude), mach (no only, machine studio's) and mextra # (only = claude, machine studio's), and the two wears. jworld() { world "$SUIT" machine studio >/dev/null 2>&1 printf 'base\n' > "$store/instructions/user.md" printf 'extra\n' > "$store/instructions/studio.md" printf 'mach\n' > "$store/instructions/mach.md" printf 'mextra\n' > "$store/instructions/mextra.md" cat > "$store/suit.conf" <<CONF [harness claude] skills.user = ~/.claude/skills instructions.user = ~/.claude/CLAUDE.md [harness codex] skills.user = ~/.codex/skills instructions.user = ~/.codex/AGENTS.md [outfit shared] instructions = instructions/user.md [outfit extra] only = claude instructions = instructions/studio.md [outfit extra2] only = claude instructions = instructions/mextra.md [outfit mach] instructions = instructions/mach.md [outfit mextra] only = claude instructions = instructions/mextra.md [wear user] outfits = $1 $([ -n "$2" ] && printf '\n[wear user machine=studio]\noutfits = %s\n' "$2") CONF } cl=$T/home/.claude/CLAUDE.md cx=$T/home/.codex/AGENTS.md jwant() { printf "$2" > "$T/want"; same "$1" "$joined/claude" "$T/want"; } jworld shared "" check join-shared-only 0 "" -- "$SUIT" apply is join-shared-only-claude-links-to-the-store "$cl" "$store/instructions/user.md" is join-shared-only-codex-links-to-the-store "$cx" "$store/instructions/user.md" [ ! -e "$joined" ] && pass join-shared-only-writes-no-joined-file || bad join-shared-only-writes-no-joined-file jworld "shared extra" "" check join-shared-and-the-claude-extra 0 "" -- "$SUIT" apply is join-claude-links-to-the-joined-file "$cl" "$joined/claude" is join-codex-links-straight-to-the-shared-file "$cx" "$store/instructions/user.md" jwant join-claude-has-shared-then-extra 'base\n\nextra\n' [ ! -e "$joined/codex" ] && pass join-codex-has-no-joined-file || bad join-codex-has-no-joined-file ledger_ok join-ledger-true-with-the-extra check join-no-change-after-apply 0 "" -- "$SUIT" compare printf 'extra two\n' >> "$store/instructions/studio.md" check join-extra-edit-is-a-change 10 "" -- "$SUIT" compare check join-extra-edit-applies 0 "" -- "$SUIT" apply jwant join-extra-edit-rewrites-the-joined-file 'base\n\nextra\nextra two\n' check join-no-change-after-the-edit 0 "" -- "$SUIT" compare ino=$(ls -i "$joined/claude" | awk '{print $1}') check join-apply-again 0 "" -- "$SUIT" apply [ "$(ls -i "$joined/claude" | awk '{print $1}')" = "$ino" ] && pass join-unchanged-is-not-rewritten || bad join-unchanged-is-not-rewritten # the extra goes: Claude links straight to the shared file again and the joined file is gone sed -i.bak 's/^outfits = shared extra$/outfits = shared/' "$store/suit.conf"; rm -f "$store/suit.conf.bak" check join-extra-removed 0 "" -- "$SUIT" apply is join-extra-removed-claude-links-to-the-store "$cl" "$store/instructions/user.md" [ ! -e "$joined/claude" ] && pass join-extra-removed-takes-the-joined-file-away || bad join-extra-removed-takes-the-joined-file-away ledger_ok join-ledger-true-after-the-extra-goes # and `suit off` removes a joined file jworld "shared extra" "" check join-again 0 "" -- "$SUIT" apply check join-off 0 "" -- "$SUIT" off [ ! -e "$joined" ] && [ ! -e "$cl" ] && pass join-off-removes-the-joined-file || bad join-off-removes-the-joined-file jworld "shared extra" mach check join-shared-machine-and-the-claude-extra 0 "" -- "$SUIT" apply jwant join-claude-has-shared-extra-machine 'base\n\nextra\n\nmach\n' printf 'base\n\nmach\n' > "$T/want"; same join-codex-has-shared-then-machine "$joined/codex" "$T/want" is join-codex-links-to-its-joined-file "$cx" "$joined/codex" jworld "shared extra" "mach mextra" check join-all-four-ranks 0 "" -- "$SUIT" apply jwant join-claude-has-all-four-in-rank-order 'base\n\nextra\n\nmach\n\nmextra\n' printf 'base\n\nmach\n' > "$T/want"; same join-codex-has-ranks-one-and-three "$joined/codex" "$T/want" printf 'mextra two\n' >> "$store/instructions/mextra.md" check join-fourth-source-edit-is-a-change 10 "" -- "$SUIT" compare check join-fourth-source-edit-applies 0 "" -- "$SUIT" apply jwant join-fourth-source-edit-rewrites-the-joined-file 'base\n\nextra\n\nmach\n\nmextra\nmextra two\n' # a machine-limited extra without a machine-limited shared one jworld shared mextra check join-machine-extra-after-shared 0 "" -- "$SUIT" apply jwant join-shared-then-machine-extra 'base\n\nmextra\n' is join-machine-extra-leaves-codex-straight "$cx" "$store/instructions/user.md" # the same file at two ranks is one source jworld "shared extra2" mextra check join-same-file-at-two-ranks 0 "" -- "$SUIT" apply jwant join-same-file-is-joined-once 'base\n\nmextra\n' # a source that is missing, or too long, in the third and the fourth place jworld "shared extra" "mach mextra" rm "$store/instructions/mach.md" check join-third-source-missing 1 "$joined/claude wants $store/instructions/mach.md, which is not in the store" -- "$SUIT" plan printf 'mach\n' > "$store/instructions/mach.md"; rm "$store/instructions/mextra.md" check join-fourth-source-missing 1 "$joined/claude wants $store/instructions/mextra.md, which is not in the store" -- "$SUIT" plan for f in user studio mach mextra; do awk 'BEGIN { for (i = 0; i < 524288; i++) printf "x" }' > "$store/instructions/$f.md"; done check join-of-four-largest-sources 0 "" -- "$SUIT" apply [ "$(wc -c < "$joined/claude" | tr -d ' ')" = 2097158 ] && pass join-of-four-largest-is-the-whole-and-three-blank-lines || bad join-of-four-largest-size "$(wc -c < "$joined/claude")" awk 'BEGIN { for (i = 0; i < 600000; i++) printf "x" }' > "$store/instructions/mextra.md" check join-fourth-source-too-long 1 "too long to join" -- "$SUIT" plan # two suppliers of one rank clash, as they always did jworld "shared extra extra2" "" check join-two-extras-clash 1 "two assets want $cl: $store/instructions/mextra.md and $store/instructions/studio.md" -- "$SUIT" plan jworld shared "mextra extra" check join-two-machine-extras-clash 1 "two assets want $cl:" -- "$SUIT" plan jworld "shared mach" "" check join-two-shared-clash 1 "two assets want $cl:" -- "$SUIT" plan # ---- needs: the done test, the prompts, and the attention file ---------------------- att=$T/sh/attention nconf() { cat > "$store/suit.conf" <<EOF [harness claude] skills.user = ~/.claude/skills [harness codex] skills.user = ~/.codex/skills [outfit base] skills = ousterhout [wear user] outfits = base [need claude statusline] prompt = needs/statusline.md done = ~/.claude/settings.json contains "slots/statusline" [need codex bare] prompt = needs/bare.md done = ~/.codex/ready exists EOF } nworld() { world nfill } nfworld() { fworld nfill } nfill() { mkdir -p "$store/needs" "$T/home/.claude" "$T/home/.codex" printf 'Add the slot.\n\nThen restart.\n' > "$store/needs/statusline.md" printf 'no final newline' > "$store/needs/bare.md" nconf } # att_is NAME TEXT: the attention file holds exactly TEXT (a file that is not there, for no text) att_is() { if [ -z "$2" ]; then [ ! -e "$att" ] && pass "$1" || bad "$1" "$(cat "$att")" else printf '%s\n' "$2" > "$T/want" cmp -s "$T/want" "$att" && pass "$1" || bad "$1" "got: $(cat "$att" 2>&1)" fi } S_ITEM='need claude statusline: run suit need claude statusline' B_ITEM='need codex bare: run suit need codex bare' done_settings() { printf '{"statusLine":"slots/statusline"}\n' > "$T/home/.claude/settings.json"; } # -- suit needs: each state, in order, with its exit code nworld check needs-none-done 1 "" -- "$SUIT" needs printf 'claude statusline: not done\ncodex bare: not done\n' > "$T/want" same needs-lists-by-harness-then-name "$T/want" "$T/out" { snap "$T/home"; snap "$T/sh"; } > "$T/snap-before" "$SUIT" needs >/dev/null 2>&1 { snap "$T/home"; snap "$T/sh"; } > "$T/snap-after" same needs-changes-nothing "$T/snap-before" "$T/snap-after" done_settings check needs-one-done 1 "" -- "$SUIT" needs printf 'claude statusline: done\ncodex bare: not done\n' > "$T/want" same needs-one-done-listing "$T/want" "$T/out" printf '{"statusLine":"other"}\n' > "$T/home/.claude/settings.json" check needs-file-without-the-text 1 "" -- "$SUIT" needs has needs-file-without-the-text-is-not-done "claude statusline: not done" done_settings : > "$T/home/.codex/ready" check needs-all-done 0 "" -- "$SUIT" needs printf 'claude statusline: done\ncodex bare: done\n' > "$T/want" same needs-all-done-listing "$T/want" "$T/out" rm "$T/home/.codex/ready"; mkdir "$T/home/.codex/ready" check needs-a-folder-exists 0 "" -- "$SUIT" needs rm -rf "$T/home/.codex/ready"; ln -s /nonexistent-target "$T/home/.codex/ready" check needs-a-dangling-link-exists 0 "" -- "$SUIT" needs rm "$T/home/.codex/ready" rm "$T/home/.claude/settings.json"; mkdir "$T/home/.claude/settings.json" check needs-a-folder-cannot-tell 1 "" -- "$SUIT" needs has needs-a-folder-cannot-tell-says-why "claude statusline: cannot tell (not a regular file)" rm -rf "$T/home/.claude/settings.json" done_settings head -c 4194305 /dev/zero > "$T/home/.claude/settings.json" check needs-an-oversized-file-cannot-tell 1 "" -- "$SUIT" needs has needs-an-oversized-file-says-why "claude statusline: cannot tell (file is over 4 MiB)" done_settings chmod 000 "$T/home/.claude/settings.json" if [ -r "$T/home/.claude/settings.json" ]; then pass needs-an-unreadable-file-cannot-tell else check needs-an-unreadable-file-cannot-tell 1 "" -- "$SUIT" needs has needs-an-unreadable-file-says-why "claude statusline: cannot tell (cannot open the file: Permission denied)" fi chmod 600 "$T/home/.claude/settings.json" chmod 000 "$T/home/.claude" if [ -r "$T/home/.claude" ]; then pass needs-a-folder-that-cannot-be-searched else check needs-a-folder-that-cannot-be-searched 1 "" -- "$SUIT" needs has needs-a-folder-that-cannot-be-searched-says-why "claude statusline: cannot tell (cannot look at the file: Permission denied)" fi chmod 700 "$T/home/.claude" check needs-with-an-argument-is-usage 2 "usage:" -- "$SUIT" needs extra world check needs-in-a-config-with-none 0 "" -- "$SUIT" needs [ ! -s "$T/out" ] && pass needs-with-none-prints-nothing || bad needs-with-none-prints-nothing # -- two needs of one harness sort by name; the commands stop at a journal and at bad paths nworld printf '[need claude alpha]\nprompt = needs/bare.md\ndone = /nonexistent-file exists\n' >> "$store/suit.conf" check needs-sorts-names-within-a-harness 1 "" -- "$SUIT" needs printf 'claude alpha: not done\nclaude statusline: not done\ncodex bare: not done\n' > "$T/want" same needs-lists-two-of-one-harness-in-name-order "$T/want" "$T/out" touch "$T/sh/mine.journal" check a-journal-stops-needs 15 "" -- "$SUIT" needs check a-journal-stops-need 15 "" -- "$SUIT" need claude statusline rm -f "$T/sh/mine.journal" check needs-without-home 1 "HOME is not set, or too long" -- env -u HOME "$SUIT" needs check need-without-home 1 "HOME is not set, or too long" -- env -u HOME "$SUIT" need claude statusline check needs-with-long-suit-home 1 "SUIT_HOME is longer than 3456 bytes" -- env SUIT_HOME="/$(longstr 3600)" "$SUIT" needs check need-with-long-suit-home 1 "SUIT_HOME is longer than 3456 bytes" -- env SUIT_HOME="/$(longstr 3600)" "$SUIT" need claude statusline # -- a need the config gets wrong is exit 2 and names the need and the line nworld ln=$(grep -n '^done = ~/.claude' "$store/suit.conf" | cut -d: -f1) for bad_done in '~/x contains nothing' '~/x contains "oops" more' 'x/y exists' '~/x contains ""' '/a exists' '~/x'; do nconf sed -i.bak "${ln}s|^done = .*|done = $bad_done|" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check "needs-refuses-test-[$bad_done]" 2 "suit.conf:$ln: need claude statusline: cannot read the test: " -- "$SUIT" needs [ ! -s "$T/out" ] && pass "needs-refusal-prints-nothing-[$bad_done]" || bad "needs-refusal-prints-nothing-[$bad_done]" done pl=$(grep -n '^prompt = needs/statusline' "$store/suit.conf" | cut -d: -f1) nconf sed -i.bak "${pl}s|^prompt = .*|prompt = needs/missing.md|" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check needs-refuses-a-missing-prompt 2 "suit.conf:$pl: need claude statusline: cannot read the prompt: No such file or directory" -- "$SUIT" needs nconf; mkdir -p "$store/needs/dir" sed -i.bak "${pl}s|^prompt = .*|prompt = needs/dir|" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check needs-refuses-a-folder-as-prompt 2 "need claude statusline: the prompt is not a file: needs/dir" -- "$SUIT" needs for esc in ../x needs/../../x /etc/hosts; do nconf sed -i.bak "${pl}s|^prompt = .*|prompt = $esc|" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check "needs-refuses-prompt-[$esc]" 2 "need claude statusline: prompt is not a path inside the store: $esc" -- "$SUIT" needs done nconf long=$(head -c 4085 /dev/zero | tr '\0' a) sed -i.bak "${pl}s|^prompt = .*|prompt = $long|" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check needs-refuses-a-prompt-path-too-long 2 "need claude statusline: prompt path is too long: " -- "$SUIT" needs nconf sed -i.bak "${pl}d" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check needs-refuses-a-need-with-no-prompt 2 "need claude statusline: has no prompt" -- "$SUIT" needs nconf sed -i.bak "$((pl + 1))d" "$store/suit.conf"; rm -f "$store/suit.conf.bak" check needs-refuses-a-need-with-no-done 2 "need claude statusline: has no done" -- "$SUIT" needs printf '[need nowhere x]\nprompt = a\ndone = /a exists\n' >> "$store/suit.conf" check needs-refuses-a-broken-config 2 "suit.conf:" -- "$SUIT" needs # -- suit need: the prompt's own bytes nworld check need-prints-the-prompt 0 "" -- "$SUIT" need claude statusline same need-prints-exact-bytes "$store/needs/statusline.md" "$T/out" check need-prints-a-prompt-with-no-final-newline 0 "" -- "$SUIT" need codex bare same need-keeps-a-missing-final-newline "$store/needs/bare.md" "$T/out" done_settings check need-prints-even-when-done 0 "" -- "$SUIT" need claude statusline same need-when-done-prints-the-same-bytes "$store/needs/statusline.md" "$T/out" check need-unknown-name 1 "no need claude nope" -- "$SUIT" need claude nope check need-unknown-harness 1 "no need pi statusline" -- "$SUIT" need pi statusline check need-with-one-argument-is-usage 2 "usage:" -- "$SUIT" need claude check need-with-three-arguments-is-usage 2 "usage:" -- "$SUIT" need claude statusline x head -c 300000 /dev/urandom > "$store/needs/bare.md" check need-prints-a-prompt-over-one-block 0 "" -- "$SUIT" need codex bare same need-over-one-block-is-exact "$store/needs/bare.md" "$T/out" nconf sed -i.bak 's|^prompt = needs/statusline.md|prompt = needs/missing.md|' "$store/suit.conf"; rm -f "$store/suit.conf.bak" check need-with-a-missing-prompt 2 "cannot read the prompt" -- "$SUIT" need codex bare nworld sfail need-open-fails-somewhere nworld open EIO "cannot open $store/needs/bare.md: $EIO" "$SUIT" need codex bare sfail need-read-fails nworld read EIO "cannot print $store/needs/bare.md: $EIO" "$SUIT" need codex bare sfail need-write-fails nworld write EIO "cannot print $store/needs/bare.md: $EIO" "$SUIT" need codex bare nworld bad_n=0 for n in $(seq 1 30); do for f in read:$n:EINTR read:$n:short write:$n:short; do SUIT_FAULT=$f "$SUIT" need codex bare >"$T/out" 2>"$T/err" && cmp -s "$store/needs/bare.md" "$T/out" || bad_n=$n done done [ $bad_n = 0 ] && pass need-survives-interrupted-and-short-transfers || bad need-survives-interrupted-and-short-transfers "n=$bad_n" nworld lstat_hit=0 for n in $(seq 1 30); do SUIT_FAULT=lstat:$n:EIO "$SUIT" needs >"$T/out" 2>"$T/err" grep -qF "codex bare: cannot tell (cannot look at the file: $EIO)" "$T/out" && lstat_hit=1 done [ $lstat_hit = 1 ] && pass needs-lstat-failure-is-listed-as-cannot-tell || bad needs-lstat-failure-is-listed-as-cannot-tell # -- apply: the attention file follows the needs nfworld check apply-with-needs-not-done 0 "" -- "$SUIT" apply att_is apply-writes-an-item-for-each-need-not-done "$S_ITEM $B_ITEM" [ -L "$T/home/.claude/skills/ousterhout" ] && pass apply-with-needs-places-the-links || bad apply-with-needs-places-the-links check status-shows-need-items 0 "" -- "$SUIT" status has status-has-the-heading "needs you:" has status-shows-the-first-need "$S_ITEM" has status-shows-the-second-need "$B_ITEM" check status-line-counts-need-items 0 "" -- "$SUIT" status --line [ "$(cat "$T/out")" = "suit: 2 need you" ] && pass status-line-says-two-need-you || bad status-line-says-two-need-you "$(cat "$T/out")" ino=$(ls -i "$att" | cut -d' ' -f1) check apply-again-with-nothing-changed 0 "" -- "$SUIT" apply [ "$(ls -i "$att" | cut -d' ' -f1)" = "$ino" ] && pass apply-does-not-rewrite-an-unchanged-attention-file || bad apply-does-not-rewrite-an-unchanged-attention-file done_settings check apply-after-one-need-is-done 0 "" -- "$SUIT" apply att_is apply-drops-the-item-of-a-need-now-done "$B_ITEM" : > "$T/home/.codex/ready" check apply-after-all-are-done 0 "" -- "$SUIT" apply att_is apply-removes-the-file-when-all-are-done "" check apply-with-needs-done-and-no-file 0 "" -- "$SUIT" apply att_is apply-leaves-no-file-when-none-is-needed "" rm "$T/home/.codex/ready" printf 'none\n' > "$T/home/.claude/settings.json" check apply-after-a-need-is-undone 0 "" -- "$SUIT" apply att_is apply-brings-the-items-back "$S_ITEM $B_ITEM" printf '{"x":"slots/statusline"}\n' > "$T/home/.claude/settings.json" : > "$T/home/.codex/ready" chmod 000 "$T/home/.claude/settings.json" 2>/dev/null if [ -r "$T/home/.claude/settings.json" ]; then pass apply-counts-cannot-tell-as-not-done; else check apply-with-a-need-that-cannot-be-told 0 "" -- "$SUIT" apply att_is apply-counts-cannot-tell-as-not-done "$S_ITEM" fi chmod 600 "$T/home/.claude/settings.json" # -- a need the apply meets that exists nowhere else: a link apply places is what `exists` sees nworld sed -i.bak 's|^done = ~/.codex/ready exists|done = ~/.claude/skills/ousterhout exists|' "$store/suit.conf"; rm -f "$store/suit.conf.bak" check needs-before-the-link-is-placed 1 "" -- "$SUIT" needs check apply-judges-needs-after-it-places-links 0 "" -- "$SUIT" apply att_is apply-sees-the-link-it-just-placed "$S_ITEM" # -- a need that is no longer in the config, and other items untouched and in order nworld printf '%s\nlint mine\n skills/x.md:3: token-shaped value\nheld other: 7 of 30 files deleted\nneed old thing: run suit need old thing\n' "$B_ITEM" > "$att" check apply-with-other-items 0 "" -- "$SUIT" apply att_is apply-keeps-others-in-order-and-adds-at-the-end "$B_ITEM lint mine skills/x.md:3: token-shaped value held other: 7 of 30 files deleted $S_ITEM" printf 'need claude statusline: old words\nlint mine\nsync mine: no remote\n' > "$att" check apply-with-a-stale-header 0 "" -- "$SUIT" apply att_is apply-replaces-an-item-whose-words-differ "lint mine sync mine: no remote $S_ITEM $B_ITEM" printf '%s\n%s\n%s\n' "$S_ITEM" "$S_ITEM" "$B_ITEM" > "$att" check apply-with-a-doubled-item 0 "" -- "$SUIT" apply att_is apply-keeps-one-of-a-doubled-item "$S_ITEM $B_ITEM" printf 'ab\n\nneedy item\nneed claude statusliXe: run suit need claude statuslinX\nneed codex bare: run suit need codex bare' > "$att" check apply-with-lookalike-items 0 "" -- "$SUIT" apply att_is apply-keeps-lookalikes-and-drops-an-unknown-need "ab needy item $B_ITEM $S_ITEM" printf 'need claude statusline: run suit need claude statuslinX\n%s\n%s\n' "$B_ITEM" "$S_ITEM" > "$att" check apply-with-an-item-of-the-same-length 0 "" -- "$SUIT" apply att_is apply-fixes-an-item-of-the-same-length "$B_ITEM $S_ITEM" nconf head -n 11 "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" check apply-after-a-need-leaves-the-config 0 "" -- "$SUIT" apply att_is apply-drops-the-item-of-a-need-no-longer-there "$S_ITEM" head -n 8 "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" check apply-with-no-needs-left 0 "" -- "$SUIT" apply att_is apply-removes-the-file-with-no-needs "" # -- off takes the need items away and nothing else nworld "$SUIT" apply >/dev/null 2>&1 printf 'lint mine\n skills/x.md:3: token-shaped value\n' >> "$att" check off-with-need-items 0 "" -- "$SUIT" off att_is off-removes-need-items-and-keeps-the-rest "lint mine skills/x.md:3: token-shaped value" nworld "$SUIT" apply >/dev/null 2>&1 check off-with-only-need-items 0 "" -- "$SUIT" off att_is off-removes-the-file-when-only-need-items-were-in-it "" off_world() { nworld; "$SUIT" apply >/dev/null 2>&1; printf 'lint mine\n' >> "$att"; } off_only_world() { nworld; "$SUIT" apply >/dev/null 2>&1; } sfail off-attention-write-fails off_world rename EIO "cannot write $att: $EIO" "$SUIT" off sfail off-attention-remove-fails off_only_world unlink EIO "cannot remove $att: $EIO" "$SUIT" off # -- run applies by the same path nfworld "$SUIT" apply >/dev/null 2>&1 rm "$att" check run-unchanged-leaves-the-attention-file-alone 0 "" -- "$SUIT" run att_is run-with-no-change-writes-nothing "" printf 'one more line\n' >> "$store/needs/bare.md" check run-after-an-edit-applies-and-writes-the-items 0 "" -- "$SUIT" run att_is run-writes-need-items "$S_ITEM $B_ITEM" # -- apply refuses a config whose need is wrong, before it places anything nworld sed -i.bak "s|^done = ~/.codex/ready exists|done = codex/ready exists|" "$store/suit.conf"; rm -f "$store/suit.conf.bak" printf 'lint mine\n' > "$att" check apply-refuses-a-bad-test 1 "need codex bare: cannot read the test: " -- "$SUIT" apply [ ! -e "$T/home/.claude/skills/ousterhout" ] && pass apply-with-a-bad-test-places-nothing || bad apply-with-a-bad-test-places-nothing att_is apply-with-a-bad-test-leaves-the-attention-file "lint mine" # -- failures on the attention file, after the links are placed attn_world() { nworld; printf 'lint mine\n' > "$att"; } attn_done_world() { nworld; "$SUIT" apply >/dev/null 2>&1; done_settings; : > "$T/home/.codex/ready"; } sfail apply-attention-open-fails attn_world open EIO "cannot open $att: $EIO" "$SUIT" apply grep -qF "the links are in place, but the attention file is not up to date" "$T/err" && pass apply-says-the-links-are-in-place || bad apply-says-the-links-are-in-place "$(cat "$T/err")" [ -L "$T/home/.claude/skills/ousterhout" ] && pass apply-places-the-links-before-the-attention-file || bad apply-places-the-links-before-the-attention-file [ ! -e "$T/sh/stamp" ] && pass apply-leaves-no-stamp-when-the-attention-file-failed || bad apply-leaves-no-stamp-when-the-attention-file-failed att_is apply-open-failure-leaves-the-file "lint mine" sfail apply-attention-read-fails attn_world read EIO "cannot read $att: $EIO" "$SUIT" apply sfail apply-attention-write-fails attn_world rename EIO "cannot write $att: $EIO" "$SUIT" apply att_is apply-write-failure-keeps-the-file "lint mine" sfail apply-attention-remove-fails attn_done_world unlink EIO "cannot remove $att: $EIO" "$SUIT" apply big_att() { nworld; { printf 'lint big: '; head -c 131060 /dev/zero | tr '\0' x; printf '\n'; } > "$att"; } big_att check apply-attention-file-too-small-for-the-items 1 "$att would be over 131072 bytes" -- "$SUIT" apply big_att check apply-attention-file-would-be-too-big-says-links-placed 1 "the links are in place" -- "$SUIT" apply nworld { printf 'lint big: '; head -c 131070 /dev/zero | tr '\0' x; printf '\n'; } > "$att" check apply-attention-file-too-big 1 "$att is over 131072 bytes" -- "$SUIT" apply nworld mkdir -p "$att" check apply-attention-is-a-folder 1 "cannot read $att:" -- "$SUIT" apply # ---- hook slots: one program, or a folder of them -------------------------------- world cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o p [outfit o] slot hook/Stop/a = files/tts/announce.sh slot hook/Stop/b = files/tts/voices.json slot hook/Stop-x = files/tts/announce.sh [outfit p] slot hook/Start = files/tts/voices.json slot hook/Deep/er/c = files/tts/announce.sh EOF check nested-slots-apply 0 "" -- "$SUIT" apply [ "$(readlink "$T/sh/slots/hook/Stop/a")" = "$store/files/tts/announce.sh" ] && [ "$(readlink "$T/sh/slots/hook/Stop/b")" = "$store/files/tts/voices.json" ] && [ -L "$T/sh/slots/hook/Stop-x" ] && [ -L "$T/sh/slots/hook/Start" ] && [ -L "$T/sh/slots/hook/Deep/er/c" ] && pass nested-slots-are-linked || bad nested-slots-are-linked "$(ls -R "$T/sh/slots" | head)" check nested-slots-apply-again-changes-nothing 0 "" -- "$SUIT" apply [ "$(readlink "$T/sh/slots/hook/Stop/a")" = "$store/files/tts/announce.sh" ] && pass nested-slots-stay-linked || bad nested-slots-stay-linked grep -v '^slot hook/Stop/b' "$store/suit.conf" > "$T/conf.new" && cp "$T/conf.new" "$store/suit.conf" check nested-slot-dropped-apply 0 "" -- "$SUIT" apply [ ! -e "$T/sh/slots/hook/Stop/b" ] && [ -L "$T/sh/slots/hook/Stop/a" ] && pass nested-slot-dropped-is-removed || bad nested-slot-dropped-is-removed "$SUIT" off >/dev/null 2>&1 [ ! -e "$T/sh/slots" ] && pass nested-slots-off-removes-the-folders-it-made || bad nested-slots-off-removes-the-folders-it-made "$(ls -R "$T/sh/slots" | head)" world cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o p [outfit o] slot hook/Stop = files/tts/announce.sh [outfit p] slot hook/Stop/a = files/tts/voices.json EOF check slot-program-and-folder-clash-plan 1 "slot hook/Stop is a program in outfit o and a folder of programs in outfit p" -- "$SUIT" plan check slot-program-and-folder-clash-apply 1 "slot hook/Stop is a program in outfit o and a folder of programs in outfit p" -- "$SUIT" apply [ ! -e "$T/sh/slots" ] && [ ! -e "$T/sh/stamp" ] && pass slot-clash-places-nothing || bad slot-clash-places-nothing cat > "$store/suit.conf" <<'EOF' [harness claude] skills.user = ~/.claude/skills [wear user] outfits = o p [outfit o] slot hook/Stop/a = files/tts/announce.sh slot hook/Stap = files/tts/announce.sh [outfit p] slot hook/Stop/a/b = files/tts/voices.json EOF check slot-folder-under-a-program-clash 1 "slot hook/Stop/a is a program in outfit o and a folder of programs in outfit p" -- "$SUIT" plan # -- usage for c in plan apply status off run; do check "usage-$c-takes-no-arguments" 2 "usage:" -- "$SUIT" $c extra done # ---- more than one wardrobe: every wardrobe under the store is placed --------- M=$T/sh/store/mine P=$T/sh/store/public # sw: a scratch home with the wardrobes mine and public, each with its own assets sw() { rm -rf "$T/home" "$T/sh" mkdir -p "$T/home" "$M/skills/m1" "$M/instructions" "$M/files" "$M/prompts" \ "$P/skills/p1" "$P/files" "$P/prompts" export HOME="$T/home" SUIT_HOME="$T/sh" echo m1 > "$M/skills/m1/SKILL.md"; echo p1 > "$P/skills/p1/SKILL.md" echo mi > "$M/instructions/m.md"; echo mf > "$M/files/mf"; echo pf > "$P/files/pf" echo mpf > "$M/files/pf"; echo hook > "$P/files/hook.sh" echo "mine prompt" > "$M/prompts/mn.md"; echo "public prompt" > "$P/prompts/pn.md" cat > "$M/suit.conf" <<'EOF' [wear user] outfits = mine-out [outfit mine-out] include = pub-out skills = * instructions = instructions/m.md file ~/h/mf = files/mf [need h mn] prompt = prompts/mn.md done = ~/mn exists EOF cat > "$P/suit.conf" <<'EOF' [harness h] skills.user = ~/h/skills instructions.user = ~/h/AGENTS.md [outfit pub-out] skills = * slot hook/Stop = files/hook.sh file ~/h/pf = files/pf [need h pn] prompt = prompts/pn.md done = ~/pn exists [upstream up] url = https://example.com/x EOF } # is NAME FILE TARGET: FILE is a link to TARGET is() { if [ -L "$2" ] && [ "$(readlink "$2")" = "$3" ]; then pass "$1"; else bad "$1" "$2 -> $(readlink "$2" 2>/dev/null)"; fi; } # sconf MINE_TEXT PUBLIC_TEXT: the two configs, in a world where they are the only change sconf() { printf '%s' "$1" > "$M/suit.conf"; printf '%s' "$2" > "$P/suit.conf"; } sw snap "$T/home" > "$T/sw-before" check stack-plan 0 "" -- "$SUIT" plan has stack-plan-lists-mine "$M/skills/m1" has stack-plan-lists-public "$P/skills/p1" check stack-apply 0 "" -- "$SUIT" apply is stack-skills-star-is-per-wardrobe-m1 "$T/home/h/skills/m1" "$M/skills/m1" is stack-skills-star-is-per-wardrobe-p1 "$T/home/h/skills/p1" "$P/skills/p1" [ "$(ls "$T/home/h/skills" | wc -l | tr -d ' ')" = 2 ] && pass stack-skills-star-places-only-each-own || bad stack-skills-star-places-only-each-own is stack-instructions-from-one-wardrobe "$T/home/h/AGENTS.md" "$M/instructions/m.md" is stack-file-from-mine "$T/home/h/mf" "$M/files/mf" is stack-file-from-public "$T/home/h/pf" "$P/files/pf" is stack-slot-from-public "$T/sh/slots/hook/Stop" "$P/files/hook.sh" grep -qF "link $T/home/h/skills/p1 $P/skills/p1" "$T/sh/ledger" && grep -qF "link $T/home/h/skills/m1 $M/skills/m1" "$T/sh/ledger" && pass stack-ledger-holds-each-source-path || bad stack-ledger-holds-each-source-path (cd "$T" && "$SUIT" why p1 > "$T/out" 2>&1) has stack-why-names-the-wardrobe "user: outfit pub-out (wardrobe public), h, $T/home/h/skills/p1: placed" (cd "$T" && "$SUIT" why m1 > "$T/out" 2>&1) has stack-why-names-the-other-wardrobe "outfit mine-out (wardrobe mine)" check stack-needs-from-both 1 "" -- "$SUIT" needs has stack-needs-lists-mine "h mn: not done" has stack-needs-lists-public "h pn: not done" check stack-need-prints-publics-prompt 0 "" -- "$SUIT" need h pn has stack-need-public-prompt "public prompt" check stack-need-prints-mines-prompt 0 "" -- "$SUIT" need h mn has stack-need-mine-prompt "mine prompt" check stack-need-unknown 1 "no need h zz in the wardrobes under $T/sh/store" -- "$SUIT" need h zz check stack-check-dumps-the-set 0 "" -- "$SUIT" check has stack-check-has-public-harness "harness h" has stack-check-has-mine-need "need h mn" has stack-check-has-public-need "need h pn" check stack-off 0 "" -- "$SUIT" off snap "$T/home" > "$T/sw-after" cmp -s "$T/sw-before" "$T/sw-after" && pass stack-off-leaves-home-as-found || bad stack-off-leaves-home-as-found "$(diff "$T/sw-before" "$T/sw-after" | head -4)" [ ! -s "$T/sh/ledger" ] && pass stack-off-empties-the-ledger || bad stack-off-empties-the-ledger # -- what is not a wardrobe sw mkdir -p "$T/sh/store/emptyw" "$T/sh/store/.hid" "$T/sh/store/bad name" "$T/sh/store/dirconf/suit.conf" echo garbage > "$T/sh/store/.hid/suit.conf"; echo garbage > "$T/sh/store/bad name/suit.conf" echo x > "$T/sh/store/afile" check stack-folders-that-are-not-wardrobes-are-skipped 0 "" -- "$SUIT" apply check stack-check-skips-them 0 "" -- "$SUIT" check is stack-the-others-still-placed "$T/home/h/skills/p1" "$P/skills/p1" sw touch "$T/sh/public.journal" check stack-journal-of-the-second-wardrobe 15 "store public has an unfinished update" -- "$SUIT" plan check stack-journal-stops-needs 15 "store public has an unfinished update" -- "$SUIT" needs rm -f "$T/sh/public.journal" # -- at most 16 sw i=1; while [ $i -le 14 ]; do mkdir "$T/sh/store/w$i"; printf '[outfit o%d]\n' $i > "$T/sh/store/w$i/suit.conf"; i=$((i + 1)); done check stack-sixteen-wardrobes-are-fine 0 "" -- "$SUIT" plan mkdir "$T/sh/store/w15"; printf '[outfit o15]\n' > "$T/sh/store/w15/suit.conf" check stack-seventeen-wardrobes-are-an-error 1 "more than 16 wardrobes with a suit.conf in $T/sh/store" -- "$SUIT" plan check stack-seventeen-wardrobes-check 2 "more than 16 wardrobes" -- "$SUIT" check check stack-seventeen-wardrobes-needs 2 "more than 16 wardrobes" -- "$SUIT" needs # -- no wardrobe, a store that cannot be read sw rm "$M/suit.conf" "$P/suit.conf" check stack-no-config-needs 2 "store:0: no wardrobe with a suit.conf" -- "$SUIT" needs check stack-no-config-check 2 "store:0: no wardrobe with a suit.conf" -- "$SUIT" check rm -rf "$T/sh/store" check stack-no-store-plan 1 "store:0: no wardrobe with a suit.conf" -- "$SUIT" plan sw check stack-status-without-a-home 1 "neither SUIT_HOME nor HOME is set" -- env -u SUIT_HOME -u HOME "$SUIT" status check stack-store-listing-fails 1 "cannot read $T/sh/store" -- env SUIT_FAULT=listdir:1 "$SUIT" plan check stack-store-listing-fails-for-check 1 "cannot read $T/sh/store" -- env SUIT_FAULT=listdir:1 "$SUIT" check check stack-conf-stat-fails 1 "cannot look at $T/sh/store/" -- env SUIT_FAULT=stat:1:EACCES "$SUIT" plan check stack-dump-write-fails 1 "cannot write the dump" -- env SUIT_FAULT=write:1 "$SUIT" check tiny fresh check stack-watch-of-the-store-fails 1 "cannot read $T/sh/store:" -- env SUIT_FAULT=listdir:5 "$SUIT" apply # -- duplicate sections across wardrobes sw sconf '[harness h] skills.user = ~/a ' '# c [harness h] ' check stack-duplicate-harness 1 "public/suit.conf:2: duplicate section [harness h]; first at $M/suit.conf:1" -- "$SUIT" plan sconf '[harness h] [outfit o] ' '[outfit o] ' check stack-duplicate-outfit 1 "public/suit.conf:1: duplicate section [outfit o]; first at $M/suit.conf:2" -- "$SUIT" apply sconf '[harness h] [wear user] ' '[wear user] ' check stack-duplicate-wear-user 1 "public/suit.conf:1: duplicate section [wear user]; first at $M/suit.conf:2" -- "$SUIT" plan sconf '[wear personal github.com/o/p machine=studio] ' ' [wear personal github.com/o/p machine=studio] ' check stack-duplicate-wear-with-target-and-machine 2 "public/suit.conf:2: duplicate section [wear personal github.com/o/p machine=studio]; first at $M/suit.conf:1" -- "$SUIT" check sconf '[harness h] [need h n] prompt = p done = ~/n exists ' '[need h n] prompt = p done = ~/n exists ' check stack-duplicate-need 1 "public/suit.conf:1: duplicate section [need h n]; first at $M/suit.conf:2" -- "$SUIT" plan sconf '[upstream u] ' '[harness h] [upstream u] ' check stack-duplicate-upstream 1 "public/suit.conf:2: duplicate section [upstream u]; first at $M/suit.conf:1" -- "$SUIT" plan sconf '[wear user] ' '[wear user machine=box] ' check stack-wear-user-and-machine-wear-are-different 0 "" -- "$SUIT" check # -- references and cycles are checked on the combined set sconf '[harness h] [wear user] outfits = a [outfit a] include = ghost ' '[outfit b] ' check stack-include-of-nothing 1 "mine/suit.conf:5: include of unknown outfit 'ghost'" -- "$SUIT" plan sconf '[wear user] outfits = a [outfit a] include = b ' '[outfit b] include = a ' check stack-include-cycle-across-wardrobes 1 "public/suit.conf:2: include cycle: a -> b -> a" -- "$SUIT" plan sconf '[need zz n] prompt = p done = ~/n exists ' '[harness h] ' check stack-need-of-an-unknown-harness 1 "mine/suit.conf:1: need names unknown harness 'zz'" -- "$SUIT" apply sconf '[outfit a] include = b ' '[outfit b] only = nope ' check stack-only-names-a-harness-nowhere 2 "public/suit.conf:2: only names unknown harness 'nope'" -- "$SUIT" check # -- a clash across wardrobes, and an error in the second file sw sconf '[wear user] outfits = a b [outfit a] file ~/h/pf = files/pf ' '[outfit b] file ~/h/pf = files/pf ' check stack-clash-across-wardrobes 1 "two assets want $T/home/h/pf: $M/files/pf (in wardrobe mine) and $P/files/pf (in wardrobe public)" -- "$SUIT" apply [ ! -e "$T/home/h" ] && [ ! -e "$T/sh/ledger" ] && pass stack-clash-places-nothing || bad stack-clash-places-nothing sw printf '[harness h]\nthis is not a pair\n' > "$P/suit.conf" snap "$T/home" > "$T/sw-before" check stack-error-in-second-file-stops-apply 1 "public/suit.conf:2: expected KEY = VALUE" -- "$SUIT" apply snap "$T/home" > "$T/sw-after" cmp -s "$T/sw-before" "$T/sw-after" && [ ! -e "$T/sh/ledger" ] && [ ! -e "$T/sh/stamp" ] && pass stack-error-in-second-file-places-nothing || bad stack-error-in-second-file-places-nothing sw rm "$P/files/pf" check stack-a-file-missing-from-the-second-store 1 "$P/files/pf" -- "$SUIT" apply sw printf '[outfit pub-out]\nskills = nosuch\n[harness h]\n' > "$P/suit.conf" check stack-pattern-matches-only-its-own-store 1 "outfit pub-out: skills 'nosuch' matches nothing in the store" -- "$SUIT" plan sw printf '[harness h]\nskills.user = ~/h/skills\n[outfit pub-out]\nskills = *\n[need h pn]\nprompt = prompts/missing.md\ndone = ~/pn exists\n' > "$P/suit.conf" check stack-need-prompt-resolves-in-its-own-store 1 "public/suit.conf:6: need h pn: cannot read the prompt" -- "$SUIT" apply # -- the limits bound the combined set sw { i=1; while [ $i -le 32 ]; do printf '[harness a%d]\n' $i; i=$((i + 1)); done; } > "$M/suit.conf" { i=1; while [ $i -le 31 ]; do printf '[harness b%d]\n' $i; i=$((i + 1)); done; } > "$P/suit.conf" check stack-sixty-three-harnesses-fit 0 "" -- "$SUIT" check printf '[harness b32]\n' >> "$P/suit.conf" check stack-sixty-four-harnesses-fit 0 "" -- "$SUIT" check printf '[harness b33]\n' >> "$P/suit.conf" check stack-combined-harness-limit 2 "public/suit.conf:33: too many harness sections (limit 64)" -- "$SUIT" check awk 'BEGIN { for (i = 0; i < 6000; i++) printf "# %098d\n", i }' > "$M/suit.conf" cp "$M/suit.conf" "$P/suit.conf" check stack-combined-size-limit 2 "public/suit.conf:0: the config files together are over the limit of 1048576 bytes" -- "$SUIT" check { printf '[outfit o]\n'; i=0; while [ $i -lt 5000 ]; do printf 'file ~/m%d = files/f\n' $i; i=$((i + 1)); done; } > "$M/suit.conf" { printf '[outfit p]\n'; i=0; while [ $i -lt 4000 ]; do printf 'file ~/p%d = files/f\n' $i; i=$((i + 1)); done; } > "$P/suit.conf" check stack-combined-entry-limit 2 "public/suit.conf:1: too many entries (limit 8192)" -- "$SUIT" check # -- a wardrobe that appears or goes is noticed by the no-change run FRONT=${FRONT:-$(dirname "$SUIT")/suit-run} sw "$SUIT" machine box cat > "$M/suit.conf" <<'EOF' [harness h] skills.user = ~/h/skills [wear user] outfits = m-out [outfit m-out] skills = * EOF rm -rf "$P" check stack-one-wardrobe-applies 0 "" -- "$SUIT" apply check stack-one-wardrobe-is-no-change 0 "" -- "$SUIT" compare mkdir -p "$P/skills/p1"; echo p1 > "$P/skills/p1/SKILL.md" printf '[wear user machine=box]\noutfits = pub-out\n[outfit pub-out]\nskills = *\n' > "$P/suit.conf" check stack-a-new-wardrobe-is-a-change 10 "" -- "$SUIT" compare has stack-a-new-wardrobe-is-reported "changed: $T/sh/store" check stack-second-wardrobe-applies 0 "" -- "$SUIT" apply is stack-second-wardrobe-placed "$T/home/h/skills/p1" "$P/skills/p1" is stack-first-wardrobe-still-placed "$T/home/h/skills/m1" "$M/skills/m1" check stack-two-wardrobes-are-no-change 0 "" -- "$SUIT" compare "$FRONT" > "$T/out" 2> "$T/err"; rc=$? if [ $rc -eq 0 ] && [ ! -s "$T/out" ] && [ ! -s "$T/err" ]; then pass stack-two-wardrobes-suit-run-is-silent-exit-0; else bad stack-two-wardrobes-suit-run-is-silent-exit-0 "exit $rc $(cat "$T/err")"; fi mkdir "$T/sh/store/late" check stack-a-folder-without-config-is-a-change-once 10 "" -- "$SUIT" compare check stack-it-applies 0 "" -- "$SUIT" apply check stack-and-is-then-no-change 0 "" -- "$SUIT" compare printf '[outfit zz]\n' > "$T/sh/store/late/suit.conf" check stack-a-config-that-appears-in-a-folder-is-a-change 10 "" -- "$SUIT" compare has stack-the-folder-is-reported "changed: $T/sh/store/late" check stack-it-applies-again 0 "" -- "$SUIT" apply check stack-no-change-again 0 "" -- "$SUIT" compare rm -rf "$P" check stack-a-wardrobe-that-goes-is-a-change 10 "" -- "$SUIT" compare check stack-apply-after-it-went 0 "" -- "$SUIT" apply [ ! -e "$T/home/h/skills/p1" ] && [ -L "$T/home/h/skills/m1" ] && pass stack-removing-a-wardrobe-removes-its-placements || bad stack-removing-a-wardrobe-removes-its-placements [ ! -L "$T/home/h/skills/p1" ] && ! grep -q "store/public" "$T/sh/ledger" && pass stack-ledger-forgets-the-wardrobe || bad stack-ledger-forgets-the-wardrobe echo "place.sh: $total cases, $failed failed" [ "$failed" -eq 0 ]