Skip to content

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

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

import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { readFileSync, writeFileSync } from 'node:fs'
import { pathToFileURL } from 'node:url'
import { linuxClients } from './release-candidate.mjs'

export function approveFailedTests(evidence, reviews, env) {
  const { GITHUB_RUN_ID, DEPLOYMENT_ATTEMPT, CANDIDATE, DIGEST, TAG, SHA, PINS, EVIDENCE_ID } = env
  for (const value of [GITHUB_RUN_ID, DEPLOYMENT_ATTEMPT, CANDIDATE, EVIDENCE_ID]) assert.match(value, /^[1-9]\d*$/)
  assert.match(DIGEST, /^sha256:[a-f0-9]{64}$/)
  for (const [key, value] of Object.entries({
    status: 'failed', run: Number(GITHUB_RUN_ID), attempt: Number(DEPLOYMENT_ATTEMPT),
    candidate: Number(CANDIDATE), digest: DIGEST, tag: TAG, sha: SHA,
  })) assert.equal(evidence[key], value, 'Failure evidence differs from deployment: ' + key)

  const pins = JSON.parse(PINS)
  assert.equal(pins.tag, TAG)
  assert.equal(pins.sha, SHA)
  assert.deepEqual(evidence.images, pins.images)
  assert.deepEqual(evidence.runner, pins.runner)
  for (const name of Object.values(linuxClients(TAG)).flat()) assert.match(evidence.clients[name], /^sha256:[a-f0-9]{64}$/)

  // Review history is run-scoped. The immutable evidence ID ties a review to this failed candidate.
  const prefix = 'waive ' + EVIDENCE_ID + ' '
  const review = reviews.find(r => r.state === 'approved' && r.user?.login &&
    r.environments?.some(e => e.name === 'release-e2e-override') &&
    r.comment?.startsWith(prefix) && r.comment.slice(prefix.length).trim())
  assert.ok(review, 'Approve release-e2e-override with the comment "' + prefix + '<reason>"')
  return { ...evidence, status: 'waived', approval: {
    reviewer: review.user.login, reason: review.comment.slice(prefix.length).trim(), evidence_id: EVIDENCE_ID,
  } }
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
  const { GITHUB_REPOSITORY, GITHUB_RUN_ID } = process.env
  const reviews = JSON.parse(execFileSync('gh', ['api', 'repos/' + GITHUB_REPOSITORY + '/actions/runs/' + GITHUB_RUN_ID + '/approvals'], { encoding: 'utf8' }))
  const evidence = JSON.parse(readFileSync('e2e-evidence/acceptance.json', 'utf8'))
  writeFileSync('acceptance.json', JSON.stringify(approveFailedTests(evidence, reviews, process.env)) + '\n')
}