Skip to content

Commit 7702fe4

Browse files
committed
fix(scenarios): each persona's role states the writes its build prompt did not
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibxF3yXjruc2fxomWA5
1 parent 3693644 commit 7702fe4

10 files changed

Lines changed: 149 additions & 16 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
fix(scenarios): each card persona's role states the writes its build prompt did not
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The open card library (shipped in `dist/library`) gives thirteen personas a role that names the objects and verbs of the writes the card has them make or refuses them, where the card's build prompt did not state them: crm `sdr` and `partner_user`, invoice `sales_rep` and `warehouse_staff`, project `contractor` and `client_viewer`, leave `hr_officer` and `employee`, service desk `support_agent` and `team_lead`, asset `asset_admin` and `employee`, and travel `employee`. A build is judged on its permission sets against those writes (`persona-grant:*`), so the prompt now asks for each. The role also reads in each persona's run prompt ("You act for …"). No other card text changes.

‎docs/qa/scenarios/asset_lifecycle.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@
766766
"personas": [
767767
{
768768
"id": "employee",
769-
"role": "Employee (asset holder), Sales - e06",
769+
"role": "Employee (asset holder), Sales - e06, who may not approve their own disposal requests",
770770
"record": {"object": "employee", "id": "e06"},
771771
"hidden": {
772772
"objects": ["depreciation_entry"],
@@ -802,7 +802,7 @@
802802
},
803803
{
804804
"id": "asset_admin",
805-
"role": "IT asset administrator, organization-wide - e12",
805+
"role": "IT asset administrator, organization-wide - e12, who registers assets",
806806
"hidden": {"fields": [{"object": "department", "field": "asset_budget"}]}
807807
}
808808
],

‎docs/qa/scenarios/crm_account_with_contacts.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@
9595
"personas": [
9696
{
9797
"id": "sdr",
98-
"role": "Sales development representative",
98+
"role": "Sales development representative who adds, updates and removes contacts",
9999
"hidden": {"fields": [{"object": "contact", "field": "email"}]},
100100
"scope": [
101101
{"object": "account", "field": "owner", "value": "u_sam"},
102102
{"object": "contact", "field": "account.owner", "value": "u_sam"}
103103
]
104104
},
105-
{"id": "partner_user", "role": "Partner portal user", "hidden": {"objects": ["account"]}}
105+
{"id": "partner_user", "role": "Partner portal user who may not change accounts", "hidden": {"objects": ["account"]}}
106106
],
107107
"operations": [
108108
{

‎docs/qa/scenarios/invoice_with_line_items.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"personas": [
112112
{
113113
"id": "sales_rep",
114-
"role": "Sales representative",
114+
"role": "Sales representative who adds and removes invoice lines and sends invoices",
115115
"hidden": {"fields": [{"object": "invoice_line", "field": "unit_price"}]},
116116
"scope": [
117117
{"object": "invoice", "field": "owner", "value": "u_ana"},
@@ -120,7 +120,7 @@
120120
},
121121
{
122122
"id": "warehouse_staff",
123-
"role": "Warehouse staff",
123+
"role": "Warehouse staff who may read invoices but not change them",
124124
"hidden": {
125125
"objects": ["account"],
126126
"fields": [{"object": "invoice_line", "field": "amount"}, {"object": "invoice_line", "field": "unit_price"}]

‎docs/qa/scenarios/leave_balances.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@
816816
"personas": [
817817
{
818818
"id": "employee",
819-
"role": "Employee, Engineering, two years of service — e07",
819+
"role": "Employee, Engineering, two years of service — e07, who may not change their own leave balance",
820820
"record": {"object": "employee", "id": "e07"},
821821
"hidden": {"fields": [{"object": "employee", "field": "personal_phone"}]},
822822
"scope": [
@@ -846,7 +846,7 @@
846846
},
847847
{
848848
"id": "hr_officer",
849-
"role": "HR officer, organization-wide — e13",
849+
"role": "HR officer, organization-wide — e13, who deletes withdrawn leave requests",
850850
"hidden": {"fields": [{"object": "leave_request", "field": "medical_note"}]}
851851
}
852852
],

‎docs/qa/scenarios/project_with_tasks.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@
104104
"personas": [
105105
{
106106
"id": "contractor",
107-
"role": "External contractor",
107+
"role": "External contractor who logs, updates and removes their own tasks",
108108
"hidden": {"fields": [{"object": "task", "field": "estimate_hours"}, {"object": "project", "field": "total_estimate"}]},
109109
"scope": [{"object": "task", "field": "assignee", "value": "u_kim"}]
110110
},
111-
{"id": "client_viewer", "role": "Client stakeholder", "hidden": {"objects": ["task"]}}
111+
{"id": "client_viewer", "role": "Client stakeholder who may not change tasks", "hidden": {"objects": ["task"]}}
112112
],
113113
"operations": [
114114
{

‎docs/qa/scenarios/service_desk.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@
690690
"personas": [
691691
{
692692
"id": "support_agent",
693-
"role": "Support agent, Billing group — a02",
693+
"role": "Support agent, Billing group — a02, who logs tickets from customer calls",
694694
"record": {"object": "agent", "id": "a02"},
695695
"hidden": {
696696
"fields": [{"object": "customer", "field": "contract_value"}, {"object": "agent", "field": "hourly_cost"}]
@@ -703,7 +703,7 @@
703703
},
704704
{
705705
"id": "team_lead",
706-
"role": "Team lead, Technical group — a04",
706+
"role": "Team lead, Technical group — a04, who reassigns and closes their group's tickets",
707707
"record": {"object": "agent", "id": "a04"},
708708
"hidden": {"fields": [{"object": "agent", "field": "hourly_cost"}]},
709709
"scope": [

‎docs/qa/scenarios/travel_expense.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@
932932
"personas": [
933933
{
934934
"id": "employee",
935-
"role": "Employee (claimant), Sales, grade g2 — e02",
935+
"role": "Employee (claimant), Sales, grade g2 — e02, who may not approve approval steps on their own claims",
936936
"record": {"object": "employee", "id": "e02"},
937937
"hidden": {"fields": [{"object": "department", "field": "travel_budget"}]},
938938
"scope": [

‎packages/qa/scenarios/test/runner/units.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ describe('prompts, seed order, template manifest and change size', () => {
452452
it('the build prompt carries the seed, the persona sets and the handles — never a question or an outcome', () => {
453453
const p = buildPrompt(namespacedScenario(crm).card);
454454
expect(p).toContain('"full_name": "Ana Ruiz"');
455-
expect(p).toContain('`democrm_sdr` for `sdr` (Sales development representative): must not read the field `democrm_contact.email`');
455+
expect(p).toContain('`democrm_sdr` for `sdr` (Sales development representative who adds, updates and removes contacts): must not read the field `democrm_contact.email`');
456456
expect(dataContract(crm.card)).toContain('`u_sam` → the `sdr` user');
457457
for (const q of crm.card.run.questions) expect(p).not.toContain(q.ask.en!);
458458
expect(p).not.toContain('VALIDATION_FAILED');

‎packages/qa/scenarios/test/score/scenario-cards.test.ts‎

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
* `scoreScenarioArtifact`: shape, capability tags and agent actions. The
1717
* readings are pinned, and one card is completed with what it asks of the
1818
* build beyond shape, then degraded, to show the score separates the two.
19+
* 3. TRACE. Every write a card has a persona make, or refuses it
20+
* (`personaGrantNeeds`: an `applied` or `pending_confirmation` operation,
21+
* one refused `PERMISSION_DENIED`), is a grant the Build checks judge, and
22+
* the build is judged only on what its prompt says. So each write need of
23+
* every card in the library is stated in that card's rendered build prompt
24+
* (`buildPrompt`), for that persona: through the persona's `role` (the
25+
* carrier the library's owner ruled), or through the card's prose.
1926
*
2027
* The cards are loaded through this package's loader; the corpus is the CLI's
2128
* (`packages/cli/src/lint/corpus.ts`, the `os lint --eval` golden set), read
@@ -32,9 +39,10 @@ import { ObjectStackDefinitionSchema, normalizeStackInput } from '@objectstack/s
3239

3340
import { DEFAULT_METADATA_EVAL_CORPUS } from '../../../../cli/src/lint/corpus.js';
3441
import type { ScenarioExpect } from '../../src/schema.js';
35-
import { formatRefusal, loadScenarioFile, readCapabilityAreas } from '../../src/loader.js';
42+
import { formatRefusal, loadScenarioFile, loadScenarios, readCapabilityAreas } from '../../src/loader.js';
43+
import { buildPrompt } from '../../src/runner/prompts.js';
3644
import type { ScenarioCard } from '../../src/schema.js';
37-
import { gradeCapabilityTags, readArtifactFacts, scoreScenarioArtifact } from '../../src/score/scenario-tags.js';
45+
import { gradeCapabilityTags, personaGrantNeeds, readArtifactFacts, scoreScenarioArtifact } from '../../src/score/scenario-tags.js';
3846

3947
type Bag = Record<string, any>;
4048

@@ -256,3 +264,118 @@ describe('control cards — scored end to end against their golden builds', () =
256264
]);
257265
});
258266
});
267+
268+
describe('every card — each write need is stated in its build prompt, for its persona', () => {
269+
const loaded = loadScenarios(SCENARIOS_DIR, { areas: AREAS, library: 'open' });
270+
if (loaded.refusals.length) throw new Error(loaded.refusals.map(formatRefusal).join('\n'));
271+
const library: ScenarioCard[] = loaded.cards.map((c) => c.card);
272+
const writeNeeds = (card: ScenarioCard) =>
273+
personaGrantNeeds(card)
274+
.flatMap((n) => (n.verb === 'read' ? [] : [{ ...n, verb: n.verb, key: `${card.id}:${n.persona}:${n.object}:${n.verb}`, refusedOnly: n.requiredBy.length === 0 }]));
275+
276+
/**
277+
* The text rule for a need the persona's `role` carries: the role names the
278+
* object (its machine name with `_` read as a space, a plural allowed) and a
279+
* word for the verb; a write the card refuses also carries a negation
280+
* ("may not", "but not", "cannot", "never"). Its limits, stated: the rule
281+
* reads words, not grammar — it does not check that the verb word governs the
282+
* object, nor which of two objects a negation applies to; a reviewer reads
283+
* the role for that. The word lists are the verbs the library's roles use;
284+
* a new role verb is added here, in the open.
285+
*/
286+
const VERB_WORDS: Record<'create' | 'update' | 'delete', RegExp> = {
287+
create: /\b(adds?|creates?|logs?|files?|raises?|registers?|records?|enters?|submits?)\b/i,
288+
update: /\b(updates?|edits?|changes?|moves?|approves?|reassigns?|closes?|resolves?|cancels?|corrects?|pays?|sends?|extends?|disposes?)\b/i,
289+
delete: /\b(deletes?|removes?)\b/i,
290+
};
291+
const NEGATION = /\b(may not|but not|cannot|never)\b/i;
292+
const namesObject = (text: string, object: string) => new RegExp(`\\b${object.split('_').join('\\s+')}s?\\b`, 'i').test(text);
293+
const roleStates = (role: string, n: { object: string; verb: 'create' | 'update' | 'delete'; refusedOnly: boolean }) =>
294+
namesObject(role, n.object) && VERB_WORDS[n.verb].test(role) && (!n.refusedOnly || NEGATION.test(role));
295+
296+
/**
297+
* Each write need of the library and where its build prompt states it:
298+
* `ROLE` (the persona's role, judged by the text rule above), or the prose
299+
* passages, quoted verbatim, that name the persona, the object and the act.
300+
* A prose trace is a reviewer's reading, pinned so that it cannot silently
301+
* stop being true: a quote edited out of the card's prose, or a new need with
302+
* no entry, is a red.
303+
*/
304+
const ROLE = 'role' as const;
305+
const TRACES: Record<string, typeof ROLE | readonly string[]> = {
306+
'asset_lifecycle:asset_admin:asset:create': ROLE,
307+
'asset_lifecycle:asset_admin:checkout:update': ['The asset administrator checks assets out to employees', 'a checkout records the checkout date, a due date'],
308+
'asset_lifecycle:dept_manager:disposal_request:update': ["the manager of the asset's department decides a scrap request", 'deciding it updates the request'],
309+
'asset_lifecycle:asset_admin:disposal_request:update': ['once it is approved the asset administrator disposes of the asset'],
310+
'asset_lifecycle:employee:disposal_request:update': ROLE,
311+
'crm_account_with_contacts:sdr:contact:create': ROLE,
312+
'crm_account_with_contacts:sdr:contact:update': ROLE,
313+
'crm_account_with_contacts:sdr:contact:delete': ROLE,
314+
'crm_account_with_contacts:partner_user:account:update': ROLE,
315+
'invoice_with_line_items:sales_rep:invoice_line:create': ROLE,
316+
'invoice_with_line_items:sales_rep:invoice:update': ROLE,
317+
'invoice_with_line_items:sales_rep:invoice_line:delete': ROLE,
318+
'invoice_with_line_items:warehouse_staff:invoice:update': ROLE,
319+
'leave_balances:employee:leave_request:create': ['An employee files a leave request'],
320+
'leave_balances:employee:leave_day:update': ['An employee files a leave request with one line per date', "The day lines are details of the request (master-detail), edited inline on the request's form"],
321+
'leave_balances:dept_manager:approval_step:update': ['up to 3 days needs only the department manager', 'approving or rejecting a step updates that record'],
322+
'leave_balances:hr_officer:leave_request:delete': ROLE,
323+
'leave_balances:employee:leave_balance:update': ROLE,
324+
'order_to_cash:sales_rep:sales_order:create': ['A rep enters sales orders for their own accounts'],
325+
'order_to_cash:sales_rep:order_line:update': ['A rep enters sales orders', "The lines are details of the order (master-detail), edited inline on the order's form"],
326+
'order_to_cash:sales_rep:sales_order:update': ['a rep cannot approve their own order'],
327+
'order_to_cash:sales_manager:sales_order:update': ["goes to the rep's sales manager for approval", 'approving updates the order'],
328+
'order_to_cash:ar_clerk:invoice:update': ['Only Finance may write off a balance as bad debt', 'Accounts receivable clerk, Finance, organization-wide'],
329+
'project_with_tasks:contractor:task:create': ROLE,
330+
'project_with_tasks:contractor:task:update': ROLE,
331+
'project_with_tasks:contractor:task:delete': ROLE,
332+
'project_with_tasks:client_viewer:task:update': ROLE,
333+
'requisition_to_receipt:buyer:purchase_order:create': ['the buyer raises a purchase order to a supplier'],
334+
'requisition_to_receipt:buyer:po_line:update': ['the buyer raises a purchase order to a supplier with several lines', "The lines are details of the order (master-detail), edited inline on the order's form"],
335+
'requisition_to_receipt:dept_manager:approval_step:update': ['up to 5,000 the department manager alone', 'approving or rejecting a level updates that record'],
336+
'requisition_to_receipt:buyer:purchase_order:update': ['the buyer raises a purchase order', 'Cancelling an order already sent to the supplier cannot be undone and is confirmed first'],
337+
'service_desk:support_agent:ticket:create': ROLE,
338+
'service_desk:team_lead:ticket:update': ROLE,
339+
'service_desk:support_agent:ticket:update': ['once an agent takes it, it is open', 'resolving it sends the customer a satisfaction survey'],
340+
'service_desk:support_agent:satisfaction_rating:update': ["no agent can change a customer's rating"],
341+
'travel_expense:employee:expense_claim:create': ['Afterwards they file an expense claim with several lines'],
342+
'travel_expense:employee:claim_line:update': ["The lines are details of the claim (master-detail), edited inline on the claim's form"],
343+
'travel_expense:dept_manager:approval_step:update': ['the department manager first', 'approving or rejecting a step updates that record'],
344+
'travel_expense:finance_officer:expense_claim:update': ['once Finance approves, Finance pays it', 'Finance officer, organization-wide'],
345+
'travel_expense:employee:approval_step:update': ROLE,
346+
};
347+
348+
it('reads every card of the library, and every write need has a trace (a need with none is a red)', () => {
349+
expect(library.length).toBe(9);
350+
expect(library.flatMap(writeNeeds).map((n) => n.key).sort()).toEqual(Object.keys(TRACES).sort());
351+
});
352+
353+
for (const card of library) {
354+
it(`${card.id}: each write need is stated, by its persona's role or by the quoted prose`, () => {
355+
const prompt = buildPrompt(card).replace(/\s+/g, ' ');
356+
for (const n of writeNeeds(card)) {
357+
const trace = TRACES[n.key]!;
358+
if (trace === ROLE) {
359+
const role = card.run.personas.find((p) => p.id === n.persona)!.role;
360+
expect([n.key, roleStates(role, n)]).toEqual([n.key, true]);
361+
expect(prompt).toContain(`for \`${n.persona}\` (${role})`);
362+
} else {
363+
for (const quote of trace) expect([n.key, prompt.includes(quote)]).toEqual([n.key, true]);
364+
}
365+
}
366+
});
367+
}
368+
369+
it('the text rule goes red on the roles the library carried before the owner\'s ruling', () => {
370+
const need = (object: string, verb: 'create' | 'update' | 'delete', refusedOnly = false) => ({ object, verb, refusedOnly });
371+
expect(roleStates('External contractor', need('task', 'create'))).toBe(false);
372+
expect(roleStates('Sales representative', need('invoice_line', 'delete'))).toBe(false);
373+
expect(roleStates('Warehouse staff', need('invoice', 'update', true))).toBe(false);
374+
// The object and a verb, but a different verb's word: still red.
375+
expect(roleStates('External contractor who logs their own tasks', need('task', 'delete'))).toBe(false);
376+
// A refusal stated without a negation is a grant, not a refusal: red.
377+
expect(roleStates('Warehouse staff who change invoices', need('invoice', 'update', true))).toBe(false);
378+
expect(roleStates('Warehouse staff who may read invoices but not change them', need('invoice', 'update', true))).toBe(true);
379+
expect(roleStates('Sales representative who adds and removes invoice lines and sends invoices', need('invoice_line', 'create'))).toBe(true);
380+
});
381+
});

0 commit comments

Comments
 (0)