fix(organization): validate narrowed arbiter resolve authority (#1873)
This commit was merged in pull request #1911.
This commit is contained in:
1 parent
7de9cfccc3
commit
e9a079fcc4
6 files changed
+45
-6
No files matched your search
@@ -76,4 +76,7 @@ test('RR: remapping arbiters cannot let a legacy decision resolve with only the
|
|||||||
f.broker.reloadBusiness('demo', f.business);
|
f.broker.reloadBusiness('demo', f.business);
|
||||||
assert.throws(() => f.call(f.pm, 'decision.resolve', { id, choice: 'yes' }), { code: 'not-resolver' });
|
assert.throws(() => f.call(f.pm, 'decision.resolve', { id, choice: 'yes' }), { code: 'not-resolver' });
|
||||||
assert.equal(f.store.get('SELECT count(*) n FROM decision_events WHERE decision=?', id).n, 0);
|
assert.equal(f.store.get('SELECT count(*) n FROM decision_events WHERE decision=?', id).n, 0);
|
||||||
|
// Human recovery closes the old route by withdrawing it, before the raiser creates a new decision.
|
||||||
|
f.call(f.human, 'decision.withdraw', { id });
|
||||||
|
assert.equal(f.store.get('SELECT op FROM decision_events WHERE decision=?', id).op, 'withdrawn');
|
||||||
});
|
});
|
||||||
@@ -55,7 +55,7 @@ for (const harness of ['pi', 'claude-code']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('PM intake writes and staff request follow the existing message.send grant', t => {
|
test('PM intake writes and staff request follow the existing message.send grant', t => {
|
||||||
const muted = bundle(t, 'pm', 'pi', doc => { doc.roles.pm.vars['limits.authority'] = ['task.assign']; });
|
const muted = bundle(t, 'pm', 'pi', doc => { doc.roles.pm.vars['limits.authority'] = ['task.assign', 'decision.resolve.delivery']; });
|
||||||
assert.deepEqual(muted.tools.filter(intake).map(t => t.name).sort(), reads.toSorted());
|
assert.deepEqual(muted.tools.filter(intake).map(t => t.name).sort(), reads.toSorted());
|
||||||
assert.ok(!muted.tools.some(t => t.name === 'request_staff'));
|
assert.ok(!muted.tools.some(t => t.name === 'request_staff'));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ test("request_staff is the pm's alone: staff.request over message.send, roles an
|
|||||||
const assistant = resolvedFor(t, "assistant", (d) => (d.roles.assistant = { definition: "assistant", holder: "mos" }));
|
const assistant = resolvedFor(t, "assistant", (d) => (d.roles.assistant = { definition: "assistant", holder: "mos" }));
|
||||||
assert.ok(!names(typedTools({ resolved: assistant })).includes("request_staff"));
|
assert.ok(!names(typedTools({ resolved: assistant })).includes("request_staff"));
|
||||||
// A pm without message.send is offered no request_staff, as for send_message.
|
// A pm without message.send is offered no request_staff, as for send_message.
|
||||||
const mute = resolvedFor(t, "pm", (d) => (d.roles.pm.vars["limits.authority"] = ["task.assign"]));
|
const mute = resolvedFor(t, "pm", (d) => (d.roles.pm.vars["limits.authority"] = ["task.assign", "decision.resolve.delivery"]));
|
||||||
assert.ok(!names(typedTools({ resolved: mute, tracker: true })).includes("request_staff"));
|
assert.ok(!names(typedTools({ resolved: mute, tracker: true })).includes("request_staff"));
|
||||||
// The pm still has no launch tool, and the chief of staff's launch offer is its limits, not a request.
|
// The pm still has no launch tool, and the chief of staff's launch offer is its limits, not a request.
|
||||||
assert.ok(!names(tools).includes("launch"));
|
assert.ok(!names(tools).includes("launch"));
|
||||||
@@ -241,7 +241,7 @@ test("list_requirements reads the requirement ids, for a task.create holder with
|
|||||||
assert.match(list.description, /task_create takes only these/);
|
assert.match(list.description, /task_create takes only these/);
|
||||||
assert.match(list.description, /Product intake always needs an approved product snapshot/);
|
assert.match(list.description, /Product intake always needs an approved product snapshot/);
|
||||||
assert.ok(!names(typedTools({ resolved: pm, arbiter: true })).includes("list_requirements"));
|
assert.ok(!names(typedTools({ resolved: pm, arbiter: true })).includes("list_requirements"));
|
||||||
const noCreate = resolvedFor(t, "pm", (d) => (d.roles.pm.vars["limits.authority"] = ["message.send", "task.assign"]));
|
const noCreate = resolvedFor(t, "pm", (d) => (d.roles.pm.vars["limits.authority"] = ["message.send", "task.assign", "decision.resolve.delivery"]));
|
||||||
const without = names(typedTools({ resolved: noCreate, tracker: true }));
|
const without = names(typedTools({ resolved: noCreate, tracker: true }));
|
||||||
assert.ok(without.includes("task_assign") && !without.includes("task_create") && !without.includes("list_requirements"));
|
assert.ok(without.includes("task_assign") && !without.includes("task_create") && !without.includes("list_requirements"));
|
||||||
const create = tools.find((x) => x.name === "task_create").parameters.properties;
|
const create = tools.find((x) => x.name === "task_create").parameters.properties;
|
||||||
|
|||||||
@@ -268,7 +268,9 @@ export function validateOrganizationDocument(document, file, { rolesDir }) {
|
|||||||
refuse(`${file} arbiters.${kind} names ${name}, whose role definition ${definition} declares messaging lists`);
|
refuse(`${file} arbiters.${kind} names ${name}, whose role definition ${definition} declares messaging lists`);
|
||||||
}
|
}
|
||||||
const right = `decision.resolve.${kind}`;
|
const right = `decision.resolve.${kind}`;
|
||||||
if (!definitions[definition].authority.withinRole.includes(right)) {
|
const narrowed = [vars, roles[name].vars].some(layer =>
|
||||||
|
layer["limits.authority"] !== undefined && !layer["limits.authority"].includes(right));
|
||||||
|
if (!definitions[definition].authority.withinRole.includes(right) || narrowed) {
|
||||||
refuse(`${file} arbiters.${kind} names ${name}, whose role definition ${definition} lacks ${right}`);
|
refuse(`${file} arbiters.${kind} names ${name}, whose role definition ${definition} lacks ${right}`);
|
||||||
}
|
}
|
||||||
arbiters[kind] = name;
|
arbiters[kind] = name;
|
||||||
|
|||||||
@@ -50,3 +50,37 @@ test('RR: a version 2 contract without its Authority section refuses', t => {
|
|||||||
writeFileSync(join(rolesDir, 'coder.md'), '# Role contract: coder\n\n## Duties\nRead only.\n');
|
writeFileSync(join(rolesDir, 'coder.md'), '# Role contract: coder\n\n## Duties\nRead only.\n');
|
||||||
assert.throws(() => loadRole(rolesDir, 'coder'), /coder.*## Authority/);
|
assert.throws(() => loadRole(rolesDir, 'coder'), /coder.*## Authority/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const [domain, instance] of [['technical', 'cto'], ['delivery', 'pm']]) {
|
||||||
|
for (const layer of ['agent', 'business', 'intersection']) {
|
||||||
|
test(`RR: ${layer} limits removing ${instance}'s ${domain} resolve right refuse when written`, t => {
|
||||||
|
const root = tmp(); t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||||
|
const file = join(root, 'businesses/acme.json'); writeJson(file, businessDoc(root));
|
||||||
|
const writer = organizationWriter({ dir: root, rolesDir: REPO_ROLES });
|
||||||
|
const { document, revision } = writer.read('acme'), before = readFileSync(file, 'utf8');
|
||||||
|
const right = `decision.resolve.${domain}`;
|
||||||
|
const rights = ['message.send', 'decision.resolve.technical', 'decision.resolve.delivery'];
|
||||||
|
if (layer === 'agent') document.roles[instance].vars['limits.authority'] = ['message.send'];
|
||||||
|
else document.vars['limits.authority'] = rights.filter(value => value !== right);
|
||||||
|
if (layer === 'intersection') document.roles[instance].vars['limits.authority'] = rights;
|
||||||
|
assert.throws(() => writer.write('acme', document, { revision, actor: 'jason' }), error => {
|
||||||
|
assert.match(error.message, new RegExp(`arbiters\\.${domain}.*${instance}.*role definition ${instance}.*decision\\.resolve\\.${domain}`));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.equal(readFileSync(file, 'utf8'), before);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test('RR: narrowed arbiters retaining their domain rights can be written', t => {
|
||||||
|
const root = tmp(); t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||||
|
const file = join(root, 'businesses/acme.json'); writeJson(file, businessDoc(root));
|
||||||
|
const writer = organizationWriter({ dir: root, rolesDir: REPO_ROLES });
|
||||||
|
const { document, revision } = writer.read('acme');
|
||||||
|
document.vars['limits.authority'] = ['message.send', 'decision.resolve.technical', 'decision.resolve.delivery'];
|
||||||
|
for (const [domain, instance] of [['technical', 'cto'], ['delivery', 'pm']]) {
|
||||||
|
document.roles[instance].vars['limits.authority'] = ['message.send', `decision.resolve.${domain}`];
|
||||||
|
}
|
||||||
|
writer.write('acme', document, { revision, actor: 'jason' });
|
||||||
|
assert.deepEqual(writer.read('acme').document.arbiters, document.arbiters);
|
||||||
|
});
|
||||||
@@ -138,10 +138,10 @@ test("limits.authority without role.launch leaves the launcher with no launch bl
|
|||||||
test("limits.authority narrows cross-role actions too", () => {
|
test("limits.authority narrows cross-role actions too", () => {
|
||||||
// pm, the role with two cross-role actions: the limit keeps one and drops the other.
|
// pm, the role with two cross-role actions: the limit keeps one and drops the other.
|
||||||
const s = setup((d) => {
|
const s = setup((d) => {
|
||||||
d.roles.pm.vars["limits.authority"] = ["task.create", "task.close", "task.priority.change"];
|
d.roles.pm.vars["limits.authority"] = ["task.create", "task.close", "task.priority.change", "decision.resolve.delivery"];
|
||||||
});
|
});
|
||||||
const pm = resolve(s, "pm");
|
const pm = resolve(s, "pm");
|
||||||
assert.deepEqual(pm.limits.authority, { withinRole: ["task.create", "task.close"], crossRole: ["task.priority.change"] });
|
assert.deepEqual(pm.limits.authority, { withinRole: ["task.create", "task.close", "decision.resolve.delivery"], crossRole: ["task.priority.change"] });
|
||||||
assert.equal(classify(pm, "task.priority.change"), "cross");
|
assert.equal(classify(pm, "task.priority.change"), "cross");
|
||||||
assert.equal(classify(pm, "task.scope.change"), "gated");
|
assert.equal(classify(pm, "task.scope.change"), "gated");
|
||||||
assert.equal(classify(pm, "task.assign"), "gated");
|
assert.equal(classify(pm, "task.assign"), "gated");
|
||||||
|
|||||||
Reference in new issue
Block a user