Adds the system-type kind with five modules (coding, creative-writing, marketing, montage, business-management), an org-level enabled list validated fail-closed, project selections limited to the org's list, read verbs, and bus migration 3t-3u. REQ-SYS-2 toolsets are designed and deferred: they need a role authority contract.
31 lines
4.0 KiB
JavaScript
31 lines
4.0 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, readFileSync } from 'node:fs';
|
|
import { join, resolve } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { spawnSync } from 'node:child_process';
|
|
const repo = resolve(import.meta.dirname, '../../..');
|
|
function run(env, ...args) { return spawnSync(join(repo, 'scripts/mosaic'), args, { cwd: repo, env, encoding: 'utf8' }); }
|
|
test('organization CLI renders, validates, creates, updates and initializes git', () => {
|
|
const home = mkdtempSync(join(tmpdir(), 'org-cli-')); const env = { ...process.env, HOME: home, MOSAIC_CONFIG: join(home, '.config/mosaic-orgtest/config.json') };
|
|
const boot = spawnSync(join(repo, 'scripts/bootstrap.sh'), ['--instance', 'orgtest'], { cwd: repo, env, encoding: 'utf8' }); assert.equal(boot.status, 0, boot.stderr);
|
|
const file = join(home, 'alpha.json'); const invoke = (...args) => { const r = run(env, ...args); assert.equal(r.status, 0, r.stderr); return r.stdout; };
|
|
invoke('org', 'template', 'render', 'alpha', '--fixture', 'local', '--output', file);
|
|
invoke('org', 'validate', file); invoke('org', 'create', 'alpha', '--from', file);
|
|
assert.deepEqual(JSON.parse(invoke('org', 'system-types', 'enabled', 'alpha')), { organization: 'alpha', enabled: [] });
|
|
const bootCheck = spawnSync(process.execPath, ['--input-type=module', '-e', `import {loadSystem, bootConfig} from './packages/cli/src/config.mjs'; const system=loadSystem({env:process.env, instance:'orgtest'}); bootConfig({system,businessId:'alpha',env:process.env});`], { cwd: repo, env, encoding: 'utf8' }); assert.equal(bootCheck.status, 0, bootCheck.stderr);
|
|
let info = JSON.parse(invoke('org', 'show', 'alpha', '--json')); assert.equal(info.id, 'alpha'); assert.equal(JSON.parse(invoke('org', 'list', '--json')).length, 1);
|
|
invoke('org', 'update', 'alpha', '--from', file, '--if-revision', String(info.revision));
|
|
invoke('org', 'queue', 'init', 'alpha', '--local-only', '--accept-local-loss-risk'); assert.equal(JSON.parse(invoke('org', 'queue', 'show', 'alpha', '--json')).riskAccepted, true);
|
|
invoke('org', 'project', 'repo', 'init', 'alpha', 'work', '--local-only', '--accept-local-loss-risk'); assert.equal(JSON.parse(invoke('org', 'project', 'repo', 'show', 'alpha', 'work', '--json')).project, 'work'); assert.equal(JSON.parse(readFileSync(file)).id, 'alpha');
|
|
info = JSON.parse(invoke('org', 'show', 'alpha', '--json')); const archived = JSON.parse(invoke('org', 'archive', 'alpha', '--if-revision', String(info.revision), '--json')); assert.equal(archived.revision, info.revision + 1);
|
|
assert.equal(JSON.parse(invoke('org', 'list', '--json'))[0].state, 'archived');
|
|
const restored = JSON.parse(invoke('org', 'restore', 'alpha', '--if-revision', String(archived.revision), '--json')); assert.equal(restored.revision, archived.revision + 1);
|
|
info = JSON.parse(invoke('org', 'show', 'alpha', '--json')); const receipt = JSON.parse(invoke('org', 'delete', 'alpha', '--confirm', 'alpha', '--if-revision', String(info.revision), '--json')); assert.equal(receipt.org, 'alpha'); assert.deepEqual(JSON.parse(invoke('org', 'list', '--json')), []);
|
|
});
|
|
test('business and org aliases conflict in either order', () => { for (const args of [['--business','alpha','--org','beta'], ['--org','beta','--business','alpha']]) { const r = run(process.env, 'tasks', ...args); assert.notEqual(r.status, 0); assert.match(r.stderr, /conflict/i); } });
|
|
|
|
import { main } from '../src/cli.mjs';
|
|
import { io } from './helpers.mjs';
|
|
test('org alias preserves existing command output and matching aliases are accepted', async () => { const seen = []; const deps = { system: { dataRoot: '/unused' }, transport: business => async () => { seen.push(business); return []; } }; const outputs = []; for (const options of [['--business','alpha'], ['--org','alpha'], ['--org','alpha','--business','alpha'], ['--business','alpha','--org','alpha']]) { const x = io(); await main(['tasks', '--json', ...options], x, deps); outputs.push(x.out.text); } assert.deepEqual(seen, ['alpha','alpha','alpha','alpha']); assert.equal(new Set(outputs).size, 1); });
|