feat(deploy): register Engine MCP materialization transition

This commit is contained in:
Codex 2026-07-23 20:37:31 +03:00
parent 4cf3a83ef1
commit 25b12d77e4
4 changed files with 1134 additions and 3 deletions

View File

@ -0,0 +1,289 @@
#!/usr/bin/env node
import { createHash } from "node:crypto";
import { spawnSync } from "node:child_process";
import { copyFile, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const here = dirname(fileURLToPath(import.meta.url));
const workspaceRoot = resolve(here, "../../..");
const engineRoot = resolve(
process.env.NODEDC_ENGINE_SOURCE_ROOT || join(workspaceRoot, "NODEDC_ENGINE_INFRA"),
);
const artifactRoot = resolve(
process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(here, "../deploy-artifacts"),
);
const baselineArtifact = resolve(
here,
"../deploy-artifacts/nodedc-engine-mcp-telemetry-catalog-20260723-035.tgz",
);
const baselineArtifactSha256 =
"4ce1563612499a19d653a174a4d73632e0aaac7dacd2eca4e7c01c87586b1155";
const nodeIntelligenceDescriptorPath =
"nodedc-source/services/node-intelligence/activation.json";
const predecessorNodeIntelligenceDescriptorSha256 =
"25ed3efd858aaf82c242dba501f0acc0c6c3dc91e8845707a4d3325750eab59f";
const targetNodeIntelligenceDescriptorSha256 =
"03b2ba120c3929e9cf99940ddc927082de376ceff762895a84103144202aef42";
const predecessorGatewaySha256 =
"69bfc91e913a3fad04e13aca86efb9d62f73c0c7d1f8f7200907494b29fa9e8d";
const targetGatewaySha256 =
"9020cf49a3558c0497fed4ecfd81367cbc11b5b249881804c29fe437900c71f8";
const [patchId = "", ...extra] = process.argv.slice(2);
if (
extra.length
|| !/^engine-mcp-execution-plan-materialization-\d{8}-\d{3}$/.test(patchId)
) {
throw new Error(
"usage: build-engine-mcp-execution-plan-materialization-artifact.mjs "
+ "<engine-mcp-execution-plan-materialization-YYYYMMDD-NNN>",
);
}
const descriptorPath =
"nodedc-source/server/deployTransitions/executionPlanMaterializationV1.json";
const targetSha256 = Object.freeze({
"nodedc-source/server/routes/n8n.js":
"391fc81228fdacd6efc6c0868991a3485f71869708e49ac15819db6ccce1bfce",
"nodedc-source/server/routes/engineAgentGateway.js":
targetGatewaySha256,
"nodedc-source/server/l2ExecutionPlan/catalog.js":
"c35b4c7ad9319aabbf1366a11ff52a6e99d961893bafdfcb4e84fc5f24fc04be",
"nodedc-source/server/l2ExecutionPlan/compiler.js":
"beb3f664073f9a372432643936a04d0cb0028cd695f759c68bd053e9cd892fe4",
"nodedc-source/server/l2ExecutionPlan/materializer.js":
"ee3bcfd06b3a5fa46800df974a2dedfdd55eeaf662329f837486c011a9bd713e",
"nodedc-source/server/assets/execution-plans/v1/catalog.json":
"a153e040e0a592bad4375b98d9a1d83d148923aa0f0fd47d225b92eda281c4e9",
[descriptorPath]:
"52c0152cff49c251be5581a9209d2e63ba710c16e815bdd6ece24f7c9dd7e480",
[nodeIntelligenceDescriptorPath]:
targetNodeIntelligenceDescriptorSha256,
});
const entries = Object.freeze(Object.keys(targetSha256));
const artifact = join(artifactRoot, `nodedc-${patchId}.tgz`);
await assertFresh(artifact);
await assertExactSources();
const targetNodeIntelligenceDescriptor =
await buildTargetNodeIntelligenceDescriptor();
const stage = await mkdtemp(
join(tmpdir(), "nodedc-engine-mcp-execution-plan-materialization-"),
);
try {
const payload = join(stage, "payload");
for (const relativePath of entries) {
const destination = join(payload, relativePath);
await mkdir(dirname(destination), { recursive: true });
if (relativePath === nodeIntelligenceDescriptorPath) {
await writeFile(destination, targetNodeIntelligenceDescriptor, {
encoding: "utf8",
flag: "wx",
mode: 0o644,
});
continue;
}
await copyFile(join(engineRoot, relativePath), destination);
}
await writeFile(
join(stage, "manifest.env"),
`id=${patchId}\ncomponent=engine\ntype=app-overlay\n`,
{ encoding: "utf8", flag: "wx", mode: 0o644 },
);
await writeFile(join(stage, "files.txt"), `${entries.join("\n")}\n`, {
encoding: "utf8",
flag: "wx",
mode: 0o644,
});
await mkdir(artifactRoot, { recursive: true });
run("python3", ["-c", canonicalTarScript(), artifact, stage]);
console.log(JSON.stringify({
ok: true,
patchId,
artifact,
sha256: digest(await readFile(artifact)),
entries,
targetSha256,
services: ["nodedc-backend"],
transition: "telemetry-catalog-v1-to-execution-plan-materialization-v1",
mcpVersion: "0.9.0",
mcpSurface: "external-codex",
mcpTools: [
"engine_plan_l2_execution_plan_materialization",
"engine_apply_l2_execution_plan_materialization",
],
providerLogicAuthority: "trusted-provider-package",
unmanagedGraphPolicy: "explicit-adoption-required",
nodeIntelligenceRelease: "2.33.2-974a9fb3492f",
predecessorGatewaySha256,
targetGatewaySha256,
predecessorNodeIntelligenceDescriptorSha256,
targetNodeIntelligenceDescriptorSha256,
untouched: [
"live L2 graphs",
"n8n workflow data",
"L1",
"Engine UI",
"node-intelligence image",
"databases",
"credentials",
"MCP Nginx",
"embedded AI Workspace",
],
}, null, 2));
} finally {
await rm(stage, { recursive: true, force: true });
}
async function assertExactSources() {
for (const [relativePath, expected] of Object.entries(targetSha256)) {
if (relativePath === nodeIntelligenceDescriptorPath) continue;
const sourcePath = join(engineRoot, relativePath);
const info = await lstat(sourcePath);
if (!info.isFile() || info.isSymbolicLink()) {
throw new Error(
`engine_mcp_execution_plan_materialization_source_unsafe:${relativePath}`,
);
}
const actual = digest(await readFile(sourcePath));
if (actual !== expected) {
throw new Error(
`engine_mcp_execution_plan_materialization_target_mismatch:${relativePath}:`
+ `expected=${expected}:actual=${actual}`,
);
}
}
const gatewaySource = await readFile(
join(engineRoot, "nodedc-source/server/routes/engineAgentGateway.js"),
"utf8",
);
for (const marker of [
"const ENGINE_AGENT_MCP_VERSION = '0.9.0'",
"name: 'engine_plan_l2_execution_plan_materialization'",
"name: 'engine_apply_l2_execution_plan_materialization'",
"'execution-plan.apply'",
]) {
if (!gatewaySource.includes(marker)) {
throw new Error(
`engine_mcp_execution_plan_materialization_gateway_marker_missing:${marker}`,
);
}
}
if (/gelios|robot2b/i.test(
await readFile(
join(engineRoot, "nodedc-source/server/l2ExecutionPlan/compiler.js"),
"utf8",
),
)) {
throw new Error("engine_mcp_execution_plan_materialization_provider_hardcode");
}
const descriptor = JSON.parse(
await readFile(join(engineRoot, descriptorPath), "utf8"),
);
if (
descriptor?.schemaVersion !== "nodedc.engine.deploy-transition/v1"
|| descriptor?.id !== "engine-mcp-l2-execution-plan-materialization-v1"
|| descriptor?.mcpVersion !== "0.9.0"
|| descriptor?.plan?.tool
!== "engine_plan_l2_execution_plan_materialization"
|| descriptor?.apply?.tool
!== "engine_apply_l2_execution_plan_materialization"
|| descriptor?.providerLogicAuthority !== "trusted-provider-package"
|| descriptor?.unmanagedGraphPolicy !== "explicit-adoption-required"
|| descriptor?.embeddedCodexChanged !== false
) {
throw new Error(
"engine_mcp_execution_plan_materialization_descriptor_contract_mismatch",
);
}
}
async function buildTargetNodeIntelligenceDescriptor() {
const baselineBytes = await readFile(baselineArtifact);
if (digest(baselineBytes) !== baselineArtifactSha256) {
throw new Error(
"engine_mcp_execution_plan_materialization_baseline_artifact_mismatch",
);
}
const baseline = run("tar", [
"-xOf",
baselineArtifact,
`payload/${nodeIntelligenceDescriptorPath}`,
]).stdout;
if (
digest(Buffer.from(baseline, "utf8"))
!== predecessorNodeIntelligenceDescriptorSha256
) {
throw new Error(
"engine_mcp_execution_plan_materialization_baseline_descriptor_mismatch",
);
}
const descriptor = JSON.parse(baseline);
if (
descriptor?.schemaVersion
!== "nodedc.engine-node-intelligence-transition/v1"
|| descriptor?.action !== "activate"
|| descriptor?.releaseId !== "2.33.2-974a9fb3492f"
|| descriptor?.source?.gatewaySha256 !== predecessorGatewaySha256
) {
throw new Error(
"engine_mcp_execution_plan_materialization_baseline_contract_mismatch",
);
}
descriptor.source.gatewaySha256 = targetGatewaySha256;
const rendered = `${JSON.stringify(descriptor, null, 2)}\n`;
if (
digest(Buffer.from(rendered, "utf8"))
!== targetNodeIntelligenceDescriptorSha256
) {
throw new Error(
"engine_mcp_execution_plan_materialization_target_descriptor_mismatch",
);
}
return rendered;
}
async function assertFresh(path) {
try {
await lstat(path);
} catch (error) {
if (error?.code === "ENOENT") return;
throw error;
}
throw new Error("artifact_already_exists");
}
function canonicalTarScript() {
return [
"import gzip,io,pathlib,sys,tarfile",
"root=pathlib.Path(sys.argv[2])",
"with open(sys.argv[1],'xb') as out:",
" with gzip.GzipFile(filename='',mode='wb',fileobj=out,compresslevel=9,mtime=0) as gz:",
" with tarfile.open(fileobj=gz,mode='w',format=tarfile.PAX_FORMAT) as tar:",
" for top in ('manifest.env','files.txt','payload'):",
" p=root/top; paths=[p]+(sorted(p.rglob('*')) if p.is_dir() else [])",
" for x in paths:",
" info=tar.gettarinfo(str(x),arcname=x.relative_to(root).as_posix())",
" info.uid=info.gid=0; info.uname=info.gname='root'; info.mtime=0; info.mode=0o755 if info.isdir() else 0o644",
" with (open(x,'rb') if info.isfile() else io.BytesIO()) as src: tar.addfile(info,src if info.isfile() else None)",
].join("\n");
}
function digest(value) {
return createHash("sha256").update(value).digest("hex");
}
function run(command, args) {
const result = spawnSync(command, args, {
encoding: "utf8",
maxBuffer: 128 * 1024 * 1024,
stdio: ["ignore", "pipe", "pipe"],
});
if (result.status !== 0) {
throw new Error(`${command}_failed:${result.stderr || result.stdout}`);
}
return result;
}

View File

@ -573,6 +573,45 @@ ENGINE_MCP_TELEMETRY_CATALOG_TARGET_SHA256 = {
ENGINE_MCP_TELEMETRY_CATALOG_NEW_PATHS = ( ENGINE_MCP_TELEMETRY_CATALOG_NEW_PATHS = (
ENGINE_MCP_TELEMETRY_CATALOG_DESCRIPTOR_REL, ENGINE_MCP_TELEMETRY_CATALOG_DESCRIPTOR_REL,
) )
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_DESCRIPTOR_REL = (
"nodedc-source/server/deployTransitions/executionPlanMaterializationV1.json"
)
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES = (
"nodedc-source/server/routes/n8n.js",
"nodedc-source/server/routes/engineAgentGateway.js",
"nodedc-source/server/l2ExecutionPlan/catalog.js",
"nodedc-source/server/l2ExecutionPlan/compiler.js",
"nodedc-source/server/l2ExecutionPlan/materializer.js",
"nodedc-source/server/assets/execution-plans/v1/catalog.json",
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_DESCRIPTOR_REL,
ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL,
)
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_PREDECESSOR_SHA256 = {
"nodedc-source/server/routes/n8n.js": "903245ae363e9b9ac161498f17988a38876a0e0ac8d80f3fa1b0112ceb7fe906",
"nodedc-source/server/routes/engineAgentGateway.js": "69bfc91e913a3fad04e13aca86efb9d62f73c0c7d1f8f7200907494b29fa9e8d",
ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL: "25ed3efd858aaf82c242dba501f0acc0c6c3dc91e8845707a4d3325750eab59f",
}
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256 = {
ENGINE_MCP_EXECUTION_PROFILE_DECODER_DESCRIPTOR_REL: "93e431902e9bcd3b828a82ed6b42b48d939051f21bf8824dafcf2addac8a711c",
ENGINE_MCP_TELEMETRY_CATALOG_DESCRIPTOR_REL: "b25ab8b6e6ad8ac24614c4630cc3635abe453464466d5a72238b05e48a24d882",
}
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256 = {
"nodedc-source/server/routes/n8n.js": "391fc81228fdacd6efc6c0868991a3485f71869708e49ac15819db6ccce1bfce",
"nodedc-source/server/routes/engineAgentGateway.js": "9020cf49a3558c0497fed4ecfd81367cbc11b5b249881804c29fe437900c71f8",
"nodedc-source/server/l2ExecutionPlan/catalog.js": "c35b4c7ad9319aabbf1366a11ff52a6e99d961893bafdfcb4e84fc5f24fc04be",
"nodedc-source/server/l2ExecutionPlan/compiler.js": "beb3f664073f9a372432643936a04d0cb0028cd695f759c68bd053e9cd892fe4",
"nodedc-source/server/l2ExecutionPlan/materializer.js": "ee3bcfd06b3a5fa46800df974a2dedfdd55eeaf662329f837486c011a9bd713e",
"nodedc-source/server/assets/execution-plans/v1/catalog.json": "a153e040e0a592bad4375b98d9a1d83d148923aa0f0fd47d225b92eda281c4e9",
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_DESCRIPTOR_REL: "52c0152cff49c251be5581a9209d2e63ba710c16e815bdd6ece24f7c9dd7e480",
ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL: "03b2ba120c3929e9cf99940ddc927082de376ceff762895a84103144202aef42",
}
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_NEW_PATHS = (
"nodedc-source/server/l2ExecutionPlan/catalog.js",
"nodedc-source/server/l2ExecutionPlan/compiler.js",
"nodedc-source/server/l2ExecutionPlan/materializer.js",
"nodedc-source/server/assets/execution-plans/v1/catalog.json",
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_DESCRIPTOR_REL,
)
ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES = ( ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES = (
ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL, ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL,
) )
@ -3271,6 +3310,7 @@ def validate_engine_node_intelligence_transition(payload_dir, entries):
"const ENGINE_AGENT_MCP_VERSION = '0.6.0'", "const ENGINE_AGENT_MCP_VERSION = '0.6.0'",
"const ENGINE_AGENT_MCP_VERSION = '0.7.0'", "const ENGINE_AGENT_MCP_VERSION = '0.7.0'",
"const ENGINE_AGENT_MCP_VERSION = '0.8.0'", "const ENGINE_AGENT_MCP_VERSION = '0.8.0'",
"const ENGINE_AGENT_MCP_VERSION = '0.9.0'",
) )
): ):
die("Engine node-intelligence gateway MCP version is not registered") die("Engine node-intelligence gateway MCP version is not registered")
@ -4422,6 +4462,50 @@ process.stdout.write('engine-mcp-telemetry-catalog:0.8.0:normalized-metadata-onl
} }
def accept_engine_mcp_execution_plan_materialization_runtime():
root = component_root("engine")
validate_engine_mcp_execution_plan_materialization_slice(
root,
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES,
)
live = run_engine_backend_probe(
(
"node",
"--input-type=module",
"-e",
"""
const fs=await import('node:fs/promises');
const gateway=await import('file:///app/server/routes/engineAgentGateway.js');
const catalogModule=await import('file:///app/server/l2ExecutionPlan/catalog.js');
const materializer=await import('file:///app/server/l2ExecutionPlan/materializer.js');
const catalog=await catalogModule.loadExecutionPlanCatalog();
const plan=gateway.engineAgentTools.find((item)=>item.name==='engine_plan_l2_execution_plan_materialization');
const apply=gateway.engineAgentTools.find((item)=>item.name==='engine_apply_l2_execution_plan_materialization');
const planRequired=plan?.inputSchema?.required||[];
const applyRequired=apply?.inputSchema?.required||[];
const genericSource=(await Promise.all(['/app/server/l2ExecutionPlan/compiler.js','/app/server/l2ExecutionPlan/materializer.js'].map((path)=>fs.readFile(path,'utf8')))).join('\\n');
const unmanaged=materializer.materializationState({source:{},nodes:[{id:'existing'}],edges:[]});
if(gateway.ENGINE_AGENT_MCP_VERSION!=='0.9.0'||!plan||!apply||plan?.inputSchema?.additionalProperties!==false||apply?.inputSchema?.additionalProperties!==false||!planRequired.includes('executionPlan')||!applyRequired.includes('planRef')||!applyRequired.includes('providerAuthRef')||catalog.schemaVersion!=='nodedc.engine.execution-plan-catalog/v1'||catalog.runtime?.graphBlueprintSchemaVersion!=='nodedc.l2-graph-blueprint/v1'||catalog.runtime?.compilerVersions?.join(',')!=='1.1.0'||unmanaged!=='unmanaged_existing'||/gelios|robot2b/i.test(genericSource))process.exit(2);
process.stdout.write('engine-mcp-execution-plan-materialization:0.9.0:provider-package-authority:two-phase:v1');
""".strip(),
),
"Engine MCP execution plan materialization",
container_id=engine_backend_container_id(),
)
expected = (
"engine-mcp-execution-plan-materialization:"
"0.9.0:provider-package-authority:two-phase:v1"
)
if live != expected:
die("Engine MCP execution plan materialization live acceptance mismatch")
return {
"target_sha256": dict(
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256
),
"live": live,
}
def validate_no_lifecycle_scripts(payload_dir, label): def validate_no_lifecycle_scripts(payload_dir, label):
forbidden = ("preinstall", "install", "postinstall", "prepare", "prepack", "postpack") forbidden = ("preinstall", "install", "postinstall", "prepare", "prepack", "postpack")
for package_path in payload_dir.rglob("package.json"): for package_path in payload_dir.rglob("package.json"):
@ -5178,6 +5262,135 @@ def validate_engine_mcp_telemetry_catalog_slice(payload_dir, entries):
) )
def validate_engine_mcp_execution_plan_materialization_slice(payload_dir, entries):
if tuple(entries) != ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES:
die(
"Engine MCP execution plan materialization files.txt exact "
"set/order mismatch"
)
for rel, expected_sha256 in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256.items()
):
path = payload_dir / rel
try:
path_stat = path.lstat()
except FileNotFoundError:
die(f"Engine MCP execution plan materialization target is missing: {rel}")
if (
stat.S_ISLNK(path_stat.st_mode)
or not stat.S_ISREG(path_stat.st_mode)
or sha256_file(path) != expected_sha256
):
die(
"Engine MCP execution plan materialization target sha256 "
f"mismatch: {rel}"
)
descriptor = read_strict_json(
payload_dir / ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_DESCRIPTOR_REL,
"Engine MCP execution plan materialization descriptor",
max_bytes=32 * 1024,
)
expected_descriptor = {
"schemaVersion": "nodedc.engine.deploy-transition/v1",
"id": "engine-mcp-l2-execution-plan-materialization-v1",
"component": "engine",
"scope": "external-mcp-l2-authoring",
"mcpVersion": "0.9.0",
"sourcePaths": [
"nodedc-source/server/routes/n8n.js",
"nodedc-source/server/routes/engineAgentGateway.js",
"nodedc-source/server/l2ExecutionPlan/catalog.js",
"nodedc-source/server/l2ExecutionPlan/compiler.js",
"nodedc-source/server/l2ExecutionPlan/materializer.js",
"nodedc-source/server/assets/execution-plans/v1/catalog.json",
],
"plan": {
"tool": "engine_plan_l2_execution_plan_materialization",
"readOnly": True,
"returnsPlanRef": True,
},
"apply": {
"tool": "engine_apply_l2_execution_plan_materialization",
"accepts": [
"planRef",
"providerAuthRef",
"confirmation",
"changeRef",
],
"rejectsCallerGraphOperations": True,
"revalidatesTargetRevisionAndScope": True,
},
"providerLogicAuthority": "trusted-provider-package",
"unmanagedGraphPolicy": "explicit-adoption-required",
"embeddedCodexChanged": False,
}
if descriptor != expected_descriptor:
die("Engine MCP execution plan materialization descriptor contract mismatch")
gateway_source = (
payload_dir / "nodedc-source/server/routes/engineAgentGateway.js"
).read_text(encoding="utf-8")
if any(
marker not in gateway_source
for marker in (
"const ENGINE_AGENT_MCP_VERSION = '0.9.0'",
"name: 'engine_plan_l2_execution_plan_materialization'",
"name: 'engine_apply_l2_execution_plan_materialization'",
"'execution-plan.apply'",
"assertExactToolArguments(args, [",
)
):
die("Engine MCP execution plan materialization gateway contract mismatch")
materializer_source = (
payload_dir / "nodedc-source/server/l2ExecutionPlan/materializer.js"
).read_text(encoding="utf-8")
compiler_source = (
payload_dir / "nodedc-source/server/l2ExecutionPlan/compiler.js"
).read_text(encoding="utf-8")
if any(
marker not in materializer_source
for marker in (
"status: 'adoption_required'",
"type: 'replaceGraph'",
"assignCredentialBindingInternal",
"execution_plan_materialization_equality_failed",
)
):
die("Engine MCP execution plan materializer contract mismatch")
if any(
marker not in compiler_source
for marker in (
"compileExecutionPlanGraph",
"materializedGraphEqualityDigest",
"ndc.semantic-mapping",
"providerPackage.publisher.nodeType",
)
):
die("Engine MCP execution plan compiler contract mismatch")
if re.search(r"gelios|robot2b", materializer_source, re.IGNORECASE) or re.search(
r"gelios|robot2b",
compiler_source,
re.IGNORECASE,
):
die("Engine MCP execution plan runtime contains provider hardcode")
node_intelligence_descriptor = read_engine_node_intelligence_descriptor(
payload_dir / ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL,
"Engine MCP execution plan materialization node-intelligence descriptor",
)
if (
node_intelligence_descriptor.get("action") != "activate"
or node_intelligence_descriptor.get("releaseId")
!= ENGINE_NODE_INTELLIGENCE_RELEASE_ID
or node_intelligence_descriptor.get("source", {}).get("gatewaySha256")
!= ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256[
ENGINE_NODE_INTELLIGENCE_GATEWAY_REL
]
):
die(
"Engine MCP execution plan materialization node-intelligence "
"attestation contract mismatch"
)
def validate_engine_agent_full_grant_migration_slice(payload_dir, entries): def validate_engine_agent_full_grant_migration_slice(payload_dir, entries):
if tuple(entries) != ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES: if tuple(entries) != ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES:
die("Engine agent full grant migration files.txt exact set/order mismatch") die("Engine agent full grant migration files.txt exact set/order mismatch")
@ -5601,6 +5814,10 @@ def load_artifact(artifact, work_dir):
manifest["component"], manifest["component"],
entries, entries,
) )
and not is_engine_mcp_execution_plan_materialization_slice(
manifest["component"],
entries,
)
and not is_engine_provider_authority_diagnostics_slice( and not is_engine_provider_authority_diagnostics_slice(
manifest["component"], manifest["component"],
entries, entries,
@ -5634,6 +5851,14 @@ def load_artifact(artifact, work_dir):
validate_engine_mcp_execution_profile_decoder_slice(payload_dir, entries) validate_engine_mcp_execution_profile_decoder_slice(payload_dir, entries)
if is_engine_mcp_telemetry_catalog_slice(manifest["component"], entries): if is_engine_mcp_telemetry_catalog_slice(manifest["component"], entries):
validate_engine_mcp_telemetry_catalog_slice(payload_dir, entries) validate_engine_mcp_telemetry_catalog_slice(payload_dir, entries)
if is_engine_mcp_execution_plan_materialization_slice(
manifest["component"],
entries,
):
validate_engine_mcp_execution_plan_materialization_slice(
payload_dir,
entries,
)
if is_engine_provider_security_catalog_slice(manifest["component"], entries): if is_engine_provider_security_catalog_slice(manifest["component"], entries):
validate_engine_provider_security_catalog_payload(payload_dir, entries) validate_engine_provider_security_catalog_payload(payload_dir, entries)
if touches_engine_credential_sink(manifest["component"], entries): if touches_engine_credential_sink(manifest["component"], entries):
@ -5655,6 +5880,10 @@ def load_artifact(artifact, work_dir):
manifest["component"], manifest["component"],
entries, entries,
) )
and not is_engine_mcp_execution_plan_materialization_slice(
manifest["component"],
entries,
)
and ( and (
touches_engine_data_product_publish_grant(entries) touches_engine_data_product_publish_grant(entries)
or ENGINE_DATA_PRODUCT_PUBLISH_GRANT_OVERRIDE_REL in entries or ENGINE_DATA_PRODUCT_PUBLISH_GRANT_OVERRIDE_REL in entries
@ -5849,6 +6078,15 @@ def is_engine_mcp_telemetry_catalog_slice(component, entries):
) )
def is_engine_mcp_execution_plan_materialization_slice(component, entries):
return (
component == "engine"
and entries is not None
and tuple(entries)
== ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES
)
def is_engine_agent_full_grant_migration_slice(component, entries): def is_engine_agent_full_grant_migration_slice(component, entries):
return ( return (
component == "engine" component == "engine"
@ -6377,6 +6615,80 @@ def preflight_engine_mcp_telemetry_catalog_predecessor():
} }
def preflight_engine_mcp_execution_plan_materialization_predecessor():
root = component_root("engine")
actual = {}
for rel, expected_sha256 in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_PREDECESSOR_SHA256.items()
):
path = root / rel
try:
path_stat = path.lstat()
except FileNotFoundError:
die(
"Engine MCP execution plan materialization predecessor is "
f"missing: {rel}"
)
if stat.S_ISLNK(path_stat.st_mode) or not stat.S_ISREG(path_stat.st_mode):
die(
"Engine MCP execution plan materialization predecessor is "
f"unsafe: {rel}"
)
actual_sha256 = sha256_file(path)
if actual_sha256 != expected_sha256:
die(
"Engine MCP execution plan materialization predecessor drift "
f"detected: path={rel} expected={expected_sha256} "
f"actual={actual_sha256}"
)
actual[rel] = actual_sha256
foundation = {}
for rel, expected_sha256 in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256.items()
):
path = root / rel
try:
path_stat = path.lstat()
except FileNotFoundError:
die(
"Engine MCP execution plan materialization foundation is "
f"missing: {rel}"
)
if (
stat.S_ISLNK(path_stat.st_mode)
or not stat.S_ISREG(path_stat.st_mode)
or sha256_file(path) != expected_sha256
):
die(
"Engine MCP execution plan materialization foundation drift "
f"detected: {rel}"
)
foundation[rel] = expected_sha256
for rel in ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_NEW_PATHS:
path = root / rel
if path.exists() or path.is_symlink():
die(
"Engine MCP execution plan materialization new path already "
f"exists: {rel}"
)
backend = preflight_engine_credential_backend_runtime()
if backend["mode"] != "verified-derived-retry":
die(
"Engine MCP execution plan materialization requires the active "
"immutable backend"
)
return {
"mode": "telemetry-catalog-v1-to-execution-plan-materialization-v1",
"predecessor_sha256": actual,
"foundation_sha256": foundation,
"target_sha256": dict(
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256
),
"new_paths": tuple(ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_NEW_PATHS),
"backend_mode": backend["mode"],
}
def preflight_engine_agent_full_grant_migration_predecessor(): def preflight_engine_agent_full_grant_migration_predecessor():
root = component_root("engine") root = component_root("engine")
store_path = root / ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL store_path = root / ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL
@ -6432,6 +6744,7 @@ def component_services(component, entries=None):
or is_engine_provider_target_host_policy_slice(component, entries) or is_engine_provider_target_host_policy_slice(component, entries)
or is_engine_mcp_execution_profile_decoder_slice(component, entries) or is_engine_mcp_execution_profile_decoder_slice(component, entries)
or is_engine_mcp_telemetry_catalog_slice(component, entries) or is_engine_mcp_telemetry_catalog_slice(component, entries)
or is_engine_mcp_execution_plan_materialization_slice(component, entries)
or is_engine_provider_security_catalog_slice(component, entries) or is_engine_provider_security_catalog_slice(component, entries)
): ):
# This slice updates only the existing Engine backend control plane. # This slice updates only the existing Engine backend control plane.
@ -8642,6 +8955,7 @@ def plan_artifact(artifact):
provider_target_host_policy_preflight = None provider_target_host_policy_preflight = None
mcp_execution_profile_decoder_preflight = None mcp_execution_profile_decoder_preflight = None
mcp_telemetry_catalog_preflight = None mcp_telemetry_catalog_preflight = None
mcp_execution_plan_materialization_preflight = None
provider_catalog_preflight = None provider_catalog_preflight = None
with tempfile.TemporaryDirectory(prefix="plan-", dir=TMP_DIR) as tmp: with tempfile.TemporaryDirectory(prefix="plan-", dir=TMP_DIR) as tmp:
manifest, entries, payload_dir = load_artifact(artifact, Path(tmp)) manifest, entries, payload_dir = load_artifact(artifact, Path(tmp))
@ -8707,6 +9021,13 @@ def plan_artifact(artifact):
mcp_telemetry_catalog_preflight = ( mcp_telemetry_catalog_preflight = (
preflight_engine_mcp_telemetry_catalog_predecessor() preflight_engine_mcp_telemetry_catalog_predecessor()
) )
if is_engine_mcp_execution_plan_materialization_slice(
manifest["component"],
entries,
):
mcp_execution_plan_materialization_preflight = (
preflight_engine_mcp_execution_plan_materialization_predecessor()
)
if is_engine_provider_security_catalog_slice(manifest["component"], entries): if is_engine_provider_security_catalog_slice(manifest["component"], entries):
provider_catalog_preflight = preflight_engine_provider_security_catalog_predecessor() provider_catalog_preflight = preflight_engine_provider_security_catalog_predecessor()
@ -8749,6 +9070,12 @@ def plan_artifact(artifact):
component, component,
entries, entries,
) )
touches_mcp_execution_plan_materialization = (
is_engine_mcp_execution_plan_materialization_slice(
component,
entries,
)
)
touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice( touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice(
component, component,
entries, entries,
@ -8766,6 +9093,7 @@ def plan_artifact(artifact):
or touches_provider_target_host_policy or touches_provider_target_host_policy
or touches_mcp_execution_profile_decoder or touches_mcp_execution_profile_decoder
or touches_mcp_telemetry_catalog or touches_mcp_telemetry_catalog
or touches_mcp_execution_plan_materialization
or touches_agent_grant_migration or touches_agent_grant_migration
): ):
credential_backend_preflight = preflight_engine_credential_backend_runtime() credential_backend_preflight = preflight_engine_credential_backend_runtime()
@ -8816,6 +9144,14 @@ def plan_artifact(artifact):
"Engine MCP telemetry catalog requires the active immutable " "Engine MCP telemetry catalog requires the active immutable "
"credential backend" "credential backend"
) )
if touches_mcp_execution_plan_materialization:
if mcp_execution_plan_materialization_preflight is None:
die("Engine MCP execution plan materialization preflight is missing")
if credential_backend_preflight["mode"] != "verified-derived-retry":
die(
"Engine MCP execution plan materialization requires the active "
"immutable credential backend"
)
if touches_agent_grant_migration: if touches_agent_grant_migration:
agent_grant_migration_predecessor_sha256 = ( agent_grant_migration_predecessor_sha256 = (
preflight_engine_agent_full_grant_migration_predecessor() preflight_engine_agent_full_grant_migration_predecessor()
@ -9182,6 +9518,82 @@ def plan_artifact(artifact):
print("engine_databases=untouched") print("engine_databases=untouched")
print("mcp_nginx=untouched") print("mcp_nginx=untouched")
print("embedded_ai_workspace=untouched") print("embedded_ai_workspace=untouched")
if mcp_execution_plan_materialization_preflight:
print(
"engine_mcp_authoring_transition="
f"{mcp_execution_plan_materialization_preflight['mode']}"
)
print("engine_mcp_version=0.9.0")
print("engine_mcp_surface=external-codex")
print(
"engine_mcp_tool="
"engine_plan_l2_execution_plan_materialization"
)
print(
"engine_mcp_tool="
"engine_apply_l2_execution_plan_materialization"
)
print("engine_mcp_provider_logic_authority=trusted-provider-package")
print("engine_mcp_unmanaged_graph_policy=explicit-adoption-required")
print("engine_mcp_plan_phase=read-only")
print("engine_mcp_apply_phase=opaque-plan-ref-only")
print("node_intelligence_descriptor=attested-gateway-successor")
print("node_intelligence_release=2.33.2-974a9fb3492f")
print("node_intelligence_image=preserved")
for foundation_path, foundation_sha256 in (
mcp_execution_plan_materialization_preflight[
"foundation_sha256"
].items()
):
print(
"engine_mcp_execution_plan_materialization_foundation_sha256"
f"[{foundation_path}]={foundation_sha256}"
)
for changed_path in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES
):
print(
"engine_mcp_execution_plan_materialization_changed_path="
f"{changed_path}"
)
if changed_path in mcp_execution_plan_materialization_preflight[
"predecessor_sha256"
]:
print(
"engine_mcp_execution_plan_materialization_predecessor_sha256"
f"[{changed_path}]="
f"{mcp_execution_plan_materialization_preflight['predecessor_sha256'][changed_path]}"
)
elif changed_path in mcp_execution_plan_materialization_preflight[
"new_paths"
]:
print(
"engine_mcp_execution_plan_materialization_predecessor_state"
f"[{changed_path}]=absent"
)
else:
die(
"Engine MCP execution plan materialization plan has no "
f"predecessor state: {changed_path}"
)
print(
"engine_mcp_execution_plan_materialization_target_sha256"
f"[{changed_path}]="
f"{mcp_execution_plan_materialization_preflight['target_sha256'][changed_path]}"
)
print(
"backend_current_barrier="
f"{mcp_execution_plan_materialization_preflight['backend_mode']}"
)
print("backend_force_recreate=yes")
print("backend_pull=never")
print("l2_graph=untouched")
print("n8n_l1=untouched")
print("engine_ui=untouched")
print("engine_databases=untouched")
print("credentials=preserved")
print("mcp_nginx=untouched")
print("embedded_ai_workspace=untouched")
if transition_descriptor: if transition_descriptor:
print(f"n8n_transition={transition_descriptor['action']}") print(f"n8n_transition={transition_descriptor['action']}")
print(f"n8n_version={transition_descriptor['n8nVersion']}") print(f"n8n_version={transition_descriptor['n8nVersion']}")
@ -10300,6 +10712,10 @@ def component_healthchecks(component, entries=None, services=None):
or is_engine_provider_target_host_policy_slice(component, entries) or is_engine_provider_target_host_policy_slice(component, entries)
or is_engine_mcp_execution_profile_decoder_slice(component, entries) or is_engine_mcp_execution_profile_decoder_slice(component, entries)
or is_engine_mcp_telemetry_catalog_slice(component, entries) or is_engine_mcp_telemetry_catalog_slice(component, entries)
or is_engine_mcp_execution_plan_materialization_slice(
component,
entries,
)
or is_engine_agent_full_grant_migration_slice(component, entries) or is_engine_agent_full_grant_migration_slice(component, entries)
or is_engine_mcp_control_plane_slice(component, entries) or is_engine_mcp_control_plane_slice(component, entries)
or is_engine_mcp_ontology_sdk_slice(component, entries) or is_engine_mcp_ontology_sdk_slice(component, entries)
@ -10717,6 +11133,12 @@ def run_healthchecks(component, entries=None, services=None):
component, component,
entries, entries,
) )
touches_mcp_execution_plan_materialization = (
is_engine_mcp_execution_plan_materialization_slice(
component,
entries,
)
)
touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice( touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice(
component, component,
entries, entries,
@ -10735,6 +11157,7 @@ def run_healthchecks(component, entries=None, services=None):
or touches_provider_target_host_policy or touches_provider_target_host_policy
or touches_mcp_execution_profile_decoder or touches_mcp_execution_profile_decoder
or touches_mcp_telemetry_catalog or touches_mcp_telemetry_catalog
or touches_mcp_execution_plan_materialization
or touches_agent_grant_migration or touches_agent_grant_migration
or touches_mcp_control_plane or touches_mcp_control_plane
or touches_mcp_ontology_sdk or touches_mcp_ontology_sdk
@ -10757,6 +11180,7 @@ def run_healthchecks(component, entries=None, services=None):
or touches_provider_target_host_policy or touches_provider_target_host_policy
or touches_mcp_execution_profile_decoder or touches_mcp_execution_profile_decoder
or touches_mcp_telemetry_catalog or touches_mcp_telemetry_catalog
or touches_mcp_execution_plan_materialization
or touches_agent_grant_migration or touches_agent_grant_migration
or touches_mcp_control_plane or touches_mcp_control_plane
or touches_mcp_ontology_sdk or touches_mcp_ontology_sdk
@ -10902,6 +11326,48 @@ def run_healthchecks(component, entries=None, services=None):
"Engine MCP telemetry catalog installed state is neither target " "Engine MCP telemetry catalog installed state is neither target "
"nor rollback predecessor" "nor rollback predecessor"
) )
if touches_mcp_execution_plan_materialization:
root = component_root("engine")
target_state = all(
(root / rel).is_file()
and not (root / rel).is_symlink()
and sha256_file(root / rel) == expected
for rel, expected in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256.items()
)
) and all(
(root / rel).is_file()
and not (root / rel).is_symlink()
and sha256_file(root / rel) == expected
for rel, expected in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256.items()
)
)
predecessor_state = all(
(root / rel).is_file()
and not (root / rel).is_symlink()
and sha256_file(root / rel) == expected
for rel, expected in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_PREDECESSOR_SHA256.items()
)
) and all(
(root / rel).is_file()
and not (root / rel).is_symlink()
and sha256_file(root / rel) == expected
for rel, expected in (
ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256.items()
)
) and all(
not (root / rel).exists() and not (root / rel).is_symlink()
for rel in ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_NEW_PATHS
)
if target_state:
accept_engine_mcp_execution_plan_materialization_runtime()
elif not predecessor_state:
die(
"Engine MCP execution plan materialization installed state is "
"neither target nor rollback predecessor"
)
container_name = COMPONENTS[component].get("health_container") container_name = COMPONENTS[component].get("health_container")
if container_name: if container_name:
healthcheck_container(container_name) healthcheck_container(container_name)
@ -11019,6 +11485,22 @@ def apply_artifact(artifact):
"Engine MCP telemetry catalog requires the active " "Engine MCP telemetry catalog requires the active "
"immutable credential backend" "immutable credential backend"
) )
if is_engine_mcp_execution_plan_materialization_slice(
component,
entries,
):
preflight_engine_mcp_execution_plan_materialization_predecessor()
execution_plan_materialization_backend_preflight = (
preflight_engine_credential_backend_runtime()
)
if (
execution_plan_materialization_backend_preflight["mode"]
!= "verified-derived-retry"
):
die(
"Engine MCP execution plan materialization requires "
"the active immutable credential backend"
)
if is_engine_agent_full_grant_migration_slice(component, entries): if is_engine_agent_full_grant_migration_slice(component, entries):
preflight_engine_agent_full_grant_migration_predecessor() preflight_engine_agent_full_grant_migration_predecessor()
migration_backend_preflight = preflight_engine_credential_backend_runtime() migration_backend_preflight = preflight_engine_credential_backend_runtime()
@ -11276,6 +11758,10 @@ def apply_artifact(artifact):
entries, entries,
) )
or is_engine_mcp_telemetry_catalog_slice(component, entries) or is_engine_mcp_telemetry_catalog_slice(component, entries)
or is_engine_mcp_execution_plan_materialization_slice(
component,
entries,
)
or is_engine_agent_full_grant_migration_slice(component, entries) or is_engine_agent_full_grant_migration_slice(component, entries)
or is_engine_mcp_control_plane_slice(component, entries) or is_engine_mcp_control_plane_slice(component, entries)
or is_engine_mcp_ontology_sdk_slice(component, entries) or is_engine_mcp_ontology_sdk_slice(component, entries)

View File

@ -0,0 +1,356 @@
import hashlib
import importlib.machinery
import importlib.util
import io
import json
import os
from pathlib import Path
import subprocess
import tarfile
import tempfile
import unittest
from contextlib import redirect_stdout
from unittest import mock
SCRIPT_DIR = Path(__file__).resolve().parent
RUNNER_PATH = SCRIPT_DIR / "nodedc-deploy"
BUILDER_PATH = (
SCRIPT_DIR / "build-engine-mcp-execution-plan-materialization-artifact.mjs"
)
ENGINE_ROOT = SCRIPT_DIR.parent.parent.parent / "NODEDC_ENGINE_INFRA"
PATCH_ID = "engine-mcp-execution-plan-materialization-20991231-999"
def load_runner():
loader = importlib.machinery.SourceFileLoader(
"nodedc_engine_mcp_execution_plan_materialization",
str(RUNNER_PATH),
)
spec = importlib.util.spec_from_loader(loader.name, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
RUNNER = load_runner()
class EngineMcpExecutionPlanMaterializationTest(unittest.TestCase):
def require_current_target_source(self):
for relative_path, expected in (
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256.items()
):
if relative_path == RUNNER.ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL:
continue
path = ENGINE_ROOT / relative_path
if (
not path.is_file()
or hashlib.sha256(path.read_bytes()).hexdigest() != expected
):
self.skipTest(
"execution plan materialization source has advanced"
)
def build(self, artifact_dir):
environment = os.environ.copy()
environment["NODEDC_ENGINE_SOURCE_ROOT"] = str(ENGINE_ROOT)
environment["NODEDC_DEPLOY_ARTIFACT_DIR"] = str(artifact_dir)
completed = subprocess.run(
["node", str(BUILDER_PATH), PATCH_ID],
check=True,
capture_output=True,
text=True,
env=environment,
)
return json.loads(completed.stdout)
def test_builder_emits_exact_deterministic_backend_only_slice(self):
self.require_current_target_source()
with tempfile.TemporaryDirectory(
prefix="nodedc-engine-mcp-execution-plan-materialization-"
) as directory:
root = Path(directory)
first = self.build(root / "first")
second = self.build(root / "second")
first_artifact = Path(first["artifact"])
second_artifact = Path(second["artifact"])
self.assertEqual(first_artifact.read_bytes(), second_artifact.read_bytes())
self.assertEqual(first["services"], ["nodedc-backend"])
self.assertEqual(first["mcpVersion"], "0.9.0")
self.assertEqual(
first["providerLogicAuthority"],
"trusted-provider-package",
)
self.assertEqual(
first["unmanagedGraphPolicy"],
"explicit-adoption-required",
)
self.assertEqual(
tuple(first["entries"]),
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES,
)
extract = root / "extract"
with tarfile.open(first_artifact, "r:gz") as archive:
archive.extractall(extract, filter="data")
entries = tuple(
(extract / "files.txt").read_text(encoding="utf-8").splitlines()
)
payload = extract / "payload"
self.assertTrue(
RUNNER.is_engine_mcp_execution_plan_materialization_slice(
"engine",
entries,
)
)
self.assertFalse(
RUNNER.is_engine_mcp_telemetry_catalog_slice("engine", entries)
)
self.assertEqual(
RUNNER.component_services("engine", entries),
("nodedc-backend",),
)
RUNNER.validate_engine_mcp_execution_plan_materialization_slice(
payload,
entries,
)
node_intelligence_descriptor = json.loads(
(
payload / RUNNER.ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL
).read_text(encoding="utf-8")
)
self.assertEqual(
node_intelligence_descriptor["source"]["gatewaySha256"],
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256[
RUNNER.ENGINE_NODE_INTELLIGENCE_GATEWAY_REL
],
)
with tempfile.TemporaryDirectory(
prefix="nodedc-engine-mcp-execution-plan-load-"
) as load_directory:
loaded = RUNNER.load_artifact(
first_artifact,
Path(load_directory),
)
self.assertEqual(tuple(loaded[1]), entries)
def test_preflight_requires_035_foundation_and_absent_new_paths(self):
with tempfile.TemporaryDirectory(
prefix="nodedc-engine-mcp-execution-plan-preflight-"
) as directory:
root = Path(directory)
hashes = {}
for mapping in (
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_PREDECESSOR_SHA256,
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256,
):
for relative_path, expected in mapping.items():
path = root / relative_path
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("installed\n", encoding="utf-8")
hashes[path] = expected
with (
mock.patch.object(RUNNER, "component_root", return_value=root),
mock.patch.object(
RUNNER,
"sha256_file",
side_effect=lambda path: hashes[Path(path)],
),
mock.patch.object(
RUNNER,
"preflight_engine_credential_backend_runtime",
return_value={"mode": "verified-derived-retry"},
),
):
result = (
RUNNER
.preflight_engine_mcp_execution_plan_materialization_predecessor()
)
self.assertEqual(
result["mode"],
"telemetry-catalog-v1-to-execution-plan-materialization-v1",
)
self.assertEqual(
result["foundation_sha256"],
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256,
)
new_path = (
root
/ RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_NEW_PATHS[0]
)
new_path.parent.mkdir(parents=True, exist_ok=True)
new_path.write_text("{}\n", encoding="utf-8")
with (
mock.patch.object(RUNNER, "component_root", return_value=root),
mock.patch.object(
RUNNER,
"sha256_file",
side_effect=lambda path: hashes[Path(path)],
),
):
with self.assertRaises(RUNNER.DeployError):
(
RUNNER
.preflight_engine_mcp_execution_plan_materialization_predecessor()
)
def test_plan_renders_external_two_phase_boundary(self):
self.require_current_target_source()
with tempfile.TemporaryDirectory(
prefix="nodedc-engine-mcp-execution-plan-plan-"
) as directory:
root = Path(directory)
artifact = Path(self.build(root / "artifacts")["artifact"])
live_root = root / "live"
live_root.mkdir()
preflight = {
"mode": "telemetry-catalog-v1-to-execution-plan-materialization-v1",
"predecessor_sha256": dict(
RUNNER
.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_PREDECESSOR_SHA256
),
"foundation_sha256": dict(
RUNNER
.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256
),
"target_sha256": dict(
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256
),
"new_paths": tuple(
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_NEW_PATHS
),
"backend_mode": "verified-derived-retry",
}
output = io.StringIO()
with (
mock.patch.object(RUNNER, "validate_artifact_location"),
mock.patch.object(RUNNER, "ensure_layout"),
mock.patch.object(RUNNER, "TMP_DIR", root),
mock.patch.object(RUNNER, "component_root", return_value=live_root),
mock.patch.object(
RUNNER,
"component_compose_root",
return_value=live_root,
),
mock.patch.object(
RUNNER,
"preflight_engine_mcp_execution_plan_materialization_predecessor",
return_value=preflight,
),
mock.patch.object(
RUNNER,
"preflight_engine_credential_backend_runtime",
return_value={"mode": "verified-derived-retry"},
),
mock.patch.object(RUNNER, "state_has_sha", return_value=False),
mock.patch.object(RUNNER, "state_has_patch_id", return_value=False),
redirect_stdout(output),
):
RUNNER.plan_artifact(artifact)
plan = output.getvalue()
self.assertIn("services=nodedc-backend", plan)
self.assertIn("engine_mcp_version=0.9.0", plan)
self.assertIn("engine_mcp_surface=external-codex", plan)
self.assertIn(
"engine_mcp_provider_logic_authority=trusted-provider-package",
plan,
)
self.assertIn(
"engine_mcp_unmanaged_graph_policy=explicit-adoption-required",
plan,
)
self.assertIn("engine_mcp_plan_phase=read-only", plan)
self.assertIn("engine_mcp_apply_phase=opaque-plan-ref-only", plan)
self.assertIn("l2_graph=untouched", plan)
self.assertIn("embedded_ai_workspace=untouched", plan)
self.assertIn("state=new", plan)
def test_healthchecks_dispatch_materialization_acceptance(self):
entries = (
RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_ARTIFACT_ENTRIES
)
with tempfile.TemporaryDirectory(
prefix="nodedc-engine-mcp-execution-plan-health-"
) as directory:
root = Path(directory)
all_hashes = {
**RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_TARGET_SHA256,
**RUNNER.ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_FOUNDATION_SHA256,
}
for relative_path in all_hashes:
path = root / relative_path
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("target\n", encoding="utf-8")
def target_hash(path):
relative_path = Path(path).relative_to(root).as_posix()
return all_hashes[relative_path]
with (
mock.patch.object(RUNNER, "component_root", return_value=root),
mock.patch.object(RUNNER, "sha256_file", side_effect=target_hash),
mock.patch.object(RUNNER, "healthcheck_compose_service"),
mock.patch.object(RUNNER, "component_healthchecks", return_value=()),
mock.patch.object(
RUNNER,
"preflight_engine_credential_backend_runtime",
return_value={"mode": "verified-derived-retry"},
),
mock.patch.object(
RUNNER,
"accept_engine_mcp_execution_plan_materialization_runtime",
return_value={"live": "accepted"},
) as acceptance,
mock.patch.object(RUNNER, "healthcheck_container"),
):
RUNNER.run_healthchecks(
"engine",
entries,
("nodedc-backend",),
)
acceptance.assert_called_once_with()
def test_live_acceptance_probes_provider_neutral_two_phase_contract(self):
expected_live = (
"engine-mcp-execution-plan-materialization:"
"0.9.0:provider-package-authority:two-phase:v1"
)
with (
mock.patch.object(RUNNER, "component_root", return_value=ENGINE_ROOT),
mock.patch.object(
RUNNER,
"validate_engine_mcp_execution_plan_materialization_slice",
),
mock.patch.object(
RUNNER,
"engine_backend_container_id",
return_value="backend",
),
mock.patch.object(
RUNNER,
"run_engine_backend_probe",
return_value=expected_live,
) as backend_probe,
):
result = (
RUNNER
.accept_engine_mcp_execution_plan_materialization_runtime()
)
self.assertEqual(result["live"], expected_live)
self.assertEqual(
backend_probe.call_args.args[1],
"Engine MCP execution plan materialization",
)
probe_source = backend_probe.call_args.args[0][-1]
self.assertIn(
"engine_plan_l2_execution_plan_materialization",
probe_source,
)
self.assertIn("unmanaged_existing", probe_source)
self.assertIn("additionalProperties!==false", probe_source)
if __name__ == "__main__":
unittest.main(verbosity=2)

View File

@ -147,15 +147,15 @@ class EngineNodeIntelligenceTest(unittest.TestCase):
) )
self.assertEqual(actual, descriptor) self.assertEqual(actual, descriptor)
def test_gateway_accepts_registered_0_8_and_rejects_unknown_successors(self): def test_gateway_accepts_registered_0_9_and_rejects_unknown_successors(self):
with tempfile.TemporaryDirectory() as directory: with tempfile.TemporaryDirectory() as directory:
payload, descriptor = self.make_activation_payload(Path(directory)) payload, descriptor = self.make_activation_payload(Path(directory))
gateway = payload / RUNNER.ENGINE_NODE_INTELLIGENCE_GATEWAY_REL gateway = payload / RUNNER.ENGINE_NODE_INTELLIGENCE_GATEWAY_REL
gateway_text = gateway.read_text(encoding="utf-8") gateway_text = gateway.read_text(encoding="utf-8")
self.assertIn("const ENGINE_AGENT_MCP_VERSION = '0.8.0'", gateway_text) self.assertIn("const ENGINE_AGENT_MCP_VERSION = '0.9.0'", gateway_text)
gateway.write_text( gateway.write_text(
gateway_text.replace( gateway_text.replace(
"const ENGINE_AGENT_MCP_VERSION = '0.8.0'", "const ENGINE_AGENT_MCP_VERSION = '0.9.0'",
"const ENGINE_AGENT_MCP_VERSION = '9.9.9'", "const ENGINE_AGENT_MCP_VERSION = '9.9.9'",
), ),
encoding="utf-8", encoding="utf-8",