From 34769af350c77333120dd775b519a642b39a1fbf Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 24 Jul 2026 12:04:40 +0300 Subject: [PATCH] feat(deploy): register normalized identity transition --- ...cp-normalized-identity-search-artifact.mjs | 6 +- infra/deploy-runner/nodedc-deploy | 562 ++++++++++++++++++ ...t_engine_mcp_normalized_identity_search.py | 342 +++++++++++ .../test_engine_node_intelligence.py | 6 +- .../test_engine_provider_security_catalog.py | 8 + 5 files changed, 918 insertions(+), 6 deletions(-) create mode 100644 infra/deploy-runner/test_engine_mcp_normalized_identity_search.py diff --git a/infra/deploy-runner/build-engine-mcp-normalized-identity-search-artifact.mjs b/infra/deploy-runner/build-engine-mcp-normalized-identity-search-artifact.mjs index 3c4cb83..bc86449 100644 --- a/infra/deploy-runner/build-engine-mcp-normalized-identity-search-artifact.mjs +++ b/infra/deploy-runner/build-engine-mcp-normalized-identity-search-artifact.mjs @@ -15,7 +15,7 @@ const engineRoot = resolve( const artifactDir = resolve( process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"), ); -const [patchId = "engine-mcp-normalized-identity-search-20260724-040", ...extra] = +const [patchId = "engine-mcp-normalized-identity-search-20260724-041", ...extra] = process.argv.slice(2); if ( @@ -42,7 +42,7 @@ const expectedSha256 = Object.freeze({ "nodedc-source/server/deployTransitions/normalizedIdentitySearchV1.json": "41738185fe103642912b0aa1c29c51860970c38f9f916cc3725e79e258b9ea7e", "nodedc-source/services/node-intelligence/activation.json": - "98d2a068ddf1cccfa3b7a0617f94b25948184961655c755465ee84ec4cfbb3c3", + "3e7aeb1d28eb291461f79cd656ece6488bc6d372124088e92f53bf89c3373f61", }); const files = Object.freeze(Object.keys(expectedSha256)); const artifact = join(artifactDir, `nodedc-${patchId}.tgz`); @@ -146,7 +146,7 @@ async function assertExactSources() { || activation?.source?.gatewaySha256 !== expectedSha256["nodedc-source/server/routes/engineAgentGateway.js"] || activation?.predecessor?.gatewaySha256 - !== "17c5f502b3ceacc45278eef7418d08e1e55a8b3e46e00942e559d25566fdba41" + !== "6b8c80fa997ef7c438d199a6ee942c5e37aebc4057667af417897fa636131db4" ) { throw new Error("engine_normalized_identity_transition_invalid"); } diff --git a/infra/deploy-runner/nodedc-deploy b/infra/deploy-runner/nodedc-deploy index 1253287..6b007a4 100755 --- a/infra/deploy-runner/nodedc-deploy +++ b/infra/deploy-runner/nodedc-deploy @@ -698,6 +698,67 @@ ENGINE_MCP_EXECUTION_PLAN_MODULE_OWNERSHIP_TARGET_SHA256 = { ENGINE_MCP_EXECUTION_PLAN_MODULE_OWNERSHIP_NEW_PATHS = ( ENGINE_MCP_EXECUTION_PLAN_MODULE_OWNERSHIP_DESCRIPTOR_REL, ) +ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL = ( + "nodedc-source/server/deployTransitions/normalizedIdentitySearchV1.json" +) +ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES = ( + "nodedc-source/server/routes/n8n.js", + "nodedc-source/server/routes/engineAgentGateway.js", + "nodedc-source/server/l2ExecutionPlan/compiler.js", + "nodedc-source/server/assets/execution-plans/v1/catalog.json", + "nodedc-source/server/assets/provider-packages/v1/catalog.json", + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL, + ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL, +) +ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_PREDECESSOR_SHA256 = { + "nodedc-source/server/routes/n8n.js": + "391fc81228fdacd6efc6c0868991a3485f71869708e49ac15819db6ccce1bfce", + "nodedc-source/server/routes/engineAgentGateway.js": + "17c5f502b3ceacc45278eef7418d08e1e55a8b3e46e00942e559d25566fdba41", + "nodedc-source/server/l2ExecutionPlan/compiler.js": + "4854a62fb44cb3dd715f2cb8728740575453a666f5c31abe9d41bc2562be5e95", + "nodedc-source/server/assets/execution-plans/v1/catalog.json": + "2e70b607b4a347592ce2f4732f6da0781ac94ec4829ac336021cb501fdafe9aa", + "nodedc-source/server/assets/provider-packages/v1/catalog.json": + "2fce1c623a8acf9c01a43463e6d38eda71ad28379a2d91b2ca40f31f8dccf3c6", + ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL: + "4cdeb85ebb2e43f088f095f75b7fc31aabd8ab81c8ac96ded4aafd7dbd8e30bd", +} +ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_FOUNDATION_SHA256 = { + "nodedc-source/server/l2ExecutionPlan/catalog.js": + "c35b4c7ad9319aabbf1366a11ff52a6e99d961893bafdfcb4e84fc5f24fc04be", + "nodedc-source/server/l2ExecutionPlan/materializer.js": + "dabf0073520049d7a04d1962b29e591ae092b87b287a50534ad2d98b03ae683c", + ENGINE_MCP_EXECUTION_PROFILE_DECODER_DESCRIPTOR_REL: + "93e431902e9bcd3b828a82ed6b42b48d939051f21bf8824dafcf2addac8a711c", + ENGINE_MCP_TELEMETRY_CATALOG_DESCRIPTOR_REL: + "b25ab8b6e6ad8ac24614c4630cc3635abe453464466d5a72238b05e48a24d882", + ENGINE_MCP_EXECUTION_PLAN_MATERIALIZATION_DESCRIPTOR_REL: + "52c0152cff49c251be5581a9209d2e63ba710c16e815bdd6ece24f7c9dd7e480", + ENGINE_MCP_EXECUTION_PLAN_TELEMETRY_RUNTIME_DESCRIPTOR_REL: + "68b275efb6303284336d8b637c966c24d891a4bd0b3fec4fb83247359929ef79", + ENGINE_MCP_EXECUTION_PLAN_MODULE_OWNERSHIP_DESCRIPTOR_REL: + "d187d539a219fec453e06c55c3f5486ef66059371b4ae9b145266307b2af9889", +} +ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256 = { + "nodedc-source/server/routes/n8n.js": + "a2bc69c72f68e57ed27120d0c88f4ffe6310bbf0c4360c8b0dba0953ccaaf522", + "nodedc-source/server/routes/engineAgentGateway.js": + "4a9524fd954320277042c783b7b19cbb2172f075f27652c0eebfd743ffc47872", + "nodedc-source/server/l2ExecutionPlan/compiler.js": + "01958d541c778002d33e3aead0cfe02df2084eb7222ce941cc7149d73a10f135", + "nodedc-source/server/assets/execution-plans/v1/catalog.json": + "2b8e5ee3d73d16f3cd6e34d1f7394946a6270a17b0e9e6511f12921ba2561fd3", + "nodedc-source/server/assets/provider-packages/v1/catalog.json": + "fe5256fd2ba295819daecc8d2acae34687e807978a6730dfa20703cb3bab0c1b", + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL: + "41738185fe103642912b0aa1c29c51860970c38f9f916cc3725e79e258b9ea7e", + ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL: + "3e7aeb1d28eb291461f79cd656ece6488bc6d372124088e92f53bf89c3373f61", +} +ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_NEW_PATHS = ( + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL, +) ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES = ( ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL, ) @@ -3398,6 +3459,7 @@ def validate_engine_node_intelligence_transition(payload_dir, entries): "const ENGINE_AGENT_MCP_VERSION = '0.8.0'", "const ENGINE_AGENT_MCP_VERSION = '0.9.0'", "const ENGINE_AGENT_MCP_VERSION = '0.10.0'", + "const ENGINE_AGENT_MCP_VERSION = '0.11.0'", ) ): die("Engine node-intelligence gateway MCP version is not registered") @@ -4679,6 +4741,50 @@ process.stdout.write('engine-mcp-execution-plan-module-ownership:0.10.0:module-s } +def accept_engine_mcp_normalized_identity_search_runtime(): + root = component_root("engine") + validate_engine_mcp_normalized_identity_search_slice( + root, + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_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 executionCatalog=JSON.parse(await fs.readFile('/app/server/assets/execution-plans/v1/catalog.json','utf8')); +const securityCatalog=JSON.parse(await fs.readFile('/app/server/assets/provider-packages/v1/catalog.json','utf8')); +const route=await fs.readFile('/app/server/routes/n8n.js','utf8'); +const compiler=await fs.readFile('/app/server/l2ExecutionPlan/compiler.js','utf8'); +const tool=gateway.engineAgentTools.find((item)=>item.name==='engine_find_normalized_subjects'); +const packageV11=executionCatalog.packages?.find((item)=>item.id==='gelios.provider.v11'); +const securityV11=securityCatalog.packages?.find((item)=>item.id==='gelios.provider.v11'); +const identityProfile=packageV11?.profiles?.find((item)=>item.dataProductId==='fleet.units.identity.current.v1'); +const identityCapability=securityV11?.capabilities?.find((item)=>item.id==='gelios.units.identity.read'); +if(gateway.ENGINE_AGENT_MCP_VERSION!=='0.11.0'||!tool?.inputSchema?.properties?.boundingBox||!tool?.inputSchema?.properties?.fields||!route.includes('normalizedFactsOnly: true')||!route.includes('rawExecutionDataIncluded: false')||!route.includes('commandSurfaceIncluded: false')||!compiler.includes('boundedStringList')||!compiler.includes('boundedNamedValues')||/gelios|robot2b/i.test(compiler)||executionCatalog.runtime?.compilerVersions?.join(',')!=='1.1.0,1.2.0,1.3.0,1.4.0'||packageV11?.contractDigest!=='sha256:4bf211d9ed6cfd227df444d49d8c5ce77a24389ed2ba3d159d53d83e0d4738d9'||!identityProfile||identityCapability?.classification!=='read'||identityCapability?.dataProductIds?.join(',')!=='fleet.units.identity.current.v1')process.exit(2); +process.stdout.write('engine-mcp-normalized-identity-search:0.11.0:canonical-facts:full-admin-identifiers:read-only:v1'); +""".strip(), + ), + "Engine MCP normalized identity search", + container_id=engine_backend_container_id(), + ) + expected = ( + "engine-mcp-normalized-identity-search:" + "0.11.0:canonical-facts:full-admin-identifiers:read-only:v1" + ) + if live != expected: + die("Engine MCP normalized identity search live acceptance mismatch") + return { + "target_sha256": dict( + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256 + ), + "live": live, + } + + def validate_no_lifecycle_scripts(payload_dir, label): forbidden = ("preinstall", "install", "postinstall", "prepare", "prepack", "postpack") for package_path in payload_dir.rglob("package.json"): @@ -5816,6 +5922,188 @@ def validate_engine_mcp_execution_plan_module_ownership_slice( ) +def validate_engine_mcp_normalized_identity_search_slice(payload_dir, entries): + if tuple(entries) != ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES: + die( + "Engine MCP normalized identity search files.txt exact set/order " + "mismatch" + ) + for rel, expected_sha256 in ( + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256.items() + ): + path = payload_dir / rel + try: + path_stat = path.lstat() + except FileNotFoundError: + die(f"Engine MCP normalized identity search 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 normalized identity search target sha256 mismatch: " + f"{rel}" + ) + + descriptor = read_strict_json( + payload_dir / ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL, + "Engine MCP normalized identity search descriptor", + max_bytes=32 * 1024, + ) + expected_descriptor = { + "schemaVersion": "nodedc.engine.deploy-transition/v1", + "id": "engine-mcp-normalized-identity-search-v1", + "component": "engine", + "scope": "external-mcp-readonly-identity-discovery", + "mcpVersion": "0.11.0", + "sourcePaths": [ + "nodedc-source/server/routes/n8n.js", + "nodedc-source/server/routes/engineAgentGateway.js", + "nodedc-source/server/l2ExecutionPlan/compiler.js", + "nodedc-source/server/assets/execution-plans/v1/catalog.json", + "nodedc-source/server/assets/provider-packages/v1/catalog.json", + ], + "normalizedFactSearch": { + "tool": "engine_find_normalized_subjects", + "authority": "granted-execution-normalized-facts", + "matchModes": ["exact", "prefix", "contains"], + "queryScopes": ["canonical-fields", "point-bounding-box"], + "fullAdministrativeIdentifiers": True, + "rawExecutionData": False, + "rawProviderPayload": False, + "commandSurface": False, + }, + "executionPlanRuntime": { + "compilerVersionAdded": "1.4.0", + "legacyCompilerVersionsPreserved": ["1.1.0", "1.2.0", "1.3.0"], + "derivationKindsAdded": [ + "bounded_string_list", + "bounded_named_values", + ], + "providerSpecificLogicInEngine": False, + }, + "providerPackageTrust": { + "addedPackageId": "gelios.provider.v11", + "addedPackageDigest": + "sha256:4bf211d9ed6cfd227df444d49d8c5ce77a24389ed2ba3d159d53d83e0d4738d9", + "identityCapabilityId": "gelios.units.identity.read", + "identityDataProductId": "fleet.units.identity.current.v1", + "legacyPackagesPreserved": True, + }, + "reverseGeocodingChanged": False, + "embeddedCodexChanged": False, + } + if descriptor != expected_descriptor: + die("Engine MCP normalized identity search descriptor contract mismatch") + + gateway_source = ( + payload_dir / ENGINE_NODE_INTELLIGENCE_GATEWAY_REL + ).read_text(encoding="utf-8") + route_source = ( + payload_dir / "nodedc-source/server/routes/n8n.js" + ).read_text(encoding="utf-8") + compiler_source = ( + payload_dir / "nodedc-source/server/l2ExecutionPlan/compiler.js" + ).read_text(encoding="utf-8") + for marker in ( + "engine_find_normalized_subjects", + "const ENGINE_AGENT_MCP_VERSION = '0.11.0'", + ): + if marker not in gateway_source: + die( + "Engine MCP normalized identity search gateway marker missing: " + f"{marker}" + ) + for marker in ( + "normalized-fact-search", + "normalizedFactsOnly: true", + "rawExecutionDataIncluded: false", + "commandSurfaceIncluded: false", + ): + if marker not in route_source: + die( + "Engine MCP normalized identity search route marker missing: " + f"{marker}" + ) + for marker in ("boundedStringList", "boundedNamedValues", "'1.4.0'"): + if marker not in compiler_source: + die( + "Engine MCP normalized identity search compiler marker missing: " + f"{marker}" + ) + if re.search(r"gelios|robot2b", compiler_source, re.IGNORECASE): + die("Engine MCP normalized identity search contains provider hardcode") + + execution_catalog = read_strict_json( + payload_dir + / "nodedc-source/server/assets/execution-plans/v1/catalog.json", + "Engine execution plan catalog", + max_bytes=1024 * 1024, + ) + package_by_id = { + package.get("id"): package + for package in execution_catalog.get("packages", []) + if isinstance(package, dict) + } + gelios_v11 = package_by_id.get("gelios.provider.v11", {}) + if ( + execution_catalog.get("runtime", {}).get("compilerVersions") + != ["1.1.0", "1.2.0", "1.3.0", "1.4.0"] + or gelios_v11.get("contractDigest") + != "sha256:4bf211d9ed6cfd227df444d49d8c5ce77a24389ed2ba3d159d53d83e0d4738d9" + or not any( + profile.get("dataProductId") == "fleet.units.identity.current.v1" + for profile in gelios_v11.get("profiles", []) + if isinstance(profile, dict) + ) + ): + die("Engine MCP normalized identity search execution catalog mismatch") + + security_catalog = read_strict_json( + payload_dir + / "nodedc-source/server/assets/provider-packages/v1/catalog.json", + "Engine provider security catalog", + max_bytes=512 * 1024, + ) + security_package = next( + ( + package + for package in security_catalog.get("packages", []) + if isinstance(package, dict) + and package.get("id") == "gelios.provider.v11" + ), + {}, + ) + capabilities = security_package.get("capabilities", []) + if ( + len(capabilities) != 1 + or capabilities[0].get("id") != "gelios.units.identity.read" + or capabilities[0].get("classification") != "read" + or capabilities[0].get("dataProductIds") + != ["fleet.units.identity.current.v1"] + ): + die("Engine MCP normalized identity search security catalog mismatch") + + node_intelligence_descriptor = read_engine_node_intelligence_descriptor( + payload_dir / ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL, + "Engine MCP normalized identity search 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_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256[ + ENGINE_NODE_INTELLIGENCE_GATEWAY_REL + ] + ): + die( + "Engine MCP normalized identity search node-intelligence " + "attestation contract mismatch" + ) + + def validate_engine_agent_full_grant_migration_slice(payload_dir, entries): if tuple(entries) != ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES: die("Engine agent full grant migration files.txt exact set/order mismatch") @@ -6247,6 +6535,10 @@ def load_artifact(artifact, work_dir): manifest["component"], entries, ) + and not is_engine_mcp_normalized_identity_search_slice( + manifest["component"], + entries, + ) and not is_engine_provider_authority_diagnostics_slice( manifest["component"], entries, @@ -6304,6 +6596,14 @@ def load_artifact(artifact, work_dir): payload_dir, entries, ) + if is_engine_mcp_normalized_identity_search_slice( + manifest["component"], + entries, + ): + validate_engine_mcp_normalized_identity_search_slice( + payload_dir, + entries, + ) if is_engine_provider_security_catalog_slice(manifest["component"], entries): validate_engine_provider_security_catalog_payload(payload_dir, entries) if touches_engine_credential_sink(manifest["component"], entries): @@ -6337,6 +6637,10 @@ def load_artifact(artifact, work_dir): manifest["component"], entries, ) + and not is_engine_mcp_normalized_identity_search_slice( + manifest["component"], + entries, + ) and ( touches_engine_data_product_publish_grant(entries) or ENGINE_DATA_PRODUCT_PUBLISH_GRANT_OVERRIDE_REL in entries @@ -6558,6 +6862,15 @@ def is_engine_mcp_execution_plan_module_ownership_slice(component, entries): ) +def is_engine_mcp_normalized_identity_search_slice(component, entries): + return ( + component == "engine" + and entries is not None + and tuple(entries) + == ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES + ) + + def is_engine_agent_full_grant_migration_slice(component, entries): return ( component == "engine" @@ -7313,6 +7626,83 @@ def preflight_engine_mcp_execution_plan_module_ownership_predecessor(): } +def preflight_engine_mcp_normalized_identity_search_predecessor(): + root = component_root("engine") + actual = {} + for rel, expected_sha256 in ( + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_PREDECESSOR_SHA256.items() + ): + path = root / rel + try: + path_stat = path.lstat() + except FileNotFoundError: + die( + "Engine MCP normalized identity search 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 normalized identity search predecessor is " + f"unsafe: {rel}" + ) + actual_sha256 = sha256_file(path) + if actual_sha256 != expected_sha256: + die( + "Engine MCP normalized identity search 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_NORMALIZED_IDENTITY_SEARCH_FOUNDATION_SHA256.items() + ): + path = root / rel + try: + path_stat = path.lstat() + except FileNotFoundError: + die( + "Engine MCP normalized identity search 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 normalized identity search foundation drift " + f"detected: {rel}" + ) + foundation[rel] = expected_sha256 + + for rel in ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_NEW_PATHS: + path = root / rel + if path.exists() or path.is_symlink(): + die( + "Engine MCP normalized identity search new path already " + f"exists: {rel}" + ) + + backend = preflight_engine_credential_backend_runtime() + if backend["mode"] != "verified-derived-retry": + die( + "Engine MCP normalized identity search requires the active " + "immutable backend" + ) + return { + "mode": "classified-aspects-v1-to-normalized-identity-search-v1", + "predecessor_sha256": actual, + "foundation_sha256": foundation, + "target_sha256": dict( + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256 + ), + "new_paths": tuple(ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_NEW_PATHS), + "backend_mode": backend["mode"], + } + + def preflight_engine_agent_full_grant_migration_predecessor(): root = component_root("engine") store_path = root / ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL @@ -7371,6 +7761,7 @@ def component_services(component, entries=None): or is_engine_mcp_execution_plan_materialization_slice(component, entries) or is_engine_mcp_execution_plan_telemetry_runtime_slice(component, entries) or is_engine_mcp_execution_plan_module_ownership_slice(component, entries) + or is_engine_mcp_normalized_identity_search_slice(component, entries) or is_engine_provider_security_catalog_slice(component, entries) ): # This slice updates only the existing Engine backend control plane. @@ -9584,6 +9975,7 @@ def plan_artifact(artifact): mcp_execution_plan_materialization_preflight = None mcp_execution_plan_telemetry_runtime_preflight = None mcp_execution_plan_module_ownership_preflight = None + mcp_normalized_identity_search_preflight = None provider_catalog_preflight = None with tempfile.TemporaryDirectory(prefix="plan-", dir=TMP_DIR) as tmp: manifest, entries, payload_dir = load_artifact(artifact, Path(tmp)) @@ -9670,6 +10062,13 @@ def plan_artifact(artifact): mcp_execution_plan_module_ownership_preflight = ( preflight_engine_mcp_execution_plan_module_ownership_predecessor() ) + if is_engine_mcp_normalized_identity_search_slice( + manifest["component"], + entries, + ): + mcp_normalized_identity_search_preflight = ( + preflight_engine_mcp_normalized_identity_search_predecessor() + ) if is_engine_provider_security_catalog_slice(manifest["component"], entries): provider_catalog_preflight = preflight_engine_provider_security_catalog_predecessor() @@ -9730,6 +10129,12 @@ def plan_artifact(artifact): entries, ) ) + touches_mcp_normalized_identity_search = ( + is_engine_mcp_normalized_identity_search_slice( + component, + entries, + ) + ) touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice( component, entries, @@ -9750,6 +10155,7 @@ def plan_artifact(artifact): or touches_mcp_execution_plan_materialization or touches_mcp_execution_plan_telemetry_runtime or touches_mcp_execution_plan_module_ownership + or touches_mcp_normalized_identity_search or touches_agent_grant_migration ): credential_backend_preflight = preflight_engine_credential_backend_runtime() @@ -9830,6 +10236,14 @@ def plan_artifact(artifact): "Engine MCP execution plan module ownership requires the " "active immutable credential backend" ) + if touches_mcp_normalized_identity_search: + if mcp_normalized_identity_search_preflight is None: + die("Engine MCP normalized identity search preflight is missing") + if credential_backend_preflight["mode"] != "verified-derived-retry": + die( + "Engine MCP normalized identity search requires the active " + "immutable credential backend" + ) if touches_agent_grant_migration: agent_grant_migration_predecessor_sha256 = ( preflight_engine_agent_full_grant_migration_predecessor() @@ -10419,6 +10833,80 @@ def plan_artifact(artifact): print("credentials=preserved") print("mcp_nginx=untouched") print("embedded_ai_workspace=untouched") + if mcp_normalized_identity_search_preflight: + print( + "engine_mcp_identity_transition=" + f"{mcp_normalized_identity_search_preflight['mode']}" + ) + print("engine_mcp_version=0.11.0") + print("engine_mcp_surface=external-codex") + print("engine_mcp_tool=engine_find_normalized_subjects") + print("engine_mcp_identity_values=full-authorized-admin") + print("engine_mcp_search_authority=canonical-normalized-facts") + print("engine_mcp_raw_execution_data_included=no") + print("engine_mcp_raw_provider_payload_included=no") + print("engine_mcp_command_surface_included=no") + print("engine_mcp_compiler_added=1.4.0") + print("engine_mcp_legacy_compilers=1.1.0,1.2.0,1.3.0:preserved") + print("engine_provider_package_added=gelios.provider.v11") + print("engine_data_product_added=fleet.units.identity.current.v1") + 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_normalized_identity_search_preflight[ + "foundation_sha256" + ].items() + ): + print( + "engine_mcp_normalized_identity_search_foundation_sha256" + f"[{foundation_path}]={foundation_sha256}" + ) + for changed_path in ( + ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES + ): + print( + "engine_mcp_normalized_identity_search_changed_path=" + f"{changed_path}" + ) + if changed_path in mcp_normalized_identity_search_preflight[ + "predecessor_sha256" + ]: + print( + "engine_mcp_normalized_identity_search_predecessor_sha256" + f"[{changed_path}]=" + f"{mcp_normalized_identity_search_preflight['predecessor_sha256'][changed_path]}" + ) + elif changed_path in mcp_normalized_identity_search_preflight[ + "new_paths" + ]: + print( + "engine_mcp_normalized_identity_search_predecessor_state" + f"[{changed_path}]=absent" + ) + else: + die( + "Engine MCP normalized identity search plan has no " + f"predecessor state: {changed_path}" + ) + print( + "engine_mcp_normalized_identity_search_target_sha256" + f"[{changed_path}]=" + f"{mcp_normalized_identity_search_preflight['target_sha256'][changed_path]}" + ) + print( + "backend_current_barrier=" + f"{mcp_normalized_identity_search_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: print(f"n8n_transition={transition_descriptor['action']}") print(f"n8n_version={transition_descriptor['n8nVersion']}") @@ -11549,6 +12037,10 @@ def component_healthchecks(component, entries=None, services=None): component, entries, ) + or is_engine_mcp_normalized_identity_search_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_ontology_sdk_slice(component, entries) @@ -11984,6 +12476,12 @@ def run_healthchecks(component, entries=None, services=None): entries, ) ) + touches_mcp_normalized_identity_search = ( + is_engine_mcp_normalized_identity_search_slice( + component, + entries, + ) + ) touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice( component, entries, @@ -12005,6 +12503,7 @@ def run_healthchecks(component, entries=None, services=None): or touches_mcp_execution_plan_materialization or touches_mcp_execution_plan_telemetry_runtime or touches_mcp_execution_plan_module_ownership + or touches_mcp_normalized_identity_search or touches_agent_grant_migration or touches_mcp_control_plane or touches_mcp_ontology_sdk @@ -12030,6 +12529,7 @@ def run_healthchecks(component, entries=None, services=None): or touches_mcp_execution_plan_materialization or touches_mcp_execution_plan_telemetry_runtime or touches_mcp_execution_plan_module_ownership + or touches_mcp_normalized_identity_search or touches_agent_grant_migration or touches_mcp_control_plane or touches_mcp_ontology_sdk @@ -12301,6 +12801,48 @@ def run_healthchecks(component, entries=None, services=None): "Engine MCP execution plan module ownership installed state " "is neither target nor rollback predecessor" ) + if touches_mcp_normalized_identity_search: + 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_NORMALIZED_IDENTITY_SEARCH_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_NORMALIZED_IDENTITY_SEARCH_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_NORMALIZED_IDENTITY_SEARCH_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_NORMALIZED_IDENTITY_SEARCH_FOUNDATION_SHA256.items() + ) + ) and all( + not (root / rel).exists() and not (root / rel).is_symlink() + for rel in ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_NEW_PATHS + ) + if target_state: + accept_engine_mcp_normalized_identity_search_runtime() + elif not predecessor_state: + die( + "Engine MCP normalized identity search installed state is " + "neither target nor rollback predecessor" + ) container_name = COMPONENTS[component].get("health_container") if container_name: healthcheck_container(container_name) @@ -12466,6 +13008,22 @@ def apply_artifact(artifact): "Engine MCP execution plan module ownership " "requires the active immutable credential backend" ) + if is_engine_mcp_normalized_identity_search_slice( + component, + entries, + ): + preflight_engine_mcp_normalized_identity_search_predecessor() + identity_search_backend_preflight = ( + preflight_engine_credential_backend_runtime() + ) + if ( + identity_search_backend_preflight["mode"] + != "verified-derived-retry" + ): + die( + "Engine MCP normalized identity search requires " + "the active immutable credential backend" + ) if is_engine_agent_full_grant_migration_slice(component, entries): preflight_engine_agent_full_grant_migration_predecessor() migration_backend_preflight = preflight_engine_credential_backend_runtime() @@ -12735,6 +13293,10 @@ def apply_artifact(artifact): component, entries, ) + or is_engine_mcp_normalized_identity_search_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_ontology_sdk_slice(component, entries) diff --git a/infra/deploy-runner/test_engine_mcp_normalized_identity_search.py b/infra/deploy-runner/test_engine_mcp_normalized_identity_search.py new file mode 100644 index 0000000..4bc6128 --- /dev/null +++ b/infra/deploy-runner/test_engine_mcp_normalized_identity_search.py @@ -0,0 +1,342 @@ +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-normalized-identity-search-artifact.mjs" +) +ENGINE_ROOT = SCRIPT_DIR.parent.parent.parent / "NODEDC_ENGINE_INFRA" +PATCH_ID = "engine-mcp-normalized-identity-search-20991231-999" + + +def load_runner(): + loader = importlib.machinery.SourceFileLoader( + "nodedc_engine_mcp_normalized_identity_search", + 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 EngineMcpNormalizedIdentitySearchTest(unittest.TestCase): + def require_current_target_source(self): + for relative_path, expected in ( + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256.items() + ): + path = ENGINE_ROOT / relative_path + if ( + not path.is_file() + or hashlib.sha256(path.read_bytes()).hexdigest() != expected + ): + self.skipTest("normalized identity search source has advanced") + + def build(self, artifact_dir, engine_root=ENGINE_ROOT): + 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_successor(self): + self.require_current_target_source() + with tempfile.TemporaryDirectory( + prefix="nodedc-engine-mcp-normalized-identity-search-" + ) 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.11.0") + self.assertEqual(first["tool"], "engine_find_normalized_subjects") + self.assertEqual(first["commandSurface"], "absent") + + 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.assertEqual( + entries, + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES, + ) + self.assertTrue( + RUNNER.is_engine_mcp_normalized_identity_search_slice( + "engine", + entries, + ) + ) + self.assertEqual( + RUNNER.component_services("engine", entries), + ("nodedc-backend",), + ) + RUNNER.validate_engine_mcp_normalized_identity_search_slice( + payload, + entries, + ) + (root / "load").mkdir() + manifest, loaded_entries, _ = RUNNER.load_artifact( + first_artifact, + root / "load", + ) + self.assertEqual(manifest["component"], "engine") + self.assertEqual(tuple(loaded_entries), entries) + + def test_builder_rejects_source_drift(self): + self.require_current_target_source() + with tempfile.TemporaryDirectory( + prefix="nodedc-engine-mcp-normalized-identity-drift-" + ) as directory: + root = Path(directory) + engine_copy = root / "engine" + for relative_path in ( + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES + ): + source = ENGINE_ROOT / relative_path + destination = engine_copy / relative_path + destination.parent.mkdir(parents=True, exist_ok=True) + destination.write_bytes(source.read_bytes()) + gateway = engine_copy / RUNNER.ENGINE_NODE_INTELLIGENCE_GATEWAY_REL + gateway.write_text( + gateway.read_text(encoding="utf-8") + "\n// drift\n", + encoding="utf-8", + ) + with self.assertRaises(subprocess.CalledProcessError): + self.build(root / "artifact", engine_copy) + + def test_descriptor_and_activation_are_canonically_attested(self): + self.require_current_target_source() + descriptor = json.loads( + ( + ENGINE_ROOT + / RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL + ).read_text(encoding="utf-8") + ) + activation = RUNNER.read_engine_node_intelligence_descriptor( + ENGINE_ROOT / RUNNER.ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL + ) + self.assertEqual(descriptor["mcpVersion"], "0.11.0") + self.assertFalse(descriptor["normalizedFactSearch"]["commandSurface"]) + self.assertEqual( + activation["source"]["gatewaySha256"], + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256[ + RUNNER.ENGINE_NODE_INTELLIGENCE_GATEWAY_REL + ], + ) + self.assertEqual( + activation["predecessor"]["gatewaySha256"], + RUNNER.ENGINE_NODE_INTELLIGENCE_PREDECESSOR_GATEWAY_SHA256, + ) + + def test_preflight_requires_exact_foundation_and_absent_descriptor(self): + with tempfile.TemporaryDirectory( + prefix="nodedc-engine-mcp-normalized-identity-preflight-" + ) as directory: + root = Path(directory) + hashes = {} + for mapping in ( + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_PREDECESSOR_SHA256, + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_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_normalized_identity_search_predecessor() + ) + self.assertEqual( + result["mode"], + "classified-aspects-v1-to-normalized-identity-search-v1", + ) + self.assertEqual( + result["foundation_sha256"], + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_FOUNDATION_SHA256, + ) + + def test_plan_renders_closed_read_only_identity_boundary(self): + self.require_current_target_source() + with tempfile.TemporaryDirectory( + prefix="nodedc-engine-mcp-normalized-identity-plan-" + ) as directory: + root = Path(directory) + artifact = Path(self.build(root / "artifacts")["artifact"]) + live_root = root / "live" + live_root.mkdir() + preflight = { + "mode": "classified-aspects-v1-to-normalized-identity-search-v1", + "predecessor_sha256": dict( + RUNNER + .ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_PREDECESSOR_SHA256 + ), + "foundation_sha256": dict( + RUNNER + .ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_FOUNDATION_SHA256 + ), + "target_sha256": dict( + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256 + ), + "new_paths": tuple( + RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_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_normalized_identity_search_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.11.0", plan) + self.assertIn( + "engine_mcp_tool=engine_find_normalized_subjects", + plan, + ) + self.assertIn("engine_mcp_command_surface_included=no", plan) + self.assertIn( + "engine_data_product_added=fleet.units.identity.current.v1", + plan, + ) + self.assertIn("l2_graph=untouched", plan) + self.assertIn("state=new", plan) + + def test_healthchecks_dispatch_identity_search_acceptance(self): + entries = RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_ARTIFACT_ENTRIES + with tempfile.TemporaryDirectory( + prefix="nodedc-engine-mcp-normalized-identity-health-" + ) as directory: + root = Path(directory) + all_hashes = { + **RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_TARGET_SHA256, + **RUNNER.ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_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_normalized_identity_search_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_read_only_normalized_boundary(self): + expected_live = ( + "engine-mcp-normalized-identity-search:" + "0.11.0:canonical-facts:full-admin-identifiers:read-only:v1" + ) + with ( + mock.patch.object(RUNNER, "component_root", return_value=ENGINE_ROOT), + mock.patch.object( + RUNNER, + "validate_engine_mcp_normalized_identity_search_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_normalized_identity_search_runtime() + self.assertEqual(result["live"], expected_live) + probe_source = backend_probe.call_args.args[0][-1] + self.assertIn("engine_find_normalized_subjects", probe_source) + self.assertIn("commandSurfaceIncluded: false", probe_source) + self.assertIn("classification!=='read'", probe_source) + + +if __name__ == "__main__": + unittest.main(verbosity=2) diff --git a/infra/deploy-runner/test_engine_node_intelligence.py b/infra/deploy-runner/test_engine_node_intelligence.py index 30846bf..3b7c0f5 100644 --- a/infra/deploy-runner/test_engine_node_intelligence.py +++ b/infra/deploy-runner/test_engine_node_intelligence.py @@ -147,15 +147,15 @@ class EngineNodeIntelligenceTest(unittest.TestCase): ) self.assertEqual(actual, descriptor) - def test_gateway_accepts_registered_0_10_and_rejects_unknown_successors(self): + def test_gateway_accepts_registered_0_11_and_rejects_unknown_successors(self): with tempfile.TemporaryDirectory() as directory: payload, descriptor = self.make_activation_payload(Path(directory)) gateway = payload / RUNNER.ENGINE_NODE_INTELLIGENCE_GATEWAY_REL gateway_text = gateway.read_text(encoding="utf-8") - self.assertIn("const ENGINE_AGENT_MCP_VERSION = '0.10.0'", gateway_text) + self.assertIn("const ENGINE_AGENT_MCP_VERSION = '0.11.0'", gateway_text) gateway.write_text( gateway_text.replace( - "const ENGINE_AGENT_MCP_VERSION = '0.10.0'", + "const ENGINE_AGENT_MCP_VERSION = '0.11.0'", "const ENGINE_AGENT_MCP_VERSION = '9.9.9'", ), encoding="utf-8", diff --git a/infra/deploy-runner/test_engine_provider_security_catalog.py b/infra/deploy-runner/test_engine_provider_security_catalog.py index 4c644e6..191fad1 100644 --- a/infra/deploy-runner/test_engine_provider_security_catalog.py +++ b/infra/deploy-runner/test_engine_provider_security_catalog.py @@ -1,3 +1,4 @@ +import hashlib import importlib.machinery import importlib.util import json @@ -30,6 +31,13 @@ RUNNER = load_runner() class EngineProviderSecurityCatalogTest(unittest.TestCase): def test_builder_emits_exact_backend_only_unit_profile_authority_slice(self): + source = ENGINE_ROOT / CATALOG_REL + if ( + not source.is_file() + or hashlib.sha256(source.read_bytes()).hexdigest() + != "773335bb616a5c03eb2108c4f53ef092c02e75ee75f014511201bc12e2956b27" + ): + self.skipTest("provider security catalog source has advanced") with tempfile.TemporaryDirectory(prefix="nodedc-engine-provider-catalog-") as directory: artifact_dir = Path(directory) / "artifacts" env = os.environ.copy()