How it is built
Mainworthy runs as one server process connected to PostgreSQL 18. This page explains how the server records results and decisions, and what the tests check about that design.
One app process and PostgreSQL #
An instance needs PostgreSQL 18 for structured records. The server stores attachment files in blobs/ under its data directory. The executable includes the server, web UI, command line, documentation, and the endpoint that agents use through MCP, the Model Context Protocol. compose.yaml starts the app and its database. You can run Mainworthy outside Compose, though the project does not yet support that setup.
For a write, the server locks the affected project rows and actor rows until the transaction commits.
Different projects can write at the same time. The server commits a report's acceptance before it applies the results.
Before applying them, it checks the original credential and the caller's current permissions again. If that check fails,
the server cancels the report, and the report no longer keeps runs pending. If a lock wait times out, the server returns
busy, and the caller can retry.
Reads use separate connections and read-only transactions with repeatable-read isolation. Before sending a read reply, the operation registry checks the caller's permissions again in a fresh snapshot. See the API for retries and configuration for connections.
One list of operations #
The operation registry lists the product's operations, such as propose, report, decide and gate. The HTTP routes, the OpenAPI document, the commands of mainworthy and the agent tools all come from that list. Each operation has an HTTP route and a command. The list also marks the ten operations that agents can call as tools.
The registry checks the input and the caller's permissions. A transaction that writes to a project takes the next number in that project's sequence. After a commit, the server tells listening clients what changed. Some writes use more than one transaction. A report first commits its receipt, then applies its results. API and agent tools lists the operations.
Corrections keep the earlier record #
Mainworthy keeps the history of case versions, results, and decisions. A correction adds a record that identifies what it replaces and leaves the original in the history. Automatic demo refreshes replace the demo project's history at startup.
Each project has a sequence counter. A project transaction takes the next number and records that number on each change. Clients use that number as a cursor to read subsequent changes through since.
One way to change what is current #
A decision is an answer that the policy accepts. Decisions control the current case version, test links, failure classifications, whether a run is closed, and which policy is in effect. The functions that write those changes require proof of a recorded decision. When a decision ends, dedicated functions reverse its effects. The database refuses to store a row that cites a decision absent from the record.
Each decision records who made it, the evidence they used, and the policy clause that applied. Tests check that the modules use the functions that require this proof. The verdict follows the evidence and the decisions still in effect. It can change when a decision expires. How Mainworthy works explains what this means when you use it.
What happens when a pipeline reports #
A pipeline report makes results available to the gate in these stages.
mainworthy reportreads the JUnit XML and the commit, branch and pull request from the CI environment.- The server stores the report durably before applying its results. The gate for the commit then reads
pendinguntil the server finishes applying those results. - The server applies the results in groups of 200. It answers other requests between groups.
- Mainworthy groups failures by cause. For an open change, Mainworthy asks a question about a cause unless a decision about it still applies. A planned run can also require an answer after the change ends.
- The server computes the verdict. When someone answers a failure question, the server computes the affected verdicts again in the same transaction.
What the tests check #
Tests check the boundaries between modules, which writes require proof of a decision, and the limit of ten agent tools. Gate tests check that a gate stays pending without evidence, unless the policy accepts a declaration that no tests were required. Latency tests measure how long people wait for operations.
The development static check asks PostgreSQL to parse and plan every declared SQL statement against the migrations,
then checks declared row columns and scalar types with TypeScript. Query meaning, parameter compatibility and
nullability still rely on the tests. The checker sets MAINWORTHY_SQL_SITES=1 to record where the statements are declared. The app leaves it unset during normal operation.
SQL metadata checks use the checkout or CI loopback trust server. The metadata client refuses unsupported passwords, remote hosts, and URL options. It also refuses a TLS requirement it cannot honour.