@greerviau/titer 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +91 -108
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,147 +1,130 @@
1
1
  # titer
2
2
 
3
- Check whether a change's tests test the change: fail-on-base, diff-scoped mutation, weakened-test scan, and CRAP, as a CLI any agent can call.
3
+ titer checks whether the tests in a change actually test the change. Run it on a branch, and it compares the branch with its base:
4
4
 
5
- `titer check` gathers evidence on one question about the diff against a base ref: do the tests in this change test the change? It cannot show that the change is correct. A test that fails on base detects a difference from base, and a reviewer still checks that the difference is the intended one. titer prints a JSON report and exits with the gate's code. It never wraps the agent and contains no model. Agents call it, read the JSON, and decide what to do.
5
+ - `scan` finds weakened tests: deleted tests, removed assertions, added skips, loosened matchers, and changed snapshots.
6
+ - `prove` runs the changed tests against the base code. A test that fails on base detects the change.
7
+ - `mutate` makes small edits to the changed source lines and checks that the changed tests catch them.
8
+ - `crap` scores each changed function by complexity and coverage. It is informational.
6
9
 
7
- | Tier | What it does |
8
- |---|---|
9
- | `scan` | Finds weakened tests: deleted tests, removed assertions, added skips, loosened matchers, and changed snapshots. |
10
- | `prove` | Runs the changed tests against the base code and classifies each one. |
11
- | `mutate` | Mutates changed source lines and runs the changed tests against each mutant. |
12
- | `crap` | Scores each changed function by complexity and coverage. Informational. |
10
+ titer is a CLI that coding agents and CI jobs call. It contains no model and never wraps the agent. It prints a report and exits with a pass or fail code, and the caller decides what to do.
11
+
12
+ titer gathers evidence. It cannot show that a change is correct: a test that fails on base detects a difference from base, and a reviewer still checks that the difference is the intended one.
13
13
 
14
- titer parses Python and TypeScript/TSX (and JavaScript) with tree-sitter, and runs pytest, unittest, and vitest. It is one Rust binary for Linux and macOS.
14
+ titer supports Python, TypeScript, TSX, JavaScript, and Rust, with pytest, unittest, vitest, and cargo test. It runs on Linux and macOS.
15
15
 
16
16
  ## Install
17
17
 
18
- Install titer as a dev dependency of the repo, so every agent and CI job runs the version the repo pins:
18
+ Add titer as a dev dependency of your repo, so every agent and CI job runs the same version.
19
+
20
+ npm:
21
+
22
+ ```sh
23
+ npm install --save-dev @greerviau/titer
24
+ ```
25
+
26
+ Python with uv:
27
+
28
+ ```sh
29
+ uv add --dev titer
30
+ ```
31
+
32
+ Rust:
33
+
34
+ ```sh
35
+ cargo install titer
36
+ ```
19
37
 
20
- | Ecosystem | Install | Run |
21
- |---|---|---|
22
- | npm | `npm install --save-dev @greerviau/titer` | `npx titer check` |
23
- | Python with uv | `uv add --dev titer` | `uv run titer check` |
24
- | Rust | `cargo install titer` | `titer check` |
38
+ Each [GitHub release](https://github.com/greerviau/titer/releases) also has binaries for Linux (x64, arm64) and macOS (x64, arm64).
25
39
 
26
- Each [GitHub release](https://github.com/greerviau/titer/releases) also has binaries for Linux x64 and arm64 and macOS arm64 and x64.
40
+ ## Set up a repo
27
41
 
28
- ## Opt in
42
+ Run `init` once from the repo root:
29
43
 
30
44
  ```sh
31
- npx @greerviau/titer init # or: uvx titer init
45
+ npx titer init # npm
46
+ uv run titer init # uv
32
47
  ```
33
48
 
34
- `init` detects the repo's runners and writes four things for you to review and commit:
49
+ `init` detects your test runners and writes these files:
35
50
 
36
- - `titer.toml`, with one `[[runner]]` per project (a monorepo gets several)
37
- - a pinned dev dependency: `@greerviau/titer` in `package.json`, or `titer` in `pyproject.toml`
38
- - the repo skill in `.agents/skills/titer/SKILL.md` (Codex, Cursor, OpenCode) and `.claude/skills/titer/SKILL.md` (Claude Code)
51
+ - `titer.toml`, with one `[[runner]]` per project. A monorepo gets several. It excludes tool configs such as `vite.config.ts` from mutation, and `init` names any `scripts/` or `tools/` dir you may want to exclude too.
52
+ - A pinned dev dependency in `package.json` or `pyproject.toml`.
53
+ - A repo skill in `.agents/skills/titer/SKILL.md` and `.claude/skills/titer/SKILL.md`. It tells agents when to run titer, how to read the report, and never to weaken a test to make it pass.
39
54
 
40
- The skill tells agents when to run `check`, how to read the report, how to triage survivors, and never to weaken a test to pass. `init --dry-run` prints the plan without writing. `init --update` rewrites the skill and the pin after an upgrade; `check` warns when they are out of date.
55
+ Review the files and commit them. Run `init --dry-run` first to see the plan without writing anything.
41
56
 
42
- titer never runs in a repo without `titer.toml`: `check` exits 2 and tells the caller to run `titer init`.
57
+ titer does not run in a repo without `titer.toml`. If `init` finds no runner, write `titer.toml` by hand with the [configuration reference](docs/configuration.md).
43
58
 
44
- ## Check
59
+ After you upgrade titer, run `init --update` to refresh the skill and the pin. `check` warns when they are out of date.
60
+
61
+ ## Run a check
62
+
63
+ With your changes committed or still in the working tree, run:
45
64
 
46
65
  ```sh
47
- titer check [--base REF] [--only scan,prove,mutate,crap] [--json]
48
- [--budget 120s] [--workers N] [--mutants FILE] [--coverage FILE] [--markdown FILE]
66
+ npx titer check # npm
67
+ uv run titer check # uv
49
68
  ```
50
69
 
51
- titer snapshots the working tree, including untracked files that are not ignored, and diffs it against the merge-base of HEAD and `--base`. `--base` defaults to `base` in `titer.toml`, then to the remote default branch. Tests run in temporary worktrees under the user cache dir (`$TITER_TMPDIR` overrides it), through the repo's own command and the runner's native selection: pytest node ids, unittest dotted ids, and vitest `file:line`. The checkout's status, index, stash, and worktree list never change, and titer kills its own process groups on exit, timeout, and SIGINT.
52
-
53
- - `prove` runs the changed tests on head, then on base with head's test files copied in. Each changed test gets a verdict: `assertion` or `exception` (the test fails on base, which the gate counts as proof), `missing_symbol` (it fails on base only because a name exists only in head), `passes_on_base`, `skipped`, `no_result`, or `timeout`.
54
- - `mutate` applies one mutant at a time to changed source lines: comparison, boolean, and arithmetic swaps, bool flips, int +1, removed `not`/`!`, `return None`/`undefined`, removed calls (never logging calls), removed raise/throw, negated `if`, and JSX attributes set to undefined. The head-green changed tests run against each mutant in parallel workers; with no changed tests, the suite runs instead. A canary first checks that the worktree loads the mutated code. A mutant whose code also appears in the base lines its hunk replaces gets `unchanged_from_base: true`, because the change may only have moved or reformatted that code. Survivors get two follow-ups: a sentinel raise before the line's statement (`not_executed` when nothing runs it), and a rerun of the whole changed test files (`caught_by_other`).
55
- - `--mutants FILE` adds agent-written mutants, one JSON object per line: `{"file": "app.py", "line": 3, "end_line": 3, "replacement": " return x", "id": "optional"}`.
56
- - `crap` scores changed functions with `CRAP = comp^2 * (1 - cov)^3 + comp`, from `--coverage` (lcov, Cobertura XML, or coverage.py JSON) or `[crap] coverage_command`.
57
-
58
- ## Exit codes and the gate
59
-
60
- - 0: the gate passes.
61
- - 1: the gate fails.
62
- - 2: the check could not run: a changed test fails on head, the canary survives, a config error, or a git error.
63
-
64
- By default the gate fails only on an unproven change: the change touches supported source lines, no changed test is proven, and the selected tests kill none of its mutants. Survivors, passes on base, scan findings, and CRAP fail the gate only when `[gate]` asks.
65
-
66
- ## Configuration
67
-
68
- ```toml
69
- base = "origin/main" # optional default for --base
70
-
71
- [[runner]]
72
- name = "api" # unique; defaults to the kind
73
- kind = "unittest" # pytest, unittest, or vitest
74
- cwd = "services/api" # repo-relative; globs and paths below are relative to it
75
- command = ["uv", "run", "--no-sync", "python", "-m", "unittest"]
76
- start_dir = "tests" # unittest only: the dir dotted ids are relative to
77
- test_globs = ["**/test*.py"] # files that contain tests (defaults per kind)
78
- support_globs = ["tests/**"] # other test-only files: copied to base, never mutated
79
- deps = [".venv"] # dependency dirs linked into worktrees (defaults per kind)
80
- env = { PYTHON_DOTENV_DISABLED = "1" }
81
-
82
- [[runner]]
83
- name = "web"
84
- kind = "vitest"
85
- cwd = "clients/web"
86
- command = ["npx", "--no-install", "vitest", "run"]
87
-
88
- [gate]
89
- fail_on_survivors = false
90
- fail_on_passes_on_base = false
91
- fail_on_scan = false
92
- fail_on_crap = false
93
-
94
- [mutate]
95
- budget = "120s" # time budget for a whole check
96
- exclude_operators = [] # for example ["remove_call"]
97
- exclude_globs = [] # repo-relative source files never mutated
98
- exclude_calls = [] # callees never removed, beyond logging calls
99
-
100
- [crap]
101
- coverage_command = ["uv", "run", "--no-sync", "coverage", "json", "-o", "coverage.json"]
102
- coverage_file = "coverage.json" # written by coverage_command, relative to the repo root
103
- threshold = 30
70
+ titer compares the working tree, including untracked files, with the merge-base of HEAD and the base branch. By default the base is the remote default branch; pass `--base origin/develop` to pick another. titer runs tests in temporary worktrees and never changes your checkout.
71
+
72
+ The output starts with the gate result:
73
+
74
+ ```text
75
+ titer gate: pass
104
76
  ```
105
77
 
106
- Python commands should not sync the environment (`uv run --no-sync`), because worktrees share the checkout's `.venv`.
78
+ The exit code tells the caller what happened:
79
+
80
+ | Code | Meaning |
81
+ |---|---|
82
+ | 0 | The gate passes. |
83
+ | 1 | The gate fails. By default, this means the change is unproven: no changed test fails on base, and the tests catch none of the mutants. |
84
+ | 2 | The check could not run. Common causes are a changed test that fails on head, a config error, and a git error. |
85
+
86
+ Agents should run `titer check --json` and read the JSON report. See the [CLI reference](docs/cli.md) for all options and the report format.
107
87
 
108
- ## GitHub Action
88
+ Common options:
89
+
90
+ - `--base REF` sets the base ref.
91
+ - `--only scan,prove` runs only some tiers.
92
+ - `--budget 60s` stops starting mutants 60 s after the check starts. It does not cut short the head and base test runs, so a check can run longer.
93
+
94
+ ## Run in CI
95
+
96
+ Add the GitHub Action to a workflow that runs on pull requests:
109
97
 
110
98
  ```yaml
99
+ on: pull_request
100
+
111
101
  permissions:
112
102
  contents: read
113
103
  pull-requests: write # only for comment: true
114
104
 
115
- # One run per pull request at a time, so two runs never post at once.
116
- concurrency:
117
- group: titer-${{ github.event.pull_request.number }}
118
- cancel-in-progress: true
119
-
120
- steps:
121
- - uses: actions/checkout@v4
122
- with:
123
- fetch-depth: 0
124
- # The pull request head, so annotations land on the right diff lines.
125
- ref: ${{ github.event.pull_request.head.sha }}
126
- # Install the repo's dependencies here.
127
- - uses: greerviau/titer@v0.1
128
- with:
129
- comment: true
105
+ jobs:
106
+ titer:
107
+ runs-on: ubuntu-latest
108
+ steps:
109
+ - uses: actions/checkout@v4
110
+ with:
111
+ fetch-depth: 0
112
+ ref: ${{ github.event.pull_request.head.sha }}
113
+ # Install your repo's dependencies here.
114
+ - uses: greerviau/titer@v0.1
115
+ with:
116
+ comment: true
130
117
  ```
131
118
 
132
- The Action runs the repo's pinned titer (`npx --no-install titer` or `uv run --no-sync titer`) against the pull request's base branch and fails on exit 1 or 2. It reports in three places:
133
-
134
- - The job summary leads with the gate result (passed, failed, or could not run) and the evidence it rests on. It then lists survivors, lines no test runs, and weakened tests, with links to the pull request's head commit. A survivor whose code is unchanged from base says so. The full test and mutant tables are collapsed. The test table shows each changed test's failure on base, so a reviewer can check that the failure is the behavior the change targets.
135
- - With `annotations: true` (the default), survivors and weakened tests are warnings on their lines in the diff, and lines no test runs are notices.
136
- - With `comment: true`, the same summary is posted as a pull request comment whose heading names the commit checked. Each new head commit gets a new comment, and earlier titer comments collapse as outdated, so the newest result sits next to the newest push. A rerun on the same commit updates that commit's comment. This needs `pull-requests: write`. On pull requests from forks of a public repo, GitHub gives the token read access only, so the Action warns and skips the comment.
137
-
138
- Annotations need the pull request head checked out, as above. The default `pull_request` checkout is a merge commit whose line numbers can differ, so the Action skips annotations there.
139
-
140
- Other inputs: `base`, `args`, `working-directory`, `command`, and `github-token`. Outputs: `exit-code`, `report` (the JSON report's path), and `summary` (the Markdown's path).
119
+ The Action runs the titer version your repo pins, writes a job summary, annotates the diff, and fails the job when the gate fails. See the [GitHub Action guide](docs/github-action.md) for inputs, outputs, and how it reports.
141
120
 
142
- ## Report
121
+ ## Documentation
143
122
 
144
- `titer check --json` prints a report that follows [`schema/report.schema.json`](schema/report.schema.json): `gate`, `tests`, `mutants`, `findings`, `crap`, `warnings`, `not_analyzed`, and `timing`.
123
+ - [How titer works](docs/how-it-works.md): the tiers, test verdicts, mutation operators, and the gate.
124
+ - [Configuration](docs/configuration.md): every `titer.toml` setting.
125
+ - [CLI reference](docs/cli.md): commands, options, exit codes, agent mutants, and the JSON report.
126
+ - [GitHub Action](docs/github-action.md): inputs, outputs, job summary, annotations, and PR comments.
127
+ - [Glossary](GLOSSARY.md): the terms titer uses and what they mean.
145
128
 
146
129
  ## License
147
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greerviau/titer",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,9 +29,9 @@
29
29
  "node": ">=18"
30
30
  },
31
31
  "optionalDependencies": {
32
- "@greerviau/titer-linux-x64": "0.1.2",
33
- "@greerviau/titer-linux-arm64": "0.1.2",
34
- "@greerviau/titer-darwin-arm64": "0.1.2",
35
- "@greerviau/titer-darwin-x64": "0.1.2"
32
+ "@greerviau/titer-linux-x64": "0.1.4",
33
+ "@greerviau/titer-linux-arm64": "0.1.4",
34
+ "@greerviau/titer-darwin-arm64": "0.1.4",
35
+ "@greerviau/titer-darwin-x64": "0.1.4"
36
36
  }
37
37
  }