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/36206-namespace-operation-via.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): a namespaced card prefixes each operation's `via` the way it prefixes the agent action it names

Clause-②: no
Metadata-protocol: none

`namespacedScenario` prefixed `run.agentActions[].name` with the card's namespace but copied `run.operations[].via` bare, so the persona-grant check never found the routed action a build declares (`decide_approval_step` against `demoleave_decide_approval_step`) and failed builds that route the decision through the card's own action. The namespaced card now carries `via` prefixed, and the loader's rule (a `via` is one of the card's agent actions on the operation's object) holds on it as on the plain card.
3 changes: 3 additions & 0 deletions packages/qa/scenarios/src/runner/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export function namespacedScenario(scenario: LoadedScenario): LoadedScenario {
operations: c.run.operations.map((op) => ({
...op,
object: o(op.object),
// `via` names one of the card's agent actions, which carry the prefix below: a bare `via`
// would never match the action the build declares.
...(op.via !== undefined ? { via: o(op.via) } : {}),
outcome: op.outcome.kind === 'applied' ? { ...op.outcome, state: op.outcome.state.map((s) => ({ ...s, object: o(s.object) })) } : op.outcome,
})),
guardrails: c.run.guardrails.map((g) => ({
Expand Down
19 changes: 19 additions & 0 deletions packages/qa/scenarios/test/runner/units.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,25 @@ describe('namespace-relative cards', () => {
expect(n.expect.appNavTargets).toEqual(['democrm_account', 'democrm_overview']);
});

it("prefixes an operation's `via` with its agent action, so the route the scorer looks for is the action the build declares", () => {
// The loader's rule — a `via` is one of `run.agentActions` on the operation's object — must
// hold on the namespaced card too: the grader matches `via` against the build's actions by
// name, and a bare `via` beside a prefixed action never matches.
let routed = 0;
for (const f of ['leave_balances', 'requisition_to_receipt', 'travel_expense']) {
const card = namespacedScenario(load(resolve(HERE, `../../../../../docs/qa/scenarios/${f}.json`))).card;
for (const op of card.run.operations.filter((o) => o.via !== undefined)) {
routed += 1;
expect(card.run.agentActions!.some((a) => a.name === op.via && a.object === op.object), `${f} ${op.id} via ${op.via}`).toBe(true);
}
}
expect(routed).toBe(3);
const leave = namespacedScenario(load(resolve(HERE, '../../../../../docs/qa/scenarios/leave_balances.json'))).card;
expect(leave.run.operations.find((o) => o.via !== undefined)!.via).toBe('demoleave_decide_approval_step');
expect(crm.card.run.operations.every((o) => o.via === undefined)).toBe(true);
expect(namespacedScenario(crm).card.run.operations.every((o) => !('via' in o))).toBe(true); // no `via` invented
});

it("template mode's host is named after the code, never the app's namespace", () => {
expect(templateHostName(crm.card)).toBe('hostcrm');
});
Expand Down
Loading