Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

4.0 KB
Raw Blame
import assert from 'node:assert/strict'
import { createHash } from 'node:crypto'
import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import test from 'node:test'
import { data, Evaluator, Lexer, Parser } from '@actions/expressions'
import { minimatch } from 'minimatch'
import { load } from 'js-yaml'

const root = new URL('../../../', import.meta.url)
const workflow = name => load(readFileSync(new URL('.github/workflows/' + name + '.yml', root)))
const release = workflow('mbuild-release')
const platforms = JSON.parse(readFileSync(new URL('.github/ci-config.json', root))).platforms

test('the exact Runner ID extracts alongside the checksum consumer', () => {
  const steps = release.jobs['publish-runner'].steps
  const download = steps.find(step => step.with?.['artifact-ids'])
  assert.equal(download.with['merge-multiple'], true, 'ID downloads otherwise extract to runner-linux-amd64/')
  assert.match(steps.find(step => step.id === 'built').run, /sha256sum --check --strict "\$tarball.sha256"/)
})

test('runtime packaging downloads every platform member and excludes aggregate output', () => {
  const step = workflow('package-runtime').jobs.package.steps.find(step => step.with?.pattern)
  const input = step.with.pattern
  let pattern = input
  if (input.startsWith('${{')) {
    const context = { needs: { config: { outputs: { platforms: JSON.stringify(platforms) } } } }
    const ast = new Parser(new Lexer(input.slice(3, -2)).lex().tokens, ['needs'], []).parse()
    pattern = new Evaluator(ast, JSON.parse(JSON.stringify(context), data.reviver)).evaluate().value
  }
  for (const { target } of platforms) {
    for (const group of ['runtime','cli']) assert.ok(minimatch(group + '-' + target, pattern))
  }
  assert.equal(minimatch('runtime-distribution', pattern), false, 'an old aggregate could overwrite a new platform archive')
  assert.equal(minimatch('cli-distribution', pattern), false)
})

test('a cache hit runs the wheel producer through its normal artifact upload', () => {
  const producer = workflow('build-wheels').jobs.build_wheels
  assert.equal(producer.if, undefined, 'all wheel jobs are skipped on a verified all-hit plan')
  const build = producer.steps.find(step => step.uses?.startsWith('pypa/cibuildwheel@'))
  assert.match(build.if, /steps\.cache\.outputs\.hit/)
  const upload = producer.steps.find(step => step.uses?.startsWith('actions/upload-artifact@'))
  assert.equal(upload.if, undefined, 'current-attempt wheel artifacts must exist after restore')
})

test('cached output survives removal of the original artifact and rejects changed bytes or native input', async t => {
  const producer = workflow('build-runner-binary').jobs.build
  assert.ok(producer.steps.some(step => step.id === 'cache'), 'runner has no durable build-output cache')
  const { saveFiles, restoreFiles } = await import(new URL('.github/actions/release-build-cache/files.mjs', root))
  const dir = mkdtempSync(join(tmpdir(), 'release-output-'))
  t.after(() => rmSync(dir, {recursive:true, force:true}))
  const dep = join(dir, 'sdks/go/libboxlite.a')
  mkdirSync(join(dir, 'sdks/go'), {recursive:true})
  writeFileSync(dep, 'library A')
  const name = 'boxlite-runner-v1.0.0-linux-amd64.tar.gz'
  writeFileSync(join(dir,name), 'candidate')
  writeFileSync(join(dir,name + '.sha256'), createHash('sha256').update('candidate').digest('hex') + '  ' + name)
  writeFileSync(join(dir,'producer.json'), '{"attempt":1}')
  const args = { root:dir, unit:'runner', dependency:'sdks/go/libboxlite.a' }
  const digest = await saveFiles(args)
  rmSync(join(dir,name))
  assert.ok(await restoreFiles({...args,digest}))
  assert.equal(readFileSync(join(dir,name),'utf8'), 'candidate')
  rmSync(join(dir,name))
  writeFileSync(dep, 'library B')
  assert.equal(await restoreFiles({...args,digest}), false)
  writeFileSync(dep, 'library A')
  writeFileSync(join(dir,'.release-build-cache/files',name), 'changed')
  assert.equal(await restoreFiles({...args,digest}), false)
  assert.equal(existsSync(join(dir,name)), false)
})