Skip to content

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

2.0 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 BoxLite AI

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
import { runInNewContext } from 'node:vm'
import { load as loadYaml } from 'js-yaml'

const root = resolve(dirname(fileURLToPath(import.meta.url)), '../../..')
const workflow: any = loadYaml(readFileSync(join(root, '.github/workflows/test.yml'), 'utf8'))
const steps = workflow.jobs.go.steps

test('only named native tests get KVM after the full Go coverage pass', () => {
  const passes = steps.filter((step: any) => step.run?.includes('make coverage:go'))
  assert.equal(passes.length, 1, 'a second coverage pass rebuilds all five modules')
  const [coverage] = passes
  const qualify = steps.find((step: any) => step.run?.includes('make _ensure-kvm'))
  assert.ok(qualify && steps.indexOf(qualify) > steps.indexOf(coverage), 'the ordinary Runner tests must run before granting KVM access')
  assert.match(qualify.run, /sudo chmod a\+rw \/dev\/kvm\s+make _ensure-kvm/)
  assert.equal(qualify['continue-on-error'], undefined)
  assert.equal(coverage.run, 'make coverage:go')
  assert.match(qualify.run, /make _coverage-go-kvm/)
  assert.equal(qualify.env.BOXLITE_REQUIRE_NESTED_RUNTIME_TESTS, '1')
  assert.equal(qualify.env.BOXLITE_REQUIRE_RUNNER_SHUTDOWN_TEST, '1')
  const deferred = coverage.env.GO_COVERAGE_DEFER_KVM.replace(/^\$\{\{\s*|\s*\}\}$/g, '')
  const tags = coverage.env.GO_SDK_COVERAGE_TAGS.replace(/^\$\{\{\s*|\s*\}\}$/g, '')
  for (const target of ['linux-x64-gnu', 'linux-arm64-gnu', 'darwin-arm64']) {
    const context = { matrix: { platform: { target } } }
    assert.equal(runInNewContext(qualify.if, context), target === 'linux-x64-gnu')
    assert.equal(runInNewContext(tags, context), target === 'linux-x64-gnu' ? 'boxlite_runner,boxlite_ssh_usage_test' : 'boxlite_runner')
    assert.equal(runInNewContext(deferred, context) === '1', target === 'linux-x64-gnu')
  }
})