MainworthyDocs Open Mainworthy

Policy

A project's policy sets who answers each kind of question and which answers count. Compare the four built-in policies, called presets, and choose how your project handles case edits, test results, and requests to close a run.

Settings with the policy preset, the preset comparisonSettings with the policy preset, the preset comparison
Settings with the policy preset, the preset comparison

What a policy is #

A preset is a built-in policy. Each project uses one of four presets, loose, standard, strict, or ci. Each line, called a clause, says who answers one kind of question under given conditions and whether an agent's answer counts. When a clause asks nobody, the policy answers automatically as soon as the question comes up. Mainworthy records the answer as a decision.

You can change settings such as custom fields or what happens to tests with no case. The preset's clauses are fixed. To submit a proposal for a policy change, you need produce, the permission to submit edits. To accept the proposal, a person needs admin on the project. A project admin holds that permission on one project. An instance admin holds it on every project.

If you upgrade from editable policies, Mainworthy keeps policies that exactly match a preset, including the existing CI table. These projects need no confirmation. Other policies switch to strict. If one of those projects automatically created cases for tests, it now asks about them in the queue.

After that conversion, reports still arrive and projects still open. Answers and withdrawals wait for a project admin to confirm a preset. In Settings, choose Confirm strict to keep strict and the preserved settings, or choose another preset, including a looser one. From the command line, use mainworthy policy use strict. Editing a setting alone does not confirm the preset. The upgrade records a new version and keeps historical policies, including the clauses behind earlier decisions.

While Mainworthy applies a new policy to existing change runs and open questions, it can serve health requests and reads between runs and questions. Readers see the previous policy until the new policy and its decisions take effect together. Other writes wait until then.

Who answers a question under a policy. Zoom, search and follow a path in the frame, or open it full screen.

Read the policy #

Open Settings with g ,, then open Policy. The page shows the preset in force, a short summary, and "Compare the policies". An instance admin also sees the policy settings.

In the command output, rule under who answers means the policy answers automatically. The last column shows the answer it records. A row marked member asks someone with the answer capability, which lets a project member's answer count. The row marked admin asks a person who administers the project.

$ mainworthy policy show
policy: loose
kind     when                      who answers  agent's answer  blocks   automatic answer
adopt    policy                    admin        refused         nothing
adopt    always                    rule         refused         nothing  {"is":"accept"}
map      unlinked:track            rule         refused         nothing  {"is":"track"}
map      unlinked:create           rule         refused         nothing  {"is":"create"}
map      always                    member       counts          nothing
failure  hint:disputed             member       advice          all
failure  scope:change & inherited  rule         refused         change   {"is":"inherited"}
failure  scope:change              member       advice          change
failure  always                    member       advice          release
finding  answer:duplicate          member       counts          nothing
finding  always                    member       advice          nothing
signoff  verdict:passed            rule         refused         nothing  {"is":"approve"}
signoff  always                    member       refused         nothing
basis: exact-or-assumed; flaky hold: 14 days; tests with no case: track; empty reports: pending

The last line shows the project settings. A result's basis tells you which case version it applies to. The basis setting specifies what evidence can fill a slot in a planned run. With strict, the result must identify the exact version. The flaky hold is how many days a "Flaky" answer carries forward. The other two settings cover tests with no case and reports with no tests.

Custom fields #

An instance admin can define a project's fields in Settings, Policy, under Custom fields. To define a field, follow these steps:

  1. Add a field.
  2. Give the field a unique key and a label.
  3. Choose Text or Choice.
  4. For a choice, enter one allowed value per line. Values must be nonblank, unique, and fit on one line.
  5. To require a nonblank value on new cases and changed field values, mark Required.
  6. Press Save field definitions to propose and accept the change.

Mainworthy records both the proposal and the instance admin's decision. Definitions belong to the project and survive a switch of preset. Saving sends the version of the policy read by the browser. A policy change during saving causes a conflict and keeps your field draft. Review the current policy before trying again. If another edit changes the definitions while you type, choose Reload field definitions before saving. Reloading replaces your unsaved form with the current definitions.

Field values remain strings in a case's fields map. A required value cannot be missing or blank. A nonblank choice value must match an allowed value exactly. An optional field can be absent or blank. Keys without definitions remain free text. Removing a definition leaves all its values in place.

New cases and restores must meet the definitions when proposed and adopted. An edit may keep unchanged values from the current case, including missing required values and choices no longer allowed. Keeping unchanged values lets you edit an older case in the web editor without filling newly required fields. Changed field values must meet the definitions, including while a proposal waits for acceptance. A refusal leaves the case unchanged. Changing a definition never rewrites existing versions.

Required fields cannot be combined with Create a case for each test. Automatic creation has no values for those fields. Choose Ask in the queue or Track without a case first. Optional definitions work with automatic creation.

When you create or edit a case in the web app, every defined field appears below the title, including optional fields. Required fields are marked required. The editor checks values before sending a save and names invalid fields in the status line. Correct those fields and save again. Your draft stays on this device. Older cases can keep unchanged missing values or obsolete choices. Clearing an optional field removes its value. The editor keeps keys that have no definition. The demo project's Priority, Team and Risk fields are optional examples you can edit.

You can also use canonical Markdown or a propose body:

$ mainworthy propose --json '{"edits":[{"op":"edit","case":"C-1","base":1,"body":{"fields":{"risk":"high","legacy":"keep this value"}}}]}'

A supplied fields map replaces the case's map. Include every value you want to keep. Omitting fields preserves the base version's values. Use mainworthy get --json '{"refs":["C-1"],"as":"md"}' to read them. The ordinary JSON case reply includes fields. A find --in cases reply includes the project's fieldDefinitions, even when the list is empty.

To define fields through the CLI or HTTP API, start with mainworthy policy show --json. Keep its settings and add a fields map, then propose the whole settings object. Use the policy's version as base in place of 1:

$ mainworthy propose --json '{"edits":[{"op":"policy","base":1,"settings":{"unlinked":"track","emptyReports":"pending","basis":"exact-or-assumed","holds":{"flakyDays":14,"infraThisTargetOnly":true},"fields":{"risk":{"kind":"choice","label":"Risk","required":true,"choices":["low","high"]},"notes":{"kind":"text","label":"Notes","required":false}}}}]}'

A project admin can accept the proposal in Queue or with decide. Sending a settings object without fields preserves the current definitions. Send "fields": {} to remove every definition explicitly. The MCP tool listing omits field definitions to keep its token limit. To change definitions, use the CLI, HTTP API, or Settings. Archives include the policy versions, values, proposals, and decisions.

The presets #

loose is the default. Ordinary case edits take effect at once, and a test needs no case. If a failure already occurs on the base commit, the policy excuses it automatically while the evidence holds. A person answers other failures and findings. An agent can also answer that a finding is a duplicate. A run that passed closes automatically.

If two or more pull requests report the same head commit, Mainworthy checks the base of each one, including closed or merged pull requests. The policy excuses the failure only if every base fails the same way. Otherwise, a person answers. See failures already present on the base.

Under standard, an agent's edit waits for a person. A person's own edit takes effect at once. A test needs no case. If two reports disagree, someone who submitted neither report must answer.

Under strict, a person must give a reason for ordinary case edits, failures, findings, and closing a run that passed. A project starts by asking about tests with no case. You can choose to track them instead. Agent answers never count. Mainworthy does not yet offer frozen evidence, gap waivers, or a regulated preset.

Under every preset, a policy change goes to a project admin. Mainworthy checks the case version before it applies the policy. If someone has already changed the version you edited, Mainworthy refuses your edit.

The table shows who answers each kind of question. Mainworthy generates it from the presets.

PresetIn short
ciThe policy answers CI failures "needs a fix" automatically, except a result that two reports disagree on, which waits for a person. Agent edits follow standard review.
looseEdits to cases take effect at once and a test needs no case. The policy automatically excuses a failure already present on the base while its evidence holds. A person answers other failures and findings, and a run that passed closes by itself.
standardAn agent's edit waits for a person. A person's own edit still takes effect at once, and a test needs no case.
strictA person, never an agent, answers every edit, test with no case, failure, finding and passed run, and gives a reason. The project can have its tests with no case tracked instead. A policy change is handled as under the other presets. Approval by two people is not built yet.

Who answers each question:

Questionciloosestandardstrict
A person's edit to a caseAutomatic: AcceptAutomatic: AcceptAutomatic: AcceptA person, with a reason
An agent's edit to a caseA personAutomatic: AcceptA personA person, with a reason
A test with no caseAutomatic: Track without a caseAutomatic: Track without a caseAutomatic: Track without a caseA person, with a reason
A failed resultAutomatic: Defect in the productA person; agents adviseA person; agents adviseA person who did not report it, with a reason
A test already failing on the baseAutomatic: Defect in the productAutomatic: Already failing on baseA person; agents adviseA person who did not report it, with a reason
A result that two reports disagree onA person who did not report itA person; agents adviseA person who did not report itA person who did not report it, with a reason
A findingA person; agents adviseA person; agents advise. Duplicate: a person or an agentA person; agents adviseA person, with a reason
Closing a run that passedAutomatic: ApproveAutomatic: ApproveAutomatic: ApproveA person, with a reason
A change to the policyAn admin, not an agentAn admin, not an agentAn admin, not an agentAn admin, not an agent
How long a flaky answer carries forward14 days14 days14 days14 days
What fills a slot of a planned runAlso a result assumed to be for the current versionAlso a result assumed to be for the current versionAlso a result assumed to be for the current versionOnly a result that names the pinned version
An empty reportpendingpendingpendingpending

ci uses standard review for edits and disputed reports. For other failures the policy automatically records a product defect. The CI gate stays failed until a build passes.

Tests with no case #

When a pipeline reports tests without a linked case, one setting controls what happens across the project. You can change it separately from the preset.

ChoiceWhat happens
Track without a case (track)Mainworthy keeps the tests and counts their results toward the gate without asking a question. This is the default for loose and standard.
Create a case for each test (create)Mainworthy creates a case with the test's name and links the two automatically. It uses the meaningful directories in the test's path for the folder, or the file name if none remain. For example, test/e2e/docs.test.ts becomes e2e/docs.
Ask in the queue (ask)Mainworthy opens one question per file with unlinked tests. The question blocks nothing. This is the default for strict.

One report or one change to this setting can create at most 100,000 cases. If a whole file does not fit, its question stays open until the next report. If one file has more than 100,000 tests without a case, link some of them yourself first.

New cases always use the computed folder, even if you moved other cases from the same file. Changing this setting or reporting again does not move existing cases. Maintainers of this repository can use the one-off regrouping procedure after deployment.

When a report creates cases, health checks and reads can run between creation slices and files. The new cases and test links become visible together when the report applies. A concurrent save waits for that transaction.

In Settings, open Policy and choose under "Tests with no case". From the command line:

$ mainworthy policy tests create
tests with no case: create; proposal P-3 and decision 4 are both recorded; 12 open questions answered automatically

To change this setting, you need produce to propose it and admin on the project to accept it. The policy answers eligible open file questions immediately. In the example, the command reports 12 automatic answers. If a person already took a question back, it still waits for a person.

Automatic case creation follows the policy for new cases. You can choose create only where the policy automatically accepts a pipeline's new cases. Under strict, a person must accept each new case, so Mainworthy refuses create.

invalid: under this policy a person adopts every new case, so the policy cannot create cases for tests automatically: choose ask or track

With create, someone who can report results can add a case for each test name they send. A report cannot edit or remove an existing case. Under standard, an agent's new case needs a person's approval. Mainworthy creates no cases for that agent's report and leaves the file's question open.

Linking tests to a case covers only the tests you name. If the file still has unlinked tests, Mainworthy asks about them immediately. It asks again if a new test appears in the file. With create, the policy creates cases for those tests automatically. A "track" answer covers the file as it was when you answered. If the set of unlinked tests changes, Mainworthy checks again. With track, the policy answers automatically and you see no question.

Reports with no tests #

Every preset starts with emptyReports: "pending". A commit without counted evidence stays pending, even when CI says no tests are required.

If your pipeline sometimes needs no tests, such as for a docs-only change, a project admin can let it declare that explicitly.

$ mainworthy policy empty nothing-required
empty reports: nothing-required; proposal P-4 and decision 5 are both recorded

As with other policy changes, you need produce to propose this setting and admin on the project to accept it. Settings has no control for this setting. To restore the default, run mainworthy policy empty pending. Choosing any preset also restores pending, and resets the same-code detector settings to their defaults.

With this setting enabled, the pipeline sends mainworthy report --nothing-required, with the tested commit supplied or detected. The declaration stays in the report record. A human or agent token cannot send it. An empty JUnit file alone is not a declaration.

The exception passes only a commit gate with an applied declaration and no ordinary reports for that commit and repository. A skipped, blocked, refused, or agent-only report prevents the exception, in any job or environment. An empty declaration cannot hide an existing failure. It never fills a planned run's case slot or required job. Missing reports stay pending.

The setting applies to recorded declarations too. Disabling it returns an otherwise empty gate to pending. An upload receipt remains the verdict at upload time. Use mainworthy gate to read the current verdict.

The API policy edit is {"op":"policy","emptyReports":"nothing-required"}. The report is {"target":{"commit":"1111111111111111111111111111111111111111"},"results":[],"nothingRequired":true}.

Switch the policy #

To switch presets in Settings, follow these steps:

  1. Open Settings, then Policy.
  2. Choose a preset in "Preset".

If another policy change wins while you choose a preset or the tests-with-no-case setting, Settings asks you to review the current policy and choose again.

From the command line:

$ mainworthy policy use standard
policy: standard; proposal P-1 and decision 1 are both recorded

To switch, you need produce on the project to propose the change and admin on the project to accept it. A switch is a proposal, and accepting it is a decision. Both stay in the record, and you can find them in Queue under "Settled". No agent can accept one, regardless of its grant.

If you cannot accept it yourself, the proposal stays open for a project admin.

$ mainworthy policy use strict
policy proposal P-2: open Q-2 needs an admin

A project admin finds it in Queue under "Proposals". Reading full policy settings needs admin on every project. Switching needs admin only on the project being changed.

If the command attempts to accept the proposal and the server refuses, it exits 4 with the server's status and requirement. forbidden means the policy does not let you accept it, invalid means the answer needs correcting, and conflict means the evidence or decision changed. With --json, the recorded proposal and decision reply remain on stdout.

Earlier results, decisions, and cases keep their recorded history. A new policy can change who answers, when they must give a reason, and whether a declaration of no required tests passes the gate. It applies to future questions and to those already open.

Mainworthy immediately checks failures that already occurred on the base. Switching to standard ends automatic excuses for these failures. Switching back to loose restores eligible excuses without another report. If the excuses cover every failure a question was blocking, that question leaves Queue. If any still block a run, the question stays open.

The new policy automatically answers eligible open questions, including requests to close passing planned runs, pending proposals, and questions about tests with no case. With create, it also creates their cases. If a person withdrew or overrode an automatic decision, the question stays with people while the same evidence holds.

Same-code detector settings #

The same-code detector looks for a test that changes outcome on the same code. In Settings, Policy shows its current values below the preset. mainworthy policy show --json includes them in settings.flakyDetection. Every preset starts with detection enabled, a 14-day window, and a threshold of two outcome changes per test and failure signature. A file-split signature has its own count, separate from the original cause.

To change the detector settings, follow these steps:

  1. Read the current policy with mainworthy policy show --json.
  2. Change the detector values and keep the other settings as they are.
  3. Use the version you read as base in place of 1.
  4. Send the policy edit through mainworthy propose --json.
  5. Ask a project admin to accept the proposal.

This example uses the other defaults:

{"edits":[{"op":"policy","base":1,"settings":{"unlinked":"track","emptyReports":"pending","basis":"exact-or-assumed","holds":{"flakyDays":14,"infraThisTargetOnly":true},"flakyDetection":{"enabled":true,"windowDays":7,"minFlips":3}}}]}

windowDays accepts 1 to 365 days, and minFlips accepts 1 to 100. enabled: false hides current detector suggestions without deleting observations. Changing these values affects current test-detail reads and future failure-question occurrences. Existing questions keep the snapshot recorded with their evidence. Omitting flakyDetection from a whole-settings edit selects its defaults.

These settings control suggestions only. They do not change holds.flakyDays, which controls how long a person's flaky answer carries forward. Infrastructure and timeout observations have their own counts and never raise the assertion count. See report results for what a flip counts.

A quarantine excuses failures of one automated test. Its duration is independent of the flaky hold and detector thresholds. Even under loose, a person with answer must give a reason to approve the proposal. The quarantine list appears below the detector settings. See quarantine an unreliable test for entry and exit rules.

Choose a preset for a new project #

Choose the first policy when you create a project. In Settings, open Projects and pick "Initial policy" under "Create a project". The initial policy defaults to loose. You can switch later without migrating anything. Choose a preset to match your review needs:

  • Start with loose when one person or a small trusted team writes the cases, and ordinary edits should take effect at once.
  • Use standard when agents propose edits and a person should read each one first.
  • Use strict when each answer needs a person and a recorded reason, for example when someone else audits the queue.

Whether each test needs a case is a separate choice. Leave it at "Track without a case" when the cases describe what people check and the pipeline's tests stand beside them. Choose "Create a case for each test" when every test should appear in the suite. Choose "Ask in the queue" when someone links each file's tests by hand.

A policy belongs to one project. A team can run a loose scratch project and a strict release project on one instance.

See also #

Historical change gates #

When you switch policies, Mainworthy recalculates the gate for every open change, including its older commits. It also updates planned runs that use those results, even closed runs with pinned results. If an open change shares a commit with an ended change, the new policy applies to that commit.

An ended change keeps its last verdict if no open change has its commit as a head and no planned run uses it. Its verdict can therefore differ from the one today's policy would give. Mainworthy checks the current policy again in these cases.

  • If you reopen the change, Mainworthy recalculates the gate before the request returns.
  • If you start a planned run that counts the change's evidence, Mainworthy checks the ended change before importing its results.
  • If you report a merge, Mainworthy checks the run for the exact head commit before recording the merge receipt.

Each check removes excuses for failures already present on the base when the current policy no longer allows them. New reports, corrections to the base, or other changes in evidence can also change an ended change's verdict.

Ending a change stops its ordinary questions (decision 0022). Excuses for failures already present on the base still depend on the evidence from that base (decision 0042). The immediate review after a policy change described in decision 0098 now applies to open changes and to evidence that planned runs still use.

Mainworthy 0.1.0 · Licence · this page is docs/guide/policy.md in the repository