Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ prepush-ci hook pre-push origin

### `hook post-push`

Puts the result of the check on the pull request after a push. Claude Code runs this hook after each command of an agent, not a person: it reads the payload on standard input, and when the command was a `git push` that landed a commit with the trailer and a recorded pass of the check, it creates or updates the one comment of the check on the pull request of the branch, with the text `report --markdown` prints. In every other case it does nothing. It uses `GITHUB_TOKEN` or `GH_TOKEN` when one is set and sends no credentials otherwise, which is what a Claude Code cloud session needs. The setup skill proposes it.
Puts the result of the check on the pull request after a push. Claude Code runs this hook after each command of an agent, not a person: it reads the payload on standard input, and when the command was a `git push` that landed a commit with the trailer and a recorded pass of the check, it creates or updates the one comment of the check on the pull request of the branch, with the text `report --markdown` prints. In every other case it does nothing. The comment it writes is the short one, with no test counts or coverage, because the hook passes no result files; an agent that puts the output of `report --markdown` with `--junit` and `--coverage` into the comment then updates that same comment, and the next push writes the short text again. It uses `GITHUB_TOKEN` or `GH_TOKEN` when one is set and sends no credentials otherwise, which is what a Claude Code cloud session needs. The setup skill proposes it.

```
prepush-ci hook post-push
Expand Down Expand Up @@ -251,7 +251,7 @@ prepush-ci report --markdown --result passed|failed --tree TREE [--commit SHA] [
prepush-ci report --result passed --tree "$(git rev-parse 'HEAD^{tree}')" --junit report.xml --coverage coverage.json
```

`--markdown` posts nothing: it prints the same summary as Markdown on standard output, for a session that cannot reach the API to put into a comment on the pull request with the tools it has. It needs no token, no app, no `origin` and no network, takes the inputs of `--result`, and does not combine with `--start`. The text starts with a hidden marker `<!-- prepush-ci:NAME -->` that names the check (`NAME` is `--name`, default prepush-ci / full; a name with `--` or a line break is refused), a title line, and a line with the full sha of the commit it reports; whoever posts it finds the comment of that check by the marker and updates it.
`--markdown` posts nothing: it prints the same summary as Markdown on standard output, for a session that cannot reach the API to put into a comment on the pull request with the tools it has. It needs no token, no app, no `origin` and no network, takes the inputs of `--result`, and does not combine with `--start`. The text starts with a hidden marker `<!-- prepush-ci:NAME -->` that names the check (`NAME` is `--name`, default prepush-ci / full; a name with `--` or a line break is refused), a title line, and a line with the full sha of the commit it reports; whoever posts it finds the comment of that check by the marker and updates it. With `--junit` and `--coverage` it shows test counts and coverage from the files it is given.

**Exit status:** 0 means the result was posted (with `--markdown`, printed), 1 means it refused or failed, 2 means the parser rejected the command line.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Context

`report` reads `--junit` (JUnit XML, counted by case) and `--coverage` (the `coverage.json` of coverage.py, `totals.percent_covered_display`) and refuses a file that is missing or of another format ("Results are read from standard formats", "Input that cannot be trusted is refused"). `hook post-push` writes the comment of `report --markdown --result passed --tree <tree of HEAD>`, with no result files, and replaces the comment whose body starts with the marker ("The comment is the Markdown of report", "The comment is replaced, left alone or created"). The skill's step 8 instruction runs the same call by hand; step 9 proposes the hook.

## Verified with the tools

pytest 9.1.1 with pytest-cov 7.1.0, in a throwaway repository whose `.gitignore` holds `.prepush-ci/`:

```
$ pytest -q --junitxml=.prepush-ci/junit.xml -o junit_family=xunit1 --cov=pkg --cov-report=json:.prepush-ci/coverage.json
1 passed in 0.02s
$ git status --short # prints nothing: the files are ignored
$ prepush-ci report --markdown --result passed --tree "$(git rev-parse 'HEAD^{tree}')" --junit .prepush-ci/junit.xml --coverage .prepush-ci/coverage.json
<!-- prepush-ci:prepush-ci / full -->
### prepush-ci / full: 1 passed, 0 failed, 0 skipped
…
| Tests | 1 passed, 0 failed, 0 skipped |
```

Both options create the directory `.prepush-ci/` themselves; `node --test --test-reporter-destination=.prepush-ci/junit.xml` does not, and on a fresh checkout (the directory is ignored, never committed) it exits 7 and turns a green check red. The `junit_family=xunit1` option makes pytest write `file` and `line` on each case, which the annotations of a failed case need.

The paths are relative to the directory the command runs in, for the option and for `report` (git 2.39.5, pytest 9.1.1, prepush-ci at `72f9245`; `backend/` holds the tests, the config is committed, `.prepush-ci/` is ignored):

```
$ sh -c 'cd backend && ../.venv/bin/python -m pytest -q --junitxml=.prepush-ci/junit.xml'
1 passed in 0.01s
$ find . -name junit.xml -not -path './.venv/*'
./backend/.prepush-ci/junit.xml # not ./.prepush-ci/junit.xml
$ cd backend && prepush-ci report --markdown --result passed --tree "$(git rev-parse 'HEAD^{tree}')" --junit .prepush-ci/junit.xml
prepush-ci: cannot read .prepush-ci/junit.xml: No such file or directory # exit 1, no comment
$ cd backend && prepush-ci report … --junit "$(git rev-parse --show-toplevel)/.prepush-ci/junit.xml"
| Tests | 1 passed, 0 failed, 0 skipped |
```

`git rev-parse --show-toplevel` gives the top from any subdirectory of the worktree. The Windows form of its output (`C:/…`, in Git Bash) was not run here.

## Decisions

- **Fixed paths: `.prepush-ci/junit.xml` and `.prepush-ci/coverage.json`.** One directory is one `.gitignore` line, and nothing in the tool writes there, and a project may already use `reports/`. The pre-push hook refuses a dirty worktree, and an untracked file that is not ignored is dirty, so the ignore line is not optional when a file is written, and not wanted when none is.
- **Only what the check already has: no new dependency, no new measurement.** JUnit goes through `pytest --junitxml`, which adds the file and takes nothing from the console output (pytest prints a line that names the written file, and that is allowed). vitest, jest and `node --test` get no JUnit file: a reporter named on the command line (`--reporter=junit`, `--reporters=jest-junit`) replaces the reporters the runner chooses itself, and it chooses them from the environment (vitest 5: `minimal` under an agent, `default` otherwise, plus `github-actions` in GitHub Actions; jest 30: `agent` under an agent, `default` otherwise), so no list of reporters in the skill equals what the check ran before, and the pre-push hook (under the agent that pushes) and CI (in GitHub Actions) would both print something else; the `reporters` of a project's own configuration are replaced the same way. The skill does not guess them: it tells the user that the comment will show no counts for that check. Coverage goes in only when the check already measures it with coverage.py. Adding `--cov` to a check that has none would start measurement, and a `fail_under` in the project's coverage configuration would then fail a check that passed: a change to what the check checks. A runner that cannot write coverage.py's JSON gets a JUnit file and no coverage file; `report` reads no other coverage format and would exit 1 on one.
- **The check's own output stays.** `--cov-report=json:` replaces the default `term` report of pytest-cov, so a check with `--cov` and no `--cov-report` would lose the table of uncovered lines that an agent reads after a push; the skill adds `--cov-report=term` beside the JSON report in that case only (a `--cov-report` on the command line or in `addopts` keeps its own terminal report). A later `--junitxml` or `--cov-report=json` also beats the project's own (`addopts = --junitxml=reports/junit.xml`), so a check that already writes such a file gets no option for it: the file is left out, the user is told, and the comment shows no counts for it.
- **The options go only where the skill can show them.** Step 1 usually ends in an entry point, and options added to `scripts/ci` or `make ci` never reach the test runner. Three forms of the check: the check is a command line (a runner call or a chain), and the options go to the test command inside it, with `init` storing the changed line; the check is a `scripts/ci` the skill wrote in this run, and the options go to its test line, with `init` storing `scripts/ci` unchanged; any other entry point (the project's script, a Makefile or justfile target, a package script, a tox or nox session) gets no files and an explanation. The same holds one level down: the options go only after a direct call of the runner (`pytest`, also behind `uv run`; a call of `vitest`, `jest` or `node --test` gets no JUnit file, above); a test command that is itself an entry point (`make test`, `npm test`, `tox -e py`, in the line or in the skill's `scripts/ci`) gets no files and an explanation, since an appended `--junitxml` would not reach the runner or would be an unknown option. Rationale: the skill edits no file of the project beyond the ones it creates, and it adds the `.gitignore` line only when it writes a file, so the cases that write nothing change nothing, a `--` pass-through reaches only the last command of a package script, and a rule that says where the change goes for every project's build file cannot be tested. The agent reads the test commands inside the command line or the script to apply the several-commands rule; for the third form it need not, since it writes nothing. A follow-up can widen the third form.
- **A `cd` before the test command: no files.** The paths of the option are relative, so a test command that starts in `backend/` writes `backend/.prepush-ci/junit.xml`, where the instruction does not look, and the call fails with exit 1 and no comment. Anchoring the option (`--junitxml="$(git rev-parse --show-toplevel)/…"`) would put a shell substitution into the stored check, and the shell that runs the check differs between hosts. The skill edits only what it can show and test, as above, so a check that changes directory first gets no files and an explanation; a follow-up can anchor it. The rule is about the directory in which the test command starts: a `cd` in a subshell that ended before it does not count.
- **The instruction anchors its paths.** The agent often works in a subdirectory, and `report` reads a relative path from the current directory. `"$(git rev-parse --show-toplevel)/.prepush-ci/junit.xml"` is the same text from any directory, needs no `cd` (the shell of an agent keeps its directory between commands), and uses the command the call already uses for the tree. `report` resolving the path against the top itself would change the tool, which is out of this slice.
- **The agent asks once, with the change shown.** The user sees the changed command line, or the changed line of the script, before it is made; a "no" stores the confirmed check unchanged, leaves the script without options and drops `--junit` and `--coverage` from the step 8 call; the question comes after the check is confirmed (step 1, item 4), so no step is renumbered.
- **A pass that skipped the check shows no facts.** When the push said the check passed earlier (the hook printed that it skipped the check; "A cached pass skips the check in the hook"), the files on disk may belong to another tree, and `report` cannot tell. The instruction leaves the files out; the comment then holds the short text, which is true.
- **The hook's short comment comes first.** The hook writes it right after the push; the agent's call replaces the same comment (same marker), so a later push resets it to the short text until the agent updates it again. The instruction says so, so the agent does not read the reset as an error.
- **The README needs no spec change.** The `readme` capability checks drift, not prose. Its two new sentences are pinned elsewhere: "the post-push hook writes the short comment and the agent's call updates the same comment" by "The comment is the Markdown of report" and "The comment is replaced, left alone or created"; "`report --markdown` shows test counts and coverage from the files it is given" by "The summary is the check run's". The builder runs both sentences against the head, as `AGENTS.md` asks.

## Out of scope

Ruff and mypy files (`--ruff`, `--mypy`), config keys that name result files, and the hook reading result files itself: those are #287.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Issue: #286

## Why

The comment on the pull request is what a reviewer of an agent's work reads, and today it says only which command ran on which tree: no test count, no coverage. `report --markdown` can add both from a JUnit and a coverage file, but the instruction the setup skill writes into `CLAUDE.md` or `AGENTS.md` (step 8) uses the bare call, and the skill never makes the check write those files. So no agent ever passes them.

## What Changes

- The setup skill, after the user confirmed the check and before `init` runs, has the agent make the check write a JUnit file, and a coverage file where the runner can write coverage.py's JSON, to fixed paths under `.prepush-ci/` at the top of the worktree. It adds the options to the test command in the check's command line, or in a `scripts/ci` the skill wrote in this run; for any other entry point (a project's script, `make ci`, `npm run ci`, tox, nox) it writes no files and says why. It shows the change and asks the user first, adds the directory to `.gitignore` if needed, and never changes what the check checks: no new dependency, no new coverage measurement, no files when the check runs tests with more than one command, and no files when the test command runs in another directory than the top of the worktree (a `cd` before it), since the paths are relative.
- The instruction of step 8 passes those files to `report --markdown` (`--junit`, `--coverage`), with paths anchored at the top of the worktree so the call works from a subdirectory, and says to leave out a file the push did not write in this run.
- The instruction says that the post-push hook writes the short comment right after the push and the agent's call then updates the same comment.
- The README says the same in one sentence under `hook post-push` and one under `report`; both sentences are pinned by requirements that exist (see the design).

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `skill`: requirements for the check that writes its result files, for where the options go, for the change to the check, for what `init` stores, and for what the instruction of the documentation step passes, leaves out and says about the comment are added; nothing existing is modified.

## Impact

- `skills/prepush-ci-setup/SKILL.md` (steps 1 and 8) and `README.md`. No code of the tool, no flag, no config key, no new dependency.
Loading
Loading