Snapshots and trends
assay keeps no history of its own. Instead, a run of assay gate or assay metrics on the whole project can write a snapshot: one line of JSON that records when and where the run was, its configuration, and what it judged or measured, as counts. Your CI keeps the snapshots, in its cache, an artifact or a branch of their own (see the recipes). Two commands read them:
assay trendshows how the project moved, in the console or as an HTML page.assay gate --compare-withadds a block “Since main (…)” to the summary of a pull request.
assay reads a snapshot only where you name it, and writes one only where you ask. A snapshot is not the baseline: the baseline is a committed record of known violations that every gate run consults; a snapshot records one run, and no verdict depends on it.
assay gate --snapshot assay-snapshots/ # a file of its own in that directoryassay gate --coverage coverage/lcov.info --duplication --snapshot build/gate.jsonassay metrics --coverage coverage/lcov.info --snapshot assay-snapshots/Writing a snapshot
Section titled “Writing a snapshot”- A directory (one that exists, or a path that ends with
/) gets a new file for each run, named so that the names sort by time: the moment, the first 12 characters of the commit (no-commitat none) and the command, as in20261126T100000Z-3f1c2ab4d5e6-gate.json. Missing directories are created. - A file is replaced whole. The text goes to
<name>.<process id>.newfirst and is then renamed, so a stopped run leaves the file as it was. A process killed between the two leaves the.newfile behind;assay trendand--compare-withpass it by, and you can delete it. - The path is absolute or relative to the package root.
- Whole project only.
gate --scope changed --snapshotandmetrics <paths> --snapshotare usage errors (exit code 2, nothing written): a record of some files would not compare with the next. - A snapshot that cannot be written ends the command with exit code 3, as a report file does: the other reports are written, and standard error gives the path, the cause and the verdict.
- The agent plugin passes no
--snapshot: nothing is recorded at turn end.
The gate record and the metrics record
Section titled “The gate record and the metrics record”The gate judges but measures no metric; metrics measures but judges nothing. So each writes its own record, and a CI job that wants both runs both on the same commit, each with --snapshot:
| Part | gate |
metrics |
|---|---|---|
| when, the commit, the versions, the package, the configuration | yes | yes |
| files judged and not judged | yes | yes (measured and not) |
| the verdict, why it fails, the gate conditions | yes | — |
| violations by tier and by rule, new and known; suppressions | yes | — |
| the baseline: its size, its growth records, the entries added since the previous commit | yes, where there is a baseline file | — |
| the code lines and the aggregates of the seven metrics | — | yes |
| the line coverage | with --coverage |
with --coverage |
| the duplicated code | with --duplication |
where duplicated_code is on |
What a record holds
Section titled “What a record holds”A record of the gate on a small test project under strict, with a condition on coverage and one on duplication (the file holds it on one line):
{"schema":"assay.snapshot/1","command":"gate","at":"2026-11-26T10:00:00Z", "commit":{"id":"31fd455ecd3bf9d5ba74325a2dbd96a9d9dfa9d4","committedAt":"2026-11-26T17:16:23Z","branch":"main"}, "versions":{"assay":"0.1.0-dev","assayLints":"0.1.0-dev"},"package":"temporary_project", "configuration":{"preset":"strict","rulesOn":147,"rules":"11a1b09f5fa52b9b","errors":0}, "files":{"judged":6,"notJudged":0}, "gate":{"verdict":"fail","failedBecause":["blocking_violation","gate_condition"], "conditions":[{"metric":"coverage","on":"overall","bound":"least","threshold":50,"value":20.0,"status":"failed"}, {"metric":"duplication","on":"overall","bound":"most","threshold":5,"value":77.4,"status":"failed"}]}, "violations":{"blocking":{"new":1,"known":2},"advisory":{"new":0,"known":8}, "byRule":[{"rule":"avoid_non_null_assertion","source":"assay","tier":"blocking","new":1,"known":2}, {"rule":"duplicated_code","source":"cross_file","tier":"advisory","new":0,"known":2}, {"rule":"no_magic_number","source":"assay","tier":"advisory","new":0,"known":6}], "suppressions":1}, "baseline":{"size":10,"growthRecords":2,"addedSincePreviousCommit":1}, "coverage":{"coverableLines":10,"coveredLines":2,"percent":20.0}, "duplication":{"codeLines":75,"duplicatedLines":58,"percent":77.4}}A record of metrics has no gate, violations or baseline. Its metrics hold the code lines measured and, for each of the seven metrics, the limit (null where none), how many values were measured, their sum, the highest, how many are over the limit, and how many of those a suppression silences.
atis the program’s clock, in UTC.commitis the checked-out commit, its committer date and its branch. It isnulloutside a repository or before the first commit; the branch isnullat a detached HEAD, as in a CI checkout of a merge request. Uncommitted changes count as their commit, and no CI variable is read.configuration.rulesOncounts assay’s rules that are on, andconfiguration.rulesis a digest of their names (the first 16 hex digits of the SHA-256 of the sorted names, each followed by a line feed): the same digest means the same rules. The SDK lints of a preset are not counted; a change of them shows as a change ofversions.assayLints.- New and known are as the baseline says; with no baseline file, all are new. Suppressed violations are not counted;
suppressionscounts the suppressions in the judged files. - Shares are stored as counts.
percentis only for display, rounded as the reports round it (coverage down, duplication up, to a tenth); comparisons use the counts. - Under a configuration error the record holds the configuration with its
errorsand, for the gate, the verdict andfailedBecause, and no counts, so a trend shows a gap, not zeros.
A record never holds a file path, a message, a line of code or a person’s name, and nothing of the judgement of a change or of a turn end.
The format is versioned like the result schema: assay.snapshot/1 may gain fields, which older readers pass by; a field removed or changed in meaning takes version 2. Its schema ships with assay_cli as lib/schema/assay_snapshot_1.schema.json, and assay version --json names the version it writes under snapshotSchemas.
Showing the trend
Section titled “Showing the trend”assay trend reads snapshots and shows how they moved: one point for each commit, a series for each measure, and the events between points. It needs no project, no configuration and no pub get, and it judges nothing. Options: assay trend.
assay trend assay-snapshots/ # every snapshot in that directoryassay trend all.jsonl assay-snapshots/ # files and directories togetherassay trend assay-snapshots/ --reporter console:build/trend.txtWhich snapshots are read
Section titled “Which snapshots are read”- A file holds one record, or one a line where its name ends with
.jsonl. A file you name is read whatever its name ends with. - A directory gives the
.jsonand.jsonlfiles directly in it, in name order. A file there that holds no snapshot at all, such as a gate result, is skipped and counted (Skipped 1 filein the head box). - One package: that of the latest snapshot. After a rename the trend follows the new name, so keep each package’s snapshots in a store of its own.
- Passed by and counted (
Passed by 3 recordsin the head box), with the reason in a boxPassed bybelow it, so that one bad record in a CI store does not hide the rest: a record of a newer version (assay.snapshot/2), a record with a missing, malformed or unknown field or a time without its zone, a.jsonlline that is no record, a file that cannot be read, and the snapshots of other packages. - Refused (exit code 2): a path that names nothing, a named pipe or device, a directory that cannot be listed, or nothing left to show. A single unreadable file gets its own message, such as
The file `result.json` holds no snapshot that this version of assay reads: it names no schema.
Points and series
Section titled “Points and series”A point is a commit: its latest gate record and its latest metrics record, merged. A job rerun on the same commit replaces them and adds no point. Points are ordered by the commit’s committer date; a record taken at no commit is a point of its own, at its own moment. Each value comes from the record that knows it, coverage and duplication from the gate where it measured them, else from metrics.
| Series | From | Counted as |
|---|---|---|
| Gate status | the gate | pass or fail |
| Blocking violations, Advisory violations | the gate | new and known together |
| Entries in the baseline | the gate | its size; a gate that judged a project without a baseline file holds none (0) |
| Suppressions | the gate | the suppressions of the judged files |
| Line coverage | the gate, else metrics |
the share, rounded down to a tenth |
| Duplicated code | the gate, else metrics |
the share, rounded up to a tenth |
| Metric over limit, for each of the six metrics a rule limits | metrics |
the values over the limit, at a point that gives the metric a limit |
| Mean cognitive complexity | metrics |
the sum over the number of functions measured, to a tenth, a half rounded up |
A point without a value leaves a gap, never a zero: a gate record holds no metrics, a gate run without --coverage no coverage. A share moves by its shown tenths: 71.0% to 74.2% is “+3.2 points”.
Events
Section titled “Events”Each event compares a point with the last earlier point that holds what it is about:
| Event | Compared between | The sentence |
|---|---|---|
| the preset changed | points taken under a configuration without errors | The preset changed: recommended -> strict. |
| the version of assay or of assay_lints changed | all points | The version of assay changed: 0.1.0 -> 0.2.0., of assay_lints, or The versions changed: … for both |
| the rules on changed: their digest differs | points taken under a configuration without errors | The rules on changed: 146 -> 147., or 147 -> 147, not all the same ones. |
| the limit of a metric changed | points with a record of metrics |
The limit of cognitive complexity changed: none -> 15. |
| the baseline grew | points where the gate judged | The baseline grew by 3 entries: 40 -> 43. |
| the gate’s verdict changed | points with a record of the gate | The gate failed (blocking_violation); it passed at 7d6e5f4. or The gate passed; it failed at 7d6e5f4. |
| a gate condition went from passed to failed, or back | points where it was judged, told by its metric, what it counts and its bound | The condition on coverage overall (at least 70%) failed; it passed at 1a2b3c4. |
The sentences are given here in the plain form; on a terminal and in the page the arrow is →. An earlier point is named by its commit’s first seven characters, or by its day. A shrinking baseline, or a share that moves without crossing a gate condition, is in the series but is no event.
The console form
Section titled “The console form”╭─ assay trend ────────────────────────────────────────────────────────────────╮│ Package my_app ││ Branch main ││ Points 3 from 2026-11-02 to 2026-11-26 ││ Snapshots 6 ││ Skipped 1 file │╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Points ─────────────────────────────────────────────────────────────────────╮│ When Commit Gate Blocking Advisory ││ ───────────────────────────────────────────── ││ 2026-11-02 1a2b3c4 pass 12 43 ││ 2026-11-15 4c3b2a1 pass 12 43 ││ 2026-11-26 9f8e7d6 fail 14 43 ││ ││ When Commit Baseline Coverage Duplicated ││ ─────────────────────────────────────────────────── ││ 2026-11-02 1a2b3c4 40 71.0% 2.6% ││ 2026-11-15 4c3b2a1 52 72.3% 2.6% ││ 2026-11-26 9f8e7d6 55 74.2% 2.6% │╰──────────────────────────────────────────────────────────────────────────────╯
╭─ From the first point to the last ───────────────────────────────────────────╮│ Measure First Last Change ││ ─────────────────────────────────────────────────────────── ││ Gate status pass fail ││ Blocking violations 12 14 +2 ││ Advisory violations 43 43 no change ││ Entries in the baseline 40 55 +15 ││ Suppressions 15 15 no change ││ Line coverage 71.0% 74.2% +3.2 points ││ Duplicated code 2.6% 2.6% no change ││ Cyclomatic complexity over limit 1 1 no change ││ Function length over limit 0 0 no change ││ Nesting depth over limit 0 0 no change ││ Parameter count over limit 0 0 no change ││ File length over limit 0 0 no change ││ Mean cognitive complexity 2.0 2.0 no change │╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Events ──────────────────────────────────────────────────────────────── 11 ─╮│ When Commit Event ││ ──────────────────────────────────────────────────────────────────────────── ││ 2026-11-15 4c3b2a1 The preset changed: recommended → strict. ││ 2026-11-15 4c3b2a1 The rules on changed: 109 → 147. ││ 2026-11-15 4c3b2a1 The limit of cyclomatic complexity changed: 15 → 10. ││ 2026-11-15 4c3b2a1 The limit of cognitive complexity changed: none → 15. ││ 2026-11-15 4c3b2a1 The limit of function length changed: 60 → 40. ││ 2026-11-15 4c3b2a1 The limit of nesting depth changed: 4 → 3. ││ 2026-11-15 4c3b2a1 The limit of parameter count changed: 6 → 4. ││ 2026-11-15 4c3b2a1 The limit of file length changed: 600 → 400. ││ 2026-11-15 4c3b2a1 The baseline grew by 12 entries: 40 → 52. ││ 2026-11-26 9f8e7d6 The baseline grew by 3 entries: 52 → 55. ││ 2026-11-26 9f8e7d6 The gate failed (blocking_violation); it passed at ││ 4c3b2a1. │╰──────────────────────────────────────────────────────────────────────────────╯The box Points holds the last 20 points, with a dash where a point has no value, and a row below them counts the earlier ones (“6 earlier points not shown”). Where the table is wider than the page, it is drawn as two tables, each with the day and the commit and half the counts, as above at 80 columns. The box “From the first point to the last” lists the series both ends hold, with how each moved. Without events the box Events says “No events”; a trend of one point says, below the boxes, that it has nothing to compare. In a file and with --color never the text is ASCII, and a report written to a file is 100 columns wide.
The page in HTML
Section titled “The page in HTML”assay trend assay-snapshots/ --reporter console --reporter html:build/assay-trend.html--reporter html:<file> writes one self-contained page, like the metric page: no server, no script, and nothing loaded from outside (its policy is default-src 'none'). It follows the system’s light or dark setting and fits a phone screen. It holds:
- the head, with the versions, preset and rules on of the last point;
- the latest value of each series and how it moved since the first point that holds it;
- a chart of each series but the gate’s verdict;
- the events;
- a table of every point with every value, so nothing rests on the charts or on colour;
- how the points are made and each series counted.
In the charts:
- Points stand side by side in order, not spaced by time, so a point is at the same place in every chart. Points unevenly spread in time look evenly spread.
- The scale runs between round numbers around the values, in steps of 1, 2 or 5 times a power of ten, never below zero.
- A gap breaks the line. Up to 50 points, each point is a dot whose title gives its day, commit and value.
- A gate condition on the whole project is a dashed line on the chart of its share. A condition on the new lines is not drawn.
- An event is a dotted line with a triangle whose title gives its sentence.
The page grows with the points: 3 points make 35 KB, 40 points 92 KB, 1,000 points 558 KB.
Output formats and exit codes
Section titled “Output formats and exit codes”--reporter console (the default), console:<file> for the plain form in a file, html:<file> for the page, and html alone for the page on standard output. The option repeats; standard output takes one report at most. A report path is absolute or relative to the current directory, and missing directories are created.
| Exit code | When |
|---|---|
| 0 | at least one snapshot was read |
| 2 | no path, a path that names nothing or no regular file or directory, a directory that cannot be listed, or no snapshot left to show |
| 3 | a report file could not be written; the others are written |
Comparing with a snapshot
Section titled “Comparing with a snapshot”--compare-with adds a block to the gate’s summary in Markdown: how the project moved since a snapshot. It is meant for the pull request job, with the snapshots the default branch’s job wrote. It works in the project judgement too.
assay gate --scope changed --base "$BASE" --coverage coverage/lcov.info --duplication \ --compare-with assay-snapshots/ --reporter console --reporter markdown:"$GITHUB_STEP_SUMMARY"- What it reads: what
assay trendreads, the project’s package only. The path is absolute or relative to the package root. - Which point: on a change with
--base <commit>, the point of that commit. The pull request jobs pass the merge-base (git merge-base HEAD "origin/$GITHUB_BASE_REF"on GitHub Actions,$CI_MERGE_REQUEST_DIFF_BASE_SHAon GitLab), so a branch is compared with where it started, not with where its target is now. Without a point of the base, it takes the latest point and says so:Since main (1eaa30c, 2026-11-26), the latest snapshot, not of this change's base. The project judgement and other changes compare with the latest point. A run is never compared with itself: the snapshots are read before its own--snapshotis written. - Never a verdict: the store never changes the gate’s verdict or exit code. Records it cannot use are passed by, as in a trend, such as those of a newer version when the default branch has upgraded assay and a pull request still pins the older one. Where no snapshot of the package is found, standard error and the summary’s notes say
No earlier snapshot was found at <path>., with what was passed by (It passed by 40 snapshots of the package `my_app` and 1 snapshot of a newer version (`assay.snapshot/2`), which a later version of assay reads.). The summary then has no comparison block, and the gate judges as without the option. - The one usage error is an empty path (
--compare-with=): exit code 2, nothing judged.
The block stands after the gate conditions:
### Since main (3f1c2ab, 2026-11-20)
| Measure | Then | Now | Change ||:--|--:|--:|--:|| Entries in the baseline | 52 | 40 | -12 || Line coverage | 72.3% | 68.0% | -4.3 points || Duplicated code | 2.6% | 5.7% | +3.1 points |
- The rules on changed: 146 → 147.- The condition on coverage overall (at least 70%) failed; it passed at 3f1c2ab.- The heading names the point by branch, commit and day:
Since 3f1c2ab (2026-11-20)without a branch,Since the snapshot of 2026-11-20without a commit. - The rows are the measures both sides hold, worded as in the trend; where they hold none in common, the block says so. On a change they are only the whole-project ones, the entries in the baseline, line coverage and duplicated code: a change’s violations are those of its changed files, which do not compare with a snapshot of the whole project. The project judgement adds the violations and suppressions. Line coverage and duplicated code need
--coverageand--duplication. Metrics never appear: the gate measures none. - The events are the trend’s, with a gate condition on the whole project only. A metric’s limit is never one, and a change of verdict is one only in the project judgement.
- Only the summary changes; every other report is the same as without the option. The agent plugin never passes
--compare-with.
Keeping the snapshots in CI
Section titled “Keeping the snapshots in CI”Your CI keeps the snapshots from one run to the next. Every recipe below keeps them in assay-snapshots/ at the package root and works the same way:
-
Before the gate, the default branch’s job restores earlier snapshots into
assay-snapshots/. The first time there are none, and--snapshotcreates the directory. -
After the tests, it records the gate and the metrics, writes the trend, and uploads the trend’s page as an artifact:
Terminal window dart test --coverage-path=coverage/lcov.info # or: flutter test --coverageassay gate --coverage coverage/lcov.info --duplication --snapshot assay-snapshots/ --reporter console --reporter githubassay metrics --coverage coverage/lcov.info --snapshot assay-snapshots/assay trend assay-snapshots/ --reporter console --reporter html:build/assay-trend.html -
The steps after the gate run even when it fails, so a failed gate is recorded. On GitHub Actions, use
if: ${{ !cancelled() }}: a condition that starts with!must be inside${{ }}or quotes. On GitLab and elsewhere, keep the gate’s exit code and end the script with it. -
It keeps the directory for the next run. Each record is a file of its own, so nothing needs merging. Deleting the oldest files shortens the trend.
-
The pull request job restores the same snapshots and passes
--compare-with assay-snapshots/. It keeps nothing. Where it finds none, its summary says so and nothing fails.
For a project below the repository root, run the commands in its directory (defaults.run.working-directory on GitHub Actions, cd on GitLab) and put that directory before the paths of the platform’s own steps, such as the path of a cache.
| Store | CI | Its limit |
|---|---|---|
| The cache | GitHub Actions | An entry that no run reads for 7 days is removed (a setting of the repository, 7 days unless changed), and the caches of a repository are capped (10 GB unless changed). A removed entry takes every snapshot with it. |
| An artifact | GitHub Actions | Removed after the retention period, 90 days unless changed, counted from the last run on the default branch. The jobs need actions: read. |
| A branch of their own | GitHub Actions | The job needs contents: write, and the branch must take its pushes. It grows by a commit a run. |
| The cache, then an artifact | GitLab CI | A cache is not guaranteed, and stays on its runner unless the runner has a distributed cache. |
| A branch of their own | GitLab CI | A push with the job’s token needs GitLab 18.4 and a project setting; else a project access token (Premium or Ultimate on GitLab.com). |
| A shared directory | any | The storage the runs share. |
Every store keeps the records of a failed gate (on GitLab, in the cache).
GitHub Actions: the cache
Section titled “GitHub Actions: the cache”The GitHub Actions pipeline uses the cache. The job gate restores it before the tests and saves it after the trend, on the default branch only; the job pull-request only restores it.
- A new entry each run. A cache entry cannot change, so each run saves a new one under a key of its run and attempt. The restore then takes the newest entry that matches
restore-keys: the latest run on the default branch. - What a pull request sees. A run restores the caches of its own branch, of the default branch and, for a pull request, of its base branch, also from a fork. What a pull request saves is seen only by its own reruns, so no pull request changes what the default branch reads.
- One run at a time.
concurrencyon the jobgatekeeps two default-branch runs from each saving an entry that lacks the other’s record. GitHub cancels a waiting run when a newer one comes; the cancelled commit gets no point.
GitHub Actions: an artifact
Section titled “GitHub Actions: an artifact”Replace the steps “The snapshots so far” and “Keep the snapshots” of the job gate with these two. In the job pull-request, the first one replaces “The snapshots of the default branch”, without its if. Both jobs need actions: read in their permissions.
- name: The snapshots so far if: github.ref == 'refs/heads/main' # in the job pull-request: no condition env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | for run in $(gh run list --workflow assay.yaml --branch main --event push --status completed --limit 20 --json databaseId --jq '.[].databaseId'); do if gh run download "$run" --name assay-snapshots --dir assay-snapshots; then break; fi done # … the tests, the gate, the metrics and the trend … - name: Keep the snapshots if: ${{ !cancelled() && github.ref == 'refs/heads/main' }} uses: actions/upload-artifact@v7 with: name: assay-snapshots path: assay-snapshots/ overwrite: true- The loop downloads the artifact of the newest completed push run on
mainthat has one, 20 runs back at most. A failed gate’s run has one; a cancelled run is skipped. The first run finds none and goes on. - The GitHub CLI is installed on GitHub’s runners and reads the job’s token from
GH_TOKEN. A fork’s read-only token is enough, since the step only reads. - An artifact lasts 90 days unless the repository or its owner sets another period (1 to 90 days in a public repository, up to 400 in a private one). Each run uploads the whole directory again, so the snapshots are lost only after that long without a run on the default branch.
overwrite: truelets a rerun’s attempt replace the artifact of the same name. The trend’s page is a separate artifact,assay-trend.
GitHub Actions: a branch of their own
Section titled “GitHub Actions: a branch of their own”The records are committed to a branch assay-snapshots that holds nothing else. In the job gate, replace the two cache steps with these, and give it contents: write:
- name: The snapshots so far if: github.ref == 'refs/heads/main' run: | if git fetch origin assay-snapshots; then git worktree add --detach assay-snapshots FETCH_HEAD else git worktree add --detach assay-snapshots git -C assay-snapshots switch --orphan assay-snapshots fi # … the tests, the gate, the metrics and the trend … - name: Keep the snapshots if: ${{ !cancelled() && github.ref == 'refs/heads/main' }} run: | cd assay-snapshots git add . git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" commit --quiet --message "assay snapshots of $GITHUB_SHA" git push origin HEAD:refs/heads/assay-snapshotsIn the job pull-request, the step “The snapshots of the default branch” only fetches: run: if git fetch origin assay-snapshots; then git worktree add --detach assay-snapshots FETCH_HEAD; fi.
- The first run creates the branch with no history in common with the code. Each later run checks it out as a worktree in
assay-snapshots/, commits the new files and pushes. It is never merged, and the records last as long as the branch. - It works from the shallow checkout of
actions/checkout, with the credentials that action keeps. A push with the job’s token starts no workflow run. - Only the default branch pushes, so a fork’s read-only token is enough for the pull request. A repository rule that protects every branch must let the job push to
assay-snapshots. concurrencykeeps two runs from pushing at once. A push that is not a fast-forward fails its step, and only that run’s records are lost.
GitLab CI
Section titled “GitLab CI”The GitLab pipeline keeps the snapshots in the cache of the job assay, and passes them to merge requests as an artifact.
- The cache is saved even when the script fails (
cache:when: always). Its key names the branch (assay-snapshots-$CI_COMMIT_REF_SLUG), so each branch keeps a chain of its own. GitLab keeps protected branches’ caches apart by default (their keys get the suffix-protected). - The artifact holds the directory and the trend’s page, also when the job fails (
artifacts:when: always). Where the cache gave no directory, the job downloads the default branch’s artifact through the jobs API with its own token. The jobassay-merge-requestcannot read the default branch’s cache, so it always downloads it.- The API gives the latest successful pipeline’s artifact.
search_recent_successful_pipelines=truelooks through up to 100 of them for one that ran the job: GitLab 18.7 and later, without a feature flag from 18.10. Drop it on an older GitLab. - Where none ran the job,
curlreports the error 404 and the job goes on without snapshots.
- The API gives the latest successful pipeline’s artifact.
- Limits. Runners that share no cache keep a chain each: pin the job to one runner by its tags, or use a branch. When the cache is lost, the chain goes on from the latest successful pipeline’s artifact, and the records of pipelines that failed after it are lost. By default GitLab keeps the artifacts of each branch’s latest pipeline and latest successful one, whatever
expire_insays; the others expire after the instance’s default (30 days on GitLab.com). - No branch name. GitLab checks out the commit, so its records name no branch, and a merge request’s block reads
Since 3f1c2ab (2026-11-20). To record it, check out the branch first, in a job that runs for branches only:git checkout -B "$CI_COMMIT_BRANCH". - Forks. A merge request from a fork runs in the fork by default, and compares with the snapshots of the fork’s default branch.
GitLab CI: a branch of their own
Section titled “GitLab CI: a branch of their own”The records go to a branch assay-snapshots, as on GitHub Actions. In the job assay, drop the cache and the download line. Open the branch before the tests and commit after the trend:
if git fetch origin assay-snapshots; then git worktree add --detach assay-snapshots FETCH_HEAD; else git worktree add --detach assay-snapshots && git -C assay-snapshots switch --orphan assay-snapshots; fi# … the tests, the gate, the metrics and the trend …if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then git -C assay-snapshots add . git -C assay-snapshots -c user.name="$GITLAB_USER_NAME" -c user.email="$GITLAB_USER_EMAIL" commit --quiet --message "assay snapshots of $CI_COMMIT_SHA" git -C assay-snapshots push "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" HEAD:refs/heads/assay-snapshotsfiIn the job assay-merge-request, replace the download line with if git fetch origin assay-snapshots; then git worktree add --detach assay-snapshots FETCH_HEAD; fi. The snapshots branch needs no GIT_DEPTH: 0: it shares no commit with the code and is fetched whole.
-
The job’s token can push from GitLab 18.4, once a maintainer turns on “Allow Git push requests to the repository” under Settings, CI/CD, Job token permissions (off by default). The token has the permissions of the user who started the job, and its push starts no pipeline.
-
Otherwise, a project access token with the scope
write_repositoryand a role that may push to the branch, in a masked CI/CD variable such asASSAY_SNAPSHOTS_TOKEN. On GitLab.com it needs Premium or Ultimate, and it expires (in 365 days unless set). Push with-o ci.skip, or the push starts a pipeline:Terminal window git -C assay-snapshots push -o ci.skip "https://assay:${ASSAY_SNAPSHOTS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" HEAD:refs/heads/assay-snapshots
Other CI systems
Section titled “Other CI systems”Use a directory on storage that all runs share, one directory a package. The script is the one on Other CI systems, with SNAPSHOTS set to that directory; the pull request job passes --compare-with "$SNAPSHOTS".
To keep one .jsonl file instead, write each record to a file of the run and append it, since --snapshot replaces a file and never appends. For the gate, and metrics the same way:
assay gate --coverage coverage/lcov.info --duplication --snapshot build/assay-gate.json --reporter console || verdict=$?cat build/assay-gate.json >> /srv/ci/assay-snapshots/my_app.jsonl