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
9e74925c2a
commit
c0b06ed89b
24 files changed
+629
-118
No files matched your search
+28
-16
@@ -32,16 +32,16 @@ mosaic agents [--business <id>] [--json]
|
||||
mosaic trail <task|decision> [--business <id>] [--json]
|
||||
mosaic talk <role> <text> [--wait <seconds> | --follow] [--business <id>]
|
||||
mosaic follow [--business <id>]
|
||||
mosaic project create <name> [--repo <repo>] [--business <id>]
|
||||
mosaic project list [--business <id>] [--json]
|
||||
mosaic threads [--project <project>] [--business <id>] [--json]
|
||||
mosaic project create <name> [--repo <repo>] [--business <id>] [--tester]
|
||||
mosaic project list [--business <id>] [--json] [--tester]
|
||||
mosaic threads [--project <project>] [--business <id>] [--json] [--tester]
|
||||
mosaic thread create <project> <name> [--business <id>]
|
||||
mosaic thread open <thread> [--business <id>]
|
||||
mosaic thread read <thread> [--business <id>] [--json]
|
||||
mosaic talk --thread <thread> <text> [--wait <seconds> | --follow] [--business <id>]
|
||||
mosaic follow --thread <thread> [--business <id>]
|
||||
mosaic name <instance> <name> [--business <id>]
|
||||
mosaic names [--business <id>] [--json]
|
||||
mosaic name <instance> <name> [--business <id>] [--tester]
|
||||
mosaic names [--business <id>] [--json] [--tester]
|
||||
mosaic stop <run>
|
||||
mosaic launches off|on [--business <id>]
|
||||
mosaic launches list [--json]
|
||||
@@ -171,14 +171,26 @@ mosaic launches list [--json]
|
||||
(`tester-required`) or while the business var `bus.tester` isn't `true`
|
||||
(`tester-off`), each exit 3. Like the human commands, `--tester` works
|
||||
only from the tree the bus runs from ("One pinned copy" below).
|
||||
`talk --tester` text must start with
|
||||
`[mos test]`, else exit 2 before any call. When no run holds the role
|
||||
Row 175 (#1673, Q173, mos-0870 N2) adds the reads `usage`, `names`,
|
||||
`limits`, `plugins`, `threads`, `project list` and `business instances`,
|
||||
which print what the human's forms print, and the writes `plugins set`,
|
||||
`business instance add` and `set`, `name`, `project create` and
|
||||
`project init` (below), each recorded as `tester`.
|
||||
`routes.set` has no CLI form yet. `talk --tester` sends any text. When no run holds the role
|
||||
(row 170, #1667), the bus refuses the message with
|
||||
`tester-target-not-running` and stores nothing, and talk prints `pm isn't
|
||||
running, so the tester's message was refused and nothing was stored` and
|
||||
exits 3. A run launched but not yet claimed counts as not running. The
|
||||
role's reply comes back to the tester, not to the human's inbox. `decide`, `stop`, `launches` and
|
||||
`inbox --read` or `--read-all` take no `--tester` (exit 4).
|
||||
role's reply comes back to the tester, not to the human's inbox. `decide`, `stop`, `launches`,
|
||||
`inbox --read` or `--read-all`, `limits set`, `reset` and `migrate`,
|
||||
`project check`, the `thread` commands and `talk` or `follow --thread`
|
||||
take no `--tester` (exit 4).
|
||||
- `project init --tester` (row 175, mos-0872 Q2) may run inside an agent.
|
||||
Before anything touches the disk it refuses a repository outside
|
||||
`<dataRoot>/projects/<business>/` (`tester-project-area`, exit 2), then
|
||||
binds the tester with one `agents` read, so `tester-off` and
|
||||
`tester-required` refuse (exit 3), then commits the layout with `tester`
|
||||
as author and committer. Tests: `tests/tester-reads.test.mjs`.
|
||||
|
||||
## The app
|
||||
|
||||
@@ -872,7 +884,7 @@ The WebUI (S5).
|
||||
|
||||
## Agent limits and models
|
||||
|
||||
`mosaic limits [--business ID] [--json]` reads the model table, each role's
|
||||
`mosaic limits [--business ID] [--json] [--tester]` reads the model table, each role's
|
||||
selection, limits and running counts. `mosaic limits set --business ID
|
||||
--file PATCH` submits JSON with the read's `revision` and any of `limits`,
|
||||
`models`, `instances`. `limits` and `models` replace those entire objects;
|
||||
@@ -883,8 +895,8 @@ The definition stays an assistant one, and `holder` and `credentials` stay
|
||||
hand edits (row 155, Q169). The chief of staff sends the same patch with
|
||||
`change_organization` and reads the revision itself with
|
||||
`organization_revision` (row 134). Both commands use
|
||||
the existing human proof and broker; neither is available to a managed role
|
||||
or tester. The Console Settings form uses the same write path and requires
|
||||
the existing human proof and broker; neither is available to a managed role.
|
||||
A tester may read (row 175), but `limits set` refuses `--tester` with exit 4. The Console Settings form uses the same write path and requires
|
||||
signed-in send mode, named Host, exact Origin and same-origin Fetch Metadata.
|
||||
|
||||
Unset limits mean unlimited; zero blocks new launches. Limits are checked
|
||||
@@ -940,9 +952,9 @@ the re-pin follows in the same window (decision 145).
|
||||
Row 165 (#1662, Q171, REQ-ROLE-3).
|
||||
|
||||
```
|
||||
mosaic business instances BUSINESS [--json]
|
||||
mosaic business instance add BUSINESS INSTANCE --definition DEF [--vars FILE] [--launch] --revision REV
|
||||
mosaic business instance set BUSINESS INSTANCE [--definition DEF] [--vars FILE] [--launch | --no-launch] --revision REV
|
||||
mosaic business instances BUSINESS [--json] [--tester]
|
||||
mosaic business instance add BUSINESS INSTANCE --definition DEF [--vars FILE] [--launch] --revision REV [--tester]
|
||||
mosaic business instance set BUSINESS INSTANCE [--definition DEF] [--vars FILE] [--launch | --no-launch] --revision REV [--tester]
|
||||
```
|
||||
|
||||
`scripts/mosaic` sends `business instances` and `business instance` here and
|
||||
@@ -988,7 +1000,7 @@ The Console Settings page has the same read and write (`packages/webui`).
|
||||
|
||||
## Token usage
|
||||
|
||||
`mosaic usage [--business ID] [--json]` reads the bus's accounting, without
|
||||
`mosaic usage [--business ID] [--json] [--tester]` reads the bus's accounting, without
|
||||
opening its database or transcripts. Text lists the total and run, instance,
|
||||
provider/model, provider and account groups, with input/output/cacheWrite/
|
||||
cacheRead and unknown turns beside every total. JSON retains the full view.
|
||||
|
||||
@@ -52,8 +52,8 @@ export const USAGE = `usage:
|
||||
mosaic talk <role> <text> [--wait <seconds> | --follow] [--business <id>] [--tester]
|
||||
mosaic follow [--business <id>] [--tester]
|
||||
${THREAD_TALK_USAGE}
|
||||
mosaic name <instance> <name> [--business <id>]
|
||||
mosaic names [--business <id>] [--json]
|
||||
mosaic name <instance> <name> [--business <id>] [--tester]
|
||||
mosaic names [--business <id>] [--json] [--tester]
|
||||
mosaic stop <run>
|
||||
mosaic launches off|on [--business <id>]
|
||||
mosaic launches list [--json]
|
||||
@@ -307,9 +307,10 @@ async function human(verb, rest, io, deps) {
|
||||
}
|
||||
|
||||
// Row 141 (#1635, REQ-MSG-2): `mosaic name` sets the name `talk` and message.send accept for an
|
||||
// instance; `mosaic names` lists the current ones. Both are the human's.
|
||||
// instance; `mosaic names` lists the current ones. Both are the human's, and since row 175
|
||||
// (#1673, Q173) the tester's too.
|
||||
async function names(verb, rest, io, deps) {
|
||||
const parsed = parse(rest, { flags: verb === "names" ? ["--json"] : [], values: ["--business"] });
|
||||
const parsed = parse(rest, { flags: verb === "names" ? ["--json", "--tester"] : ["--tester"], values: ["--business"] });
|
||||
if (parsed.positional.length !== (verb === "name" ? 2 : 0)) throw usage(verb === "name" ? "name takes an instance and a name" : "names takes no arguments");
|
||||
const call = callFor(parsed, io, deps);
|
||||
if (verb === "name") {
|
||||
@@ -322,7 +323,6 @@ async function names(verb, rest, io, deps) {
|
||||
}
|
||||
|
||||
const TALK_WAIT_S = 900;
|
||||
const TESTER_PREFIX = "[mos test]";
|
||||
const TALK_POLL_MS = 2000;
|
||||
|
||||
function formatMessage(m) {
|
||||
@@ -365,8 +365,6 @@ async function talk(rest, io, deps, receiveOnly = false) {
|
||||
if (!Number.isInteger(wait) || wait < 0) throw usage("--wait takes whole seconds, 0 or more");
|
||||
let [to, body] = parsed.positional;
|
||||
if (threadRef !== undefined) [to, body] = [threadRef, to];
|
||||
// The broker refuses it too (tester-prefix); this is the clear early message.
|
||||
if (!receiveOnly && parsed.flags.has("--tester") && !body.startsWith(TESTER_PREFIX)) throw new CliError(`a tester message starts with "${TESTER_PREFIX}"`, 2);
|
||||
const call = threadRef === undefined ? callFor(parsed, io, deps) : channelCallFor(parsed, io, deps);
|
||||
let sent;
|
||||
let thread = null;
|
||||
@@ -568,7 +566,7 @@ export async function main(argv, io = { env: process.env, stdin: process.stdin,
|
||||
if (argv.length === 0) return app(io, deps);
|
||||
const [verb, ...rest] = argv;
|
||||
if (["inbox", "decide", "tasks", "agents", "trail"].includes(verb)) return human(verb, rest, io, deps);
|
||||
if (verb === "project") return ["create", "list"].includes(rest[0]) ? projectBusCommand(rest, io, (p) => channelCallFor(p, io, deps)) : projectCommand(rest, io, deps);
|
||||
if (verb === "project") return ["create", "list"].includes(rest[0]) ? projectBusCommand(rest, io, (p) => channelCallFor(p, io, deps)) : projectCommand(rest, io, deps, (p) => callFor(p, io, deps));
|
||||
if (verb === "threads") return threadsCommand(rest, io, (p) => channelCallFor(p, io, deps));
|
||||
if (verb === "thread") return threadCommand(rest, io, (p) => channelCallFor(p, io, deps), formatMessage);
|
||||
if (verb === "limits") return limitsCommand(rest,io,p=>callFor(p,io,deps));
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// `mosaic business instances` and `mosaic business instance add|set` (row 165, #1662, Q171,
|
||||
// REQ-ROLE-3): the human reads, adds and changes role instances through the broker's human-only
|
||||
// instances and instances.set verbs. The broker refuses an agent, a reader and a tester; the
|
||||
// business package's instance writer refuses a stale revision and every document
|
||||
// `mosaic business validate` would refuse, and logs the change with its actor.
|
||||
// REQ-ROLE-3): the human reads, adds and changes role instances through the broker's instances
|
||||
// and instances.set verbs, and with --tester the tester does (row 175, #1673, Q173). The broker
|
||||
// refuses an agent and a reader; the business package's instance writer refuses a stale revision
|
||||
// and every document `mosaic business validate` would refuse, and logs the change with its actor.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { CliError } from "./errors.mjs";
|
||||
|
||||
export const INSTANCES_USAGE = "mosaic business instances BUSINESS [--json] | " +
|
||||
"business instance add BUSINESS INSTANCE --definition DEF [--vars FILE] [--launch] --revision REV | " +
|
||||
"business instance set BUSINESS INSTANCE [--definition DEF] [--vars FILE] [--launch | --no-launch] --revision REV";
|
||||
export const INSTANCES_USAGE = "mosaic business instances BUSINESS [--json] [--tester] | " +
|
||||
"business instance add BUSINESS INSTANCE --definition DEF [--vars FILE] [--launch] --revision REV [--tester] | " +
|
||||
"business instance set BUSINESS INSTANCE [--definition DEF] [--vars FILE] [--launch | --no-launch] --revision REV [--tester]";
|
||||
|
||||
// The bus answers a refusal with its code alone, so the reason a human reads is here.
|
||||
export const REASONS = {
|
||||
@@ -32,7 +32,7 @@ function parse(args) {
|
||||
const out = { positional: [], flags: new Set(), values: {} };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (["--json", "--launch", "--no-launch"].includes(arg)) {
|
||||
if (["--json", "--launch", "--no-launch", "--tester"].includes(arg)) {
|
||||
if (out.flags.has(arg)) throw new CliError(INSTANCES_USAGE, 4);
|
||||
out.flags.add(arg);
|
||||
} else if (["--definition", "--vars", "--revision"].includes(arg)) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { CliError } from "./errors.mjs";
|
||||
import { migrateLaunch } from "../../business/src/migrate-launch.mjs";
|
||||
|
||||
// Row 155 (#1649, Q169): a PATCH may carry `assistants`, the assistant's vars, tracker and definition.
|
||||
export const LIMITS_USAGE = "mosaic limits [--business ID] [--json] | set --file PATCH [--business ID] | " +
|
||||
export const LIMITS_USAGE = "mosaic limits [--business ID] [--json] [--tester] | set --file PATCH [--business ID] | " +
|
||||
"reset PATH... [--business ID] | migrate --file ORGANIZATION --models MAPPING [--roles-dir DIR]; " +
|
||||
"PATCH keys: revision, limits, models, instances, reset, assistants";
|
||||
|
||||
@@ -35,7 +35,7 @@ export function parseLimits(args) {
|
||||
const out = { positional: [], flags: new Set(), values: {} };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === "--json") out.flags.add(arg);
|
||||
if (arg === "--json" || arg === "--tester") out.flags.add(arg);
|
||||
else if (["--file", "--models", "--roles-dir", "--business"].includes(arg)) {
|
||||
if (!args[i + 1] || Object.hasOwn(out.values, arg)) throw new CliError(LIMITS_USAGE, 4);
|
||||
out.values[arg] = args[++i];
|
||||
@@ -50,6 +50,8 @@ export async function limitsCommand(args, io, callFor) {
|
||||
const verb = parsed.positional[0] ?? "view";
|
||||
const values = parsed.values;
|
||||
if (parsed.positional.length > 1 && verb !== "reset") throw new CliError(LIMITS_USAGE, 4);
|
||||
// Row 175 (#1673, Q173): the tester reads limits; set, reset and migrate stay the human's.
|
||||
if (parsed.flags.has("--tester") && verb !== "view") throw new CliError(`--tester takes only the read\n${LIMITS_USAGE}`, 4);
|
||||
try {
|
||||
if (verb === "migrate") {
|
||||
if (!values["--file"] || !values["--models"] || values["--business"]) {
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
// `mosaic plugins` (vikunja:19/305, REQ-PLUG-1): read and switch the organization file's plug-in
|
||||
// modules through the broker's human-only plugins and plugins.set verbs. The broker refuses an
|
||||
// agent, a reader and a tester, a stale revision, a bad shape and a module that doesn't exist, and
|
||||
// the change is logged with its actor in the organization's changes.jsonl.
|
||||
// modules through the broker's plugins and plugins.set verbs, the human's and, with --tester, the
|
||||
// tester's (row 175, #1673, Q173). The broker refuses an agent and a reader, a stale revision, a bad
|
||||
// shape and a module that doesn't exist, and the change is logged with its actor (the human or
|
||||
// `tester`) in the organization's changes.jsonl.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { CliError } from "./errors.mjs";
|
||||
|
||||
export const PLUGINS_USAGE = "mosaic plugins [--business ID] [--json] | set --file PATCH [--business ID]";
|
||||
export const PLUGINS_USAGE = "mosaic plugins [--business ID] [--json] [--tester] | set --file PATCH [--business ID] [--tester]";
|
||||
|
||||
function parse(args) {
|
||||
const out = { positional: [], flags: new Set(), values: {} };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === "--json") out.flags.add(arg);
|
||||
if (arg === "--json" || arg === "--tester") out.flags.add(arg);
|
||||
else if (["--file", "--business"].includes(arg)) {
|
||||
if (!args[i + 1] || Object.hasOwn(out.values, arg)) throw new CliError(PLUGINS_USAGE, 4);
|
||||
out.values[arg] = args[++i];
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
import { configDir, loadBusiness } from '../../business/src/index.mjs';
|
||||
import { checkProject, initProject, ProjectError } from '../../project/src/index.mjs';
|
||||
import { checkProject, initProject, ProjectError, testerProjectArea } from '../../project/src/index.mjs';
|
||||
import { loadSystem, rolesDir } from './config.mjs';
|
||||
import { CliError } from './errors.mjs';
|
||||
import { shortId } from './format.mjs';
|
||||
import { parseArgs } from './thread.mjs';
|
||||
import { refuseInsideAgent } from './transport.mjs';
|
||||
|
||||
export const PROJECT_USAGE = 'mosaic project init|check <business> <project>';
|
||||
export const PROJECT_USAGE = 'mosaic project init <business> <project> [--tester] | check <business> <project>';
|
||||
// Row 128 (#1622): create and list work on the bus record (project.create, project.list); init
|
||||
// and check above work on the repository on disk and never contact the bus.
|
||||
// and check above work on the repository on disk and never contact the bus, except that
|
||||
// init --tester (row 175, #1673) binds the tester once before it writes.
|
||||
export const PROJECT_BUS_USAGE = [
|
||||
'mosaic project create <name> [--repo <repo>] [--business <id>]',
|
||||
'mosaic project list [--business <id>] [--json]',
|
||||
'mosaic project create <name> [--repo <repo>] [--business <id>] [--tester]',
|
||||
'mosaic project list [--business <id>] [--json] [--tester]',
|
||||
'A thread project named for a business repository must carry that repo: --repo <name>.',
|
||||
].join('\n ');
|
||||
|
||||
export async function projectBusCommand(args, io, callFor) {
|
||||
const [sub, ...rest] = args;
|
||||
const parsed = parseArgs(rest, PROJECT_BUS_USAGE, sub === 'create'
|
||||
? { values: ['--repo', '--business'] }
|
||||
: { flags: ['--json'], values: ['--business'] });
|
||||
? { flags: ['--tester'], values: ['--repo', '--business'] }
|
||||
: { flags: ['--json', '--tester'], values: ['--business'] });
|
||||
if (parsed.positional.length !== (sub === 'create' ? 1 : 0))
|
||||
throw new CliError(`project ${sub} takes ${sub === 'create' ? 'one name' : 'no arguments'}\n${PROJECT_BUS_USAGE}`, 4);
|
||||
const call = callFor(parsed);
|
||||
@@ -40,17 +41,27 @@ export async function projectBusCommand(args, io, callFor) {
|
||||
io.stdout.write(projects.length === 0 ? 'no projects\n' : projects.map(p => `${p.name} ${p.repo ?? '-'} ${shortId(p.id)}\n`).join(''));
|
||||
}
|
||||
|
||||
export async function projectCommand(args, io, deps = {}) {
|
||||
if (args.length !== 3 || !['init', 'check'].includes(args[0]) || args.some(arg => arg.startsWith('--')))
|
||||
// Row 175 (#1673, Q173, mos-0872 Q2): `init --tester` may run inside an agent. Before anything
|
||||
// touches the disk it refuses a repository outside <dataRoot>/projects/<business>/
|
||||
// (tester-project-area, exit 2), then binds the tester with one agents read, so tester-off and
|
||||
// tester-required refuse (exit 3), then commits the layout as `tester`.
|
||||
export async function projectCommand(args, io, deps = {}, callFor) {
|
||||
const tester = args[0] === 'init' && args.filter(arg => arg === '--tester').length === 1;
|
||||
const words = tester ? args.filter(arg => arg !== '--tester') : args;
|
||||
if (words.length !== 3 || !['init', 'check'].includes(words[0]) || words.some(arg => arg.startsWith('--')))
|
||||
throw new CliError(PROJECT_USAGE, 4);
|
||||
const [verb, id, project] = args;
|
||||
if (verb === 'init') refuseInsideAgent(io.env);
|
||||
const [verb, id, project] = words;
|
||||
if (verb === 'init' && !tester) refuseInsideAgent(io.env);
|
||||
try {
|
||||
const system = deps.system ?? loadSystem({ env: io.env });
|
||||
const business = loadBusiness(id, { dir: configDir(io.env), rolesDir: rolesDir(io.env) });
|
||||
const context = { business, project, dataRoot: system.dataRoot };
|
||||
if (tester) {
|
||||
testerProjectArea(context);
|
||||
await callFor({ positional: [], flags: new Set(['--tester']), values: { '--business': id } })('agents', {});
|
||||
}
|
||||
if (verb === 'init') {
|
||||
const result = await initProject(context);
|
||||
const result = await initProject(context, tester ? { author: 'tester' } : {});
|
||||
io.stdout.write(`initialized ${result.repo}\ncommit ${result.commit}\n`);
|
||||
} else {
|
||||
const result = await checkProject(context);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { shortId } from "./format.mjs";
|
||||
import { configDir, loadBusiness } from "../../business/src/index.mjs";
|
||||
import { rolesDir } from "./config.mjs";
|
||||
|
||||
export const THREADS_USAGE = "mosaic threads [--project <project>] [--business <id>] [--json]";
|
||||
export const THREADS_USAGE = "mosaic threads [--project <project>] [--business <id>] [--json] [--tester]";
|
||||
export const THREAD_USAGE = [
|
||||
"mosaic thread create <project> <name> [--business <id>]",
|
||||
"mosaic thread open <thread> [--business <id>]",
|
||||
@@ -107,8 +107,9 @@ export function threadMembers(call, thread) {
|
||||
|
||||
const json = (io, value) => io.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
||||
|
||||
// Row 175 (#1673, Q173): with --tester the tester lists the business human's threads.
|
||||
export async function threadsCommand(args, io, callFor) {
|
||||
const parsed = parseArgs(args, THREADS_USAGE, { flags: ["--json"], values: ["--business", "--project"] });
|
||||
const parsed = parseArgs(args, THREADS_USAGE, { flags: ["--json", "--tester"], values: ["--business", "--project"] });
|
||||
if (parsed.positional.length !== 0) throw new CliError(`threads takes no arguments\n${THREADS_USAGE}`, 4);
|
||||
const call = callFor(parsed);
|
||||
const project = parsed.values["--project"] === undefined ? null : await resolveProject(call, parsed.values["--project"], { business: call.business, env: io.env });
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { CliError } from './errors.mjs';
|
||||
export const USAGE_USAGE = 'mosaic usage [--business ID] [--json]';
|
||||
export const USAGE_USAGE = 'mosaic usage [--business ID] [--json] [--tester]';
|
||||
export async function usageCommand(args, io, callFor) {
|
||||
const parsed = { flags: new Set(), values: {} };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === '--json' && !parsed.flags.has(arg)) parsed.flags.add(arg);
|
||||
if ((arg === '--json' || arg === '--tester') && !parsed.flags.has(arg)) parsed.flags.add(arg);
|
||||
else if (arg === '--business' && args[i + 1] && !args[i + 1].startsWith('--') && !parsed.values[arg]) parsed.values[arg] = args[++i];
|
||||
else throw new CliError(USAGE_USAGE, 4);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,6 @@ test("name and names refuse the wrong number of arguments with the usage", async
|
||||
assert.ok(r.error.endsWith(USAGE), r.error);
|
||||
}
|
||||
assert.equal(s.calls.length, 0);
|
||||
assert.match(USAGE, /^ {2}mosaic name <instance> <name> \[--business <id>\]$/m);
|
||||
assert.match(USAGE, /^ {2}mosaic names \[--business <id>\] \[--json\]$/m);
|
||||
assert.match(USAGE, /^ {2}mosaic name <instance> <name> \[--business <id>\] \[--tester\]$/m);
|
||||
assert.match(USAGE, /^ {2}mosaic names \[--business <id>\] \[--json\] \[--tester\]$/m);
|
||||
});
|
||||
@@ -0,0 +1,185 @@
|
||||
// Row 175 (#1673, Q173, mos-0870 N2, mos-0872): the CLI's tester forms. The seven reads print what
|
||||
// the human's forms print, every write form outside W1-W7 refuses --tester before any call, and
|
||||
// `project init --tester` checks the project area, binds the tester, then commits as `tester`.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { existsSync, readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { main } from "../src/cli.mjs";
|
||||
import { BusError } from "../../bus/src/broker.mjs";
|
||||
import { startBroker } from "../../bus/src/runtime.mjs";
|
||||
import { systemFor, writeJson } from "../../business/tests/helpers.mjs";
|
||||
import { fixture, humanEnv, io, tmp } from "./helpers.mjs";
|
||||
|
||||
const none = { authority: { withinRole: ["message.send"], crossRole: [] } };
|
||||
const inAgent = (env) => io({ ...env, CLAUDECODE: "1", CLAUDE_CODE_ENTRYPOINT: "sdk-ts" });
|
||||
const bus = (vars = { "bus.tester": true }) => ({
|
||||
acme: {
|
||||
id: "acme", human: "jason", arbiters: { technical: "coder", delivery: "coder" }, ...(vars ? { vars } : {}),
|
||||
roles: { coder: { definition: "coder", ...none }, assistant: { definition: "assistant", ...none } },
|
||||
},
|
||||
});
|
||||
|
||||
// The runtime in this process behind stand-in transports, as instances.test.mjs.
|
||||
async function setup(t) {
|
||||
const root = tmp(t, "mosaic-cli-tester-reads-");
|
||||
const f = fixture(root, "acme");
|
||||
const rt = await startBroker({ dataRoot: f.dataRoot, businesses: bus(), organization: { dir: join(root, "config"), rolesDir: f.roles, system: systemFor(root) } });
|
||||
t.after(() => rt.close());
|
||||
const human = rt.broker.bindHuman({ business: "acme", human: "jason", via: "cli", outsideAgent: true });
|
||||
const tester = rt.broker.bindTester({ business: "acme" });
|
||||
const calls = { human: [], tester: [] };
|
||||
const via = (cap, list) => (business) => async (verb, args = {}) => {
|
||||
list.push(verb);
|
||||
try {
|
||||
return structuredClone(rt.broker.request(cap, { verb, args }));
|
||||
} catch (e) {
|
||||
if (!(e instanceof BusError)) throw e;
|
||||
const error = new Error(e.code);
|
||||
error.code = e.code;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
const deps = { system: { dataRoot: f.dataRoot }, transport: via(human, calls.human), testerTransport: via(tester, calls.tester), talkPollMs: 5 };
|
||||
const call = (verb, args = {}) => rt.broker.request(human, { verb, args });
|
||||
return { root, f, rt, human, tester, calls, deps, call };
|
||||
}
|
||||
|
||||
const READS = [
|
||||
["usage"],
|
||||
["names"],
|
||||
["limits"],
|
||||
["plugins"],
|
||||
["threads"],
|
||||
["project", "list"],
|
||||
];
|
||||
|
||||
test("row 175: each read with --tester inside an agent prints the human form's output, and refuses without --tester", async (t) => {
|
||||
const s = await setup(t);
|
||||
s.call("plugins.set", { revision: s.call("plugins").revision, plugins: { channel: ["cli", "webui"] } });
|
||||
s.call("name.set", { instance: "coder", name: "rex" });
|
||||
const project = s.call("project.create", { name: "alpha" }).id;
|
||||
s.call("thread.create", { project, name: "one" });
|
||||
const forms = [...READS.map((argv) => [...argv, "--business", "acme"]), ["business", "instances", "acme"]];
|
||||
for (const argv of forms) {
|
||||
const name = argv.slice(0, 2).join(" ");
|
||||
const h = io(s.f.env);
|
||||
await main(argv, h, s.deps);
|
||||
const humanCalls = s.calls.human.length;
|
||||
const testerCalls = s.calls.tester.length;
|
||||
const x = inAgent(s.f.env);
|
||||
await main([...argv, "--tester"], x, s.deps);
|
||||
assert.equal(x.out.text, h.out.text, name);
|
||||
assert.ok(x.out.text.length > 0, name);
|
||||
assert.equal(s.calls.human.length, humanCalls, `${name}: the tester form made no human call`);
|
||||
assert.ok(s.calls.tester.length > testerCalls, `${name}: the tester form called the tester transport`);
|
||||
await assert.rejects(main(argv, inAgent(s.f.env), s.deps), (e) => e.exitCode === 3, `${name} without --tester`);
|
||||
assert.equal(s.calls.human.length, humanCalls, `${name}: the refusal came before any call`);
|
||||
}
|
||||
// Not empty: the names, the thread and the project the human made are in the tester's view.
|
||||
const x = inAgent(s.f.env);
|
||||
await main(["threads", "--business", "acme", "--json", "--tester"], x, s.deps);
|
||||
assert.deepEqual(JSON.parse(x.out.text).map((r) => r.name), ["one"]);
|
||||
});
|
||||
|
||||
test("row 175: --tester on limits set, reset and migrate and every write form outside W1-W7 exits 4 before any call", async (t) => {
|
||||
const s = await setup(t);
|
||||
for (const argv of [
|
||||
["limits", "set", "--file", "patch.json", "--business", "acme"],
|
||||
["limits", "reset", "total", "--business", "acme"],
|
||||
["limits", "migrate", "--file", "org.json", "--models", "map.json"],
|
||||
["decide", "d1", "yes", "--business", "acme"],
|
||||
["inbox", "--read", "abcdefgh", "--business", "acme"],
|
||||
["inbox", "--read-all", "--business", "acme"],
|
||||
["thread", "create", "alpha", "one", "--business", "acme"],
|
||||
["thread", "open", "t-1", "--business", "acme"],
|
||||
["thread", "read", "t-1", "--business", "acme"],
|
||||
["talk", "--thread", "t-1", "hello", "--business", "acme"],
|
||||
["follow", "--thread", "t-1", "--business", "acme"],
|
||||
["stop", "run-1"],
|
||||
["launches", "off", "--business", "acme"],
|
||||
["launches", "on", "--business", "acme"],
|
||||
["launches", "list"],
|
||||
["project", "check", "acme", "stack"],
|
||||
["project", "init", "acme", "stack", "--tester"],
|
||||
]) {
|
||||
const x = inAgent(s.f.env);
|
||||
await assert.rejects(main([...argv, "--tester"], x, s.deps), (e) => e.exitCode === 4, argv.join(" "));
|
||||
}
|
||||
assert.deepEqual(s.calls, { human: [], tester: [] });
|
||||
assert.equal(existsSync(join(s.f.dataRoot, "projects")), false);
|
||||
});
|
||||
|
||||
// W7 through the real tester transport: the CLI runs as its own process, so the tester-cli.mjs it
|
||||
// spawns can reach the runtime in this one.
|
||||
const MOSAIC = fileURLToPath(new URL("../../../scripts/mosaic", import.meta.url));
|
||||
function mosaic(args, env) {
|
||||
const clean = Object.fromEntries(Object.entries(env).filter(([k]) => !/^MOSAIC_BUS_(TESTER|CLI)_NONCE$/.test(k)));
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(MOSAIC, args, { env: clean, timeout: 60000 });
|
||||
let out = "";
|
||||
let err = "";
|
||||
child.stdout.on("data", (d) => (out += d));
|
||||
child.stderr.on("data", (d) => (err += d));
|
||||
child.on("error", reject);
|
||||
child.on("close", (status) => resolve({ status, out, err }));
|
||||
});
|
||||
}
|
||||
const listing = (dir) => readdirSync(dir, { recursive: true }).map(String).sort();
|
||||
async function w7(t, vars, edit) {
|
||||
const root = tmp(t, "mosaic-cli-tester-init-");
|
||||
const f = fixture(root, "acme", edit);
|
||||
const rt = await startBroker({ dataRoot: f.dataRoot, businesses: bus(vars) });
|
||||
t.after(() => rt.close());
|
||||
return { root, f, agent: { ...f.env, CLAUDECODE: "1", CLAUDE_CODE_ENTRYPOINT: "sdk-ts" } };
|
||||
}
|
||||
|
||||
test("row 175 W7: project init --tester makes the repository under the project area, committed by tester", async (t) => {
|
||||
const { f, agent } = await w7(t);
|
||||
const r = await mosaic(["project", "init", "acme", "stack", "--tester"], agent);
|
||||
assert.equal(r.status, 0, r.err);
|
||||
const repo = join(f.dataRoot, "projects", "acme", "stack");
|
||||
assert.match(r.out, new RegExp(`^initialized ${repo}\ncommit [0-9a-f]{40}\n$`));
|
||||
const log = spawnSync("git", ["-C", repo, "log", "--format=%an|%cn"], { encoding: "utf8" });
|
||||
assert.equal(log.stdout, "tester|tester\n");
|
||||
// Without --tester the same init inside an agent refuses, as before.
|
||||
const again = await mosaic(["project", "init", "acme", "stack"], agent);
|
||||
assert.equal(again.status, 3);
|
||||
assert.match(again.err, /outside any agent run/);
|
||||
});
|
||||
|
||||
test("row 175 W7: a repo outside the project area refuses tester-project-area before any bus call, and nothing changes", async (t) => {
|
||||
// The switch is off: a bind would refuse tester-off (exit 3), so exit 2 shows the area check ran first.
|
||||
const { f, agent } = await w7(t, null, (doc) => {
|
||||
doc.projects.stack.repo = join(doc.projects.stack.root, "..", "records");
|
||||
return doc;
|
||||
});
|
||||
const records = f.doc.projects.stack.repo;
|
||||
const data = listing(f.dataRoot);
|
||||
const r = await mosaic(["project", "init", "acme", "stack", "--tester"], agent);
|
||||
assert.equal(r.status, 2, r.err);
|
||||
assert.match(r.err, /tester-project-area/);
|
||||
assert.equal(existsSync(records), false);
|
||||
assert.deepEqual(listing(f.dataRoot), data);
|
||||
});
|
||||
|
||||
test("row 175 W7: the tester bind refuses tester-off and tester-required before any directory", async (t) => {
|
||||
const off = await w7(t, null);
|
||||
const data = listing(off.f.dataRoot);
|
||||
const r = await mosaic(["project", "init", "acme", "stack", "--tester"], off.agent);
|
||||
assert.equal(r.status, 3, r.err);
|
||||
assert.match(r.err, /tester-off/);
|
||||
assert.deepEqual(listing(off.f.dataRoot), data);
|
||||
assert.equal(existsSync(join(off.f.dataRoot, "projects")), false);
|
||||
const on = await w7(t);
|
||||
const before = listing(on.f.dataRoot);
|
||||
for (const marker of ["MOSAIC_RUN_ID", "MOSAIC_BUS_CAP", "MOSAIC_AGENT_RUN"]) {
|
||||
const under = await mosaic(["project", "init", "acme", "stack", "--tester"], { ...on.agent, [marker]: "x" });
|
||||
assert.equal(under.status, 3, `${marker}: ${under.err}`);
|
||||
assert.match(under.err, /tester-required/, marker);
|
||||
}
|
||||
assert.deepEqual(listing(on.f.dataRoot), before);
|
||||
assert.equal(existsSync(join(on.f.dataRoot, "projects")), false);
|
||||
});
|
||||
@@ -38,7 +38,7 @@ function setup(t, extra = {}) {
|
||||
// The tester runs inside an agent: a T3 seat or Mos.
|
||||
const inAgent = () => io({ ...humanEnv(), CLAUDECODE: "1", CLAUDE_CODE_ENTRYPOINT: "sdk-ts" });
|
||||
|
||||
test("talk --tester sends a [mos test] message as tester from inside an agent and prints the role's reply", async (t) => {
|
||||
test("talk --tester sends a message as tester from inside an agent and prints the role's reply", async (t) => {
|
||||
const s = setup(t);
|
||||
const x = inAgent();
|
||||
const deps = {
|
||||
@@ -57,7 +57,7 @@ test("talk --tester sends a [mos test] message as tester from inside an agent an
|
||||
};
|
||||
},
|
||||
};
|
||||
await main(["talk", "coder", "[mos test] is the plan current?", "--tester", "--business", "demo"], x, deps);
|
||||
await main(["talk", "coder", "is the plan current?", "--tester", "--business", "demo"], x, deps);
|
||||
assert.match(x.out.text, /^sent [0-9a-f-]{8} to coder\n/);
|
||||
assert.match(x.out.text, /coder \(INFO, re [0-9a-f-]{8}\) [0-9a-f-]{8}:\nthe plan is current\n/);
|
||||
assert.deepEqual(s.calls.human, []);
|
||||
@@ -69,11 +69,13 @@ test("talk --tester sends a [mos test] message as tester from inside an agent an
|
||||
assert.equal(s.store.get("SELECT count(*) n FROM events WHERE kind='human.input'").n, 0);
|
||||
});
|
||||
|
||||
test("talk --tester refuses text without the [mos test] prefix before any call", async (t) => {
|
||||
// Row 175 (#1673, mos-0872 Q1): the test system needs no "[mos test]" prefix; the body goes as typed.
|
||||
test("talk --tester sends text with no prefix, and follow --tester reads", async (t) => {
|
||||
const s = setup(t);
|
||||
await assert.rejects(main(["talk", "coder", "is the plan current?", "--tester", "--business", "demo"], inAgent(), s.deps), (e) => e.exitCode === 2 && /starts with "\[mos test\]"/.test(e.message));
|
||||
assert.deepEqual(s.calls.tester, []);
|
||||
// follow sends nothing, so it takes no prefix.
|
||||
await main(["talk", "coder", "is the plan current?", "--tester", "--wait", "0", "--business", "demo"], inAgent(), s.deps);
|
||||
assert.deepEqual(s.calls.tester.map((c) => c.verb), ["message.send"]);
|
||||
assert.equal(s.store.get("SELECT body FROM messages WHERE from_role='tester'").body, "is the plan current?");
|
||||
s.calls.tester.length = 0;
|
||||
const controller = new AbortController();
|
||||
const deps = { ...s.deps, signal: controller.signal, testerTransport: (b) => async (verb, args) => (controller.abort(), s.deps.testerTransport(b)(verb, args)) };
|
||||
await main(["follow", "--tester", "--business", "demo"], inAgent(), deps);
|
||||
@@ -116,7 +118,6 @@ test("the tester transport runs tester-cli.mjs, and the tester's refusals exit 3
|
||||
assert.deepEqual(seen.argv, [TESTER_CLI, "/run/fake.sock"]);
|
||||
assert.deepEqual(JSON.parse(seen.input), { business: "acme", verb: "agents", args: {} });
|
||||
for (const code of ["tester-required", "tester-off", "tester-refused"]) assert.equal(busExit(code), 3, code);
|
||||
assert.equal(busExit("tester-prefix"), 2);
|
||||
});
|
||||
|
||||
test("with no stand-in transport, --tester runs tester-cli.mjs on the data root's socket", async (t) => {
|
||||
|
||||
Reference in new issue
Block a user