Files
Agent-System-Frontend/scripts/test-packages.mjs
T
weichen ad53e90a85 Consume immutable UI and contract packages in the frontend
Why: Build the application without requiring adjacent Core or UI source checkouts.

Evidence: SELF full frontend tests, isolated no-sibling package consumption, design guards and production build are recorded in the Dev dependency-workspace task card.

Impact: Pin exact provider Git revisions and package exports; preserve component behavior, visual tokens and third-party versions.

Refs: Versioned dependencies U4; Core f32d431; UI 468776e; feature/dependency-workspace
2026-10-13 15:37:20 +00:00

39 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { test } from 'node:test'
const root = dirname(dirname(fileURLToPath(import.meta.url)))
test('the application builds from packed dependencies without UI or Core source siblings', () => {
const consumer = mkdtempSync(join(tmpdir(), 'agent-frontend-packages-'))
try {
// Only the application is copied. Source checkouts and node_modules never enter the fixture.
for (const path of ['src', 'test', 'index.html', 'vite.config.ts', 'tsconfig.json', 'package.json', 'package-lock.json']) {
cpSync(join(root, path), join(consumer, path), { recursive: true })
}
const pack = (name, envName) => {
if (process.env[envName]) return resolve(process.env[envName])
const [artifact] = JSON.parse(execFileSync('npm', ['pack', '--json', '--ignore-scripts', '--pack-destination', consumer], { cwd: join(root, 'node_modules/@agent-system', name), encoding: 'utf8' }))
return join(consumer, artifact.filename)
}
const manifest = JSON.parse(readFileSync(join(consumer, 'package.json'), 'utf8'))
const contracts = `file:${pack('contracts', 'CONTRACTS_TARBALL')}`
manifest.dependencies['@agent-system/contracts'] = contracts
manifest.dependencies['@agent-system/ui'] = `file:${pack('ui', 'UI_TARBALL')}`
manifest.overrides = { ...manifest.overrides, '@agent-system/contracts': contracts }
writeFileSync(join(consumer, 'package.json'), JSON.stringify(manifest))
// Overrides exist only in this disposable fixture. Formal manifests retain fixed Git commits.
execFileSync('npm', ['install', '--ignore-scripts', '--no-audit', '--no-fund', '--offline'], { cwd: consumer, stdio: 'inherit' })
execFileSync('npm', ['run', 'build'], { cwd: consumer, stdio: 'inherit' })
assert.ok(existsSync(join(consumer, 'dist/index.html')))
const copies = execFileSync('npm', ['ls', 'react', 'react-dom', '--parseable', '--all'], { cwd: consumer, encoding: 'utf8' }).trim().split('\n').filter(path => /node_modules\/(react|react-dom)$/.test(path))
assert.equal(copies.length, 2, 'the bundle must share the host React/ReactDOM peers')
} finally {
rmSync(consumer, { recursive: true, force: true })
}
})