# Development

How to run the tests, the local end-to-end harness and how to extend Herald. The contribution
rules are in [`CONTRIBUTING.md`](../CONTRIBUTING.md); the release steps are in
[`docs/release-checklist.md`](release-checklist.md).

## Tests

Tests run in an isolated container with no network access. They use recorded fixtures only:

```bash
docker build --target test -t herald:test .
docker run --rm --network none herald:test            # ruff check + ruff format --check + pytest
```

Locally, the same checks are:

```bash
uv sync
uv run pytest -q
uv run ruff check src tests && uv run ruff format src tests
```

## Secret scanning

No key-shaped literal is committed, not even a fake one. Tests take secrets from the
`fake_secrets` fixture in `tests/conftest.py`, generated at runtime; the only exception is the
public Standard Webhooks test vectors in `tests/fixtures/vectors/standard-webhooks.json`,
allowlisted by exact value in `.gitleaks.toml`. Three layers check it:

- `tests/test_secret_scan.py` runs the `herald-*` rules of `.gitleaks.toml` over `tests/`,
  `docs/`, `scripts/`, `site/`, the READMEs and `config.example.json`, so the Docker gate fails
  on a leak without gitleaks installed.
- The `secrets` job in `.github/workflows/ci.yml` runs a pinned, checksum-verified gitleaks
  (default rules plus ours) over the commits a push or pull request adds and over the tree. It
  does not scan the whole history, which holds three resolved false positives.
- `.pre-commit-config.yaml` runs gitleaks on staged changes before a commit and on the outgoing
  commits before a push:

```bash
uv tool install pre-commit
pre-commit install --hook-type pre-commit --hook-type pre-push
docker run --rm -v "$PWD:/repo" -w /repo zricethezav/gitleaks:v8.28.0 dir . --config .gitleaks.toml --redact -v
```

The conventions and how to triage a false positive are in
[`CONTRIBUTING.md`](../CONTRIBUTING.md#secrets-in-tests).

## End-to-end tests (local)

`scripts/e2e-local.sh <channel|all>` starts local stand-ins from
`docker-compose.e2e.yml` (Mailpit, a Conduit Matrix homeserver, a self-hosted ntfy server and
`herald dev sink` with HMAC, Standard Webhooks and bearer credentials). For each channel
(`email`, `matrix`, `ntfy`, `webhook-hmac`, `webhook-standard-webhooks`, `webhook-bearer`) it runs
`herald notify send --sample`, plus `--alert` where the channel sends alerts, with only that
notifier enabled, checks the delivery through the stand-in's API and prints PASS or FAIL. Email
goes to one subscriber per output language; webhooks also prove the sink refuses a wrong
credential. It needs Docker, `curl` and `openssl`, binds to 127.0.0.1 only, cleans up after
itself and never runs in CI.

Vendors without a self-hostable stand-in are covered in the test suite instead:
`tests/test_connector_contracts.py` runs `herald notify preview` for each of them with a long
six-language briefing and checks every request against the vendor contract in
`tests/contracts/` and its size limits. What each connector has, and the live checks that need
real accounts, are in [`docs/release-checklist.md`](release-checklist.md).

## The docs site

https://herald.day/docs/ publishes the guides in `docs/`, and https://herald.day/pt/docs/ their
Brazilian Portuguese translation in `docs/pt-BR/` (same file names). The Markdown stays the
source of truth; `scripts/build_docs.py` renders every `docs/**/*.md` to
`site/docs/<slug>/index.html` (`docs/integrations/README.md` becomes `/docs/integrations/`) and
every `docs/pt-BR/**/*.md` to `site/pt/docs/<slug>/index.html`, with the site's header, footer
and `style.css`, plus a `/docs/` index per language and the docs entries of `site/sitemap.xml`:

```bash
uv run python scripts/build_docs.py    # after any change under docs/; commit site/ with it
```

- **Renderer:** markdown-it-py (CommonMark plus tables), in the `docs` dependency group, so
  it is never installed in the runtime image. Raw HTML in the Markdown passes through.
- **Navigation:** the `NAV` list in the script sets the sidebar groups, labels and the
  previous/next order. A new guide must be added there, or the build stops and says so. The
  Portuguese labels and page chrome are in the script's `PT` language entry.
- **Translation:** a change to a guide updates its `docs/pt-BR/` copy in the same commit. The
  translation keeps the headings (same levels, same order) and every code block byte for byte;
  links between guides stay relative and use the Portuguese headings' anchors, links that leave
  `docs/` take one more `../`, and the README is `README.pt-BR.md`.
  `tests/test_docs_translation.py` fails when a guide has no translation or the pair drifts
  apart. The generated sources report stays English only: the Portuguese sidebar links the
  English page, marked "(em inglês)", as it would any guide not translated yet.
- **Links:** `configuration.md#x` becomes `/docs/configuration/#x` (`/pt/docs/configuration/#x`
  from `docs/pt-BR/`); links to other repository files go to GitHub; brand images use the
  published `/brand/` assets; other images under `docs/` are copied next to the pages. A broken
  relative link stops the build. Heading ids follow GitHub's slugs, so the same `#fragment`
  works on both.
- **Metadata:** the title is the guide's `#` heading, the description its opening paragraphs
  (shortened to 155 characters), or a `<!-- description: ... -->` comment when those do not
  summarize the guide (the integration recipes open with a status line). Each page has a
  canonical URL, hreflang alternates between a guide and its translation, Open Graph and Twitter
  tags pointing at its language's docs card (`site/og/en/docs.png` or `site/og/pt/docs.png`, made
  by `scripts/og-cards.sh` from each `/docs/` index) and BreadcrumbList JSON-LD.
- **No client JavaScript** besides `copy.js` on pages with code blocks. On small screens the
  guide list is a `<details>` menu.

The pages are committed, so the Pages workflow publishes them unchanged and IndexNow sees which
ones changed. `tests/test_docs_site.py` rebuilds them into a temporary directory and fails when
the committed output is stale; it also checks the nav, every link and anchor, and the metadata.

## Extending Herald

**New source type:** subclass `herald.sources.base.Source`, set `type`, implement
`async fetch(since) -> list[Item]`, decorate it with `@register` and add a fixture-based test.

**New notifier:** subclass `herald.notify.Notifier` and implement `async send(briefing)`.

**New AI provider:** implement `complete()` (see `herald.ai.base.LLM`) and register it in
`make_llm`.

## Release

Pushing a version tag (`v1.0.0`, `v1.1.0-beta`, ...) runs `.github/workflows/release.yml`: the
isolated tests first, then the runtime image is published to
`ghcr.io/felipebossolani/herald:<version>`, plus `:beta` for a `-beta` tag and `:latest` for a
stable version. Before tagging,
walk through [`docs/release-checklist.md`](release-checklist.md) and add the version to
[`CHANGELOG.md`](../CHANGELOG.md).
