Files
loki/scripts/smoke.sh
CatoandClaude Opus 5 a02d31d996 Every public claim matches the code, and two gates can now fail (#802)
* fix(truth): every public claim now matches what the code and the licence say

The /license page forbade what LICENSE grants. #791 relicensed the repo to MIT
and fixed LICENSE, the README and the Terms — but missed the page, which still
said "source-available", listed hosting and repackaging under "you may not",
and promised a replacement licence that had already shipped. On a public repo,
that revoked rights we had granted.

Same shape, five more places:

- Three live /thoughts pages and four front-matters carried "Mao Nakamoto",
  the retired identity, into the rendered byline and the OG social card.
- legal/ named that identity as operator, data controller and IP assignor, and
  assigned the work to bitbaum AG / orangecat GmbH / loki GmbH — none of which
  were ever incorporated. Rewritten as a record of authorship and the MIT
  grant, which is what is actually true.
- The desktop About dialog and the installer copyright metadata shipped
  "© 2026 Mao Nakamoto" in every build. No audit pass had looked there.
- /pricing and the feedback-widget docs said the report loop "closes itself"
  months after close-loop.ts deliberately removed auto-resolve for being
  untrue; resolve is an operator act and has zero call sites.
- /roadmap claimed signed installers under "Shipping now"; no signing secret
  exists and /download says the opposite two pages away.
- /releases claimed "every shipped version" while missing nine, and listed a
  0.8.25 that was never tagged — its "Binaries →" link 404'd. Removed per the
  file's own rule: one entry per tag pushed to loki-releases.
- desktop/README pointed all five install commands at bitbaum/loki, which
  404s; releases publish to loki-releases. Version pin replaced with a glob so
  it cannot rot again.
- DEFAULT_USER_NAME greeted nameless OAuth users as "Mao".

And the two that lied to agents rather than users: CLAUDE.md claimed pre-push
runs the full verify bundle so "green locally means green in CI", and
AGENTS.md claimed pre-commit runs tsc. The hook's own header documents why it
stopped doing both — a docs-only push runs nothing. An agent trusting either
line would skip the verification it needed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(gates): close the two gaps that let deleted things keep passing

Two gates could not fail, and one migration ledger had silently drifted.

MIGRATION JOURNAL — 13 files missing, next db:generate breaks the deploy.
drizzle/ held 78 .sql files; meta/_journal.json had 65 entries. Production
was fine and always had been: apply-schema.sh globs the directory and keeps
its own _deploy_schema_history, so it never reads the journal. But
drizzle-kit does, and its newest snapshot was 0072 — so the next generate
would re-emit 0073-0077, including CREATE TABLE "calendar_busy" with no
IF NOT EXISTS. apply-schema.sh rewrites ADD COLUMN only, and the batch is one
transaction, so the deploy would abort on a change unrelated to it.

Reconciled to 78 via bootstrap-migration-ledger.ts --write-journal, and added
scripts/test/migration-journal-coverage.ts so it cannot drift again: files vs
journal in both directions, plus idx contiguity. Proven by mutation — drop one
entry and it exits 1; restore it and it exits 0.

SMOKE — every authenticated probe passed whether or not the route existed.
The auth middleware answers 401 before routing, and check_route accepted 401
for everything in AUTH_API_ROUTES. Measured: /api/definitely-not-a-real-route
returns 401 exactly like /api/orgs. So the list proved nothing, and
/api/checkout/personal sat in it for 15 days after the Stripe rail was
removed. A 401 now only passes if a route file actually resolves on disk
(dynamic and catch-all segments included); the dead entry is gone, and all
remaining probes resolve.

Also: bumping desktop/package.json to 0.8.29, because the retired-identity fix
in the previous commit touched desktop/src/main/index.ts and desktop-release-
drift.ts correctly refused to let a shipped file change without a release to
carry it. That gate was right and is the model for the two above.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 08:40:34 -07:00

239 lines
7.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Smoke test: hit every page route and fail if any returns non-2xx/3xx
# OR if the body contains the error-boundary marker (a 200 response that
# renders src/app/error.tsx still indicates a broken server component).
# Usage: npm run smoke (defaults to http://localhost:3000)
# BASE=https://cockpit.example.com npm run smoke
#
# Routes are derived manually here rather than by parsing navigation.ts,
# because this script must run without a TS toolchain. Keep in sync with
# config/navigation.ts NAV_ITEMS plus the / redirect.
set -u
BASE="${BASE:-http://localhost:3000}"
# String that src/app/error.tsx renders when a Server Component throws.
# Page responses still carry HTTP 200 in that case, so status-only
# checking misses the regression — body grep is the correction.
ERROR_BOUNDARY_MARKER="Something went wrong"
# Page routes — match config/navigation.ts NAV_ITEMS plus the / redirect
# and public-surface pages (/whitepaper).
PAGE_ROUTES=(
"/"
"/pricing"
"/whitepaper"
"/today"
"/approvals"
"/control"
"/projects"
"/goals"
"/people"
"/crew"
"/habits"
"/events"
"/money"
"/activity"
"/digests"
"/history"
"/decisions"
"/prompts"
"/system"
"/memory"
"/thoughts"
"/settings"
)
# DB-backed API GETs. Exercises drizzle, the postgres connection, and the
# query layer — catches silent regressions a page-only smoke would miss.
# Tool-dependent endpoints (/api/calendar, /api/weather, /api/github) are
# omitted from unauthenticated smoke — calendar needs local `gog` on a runtime host;
# weather uses open-meteo on cloud or weather.sh locally.
#
# AUTH_ROUTES require a valid session. Without one they return 401 (correct).
# We accept 200 OR 401 — either proves the route isn't crashing (500).
# Set LOKI_SESSION_TOKEN=<token> to run them fully authenticated.
# COCKPIT_SESSION_TOKEN is still accepted (legacy).
PUBLIC_API_ROUTES=(
"/api/health"
"/api/system"
"/api/setup"
)
AUTH_API_ROUTES=(
"/api/me"
"/api/onboarding"
"/api/crons"
"/api/goals"
"/api/habits"
"/api/people"
"/api/crew"
"/api/crew/tasks"
"/api/events"
"/api/control"
"/api/control/agent"
"/api/control/commands"
"/api/user-projects"
"/api/invitations"
"/api/sessions"
"/api/prompts/agent"
"/api/captures"
"/api/beacon-settings"
"/api/orgs"
"/api/agent-tokens"
"/api/agent/register"
)
# Optional session cookie for authenticated smoke runs.
# HTTPS deployments use the __Secure- prefixed Auth.js cookie name.
CURL_AUTH_ARGS=()
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/_brand.sh"
SMOKE_SESSION_TOKEN="$(_brand_env SESSION_TOKEN)"
if [ -n "${SMOKE_SESSION_TOKEN}" ]; then
if [[ "${BASE}" == https://* ]]; then
CURL_AUTH_ARGS=(-H "Cookie: __Secure-authjs.session-token=${SMOKE_SESSION_TOKEN}")
else
CURL_AUTH_ARGS=(-H "Cookie: authjs.session-token=${SMOKE_SESSION_TOKEN}")
fi
fi
# 1) Probe the base URL once so we fail fast with a clear message
# instead of dribbling out one curl error per route.
# 20s timeout: dev mode compiles on first request which can be slow.
if ! curl -s -o /dev/null --max-time 20 "$BASE/"; then
echo "✗ no server reachable at $BASE — start the dev server first (pnpm run dev)" >&2
exit 2
fi
failed=0
# Resolve a URL path to its route file, honouring [dynamic] and [...catch-all]
# segments. Returns 0 if a route exists on disk.
#
# WHY THIS EXISTS: the auth middleware answers 401 BEFORE routing, so an
# authenticated probe cannot tell a real route from one that was deleted —
# /api/definitely-not-real returns 401 exactly like /api/orgs. Every entry in
# AUTH_API_ROUTES therefore passed unconditionally, and /api/checkout/personal
# sat in the list for 15 days after the Stripe rail was removed without the
# gate noticing. A probe that cannot fail is not a gate.
route_file_exists() {
local path="${1#/}"
local dir="src/app"
local IFS='/'
for seg in $path; do
[ -z "$seg" ] && continue
if [ -d "$dir/$seg" ]; then
dir="$dir/$seg"
else
local match=""
for cand in "$dir"/\[*\]; do
[ -d "$cand" ] && { match="$cand"; break; }
done
[ -n "$match" ] || return 1
dir="$match"
case "$match" in *"[..."*) return 0 ;; esac
fi
done
[ -f "$dir/route.ts" ] || [ -f "$dir/route.tsx" ] \
|| [ -f "$dir/page.tsx" ] || [ -f "$dir/page.ts" ]
}
# check_route ROUTE [check_body=0] [label] [allow_401=0] [extra_ok_code=""]
check_route() {
local route="$1"
local check_body="${2:-0}"
local label="${3:-$route}"
local allow_401="${4:-0}"
local extra_ok_code="${5:-}"
local body_file
body_file=$(mktemp)
local code
code=$(curl -s -o "$body_file" --max-time 30 "${CURL_AUTH_ARGS[@]}" \
-w "%{http_code}" "$BASE$route" || echo "000")
local ok=0
if [ "$code" -ge 200 ] && [ "$code" -lt 400 ]; then
ok=1
elif [ "$allow_401" = "1" ] && [ "$code" = "401" ]; then
# A 401 only proves the middleware ran. Demand that the route actually
# exists, or a deleted route passes forever.
if route_file_exists "$route"; then
ok=1
else
printf " FAIL %3s %s (401, but no route file — route was deleted)\n" "$code" "$label"
rm -f "$body_file"
failed=$((failed + 1))
return
fi
elif [ -n "$extra_ok_code" ] && [ "$code" = "$extra_ok_code" ]; then
ok=1
fi
if [ "$ok" = "0" ]; then
printf " FAIL %3s %s\n" "$code" "$label"
rm -f "$body_file"
failed=$((failed + 1))
return
fi
if [ "$check_body" = "1" ] && grep -q "$ERROR_BOUNDARY_MARKER" "$body_file"; then
printf " FAIL %3s %s (error boundary rendered)\n" "$code" "$label"
rm -f "$body_file"
failed=$((failed + 1))
return
fi
printf " ok %3s %s\n" "$code" "$label"
rm -f "$body_file"
}
for route in "${PAGE_ROUTES[@]}"; do
check_route "$route" 1
done
for route in "${PUBLIC_API_ROUTES[@]}"; do
check_route "$route" 0
done
for route in "${AUTH_API_ROUTES[@]}"; do
check_route "$route" 0 "$route" 1
done
# Invitation token routes are excluded from the auth middleware so unauthenticated
# users can accept invites. A bogus token must return 404 — if it returns 401 the
# middleware exclusion regressed and new users can no longer accept invitations.
check_route "/api/invitations/smoke-test-bogus-token" 0 "/api/invitations/<token> (must not 401)" 0 "404"
# Dynamic [id] routes — discover an id from a list endpoint, then hit
# the detail route. Catches regressions in the parameter handlers and
# the per-row drizzle queries that the static-list smoke can't.
# Optional: skipped silently if jq isn't installed or the list is empty.
dynamic_total=0
if command -v jq >/dev/null 2>&1; then
person_id=$(curl -s --max-time 5 "${CURL_AUTH_ARGS[@]}" "$BASE/api/people" 2>/dev/null \
| jq -r '.people[0].id // empty' 2>/dev/null)
if [ -n "$person_id" ]; then
dynamic_total=$((dynamic_total + 1))
check_route "/api/people/$person_id" 0 "/api/people/<id>" 1
fi
# /api/projects/[id] — GET is the hottest project route (every drawer open) but
# static-list smoke can't cover it. Derive an entity project ID from user-projects.
project_id=$(curl -s --max-time 5 "${CURL_AUTH_ARGS[@]}" "$BASE/api/user-projects" 2>/dev/null \
| jq -r '.[0].entityProjectId // empty' 2>/dev/null)
if [ -n "$project_id" ]; then
dynamic_total=$((dynamic_total + 1))
check_route "/api/projects/$project_id" 0 "/api/projects/<id>" 1
fi
fi
total=$((${#PAGE_ROUTES[@]} + ${#PUBLIC_API_ROUTES[@]} + ${#AUTH_API_ROUTES[@]} + 2 + dynamic_total))
echo ""
if [ "$failed" -gt 0 ]; then
echo "✗ $failed/$total route(s) failed"
exit 1
fi
echo "✓ all $total routes ok"