Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/33597-persona-roles-state-writes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): each card persona's role states the writes its build prompt did not

Clause-②: no
Metadata-protocol: none

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.
4 changes: 2 additions & 2 deletions docs/qa/scenarios/asset_lifecycle.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@
"personas": [
{
"id": "employee",
"role": "Employee (asset holder), Sales - e06",
"role": "Employee (asset holder), Sales - e06, who may not approve their own disposal requests",
"record": {"object": "employee", "id": "e06"},
"hidden": {
"objects": ["depreciation_entry"],
Expand Down Expand Up @@ -802,7 +802,7 @@
},
{
"id": "asset_admin",
"role": "IT asset administrator, organization-wide - e12",
"role": "IT asset administrator, organization-wide - e12, who registers assets",
"hidden": {"fields": [{"object": "department", "field": "asset_budget"}]}
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/qa/scenarios/crm_account_with_contacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@
"personas": [
{
"id": "sdr",
"role": "Sales development representative",
"role": "Sales development representative who adds, updates and removes contacts",
"hidden": {"fields": [{"object": "contact", "field": "email"}]},
"scope": [
{"object": "account", "field": "owner", "value": "u_sam"},
{"object": "contact", "field": "account.owner", "value": "u_sam"}
]
},
{"id": "partner_user", "role": "Partner portal user", "hidden": {"objects": ["account"]}}
{"id": "partner_user", "role": "Partner portal user who may not change accounts", "hidden": {"objects": ["account"]}}
],
"operations": [
{
Expand Down
4 changes: 2 additions & 2 deletions docs/qa/scenarios/invoice_with_line_items.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"personas": [
{
"id": "sales_rep",
"role": "Sales representative",
"role": "Sales representative who adds and removes invoice lines and sends invoices",
"hidden": {"fields": [{"object": "invoice_line", "field": "unit_price"}]},
"scope": [
{"object": "invoice", "field": "owner", "value": "u_ana"},
Expand All @@ -120,7 +120,7 @@
},
{
"id": "warehouse_staff",
"role": "Warehouse staff",
"role": "Warehouse staff who may read invoices but not change them",
"hidden": {
"objects": ["account"],
"fields": [{"object": "invoice_line", "field": "amount"}, {"object": "invoice_line", "field": "unit_price"}]
Expand Down
4 changes: 2 additions & 2 deletions docs/qa/scenarios/leave_balances.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@
"personas": [
{
"id": "employee",
"role": "Employee, Engineering, two years of service — e07",
"role": "Employee, Engineering, two years of service — e07, who may not change their own leave balance",
"record": {"object": "employee", "id": "e07"},
"hidden": {"fields": [{"object": "employee", "field": "personal_phone"}]},
"scope": [
Expand Down Expand Up @@ -846,7 +846,7 @@
},
{
"id": "hr_officer",
"role": "HR officer, organization-wide — e13",
"role": "HR officer, organization-wide — e13, who deletes withdrawn leave requests",
"hidden": {"fields": [{"object": "leave_request", "field": "medical_note"}]}
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/qa/scenarios/project_with_tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@
"personas": [
{
"id": "contractor",
"role": "External contractor",
"role": "External contractor who logs, updates and removes their own tasks",
"hidden": {"fields": [{"object": "task", "field": "estimate_hours"}, {"object": "project", "field": "total_estimate"}]},
"scope": [{"object": "task", "field": "assignee", "value": "u_kim"}]
},
{"id": "client_viewer", "role": "Client stakeholder", "hidden": {"objects": ["task"]}}
{"id": "client_viewer", "role": "Client stakeholder who may not change tasks", "hidden": {"objects": ["task"]}}
],
"operations": [
{
Expand Down
4 changes: 2 additions & 2 deletions docs/qa/scenarios/service_desk.json
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@
"personas": [
{
"id": "support_agent",
"role": "Support agent, Billing group — a02",
"role": "Support agent, Billing group — a02, who logs tickets from customer calls",
"record": {"object": "agent", "id": "a02"},
"hidden": {
"fields": [{"object": "customer", "field": "contract_value"}, {"object": "agent", "field": "hourly_cost"}]
Expand All @@ -703,7 +703,7 @@
},
{
"id": "team_lead",
"role": "Team lead, Technical group — a04",
"role": "Team lead, Technical group — a04, who reassigns and closes their group's tickets",
"record": {"object": "agent", "id": "a04"},
"hidden": {"fields": [{"object": "agent", "field": "hourly_cost"}]},
"scope": [
Expand Down
2 changes: 1 addition & 1 deletion docs/qa/scenarios/travel_expense.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@
"personas": [
{
"id": "employee",
"role": "Employee (claimant), Sales, grade g2 — e02",
"role": "Employee (claimant), Sales, grade g2 — e02, who may not approve approval steps on their own claims",
"record": {"object": "employee", "id": "e02"},
"hidden": {"fields": [{"object": "department", "field": "travel_budget"}]},
"scope": [
Expand Down
2 changes: 1 addition & 1 deletion packages/qa/scenarios/test/runner/units.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ describe('prompts, seed order, template manifest and change size', () => {
it('the build prompt carries the seed, the persona sets and the handles — never a question or an outcome', () => {
const p = buildPrompt(namespacedScenario(crm).card);
expect(p).toContain('"full_name": "Ana Ruiz"');
expect(p).toContain('`democrm_sdr` for `sdr` (Sales development representative): must not read the field `democrm_contact.email`');
expect(p).toContain('`democrm_sdr` for `sdr` (Sales development representative who adds, updates and removes contacts): must not read the field `democrm_contact.email`');
expect(dataContract(crm.card)).toContain('`u_sam` → the `sdr` user');
for (const q of crm.card.run.questions) expect(p).not.toContain(q.ask.en!);
expect(p).not.toContain('VALIDATION_FAILED');
Expand Down
127 changes: 125 additions & 2 deletions packages/qa/scenarios/test/score/scenario-cards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
* `scoreScenarioArtifact`: shape, capability tags and agent actions. The
* readings are pinned, and one card is completed with what it asks of the
* build beyond shape, then degraded, to show the score separates the two.
* 3. TRACE. Every write a card has a persona make, or refuses it
* (`personaGrantNeeds`: an `applied` or `pending_confirmation` operation,
* one refused `PERMISSION_DENIED`), is a grant the Build checks judge, and
* the build is judged only on what its prompt says. So each write need of
* every card in the library is stated in that card's rendered build prompt
* (`buildPrompt`), for that persona: through the persona's `role` (the
* carrier the library's owner ruled), or through the card's prose.
*
* The cards are loaded through this package's loader; the corpus is the CLI's
* (`packages/cli/src/lint/corpus.ts`, the `os lint --eval` golden set), read
Expand All @@ -32,9 +39,10 @@ import { ObjectStackDefinitionSchema, normalizeStackInput } from '@objectstack/s

import { DEFAULT_METADATA_EVAL_CORPUS } from '../../../../cli/src/lint/corpus.js';
import type { ScenarioExpect } from '../../src/schema.js';
import { formatRefusal, loadScenarioFile, readCapabilityAreas } from '../../src/loader.js';
import { formatRefusal, loadScenarioFile, loadScenarios, readCapabilityAreas } from '../../src/loader.js';
import { buildPrompt } from '../../src/runner/prompts.js';
import type { ScenarioCard } from '../../src/schema.js';
import { gradeCapabilityTags, readArtifactFacts, scoreScenarioArtifact } from '../../src/score/scenario-tags.js';
import { gradeCapabilityTags, personaGrantNeeds, readArtifactFacts, scoreScenarioArtifact } from '../../src/score/scenario-tags.js';

type Bag = Record<string, any>;

Expand Down Expand Up @@ -256,3 +264,118 @@ describe('control cards — scored end to end against their golden builds', () =
]);
});
});

describe('every card — each write need is stated in its build prompt, for its persona', () => {
const loaded = loadScenarios(SCENARIOS_DIR, { areas: AREAS, library: 'open' });
if (loaded.refusals.length) throw new Error(loaded.refusals.map(formatRefusal).join('\n'));
const library: ScenarioCard[] = loaded.cards.map((c) => c.card);
const writeNeeds = (card: ScenarioCard) =>
personaGrantNeeds(card)
.flatMap((n) => (n.verb === 'read' ? [] : [{ ...n, verb: n.verb, key: `${card.id}:${n.persona}:${n.object}:${n.verb}`, refusedOnly: n.requiredBy.length === 0 }]));

/**
* The text rule for a need the persona's `role` carries: the role names the
* object (its machine name with `_` read as a space, a plural allowed) and a
* word for the verb; a write the card refuses also carries a negation
* ("may not", "but not", "cannot", "never"). Its limits, stated: the rule
* reads words, not grammar — it does not check that the verb word governs the
* object, nor which of two objects a negation applies to; a reviewer reads
* the role for that. The word lists are the verbs the library's roles use;
* a new role verb is added here, in the open.
*/
const VERB_WORDS: Record<'create' | 'update' | 'delete', RegExp> = {
create: /\b(adds?|creates?|logs?|files?|raises?|registers?|records?|enters?|submits?)\b/i,
update: /\b(updates?|edits?|changes?|moves?|approves?|reassigns?|closes?|resolves?|cancels?|corrects?|pays?|sends?|extends?|disposes?)\b/i,
delete: /\b(deletes?|removes?)\b/i,
};
const NEGATION = /\b(may not|but not|cannot|never)\b/i;
const namesObject = (text: string, object: string) => new RegExp(`\\b${object.split('_').join('\\s+')}s?\\b`, 'i').test(text);
const roleStates = (role: string, n: { object: string; verb: 'create' | 'update' | 'delete'; refusedOnly: boolean }) =>
namesObject(role, n.object) && VERB_WORDS[n.verb].test(role) && (!n.refusedOnly || NEGATION.test(role));

/**
* Each write need of the library and where its build prompt states it:
* `ROLE` (the persona's role, judged by the text rule above), or the prose
* passages, quoted verbatim, that name the persona, the object and the act.
* A prose trace is a reviewer's reading, pinned so that it cannot silently
* stop being true: a quote edited out of the card's prose, or a new need with
* no entry, is a red.
*/
const ROLE = 'role' as const;
const TRACES: Record<string, typeof ROLE | readonly string[]> = {
'asset_lifecycle:asset_admin:asset:create': ROLE,
'asset_lifecycle:asset_admin:checkout:update': ['The asset administrator checks assets out to employees', 'a checkout records the checkout date, a due date'],
'asset_lifecycle:dept_manager:disposal_request:update': ["the manager of the asset's department decides a scrap request", 'deciding it updates the request'],
'asset_lifecycle:asset_admin:disposal_request:update': ['once it is approved the asset administrator disposes of the asset'],
'asset_lifecycle:employee:disposal_request:update': ROLE,
'crm_account_with_contacts:sdr:contact:create': ROLE,
'crm_account_with_contacts:sdr:contact:update': ROLE,
'crm_account_with_contacts:sdr:contact:delete': ROLE,
'crm_account_with_contacts:partner_user:account:update': ROLE,
'invoice_with_line_items:sales_rep:invoice_line:create': ROLE,
'invoice_with_line_items:sales_rep:invoice:update': ROLE,
'invoice_with_line_items:sales_rep:invoice_line:delete': ROLE,
'invoice_with_line_items:warehouse_staff:invoice:update': ROLE,
'leave_balances:employee:leave_request:create': ['An employee files a leave request'],
'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"],
'leave_balances:dept_manager:approval_step:update': ['up to 3 days needs only the department manager', 'approving or rejecting a step updates that record'],
'leave_balances:hr_officer:leave_request:delete': ROLE,
'leave_balances:employee:leave_balance:update': ROLE,
'order_to_cash:sales_rep:sales_order:create': ['A rep enters sales orders for their own accounts'],
'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"],
'order_to_cash:sales_rep:sales_order:update': ['a rep cannot approve their own order'],
'order_to_cash:sales_manager:sales_order:update': ["goes to the rep's sales manager for approval", 'approving updates the order'],
'order_to_cash:ar_clerk:invoice:update': ['Only Finance may write off a balance as bad debt', 'Accounts receivable clerk, Finance, organization-wide'],
'project_with_tasks:contractor:task:create': ROLE,
'project_with_tasks:contractor:task:update': ROLE,
'project_with_tasks:contractor:task:delete': ROLE,
'project_with_tasks:client_viewer:task:update': ROLE,
'requisition_to_receipt:buyer:purchase_order:create': ['the buyer raises a purchase order to a supplier'],
'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"],
'requisition_to_receipt:dept_manager:approval_step:update': ['up to 5,000 the department manager alone', 'approving or rejecting a level updates that record'],
'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'],
'service_desk:support_agent:ticket:create': ROLE,
'service_desk:team_lead:ticket:update': ROLE,
'service_desk:support_agent:ticket:update': ['once an agent takes it, it is open', 'resolving it sends the customer a satisfaction survey'],
'service_desk:support_agent:satisfaction_rating:update': ["no agent can change a customer's rating"],
'travel_expense:employee:expense_claim:create': ['Afterwards they file an expense claim with several lines'],
'travel_expense:employee:claim_line:update': ["The lines are details of the claim (master-detail), edited inline on the claim's form"],
'travel_expense:dept_manager:approval_step:update': ['the department manager first', 'approving or rejecting a step updates that record'],
'travel_expense:finance_officer:expense_claim:update': ['once Finance approves, Finance pays it', 'Finance officer, organization-wide'],
'travel_expense:employee:approval_step:update': ROLE,
};

it('reads every card of the library, and every write need has a trace (a need with none is a red)', () => {
expect(library.length).toBe(9);
expect(library.flatMap(writeNeeds).map((n) => n.key).sort()).toEqual(Object.keys(TRACES).sort());
});

for (const card of library) {
it(`${card.id}: each write need is stated, by its persona's role or by the quoted prose`, () => {
const prompt = buildPrompt(card).replace(/\s+/g, ' ');
for (const n of writeNeeds(card)) {
const trace = TRACES[n.key]!;
if (trace === ROLE) {
const role = card.run.personas.find((p) => p.id === n.persona)!.role;
expect([n.key, roleStates(role, n)]).toEqual([n.key, true]);
expect(prompt).toContain(`for \`${n.persona}\` (${role})`);
} else {
for (const quote of trace) expect([n.key, prompt.includes(quote)]).toEqual([n.key, true]);
}
}
});
}

it('the text rule goes red on the roles the library carried before the owner\'s ruling', () => {
const need = (object: string, verb: 'create' | 'update' | 'delete', refusedOnly = false) => ({ object, verb, refusedOnly });
expect(roleStates('External contractor', need('task', 'create'))).toBe(false);
expect(roleStates('Sales representative', need('invoice_line', 'delete'))).toBe(false);
expect(roleStates('Warehouse staff', need('invoice', 'update', true))).toBe(false);
// The object and a verb, but a different verb's word: still red.
expect(roleStates('External contractor who logs their own tasks', need('task', 'delete'))).toBe(false);
// A refusal stated without a negation is a grant, not a refusal: red.
expect(roleStates('Warehouse staff who change invoices', need('invoice', 'update', true))).toBe(false);
expect(roleStates('Warehouse staff who may read invoices but not change them', need('invoice', 'update', true))).toBe(true);
expect(roleStates('Sales representative who adds and removes invoice lines and sends invoices', need('invoice_line', 'create'))).toBe(true);
});
});
Loading