Current section

Files

Jump to
ash_hooks CONTRIBUTING.md
Raw

CONTRIBUTING.md

<!--
SPDX-FileCopyrightText: © 2026 BaseLabs Holdings LLC

SPDX-License-Identifier: MIT
-->

# Contributing

Use this guide to set up an AshHooks checkout, run the project's checks, and
prepare a Hex release.

## Development environment

Use the Elixir and Erlang/OTP versions pinned in `.tool-versions`. Use macOS or
Linux. On Windows, use WSL2 and clone inside its Linux filesystem. See
[Compatibility](documentation/topics/support/compatibility.md) for consumer
requirements.

Set Ash's required string-length counting mode before compiling host resources. The test
application uses:

<!-- tested: contributing-string-config -->
```elixir
config :ash, default_string_length_count: :codepoints
```

Ordinary tests use the repository's SQLite test application. PostgreSQL tests
require a real PostgreSQL 16 or later service and run only when
`ASH_HOOKS_POSTGRES=1` is set. Configure the connection with
`ASH_HOOKS_TEST_PG_HOST`, `ASH_HOOKS_TEST_PG_PORT`, `ASH_HOOKS_TEST_PG_USER`,
`ASH_HOOKS_TEST_PG_PASSWORD`, and `ASH_HOOKS_TEST_PG_DATABASE`.

Point these variables at a disposable test database with a PostgreSQL
superuser for fixture setup. Each run creates a separate login with
`NOSUPERUSER` and `NOBYPASSRLS`. Test actions use that login, including the
Oban job consumed in a fresh BEAM. The suite removes the login and its
disposable fixtures on exit.

Row-security cases create admin-owned tables, force row security, and grant
each test login access through the fixture policies.

The PostgreSQL delivery qualification also uses a real WebHook Tester receiver.
For first-time setup, start the receiver from the repository root:

<!-- not-run: This starts a persistent receiver service and requires an available local port. -->
```sh
docker compose -f ops/local/webhook-tester.compose.yaml up -d
curl -fsS http://127.0.0.1:52871/api/version
```

Set `ASH_HOOKS_REAL_RECEIVER_PORT` to `52871` to include these tests. Set
`LOCAL_WEBHOOK_TESTER_PORT` on the Compose command and match it in the test
variable to use a different free loopback port. Reuse an existing receiver
when available; do not restart another user's service or remove capture data.
See the [receiver
guide](https://github.com/baselabs/ash_hooks/blob/main/ops/local/README.md).

CI provides the receiver alongside PostgreSQL. Its PostgreSQL job runs the
public platform engine checked in `.github/postgres.ref` and the compatibility
majors declared once in `.github/postgres-lanes`, using digest-pinned upstream
images. The reader in `scripts/postgres-lanes.py` supplies both the matrix and
compatibility images and refuses a lane for the engine's major. Each lane
starts a disposable server on IPv4 loopback and removes it after the job.

## Testing changes

- Preserve exact bytes across inbound verification and outbound signing. Tests should
  assert the bytes observed by the receiver, not only the request assembled in memory.
- Exercise both the default resource shape and affected supported variants, including
  tenancy, renamed or composite ledger keys, UUIDv7 endpoint/subscription keys, and
  optional Oban/Plug absence where relevant.

Coverage is 100% of the surface declared in `mix.exs`; whole-module exclusions are
outside that denominator. Do not add an exclusion to hide reachable runtime behavior.
Add a meaningful test for reachable behavior or remove an unreachable branch.

GitHub-hosted runners build and test the project. `mix check` defines the
project checks in `.check.exs`, including formatting, compilation, Credo,
ExDoc, and packaging. The REUSE check uses `pipx` and pins reuse 6.3.0.

Push your work branch outside `main` and `kci/**` for quick checks on
GitHub-hosted runners. Read the result once after it finishes, without
polling, and fix failures in a new commit. The workflow runs `mix check
--except ex_unit` and the SQLite tests chosen by `MIX_ENV=test mix
covering_tests origin/main`. The selector covers changed tests and tests for
changed, deleted, or renamed library modules and their direct dependents.

Shared build and test inputs select the whole suite. For storage, tenancy,
worker, and other PostgreSQL-dependent changes, the workflow also runs the
selected tests against the platform PostgreSQL engine and real receiver.
Public HTTPS and Livebook examples run in qualification.

CI fetches project dependencies from committed locks with `--check-locked`.
A change to the package requirements or to a supported floor
also refreshes the two floor locks. The production consumer's lock is the graph
CI compiles and audits at the floor. The floor lock is the development graph at
the floor, which the full-suite qualification below runs on:

<!-- not-run: This resolves the floor graphs' dependencies. -->
```sh
(cd test/consumer && MIX_ENV=prod mix deps.get)
elixir scripts/check-ash-floor.exs --update-lock
```

To move a package in the floor graph to its newest admitted release, for example
after an advisory, name it to resolve that dependency again:

<!-- not-run: This resolves the floor graph's dependencies. -->
```sh
elixir scripts/check-ash-floor.exs --update-lock db_connection
```

The CI precheck runs on a push to `kci/<topic>`. To land a change, a maintainer runs the
full workflow on `kci/<full SHA>` and moves `main` only after `qualified` passes for that
exact commit. The PostgreSQL job runs `mix check --except ex_unit --except documentation_examples`,
the required documentation examples, and the full test suite with coverage.

CI only restores build caches. The one writer is
`.github/workflows/cache-warmer.yml`, which runs hourly on `main` and builds each
key CI restores from the committed lock: every test lane (the default lane with
its Dialyzer PLTs), the floor and dev. A commit that changes `mix.lock` qualifies
on a cold build until the warmer next runs.

CI's PostgreSQL job qualifies the full suite at the
[Ash and Spark floors](documentation/topics/support/compatibility.md) with its
PostgreSQL service and real receiver. The job runs:

<!-- not-run: This requires configured PostgreSQL and local receiver services. -->
```sh
ASH_HOOKS_POSTGRES=1 ASH_HOOKS_REAL_RECEIVER_PORT=52871 elixir scripts/check-ash-floor.exs
```

This full-suite check consumes a persisted Oban.Basic job in a fresh BEAM
process and verifies its HTTPS delivery at a loopback receiver using the test
CA. The tests use local services and resolve hostnames through a local hosts
database.

It runs on the committed `test/floor/mix.lock`, fetched with `--check-locked`,
and keeps the main lock, dependencies, and build files unchanged by using
`_build/ash-floor` for the minimum supported graph and removing it on exit.

CI runs Livebook changes through `scripts/run-livebook.sh` against the candidate Hex archive.

## Documentation and confidentiality checks

The required documentation run is enabled with `ASH_HOOKS_DOCS_REQUIRED=1`. It
needs PostgreSQL and the WebHook Tester receiver. The HTTPS examples start
their own loopback receivers using the test CA. The Livebook qualification
fetches the notebook's locked dependencies into its own Hex home, builds its
SQLite NIF locally, and serves the candidate archive and the checksum-verified
tarballs from a loopback registry.

Static dispositions and consumer formatting remain part of the ordinary tests.
Each block uses its dependencies' formatter exports. A lane without a block's
dependency reports why its format check is skipped; full lanes must check
every block.

`scripts/check-confidentiality.sh` scans tracked files, the built archive, and
generated HTML and Markdown docs using `PUBLIC_DOCS_DENYLIST` from the
caller's environment. The live policy test is excluded when that variable is
absent; the scanner itself refuses an empty policy. Synthetic scanner tests
always run. `scripts/check-document-dashes.py` checks the archive and
generated HTML and Markdown surfaces.

Generated HTML is checked without rewriting it. The checker reads the build's
project name and version through Mix without compiling or starting the
application. Only ExDoc's final page-title separator before that identity and
its index redirect separator before `Documentation` are exempt. Authored title
and body text remain subject to the dash check.

CI runs the confidentiality scan, required-document qualification, and
publication dash checks, and requires them in `qualified`. Local
optional-service runs remain focused unless their flags are enabled.

## Code and documentation

- Follow the [Code of Conduct](CODE_OF_CONDUCT.md).
- Use a tutorial for a first working integration, a how-to guide for a task,
  and a topic for behavior or guarantees. Define DSL reference text in the
  extension module and regenerate it with the existing Spark task.
- Keep each example's disposition marker with its code. Use the existing
  documentation examples runner for executable examples.

- Keep consumer-owned boundaries explicit: applications own migrations, Ash policies,
  secret storage, business effects, queue scheduling, and retention scheduling.
- Security changes must preserve finite resource bounds and reject unverified
  input before business processing. Review the public contracts for signature
  verification, destination checks, secret resolution, transport, tenancy,
  and delivery ownership before changing those paths.
- Record user-visible changes in `CHANGELOG.md` and set the version and publication date at release.
  Update `mix.exs`, the comparison link, and install constraints. Document required adopter
  changes to code, schema, or operations in `UPGRADING.md`.

## Bugs and security reports

Use the repository's
[issue templates](https://github.com/baselabs/ash_hooks/issues/new/choose) for bugs and
feature requests. Report vulnerabilities privately as described in
[SECURITY.md](SECURITY.md).

## Releases

A release records the package and docs served by Hex, their checksums, and the
GitHub tag and release for the source commit. Keep `.github/hex-packages.json`
in sync with the shipped files and requirements. Publication uses GitHub workload
identity through the [shared Hex action](https://github.com/baselabs/.github/tree/654fcd0ef63daf8e3f79dfeb4ca900adffd0d4e2/.github/actions/hex-publish).

### Version author

1. Choose the version under the [support policy](https://github.com/baselabs/ash_hooks/blob/main/docs/adr/0010-semver-and-support-policy.md).
   Update `@version` in `mix.exs`, the dated changelog heading and comparison
   link, and the release heading and anchor in `UPGRADING.md`. Keep any sections
   above the version's changelog heading empty.
2. Update the install constraints in the get-started tutorial and documentation
   examples test. Update the notebook's package pin and release links, and keep
   the supported release line on the
   [Compatibility page](documentation/topics/support/compatibility.md) current.
   Use `baselabs_ash_hooks-v<version>` for new release links.
3. Land the commit on `main` after the CI run on `kci/<full SHA>` passes
   `qualified`. Hand off the repository, full SHA as `release_commit`, version,
   release contents, and green CI run URL to the release maintainer.

The package job installs the locked BEAM runtime and the shared action's
pinned Hex client. The action builds the archives, verifies the package files
and requirements against `.github/hex-packages.json`, compares packaged files
with the commit, and compiles a consumer using the project's lock.

It builds HexDocs in HTML and Markdown, includes a root `release.json` with
the package, version and commit, and retains both archives with their manifest
in `hex-hexpm-ash_hooks` for seven days. Qualification checks the archives'
dash rules, the packaged documentation links, and the Livebook against the
candidate archive with a real receiver.

### Release maintainer

1. Obtain owner approval to dispatch `publish.yml` from `main`. Pass the full
   40-character lowercase `release_commit` SHA and the handoff CI run ID as
   `qualification_run`. If the run ID is omitted, upload selects the earliest
   successful CI run for that exact SHA that still retains the package
   artifact, so a repeat dispatch reuses the same archives.
2. Verify the upload result. The shared action checks the commit's ancestry,
   green `qualified` job, artifact provenance, archive bytes, stamped changelog,
   tag and registry state. For public Hex it confirms the package exists
   anonymously. The organization API-read key is used only in the protected
   upload job to check for a private release of the same application and
   version. The upload job runs Hex outside the checkout and uses a short-lived,
   package-scoped workload token for any uploads.
3. If Hex holds the release for approval, upload stops and names what needs
   approval (package and docs, or docs alone), the hex.pm staged-release page
   and Hex's approval checksum. The owner checks that checksum on the page and
   approves there. Dispatch again with the same `release_commit` and the **original**
   `qualification_run` to reuse the exact archives.
4. Wait for read-back and the published Livebook job. Read-back uses the run ID
   and qualified manifest checksum from upload, verifies the signed Hex registry
   and exact served archive bytes, and records `release-assets` with both
   archives and `SHA256SUMS`. The published Livebook job checks the versioned
   HexDocs page and runs the notebook against hex.pm with a real receiver.
5. Use the published commit from read-back to record the annotated
   `baselabs_ash_hooks-v<version>` tag and GitHub release. Attach the verified
   archives and `SHA256SUMS` and use the packaged changelog for release notes.
   Confirm the tag, GitHub release and Hex agree. Existing `v<version>` tags
   remain the release records for versions published under those tags.

If upload is interrupted or the served archives need time to propagate, reuse
the original qualification. A fresh artifact after expiration can proceed only
if it matches any archive Hex already serves. Report a retired version or an
archive mismatch to the owner before recording a release.

The [architecture decisions](https://github.com/baselabs/ash_hooks/tree/main/docs/adr)
record the package contracts and their consequences for hosts.