refactor: route runtime integration via adapter table
This commit is contained in:
@@ -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