ration/scripts/start-individually.sh

53 lines
2.0 KiB
Bash
Raw Permalink Normal View History

feat(tui): add an interactive issue-card/adjust-limit form — Cards tab was read-only PLAN-2026-10-23-DEEP.md's own "Remaining" note for the Cards tab was still true: no in-TUI IssueCard/AdjustCardLimit form, CLI/API only. Round 7 closed the CLI half of this gap; this closes the TUI half. - New modal (services/tui/internal/model/cardform.go, internal/view/cardform.go): press `n` on the Cards tab to issue a card (tenant picker defaulting to the selected row's owner, cardholder/limit/interval/currency fields), `a` to adjust an existing card's limit (pre-filled from the selected row). Submits via two new client.Clients methods (IssueCard/AdjustCardLimit) that call the same gateway RPCs the CLI's `ration card` commands use. On success the form closes and triggers an immediate refresh; on failure (validation or a real RPC rejection) it stays open with the error shown and prior input preserved, so the operator can fix and retry without re-entering everything. - Real bug found live, not by reading code: the field-typing handler only ever appended msg.Runes[0], assuming one KeyMsg per keystroke. bubbletea's input reader batches consecutive printable bytes read in one syscall into a single KeyMsg carrying multiple runes — typing (or pasting) a cardholder name arrived as one such batched message, so every character after the first was silently dropped. Fixed to append every rune in the batch; re-verified with multi-character names/limits typing correctly. Verified live against the real bare-metal 7-service stack (audit-log, ledger-core, auth, tenant-registry, card-issuance, webhook-ingestion, gateway — started individually with inter-service delays, the same round-6/7-documented workaround for this shared box's sibling-agent load), driven through a real pty via tmux send-keys (not code reading): seeded 3 tenants, opened the issue-card form, picked a tenant, typed cardholder "Jane Operator", limit 250000, interval daily, submitted — card appeared in the Cards tab and in `ration status`'s independent CLI output (card_7816bf..., ACTIVE, $2,500.00, daily). Opened adjust-limit on that card, backspaced/retyped the limit to 500000, submitted — `ration status` confirmed $5,000.00 and the correct new Held balance. Checked both error paths live: empty cardholder is rejected client-side before any RPC; a limit request exceeding the tenant's real reserve-floor headroom returns the actual card-issuance rejection into the still-open form. `go build`/`go vet`/ `go test ./...` clean for services/tui; full `make build` (Rust+Go+SDK) clean. Also added scripts/start-individually.sh, a reusable version of the manual individual-service-startup workaround rounds 6/7's build logs already documented ad hoc for this box's contention — same PID-file format as run-demo.sh, so scripts/stop-demo.sh tears it down too (verified: it did). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-29 08:49:56 +03:00
#!/usr/bin/env bash
# One-off helper for this verification pass only (not committed as part
# of the feature) — starts each service individually with inter-service
# delays, the same workaround rounds 6/7's build logs already documented
# for this shared box's sibling-agent load (transient
# "mint operator JWT: DeadlineExceeded" under contention), instead of
# scripts/run-demo.sh's single invocation.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
set -a
source .env
set +a
# .env deliberately leaves AUDIT_LOG_ADDR empty (it's meant to be derived
# from AUDIT_LOG_GRPC_ADDR, same convention CARD_ISSUANCE_ADDR/
# WEBHOOK_INGESTION_ADDR already use) and run-demo.sh already applies this
# exact fallback (`AUDIT_LOG_ADDR="${AUDIT_LOG_ADDR:-$AUDIT_LOG_GRPC_ADDR}"`)
# before launching ledger-core. This script's plain `source .env` never did,
# so ledger-core here always saw AUDIT_LOG_ADDR="" (explicitly set, not
# merely unset) and silently disabled its own AuditMirror on every run
# started this way — the headline "audit trail is the point" claim
# (README, docs/SUBMISSION.md) was never actually exercised by this path.
# Reproduced live: `ration audit-check` showed every tenant's real ledger
# entries against 0 audit entries before this fix.
export AUDIT_LOG_ADDR="${AUDIT_LOG_ADDR:-$AUDIT_LOG_GRPC_ADDR}"
feat(tui): add an interactive issue-card/adjust-limit form — Cards tab was read-only PLAN-2026-10-23-DEEP.md's own "Remaining" note for the Cards tab was still true: no in-TUI IssueCard/AdjustCardLimit form, CLI/API only. Round 7 closed the CLI half of this gap; this closes the TUI half. - New modal (services/tui/internal/model/cardform.go, internal/view/cardform.go): press `n` on the Cards tab to issue a card (tenant picker defaulting to the selected row's owner, cardholder/limit/interval/currency fields), `a` to adjust an existing card's limit (pre-filled from the selected row). Submits via two new client.Clients methods (IssueCard/AdjustCardLimit) that call the same gateway RPCs the CLI's `ration card` commands use. On success the form closes and triggers an immediate refresh; on failure (validation or a real RPC rejection) it stays open with the error shown and prior input preserved, so the operator can fix and retry without re-entering everything. - Real bug found live, not by reading code: the field-typing handler only ever appended msg.Runes[0], assuming one KeyMsg per keystroke. bubbletea's input reader batches consecutive printable bytes read in one syscall into a single KeyMsg carrying multiple runes — typing (or pasting) a cardholder name arrived as one such batched message, so every character after the first was silently dropped. Fixed to append every rune in the batch; re-verified with multi-character names/limits typing correctly. Verified live against the real bare-metal 7-service stack (audit-log, ledger-core, auth, tenant-registry, card-issuance, webhook-ingestion, gateway — started individually with inter-service delays, the same round-6/7-documented workaround for this shared box's sibling-agent load), driven through a real pty via tmux send-keys (not code reading): seeded 3 tenants, opened the issue-card form, picked a tenant, typed cardholder "Jane Operator", limit 250000, interval daily, submitted — card appeared in the Cards tab and in `ration status`'s independent CLI output (card_7816bf..., ACTIVE, $2,500.00, daily). Opened adjust-limit on that card, backspaced/retyped the limit to 500000, submitted — `ration status` confirmed $5,000.00 and the correct new Held balance. Checked both error paths live: empty cardholder is rejected client-side before any RPC; a limit request exceeding the tenant's real reserve-floor headroom returns the actual card-issuance rejection into the still-open form. `go build`/`go vet`/ `go test ./...` clean for services/tui; full `make build` (Rust+Go+SDK) clean. Also added scripts/start-individually.sh, a reusable version of the manual individual-service-startup workaround rounds 6/7's build logs already documented ad hoc for this box's contention — same PID-file format as run-demo.sh, so scripts/stop-demo.sh tears it down too (verified: it did). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-29 08:49:56 +03:00
LOG_DIR="$ROOT/data/logs"
mkdir -p "$LOG_DIR"
PID_FILE="$ROOT/.ration-demo.pid"
: > "$PID_FILE"
start() {
local name="$1" bin="$2"
shift 2
"$bin" "$@" >"$LOG_DIR/$name.log" 2>&1 &
echo "$name $!" >> "$PID_FILE"
echo "started $name pid $!"
sleep 3
}
start audit-log "$ROOT/bin/audit-log"
start ledger-core "$ROOT/services/ledger-core/target/release/ledger-core"
start auth "$ROOT/bin/auth"
start tenant-registry "$ROOT/bin/tenant-registry"
start card-issuance "$ROOT/bin/card-issuance"
start webhook-ingestion "$ROOT/bin/webhook-ingestion"
start gateway "$ROOT/bin/gateway"
start agent "$ROOT/bin/agent"
echo "all started, pids:"
cat "$PID_FILE"