Files
stack/packages/project/tests/tester-init.test.mjs
T
jason.woltje 98d29769e2 bus, cli: tester reads and the W1-W7 tester writes, recorded as tester; scripts/mosaic sends plugins, name and names to the CLI (row 175, #1673)
TESTER_VERBS gains usage, names, limits, plugins, instances, project.list,
thread.list, name.set and project.create. A tester reads limits, plugins
and instances and sends plugins.set, instances.set and routes.set, each
logged with actor tester. The project file verbs refuse a tester
tester-refused. The broker and CLI drop the [mos test]
prefix rule (mos-0872 Q1). The CLI takes --tester on the seven reads and
the W1-W7 write forms and refuses it (exit 4) elsewhere, bus start and
stop included.

project init --tester checks the project area, refuses the area root
itself, binds the tester with one agents read, then commits the layout as
tester (mos-0872 Q2). scripts/mosaic sends plugins, name, names, follow,
threads and thread to packages/cli (sage-1081). The row 164 pins are
untouched.

Built by Dewey on 9e74925c2 (three commits to 989699f7c, manifest
2e30f2a1...29d5f), approved by Filbert in round 3 (#1673 comment 29279),
Sage's gate green on 716ddcf1e plus the patch.
2026-10-19 19:04:50 -05:00

65 lines
3.3 KiB
JavaScript

// Row 175 (#1673, mos-0872 Q2): `project init --tester` initializes only a repository under
// <dataRoot>/projects/<business>/, and its layout commit names `tester` as author and committer.
import test from 'node:test';
import assert from 'node:assert/strict';
import { existsSync, mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { execFileSync } from 'node:child_process';
import { initProject, testerProjectArea } from '../src/index.mjs';
const git = (repo, ...args) => execFileSync('git', ['-c', 'core.hooksPath=/dev/null', '-C', repo, ...args], { encoding: 'utf8' }).trim();
function context(t, repo) {
const root = mkdtempSync(join(tmpdir(), 'project-tester-'));
t.after(() => rmSync(root, { recursive: true, force: true }));
const dataRoot = join(root, 'data');
return { root, business: { id: 'acme', human: 'jason', projects: { stack: { root: join(root, 'code'), ...(repo ? { repo: repo(root, dataRoot) } : {}) } } }, project: 'stack', dataRoot };
}
test('row 175: init with author tester commits the layout as tester; without it, as the human', async (t) => {
const c = context(t);
const { repo, commit } = await initProject(c, { author: 'tester' });
assert.equal(repo, join(c.dataRoot, 'projects/acme/stack'));
assert.equal(git(repo, 'show', '-s', '--format=%an|%cn', commit), 'tester|tester');
assert.equal(git(repo, 'rev-list', '--count', 'HEAD'), '1');
const h = context(t);
const human = await initProject(h);
assert.equal(git(human.repo, 'show', '-s', '--format=%an|%cn', human.commit), 'jason|jason');
});
test('row 175: init refuses an author that is no id before it makes any directory', async (t) => {
const c = context(t);
for (const author of ['', 'two words', '../x', 7])
await assert.rejects(initProject(c, { author }), { code: 'project-id' }, String(author));
assert.equal(existsSync(c.dataRoot), false);
});
test('row 175: testerProjectArea passes a repository inside the business area and refuses the area itself and any other, touching nothing', (t) => {
const inside = [
null,
(root, dataRoot) => join(dataRoot, 'projects', 'acme', 'records'),
(root, dataRoot) => join(dataRoot, 'projects', 'acme', 'deep', 'records'),
];
for (const repo of inside) {
const c = context(t, repo);
assert.equal(testerProjectArea(c), repo ? repo(c.root, c.dataRoot) : join(c.dataRoot, 'projects', 'acme', 'stack'));
}
const outside = [
(root) => join(root, 'records'),
(root, dataRoot) => join(dataRoot, 'records'),
(root, dataRoot) => join(dataRoot, 'projects', 'other', 'stack'),
// A sibling whose name starts with the business id is not inside it.
(root, dataRoot) => join(dataRoot, 'projects', 'acme-2', 'stack'),
// The area itself: a repository there would hold the other projects' default repositories.
(root, dataRoot) => join(dataRoot, 'projects', 'acme'),
];
for (const repo of outside) {
const c = context(t, repo);
assert.throws(() => testerProjectArea(c), { code: 'tester-project-area' }, repo(c.root, c.dataRoot));
assert.equal(existsSync(c.dataRoot), false);
assert.equal(existsSync(repo(c.root, c.dataRoot)), false);
}
// projectRepo's own checks still come first.
assert.throws(() => testerProjectArea({ ...context(t), project: 'missing' }), { code: 'project-not-declared' });
});