Test locally
Test the code you're editing right now by syncing your working files into a sandbox, before you commit.
Sync your working files, uncommitted changes included, into a sandbox, a live copy of your app (also called a test environment). You change code, run a test and see the result without a commit, an image build or a pull request.
Test a change in a sandbox
-
Check your definition. You need a
cofactor.sandbox.yaml. See Build from GitHub or Build from a pushed image.bashcofactor sandbox validate
For an app delivered as a pushed image, run
cofactor sandbox validate --upload cofactor.sandbox.yamlfrom the folder that holds the file. -
Claim a sandbox.
bashcofactor sandbox claim --application "Acme App" --wait
-
Sync your files.
synclists what it will write and delete, then applies it. Check the list for a stray.env.bashcofactor sandbox sync <sandbox id>
The output of cofactor sandbox sync: a plan of 3 files to write and 0 to delete, the files that stay only in the sandbox, and the synced tree id. -
Rebuild and restart. Services keep running old code until they restart.
--buildreruns the build steps whose inputs changed and restarts the services markedafter_build: true. To restart a service yourself, useexec. If you name a service that doesn't exist, the error lists the ones that do.bashcofactor sandbox sync <sandbox id> --build cofactor sandbox exec <sandbox id> -- cofactor-sandbox restart app
-
Run a test on it.
bashcofactor workflow run <workflow id> --sandbox <sandbox id> --stream
The run uses your sandbox and leaves it running. You can also open the sandbox URL and sign in with a login from
cofactor sandbox show <sandbox id>. -
Repeat from step 3, then destroy it.
bashcofactor sandbox destroy <sandbox id>
Check it worked
cofactor sandbox show <sandbox id> cofactor workflow runs list <workflow id>
show records the synced tree id. The run records the version and tree it ran against. Your change is visible in the running app.
Go deeper
- Environments
- Seed data and logins
- Reference: Sandbox CLI
Start from local files, compiled output, localhost mode and common errors.
Start from local files. cofactor sandbox claim --application "Acme App" --from-local --wait claims your tracked and unignored untracked files and leaves your git HEAD and index alone. Before you merge, make a fresh claim from your final files and run cofactor sandbox verify-env --application "Acme App" --at <sha>.
Compiled output. Build locally, then mirror the result into the sandbox with cofactor sandbox sync <id> frontend/dist --to static.
Logs. Each service logs to /var/lib/cofactor/logs/<service>.log. Read one with cofactor sandbox exec <id> -- tail -n 100 /var/lib/cofactor/logs/app.log.
Your own Playwright. Use the sandbox's public URL, or cofactor sandbox forward <id> for a tunnel to one port on 127.0.0.1.
Point Cofactor at your own localhost. If your app can't run in a sandbox yet, register it with cofactor local init --property "Acme App" --url http://localhost:3000. Add --credentials enter --username <u> --password <p> for a login. Then run cofactor local start to open a browser on it. The flag is still named --property.
Errors. Restart the service if a change isn't visible. Only sandboxes you claimed can be synced. Sync changes files and never data, so destroy the sandbox to reset it. sync and exec need the sandbox:exec scope.