Skip to content

CI And Test Shards

Capell’s CI runs code-quality checks and divides the test suite with Pest’s native sharding support.

composer test:preflight runs Pest’s parallel suite. Pull-request jobs set PEST_SHARD and use composer test:fast:ci to select their native Pest shard.

On ready pull requests, the three SQLite Fast PR gate shards start alongside matrix resolution. Sentinel waits only for matrix resolution, then the Test All behaviour, unit and portability jobs wait for sentinel. Fast PR gate remains an independent failing job: all three fast shards and all Test All cells must pass for a successful workflow. Draft, Dependabot and targeted-dispatch conditions, and concurrency cancellation, still apply.

The MySQL Admin Feature cell uses two native Pest shards, named Feature - Admin (1/2) - DBmysql and Feature - Admin (2/2) - DBmysql. Both retain the Feature suite and admin group and partition that selection with --shard=1/2 and --shard=2/2. Each has separate JUnit, logs and engineering metrics, so aggregation counts both shards. Exact dispatches use l13-feature-admin-shard-1 or l13-feature-admin-shard-2; the local matrix runner uses the same definitions and cell runner.

Run composer test:shards when the timing manifest needs refreshing. Pest writes tests/.pest/shards.json directly.

This checkout uses Pest 5 with its native sharding support.

Use composer test:preflight:serial -- <paths or filter> for focused selections. With the locked Pest 5.3.x, a filter across the whole tree can report passing tests while its parallel result has hasTests=false and exits 1. Retain that exit as a tooling failure; use the serial runner for focused proof and require the full parallel suite and hosted matrix before merge.

The release-environment Composer constraint checks read sibling locks from the measured source commits. Set CAPELL_RELEASE_APP_COMMIT and CAPELL_RELEASE_PACKAGES_COMMIT to full 40-character commit hashes, alongside CAPELL_APPLICATION_ROOT and CAPELL_PACKAGES_REPO_PATH, when running that group locally. Moving fetched refs or editing a sibling lock cannot change its input. The App release verifier supplies these pins and includes all three repository commits in Core’s lane cache key; missing or mutable pins fail admission.

Composer install and autoload refresh matter for screenshot and docs checks because generated Filament/admin fixtures depend on package discovery and Testbench state. CI runs Composer validation and dependency install before quality checks so package providers, screenshot fixtures, and generated docs state use the current lock file rather than stale vendor metadata.

The documentation receipt checks also need the shared screenshot runner. In a linked worktree, npm ci can leave the local file:../capell-screenshot-tools dependency pointing at an absent sibling; set CAPELL_SCREENSHOT_RUNNER_PATH to the absolute path of a clean, committed runner checkout before composer preflight:all. The receipt check validates that checkout’s src/receipt-validator-cli.mjs; an unavailable validator is a missing prerequisite, not a passing screenshot check.

Use the narrowest command while changing code:

Terminal window
vendor/bin/pest packages/frontend/tests/Unit/Cache --configuration=phpunit.xml

Before a finished branch, use:

Terminal window
composer preflight:all

preflight:all applies repository-wide Rector transformations and Pint formatting automatically, then runs Prettier in check mode. It also runs documentation checks, the root-doc guard, PHPStan baseline growth protection, and Pest. Review and commit any generated changes before pushing; CI asserts that the command leaves a clean checkout, so uncommitted transformations still fail the build.

Preflight runs every selected gate and prints a per-stage summary at the end, even when an earlier independent gate fails. Pest also runs without fail-fast flags so one integrated run reports the complete test failure set. To rerun only named failing gates, pass their stage names after --:

Terminal window
composer preflight -- phpstan tests
composer preflight:all -- docs-links phpstan-baseline

Whole-tree preflight runs queue in the host-wide heavy pool (heavy status lists holders and the current limits; by default 5 slots and a load cap of 10, set by HEAVY_SLOTS and HEAVY_MAX_LOAD). scripts/run-preflight.php takes weight 3 (three of the five default slots) through scripts/heavy-admission.php, and the stage commands that run behind scripts/with-lock.php take weight 3, or 2 for PHPStan, so a second composer preflight from another worktree waits for a slot instead of doubling the Pest, Rector and PHPStan worker load. composer coverage and composer coverage-report are admitted the same way, once and before their first step, through scripts/with-admission.php, so on a busy host no preparation or Pest worker starts and a later step never queues again mid-run. Stages of an admitted run inherit its slot (CAPELL_HEAVY_ADMITTED, HEAVY_SLOT_OWNER) and do not wait again. Use CAPELL_HEAVY_WEIGHT=1 to lower a focused stage command’s weight. The guard is HEAVY_SLOT_GUARD, scripts/guards/heavy-slot.sh or ~/.local/share/heavy/heavy-slot.sh; when none exists a warning is printed and the run is unqueued. CAPELL_NO_LOCK=1 or HEAVY_SLOT_ENABLED=0 bypasses admission for diagnostics only.

An unknown stage exits with the available names. The final preflight exit remains non-zero when any selected gate fails.

On pull requests, the required PHP Quality (8.4) job runs the quick static and formatting stages directly: Composer-major constraints, queue contract, language-key drift, package dependencies, split-repository health, Agent Schema, Prettier, ESLint, Pint, and PHPStan. It also runs the PHPStan baseline check, Composer audit, and the full Rector transformation followed by a clean-tree assertion. The expensive tests stage remains in the required Test All workflow, which runs the PR Pest shards and the repository’s matrix cells rather than duplicating that work in PHP Quality.

To apply Rector, Pint, and Prettier changes before rerunning the same checks, use:

Terminal window
composer preflight:fix

A new leaf in any packages/*/config/*.php must be documented in docs/development/configuration.md or classified in scripts/docs-config-key-classifications.php. Otherwise php scripts/check-docs-config-keys.php (composer check:docs-config) fails, and so do the PHP Quality workflow and DocumentationConfigKeysScriptTest. Run the script before pushing. Keep the required PHP Quality (8.4) and actionlint checks present on every pull request to main, and read their results before merging.

scripts/audit-language-keys.sh decides a translation key is used as follows:

  • Static: a full literal key closed by its quote, __('capell-x::group.a.b').
  • Family (credits every matching defined key): sprintf('capell-x::group.a.%s', $value) with any prefix or suffix around %s, or dot-terminated concatenation, __('capell-x::group.a.' . $value).
  • Not matched as a family, so the keys are reported as unused: interpolation, __("...a.{$value}"), and underscore-suffix concatenation, __('...outcome_' . $value). Convert such sites to the sprintf form.

scripts/check-language-key-drift.php gates new drift against a baseline, so a call-site refactor that legitimately changes the dynamic sites needs a baseline --update.

  • phpunit.xml sets <ini name="memory_limit" value="2G"/>. PHPUnit applies it in every process, parent and workers, and it overrides -d memory_limit on the command line, so no Pest command should pass -d memory_limit. Delete the line and workers drop to the host php.ini default, so workers dying with Allowed memory size of 134217728 bytes exhausted while static stages pass is the 128M default reaching a worker, not a crash.
  • phpunit-coverage.xml is the second configuration, at 8G, used by the coverage, coverage:blade and mutation scripts. A second file is needed because the parent and the workers cannot differ, and under --parallel the parent deserialises every worker’s coverage set. CoverageWorkflowTest requires the two files to be identical apart from comments and the <ini> line, so edit both together.
  • XML comments cannot contain a double hyphen. A flag name such as --parallel in a comment makes the file malformed and every Pest run fails to load its configuration. Run xmllint --noout phpunit.xml after editing a comment.
  • PHPStan is not a Pest process and gets no limit from these files: pass its own memory limit (the analyze scripts use --memory-limit=4G).

Test All and PHP Quality run on pull requests to main, without duplicate post-merge runs. CodeQL runs weekly or by manual dispatch. Coverage runs on tags or by manual dispatch. Core Screenshots runs by manual dispatch; screenshots also run during release deployment. Existing release and dispatch entry points remain available. The Test All engineering-metrics job is still push-only and has no automatic trigger after the main push trigger is removed.

Nightly main (.github/workflows/nightly-main.yml) runs every night and by manual dispatch. It calls the Fast PR gate with a fresh latest-dependency update (no vendor cache) followed by composer audit, and calls Test All. A failure on main opens or comments on a single issue labelled nightly-failure; the next passing run closes it.

Approval environments and workflow credentials

Section titled “Approval environments and workflow credentials”

Configure a release environment in the monorepo with required reviewers, prevent self-review and bypass, and allow deployments only from main. Store SPLIT_APP_ID and SPLIT_APP_PRIVATE_KEY in that environment and remove any repository or organisation secret copies available to other jobs. Release dispatches must use main; the approved plan source must be an ancestor of the exact main commit supplying the workflow. Only the publication job receives write permissions and enters the approval environment.

Each split repository needs a split-pr-forwarding environment with required reviewers, self-review and bypass disabled, and deployment branches restricted to its protected default branch. Store SPLIT_PR_FORWARD_TOKEN there (or the legacy ACCESS_TOKEN fallback) and remove broader copies. Approval is required for each run, including source updates, before fork-authored files are copied into a monorepo branch. Review the event’s exact source SHA before approving; the checkout uses that immutable SHA. Per-PR concurrency cancels older pending runs when the source changes. The forwarder only copies package files and must never execute code from the source checkout.

Environment names in YAML do not create reviewer or branch protection rules. Provision and verify these settings before enabling the workflows; an unprotected environment does not provide an approval boundary. The forwarding target remains 1.x, so verify its workflow and secret policies separately.

All read-only workflow checkouts discard credentials immediately after fetching, including Test All’s reusable fast gate, asset formatting, package builds, coverage, extension audit, browser smoke, Windows verification, CodeQL and Workflow Lint. The credential contract discovers all monorepo workflows, split workflows and the forwarding template. Changelog’s dedicated write-back job is the sole exception: its commit action uses persisted checkout credentials to update CHANGELOG.md on main, and it contains no repository run steps.

Screenshot, release-smoke, Test All, PHP Quality and Rector repository run steps receive no PAT, including Test All’s framework dependency preparation. Screenshot, release-smoke, PHP Quality and Rector dependency installation disables npm lifecycle hooks and Composer scripts/plugins; the root Composer autoload preparation is then invoked explicitly without credentials using composer dump-autoload, preserving Pest plugin registration, package discovery and Testbench preparation. PHP Quality refreshes autoload state on both Composer cache hits and misses.

Dependabot opens one monthly grouped PR per ecosystem. Dependabot PRs run no hosted jobs and never auto-merge. Combine all open Dependabot PRs into one branch (for example, gh combine-prs --query "author:app/dependabot", if that extension is installed, or cherry-pick their commits), run the repository’s local gates, merge once, then close the original PRs.

Run composer preflight:all and composer test:all:matrix:local before merging the combined branch.

A pull request state is not a test result. Before release work, run Coverage for the exact release SHA through its tag trigger or manual dispatch, then inspect every required workflow for that SHA. A workflow which is still running, failed after executing steps, or was refused before a runner was assigned is not a green gate. For a failed Coverage run, inspect the individual shard jobs and retain their logs before rerunning anything:

Terminal window
gh run list --repo capell-app/capell --branch main --limit 20 \
--json databaseId,name,status,conclusion,headSha
gh run view <coverage-run-id> --repo capell-app/capell --log-failed
gh api 'repos/capell-app/capell/actions/runs/<coverage-run-id>/jobs?per_page=100' \
--jq '.jobs[] | [.id,.name,.status,.conclusion] | @tsv'

Use the exact hosted failure as the starting point for a focused local reproduction. Run composer prepare and the same Testbench optimize command before the affected Pest path; an already-warm vendor or cache directory can hide a clean-install failure. Keep the configured parallel worker count when checking an isolation problem, but do not rerun the whole package matrix just to rediscover one shard failure.

Two small Testbench details are easy to miss. A route-isolation fixture that replaces a Laravel RouteCollection must leave both the router and app('url') observing the intended collection after replacement and restoration; refresh name lookups after fluent named-route registration. That lookup repair does not replace modelling an unavailable Admin resource when a test is intended to exercise the named-route fallback. Child list/optimize commands must boot from the same runtime-role configuration and cache paths as the parent; verify the expected runtime-role cache file exists after optimize, and make missing settings/provider configuration fail with a useful child command receipt.

The shard timing warning for tests/.pest/shards.json is advisory. Refresh it only as an intentional, separately reviewed change; updating timings to make a failure disappear is not a repair. The Update Pest shards workflow runs monthly (and on manual dispatch from main) and opens or refreshes a chore/update-pest-shards pull request when the timings change; it is not labelled, so it merges only once someone reviews it and adds ready-to-merge. A complete Coverage gate requires every shard plus the merge/threshold job to finish successfully.

Test All owns a focused portability group for every advertised database family:

CellRuntime
l13-portability-sqliteSQLite from PHP 8.4
l13-portability-mysql-8mysql:8.0
l13-portability-mariadb-10-5mariadb:10.5 through the MariaDB platform seam
l13-portability-postgresql-16postgres:16 through pdo_pgsql

Every cell runs the same repository-owned Pest group. It proves the complete Core migration set, database provisioning, install, doctor and upgrade paths, query and JSON dialects, uniqueness and foreign-key behaviour, and safe backup/restore process contracts. MariaDB is a separate service and platform assertion rather than an alias for the MySQL cell. PostgreSQL-specific executable assertions run in the PostgreSQL cell.

Run one exact committed-head cell locally with:

Terminal window
composer test:all:matrix:local -- --cell=l13-portability-postgresql-16

The local runner creates a detached worktree at the current HEAD, prepares the pinned Laravel/Testbench dependencies, and owns a generated database name, random host port, and disposable service container. It never uses or mutates a shared development database. Evidence is written beneath .test-all-results/; a failed or timed-out cell is incomplete evidence, not support proof.

The complete Test All matrix runs once per change, on the merge-group commit, not again on the pull request. A pull request runs the fast PR gate, PHP Quality and the other cheap checks for quick feedback. The Merge queue full matrix check then runs every matrix cell on each merge-group commit and validates a non-empty, passing JUnit report for every configured cell from that attempt. Merge queue full matrix is a required check on main, so an entry whose matrix fails leaves the queue instead of merging, without blocking the entries behind it. On a pull request the same check passes without running the matrix, so a PR can still join the queue. A merge group that changes no file listed in .github/ci/test-all-paths.txt (Test All’s own path filter plus the merge queue’s files) skips the matrix, and the check passes. To run the matrix on a pull request before queueing it, dispatch Test All manually for the branch.

Adding ready-to-merge to an open, non-draft PR targeting main authorises GitHub to merge it through the main merge queue without a further per-PR chat approval. This is an explicit exception to the normal PR merge approval rule. The worker enables squash auto-merge for the PR’s current head, so GitHub adds it to the queue the moment the required checks pass; if they have already passed, the worker enqueues it immediately. Nothing waits on a schedule and no branch update is forced: the queue builds each entry on top of the one ahead.

The worker runs when the label is added or removed, when the PR is pushed to, reopened, marked ready or converted to draft, by manual dispatch (leave pr_number blank to sweep every labelled PR) and hourly as a safety net. It disables auto-merge again when the label is removed, awaiting-merge is added or the PR becomes a draft. A PR that is already in the queue must be removed from GitHub’s queue separately.

If the merge-group checks fail, GitHub ejects the entry and the entries behind it continue. Fix the problem and push, or remove and reapply the label, to retry. PRs from forks must be merged manually. The label authorises the PR’s current head and later pushes to the branch; remove it before pushing changes that should not merge. Enqueueing can lead to an automatic merge and there is no direct-merge fallback.

An administrator must enable the main merge queue and install a dedicated GitHub App on this repository with Contents write, Pull requests write and Merge queues write permissions, without bypass rights. Store its ID and private key in MERGE_QUEUE_APP_ID and MERGE_QUEUE_APP_PRIVATE_KEY repository secrets. The workflow creates a short-lived installation token for each run. The ready-to-merge label must exist. Verify the App can enqueue and required checks run before relying on the queue. The main ruleset requires PHP Quality (8.4) and Merge queue full matrix; both, and actionlint, run on merge_group. Any further required check must also report on merge_group. Hosted Actions billing or credential restrictions can prevent the worker from running; local checks do not produce the required merge-group status.

For concurrent local screenshot runs, set CAPELL_SCREENSHOT_PORT to an available port from 1024 to 65535 (the default is 8145). The Testbench server, runner and local Marketplace fixture use that port. Set CAPELL_SCREENSHOT_OUTPUT_ROOT to a directory outside every source checkout so captures and receipts are retained.