# Verification

Two different checks, at two different costs.

### `cofactor sandbox validate [file] [--upload]`

Offline — no sandbox, no claim. The definition repository comes from the
checkout's `origin`.


Pass `--repo owner/name` for a checkout without a GitHub remote (a CI
mirror, an SSH host alias).


Parses the YAML, runs the full
schema, and cross-checks everything static analysis can catch: unknown
actions or operations referenced by a seed, `${id.key}` references to a
later step or an undeclared output key, an `extends` cycle, a duplicate
step id across a chain, an unknown emulation plugin, port 80/443 declared
while emulation is on, and more. Every issue is reported with a dotted
path to exactly where it is, so a broken definition doesn't need a claim
to find the problem:

```text
environments.default.seeds[0].input.workspace_id: references step "acme", which has not run yet (or does not exist)
environments.free-plan.extends: unknown environment "defualt"
ports.emulation: "emulation" is a reserved port name
```

Run this before pushing any change to `cofactor.sandbox.yaml` — it's
instant and catches most authoring mistakes before they cost a real
claim. It is the only local check; only a claim proves the definition.

### `cofactor sandbox verify-env --application A [--environment E]`

Actually claims each requested environment of the application's current
version (or every environment in the definition, if none is named) in turn:
claim, wait for ready, report every seed step's output and timing, sign
every persona in as a test's Login step would (when the definition
declares `authentication`), then destroy. This is the only way to prove an
environment's seed chain and persona logins actually run end to end —
`validate` can tell you a reference is well-formed, but only a real claim
proves the referenced action produces the output at runtime, and that
`authentication.run` works in the image (a command the image lacks, a
wrong URL). Each persona prints `signed in`, or FAILED with the script's
exit code and the end of its stderr; any failure fails the environment.
Without a pinned version, a GitHub application uses the default
environment's head (or the default branch's tip when that head is stale).
A default branch without a definition is not ready for unpinned checks.


For a multi-repository definition, that current version is a revision of
the definition and all declared repositories together. To verify a
specific combination of commits, claim it with `--at` (see `cli`) and
run `auth-check` or `exec` against that sandbox.



### `cofactor sandbox verify-env --application A --at <sha> [--environment E]`

Reads and verifies that pushed commit's definition before any merge.
Use either a branch SHA or the full source SHA printed by
`claim --from-local`. The latter creates its source object without
changing the user's HEAD or index. After the last edit, validate and
make a fresh claim from local files or the final branch SHA, then run
this check. A previously synced copy alone is not evidence that the
source snapshot builds from scratch.

Check the UI at the claimed copy's web URL and run a workflow with
`cofactor workflow run <flow> --sandbox <id>` before merge. For one
existing copy, `cofactor sandbox auth-check <id> --persona P` checks a
native persona without a workflow. Merge only when the user wants
default-branch adoption; unpinned refresh and verify-env check that
adoption afterwards. See `cli`, "Setting up a new GitHub application".


## When a seed fails

Seeds run once per version (commit or push) and environment, while its
ready snapshot is built. Any step's failure fails that snapshot — the
builder is destroyed, so there's no partially-seeded sandbox left around
to poke at — and the claims waiting on it fail with that error. The next
claim builds the snapshot again, so a seed that fails every time keeps
failing until a fixed source version is supplied. An infrastructure failure,
by contrast, is retried by the build, within the claim's time limit
(`cofactor sandbox claim --timeout`, 2 hours by default).

To debug a failing seed:

1. Read the error — the claim (or `verify-env`) reports which step
   failed, its action, and the script's stderr (everything a script
   prints besides its final `{...}` result line goes to stderr, so
   this is where the real error message is).
2. Claim a sandbox **without** the failing environment (or on an
   environment that stops short of the failing step) so you have a
   live sandbox to work on.
3. Run the failing action by hand against that live sandbox with
   `cofactor sandbox run <id> <action> --input k=v ...`, using the
   same inputs the seed step would have resolved (substitute in the
   actual values for any `${id.key}` references by hand). This lets
   you iterate on the action's script without repeatedly re-claiming.
4. Once the action succeeds standalone, fix the seed definition or the
   action script and confirm the full chain on a fresh source version.
   For a pushed image, push the fixed image and rerun verify-env.


   For GitHub, validate, claim --from-local again, and verify-env --at
   its new source SHA, or use a fixed pushed branch SHA. Neither path
   requires a merge or a user commit during local iteration.
