import assert from 'node:assert/strict'; import { mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import test from 'node:test'; import { buildSkillRuntime } from '../apps/detail-agent-pi/scripts/build-skill-runtime.mjs'; test('builds the locked skill image with an isolated temporary Docker context', t => { const tempDir = mkdtempSync(join(tmpdir(), 'skill-runtime-build-test-')); t.after(() => rmSync(tempDir, { recursive: true, force: true })); const calls = []; buildSkillRuntime({ tempDir }, (command, args) => { calls.push([command, args]); if (command === 'python') { assert.ok(args.includes('Pillow==12.3.0')); assert.ok(args.includes('musllinux_1_2_x86_64')); const context = args[args.indexOf('--dest') + 1]; assert.deepEqual(readdirSync(context).sort(), ['.dockerignore', 'Dockerfile']); writeFileSync(join(context, 'pillow-12.3.0-fixture.whl'), ''); } if (args.includes('build')) { assert.ok(args.includes('--pull=false')); assert.ok(args.includes('--network=none')); assert.ok(args.includes('gongxiangp2-skill-runtime:python3.13-pillow12.3.0')); assert.ok(readdirSync(args.at(-1)).includes('pillow-12.3.0-fixture.whl')); } }); assert.deepEqual(calls.map(([command]) => command), ['docker', 'python', 'docker']); assert.deepEqual(readdirSync(tempDir), []); }); test('accepts an offline wheel and clears its temporary copy when Docker fails', t => { const tempDir = mkdtempSync(join(tmpdir(), 'skill-runtime-build-test-')); t.after(() => rmSync(tempDir, { recursive: true, force: true })); const wheel = join(tempDir, 'pillow-12.3.0-fixture.whl'); writeFileSync(wheel, 'fixture'); assert.throws(() => buildSkillRuntime({ tempDir, wheel }, (command, args) => { assert.equal(command, 'docker'); if (args.includes('build')) { assert.ok(readdirSync(args.at(-1)).includes('pillow-12.3.0-fixture.whl')); throw Error('fixture build failure'); } }), /fixture build failure/); assert.deepEqual(readdirSync(tempDir), ['pillow-12.3.0-fixture.whl']); });