Metadata-Version: 2.4
Name: red-green-proof
Version: 0.1.0
Summary: A gate that answers, with evidence, whether a change causes a test to pass.
Author: ismaellnog
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/ismaellnog/red-green-proof
Project-URL: Source, https://github.com/ismaellnog/red-green-proof
Project-URL: Issues, https://github.com/ismaellnog/red-green-proof/issues
Keywords: testing,tdd,test-runner,causality,pytest,vitest,evidence,red-green
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Dynamic: license-file

# red-green-proof

An agent writes a fix, runs the test, sees green, and reports the change done. Nothing
checked that the test was ever red, that it fails for a behavioural reason, or that the fix —
rather than a test shaped to fit it — is what turned it green. `red-green-proof` answers one
question with evidence instead of assertion: is there empirical evidence that this change
causes this test to pass?

The harness runs the target and the suite in defined states, records what it observed in a
machine-readable document, and returns exactly one of three words: `proven`, `unproven`, or
`unstable`.

## A real run

The bundled `leap_year_proven` example is a leap-year check missing the Gregorian century
rule: `is_leap_year(1900)` returns `True` when it should be `False`. A committed regression
test is red at HEAD; the working-tree change adds the century correction.

```
$ python examples/leap_year_proven/run.py
$ python -m rgp test_leap.py::test_gregorian_century_rule --repo /tmp/rgp-leap-XXXXXXXX
{
  "audit": { "blocking": false, "findings": [] },
  "change": {
    "carried_files": [],
    "diff_sha256": "...",
    "source_files": [ "leap.py" ],
    "test_files": []
  },
  ⋮   (created_at, error, and the full per-gate G1-G5 detail omitted)
  "repo": {
    "branch": "master",
    "dirty": true,
    "head": "b85487653b8c52c3bd7d06f58e5c203328ffae74"
  },
  "schema": "rgp/1",
  "target": {
    "runner": "pytest",
    "runner_version": "pytest 8.4.2",
    "selector": "test_leap.py::test_gregorian_century_rule"
  },
  "verdict": "proven",
  "waiver": null
}
```

The five gate statuses from that document:

```
G1 pass  (assertion)   red at HEAD: assert True is False on the 1900 case
G2 pass  (assertion)   the red is behavioural, not a failure to collect or import
G3 pass  (none)        the target passes against the working-tree fix
G4 pass                no baseline-passing test regressed
G5 pass  (assertion)   revert leap.py, keep the test: red again -> the fix is causal
```

The output above is real (pytest 8.4.2 / Python 3.12.4 on Windows), with the per-gate detail
elided; the `--repo` path is a temp directory and changes each run. The full JSON is written
to the proof's `.rgproof/` directory.

## The five gates

All five must pass, in order; the first that does not is terminal and the verdict is
`unproven` (or `unstable` if a sampled gate's runs disagree).

- **G1 RED-EXISTS** — the target test does not pass against the baseline (HEAD).
- **G2 RED-VALID** — that failure is behavioural (an assertion or an application error), not a
  test that failed to load, import, or was skipped.
- **G3 GREEN** — the target passes against your working tree.
- **G4 NO-COLLATERAL** — no test that passed at baseline fails against the working tree.
- **G5 CAUSALITY** — with your source change reverted but your test kept, the target fails
  again, behaviourally. This is the gate that rejects a test which passes regardless of the
  change.

G1 and G5 run the target three times (`[stability].samples`); if the runs disagree the
verdict is `unstable`, never `proven`. G5 is built in an isolated `git worktree`, never by
mutating your working tree — a `stash`/`reset` that is interrupted mid-restore can lose
uncommitted work, which is exactly what this tool must not do.

## Install and first run

The harness core is standard-library Python (requires Python 3.11+; developed and tested on
3.12.4). It has no runtime dependencies of its own — it needs the test runner of the project
you point it at, and the two supported runners are `pytest` and `vitest`.

Install the `rgp` command with pipx (or pip) straight from the repository:

```
pipx install git+https://github.com/ismaellnog/red-green-proof.git
# or, into the current environment:
python -m pip install git+https://github.com/ismaellnog/red-green-proof.git
```

Then point it at a git repository whose working tree holds the change under proof:

```
rgp <selector> --repo <path-to-repo>
```

`<selector>` is a single test, e.g. `tests/test_billing.py::test_prorates_mid_cycle`. The
repository must be a git repo with a dirty working tree (the change under proof) and the
target test must exist at HEAD. Full CLI (`rgp`, or the equivalent `python -m rgp` from a
source checkout):

```
rgp [-h] [--repo REPO] [--waiver WAIVER] selector
```

To try the bundled examples from a clone instead of installing:

```
git clone https://github.com/ismaellnog/red-green-proof.git
cd red-green-proof
python -m pip install pytest        # the runner the examples use
python examples/leap_year_proven/run.py   # ends in "verdict": "proven"
```

`--waiver REASON` waives only G5 and forces `unproven` (see Configuration). A completed run
exits 0 whatever the verdict; a preflight or worktree abort (bad selector, clean tree,
unsplittable change) exits 2 with an `error` object and no gate statuses.

## What it does not do

Verbatim from `CONTRACT.md` §8:

- Generating tests. The skill judges tests; it does not write them.
- Measuring coverage. Coverage answers a different question.
- Behavioural parity for large refactors. Separate problem, separate tool.
- Proving absence of bugs. The skill proves one specific coupling, nothing wider.
- Replacing CI. The skill runs at authoring time and produces an artifact CI can check.

## Known limitations

- **Evidence is trust-on-execution, not cryptographic proof.** The `rgp/1` document records
  what the harness observed when it ran (CONTRACT §5). It is not signed, and it does not
  defend against a party who controls the harness or the machine it runs on. It replaces an
  unchecked claim with a checked observation; it does not make that observation unforgeable.

- **Only `pytest` and `vitest` are supported.** Each has an adapter backed by fixtures for all
  nine failure outcomes (`docs/adapters.md` §8-§9). `CONTRACT.md` §7 also names `jest` and
  `go test`, but those adapters are **not built**: the runners were not installable in the
  build environment, and an adapter with no fixture is not merged. Do not expect them to work.

- **ADV-001 residual — a non-empty change plus a git-ignored dependency can still confound
  G5.** G5 assumes the only difference between your working tree and its synthetic tree is the
  reverted source. That assumption is false for working-tree content git omits (git-ignored or
  untracked files): such content is present in your tree and absent in the synthetic checkout,
  and its absence is attributed to the revert. The `source_files == []` (test-only change)
  case is closed — it can never reach `proven` — but with a non-empty source change an
  attacker could, in principle, place the real dependency in a git-ignored file and let a
  trivial classified edit take the credit. Reproduction and the full write-up:
  `docs/adversarial-findings.md` (ADV-001), fixtures under
  `fixtures/adversarial/adv-001-hidden-gitignored-dep/`.

- **A blocking audit finding does not downgrade a `proven` verdict.** The static tautology
  audit runs and its findings are recorded in `audit.findings` (CONTRACT §5.1). But the
  verdict is a pure function of the gate statuses, so a target that provably passes while
  asserting nothing can still be `proven` with `audit.blocking == true`. Whether a blocking
  hollowness finding should downgrade the verdict is an open question for the contract owner
  (`docs/adversarial-findings.md`, ADV-002 handoff). Today the audit is advisory.

## Configuration

`rgp.toml` at the repository root. Every key below is optional; a repository with no `rgp.toml`
behaves as if these defaults were in effect. The file in this repository documents each key
inline.

| Key | Default | Meaning |
|---|---|---|
| `[runner].name` | `"pytest"` | The runner adapter. Supported: `"pytest"`, `"vitest"`. |
| `[runner].command` | `[]` | Explicit argv overriding the adapter's canonical invocation. |
| `[runner].timeout_seconds` | `120` | Per-invocation bound; an over-run is classified `timeout` and never satisfies G1. |
| `[patterns].test` | `["tests/**/*.py", "**/test_*.py", "**/*_test.py"]` | Globs that classify a changed file as a test (retained in G5). |
| `[patterns].source` | `["**/*.py"]` | Globs that classify a changed file as source (reverted in G5). A changed file matching neither list is a hard error — classification is never guessed. |
| `[patterns].carry` | `[]` | Non-test files carried verbatim into G5's synthetic state. Each is a hole in the guarantee and is recorded in `change.carried_files`. |
| `[scope].suite` | `"full"` | G4 suite scope. `"full"` runs the whole suite at baseline and at the working tree. |
| `[scope].select` | `[]` | When `suite` is narrowed, the globs selecting in-scope tests. Recorded in `gates.G4.collateral.scope`. |
| `[stability].samples` | `3` | Times G1 and G5 sample the target. Divergence yields `unstable`; there is no majority rule. Values below 3 are discouraged. |
| `[evidence].dir` | `".rgproof"` | Where the evidence JSON and its output sidecars are written. Git-ignored by default. |
| `[evidence].excerpt_bytes` | `4096` | Maximum size of each gate's `output_excerpt`; truncated verbatim, never summarised. |
| `[worktree].dependencies` | `"reuse"` | How G5's worktree obtains dependencies. `"reuse"` shares the primary tree's environment. |

**Waivers.** Some legitimate changes cannot satisfy G5 — a dependency bump, a
configuration-only change, a pure refactor with no behavioural delta. Pass `--waiver
"<reason>"`; the reason is recorded, G5 is written `skipped`, and the verdict is forced to
`unproven`. A waiver never masks a G1-G4 failure and never yields `proven`. Waived is a
visible state, not a pass.

## Further reading

- `CONTRACT.md` — the normative specification (gates, evidence schema, non-goals).
- `SKILL.md` — the authoring procedure: write the failing test first, observe each state.
- `docs/skill-install.md` — installing `SKILL.md` as an agent skill (Claude Code and generic).
- `docs/adapters.md` — the observed per-runner behaviour, each claim backed by a fixture.
- `docs/adversarial-findings.md` — the adversary pass and its residual findings.
- `docs/bootstrap.md` — what was accepted before the harness could prove itself.
- `SECURITY.md` — how to report a way to obtain `proven` without a real fix.
- `CONTRIBUTING.md` — the one rule: never encode an unobserved claim about a runner.

Licensed under Apache-2.0 (`LICENSE`).
