Cotton code
125 lines · 6.9 KB · ShellRaw
#!/usr/bin/env bash# The faces walk's household (lane faces, 23 Oct 2026): a phone's state# folder (client/connection.json + client/<database>/replica.db, the layout# `scripts/perf/pages.py fixture` makes) over an invented household that# holds, beyond `cotton-headless seed --size small`, the tools whose deck# cards the faces lane draws, each with rows to draw: Machines (machine# face), Quotas (quota), Subscriptions (subscription; renewals in the weeks# ahead, so Home's money due names them), Money (views Past, Future and Bank# accounts over the seed's movements and accounts: transaction and account# faces), Birthdays (a view over People: birthday face, with people whose# birthdays come round soon) and Artifacts (three HTML pages filed as# documents).## THE CARDS ARE THE COORDINATOR'S. Each fixture mirrors the owner's real# database-only tool — its table ids and column keys as scripts/dev/# machine-row.sh and quota-row.sh write them, Money's three views by their# labels — and carries no card of its own: cards.json holds every card block# the coordinator installs (tool → table or view id → card), and seed.py# packages puts each on its table or view at pack time. The import refusing a# block refuses the walk, so a card that imports here imports there.##   scripts/faces-walk/seed.sh <state dir>## Every row is invented: the seed's, the fixtures' under tools/, and the# dates moved to fall around today. Nothing here reads or opens a person's# database; the household is a fresh folder at <state dir>.work, founded with# COTTON_FLAVOR=dev. Tools go in through the core's own tools.import and rows# change through its update_record (`cotton-headless time`, which runs each# call twice: a second update is refused as "changes nothing", and an# import's second copy of its sample rows is dropped after). The HTML pages# are written as rows, as the seed writes its documents, because a document# arrives only as its file and this household has no store to file one in.# The shelves' covers, posters and sleeve (art/, cut from the Codex# references; invented titles, test and walk fixtures only, never in the# app) go in through the phone's own capture.media, which keeps their bytes# in this household's media store and its ledger names where: the copied# state carries those paths, which the simulator reads off this Mac.## Uses the built cotton-headless (COTTON_HEADLESS, default# ~/lanes/faces/target/debug/cotton-headless); builds nothing.set -euo pipefailREPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"HERE="$REPO/scripts/faces-walk"BIN="${COTTON_HEADLESS:-$HOME/lanes/faces/target/debug/cotton-headless}"TODAY="${FACES_WALK_TODAY:-$(date +%F)}"[ $# -eq 1 ] || { echo "usage: scripts/faces-walk/seed.sh <state dir>" >&2; exit 2; }[ -x "$BIN" ] || { echo "faces-walk: no cotton-headless at $BIN (build it, or name it in COTTON_HEADLESS)" >&2; exit 2; }mkdir -p "$(dirname "$1")"STATE="$(cd "$(dirname "$1")" && pwd -P)/$(basename "$1")"WORK="$STATE.work". "$REPO/scripts/lib/owned-root.sh". "$REPO/scripts/lib/real-data-root.sh"refuse_wide_root "the walk's state folder" "$STATE"refuse_wide_root "the walk's household folder" "$WORK"refuse_real_data_root faces-walk "$STATE"if [ -e "$WORK" ]; then  [ -f "$WORK/.faces-walk" ] || { echo "faces-walk: $WORK exists and is not this script's; remove it yourself" >&2; exit 2; }  rm -rf "$WORK"fimkdir -p "$WORK/packages"touch "$WORK/.faces-walk"HOUSEHOLD="$WORK/household"# headless <calls file> <log>: run the calls on the household, fail on a refusal.headless() {  COTTON_FLAVOR=dev "$BIN" time --calls "$(cat "$1")" --times 1 --data-dir "$HOUSEHOLD" > "$2" 2>&1 \    || { cat "$2" >&2; echo "faces-walk: cotton-headless failed (see $2)" >&2; exit 1; }  python3 "$HERE/seed.py" checked "$2"}echo "faces-walk: seeding an invented household in $HOUSEHOLD"COTTON_FLAVOR=dev "$BIN" seed --data-dir "$HOUSEHOLD" --size small > "$WORK/seed.json"DB="$(ls "$HOUSEHOLD"/files/*/*/life.db | head -1)"echo "faces-walk: importing ${TODAY}'s tools"python3 "$HERE/seed.py" packages "$HERE/tools" "$WORK/packages" "$TODAY" > "$WORK/imports.json"headless "$WORK/imports.json" "$WORK/imports.log"python3 "$HERE/seed.py" dedupe "$DB" "$HERE/tools"echo "faces-walk: birthdays ahead, wishes and money due"python3 "$HERE/seed.py" touches "$DB" "$TODAY" > "$WORK/touches.json"headless "$WORK/touches.json" "$WORK/touches.log"python3 "$HERE/seed.py" artifacts "$DB" "$TODAY"echo "faces-walk: the shelves' covers, posters and sleeves"python3 "$HERE/seed.py" pictures "$HERE/art" > "$WORK/pictures.json"headless "$WORK/pictures.json" "$WORK/pictures.log"echo "faces-walk: books, films, a series' episodes and an album's song on the shelves"for pass in 1 2 3; do  python3 "$HERE/seed.py" shelves "$DB" "$TODAY" "$pass" "$HERE/art" > "$WORK/shelves-$pass.json"  headless "$WORK/shelves-$pass.json" "$WORK/shelves-$pass.log"  python3 "$HERE/seed.py" kept "$DB"done# Read back through the core: each tool's rows and views, and Home's two reads.cat > "$WORK/reads.json" <<'EOF'[  {"name": "tools", "method": "tools.list", "args": {}},  {"name": "machine", "method": "records.list", "args": {"table": "machine"}},  {"name": "quota", "method": "records.list", "args": {"table": "quota"}},  {"name": "quota_reading", "method": "records.list", "args": {"table": "quota_reading"}},  {"name": "subscription", "method": "records.list", "args": {"table": "subscription"}},  {"name": "transaction", "method": "records.list", "args": {"table": "transaction"}},  {"name": "money_account", "method": "records.list", "args": {"table": "money_account"}},  {"name": "money past", "method": "records.list", "args": {"table": "transaction", "view": "money/past"}},  {"name": "money future", "method": "records.list", "args": {"table": "transaction", "view": "money/future"}},  {"name": "money bank_accounts", "method": "records.list", "args": {"table": "money_account", "view": "money/bank_accounts"}},  {"name": "birthdays coming", "method": "records.list", "args": {"table": "person", "view": "birthdays/coming"}},  {"name": "views machines", "method": "shell.fan", "args": {"tool": "machines"}},  {"name": "views quotas", "method": "shell.fan", "args": {"tool": "quotas"}},  {"name": "views subscriptions", "method": "shell.fan", "args": {"tool": "subscriptions"}},  {"name": "views money", "method": "shell.fan", "args": {"tool": "money"}},  {"name": "views birthdays", "method": "shell.fan", "args": {"tool": "birthdays"}},  {"name": "views artifacts", "method": "shell.fan", "args": {"tool": "artifacts"}},  {"name": "birthdays", "method": "cards.birthdays", "args": {"days": 30}},  {"name": "money due", "method": "cards.moneyDue", "args": {"days": 30}}]EOFheadless "$WORK/reads.json" "$WORK/reads.log"python3 "$HERE/seed.py" counts "$DB" | tee "$WORK/counts.json"echo "faces-walk: the phone's state"python3 "$HERE/seed.py" state "$HOUSEHOLD" "$STATE"echo "faces-walk: state in $STATE (household in $HOUSEHOLD)"