# Contributing Setup and commands are in the [README](README.md) and [Getting started](https://docs.protobase.net/getting-started/#commands). CI is in [docs/ci.md](docs/ci.md) and the snapshot tests in [docs/snapshot-tests.md](docs/snapshot-tests.md). The rules are here and in `AGENTS.md`. ## Commit messages Commit messages follow [Conventional Commits](https://www.conventionalcommits.org), as releases come from them: ``` feat(ui): a working global search in the top bar fix(query): report the failing statement from withStatementTimeout feat(cli)!: refuse bundles without a Protobase version ``` - `feat` releases a feature, `fix` a fix; `docs`, `test`, `refactor`, `perf`, `build`, `ci`, `style`, `chore` and `revert` release nothing on their own. - A breaking change takes `!` after type or scope, or a `BREAKING CHANGE:` footer on what to do, in a new commit; the pull request's title takes the `!`. - The subject starts in lowercase and ends without a period. The header is at most 92 characters and every body line at most 100, so the squash merge's ` (#)` suffix or `* ` list item still fits. - A `feat` commit adds something a user of Protobase can see or call, and is documented (see [Features and docs](#features-and-docs)). A change no user can see is `fix`, `perf`, `refactor` or `chore`. The `commit-msg` hook from `bun install` and CI check branch commits with `commitlint.branch.config.mjs`; the release workflow checks `main`, and `pr-title` a pull request's squash message (title, or only commit's subject, with ` (#)`), with `commitlint.config.mjs`. By hand: `bun x commitlint --config commitlint.branch.config.mjs --from `, no `--config` for `main`. `bun install` writes the protobase skill's references (`packages/cli/skills/protobase/references`) from the docs, uncommitted; the CLI's build writes them again. `bun run docs:skill` shows a docs change in them. ## Features and docs `docs/website/src/content/docs/features.md` links one page per area. Each area page under `docs/website/src/content/docs/features/` lists its features, one line each, with `## Subarea` headings where it has them: ``` - [Name](/page/#anchor) (stability): what someone gets, in one or two plain sentences. ``` The link goes to the heading that explains the feature; a feature no page explains yet has no link. A stable feature has no stability; the others say `(experimental)`, `(beta)`, `(in development)` or `(coming soon)`. A new area page goes into `features` in `docs/website/sidebar.mjs` and gets a line in `features.md`. - A feature ships with its docs: the change that adds or changes it updates its page and, for a new feature, adds its entry. - Nothing is documented that is not built, unless marked coming soon, and only while a task builds it. - Stable: built, released and complete as documented. Experimental: released to try out, with the limits its page lists, and may change in any release. Beta: released, with the limits its page lists, and may still change. In development: partly released, not usable on its own. Coming soon: documented, not built. The section a non-stable entry links starts with an aside, such as `:::caution[Beta]`, naming what is missing. Stability changes only in a change whose plan says so. - Public text names no other company or product unless compatibility with it or its own API is the subject: compatibility goes in the compatibility area, a plugin on a service's API in its feature's area. - `…` marks a known limitation, one sentence: "X cannot do Y because Z is not implemented". `bun run features:check` (in CI) checks this grammar, the headings, that area pages are in the sidebar and features page, and that every reference page has an entry. With `--release-rule`, in CI and the release workflow, it fails a release with a `feat` commit when no docs page changed since the last release. ## Doc comments and the API reference The [schema API reference](https://docs.protobase.net/api/schema/) is generated by TypeDoc from the doc comments of `packages/schema/src/index.ts`. Every export and member, such as a builder method, needs a doc comment; `bun run docs:build` fails without one or on a broken `{@link}`, and `bun run docs:api-check` runs the same check in seconds. Helpers only the `@protobase` packages use are exported from `@protobase/schema/internal`, which the reference leaves out. A doc comment links a docs page by its file from the repository root: `[Access](docs/website/src/content/docs/reference/access.mdx#capabilities)` becomes `/reference/access/#capabilities`. A missing file, page or anchor fails the build. Config: `docs/website/typedoc.json` and `typedoc-doc-pages.mjs`. ## Built-in texts The admin app's and server's own texts live in one JSON file per language and package: `packages/ui/src/locale/` and `packages/server/src/locale/`, `en.json` and `nl.json`, keyed by area (the code's folder, such as `app/delete`) and id. Each is an [ICU MessageFormat](https://unicode-org.github.io/icu/userguide/format_parse/messages/) message (`intl-messageformat`): named values (`Delete {title}?`), plurals (`{count, plural, one {# row} other {# rows}}`) and choices (`{dayFirst, select, true {…} other {…}}`). Numbers are written for the language. `{label}` lower-cases a value; a language that keeps capitals leaves the tag out. Code calls `messages('app/delete')`, then `text('confirmTitle', { title })`, or `text.rich(…)` for a React node value. Every language has each text English has and names only values English names; each package's `locale/messages.test.ts` checks both. Protobase's own views, such as those tables are made in, come from the server in English; the admin app translates them in `app/built-in-views/translated-views.ts`, keyed by resource table and text place, and its test checks the English matches the server's. ## Layout snapshots `bun run test:dom`, also in CI, builds Storybook and compares the main pages' layout (a filtered list, card list and record with actions, on desktop and phone) with `scripts/dom-snapshots/layouts`: each element's classes, role and placing CSS, with a plugin's stylesheet loaded after the app's. A change prints its lines and screenshots to `screenshots/dom/`; fix it or run `bun run test:dom:update` and commit. `bun run test:a11y` checks their accessibility tree and that text grows with the root size, so sizes use `rem`. ## Snapshot tests The database tests in `packages/*/tests/` and `tests/` replay SQL recorded from real Postgres, so `bun run test` needs no database. - A test opens its databases with `openSnapshotDb(template)` (`test-support/sql-snapshot.ts`) or a helper on it, such as `createTestDb` or `createFixtureDb`. - Commit the recordings with the change that made them, taken from CI's record job (the `sql-snapshots` artifact), not from a local run: `version()` names the CPU, so a Mac's differ. - A stale recording fails with `stale snapshot: run bun run test:record`. - Templates hold nothing Postgres makes up itself: clock times, random UUIDs, created objects' OIDs or the clone's name. - Files that replace a module, change a global or create a Better Auth instance run in the `snapshot-isolated` project. - A test that depends on timing or several connections at once (polling, real backoff, advisory locks, a statement timeout firing, `LISTEN`), or sends to SQL randomness not drawn from `crypto` (an ECDSA signature, the server's transaction ids), cannot be replayed. It is a `*.postgres.test.ts` file that opens a clone with `openPostgresDatabase(template)` (`test-support/postgres-database.ts`). Jobs a test drains with `runtime.drain` do replay. - Keep a recording under about 200 KB: read only the columns a test checks and seed only the rows it needs. Send requests one at a time for a stable recording. - A table above 30k rows needs a higher statistics target (`alter table ... alter column ... set statistics 1000`) and `autovacuum_enabled = off`. ## Releases Every push to `main` with a fix, feature or breaking change is released by `.github/workflows/release.yml`: a `v` tag and a GitHub release, without a commit to `main`. Below 1.0 a breaking change bumps the minor and a feature or fix the patch. `bun run release --dry-run` shows the next release. Its rules: [Versioning](https://docs.protobase.net/reference/versioning/). ## CI Pushes to `main` and `fm/**` run what they affect, on `CHECK_RUNNER`. Pull requests check all on GitHub's. Before 1.0 a breaking change skips the upgrade check on its pull request and on each push whose commits since the upgrade's base hold it: its `fm/**` branch, and `main` until the next release. - A test that reads a file or starts a process by path needs a rule in `scripts/affected/rules.mjs`, or a change to that file skips it. - `CHECK_BASE=main bun run check` runs what pushing the branch, uncommitted changes too, would. - The release-speed report never holds up or fails a release.