refactor: route runtime integration via adapter table
This commit is contained in:
@@ -6,6 +6,7 @@ import { loadDeploymentProfileArtifact, createDeploymentBindingContract, assertU
|
||||
export function runOrchestratorAdapter({
|
||||
scriptPath = null,
|
||||
runtimeBinding = null,
|
||||
deploymentBinding = null,
|
||||
profileArtifact = null,
|
||||
profileArtifactPath = null,
|
||||
profileId = null,
|
||||
@@ -28,26 +29,28 @@ export function runOrchestratorAdapter({
|
||||
claim = false,
|
||||
dryRun = false,
|
||||
} = {}) {
|
||||
const deploymentBinding = profileArtifact || profileArtifactPath || profileId
|
||||
? createDeploymentBindingContract({
|
||||
artifact: profileArtifact ?? loadDeploymentProfileArtifact({ artifactPath: profileArtifactPath, profileId }).artifact,
|
||||
repoRootOverride,
|
||||
})
|
||||
: null;
|
||||
const resolvedDeploymentBinding = deploymentBinding ?? (
|
||||
profileArtifact || profileArtifactPath || profileId
|
||||
? createDeploymentBindingContract({
|
||||
artifact: profileArtifact ?? loadDeploymentProfileArtifact({ artifactPath: profileArtifactPath, profileId }).artifact,
|
||||
repoRootOverride,
|
||||
})
|
||||
: null
|
||||
);
|
||||
|
||||
const binding = runtimeBinding ?? createRuntimeBinding({
|
||||
cwd: repoRootOverride,
|
||||
scripts: deploymentBinding?.scripts,
|
||||
scripts: resolvedDeploymentBinding?.scripts,
|
||||
});
|
||||
const resolvedScriptPath = path.resolve(scriptPath ?? deploymentBinding?.entrypoint ?? resolveScriptPath('orchestrator', { runtimeBinding: binding }));
|
||||
const resolvedScriptPath = path.resolve(scriptPath ?? resolvedDeploymentBinding?.entrypoint ?? resolveScriptPath('orchestrator', { runtimeBinding: binding }));
|
||||
const resolvedWatchdogScript = path.resolve(watchdogScript ?? resolveScriptPath('watchdog', { runtimeBinding: binding }));
|
||||
const resolvedDispatcherScript = path.resolve(dispatcherScript ?? resolveScriptPath('dispatcher', { runtimeBinding: binding }));
|
||||
const resolvedSupervisorScript = path.resolve(supervisorScript ?? resolveScriptPath('bridgeSupervisor', { runtimeBinding: binding }));
|
||||
|
||||
const resolvedQueueDir = queueDir
|
||||
? path.resolve(queueDir)
|
||||
: deploymentBinding?.artifactRoots?.queueItems
|
||||
? assertUseTimePathWithinRepoRoot(deploymentBinding.artifactRoots.queueItems, 'orchestrator adapter queueDir', { repoRootOverride, allowMissingLeaf: true })
|
||||
: resolvedDeploymentBinding?.artifactRoots?.queueItems
|
||||
? assertUseTimePathWithinRepoRoot(resolvedDeploymentBinding.artifactRoots.queueItems, 'orchestrator adapter queueDir', { repoRootOverride, allowMissingLeaf: true })
|
||||
: null;
|
||||
const resolvedSpoolDir = spoolDir
|
||||
? path.resolve(spoolDir)
|
||||
|
||||
@@ -1,6 +1,75 @@
|
||||
import { executeGovernanceContract } from './execute-governance-contract.mjs';
|
||||
import { runOrchestratorAdapter } from '../adapters/orchestrator.mjs';
|
||||
|
||||
const ACTION_ADAPTER_ROUTING = Object.freeze({
|
||||
notify_operator: {
|
||||
adapter: 'orchestrator',
|
||||
reason: 'deployment binding + adapter action routed into orchestrator adapter',
|
||||
run: ({ governance, repoRootOverride, runtime }) => runOrchestratorAdapter({
|
||||
deploymentBinding: governance.deploymentBinding,
|
||||
repoRootOverride,
|
||||
...runtime,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
function resolveRuntimeRoute({ governance, runtime, repoRootOverride }) {
|
||||
if (!runtime) {
|
||||
return {
|
||||
attempted: false,
|
||||
adapter: null,
|
||||
action: null,
|
||||
reason: 'runtime execution not attempted',
|
||||
runtimeExecution: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (governance.preflight?.status !== 'pass') {
|
||||
return {
|
||||
attempted: false,
|
||||
adapter: null,
|
||||
action: null,
|
||||
reason: 'runtime execution not attempted: compatibility preflight did not pass',
|
||||
runtimeExecution: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (!governance.deploymentBinding) {
|
||||
return {
|
||||
attempted: false,
|
||||
adapter: null,
|
||||
action: null,
|
||||
reason: 'runtime execution not attempted: deployment binding is missing',
|
||||
runtimeExecution: null,
|
||||
};
|
||||
}
|
||||
|
||||
const adapterActions = Array.isArray(governance.contract?.adapter_actions)
|
||||
? governance.contract.adapter_actions
|
||||
: [];
|
||||
|
||||
for (const action of adapterActions) {
|
||||
const route = ACTION_ADAPTER_ROUTING[action];
|
||||
if (!route) continue;
|
||||
|
||||
return {
|
||||
attempted: true,
|
||||
adapter: route.adapter,
|
||||
action,
|
||||
reason: route.reason,
|
||||
runtimeExecution: route.run({ governance, runtime, repoRootOverride }),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
attempted: false,
|
||||
adapter: null,
|
||||
action: null,
|
||||
reason: 'runtime execution not attempted: no routed adapter action matched runtime integration table',
|
||||
runtimeExecution: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function executeRuntimeIntegratedGovernance({
|
||||
event,
|
||||
evidence = [],
|
||||
@@ -23,30 +92,25 @@ export function executeRuntimeIntegratedGovernance({
|
||||
repoRootOverride,
|
||||
});
|
||||
|
||||
const shouldRunOrchestrator = Boolean(
|
||||
runtime
|
||||
&& governance.preflight?.status === 'pass'
|
||||
&& governance.deploymentBinding
|
||||
&& governance.contract?.adapter_actions?.includes('notify_operator')
|
||||
);
|
||||
|
||||
const runtimeExecution = shouldRunOrchestrator
|
||||
? runOrchestratorAdapter({
|
||||
profileArtifact: profile,
|
||||
repoRootOverride,
|
||||
...runtime,
|
||||
})
|
||||
: null;
|
||||
const routeResult = resolveRuntimeRoute({
|
||||
governance,
|
||||
runtime,
|
||||
repoRootOverride,
|
||||
});
|
||||
|
||||
return {
|
||||
...governance,
|
||||
runtimeExecution,
|
||||
runtimeExecution: routeResult.runtimeExecution,
|
||||
runtimeIntegration: {
|
||||
attempted: shouldRunOrchestrator,
|
||||
adapter: shouldRunOrchestrator ? 'orchestrator' : null,
|
||||
reason: shouldRunOrchestrator
|
||||
? 'deployment binding + notify_operator adapter action routed into orchestrator adapter'
|
||||
: 'runtime execution not attempted',
|
||||
attempted: routeResult.attempted,
|
||||
adapter: routeResult.adapter,
|
||||
action: routeResult.action,
|
||||
reason: routeResult.reason,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const __testables = {
|
||||
ACTION_ADAPTER_ROUTING,
|
||||
resolveRuntimeRoute,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user