feat: add deployment profile generation slice
This commit is contained in:
71
plugins/reporting-governance/test/profile-generator.test.mjs
Normal file
71
plugins/reporting-governance/test/profile-generator.test.mjs
Normal file
@@ -0,0 +1,71 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import {
|
||||
parseDeploymentProfileYaml,
|
||||
validateDeploymentProfileSchema,
|
||||
generateDeploymentProfileArtifact,
|
||||
generateDeploymentProfileArtifactFromFile,
|
||||
} from '../src/storage/profile-generator.mjs';
|
||||
import { validateDeploymentProfileArtifact } from '../src/storage/profile-artifact.mjs';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..');
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
|
||||
test('deployment profile yaml parser reads strict-manager-mode profile shape', () => {
|
||||
const artifact = generateDeploymentProfileArtifactFromFile(path.join(repoRoot, 'profiles', 'strict-manager-mode.yaml'));
|
||||
|
||||
assert.equal(artifact.metadata.id, 'strict-manager-mode');
|
||||
assert.equal(artifact.metadata.runtime, 'openclaw');
|
||||
assert.equal(artifact.spec.package.pluginVersion, '0.1.0-mainline');
|
||||
assert.equal(artifact.metadata.source_profile, 'profiles/strict-manager-mode.yaml');
|
||||
});
|
||||
|
||||
test('deployment profile schema validator rejects malformed profile', () => {
|
||||
assert.throws(
|
||||
() => validateDeploymentProfileSchema({ kind: 'DeploymentProfile' }),
|
||||
/deployment profile apiVersion must be reporting-governance\/v1alpha1/
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => validateDeploymentProfileSchema({
|
||||
apiVersion: 'reporting-governance/v1alpha1',
|
||||
kind: 'DeploymentProfile',
|
||||
metadata: { id: 'x', version: '1.0.0', runtime: 'openclaw' },
|
||||
spec: {
|
||||
package: { pluginVersion: '0.1.0-mainline' },
|
||||
adapters: {},
|
||||
notifications: {},
|
||||
audit: { requiredArtifacts: [] },
|
||||
capability_expectations: { required: [] },
|
||||
},
|
||||
}),
|
||||
/deployment profile spec\.audit\.requiredArtifacts must be a non-empty array/
|
||||
);
|
||||
});
|
||||
|
||||
test('yaml to artifact generation produces validator-compatible package artifact', () => {
|
||||
const profile = parseDeploymentProfileYaml(`apiVersion: reporting-governance/v1alpha1\nkind: DeploymentProfile\nmetadata:\n id: demo\n version: 1.0.0\n runtime: openclaw\nspec:\n package:\n pluginVersion: 0.1.0-mainline\n adapters:\n watchdog:\n enabled: true\n queue:\n enabled: true\n dispatcher:\n enabled: true\n bridge:\n enabled: true\n sender:\n mode: openclaw-cli\n orchestrator:\n enabled: true\n notifications:\n operatorVisibleRecoveryRequired: true\n allowedTerminalStates:\n - acked\n audit:\n portableArtifactsRequired: true\n requiredArtifacts:\n - queue_items\n capability_expectations:\n required:\n - create_queue_items\n`);
|
||||
const artifact = generateDeploymentProfileArtifact(profile, { sourceProfile: 'profiles/demo.yaml' });
|
||||
|
||||
assert.equal(artifact.kind, 'DeploymentProfileArtifact');
|
||||
assert.equal(artifact.metadata.source_profile, 'profiles/demo.yaml');
|
||||
assert.equal(artifact.spec.bindings.entrypoint, 'scripts/watchdog_auto_notify_orchestrator.mjs');
|
||||
assert.doesNotThrow(() => validateDeploymentProfileArtifact(artifact));
|
||||
});
|
||||
|
||||
test('strict-manager YAML generation matches checked-in package artifact snapshot', () => {
|
||||
const generated = generateDeploymentProfileArtifactFromFile(path.join(repoRoot, 'profiles', 'strict-manager-mode.yaml'));
|
||||
const checkedIn = validateDeploymentProfileArtifact(
|
||||
JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(packageRoot, 'profiles', 'strict-manager-mode.profile.json'),
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
assert.deepEqual(generated, checkedIn);
|
||||
});
|
||||
Reference in New Issue
Block a user