Skip to content

Local development

Runs Homefelt’s whole stack on one Mac with no Docker: Postgres 17, canasta-server with the dev sign-in, and a seeded family table you can join from the terminal. The server’s settings are in server.md “Configuration”; the dev sign-in is described in its “Local development”. New here? Getting started is the short path from a clone to a solo game in the browser and bin/test; this page is the detail.

First run

bin/setup # tools, Postgres, databases, .env.development.local, the signing key
bin/dev # Postgres up, then the server on 127.0.0.1:8080 (Ctrl-C stops it)
bin/dev seed # in a second terminal: players, the Familia group, the familia and solo tables
bin/dev play eduardo # sit at the table (its lobby); repeat as abuela, tio, prima elsewhere,
# then eduardo, the host, types start to deal
bin/dev play eduardo solo # or play alone: the other three seats are computer players (start)

A table of your own, as the apps will make one:

id=$(bin/dev new eduardo human,human,human,normal) # POST /tables: eduardo hosts, seat 0
bin/dev invite eduardo "$id" # token … and code … (typed; 30 minutes)
bin/dev redeem abuela <token> # the link: abuela takes the free seat 1
bin/dev redeem tio <code> # typed: tio shares Familia with eduardo, so
# he sits at once (seat 2); a stranger waits
# for eduardo to approve at the table
bin/dev play eduardo "$id" # and bin/dev play abuela "$id" elsewhere;
# eduardo, the host, types start to deal

What the scripts do

bin/setup can run any number of times; it only adds what is missing.

  1. Stops unless 8 GB are free (HOMEFELT_MIN_FREE_GB).
  2. Installs bun, xcodegen, openssl and rustup with Homebrew when they are missing, the stable toolchain and the wasm32-unknown-unknown target, and, once rust/canasta-wasm exists, wasm-bindgen-cli at the version in rust/Cargo.lock. Each brew install gives up after HOMEFELT_BREW_TIMEOUT seconds (600), and none starts while another brew command runs.
  3. Postgres 17: Homebrew’s postgresql@17, or else the Postgres.app cask. Homebrew’s runs as a brew service. Postgres.app’s binaries run with pg_ctl on its default data directory (~/Library/Application Support/Postgres/var-17, HOMEFELT_PGDATA), so the app shows the same server; it is not a login item, and bin/dev starts it when it is down.
  4. Creates the roles and databases homefelt_dev (the server’s) and homefelt_test (the tests’), each owned by its role. Local connections are trusted, so there are no passwords. A machine set up before the Homefelt rename has canasta_dev and canasta_test instead: with bin/dev stopped, rename the server’s in place, role and all, before the next bin/setup or bin/dev (psql -h 127.0.0.1 -d postgres -c 'ALTER DATABASE canasta_dev RENAME TO homefelt_dev;' -c 'ALTER ROLE canasta_dev RENAME TO homefelt_dev;'), and let bin/dev test make a fresh homefelt_test (dropdb canasta_test when you like).
  5. Copies the committed .env.example to .env.development.local (if it is missing) and generates a P-256 key in .dev/token-key.pem for the server’s access tokens. Both are git-ignored; edit the copy, not the example.

bin/dev reads .env.development.local and always sets HOMEFELT_DEV_AUTH=1 and HOST=127.0.0.1. It also raises HOMEFELT_AUTH_PER_MINUTE, HOMEFELT_API_PER_MINUTE and HOMEFELT_HELLOS_PER_MINUTE to 600 and HOMEFELT_REDEEM_FAILURES_PER_IP to 1000 (unless set), since every bin/dev command and e2e player signs in, opens its WebSocket and types its codes from the same address, and lists the web client’s dev and preview origins in HOMEFELT_WEB_ORIGINS (http://localhost:5173,http://localhost:4173, unless set).

Command Does
bin/dev (or bin/dev up) Starts Postgres if it is down, builds canasta-server with --features dev-auth and runs it in the foreground; it migrates homefelt_dev on start (HOMEFELT_DB_MIGRATE). Prints the URLs. Ctrl-C saves every table and stops it
bin/dev seed With the server running: signs in eduardo, abuela, tio and prima through POST /auth/dev, then canasta-dev-seed (a dev-auth-only binary on the server’s repository functions) names them, makes eduardo’s group Familia with the others joining by invite links (one each: a token opens once), and deals two tables hosted by eduardo in seat 0: familia, four human seats, and solo, with Easy, Normal and Easy computer players in seats 1 to 3. The fixed ids are written before the server loads them; then the script makes a familia invite as eduardo, redeems its typed code for the other three through POST /invites/redeem (only a table’s task seats people; they share Familia with eduardo, so no approval) and revokes it. Running it again changes nothing
bin/dev token <name> Prints a 15-minute access token for that dev player (made if new), for a hand-written WebSocket client
bin/dev new <name> [controllers] POST /tables as that player, who hosts it from seat 0; prints the new id. controllers is one per seat, comma-separated (human,easy,normal,easy)
bin/dev invite <name> <table> POST /tables/<table>/invites as that player (the host or a seated player); prints the link token (single use) and the typed code with its expiry
bin/dev redeem <name> <token|code> POST /invites/redeem as that player, with a token (more than 6 characters) or a code; prints the answer (the seat, the group, or a pending join request)
bin/dev play <name> [table] bin/lib/play.ts (bun): signs in, says hello on ws://127.0.0.1:8080/tables/<table>/ws (default familia), prints your seat’s view after each change and who sits where, and sends one move per line: draw, take, discard KS, lay AS AD AD / 7H 7D 7S, any <action> {json}, the host’s `start [easy
bin/dev reset Drops and recreates homefelt_dev. Restart bin/dev afterwards, then seed again
bin/dev test [cargo args] cargo test --workspace -q with DATABASE_URL set to homefelt_test, so the database tests run instead of skipping (bin/dev test -p canasta-server --features dev-auth for the dev sign-in tests)

A WebSocket by hand, with any client (websocat is not installed by setup). Only a player with a seat there gets in (notSeated otherwise), and an unknown id is refused (noSuchTable):

token=$(bin/dev token eduardo)
websocat ws://127.0.0.1:8080/tables/familia/ws # then send {"type":"hello","token":"<token>"}

The web client

With bin/dev running, the browser app plays online against it (web/README.md “Online play”):

cd web
VITE_SERVER_URL=http://localhost:8080 VITE_DEV_AUTH=1 npm run dev # http://localhost:5173/online
E2E_ONLINE=1 PLAYWRIGHT_CHANNEL=chrome npm run e2e # starts bin/dev itself if needed

Use localhost, not 127.0.0.1, in VITE_SERVER_URL: the page is on localhost, and the refresh cookie is SameSite=Strict, so the server must be the same site. The dev sign-in asks for a name; a new dev player is named after it (abuela becomes “Abuela”), and the name prompt that follows a sign-in starts from that name. Until Save name keeps it, the name is not chosen, so tables show their seat’s number (“Player 2”, “Jugador 2”) as for any new account; the seeded players’ names are chosen.

Sign in with Apple does not run locally: Apple accepts only https:// return URLs on a real domain, never localhost, so .env.development.local leaves these unset and the dev sign-in stands in. On a deployed server (docs/server.md “What Eduardo configures”, #48) the web needs, with placeholders for Eduardo’s real values:

Where Name Value
server HOMEFELT_APPLE_WEB_SERVICES_ID <services-id>, the web Services ID
server HOMEFELT_APPLE_WEB_REDIRECT_URI https://<site-domain>/, its registered return URL; its origin must be in HOMEFELT_WEB_ORIGINS
server HOMEFELT_APPLE_TEAM_ID, HOMEFELT_APPLE_KEY_ID, HOMEFELT_APPLE_PRIVATE_KEY_FILE <team-id>, <key-id>, the path of AuthKey_<key-id>.p8: the key that trades and revokes Apple tokens, for the app and the web alike
web build VITE_APPLE_SERVICES_ID, VITE_APPLE_REDIRECT_URI the same <services-id> and return URL

The server’s tests trade and revoke web codes against a local Apple stand-in (tests/web.rs, “Sign in with Apple on the web”); nothing calls Apple.

The apps

TODO (follow-up to #32): the apps have no server URL setting yet, so they cannot be pointed at this server. When they do, a debug build reads it from a build setting (iOS) or BuildConfig (Android), never a hard-coded release value:

  • iOS simulator: it shares the Mac’s network, so http://localhost:8080 and ws://localhost:8080/tables/<id>/ws reach the server as they are.
  • Android emulator: 10.0.2.2 is the Mac’s loopback, so use http://10.0.2.2:8080. The server listening on 127.0.0.1 is enough, and the dev sign-in accepts these requests because they reach the Mac from loopback. A debug build needs cleartext allowed for 10.0.2.2 (a network security config) since this is plain http.
  • A physical phone cannot reach 127.0.0.1; that needs HOST=0.0.0.0, which also stops the dev sign-in answering it (loopback only), so it is out of scope here.

App versions

Both apps carry a date version (docs/decisions/0013-date-versions-for-apps-semver-for-apis.md): the marketing version is YYYY.M.D of the release day, without leading zeros (2026.12.3), and the build number is YYYYMMDDNN, NN the build of that day from 01 (2026120301). They live in swift/App/project.yml (MARKETING_VERSION, CURRENT_PROJECT_VERSION, and the generated Xcode project) and kotlin/app/build.gradle.kts (versionName, versionCode). Change them only with bin/set-version:

  • bin/set-version shows the version; bin/set-version --check fails unless both apps agree and the values are well formed (bin/test version and CI run it).
  • bin/set-version 2026-12-03 (or today) sets both apps to that day, build 01; run it again on the same day for the next build (02), for another TestFlight or internal-testing upload. It refuses to go backwards.
  • A second store release on the same day takes the next day’s date: the stores need a higher marketing version for each release.

The APIs (the CLI and server protocol, the app-status feed schema) carry semantic versions instead.

App unit tests

NodeState and the apps’ wording have unit tests in each app, with the same names and cases: kotlin/app/src/test (cd kotlin && ./gradlew :app:testDebugUnitTest -q --console=plain, plain JVM) and swift/App/Tests (the CanastaTests target in project.yml, hosted in the app, so it needs a simulator and bin/test does not run it; CI does):

cd swift/App
xcodebuild test -scheme Canasta -destination 'platform=iOS Simulator,name=iPhone 17' \
-only-testing:CanastaTests 2>&1 | xcbeautify --quiet

UI tests

One test per app deals a solo game on the new-game screen (Family rules, 4 players, Normal computer players in seats 2 to 4) and plays your seat to the end through the app’s own buttons: draw from the stock, select the first card the app takes, discard it, say Yes when partner asks to go out, and deal each next hand. It passes on the game-over sheet once a side has 5,000 points. In this test both apps deal from seed 7 and move the computer seats without a pause, so the game is the same every run and on both phones (4 hands; Game score 125 and 5,370). They need a simulator or an emulator, so bin/test does not run them.

  • iPhone (swift/App/UITests, the CanastaUITests target in project.yml; about 8 minutes):
    cd swift/App
    xcodebuild test -scheme Canasta -destination 'platform=iOS Simulator,name=iPhone 17' \
    -only-testing:CanastaUITests 2>&1 | xcbeautify --quiet
    The test sets CANASTA_UI_TEST_SEED in the app’s launch environment; only a Debug build reads it.
  • iPhone online (swift/App/UITests/OnlineUITests.swift): signs in with the dev provider, makes a table against computers, draws, then restarts the app and reconnects. bin/ios-online-uitest builds canasta-server with dev-auth, starts it on a free port with a throwaway key (needs DATABASE_URL, e.g. postgres://localhost/homefelt_test), runs the test and stops the server. Without the server the test is skipped. The script signs the simulator build ad hoc (CODE_SIGN_IDENTITY=-): an unsigned build cannot use the Keychain, where the refresh token lives. A Debug build points at a local server through HOMEFELT_SERVER_URL (launch environment) or the online.serverURL default; Release never does.
  • Android online (kotlin/app/src/androidTest/kotlin/canasta/app/OnlineUiTest.kt): signs in with the dev provider, makes a table against computers, draws, recreates the activity (the table carries on), then starts a new online model as a new launch would (the Keystore token signs in again) and reconnects. bin/android-online-uitest builds canasta-server with dev-auth, starts it on a free port with a throwaway key (needs DATABASE_URL, e.g. postgres://localhost/homefelt_test) and a booted emulator, which reaches it through adb reverse on its own 127.0.0.1 (an app targeting API 37 needs the local-network permission for 10.0.2.2; loopback is exempt), then stops the server. Without the server the test is skipped. A debug build points at a local server with the launch extra homefeltServer (kept in the online.serverURL setting; adb reverse tcp:8080 tcp:8080, then adb shell am start -n dev.edsancha.homefelt.canasta/canasta.app.MainActivity --es homefeltServer http://127.0.0.1:8080); only debug builds allow cleartext to 127.0.0.1, localhost and 10.0.2.2 (src/debug/res/xml), and release builds never read the setting or offer the dev provider.
  • Android (kotlin/app/src/androidTest; about 2 minutes with the build): start an emulator first, headless if you like ($ANDROID_HOME/emulator/emulator -avd Medium_Phone_API_37.0 -no-window -no-audio), then
    cd kotlin
    ./gradlew :app:connectedDebugAndroidTest -q --console=plain \
    -Pandroid.testInstrumentationRunnerArguments.class=canasta.app.FullGameUiTest
    The test sets UiTestLaunch.seed before the activity starts. Each run logs its result: adb logcat -d -s FullGameUiTest:I. Without the class argument it also runs LocalizationTest (the words in English and Spanish) and LanguageUiTest (the Language setting switches the app to Spanish and back).

Troubleshooting

  • The emulator says there is not enough disk space: it checks the disk that holds the AVD (~/.android/avd). Copy the AVD folder and its .ini to a roomier disk, point the .ini’s path= at the copy, and start it with ANDROID_AVD_HOME=<that folder>.
  • Postgres is not running (bin/dev says it did not answer): pg_isready -h 127.0.0.1. Homebrew: brew services list, then brew services restart postgresql@17. Postgres.app: read ~/Library/Application Support/Postgres/var-17/postgresql.log; a stale postmaster.pid there after a crash is the usual cause (remove it only when no postgres process runs). Another Postgres already on 5432 is used as it is: bin/setup creates the databases in it.
  • Port in use: lsof -nP -iTCP:8080 -sTCP:LISTEN shows who holds it. Stop it, or set PORT in .env.development.local. bin/dev refuses to start when something already answers /health there. Postgres on another port: PGPORT=5433 bin/dev, and change the port in the two URLs in .env.development.local.
  • brew hangs at “Fetching downloads” or “Verifying checksum”: on the Mac this was written on, Homebrew 7’s sandboxed bottle extraction (sandbox_operation.rb extract workers) waits forever, for formulae and casks alike, and the workers outlive the install that started them. Check pgrep -fl sandbox_operation; quit those (kill <pid>) before trying again. When it keeps hanging, install Postgres.app by hand: open the DMG from https://postgresapp.com (or the one brew already downloaded, in ~/Library/Caches/Homebrew/downloads), drag Postgres.app to /Applications, and run bin/setup again; it uses the app’s binaries without opening the app.
  • Missing iOS runtime: xcrun simctl list runtimes is empty or lacks the iOS version the app targets. Xcode → Settings → Components, or xcodebuild -downloadPlatform iOS (several GB: check free disk first).
  • DATABASE_URL is not set or the key file is missing: bin/setup writes both; a moved checkout needs it again. The key path is relative to the repository root, where bin/dev runs the server.
  • Tests skip the database: run them with bin/dev test, not plain cargo test.