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 keybin/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 tablesbin/dev play eduardo # sit at the table (its lobby); repeat as abuela, tio, prima elsewhere, # then eduardo, the host, types start to dealbin/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 0bin/dev invite eduardo "$id" # token … and code … (typed; 30 minutes)bin/dev redeem abuela <token> # the link: abuela takes the free seat 1bin/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 tablebin/dev play eduardo "$id" # and bin/dev play abuela "$id" elsewhere; # eduardo, the host, types start to dealWhat the scripts do
bin/setup can run any number of times; it only adds what is missing.
- Stops unless 8 GB are free (
HOMEFELT_MIN_FREE_GB). - Installs bun, xcodegen, openssl and rustup with Homebrew when they are missing, the stable
toolchain and the
wasm32-unknown-unknowntarget, and, oncerust/canasta-wasmexists,wasm-bindgen-cliat the version inrust/Cargo.lock. Eachbrew installgives up afterHOMEFELT_BREW_TIMEOUTseconds (600), and none starts while another brew command runs. - Postgres 17: Homebrew’s
postgresql@17, or else the Postgres.app cask. Homebrew’s runs as a brew service. Postgres.app’s binaries run withpg_ctlon 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, andbin/devstarts it when it is down. - Creates the roles and databases
homefelt_dev(the server’s) andhomefelt_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 hascanasta_devandcanasta_testinstead: withbin/devstopped, rename the server’s in place, role and all, before the nextbin/setuporbin/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 letbin/dev testmake a freshhomefelt_test(dropdb canasta_testwhen you like). - Copies the committed
.env.exampleto.env.development.local(if it is missing) and generates a P-256 key in.dev/token-key.pemfor 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 webVITE_SERVER_URL=http://localhost:8080 VITE_DEV_AUTH=1 npm run dev # http://localhost:5173/onlineE2E_ONLINE=1 PLAYWRIGHT_CHANNEL=chrome npm run e2e # starts bin/dev itself if neededUse 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:8080andws://localhost:8080/tables/<id>/wsreach the server as they are. - Android emulator:
10.0.2.2is the Mac’s loopback, so usehttp://10.0.2.2:8080. The server listening on127.0.0.1is enough, and the dev sign-in accepts these requests because they reach the Mac from loopback. A debug build needs cleartext allowed for10.0.2.2(a network security config) since this is plain http. - A physical phone cannot reach
127.0.0.1; that needsHOST=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-versionshows the version;bin/set-version --checkfails unless both apps agree and the values are well formed (bin/test versionand CI run it).bin/set-version 2026-12-03(ortoday) sets both apps to that day, build01; 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/Appxcodebuild test -scheme Canasta -destination 'platform=iOS Simulator,name=iPhone 17' \ -only-testing:CanastaTests 2>&1 | xcbeautify --quietUI 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, theCanastaUITeststarget inproject.yml; about 8 minutes):The test setscd swift/Appxcodebuild test -scheme Canasta -destination 'platform=iOS Simulator,name=iPhone 17' \-only-testing:CanastaUITests 2>&1 | xcbeautify --quietCANASTA_UI_TEST_SEEDin 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-uitestbuildscanasta-serverwithdev-auth, starts it on a free port with a throwaway key (needsDATABASE_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 throughHOMEFELT_SERVER_URL(launch environment) or theonline.serverURLdefault; 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-uitestbuildscanasta-serverwithdev-auth, starts it on a free port with a throwaway key (needsDATABASE_URL, e.g.postgres://localhost/homefelt_test) and a booted emulator, which reaches it throughadb reverseon its own127.0.0.1(an app targeting API 37 needs the local-network permission for10.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 extrahomefeltServer(kept in theonline.serverURLsetting;adb reverse tcp:8080 tcp:8080, thenadb shell am start -n dev.edsancha.homefelt.canasta/canasta.app.MainActivity --es homefeltServer http://127.0.0.1:8080); only debug builds allow cleartext to127.0.0.1,localhostand10.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), thenThe test setscd kotlin./gradlew :app:connectedDebugAndroidTest -q --console=plain \-Pandroid.testInstrumentationRunnerArguments.class=canasta.app.FullGameUiTestUiTestLaunch.seedbefore the activity starts. Each run logs its result:adb logcat -d -s FullGameUiTest:I. Without theclassargument it also runsLocalizationTest(the words in English and Spanish) andLanguageUiTest(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.inito a roomier disk, point the.ini’spath=at the copy, and start it withANDROID_AVD_HOME=<that folder>. - Postgres is not running (
bin/devsays it did not answer):pg_isready -h 127.0.0.1. Homebrew:brew services list, thenbrew services restart postgresql@17. Postgres.app: read~/Library/Application Support/Postgres/var-17/postgresql.log; a stalepostmaster.pidthere after a crash is the usual cause (remove it only when nopostgresprocess runs). Another Postgres already on 5432 is used as it is:bin/setupcreates the databases in it. - Port in use:
lsof -nP -iTCP:8080 -sTCP:LISTENshows who holds it. Stop it, or setPORTin.env.development.local.bin/devrefuses to start when something already answers/healththere. 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 extractworkers) waits forever, for formulae and casks alike, and the workers outlive the install that started them. Checkpgrep -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 runbin/setupagain; it uses the app’s binaries without opening the app. - Missing iOS runtime:
xcrun simctl list runtimesis empty or lacks the iOS version the app targets. Xcode → Settings → Components, orxcodebuild -downloadPlatform iOS(several GB: check free disk first). DATABASE_URL is not setor the key file is missing:bin/setupwrites both; a moved checkout needs it again. The key path is relative to the repository root, wherebin/devruns the server.- Tests skip the database: run them with
bin/dev test, not plaincargo test.