# Declare tests

## Declare a Playwright suite

The test repository must already be connected and authorized, then linked to
the Application it exercises. In these examples, the organization is `Acme`,
the Application is `Example`, and the linked test repository is
`Acme/browser-tests`. Use your own organization, Application and linked
repository names when you run the commands.

The GitHub App must be installed with access to the repository. If it is
already authorized but not yet linked to the Application, use the existing
repository-link command. First find the Application ID:

```bash
cofactor application list --org Acme --json
```

Then pass the returned Application UUID to the link command:

```bash
cofactor application repo link --application <application-uuid> \
  --repo Acme/browser-tests --org Acme
```

Create the external suite with the supported customer configuration:

```bash
cofactor test-suite create --name "Example browser tests" --kind external \
  --provider playwright --source github --repo Acme/browser-tests \
  --application Example --environment default --org Acme
```

Then update the suite that was just created. Use its returned name or ID:

```bash
cofactor test-suite update "Example browser tests" --ref main \
  --capture-policy retry --max-retries 1 --org Acme
```

`create` establishes the suite and source. `update` changes only the runner
settings you pass. The example keeps the standard Playwright runner and selects
the `main` branch, retry capture, and one Cofactor retry. Advanced container
and command settings are not part of this customer setup.

The repository's root `cofactor.tests.yaml` declares the version-1 contract:

```yaml
version: 1
install: npm ci
run:
  playwright:
    config: playwright.config.ts
env:
  BASE_URL: ${app.url}
  QA_EMAIL: ${personas.qa.email}
  QA_PASSWORD: ${personas.qa.password}
  ACCOUNT_ID: ${seeds.account.accountId}
```

`install` is the install command. `run.playwright.config` points to the
repository's Playwright config. The config and tests can read the variables
from `process.env`, for example `process.env.BASE_URL`.

Every runtime reference must be the entire value of one environment entry:
`${app.url}`, `${personas.<name>.email}`, `${personas.<name>.password}`, or
`${seeds.<seed>.<output>}`. Do not concatenate a reference with literal text
or interpolate it into a larger value. Plain values such as `NODE_ENV:
test` remain literal values.

Persona names and seed output names come from the Application's Sandbox
definition and its seed outputs. Ensure the named `qa` persona exists, and that
the `account` seed produces the `accountId` output. Do not put resolved
passwords or other runtime values into the repository. Actual app URLs,
persona values and seed outputs are resolved only for each fresh runtime copy;
installation and discovery never receive those real values.

Validate the declaration from its directory before pushing:

```bash
cofactor test-suite validate <directory>
```

This checks the declaration schema offline. It does not connect to the
Application or prove that the referenced persona or seed output exists.

## Large GitHub repositories

For GitHub sources, optionally add literal repository-relative files or
directories under `source.paths`. Cofactor preserves their repository layout:

```yaml
source:
  paths:
    - package.json
    - package-lock.json
    - e2e
```

The root `cofactor.tests.yaml` is always included. Include everything needed by
install and by the tests: workspace manifests, lockfiles, patches, scripts,
config, shared helpers and fixtures. Dependencies are not inferred. A path
must name an existing file or directory; globs, traversal, symlinks and
submodules are not supported. Missing/unsafe paths fail preparation.

Cofactor uses a sparse, shallow checkout at the run-pinned test commit inside
a clean platform sandbox that is separate from your application and runs none of
your code; the read-only repository token exists only there and is revoked right
after. The validated files are then handed to the sandbox that builds your suite. Selected files are limited to
100 MiB total and 10,000 entries.

Without source.paths, Cofactor checks out the whole repository at the pinned
commit under the same limits. EXTERNAL_TEST_SOURCE_TOO_LARGE means you should add
source.paths, commit the declaration, and run again at the new pinned commit.
Uploaded
bundles keep their 100 MiB limit; source.paths does not prune an upload or image.
