import assert from 'node:assert/strict'; import { access, readFile } from 'node:fs/promises'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { describe, it } from 'node:test'; const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..'); const ciWorkflowPath = resolve(repoRoot, '.github', 'workflows', 'ci.yml'); async function readCiWorkflowOrSkip(testContext) { try { await access(ciWorkflowPath); } catch (error) { if (error && error.code === 'ENOENT') { testContext.skip('root CI workflow is absent from sparse klo checkout'); return null; } throw error; } return readFile(ciWorkflowPath, 'utf-8'); } describe('KLO CI artifact upload contract', () => { it('uploads verified KLO package artifacts from check-klo-subtree', async (testContext) => { const workflow = await readCiWorkflowOrSkip(testContext); if (workflow === null) { return; } assert.match( workflow, /name: Build klo package artifacts and verify public smoke\s+run: cd klo && pnpm run artifacts:build && pnpm run artifacts:verify-manifest && pnpm run artifacts:verify-demo\s+- name: Upload klo package artifacts/s, ); assert.match(workflow, /uses: actions\/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f/); assert.match(workflow, /name: klo-package-artifacts-\$\{\{ github\.sha \}\}/); assert.match(workflow, /klo\/dist\/artifacts\/manifest\.json/); assert.match(workflow, /klo\/dist\/artifacts\/npm\/\*\.tgz/); assert.match(workflow, /klo\/dist\/artifacts\/python\/\*\.whl/); assert.match(workflow, /klo\/dist\/artifacts\/python\/\*\.tar\.gz/); assert.match(workflow, /if-no-files-found: error/); assert.match(workflow, /retention-days: 7/); }); it('runs packed demo artifact smoke on Linux and macOS', async (testContext) => { const workflow = await readCiWorkflowOrSkip(testContext); if (workflow === null) { return; } assert.match(workflow, /check-klo-packed-demo:/); assert.match(workflow, /matrix:\s+os: \[ubuntu-latest, macos-latest\]/s); assert.match(workflow, /name: Download klo package artifacts/); assert.match(workflow, /path: klo\/dist\/artifacts/); assert.match(workflow, /run: cd klo && pnpm run artifacts:verify-demo/); }); it('includes packed demo artifact smoke in ci-success', async (testContext) => { const workflow = await readCiWorkflowOrSkip(testContext); if (workflow === null) { return; } assert.match( workflow, /needs: \[check-klo-subtree, check-klo-packed-demo, build-python-service, test-server, build-frontend, run-pre-commit, build-docker-images\]/, ); assert.match(workflow, /needs\.check-klo-packed-demo\.result.*== "failure"/); assert.match(workflow, /needs\.check-klo-packed-demo\.result.*== "cancelled"/); }); });