23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
353 lines
14 KiB
TypeScript
353 lines
14 KiB
TypeScript
/**
|
||
* Tests for business_pod_validate + business_pod_route_backend MCP tools
|
||
* + pod-schema validator + domain-affinity policy
|
||
* (ADR-164 Phase 2 + Phase 3, ADR-164.1 reservationExpiryMs bound).
|
||
*/
|
||
import { describe, it, expect } from 'vitest';
|
||
import { readFileSync } from 'node:fs';
|
||
import { resolve } from 'node:path';
|
||
|
||
import { businessPodTools } from '../src/mcp-tools/business-pod-tools.js';
|
||
import {
|
||
validatePodTemplate,
|
||
PodTemplateValidationError,
|
||
type PodTemplate,
|
||
} from '../src/business-pods/pod-schema.js';
|
||
import {
|
||
selectAgentBackend,
|
||
CLOUD_BUDGET_THRESHOLD_USD,
|
||
} from '../src/business-pods/domain-affinity-policy.js';
|
||
|
||
function findTool(name: string) {
|
||
const t = businessPodTools.find((x) => x.name === name);
|
||
if (!t) throw new Error(`tool not found: ${name}`);
|
||
return t;
|
||
}
|
||
|
||
const TEMPLATES_DIR = resolve(
|
||
__dirname,
|
||
'../../../../plugins/ruflo-business-pods/templates',
|
||
);
|
||
const POD_NAMES = ['sales', 'marketing', 'finance', 'ops', 'support', 'hr', 'exec'] as const;
|
||
const loadJson = (name: string): unknown =>
|
||
JSON.parse(readFileSync(resolve(TEMPLATES_DIR, `${name}.json`), 'utf-8'));
|
||
|
||
const salesJson = loadJson('sales');
|
||
|
||
function clone<T>(v: T): T {
|
||
return JSON.parse(JSON.stringify(v));
|
||
}
|
||
|
||
describe('pod-schema validator — structural', () => {
|
||
it('rejects non-object input with JSON-pointer "/"', () => {
|
||
expect(() => validatePodTemplate('not an object')).toThrow(PodTemplateValidationError);
|
||
expect(() => validatePodTemplate(null)).toThrow(/pod-template must be a JSON object/);
|
||
expect(() => validatePodTemplate([])).toThrow(/pod-template must be a JSON object/);
|
||
});
|
||
|
||
it('rejects missing required fields with structured error', () => {
|
||
expect(() => validatePodTemplate({})).toThrow(/field "name" must be a non-empty string/);
|
||
expect(() => validatePodTemplate({ name: 'sales' })).toThrow(/displayName/);
|
||
});
|
||
|
||
it('rejects malformed name (must be lowercase-kebab)', () => {
|
||
const t = clone(salesJson) as Record<string, unknown>;
|
||
t.name = 'Sales Pod';
|
||
expect(() => validatePodTemplate(t)).toThrow(/lowercase-kebab/);
|
||
});
|
||
|
||
it('rejects empty agents array', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.agents = [];
|
||
expect(() => validatePodTemplate(t)).toThrow(/agents must have ≥1 entry/);
|
||
});
|
||
|
||
it('rejects empty allowedMcpTools array', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.allowedMcpTools = [];
|
||
expect(() => validatePodTemplate(t)).toThrow(/allowedMcpTools must have ≥1 entry/);
|
||
});
|
||
|
||
it('rejects empty bench.successCriteria', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.bench.successCriteria = [];
|
||
expect(() => validatePodTemplate(t)).toThrow(/successCriteria must have ≥1 entry/);
|
||
});
|
||
|
||
it('rejects invalid piiPolicy', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.piiPolicy = 'invalid';
|
||
expect(() => validatePodTemplate(t)).toThrow(/piiPolicy must be one of/);
|
||
});
|
||
|
||
it('rejects malformed cronSchedule', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.cronSchedule = 'every six hours';
|
||
expect(() => validatePodTemplate(t)).toThrow(/cronSchedule must be a POSIX cron expression/);
|
||
});
|
||
|
||
it('rejects budgetUsdPerRun exceeding budgetUsdMonthly', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.budgetUsdPerRun = 100;
|
||
t.budgetUsdMonthly = 50;
|
||
expect(() => validatePodTemplate(t)).toThrow(/budgetUsdPerRun must not exceed budgetUsdMonthly/);
|
||
});
|
||
|
||
it('rejects negative budgets', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.budgetUsdMonthly = -1;
|
||
expect(() => validatePodTemplate(t)).toThrow(/budgetUsdMonthly must be ≥0/);
|
||
});
|
||
|
||
it('ADR-164.1 §3.2 — reservationExpiryMs below 5000 ms is rejected', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.reservationExpiryMs = 1000;
|
||
expect(() => validatePodTemplate(t)).toThrow(/reservationExpiryMs must be within \[5000, 300000\] ms/);
|
||
});
|
||
|
||
it('ADR-164.1 §3.2 — reservationExpiryMs above 300000 ms is rejected', () => {
|
||
const t = clone(salesJson) as any;
|
||
t.reservationExpiryMs = 600_000;
|
||
expect(() => validatePodTemplate(t)).toThrow(/reservationExpiryMs must be within \[5000, 300000\] ms/);
|
||
});
|
||
|
||
it('reservationExpiryMs is optional — omitting it validates', () => {
|
||
const t = clone(salesJson) as any;
|
||
delete t.reservationExpiryMs;
|
||
expect(() => validatePodTemplate(t)).not.toThrow();
|
||
});
|
||
|
||
it('accepts the Phase 2 sales.json template verbatim', () => {
|
||
const t = validatePodTemplate(salesJson) as PodTemplate;
|
||
expect(t.name).toBe('sales');
|
||
expect(t.roomId).toBe('sales');
|
||
expect(t.agents.length).toBe(4);
|
||
expect(t.piiPolicy).toBe('soc2');
|
||
expect(t.budgetUsdMonthly).toBe(50);
|
||
expect(t.reservationExpiryMs).toBe(60_000);
|
||
});
|
||
});
|
||
|
||
describe('Phase 3 — all 7 pod templates validate', () => {
|
||
for (const name of POD_NAMES) {
|
||
it(`${name}.json validates without errors`, () => {
|
||
const raw = loadJson(name);
|
||
const t = validatePodTemplate(raw);
|
||
expect(t.name).toBe(name);
|
||
expect(t.agents.length).toBeGreaterThanOrEqual(1);
|
||
expect(t.allowedMcpTools.length).toBeGreaterThanOrEqual(1);
|
||
expect(t.bench.successCriteria.length).toBeGreaterThanOrEqual(1);
|
||
});
|
||
}
|
||
|
||
it('ops.json bench description references the synthetic-HTTP-endpoint test (ADR-164 §4.4)', () => {
|
||
const ops = validatePodTemplate(loadJson('ops')) as PodTemplate;
|
||
expect(ops.bench.description).toMatch(/synthetic.*endpoint/i);
|
||
expect(ops.bench.description).toMatch(/200/);
|
||
expect(ops.bench.description).toMatch(/500/);
|
||
expect(ops.bench.description).toMatch(/60 seconds|60s/i);
|
||
expect(ops.allowedMcpTools).toContain('http_fetch');
|
||
expect(ops.allowedMcpTools).toContain('aidefence_analyze');
|
||
expect(ops.allowedMcpTools).toContain('terminal_execute');
|
||
expect(ops.allowedMcpTools).toContain('agent_execute');
|
||
});
|
||
|
||
it('exec.json bench description references the founder-bootstrap trust elevation (ADR-164 §3.5.4)', () => {
|
||
const exec = validatePodTemplate(loadJson('exec')) as PodTemplate;
|
||
expect(exec.bench.description).toMatch(/share-context/);
|
||
expect(exec.bench.description).toMatch(/3\.5\.4|founder-bootstrap|escape hatch/i);
|
||
});
|
||
|
||
it('finance.json + hr.json + exec.json use gdpr piiPolicy (most restrictive)', () => {
|
||
for (const n of ['finance', 'hr', 'exec'] as const) {
|
||
const t = validatePodTemplate(loadJson(n)) as PodTemplate;
|
||
expect(t.piiPolicy).toBe('gdpr');
|
||
expect(t.preferLocalExecution).toBe(true);
|
||
}
|
||
});
|
||
});
|
||
|
||
describe('business_pod_validate MCP tool', () => {
|
||
it('exposes business_pod_validate with required schema shape', () => {
|
||
const t = findTool('business_pod_validate');
|
||
expect(t.name).toBe('business_pod_validate');
|
||
expect(t.inputSchema.type).toBe('object');
|
||
expect(t.inputSchema.properties).toBeDefined();
|
||
expect(typeof t.handler).toBe('function');
|
||
// ADR-112 — description must be ≥80 chars and carry use-when guidance.
|
||
expect(t.description.length).toBeGreaterThanOrEqual(80);
|
||
expect(t.description).toMatch(/Use when/i);
|
||
expect(t.description).toMatch(/wrong because/i);
|
||
});
|
||
|
||
it('exposes business_pod_route_backend with required schema shape', () => {
|
||
const t = findTool('business_pod_route_backend');
|
||
expect(t.name).toBe('business_pod_route_backend');
|
||
expect(t.inputSchema.type).toBe('object');
|
||
expect(t.inputSchema.properties).toBeDefined();
|
||
expect(typeof t.handler).toBe('function');
|
||
// ADR-112 — description must be ≥80 chars and carry use-when guidance.
|
||
expect(t.description.length).toBeGreaterThanOrEqual(80);
|
||
expect(t.description).toMatch(/Use when/i);
|
||
expect(t.description).toMatch(/wrong because/i);
|
||
});
|
||
|
||
it('exposes exactly 2 business-pod tools (Phase 2 + Phase 3)', () => {
|
||
expect(businessPodTools.length).toBe(2);
|
||
});
|
||
|
||
it('happy path: returns {success:true, valid:true, template, warnings}', async () => {
|
||
const tool = findTool('business_pod_validate');
|
||
const r: any = await tool.handler({ podTemplate: salesJson });
|
||
expect(r.success).toBe(true);
|
||
expect(r.valid).toBe(true);
|
||
expect(r.template.name).toBe('sales');
|
||
expect(r.warnings).toEqual([]);
|
||
});
|
||
|
||
it('error path: returns {success:false, valid:false, error, path}', async () => {
|
||
const tool = findTool('business_pod_validate');
|
||
const bad = clone(salesJson) as any;
|
||
bad.reservationExpiryMs = 1000;
|
||
const r: any = await tool.handler({ podTemplate: bad });
|
||
expect(r.success).toBe(false);
|
||
expect(r.valid).toBe(false);
|
||
expect(r.error).toMatch(/reservationExpiryMs/);
|
||
expect(r.path).toBe('/');
|
||
});
|
||
|
||
it('error path: non-object podTemplate is rejected before validation', async () => {
|
||
const tool = findTool('business_pod_validate');
|
||
const r: any = await tool.handler({ podTemplate: 'not an object' });
|
||
expect(r.success).toBe(false);
|
||
expect(r.valid).toBe(false);
|
||
expect(r.error).toMatch(/podTemplate must be a JSON object/);
|
||
});
|
||
|
||
it('warns (does not fail) on unknown agent types', async () => {
|
||
const tool = findTool('business_pod_validate');
|
||
const withUnknown = clone(salesJson) as any;
|
||
withUnknown.agents[0].agentType = 'not-a-real-agent-type-xyz';
|
||
const r: any = await tool.handler({ podTemplate: withUnknown });
|
||
expect(r.success).toBe(true);
|
||
expect(r.valid).toBe(true);
|
||
expect(r.warnings.length).toBeGreaterThan(0);
|
||
expect(r.warnings[0]).toMatch(/not-a-real-agent-type-xyz/);
|
||
});
|
||
});
|
||
|
||
describe('Phase 3 — domain-affinity policy (selectAgentBackend)', () => {
|
||
// Synthesize the four combinations of (preferLocalExecution × budget vs threshold)
|
||
// off the sales template — keeps the test independent of pod-file edits.
|
||
const base = clone(salesJson) as PodTemplate;
|
||
|
||
it('preferLocalExecution=true → local-stdio regardless of budget', () => {
|
||
const t = { ...base, preferLocalExecution: true, budgetUsdMonthly: 999 };
|
||
const d = selectAgentBackend(t);
|
||
expect(d.backend).toBe('local-stdio');
|
||
expect(d.reason).toMatch(/local stdio/);
|
||
});
|
||
|
||
it('preferLocalExecution=true → local-stdio even with budget=0', () => {
|
||
const t = { ...base, preferLocalExecution: true, budgetUsdMonthly: 0, budgetUsdPerRun: 0 };
|
||
const d = selectAgentBackend(t);
|
||
expect(d.backend).toBe('local-stdio');
|
||
});
|
||
|
||
it(`preferLocalExecution=false AND budgetUsdMonthly >= ${CLOUD_BUDGET_THRESHOLD_USD} → cloud-managed`, () => {
|
||
const t = {
|
||
...base,
|
||
preferLocalExecution: false,
|
||
budgetUsdMonthly: CLOUD_BUDGET_THRESHOLD_USD,
|
||
};
|
||
const d = selectAgentBackend(t);
|
||
expect(d.backend).toBe('cloud-managed');
|
||
expect(d.reason).toMatch(/cloud Managed Agents/);
|
||
});
|
||
|
||
it(`preferLocalExecution=false AND budgetUsdMonthly < ${CLOUD_BUDGET_THRESHOLD_USD} → remote-peer`, () => {
|
||
const t = {
|
||
...base,
|
||
preferLocalExecution: false,
|
||
budgetUsdMonthly: CLOUD_BUDGET_THRESHOLD_USD - 1,
|
||
budgetUsdPerRun: 0.05,
|
||
};
|
||
const d = selectAgentBackend(t);
|
||
expect(d.backend).toBe('remote-peer');
|
||
expect(d.reason).toMatch(/federation peer node/);
|
||
});
|
||
|
||
it('rejects malformed input (non-object)', () => {
|
||
expect(() => selectAgentBackend(null as any)).toThrow(/must be a validated PodTemplate/);
|
||
expect(() => selectAgentBackend('not a pod' as any)).toThrow(/must be a validated PodTemplate/);
|
||
});
|
||
|
||
it('rejects pod missing preferLocalExecution', () => {
|
||
const t: any = { ...base };
|
||
delete t.preferLocalExecution;
|
||
expect(() => selectAgentBackend(t)).toThrow(/preferLocalExecution must be boolean/);
|
||
});
|
||
|
||
it('rejects pod with non-finite budgetUsdMonthly', () => {
|
||
const t: any = { ...base, budgetUsdMonthly: Number.NaN };
|
||
expect(() => selectAgentBackend(t)).toThrow(/budgetUsdMonthly must be a finite number/);
|
||
});
|
||
});
|
||
|
||
describe('Phase 3 — business_pod_route_backend MCP tool', () => {
|
||
it('routes the sales template per §3.4 rules', async () => {
|
||
const tool = findTool('business_pod_route_backend');
|
||
const r: any = await tool.handler({ podTemplate: salesJson });
|
||
expect(r.success).toBe(true);
|
||
expect(r.valid).toBe(true);
|
||
// sales has preferLocalExecution=false and budgetUsdMonthly=50 → cloud-managed.
|
||
expect(r.backend).toBe('cloud-managed');
|
||
expect(r.pod.name).toBe('sales');
|
||
expect(r.pod.budgetUsdMonthly).toBe(50);
|
||
expect(r.reason).toMatch(/cloud Managed Agents/);
|
||
});
|
||
|
||
it('routes the marketing template (budget=40, preferLocal=false) to remote-peer', async () => {
|
||
const tool = findTool('business_pod_route_backend');
|
||
const r: any = await tool.handler({ podTemplate: loadJson('marketing') });
|
||
expect(r.success).toBe(true);
|
||
expect(r.backend).toBe('remote-peer');
|
||
});
|
||
|
||
it('routes the finance template (preferLocal=true) to local-stdio', async () => {
|
||
const tool = findTool('business_pod_route_backend');
|
||
const r: any = await tool.handler({ podTemplate: loadJson('finance') });
|
||
expect(r.success).toBe(true);
|
||
expect(r.backend).toBe('local-stdio');
|
||
});
|
||
|
||
it('accepts a podTemplatePath string and resolves it', async () => {
|
||
const tool = findTool('business_pod_route_backend');
|
||
const r: any = await tool.handler({
|
||
podTemplatePath: resolve(TEMPLATES_DIR, 'hr.json'),
|
||
});
|
||
expect(r.success).toBe(true);
|
||
expect(r.backend).toBe('local-stdio');
|
||
expect(r.pod.name).toBe('hr');
|
||
});
|
||
|
||
it('rejects malformed input (no podTemplate and no podTemplatePath)', async () => {
|
||
const tool = findTool('business_pod_route_backend');
|
||
const r: any = await tool.handler({});
|
||
expect(r.success).toBe(false);
|
||
expect(r.valid).toBe(false);
|
||
expect(r.error).toMatch(/podTemplate.*or.*podTemplatePath/);
|
||
});
|
||
|
||
it('rejects a malformed pod template with structured error path', async () => {
|
||
const tool = findTool('business_pod_route_backend');
|
||
const bad = clone(salesJson) as any;
|
||
bad.reservationExpiryMs = 1;
|
||
const r: any = await tool.handler({ podTemplate: bad });
|
||
expect(r.success).toBe(false);
|
||
expect(r.valid).toBe(false);
|
||
expect(r.error).toMatch(/reservationExpiryMs/);
|
||
expect(r.path).toBe('/');
|
||
});
|
||
});
|