feat(reporting-governance): add package-first portability smoke
This commit is contained in:
@@ -4,7 +4,7 @@ import process from 'node:process';
|
||||
const ENV_PREFIX = 'OPENCLAW_REPORTING_GOVERNANCE_';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
const repoRoot = packageRoot;
|
||||
|
||||
const SCRIPT_NAMES = {
|
||||
watchdog: 'long_task_watchdog.mjs',
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
const repoRoot = packageRoot;
|
||||
const EXPECTED_KIND = 'DeploymentProfileArtifact';
|
||||
const EXPECTED_API_VERSION = 'reporting-governance/v1alpha1';
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ import Ajv2020 from 'ajv/dist/2020.js';
|
||||
import YAML from 'yaml';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
const schemaPath = path.resolve(repoRoot, 'schemas', 'reporting-governance', 'deployment-profile.schema.json');
|
||||
const artifactSchemaRefPath = '../../../schemas/reporting-governance/deployment-profile.schema.json';
|
||||
const packageProfileSourceRoot = path.resolve(packageRoot, 'profiles-src');
|
||||
const schemaPath = path.resolve(packageRoot, 'schemas', 'reporting-governance', 'deployment-profile.schema.json');
|
||||
const artifactSchemaRefPath = './schemas/reporting-governance/deployment-profile.schema.json';
|
||||
const defaultSourceProfilePath = path.join('profiles-src', 'strict-manager-mode.yaml');
|
||||
const packageScriptsRoot = 'scripts';
|
||||
|
||||
function readText(filePath) {
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
@@ -17,6 +19,10 @@ function loadDeploymentProfileSchema() {
|
||||
return JSON.parse(readText(schemaPath));
|
||||
}
|
||||
|
||||
function relativizeToPackage(filePath) {
|
||||
return path.relative(packageRoot, filePath).split(path.sep).join('/');
|
||||
}
|
||||
|
||||
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
||||
const validateDeploymentProfile = ajv.compile(loadDeploymentProfileSchema());
|
||||
|
||||
@@ -66,7 +72,7 @@ export function validateDeploymentProfileSchema(profile) {
|
||||
export function generateDeploymentProfileArtifact(profile, { sourceProfile } = {}) {
|
||||
const validated = validateDeploymentProfileSchema(profile);
|
||||
const id = validated.metadata.id;
|
||||
const sourceProfilePath = sourceProfile ?? path.join('profiles', `${id}.yaml`);
|
||||
const sourceProfilePath = sourceProfile ?? (id === 'strict-manager-mode' ? defaultSourceProfilePath : path.join('profiles-src', `${id}.yaml`));
|
||||
|
||||
return {
|
||||
$schema: artifactSchemaRefPath,
|
||||
@@ -85,13 +91,13 @@ export function generateDeploymentProfileArtifact(profile, { sourceProfile } = {
|
||||
},
|
||||
bindings: {
|
||||
runtime: validated.metadata.runtime,
|
||||
entrypoint: 'scripts/watchdog_auto_notify_orchestrator.mjs',
|
||||
entrypoint: `${packageScriptsRoot}/watchdog_auto_notify_orchestrator.mjs`,
|
||||
scripts: {
|
||||
watchdog: 'scripts/long_task_watchdog.mjs',
|
||||
dispatcher: 'scripts/operator_notify_dispatcher.mjs',
|
||||
bridgeSupervisor: 'scripts/operator_notify_bridge_supervisor.mjs',
|
||||
senderBinding: 'scripts/operator_notify_sender_binding.mjs',
|
||||
orchestrator: 'scripts/watchdog_auto_notify_orchestrator.mjs',
|
||||
watchdog: `${packageScriptsRoot}/long_task_watchdog.mjs`,
|
||||
dispatcher: `${packageScriptsRoot}/operator_notify_dispatcher.mjs`,
|
||||
bridgeSupervisor: `${packageScriptsRoot}/operator_notify_bridge_supervisor.mjs`,
|
||||
senderBinding: `${packageScriptsRoot}/operator_notify_sender_binding.mjs`,
|
||||
orchestrator: `${packageScriptsRoot}/watchdog_auto_notify_orchestrator.mjs`,
|
||||
},
|
||||
artifact_roots: {
|
||||
watchdogEvidence: 'state/long-task-watchdog',
|
||||
@@ -109,9 +115,12 @@ export function generateDeploymentProfileArtifact(profile, { sourceProfile } = {
|
||||
export function generateDeploymentProfileArtifactFromFile(profilePath) {
|
||||
const absoluteProfilePath = path.resolve(profilePath);
|
||||
const profile = parseDeploymentProfileYaml(readText(absoluteProfilePath));
|
||||
return generateDeploymentProfileArtifact(profile, {
|
||||
sourceProfile: path.relative(repoRoot, absoluteProfilePath),
|
||||
});
|
||||
const relativeToPackageSource = path.relative(packageProfileSourceRoot, absoluteProfilePath);
|
||||
const sourceProfile = relativeToPackageSource.startsWith(`..${path.sep}`)
|
||||
? relativizeToPackage(absoluteProfilePath)
|
||||
: path.join('profiles-src', relativeToPackageSource).split(path.sep).join('/');
|
||||
|
||||
return generateDeploymentProfileArtifact(profile, { sourceProfile });
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user