Skip to content

Add a CircleCI mode to mockci: setup workflows, continuation and the cache - #41

Open
ndbroadbent wants to merge 5 commits into
mainfrom
providers/mockci-circleci
Open

ndbroadbent wants to merge 5 commits into
mainfrom
providers/mockci-circleci

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

CircleCI parity item (a): a CircleCI mode for mockci, so (b)'s setup job, plan slice and gate can be tested end to end. circleci local execute runs single jobs and skips cache steps, so until now nothing could show what CircleCI does with a setup workflow, a continuation or a cache key.

What changed

Simulator::run_circleci(&event) (or run_circleci_with(&event, parameters)) runs .circleci/config.yml at the event's commit and returns a PipelineReport: the setup workflow, the workflows that ran and their parameters. Code in crates/mockci/src/circleci/, every file under 300 lines.

  • Setup workflows: continuation/continue and finish run natively, because the orb's script posts to CircleCI's API and writes to the host's /tmp. They make the checks orb 1.0.0 makes (fetched from the orb registry): the continuation key first, then parameters as JSON or a path to a JSON file. They also refuse what the continue API refuses: a second continuation, a setup config, and parameters the continued config doesn't declare or that have the wrong type. A workflow whose when is false is left out.
  • Jobs: requires order; a job whose requirement didn't succeed is blocked and reported as skipped. Also branch only/ignore (exact names), checkout, run (/bin/bash -eo pipefail, a BASH_ENV every step sources), step when, circleci step halt, commands with parameters, when/unless steps, and << pipeline.* >> substitution. Each job gets its own home directory, with ~/project as the working directory.
  • The cache: one scope for the project (branches share it); each key matches as a prefix, newest save first; caches are immutable and expire 15 days after the save. Keys support {{ checksum }} (base64 SHA-256), .Branch, .Revision, .Environment.X and epoch.
  • Strict: unknown keys, other orbs, job parameters, contexts, regular expressions in branch filters, logic statements in when, and anything that would touch the host are errors. Touching the host means an absolute cache path or a working directory outside ~. The docker image is checked but steps run on the host.

Testing

  • tests/mockci_circleci.rs: BASH_ENV, commands, when, blocked jobs, halt, the shared cache across branches, immutability, 15-day expiry, prefix keys in order newest first, and the strictness errors. The checksum is checked against openssl dgst -sha256 -binary | base64.
  • tests/mockci_circleci_setup.rs: continuing with parameters from a file, a false workflow when, the continuation key only in the setup workflow, continuing once, finish, refused parameters, and continuing outside a setup workflow.
  • Checked that the tests can fail: with expiry set to 16 days, the 15-day test fails.
  • task ci green. MOCK_CI.md has a "CircleCI mode" section with the limits; STATUS's Tests list names the new files.

For (b)

Today's generated setup job writes to /tmp on the host (rm -rf /tmp/skip), so it can't run in mockci safely. STATUS 13 will be shown running by (b)'s scenarios, with workspace-relative paths.


Run Proof on this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…cache

CircleCI parity item (a). `circleci local execute` runs single jobs and skips
cache steps, so nothing could show what CircleCI does with a setup workflow,
a continuation or a cache key. Simulator::run_circleci runs
.circleci/config.yml at the event's commit and returns a PipelineReport.

- Setup workflows: continuation/continue and finish run natively (the orb's
  script posts to CircleCI and writes to the host's /tmp), with the orb's own
  checks and what the continue API refuses: a second continuation, a setup
  config, undeclared or mistyped parameters.
- Jobs: requires order, blocked jobs, branch filters, checkout, run with
  BASH_ENV, step when, circleci step halt, commands with parameters,
  << pipeline.* >> substitution, a home directory per job.
- The cache: one scope for the project, keys matched as prefixes newest
  first, immutable, expiring 15 days after the save; checksum, .Branch,
  .Revision, .Environment and epoch templates.
- Strict: unknown keys, other orbs and anything that would touch the host
  (absolute cache paths, working directories outside ~) are errors.

Tests: tests/mockci_circleci.rs and tests/mockci_circleci_setup.rs, with
hand-written configs. MOCK_CI.md documents the mode and its limits.
…d, a /tmp per job

From CircleCI's configuration reference:

- `requires` can name statuses: `build: failed`, `build: [success, failed]`,
  `build: terminal` (success, failed, canceled, unauthorized, not_run). A
  blocked job counts as not_run. (b)'s gate needs this to run when a job
  fails.
- "If filters stop a dependency from running, CircleCI ignores them as
  dependencies for other jobs." mockci errored instead; now it ignores them.
- restore_cache puts files back where they were saved from, so markers that
  pass between jobs with different images belong in /tmp. Each job gets its
  own /tmp, which steps reach through TMPDIR; cache paths, checksum files and
  step directories under /tmp/ resolve to it.
…gaps

1. `{{ .Environment.X }}` sees only CircleCI's own variables and the
   project's. A job's or an image's `environment:`, or an unset name, renders
   as `<no value>` on CircleCI (a constant key), so mockci refuses it instead
   of rendering a varying one. Template errors now stop the run instead of
   failing the step. A test checks generated CircleCI config uses no
   .Environment.
2, 3. Every path a config names resolves through src/circleci/paths.rs:
   cache paths, checksum files, checkout and step directories, the job's
   working_directory, and the continuation's configuration_path and
   parameters file. It refuses `..` and absolute paths outside /tmp, so
   nothing reaches a host file. tests/mockci_circleci_strict.rs probes each.
4, 5. Documented under "Not modelled yet": jobs ready together run one at
   a time and see each other's caches; the continue API's "Conflicting
   pipeline parameters" refusal.
@ndbroadbent

Copy link
Copy Markdown
Member Author

Pushed review fixes and CircleCI facts:

  • 596a3a6, from the configuration reference: requires can name statuses (build: terminal and the like; a blocked job counts as not_run), which (b)'s gate needs. A required job that the branch filters leave out is now ignored, as CircleCI documents. Each job gets its own /tmp through TMPDIR, because restore_cache puts files back at the path they were saved from.
  • 05a158f, review findings:
    • .Environment sees only CircleCI and project variables, and anything else is an error.
    • Every path goes through src/circleci/paths.rs, which refuses .. and absolute paths outside /tmp. That covers the continuation's configuration_path and parameters file.
    • Template errors stop the run.
    • Concurrency between jobs that are ready together, and the "Conflicting pipeline parameters" refusal, are listed under "Not modelled yet".
    • New tests/mockci_circleci_strict.rs. A mutation check confirmed it: with the .. check removed, two tests fail.

…filtered, host /tmp

A. A doubled slash escaped every guard: `~//etc/hosts` stripped to an
   absolute path that Path::join used as is. paths.rs refuses `//`, and
   checks that the joined path stays inside its base. The unit test lists
   `~//etc/passwd`, `/tmp//etc/passwd` and `a//b`.
B. "If filters exclude all dependencies of a job, that job doesn't execute
   either": order.rs leaves such a job out, and carries on to the jobs that
   lose all their requirements that way. A job with one requirement left
   still runs.
C. save_cache of a /tmp path that the job's /tmp lacks but the host's has is
   an error pointing at ${TMPDIR:-/tmp}, instead of a quiet "No files to
   save".
…ale host /tmp not blamed

copy_tree recursed forever on a directory symlink (walkdir reports it as not a directory, so it
called itself on the same path). It now copies symlinks as symlinks, replaces a symlink at the
destination instead of writing through it, and refuses a parent that resolves outside the
destination. The CircleCI path guard follows symlinks a step made before checking containment.
save_cache blames the host's /tmp only when that path changed after the job started.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant