The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
/*
* The runner leg of `mdeploy-all.yml`, held against what the tools actually
* demand of the machine they run on.
*
* There are two legs now, and which one runs is decided by the ref. A commit
* rollout compiles the binary and stages it in the stage's bucket, and three of
* `runner:build`'s demands are invisible in its own tests: the tree has to be
* the commit being staged, its submodules have to be there, and on GCP the
* upload goes through a CLI nothing else here installs. A release rollout
* compiles nothing — `stack/runner-binary.ts` downloads the tarball the GitHub
* Release already carries — so the staging steps are skipped.
*/
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { load } from 'js-yaml'
import { actionSource, workflowSource } from './workflow-source.js'
const raw = readFileSync(new URL('../../../../.github/workflows/mdeploy-all.yml', import.meta.url), 'utf8')
const source = workflowSource('mdeploy-all.yml')
const workflow = load(raw) as any
const staging = actionSource('build-staged-runner')
.split('\n')
.filter((line) => !/^\s*#/.test(line))
.join('\n')
test('it stages the commit it was given, with the submodules that commit names', () => {
// `inspectCheckout` refuses a tree whose submodules are missing or ahead: a
// commit-keyed object that held anything else would claim bytes that commit
// does not produce, and nothing downstream could tell.
const moved = staging.indexOf('ref: ${{ inputs.sha }}')
assert.notEqual(moved, -1, 'nothing checks out the commit being staged')
assert.match(staging.slice(moved, moved + 200), /submodules: recursive/)
assert.ok(moved < staging.indexOf('runner:build'), 'the build must come from that commit')
})
test('the GCP path installs the CLI the upload goes through', () => {
// `gcpDestination` reaches Cloud Storage with `gcloud storage`, and
// `google-github-actions/auth` writes a credential without installing one.
// The failure without this is at the upload, after the build has been paid.
const install = staging.indexOf('setup-gcloud')
assert.notEqual(install, -1, 'a GCP stage cannot upload without it')
assert.ok(install < staging.indexOf('runner:build'), 'and it has to be there before the build')
assert.match(
staging.slice(staging.lastIndexOf('- name:', install), install),
/artifact-registry/,
'only the cloud that needs it',
)
})
test('staging is not retried, because neither of its failures is transient', () => {
// The destination is proved reachable before anything is compiled, so what is
// left is the build itself and a refusal about what the bucket already holds.
const start = staging.indexOf('- name: Build the runner')
assert.notEqual(start, -1, 'the step this is about is not in the workflow')
assert.doesNotMatch(staging.slice(start), /for attempt in/)
})
test('a release rollout compiles no runner at all', () => {
assert.match(
String(workflow.jobs.plan.steps.find((step: any) => step.uses === './.github/actions/build-staged-runner').if),
/steps\.plan\.outputs\.runner == 'build'/,
'the staging job runs on something other than the plan saying build',
)
const plan = source.slice(source.indexOf('- name: Decide'))
assert.match(
plan.slice(0, plan.indexOf('printf')),
/if \[ -n "\$VERSION" \]; then\n(?:[^\n]*\n)*?\s*echo "\$VERSION installs the Runner pinned by its release candidate from GHCR"/,
'the plan compiles a runner for a released version',
)
})
test('the deploy names which of the two artifacts the stack installs', () => {
// `selectRunnerBinary` defaults to `release` and reads `VERSION`, stripping
// the leading v itself. Both modes are written explicitly so the run says
// which one it is rather than leaving it to an absent variable.
const addressing = source.slice(source.indexOf('- name: Address what this deploy installs'))
assert.match(addressing, /source=release/)
assert.match(addressing, /printf 'VERSION=%s\\n' "\$VERSION"/)
assert.match(addressing, /source=build/)
assert.match(addressing, /printf 'RUNNER_ARTIFACT_REF=%s\\n' "\$SHA"/)
})
test('a run that was not about the runner never installs one this run did not stage', () => {
/*
* `plan` leaves the runner alone for `components: api`, so build mode there
* addresses `runner/<sha>/` in a bucket nothing wrote to. `runnerArtifactFor`
* composes that address without asking whether it exists, so the apply
* reports success and the host 404s at boot — the same failure the release
* gate above exists to stop, on the other line.
*
* The old shape passed `runner_ref` only when the components named the
* runner, and the workflow it called turned an empty one into release mode;
* the components test has to survive the two becoming one job.
*/
const addressing = source.slice(
source.indexOf('- name: Address what this deploy installs'),
source.indexOf('- name: Resolve the stage', source.indexOf('- name: Address what this deploy installs')),
)
assert.match(addressing, /COMPONENTS: \$\{\{ inputs\.components \}\}/, 'the step cannot see what this run was about')
assert.match(
addressing,
/case "\$COMPONENTS" in\n\s*\*runner\*\)[^\n]*source=build/,
'build mode is entered without asking whether this run staged a binary',
)
// And the plan it has to agree with: the same membership test decides
// whether anything is staged at all.
const plan = source.slice(source.indexOf('- name: Decide'))
assert.match(plan.slice(0, plan.indexOf('printf')), /case "\$COMPONENTS" in\n\s*\*runner\*\)/)
})
test('release apply forwards verified pins to the stack', () => {
assert.match(source, /registry-digests: \$\{\{ needs.resolve.outputs.registry_digests/)
assert.match(source, /BOXLITE_RELEASE_DIGESTS=%s/)
})