import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { readFileSync } from 'node:fs'; import path from 'node:path'; const baseline = JSON.parse( readFileSync('cloud/skills/container-provision-job/container-baseline-v1.json', 'utf8'), ); const skill = readFileSync('cloud/skills/container-provision-job/SKILL.md', 'utf8'); const provisioning = readFileSync('cloud/functions/fmode-provisioning.js', 'utf8'); const onboarding = readFileSync('cloud/functions/fmode-provisioning.js', 'utf8'); const planService = readFileSync('src/app/core/plan.service.ts', 'utf8'); assert.equal(baseline.version, '1.0.0'); assert.equal(baseline.runtime.image, 'fmode/agent-node:0.21.3'); assert.equal(baseline.runtime.memoryLimit, '1536m'); assert.equal(baseline.runtime.nanoCpus, 1_500_000_000); assert.equal(baseline.runtime.pidsLimit, 512); assert.equal(baseline.runtime.hermesHome, '/opt/data'); assert.equal(baseline.reporting.heartbeatSeconds, 3600); assert.equal(baseline.reporting.jitterMaxSeconds, 900); assert.equal(baseline.reporting.appOfflineSeconds, 80 * 60); assert.equal(baseline.cleanup.inactiveSeconds, 3600); assert.equal(baseline.cleanup.uploadedFileGraceSeconds, 3600); assert.equal(baseline.cleanup.diskPressurePercent, 80); assert.equal(baseline.cleanup.requiresAppRegistration, true); assert.equal(baseline.cleanup.contentDigest, 'sha256'); for (const skillPath of [baseline.directories.platformSkills, baseline.directories.customSkills]) { assert.ok( path.posix.relative(baseline.runtime.hermesHome, skillPath).startsWith('skills/'), `Hermes skill directory must be below HERMES_HOME/skills: ${skillPath}`, ); } for (const value of [baseline.runtime.image, '--memory 1536m --cpus 1.5 --pids-limit 512']) { assert.ok(skill.includes(value), `container skill is out of sync: ${value}`); } assert.ok(provisioning.includes("var CONTAINER_BASELINE_VERSION = '1.0.0'"), 'server baseline version must match'); assert.ok(provisioning.includes('baselineVersion: CONTAINER_BASELINE_VERSION'), 'platform job must carry the baseline version'); assert.ok(onboarding.includes('AGENT_STATUS_HEARTBEAT=3600'), 'self-managed onboarding must set the baseline heartbeat'); assert.ok(onboarding.includes('AGENT_STATUS_JITTER=900'), 'self-managed onboarding must set heartbeat jitter'); assert.ok(skill.includes('-e HERMES_HOME=/opt/data'), 'new containers must point Hermes at persistent skills'); assert.ok(skill.includes('/opt/hermes/.venv/bin/hermes skills list'), 'provisioning must inspect Hermes skills'); assert.ok(skill.includes('install -d -o 10000 -g 10000'), 'persistent task and skill directories must be writable by Hermes'); const runtimeInstall = skill.match(/install -d -o 10000 -g 10000 -m 0755 ([\s\S]*?)\n\n/)?.[1] || ''; for (const parent of baseline.directories.writableRuntimeParents) { const relative = path.posix.relative(baseline.runtime.hermesHome, parent); assert.ok(relative && !relative.startsWith('..'), 'runtime parent must stay below HERMES_HOME'); assert.ok(runtimeInstall.includes(`"$DST/${relative}"`), `runtime parent must be assigned to Hermes: ${parent}`); } assert.ok(skill.indexOf("\nFMODE_GC_INSTALL\n") < skill.indexOf('docker start "$AGENT_ID"'), 'install cleanup before starting the gateway scheduler'); for (const [file, remote] of [ ['cloud/skills/container-provision-job/patch_app_reporter.py', '/tmp/fmode-patch-app-reporter.py'], ['cloud/skills/container-provision-job/patch_process_notice.py', '/tmp/fmode-patch-process-notice.py'], ['cloud/skills/container-provision-job/patch_deliverable_ack.py', '/tmp/fmode-patch-deliverable-ack.py'], ['cloud/skills/container-provision-job/fmode-safe-gc.py', '/tmp/fmode-safe-gc.py'], ['cloud/skills/container-provision-job/fmode-safe-gc-run.py', '/tmp/fmode-safe-gc-run.py'], ]) { const digest = createHash('sha256').update(readFileSync(file)).digest('hex'); assert.ok(skill.includes(`${digest} ${remote}`), `container skill SHA256 must match ${file}`); } assert.doesNotMatch(planService, /\b(?:\d+(?:\.\d+)?\s*(?:核|GiB|GB|g)\b|CPU\s*\d)/i, 'customer-facing plan copy must not expose infrastructure sizing'); console.log('Container baseline v1.0.0 is internally consistent.');