MainworthyDocs Open Mainworthy

Quickstart

In about ten minutes, you can start a local Mainworthy server, write a test case, and upload a failed result. Then you can answer the resulting question and see how your answer changes the gate. The gate tells you whether a commit meets the testing requirements.

If your hosted instance accepts signups, sign in through its identity provider and create an organisation and its first project. Skip to write one case and create the case in the browser.

Start a local instance #

Mainworthy needs PostgreSQL 18. The compose.yaml file starts PostgreSQL alongside the app. Other setups are outside supported use for now.

For this tutorial, install the PostgreSQL 18 binaries and start the checkout's development cluster with bun run dev. If you already have a dedicated empty PostgreSQL 18 database, set MAINWORTHY_DATABASE_URL to its URL.

The Local product layer has ended. For development, the server can still sign you in automatically when you connect from your own machine.

You need the mainworthy command. First, install Bun 1.4.4 or newer. From the source tree, run bun install, then bun run build. The executable is dist/mainworthy. Where this tutorial says mainworthy, use dist/mainworthy or add dist to your PATH. You can also use bun src/cli/main.ts without a build. See configuration.

To run the server from the source tree, use bun run start in place of mainworthy serve. It serves the same web UI as the executable. Both bun src/cli/main.ts serve and bun run dev serve the web UI as a development bundle that reloads when the code changes. The development bundle relaxes the browser's content security policy for work on Mainworthy.

This tutorial uses a fresh temporary data directory and port 7701. If that port is in use, choose another. Use the chosen port in every address below. Run the commands in a shell on your own machine.

  1. Start the server in your first terminal.

    $ export MAINWORTHY_DATA=$(mktemp -d)
    $ export MAINWORTHY_PORT=7701
    $ export MAINWORTHY_OWNER=robin
    $ bun run dev
    

    The server prints its address and data directory, followed by a line like this one. The policy, here loose, sets who answers each kind of question and which answers count.

    project "scratch" · you are robin@this-machine · policy: loose
    
  2. Open http://127.0.0.1:7701.

    The development server signs you in as the owner. Suite, the list of cases, opens empty.

  3. Keep the first terminal open.

  4. Point a second terminal at this instance.

    $ export MAINWORTHY_URL=http://127.0.0.1:7701
    

Write one case #

Create a case for a coupon test with these steps.

  1. Create coupon.txt with this outline.

    Checkout applies a percentage coupon #checkout
      Open the cart with one $100.00 item
      Apply coupon SAVE10 > Total shows $90.00
    
  2. Create the case.

    $ mainworthy new coupon.txt
    C-1
    
  3. Open Suite to see the case.

    You can also create a case with c. Write cases explains the editor and when it records a version.

Report a failure #

  1. Create results.xml with this small JUnit report.

    <testsuite name="checkout">
      <testcase name="percentage coupon @C-1@v1" classname="checkout">
        <failure message="expected $90.00, got $100.00" />
      </testcase>
    </testsuite>
    

    The test name identifies case C-1, version 1. If your case has another ID, use that ID in the test name. Use the sample commit ID in the command below. There is no Git setup for this example.

  2. Upload the report.

    $ mainworthy report results.xml --commit 1111111111111111111111111111111111111111 --branch quickstart
    mainworthy report  scratch @ 1111111  (quickstart)
      1 result   0 pass   1 fail   0 skip  (R-1)
      1 new   Q-2 "expected $90.00, got $100.00"   (1 test)
      0 results had no case or version when recorded
      basis: exact 1 result
    mainworthy gate    blocked: 1 failure unexplained, 1 question open
    

    The upload records the report and the gate shows why the commit is blocked. In the report, basis: exact means the result names the case and version it tested. Report results explains CI detection and result identity.

  3. Read the gate and its exit code.

    $ mainworthy gate --commit 1111111111111111111111111111111111111111
    mainworthy gate    blocked: 1 failure unexplained, 1 question open
      Q-2 needs an answer
    $ printf 'exit code: %s\n' "$?"
    exit code: 2
    

Answer the question #

For this exercise, answer that the test environment caused the failure. When the policy accepts your answer, Mainworthy records a decision.

  1. Open Queue with g q.

    The failure question asks why the test failed. The answer choices say what each answer does.

  2. Read the question through the CLI.

    $ mainworthy inbox --kind failure
          "q": "Q-2",
          "kind": "failure",
          "title": "expected $90.00, got $100.00",
          "evidenceHash": "7e76b294befd",
          "needs": "one member",
    

    The excerpt omits other output lines. If your question ID or evidence hash differs, use the values from your output. The hash makes your answer apply to the evidence you just read.

  3. Answer through the CLI.

    $ mainworthy decide --json '{"q":"Q-2","onEvidence":"7e76b294befd","answer":{"is":"infra"}}'
        "q": "Q-2",
        "status": "decided",
    

    The excerpt shows two lines of the returned decision. In Queue, the equivalent answer is i, "Infrastructure". That answer excuses only this build.

  4. Read the gate again.

    $ mainworthy gate --commit 1111111111111111111111111111111111111111
    mainworthy gate    passed: 1 failure excused by a decision, nothing else ran
    $ printf 'exit code: %s\n' "$?"
    exit code: 0
    

    The failed result remains recorded. The decision explains why the failure does not block the gate. You do not need a second upload. See decide and changes for answers that require a fix instead.

Stop the tutorial instance #

When you finish the exercise, stop the server in your first terminal.

  1. Press Ctrl C in the first terminal.

  2. If you no longer need the exercise, remove the temporary data directory.

    Keep the data directory if you want to return to its case and decision history.

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