test: add packed consumer install smoke
This commit is contained in:
@@ -29,6 +29,8 @@ const requiredPaths = [
|
||||
'profiles-src/strict-manager-mode.yaml',
|
||||
'schemas/reporting-governance/deployment-profile.schema.json',
|
||||
'schemas/reporting-governance/capability-descriptor.schema.json',
|
||||
'schemas/reporting-governance/decision.schema.json',
|
||||
'schemas/reporting-governance/decision-record-artifact.schema.json',
|
||||
'scripts/package-smoke.mjs',
|
||||
'scripts/watchdog_auto_notify_orchestrator.mjs',
|
||||
'scripts/long_task_watchdog.mjs',
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..');
|
||||
|
||||
function run(command, args, { cwd, env = {} } = {}) {
|
||||
const result = spawnSync(command, args, {
|
||||
cwd,
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
...env,
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
result.status,
|
||||
0,
|
||||
[
|
||||
`command failed: ${command} ${args.join(' ')}`,
|
||||
`cwd: ${cwd}`,
|
||||
result.stdout && `stdout:\n${result.stdout.trim()}`,
|
||||
result.stderr && `stderr:\n${result.stderr.trim()}`,
|
||||
].filter(Boolean).join('\n\n')
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
test('packed tarball installs into clean consumer and works via public exports/bin only', () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'reporting-governance-packed-consumer-'));
|
||||
|
||||
try {
|
||||
const packResult = run('npm', ['pack', '--json'], { cwd: packageRoot });
|
||||
const packPayload = JSON.parse(packResult.stdout.trim());
|
||||
const tarballName = packPayload.at(-1)?.filename;
|
||||
assert.ok(tarballName, 'npm pack should return tarball filename');
|
||||
|
||||
const tarballPath = path.join(packageRoot, tarballName);
|
||||
assert.equal(fs.existsSync(tarballPath), true, 'tarball should exist after npm pack');
|
||||
|
||||
const consumerRoot = path.join(root, 'consumer');
|
||||
fs.mkdirSync(consumerRoot, { recursive: true });
|
||||
run('npm', ['init', '-y'], { cwd: consumerRoot });
|
||||
run('npm', ['install', tarballPath], { cwd: consumerRoot });
|
||||
|
||||
const exportProbe = run(process.execPath, ['--input-type=module', '--eval', `
|
||||
import * as plugin from '@openclaw/plugin-reporting-governance';
|
||||
import { runOrchestratorAdapter } from '@openclaw/plugin-reporting-governance/adapters/orchestrator';
|
||||
process.stdout.write(JSON.stringify({
|
||||
packageName: plugin.packageName,
|
||||
hasRunWatchdogChain: typeof plugin.runWatchdogChain,
|
||||
hasRunOrchestratorAdapter: typeof runOrchestratorAdapter,
|
||||
}));
|
||||
`], { cwd: consumerRoot });
|
||||
const exportPayload = JSON.parse(exportProbe.stdout.trim());
|
||||
assert.equal(exportPayload.packageName, '@openclaw/plugin-reporting-governance');
|
||||
assert.equal(exportPayload.hasRunWatchdogChain, 'function');
|
||||
assert.equal(exportPayload.hasRunOrchestratorAdapter, 'function');
|
||||
|
||||
const smokeResult = run(
|
||||
path.join(consumerRoot, 'node_modules', '.bin', 'reporting-governance-package-smoke'),
|
||||
['--compact'],
|
||||
{ cwd: consumerRoot }
|
||||
);
|
||||
const smokePayload = JSON.parse(smokeResult.stdout.trim());
|
||||
assert.equal(smokePayload.ok, true);
|
||||
assert.equal(smokePayload.tool, 'reporting-governance-package-smoke');
|
||||
assert.equal(smokePayload.orchestrator.ok, true);
|
||||
assert.equal(smokePayload.orchestrator.dispatchedCount, 1);
|
||||
assert.equal(smokePayload.orchestrator.pendingCount, 1);
|
||||
assert.equal(smokePayload.orchestrator.notificationCount, 1);
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user