verify-container-baseline.mjs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import assert from 'node:assert/strict';
  2. import { createHash } from 'node:crypto';
  3. import { readFileSync } from 'node:fs';
  4. import path from 'node:path';
  5. const baseline = JSON.parse(
  6. readFileSync('cloud/skills/container-provision-job/container-baseline-v1.json', 'utf8'),
  7. );
  8. const skill = readFileSync('cloud/skills/container-provision-job/SKILL.md', 'utf8');
  9. const provisioning = readFileSync('cloud/functions/fmode-provisioning.js', 'utf8');
  10. const onboarding = readFileSync('cloud/functions/fmode-provisioning.js', 'utf8');
  11. const planService = readFileSync('src/app/core/plan.service.ts', 'utf8');
  12. assert.equal(baseline.version, '1.0.0');
  13. assert.equal(baseline.runtime.image, 'fmode/agent-node:0.21.3');
  14. assert.equal(baseline.runtime.memoryLimit, '1536m');
  15. assert.equal(baseline.runtime.nanoCpus, 1_500_000_000);
  16. assert.equal(baseline.runtime.pidsLimit, 512);
  17. assert.equal(baseline.runtime.hermesHome, '/opt/data');
  18. assert.equal(baseline.reporting.heartbeatSeconds, 3600);
  19. assert.equal(baseline.reporting.jitterMaxSeconds, 900);
  20. assert.equal(baseline.reporting.appOfflineSeconds, 80 * 60);
  21. assert.equal(baseline.cleanup.inactiveSeconds, 3600);
  22. assert.equal(baseline.cleanup.uploadedFileGraceSeconds, 3600);
  23. assert.equal(baseline.cleanup.diskPressurePercent, 80);
  24. assert.equal(baseline.cleanup.requiresAppRegistration, true);
  25. assert.equal(baseline.cleanup.contentDigest, 'sha256');
  26. for (const skillPath of [baseline.directories.platformSkills, baseline.directories.customSkills]) {
  27. assert.ok(
  28. path.posix.relative(baseline.runtime.hermesHome, skillPath).startsWith('skills/'),
  29. `Hermes skill directory must be below HERMES_HOME/skills: ${skillPath}`,
  30. );
  31. }
  32. for (const value of [baseline.runtime.image, '--memory 1536m --cpus 1.5 --pids-limit 512']) {
  33. assert.ok(skill.includes(value), `container skill is out of sync: ${value}`);
  34. }
  35. assert.ok(provisioning.includes("var CONTAINER_BASELINE_VERSION = '1.0.0'"), 'server baseline version must match');
  36. assert.ok(provisioning.includes('baselineVersion: CONTAINER_BASELINE_VERSION'), 'platform job must carry the baseline version');
  37. assert.ok(onboarding.includes('AGENT_STATUS_HEARTBEAT=3600'), 'self-managed onboarding must set the baseline heartbeat');
  38. assert.ok(onboarding.includes('AGENT_STATUS_JITTER=900'), 'self-managed onboarding must set heartbeat jitter');
  39. assert.ok(skill.includes('-e HERMES_HOME=/opt/data'), 'new containers must point Hermes at persistent skills');
  40. assert.ok(skill.includes('/opt/hermes/.venv/bin/hermes skills list'), 'provisioning must inspect Hermes skills');
  41. assert.ok(skill.includes('install -d -o 10000 -g 10000'), 'persistent task and skill directories must be writable by Hermes');
  42. const runtimeInstall = skill.match(/install -d -o 10000 -g 10000 -m 0755 ([\s\S]*?)\n\n/)?.[1] || '';
  43. for (const parent of baseline.directories.writableRuntimeParents) {
  44. const relative = path.posix.relative(baseline.runtime.hermesHome, parent);
  45. assert.ok(relative && !relative.startsWith('..'), 'runtime parent must stay below HERMES_HOME');
  46. assert.ok(runtimeInstall.includes(`"$DST/${relative}"`), `runtime parent must be assigned to Hermes: ${parent}`);
  47. }
  48. assert.ok(skill.indexOf("\nFMODE_GC_INSTALL\n") < skill.indexOf('docker start "$AGENT_ID"'),
  49. 'install cleanup before starting the gateway scheduler');
  50. for (const [file, remote] of [
  51. ['cloud/skills/container-provision-job/patch_app_reporter.py', '/tmp/fmode-patch-app-reporter.py'],
  52. ['cloud/skills/container-provision-job/patch_process_notice.py', '/tmp/fmode-patch-process-notice.py'],
  53. ['cloud/skills/container-provision-job/patch_deliverable_ack.py', '/tmp/fmode-patch-deliverable-ack.py'],
  54. ['cloud/skills/container-provision-job/fmode-safe-gc.py', '/tmp/fmode-safe-gc.py'],
  55. ['cloud/skills/container-provision-job/fmode-safe-gc-run.py', '/tmp/fmode-safe-gc-run.py'],
  56. ]) {
  57. const digest = createHash('sha256').update(readFileSync(file)).digest('hex');
  58. assert.ok(skill.includes(`${digest} ${remote}`), `container skill SHA256 must match ${file}`);
  59. }
  60. assert.doesNotMatch(planService, /\b(?:\d+(?:\.\d+)?\s*(?:核|GiB|GB|g)\b|CPU\s*\d)/i,
  61. 'customer-facing plan copy must not expose infrastructure sizing');
  62. console.log('Container baseline v1.0.0 is internally consistent.');