verify-container-baseline.mjs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import assert from 'node:assert/strict';
  2. import { readFileSync } from 'node:fs';
  3. import path from 'node:path';
  4. const baseline = JSON.parse(
  5. readFileSync('cloud/skills/container-provision-job/container-baseline-v1.json', 'utf8'),
  6. );
  7. const skill = readFileSync('cloud/skills/container-provision-job/SKILL.md', 'utf8');
  8. const provisioning = readFileSync('cloud/functions/fmode-provisioning.js', 'utf8');
  9. const onboarding = readFileSync('cloud/functions/fmode-provisioning.js', 'utf8');
  10. const planService = readFileSync('src/app/core/plan.service.ts', 'utf8');
  11. assert.equal(baseline.version, '1.1.0');
  12. assert.equal(baseline.runtime.image, 'fmode/agent-node:0.21.3');
  13. assert.equal(baseline.runtime.memoryLimit, '1536m');
  14. assert.equal(baseline.runtime.nanoCpus, 1_500_000_000);
  15. assert.equal(baseline.runtime.pidsLimit, 512);
  16. assert.equal(baseline.runtime.hermesHome, '/opt/data');
  17. assert.equal(baseline.reporting.heartbeatSeconds, 3600);
  18. assert.equal(baseline.reporting.jitterMaxSeconds, 900);
  19. assert.equal(baseline.reporting.appOfflineSeconds, 80 * 60);
  20. assert.equal(baseline.cleanup.inactiveSeconds, 3600);
  21. assert.equal(baseline.cleanup.uploadedFileGraceSeconds, 3600);
  22. assert.equal(baseline.cleanup.diskPressurePercent, 80);
  23. assert.equal(baseline.cleanup.requiresAppRegistration, true);
  24. assert.equal(baseline.cleanup.contentDigest, 'sha256');
  25. for (const skillPath of [baseline.directories.platformSkills, baseline.directories.customSkills]) {
  26. assert.ok(
  27. path.posix.relative(baseline.runtime.hermesHome, skillPath).startsWith('skills/'),
  28. `Hermes skill directory must be below HERMES_HOME/skills: ${skillPath}`,
  29. );
  30. }
  31. const script = readFileSync('cloud/skills/container-provision-job/provision.sh', 'utf8');
  32. assert.ok(skill.includes('provision.sh'), 'container skill must delegate to provision.sh');
  33. assert.ok(script.includes('--memory 1536m --cpus 1.5 --pids-limit 512'), 'provision.sh resources must match baseline');
  34. assert.ok(script.includes('"$IMAGE" gateway run'), 'containers must start the gateway explicitly');
  35. assert.ok(script.includes('--env-file "$ENV_FILE"'), 'docker env and .env must come from one container.env');
  36. assert.ok(script.includes('HERMES_HOME=/opt/data'), 'new containers must point Hermes at persistent skills');
  37. assert.ok(script.includes('/opt/hermes/.venv/bin/hermes skills list'), 'provisioning must inspect Hermes skills');
  38. assert.ok(script.includes('install -d -o 10000 -g 10000'), 'persistent task and skill directories must be writable by Hermes');
  39. assert.ok(script.includes('/opt/fmode-bundle/install.py'), 'platform containers must install the onboarding bundle');
  40. for (const key of baseline.channels.wecomEnv) assert.ok(script.includes(key), `wecom env must be supported: ${key}`);
  41. const runtimeInstall = script.match(/install -d -o 10000 -g 10000 -m 0755 ([\s\S]*?)\n "\$DOCKER"/)?.[1] || '';
  42. for (const parent of baseline.directories.writableRuntimeParents) {
  43. const relative = path.posix.relative(baseline.runtime.hermesHome, parent);
  44. assert.ok(relative && !relative.startsWith('..'), 'runtime parent must stay below HERMES_HOME');
  45. assert.ok(runtimeInstall.includes(`"$DST/${relative}"`), `runtime parent must be assigned to Hermes: ${parent}`);
  46. }
  47. const createBody = script.slice(script.indexOf('create() {'), script.indexOf('install_safe_gc() {'));
  48. assert.ok(createBody.indexOf('install_safe_gc') < createBody.indexOf('docker_create ||'),
  49. 'install cleanup before starting the gateway scheduler');
  50. assert.doesNotMatch(planService, /\b(?:\d+(?:\.\d+)?\s*(?:核|GiB|GB|g)\b|CPU\s*\d)/i,
  51. 'customer-facing plan copy must not expose infrastructure sizing');
  52. console.log('Container baseline v1.1.0 is internally consistent.');