row 175 (#1673): tester reads, W1-W7 writes recorded as tester, human-only verbs refuse tester-refused
TESTER_VERBS gains usage, names, limits, plugins, instances, project.list, thread.list, name.set and project.create; TESTER_ORGANIZATION_VERBS lets a tester read limits, plugins and instances and send 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. project init --tester checks the project area, binds the tester with one agents read, then commits the layout as tester (mos-0872 Q2).
This commit is contained in:
1 parent
1bfc9833b1
commit
e5e64afecb
24 files changed
+629
-118
No files matched your search
@@ -4,10 +4,10 @@ import {
|
||||
} from 'node:fs';
|
||||
import { dirname, join, normalize } from 'node:path';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { ProjectError, checkedId, documentPath, noLinks, projectRepo } from './paths.mjs';
|
||||
import { ProjectError, checkedId, documentPath, noLinks, projectRepo, testerProjectArea } from './paths.mjs';
|
||||
import { git, identity, inspectGit, requireClean } from './git.mjs';
|
||||
import { validateRecord } from './validate.mjs';
|
||||
export { ProjectError, projectRepo, validateRecord };
|
||||
export { ProjectError, projectRepo, testerProjectArea, validateRecord };
|
||||
|
||||
const DIRECTORIES = ['spec', 'docs', 'requirements', 'decisions', 'templates'];
|
||||
const TEMPLATES = ['project.json', 'requirement.json', 'decision.json', 'document.md', 'north-star.md'];
|
||||
@@ -92,8 +92,10 @@ export async function checkProject(context) {
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function initProject(context) {
|
||||
const repo = projectRepo(context), human = checkedId(context.business.human);
|
||||
// Row 175 (#1673): `author` names the layout commit's author and committer; without it the
|
||||
// business human commits, as before. The tester's init passes "tester".
|
||||
export async function initProject(context, { author } = {}) {
|
||||
const repo = projectRepo(context), committer = checkedId(author ?? context.business.human);
|
||||
if (existsSync(repo) && readdirSync(repo).length) throw new ProjectError('project-not-empty', 'refusing existing non-empty directory');
|
||||
const parents = [];
|
||||
for (let path = repo; !existsSync(path); path = dirname(path)) parents.unshift(path);
|
||||
@@ -130,7 +132,7 @@ export async function initProject(context) {
|
||||
const result = await checkLayout(context);
|
||||
if (!result.ok) throw new ProjectError('project-invalid', result.problems.join('\n'));
|
||||
await git(repo, ['add', '--', 'project.json', ...DIRECTORIES]);
|
||||
await git(repo, ['commit', '-m', 'Initialize project layout v1'], identity(human));
|
||||
await git(repo, ['commit', '-m', 'Initialize project layout v1'], identity(committer));
|
||||
return { repo, commit: await git(repo, ['rev-parse', 'HEAD']) };
|
||||
} catch (error) {
|
||||
for (const entry of created.reverse()) {
|
||||
|
||||
@@ -27,6 +27,10 @@ export function noLinks(path) {
|
||||
if (part === dirname(part)) break;
|
||||
}
|
||||
}
|
||||
const contains = (base, child) => {
|
||||
const rel = relative(base, child);
|
||||
return rel === '' || (rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel));
|
||||
};
|
||||
export function projectRepo({ business, project, dataRoot }) {
|
||||
checkedId(business?.id); checkedId(project);
|
||||
if (!Object.hasOwn(business?.projects ?? {}, project))
|
||||
@@ -34,10 +38,6 @@ export function projectRepo({ business, project, dataRoot }) {
|
||||
absolute(dataRoot);
|
||||
const entry = business.projects[project];
|
||||
const repo = absolute(entry.repo ?? join(dataRoot, 'projects', business.id, project));
|
||||
const contains = (base, child) => {
|
||||
const rel = relative(base, child);
|
||||
return rel === '' || (rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel));
|
||||
};
|
||||
for (const project of Object.values(business.projects)) {
|
||||
const code = absolute(project.root);
|
||||
if (contains(code, repo) || contains(repo, code))
|
||||
@@ -46,3 +46,11 @@ export function projectRepo({ business, project, dataRoot }) {
|
||||
noLinks(repo);
|
||||
return repo;
|
||||
}
|
||||
// Row 175 (#1673, mos-0872 Q2): the tester initializes only a repository in the data root's
|
||||
// project area, <dataRoot>/projects/<business id>/. It writes nothing; projectRepo only lstats the path.
|
||||
export function testerProjectArea(context) {
|
||||
const repo = projectRepo(context);
|
||||
if (!contains(join(context.dataRoot, 'projects', context.business.id), repo))
|
||||
throw new ProjectError('tester-project-area', `the tester initializes only a repository under ${join(context.dataRoot, 'projects', context.business.id)}`);
|
||||
return repo;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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 in the business area and refuses 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'),
|
||||
];
|
||||
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' });
|
||||
});
|
||||
Reference in new issue
Block a user