salvage 2026-11-06: uncommitted work from scratch/darkwing-scratch/r187/wt (disk cleanup #824)
This commit is contained in:
1 parent
f81ebfbae9
commit
79db90a775
3 files changed
+376
-16
No files matched your search
+115
-7
@@ -2,7 +2,8 @@
|
||||
# Stack activate and rollback, health-gated (D1, #1659; docs/plans/2026-10-18_stack-release.md).
|
||||
# Moves the bus, the Console and the human CLI from the pointer's copy to another copy together,
|
||||
# behind a health gate, and puts the old stack back inside the same run when the gate fails.
|
||||
# Console tester listener flags follow target support (row 176, #1674).
|
||||
# Console tester listener flags follow target support (row 176, #1674); so does the row 178 proof
|
||||
# pair, which activate sets or drops (row 187, #1685).
|
||||
# Design and tests: agents/darkwing/work/queue-162/BUILD.md.
|
||||
#
|
||||
# Who runs it. Decision 96 (Mos, mos-0716) lets this script stop and start the live units under
|
||||
@@ -27,11 +28,13 @@ BIN="$HOME/.npm-global/bin"
|
||||
UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
|
||||
CONSOLE_UNIT=mosaic-webui.service
|
||||
TIMEOUT=60 WANT_PM=0 AFTER_HARNESS=0 MIGRATE=0 PLAN=0 RESTORE="" EVENTS="" TESTER_PORT=""
|
||||
PROOF_HEADER="" PROOF_FILE="" NO_PROOF=0
|
||||
|
||||
usage() {
|
||||
cat >&2 <<'USAGE'
|
||||
usage: stack-release.sh adopt BUSINESS
|
||||
stack-release.sh activate ID BUSINESS [--pm | --pm-after-harness] [--migrate] [--tester-port N] [--timeout S] [--plan]
|
||||
stack-release.sh activate ID BUSINESS [--pm | --pm-after-harness] [--migrate] [--tester-port N]
|
||||
[--proof-header NAME --proof-file PATH | --no-proof] [--timeout S] [--plan]
|
||||
stack-release.sh pm-on BUSINESS [--timeout S]
|
||||
stack-release.sh rollback BUSINESS [--restore ACTIVATION [--events N]] [--timeout S] [--plan]
|
||||
stack-release.sh status BUSINESS
|
||||
@@ -76,6 +79,9 @@ parse_opts() {
|
||||
--pm) [ "$OP" = activate ] || usage; WANT_PM=1; shift ;;
|
||||
--pm-after-harness) [ "$OP" = activate ] || usage; AFTER_HARNESS=1; shift ;;
|
||||
--tester-port) [ "$OP" = activate ] && [ $# -ge 2 ] && [ -n "$2" ] || usage; TESTER_PORT="$2"; shift 2 ;;
|
||||
--proof-header) [ "$OP" = activate ] && [ $# -ge 2 ] && [ -n "$2" ] || usage; PROOF_HEADER="$2"; shift 2 ;;
|
||||
--proof-file) [ "$OP" = activate ] && [ $# -ge 2 ] && [ -n "$2" ] || usage; PROOF_FILE="$2"; shift 2 ;;
|
||||
--no-proof) [ "$OP" = activate ] || usage; NO_PROOF=1; shift ;;
|
||||
--migrate) [ "$OP" = activate ] || usage; MIGRATE=1; shift ;;
|
||||
--restore) [ "$OP" = rollback ] && [ $# -ge 2 ] && [[ "$2" =~ ^[0-9]{8}T[0-9]{6}Z-[0-9a-f]{12}(-[1-9])?$ ]] || usage; RESTORE="$2"; shift 2 ;;
|
||||
--events) [ "$OP" = rollback ] && [ $# -ge 2 ] && [[ "$2" =~ ^(0|[1-9][0-9]*)$ ]] || usage; EVENTS="$2"; shift 2 ;;
|
||||
@@ -87,6 +93,9 @@ parse_opts() {
|
||||
[ -z "$TESTER_PORT" ] || [ "$PLAN" = 1 ] || valid_tester_port "$TESTER_PORT" 7332 || usage
|
||||
# --pm-after-harness replaces --pm (row 169 item 1), so the two never go together.
|
||||
[ "$WANT_PM" = 0 ] || [ "$AFTER_HARNESS" = 0 ] || usage
|
||||
# The proof pair goes together, and --no-proof goes alone (row 187).
|
||||
[ "${PROOF_HEADER:+1}" = "${PROOF_FILE:+1}" ] || usage
|
||||
[ "$NO_PROOF" = 0 ] || [ -z "$PROOF_HEADER" ] || usage
|
||||
local d
|
||||
for d in "$COPIES" "$BIN"; do
|
||||
case "$d" in /*) ;; *) usage ;; esac
|
||||
@@ -228,12 +237,16 @@ target_schema() {
|
||||
|
||||
in_chain() { local v; for v in "${T_CHAIN[@]}"; do [ "$v" != "$1" ] || return 0; done; return 1; }
|
||||
|
||||
# The item 3 checks on the target copy, in order: copy, schema, already-active.
|
||||
# The item 3 checks on the target copy, in order: copy, schema, already-active. An activate that
|
||||
# sets a proof pair, or drops the pointer's pair with --no-proof, may name the pointer's copy: it
|
||||
# re-pins the live copy with new Console flags (row 187, Part B's B3 and B-R1).
|
||||
check_target() {
|
||||
copy_exists "$TO" 2>/dev/null || refuse copy-missing "no copy $TO in $COPIES"
|
||||
copy_ok "$TO" 2>/dev/null || refuse copy-unreachable "$TO is not reachable from refactor and origin/refactor"
|
||||
target_schema "$TO" || refuse copy-schema-unknown "cannot read SCHEMA_VERSION and its chain from $COPIES/$TO/packages/bus/src/store.mjs"
|
||||
[ "$TO" != "$P_COPY" ] || refuse already-active "$TO is the pointer's copy"
|
||||
[ "$TO" != "$P_COPY" ] || [ -n "$PROOF_HEADER" ] ||
|
||||
{ [ "$NO_PROOF" = 1 ] && [[ " ${P_CONSOLE[*]} " == *" --proof-header "* ]]; } ||
|
||||
refuse already-active "$TO is the pointer's copy"
|
||||
}
|
||||
|
||||
# --- Plug-in kinds (row 169) ---
|
||||
@@ -637,8 +650,8 @@ flags_drift() {
|
||||
[ -z "$d" ] || refuse unit-flags-drift "the units differ from the pointer; settle it first:$d"
|
||||
}
|
||||
|
||||
# Row 178: --proof-header and --proof-file are an opaque pair in P_CONSOLE.
|
||||
# Carry them unchanged on re-pin and rollback; never read the proof value.
|
||||
# Row 178: --proof-header and --proof-file are a pair in P_CONSOLE, which proof_for_target (row
|
||||
# 187) carries unchanged, replaces or drops; never read the proof value.
|
||||
# Resolve desired flags independently of the pointer and effective units, so a hand-edited
|
||||
# unit still refuses drift and a failed attempt can restore exactly the captured stack.
|
||||
# Read the target's own Console, because old copies cannot start with the new flag.
|
||||
@@ -670,6 +683,98 @@ console_for_target() {
|
||||
RUN_CONSOLE=("${without_tester[@]}")
|
||||
DROP_TESTER="--tester-port $inherited"
|
||||
fi
|
||||
proof_for_target
|
||||
}
|
||||
|
||||
# Row 187: the row 178 proof pair in RUN_CONSOLE. A new pair replaces the pointer's and goes last;
|
||||
# --no-proof drops it. With neither, a target Console that takes --proof-header carries the pair
|
||||
# unchanged. One that doesn't drops it on rollback, the way back, and refuses proof-target on
|
||||
# activate, so only --no-proof turns the proof off. Sets PROOF_PLAN (the plan's proof: line) and
|
||||
# PROOF_STEP (a steps log line, or empty).
|
||||
proof_for_target() {
|
||||
local supported=0 had=0 header="" file="" i
|
||||
local -a without_proof=()
|
||||
grep -q -- '--proof-header' "$COPIES/$TO/packages/webui/src/cli.mjs" && supported=1
|
||||
for ((i = 0; i < ${#RUN_CONSOLE[@]}; i++)); do
|
||||
case "${RUN_CONSOLE[i]}" in
|
||||
--proof-header) had=1; i=$((i + 1)); header="${RUN_CONSOLE[i]:-}" ;;
|
||||
--proof-file) had=1; i=$((i + 1)); file="${RUN_CONSOLE[i]:-}" ;;
|
||||
*) without_proof+=("${RUN_CONSOLE[i]}") ;;
|
||||
esac
|
||||
done
|
||||
PROOF_PLAN="proof: off" PROOF_STEP=""
|
||||
if [ "$NO_PROOF" = 1 ]; then
|
||||
RUN_CONSOLE=("${without_proof[@]}")
|
||||
if [ "$had" = 1 ]; then
|
||||
PROOF_PLAN="proof: dropped; --no-proof drops header $header"
|
||||
PROOF_STEP="drop --proof-header $header --proof-file $file; --no-proof was given"
|
||||
else
|
||||
PROOF_PLAN="proof: off; --no-proof was given and the pointer holds no pair"
|
||||
PROOF_STEP="--no-proof was given and the pointer holds no proof pair, so there is nothing to drop"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
if [ -n "$PROOF_HEADER" ]; then
|
||||
# webui-service.sh renders the pair after the preview flags and before --send and
|
||||
# --tester-port, and flags_drift compares the pointer with that argv as it stands.
|
||||
header="$PROOF_HEADER" file="$PROOF_FILE" RUN_CONSOLE=()
|
||||
for ((i = 0; i < ${#without_proof[@]}; i++)); do
|
||||
case "${without_proof[i]}" in --send | --tester-port) break ;; esac
|
||||
RUN_CONSOLE+=("${without_proof[i]}")
|
||||
done
|
||||
RUN_CONSOLE+=(--proof-header "$header" --proof-file "$file" "${without_proof[@]:i}")
|
||||
PROOF_PLAN="proof: on, header $header, file $file"
|
||||
[ "$supported" = 1 ] || check_refuse proof-target "$TO's Console does not support --proof-header"
|
||||
elif [ "$had" = 0 ]; then
|
||||
return 0
|
||||
elif [ "$supported" = 0 ] && [ "$OP" = rollback ]; then
|
||||
RUN_CONSOLE=("${without_proof[@]}")
|
||||
PROOF_PLAN="proof: dropped; $TO's Console does not support --proof-header, so the rollback drops header $header"
|
||||
PROOF_STEP="drop --proof-header $header --proof-file $file; the target Console does not support it"
|
||||
return 0
|
||||
else
|
||||
PROOF_PLAN="proof: carried, header $header"
|
||||
[ "$supported" = 1 ] || check_refuse proof-target "$TO's Console does not support --proof-header, which the pointer's Console flags carry; give --no-proof to drop the pair"
|
||||
fi
|
||||
proof_checks "$header" "$file"
|
||||
}
|
||||
|
||||
# Row 187: proofOptions' own rules (packages/webui/src/serve.mjs), checked before anything stops so
|
||||
# the Console can't fail its start on them. The file gets stat only: this script never opens it,
|
||||
# and no line it writes holds the value.
|
||||
proof_checks() {
|
||||
local header="${1,,}" auth="" seen=" " missing="" f i why
|
||||
for ((i = 0; i < ${#RUN_CONSOLE[@]}; i++)); do
|
||||
seen+="${RUN_CONSOLE[i]} "
|
||||
[ "${RUN_CONSOLE[i]}" != --auth-header ] || auth="${RUN_CONSOLE[i + 1]:-}"
|
||||
done
|
||||
for f in --public-host --auth-header --allow-user; do
|
||||
[[ "$seen" == *" $f "* ]] || missing+=" $f"
|
||||
done
|
||||
[ -z "$missing" ] || check_refuse proof-needs-preview "the proof pair needs --public-host, --auth-header and --allow-user in the Console flags; the run's flags lack$missing"
|
||||
if ! [[ "$header" =~ ^[a-z0-9][a-z0-9-]{0,63}$ ]] || [ "$header" = host ] || [ "$header" = origin ] ||
|
||||
[ "$header" = x-mosaic-tester ] || [ "$header" = "${auth,,}" ]; then
|
||||
check_refuse proof-header-invalid "--proof-header $1 must be a header name of a-z, 0-9 and - (64 at most, lowercased) other than host, origin, x-mosaic-tester and the --auth-header value"
|
||||
fi
|
||||
why="$(proof_file_problem "$2")"
|
||||
[ -z "$why" ] || check_refuse proof-file-invalid "--proof-file $2 $why"
|
||||
}
|
||||
|
||||
# Why the proof file can't serve, or nothing. lstat, stat and realpath only; the order follows
|
||||
# webui-service.sh render, which refuses the same files.
|
||||
proof_file_problem() {
|
||||
local st uid mode type real copies
|
||||
case "$1" in /*) ;; *) echo "is not an absolute path"; return ;; esac
|
||||
case "$1" in *[!A-Za-z0-9/._+-]*) echo "holds a character outside [A-Za-z0-9/._+-]"; return ;; esac
|
||||
[ ! -L "$1" ] || { echo "is a symlink"; return; }
|
||||
st="$(stat -c '%u:%a:%F' -- "$1" 2>/dev/null)" || { echo "cannot be found"; return; }
|
||||
uid="${st%%:*}" st="${st#*:}"
|
||||
mode="${st%%:*}" type="${st#*:}"
|
||||
case "$type" in "regular file" | "regular empty file") ;; *) echo "is not a regular file"; return ;; esac
|
||||
real="$(realpath -e -- "$1")" && copies="$(realpath -m -- "$COPIES")" || { echo "cannot be resolved"; return; }
|
||||
case "$real" in "$REPO" | "$REPO"/* | "$copies" | "$copies"/*) echo "is inside the repository or the copies"; return ;; esac
|
||||
[ "$mode" = 600 ] || [ "$mode" = 400 ] || { echo "has mode $mode, not 600 or 400"; return; }
|
||||
[ "$uid" = "$(id -u)" ] || echo "is owned by uid $uid, not $(id -u), the uid this script runs as"
|
||||
}
|
||||
|
||||
# The item 3 checks after the pointer, shared by activate and rollback, for target $TO.
|
||||
@@ -794,6 +899,7 @@ plan() {
|
||||
echo "plan: $OP for $BUSINESS"
|
||||
echo "from: $P_COPY"
|
||||
echo "to: $TO"
|
||||
[ "$TO" != "$P_COPY" ] || echo "note: $TO is the pointer's copy; the run re-pins it and only the Console flags change"
|
||||
echo "store schema: $S_SCHEMA ($S_FROM)"
|
||||
echo "target schema: $T_SCHEMA"
|
||||
[ "$S_SCHEMA" = "$P_SCHEMA" ] || [ -n "$S_CHANGED" ] || echo "note: the pointer says $P_SCHEMA; the run reads the stopped store and goes by that"
|
||||
@@ -830,6 +936,7 @@ plan() {
|
||||
[ "$RUN_PENDING" = 0 ] || echo "pm: the bus starts without --pm and the PM stays pending; next: Jason's plugins set of harness, then pm-on"
|
||||
echo "bus: scripts/bus-service.sh install --copy $TO --copies $COPIES$([ "$RUN_PM" = 0 ] || echo ' --pm') --claude $P_CLAUDE"
|
||||
[ -z "$DROP_TESTER" ] || echo "drop $DROP_TESTER; the target Console does not support it"
|
||||
echo "$PROOF_PLAN"
|
||||
echo "Console: scripts/webui-service.sh install --copy $TO --copies $COPIES${RUN_CONSOLE[*]:+ ${RUN_CONSOLE[*]}}"
|
||||
echo "CLI: scripts/stack-copy.sh wrapper $TO --copies $COPIES --bin $BIN"
|
||||
local r
|
||||
@@ -842,6 +949,7 @@ run_steps() {
|
||||
log_line result started
|
||||
capture || refuse capture-failed "could not write the rollback set $RS; nothing was stopped"
|
||||
[ -z "$DROP_TESTER" ] || say "drop $DROP_TESTER; the target Console does not support it"
|
||||
[ -z "$PROOF_STEP" ] || say "$PROOF_STEP"
|
||||
trap 'after_fail signal' INT TERM HUP
|
||||
stop_both || rollback_in_run stop-timeout
|
||||
if [ -e "$STORE" ]; then
|
||||
@@ -1070,7 +1178,7 @@ STORE="$DATA/bus/bus.sqlite"
|
||||
BUS_UNIT="mosaic-bus@$BUSINESS.service"
|
||||
FROM="" TO="" ACT="" RS="" POST="" BACKUP="" TAKEN="" RESTORED="" STEPS="" COUNT="" UNCLEAN="" FAIL=""
|
||||
STORE_SCHEMA="" START_EPOCH="" START_MS=0 GATE="" GATE_WHY="" S_CHANGED=""
|
||||
P_COPY="" P_PM=0 P_PENDING=0 P_SCHEMA="" P_CLAUDE="" P_CONSOLE=() RUN_PM=0 RUN_PENDING=0 RUN_CONSOLE=() DROP_TESTER="" PLAN_REFUSE=()
|
||||
P_COPY="" P_PM=0 P_PENDING=0 P_SCHEMA="" P_CLAUDE="" P_CONSOLE=() RUN_PM=0 RUN_PENDING=0 RUN_CONSOLE=() DROP_TESTER="" PROOF_PLAN="" PROOF_STEP="" PLAN_REFUSE=()
|
||||
case "$OP" in
|
||||
adopt) do_adopt ;;
|
||||
activate) do_activate ;;
|
||||
|
||||
Reference in new issue
Block a user