test: harden reporting-governance package boundaries

This commit is contained in:
Eve
2026-05-08 09:11:04 +08:00
parent 145371fd23
commit 87911d16e0
11 changed files with 272 additions and 48 deletions

View File

@@ -0,0 +1,59 @@
import path from 'node:path';
import process from 'node:process';
const ENV_PREFIX = 'OPENCLAW_REPORTING_GOVERNANCE_';
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
const repoRoot = path.resolve(packageRoot, '..', '..');
const SCRIPT_NAMES = {
watchdog: 'long_task_watchdog.mjs',
dispatcher: 'operator_notify_dispatcher.mjs',
bridgeSupervisor: 'operator_notify_bridge_supervisor.mjs',
senderBinding: 'operator_notify_sender_binding.mjs',
orchestrator: 'watchdog_auto_notify_orchestrator.mjs',
};
const SCRIPT_ENV_KEYS = {
watchdog: `${ENV_PREFIX}WATCHDOG_SCRIPT`,
dispatcher: `${ENV_PREFIX}DISPATCHER_SCRIPT`,
bridgeSupervisor: `${ENV_PREFIX}BRIDGE_SUPERVISOR_SCRIPT`,
senderBinding: `${ENV_PREFIX}SENDER_BINDING_SCRIPT`,
orchestrator: `${ENV_PREFIX}ORCHESTRATOR_SCRIPT`,
};
function normalizeString(value) {
return typeof value === 'string' && value.trim() ? value.trim() : null;
}
export function resolveRepoPath(...segments) {
return path.join(repoRoot, ...segments);
}
export function createRuntimeBinding(overrides = {}) {
const scripts = {};
for (const [key, fileName] of Object.entries(SCRIPT_NAMES)) {
const envValue = normalizeString(process.env[SCRIPT_ENV_KEYS[key]]);
const overrideValue = normalizeString(overrides?.scripts?.[key]);
scripts[key] = path.resolve(overrideValue ?? envValue ?? resolveRepoPath('scripts', fileName));
}
return {
packageRoot,
repoRoot,
cwd: path.resolve(normalizeString(overrides.cwd) ?? repoRoot),
scripts,
};
}
export function resolveScriptPath(name, options = {}) {
const runtimeBinding = options.runtimeBinding ?? createRuntimeBinding(options);
const scriptPath = runtimeBinding?.scripts?.[name];
if (!scriptPath) {
throw new Error(`unknown runtime binding script: ${name}`);
}
return path.resolve(scriptPath);
}
export { packageRoot, repoRoot, SCRIPT_ENV_KEYS, SCRIPT_NAMES };