crosscode: the Church App (app.sh, add, demo) and the App's changelog

scripts/products/app.sh and app.env.template.json; app in
SUPPORTED_PRODUCTS; crosscode add <church> app (Accounts first);
crosscode demo <church> app --profile <s>, and the App's turn, last,
in a whole demo scenario. app.bats and demo.bats; app.sh linted.
The full bats suite wasn't run (stopped for low memory); app.bats and
demo.bats pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 16:11:41 +02:00
co-authored by Claude Opus 5.5
parent acd3b259a1
commit 71f2f02ee5
11 changed files with 407 additions and 25 deletions
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env bats
# The Church App's hooks that don't need a server (APP-1.0-PLAN §12), and where `crosscode add`
# puts it on the church's address. Run with `npm run test:scripts`.
setup() {
# shellcheck source=../lib/common.sh
source "$BATS_TEST_DIRNAME/../lib/common.sh"
# shellcheck source=../lib/install.sh
source "$BATS_TEST_DIRNAME/../lib/install.sh"
# shellcheck source=../products/app.sh
source "$BATS_TEST_DIRNAME/../products/app.sh"
TMP="$BATS_TEST_TMPDIR"
CALLS="$TMP/calls"
: > "$CALLS"
# Record what would run, as the app user, instead of running it.
run_as() { local user="$1" dir="$2"; shift 2; echo "$user|${dir#"$TMP"/}|$*" >> "$CALLS"; }
CENV=()
}
checkout() {
local dir="$TMP/$1" p
for p in contracts ui auth-client seo demo; do
mkdir -p "$dir/packages/$p"
echo "{\"name\":\"@crosscode/$p\"}" > "$dir/packages/$p/package.json"
done
mkdir -p "$dir/apps/app/backend" "$dir/apps/app/frontend"
echo '{"version":"1.0.0"}' > "$dir/apps/app/backend/package.json"
cp "$BATS_TEST_DIRNAME/../../apps/app/ecosystem.config.example.cjs" "$dir/apps/app/"
}
@test "the App goes on app.<address>" {
[ "$(default_domain app hopefamily.co.za)" = app.hopefamily.co.za ]
[ "$(default_domain app hope.crosscode.co.za)" = app.hope.crosscode.co.za ]
}
@test "the App is a product this script deploys, last" {
is_supported_product app
[ "${PRODUCT_ORDER[*]}" = "accounts events website app" ]
}
@test "contracts, ui, auth-client, seo and demo are installed; all but ui built before the App" {
checkout new
app_install_deps "$TMP/new" hope
grep -qx 'hope|new|npm ci --include=dev --no-audit --no-fund --include-workspace-root -w packages/contracts -w packages/ui -w packages/auth-client -w packages/seo -w packages/demo -w apps/app/backend -w apps/app/frontend' "$CALLS"
: > "$CALLS"
app_build "$TMP/new" hope
[ "$(cut -d'|' -f2 "$CALLS" | tr '\n' ' ')" = "new/packages/contracts new/packages/auth-client new/packages/seo new/packages/demo new/apps/app/backend new/apps/app/frontend " ]
}
@test "ports default to 5400 / 3400, else church.env's" {
[ "$(app_api_port)" = 5400 ]
[ "$(app_web_port)" = 3400 ]
church_env_set APP_PORTS "5510 3510"
[ "$(app_health_url)" = http://127.0.0.1:5510/api/health ]
[ "$(app_web_port)" = 3510 ]
}
@test "the PM2 config is made once, with the church's names and port" {
checkout new
church_env_set APP_PM2 "hope-app-backend hope-app-frontend"
church_env_set APP_PORTS "5510 3510"
info() { :; }
app_ensure_pm2_config "$TMP/new" "$(id -un)"
conf="$TMP/new/apps/app/ecosystem.config.cjs"
grep -q "'hope-app-backend'" "$conf"
grep -q "'hope-app-frontend'" "$conf"
grep -q -- "-p 3510" "$conf"
echo changed > "$conf"
app_ensure_pm2_config "$TMP/new" "$(id -un)"
[ "$(cat "$conf")" = changed ]
}
@test "the export is the App's own script, into the folder given" {
checkout new
app_export "$TMP/new" hope "$TMP/out"
grep -qx "hope|new/apps/app/backend|npx tsx scripts/export-church.ts --out-dir $TMP/out" "$CALLS"
}
@test "the uploads are copied into the export; none is fine" {
command -v rsync >/dev/null || skip "rsync isn't installed here"
checkout new
app_copy_uploads "$TMP/new" "$TMP/out1"
[ -d "$TMP/out1" ]
mkdir -p "$TMP/new/apps/app/backend/uploads/2026/12"
echo jpg > "$TMP/new/apps/app/backend/uploads/2026/12/campaign.jpg"
app_copy_uploads "$TMP/new" "$TMP/out2"
[ "$(cat "$TMP/out2/2026/12/campaign.jpg")" = jpg ]
}
@test "the env template in the script is the App's own (the Hub reads apps/app's at the tag)" {
diff <(node -e 'console.log(JSON.stringify(require(process.argv[1])))' "$BATS_TEST_DIRNAME/../products/app.env.template.json") \
<(node -e 'console.log(JSON.stringify(require(process.argv[1])))' "$BATS_TEST_DIRNAME/../../apps/app/env.template.json")
}
+55 -5
View File
@@ -21,6 +21,15 @@ setup() {
echo "scenarioTeam" > "$TMP/sites/hope/website/apps/website/backend/src/demo/seeds.ts"
mkdir -p "$TMP/sites/hope/accounts/apps/accounts/backend/scripts"
touch "$TMP/sites/hope/accounts/apps/accounts/backend/scripts/demo.ts"
mkdir -p "$TMP/sites/hope/app/apps/app/backend/scripts"
touch "$TMP/sites/hope/app/apps/app/backend/scripts/demo.ts"
cat > "$CROSSCODE_HOME/products/app.sh" <<EOF4
app_app() { printf '%s/apps/app' "\$1"; }
app_backup() { echo "backup \$2" >> "$CALLS"; [ -z "\${FAIL_BACKUP:-}" ]; }
app_reload() { echo "reload \$2" >> "$CALLS"; }
app_health_url() { echo http://127.0.0.1:5400/api/health; }
app_expected_version() { echo \${APP_VERSION:-1.0.0}; }
EOF4
cat > "$CROSSCODE_HOME/products/accounts.sh" <<EOF3
accounts_app() { printf '%s/apps/accounts' "\$1"; }
accounts_backup() { echo "backup \$2" >> "$CALLS"; [ -z "\${FAIL_BACKUP:-}" ]; }
@@ -172,13 +181,36 @@ wait 1.9.0" ]
[[ "$(cat "$CALLS")" == *"demo -- --profile bold-youth --force"* ]]
}
@test "the App's demo (agent 1.7.0 sends it) is refused clearly until App 1.0.0" {
run cmd_demo hope app --profile community-family --scenario community-family
@test "app: backup, then the scenario as the App's user, then a reload" {
HAS="accounts app" run cmd_demo hope app --profile community-family --scenario community-family
[ "$status" -eq 0 ]
[ "$(cat "$CALLS")" = "backup cc-hope-app
run cc-hope-app sites/hope/app/apps/app/backend npm run --silent demo -- --profile community-family --scenario community-family --force
reload cc-hope-app
wait 1.0.0" ]
}
@test "app: only a scenario, no admin email, an App installed, and a release that has the demo" {
HAS="accounts app" run cmd_demo hope app --profile small
[ "$status" -eq 1 ]
[[ "$output" == *"comes with App 1.0.0"* ]]
HAS="accounts app" run cmd_demo hope app --profile bold-plant --admin-email jane@hope.test
[ "$status" -eq 1 ]
HAS="accounts" run cmd_demo hope app --profile bold-plant
[ "$status" -eq 1 ]
[[ "$output" == *"has no Church App"* ]]
rm "$TMP/sites/hope/app/apps/app/backend/scripts/demo.ts"
HAS="accounts app" run cmd_demo hope app --profile bold-plant
[ "$status" -eq 1 ]
[[ "$output" == *"has no demo (1.0.0 or later has)"* ]]
[ ! -s "$CALLS" ]
}
@test "app: a failed backup stops it before the data is touched" {
HAS="accounts app" FAIL_BACKUP=1 run cmd_demo hope app --profile bold-plant
[ "$status" -eq 1 ]
[[ "$(cat "$CALLS")" != *"run "* ]]
}
@test "a failed Accounts demo isn't followed by a reload" {
FAIL_SEED=1 run cmd_demo hope accounts --profile clean-modern
[ "$status" -eq 1 ]
@@ -224,10 +256,28 @@ cc-hope-website" ]
[[ "$(cat "$CALLS")" != *"cc-hope-website"* ]]
}
@test "seed-scenario: an App installed is refused (its demo comes with App 1.0.0), nothing changed" {
@test "seed-scenario: the App loads last, after Accounts, Events and the Website" {
HAS="accounts events website app" EVENTS_VERSION=3.8.0 WEBSITE_VERSION=1.8.0 run cmd_demo hope --scenario clean-campus
[ "$status" -eq 0 ]
[ "$(grep '^run' "$CALLS" | cut -d' ' -f2)" = "cc-hope-accounts
cc-hope-events
cc-hope-website
cc-hope-app" ]
[[ "$(cat "$CALLS")" == *"run cc-hope-app sites/hope/app/apps/app/backend npm run --silent demo -- --profile clean-campus --scenario clean-campus --force"* ]]
}
@test "seed-scenario: only Accounts and the App, the rest skipped" {
HAS="accounts app" run cmd_demo hope --scenario bold-plant
[ "$status" -eq 0 ]
[[ "$output" == *"Not installed, so skipped: events website"* ]]
[ "$(grep '^run' "$CALLS" | cut -d' ' -f2)" = "cc-hope-accounts
cc-hope-app" ]
}
@test "seed-scenario: an App before 1.0.0 stops it before anything changes" {
HAS="accounts app" APP_VERSION=0.9.0 run cmd_demo hope --scenario bold-plant
[ "$status" -eq 1 ]
[[ "$output" == *"comes with App 1.0.0"* ]]
[[ "$output" == *"The App is 0.9.0 here: a demo scenario needs 1.0.0 or later"* ]]
[ ! -s "$CALLS" ]
}