Docs/Test locally
#

Test locally

Test the code you're editing right now by syncing your working files into a sandbox, before you commit.

Test my uncommitted change

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

  1. Check your definition. You need a cofactor.sandbox.yaml. See Build from GitHub or Build from a pushed image.

    bash
    cofactor sandbox validate
    

    For an app delivered as a pushed image, run cofactor sandbox validate --upload cofactor.sandbox.yaml from the folder that holds the file.

  2. Claim a sandbox.

    bash
    cofactor sandbox claim --application "Acme App" --wait
    
  3. Sync your files. sync lists what it will write and delete, then applies it. Check the list for a stray .env.

    bash
    cofactor 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.
  4. Rebuild and restart. Services keep running old code until they restart. --build reruns the build steps whose inputs changed and restarts the services marked after_build: true. To restart a service yourself, use exec. If you name a service that doesn't exist, the error lists the ones that do.

    bash
    cofactor sandbox sync <sandbox id> --build
    cofactor sandbox exec <sandbox id> -- cofactor-sandbox restart app
    
  5. Run a test on it.

    bash
    cofactor 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>.

  6. Repeat from step 3, then destroy it.

    bash
    cofactor sandbox destroy <sandbox id>
    

Check it worked

bash
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

Advanced

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.