107 lines
4.2 KiB
JavaScript
107 lines
4.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
import {
|
|
loadDeploymentProfileArtifact,
|
|
createDeploymentBindingContract,
|
|
validateDeploymentProfileArtifact,
|
|
} from '../src/storage/profile-artifact.mjs';
|
|
import { createRuntimeBinding } from '../src/adapters/index.mjs';
|
|
|
|
const packageRoot = path.resolve(import.meta.dirname, '..');
|
|
const repoRoot = path.resolve(packageRoot, '..', '..');
|
|
|
|
test('deployment profile artifact loads from package profiles and preserves compatibility envelope metadata', () => {
|
|
const { artifactPath, artifact } = loadDeploymentProfileArtifact({ profileId: 'strict-manager-mode' });
|
|
|
|
assert.equal(path.relative(packageRoot, artifactPath), path.join('profiles', 'strict-manager-mode.profile.json'));
|
|
assert.equal(artifact.kind, 'DeploymentProfileArtifact');
|
|
assert.equal(artifact.metadata.id, 'strict-manager-mode');
|
|
assert.equal(artifact.metadata.compatibility_mode, 'strict_envelope');
|
|
assert.equal(artifact.spec.package.pluginVersion, '0.1.0-mainline');
|
|
});
|
|
|
|
test('deployment binding contract resolves package artifact into real repo script and artifact paths', () => {
|
|
const { artifact } = loadDeploymentProfileArtifact({ profileId: 'strict-manager-mode' });
|
|
const binding = createDeploymentBindingContract({ artifact });
|
|
|
|
assert.equal(binding.runtime, 'openclaw');
|
|
assert.equal(binding.pluginVersion, '0.1.0-mainline');
|
|
assert.equal(binding.compatibilityMode, 'strict_envelope');
|
|
assert.equal(binding.entrypoint, path.resolve(repoRoot, 'scripts/watchdog_auto_notify_orchestrator.mjs'));
|
|
assert.equal(binding.scripts.watchdog, path.resolve(repoRoot, 'scripts/long_task_watchdog.mjs'));
|
|
assert.equal(binding.artifactRoots.queueItems, path.resolve(repoRoot, 'state/operator-notify-queue'));
|
|
assert.equal(fs.existsSync(binding.scripts.orchestrator), true);
|
|
});
|
|
|
|
test('runtime binding can be instantiated from profile artifact binding contract', () => {
|
|
const { artifact } = loadDeploymentProfileArtifact({ profileId: 'strict-manager-mode' });
|
|
const contract = createDeploymentBindingContract({ artifact });
|
|
const runtimeBinding = createRuntimeBinding({
|
|
cwd: repoRoot,
|
|
scripts: contract.scripts,
|
|
});
|
|
|
|
assert.equal(runtimeBinding.cwd, repoRoot);
|
|
assert.equal(runtimeBinding.scripts.dispatcher, contract.scripts.dispatcher);
|
|
assert.equal(runtimeBinding.scripts.bridgeSupervisor, contract.scripts.bridgeSupervisor);
|
|
assert.equal(runtimeBinding.scripts.senderBinding, contract.scripts.senderBinding);
|
|
});
|
|
|
|
test('deployment profile artifact validation fails closed on boundary drift', () => {
|
|
assert.throws(
|
|
() => validateDeploymentProfileArtifact({}),
|
|
/kind must be DeploymentProfileArtifact/
|
|
);
|
|
|
|
assert.throws(
|
|
() => validateDeploymentProfileArtifact({
|
|
kind: 'DeploymentProfileArtifact',
|
|
apiVersion: 'reporting-governance/v1alpha1',
|
|
spec: {
|
|
package: { pluginVersion: '0.1.0-mainline' },
|
|
bindings: {
|
|
entrypoint: '',
|
|
scripts: { watchdog: 'scripts/long_task_watchdog.mjs' },
|
|
artifact_roots: { queueItems: 'state/operator-notify-queue' },
|
|
},
|
|
},
|
|
}),
|
|
/spec\.bindings\.entrypoint must be a non-empty string/
|
|
);
|
|
|
|
assert.throws(
|
|
() => validateDeploymentProfileArtifact({
|
|
kind: 'DeploymentProfileArtifact',
|
|
apiVersion: 'reporting-governance/v1alpha1',
|
|
spec: {
|
|
package: { pluginVersion: '' },
|
|
bindings: {
|
|
entrypoint: 'scripts/watchdog_auto_notify_orchestrator.mjs',
|
|
scripts: { watchdog: '' },
|
|
artifact_roots: { queueItems: 'state/operator-notify-queue' },
|
|
},
|
|
},
|
|
}),
|
|
/spec\.package\.pluginVersion must be a non-empty string/
|
|
);
|
|
|
|
assert.throws(
|
|
() => validateDeploymentProfileArtifact({
|
|
kind: 'DeploymentProfileArtifact',
|
|
apiVersion: 'reporting-governance/v1alpha1',
|
|
spec: {
|
|
package: { pluginVersion: '0.1.0-mainline' },
|
|
bindings: {
|
|
entrypoint: 'scripts/watchdog_auto_notify_orchestrator.mjs',
|
|
scripts: [],
|
|
artifact_roots: { queueItems: 'state/operator-notify-queue' },
|
|
},
|
|
},
|
|
}),
|
|
/spec\.bindings\.scripts must be an object record/
|
|
);
|
|
});
|