Skip to content

Commit cceb5c6

Browse files
fix(audit): an aggregate bulk call's invocation row records its per-row counts (#35736)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao6bxiPKCvVuzoFTExumbxoz)_ Fixes #34292 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 管理员在审计日志里查看批量操作记录时,一次部分失败的批量动作除了仍标「成功」外,还会写明选中几行、成功几行、失败几行、未确认几行;以前只有「成功」两个字。 - 属于批量操作结果如实呈现这一组工作,替审计合规读者解决「部分失败被记成全部成功」的问题,并与控制台批量对话框的计数规则保持一致。 - 只影响带选中行列表的批量动作的审计行;若计数有误,只是审计日志里多出的数字不准,动作本身的执行和返回不受影响,可直接撤回本次改动。 - 无。 ## What changes Ruling (verbatim, maintainer 2026-11-19T05:04Z): 「B 仍记成功,加行数」 — seat ruling record 7000299515: the invocation audit outcome stays `succeeded`; when the request carries `_selectedIds` and the resolve value reads under `BulkActionResultSchema`, the row also records selected / succeeded / failed / unconfirmed counts; when it cannot be read, one "unreadable" key and no succeeded count. - **One reader, in the runtime.** `actionInvocationBulkReading(params, result)` (`packages/runtime/src/action-invocation-audit.ts`) reads an answered call's resolve value against its `params._selectedIds`, with the console's aggregate reader's rules (`readAggregateResult`, `ui/packages/plugin-grid/src/hooks/useBulkExecutor.ts`): no `_selectedIds` array, or a value with neither a `succeeded` nor a `failed` own member, records nothing; a value carrying one that fails `BulkActionResultSchema` reads `{ unreadable: true }`; a parsed value is counted with ids outside the selection dropped, duplicates once, an id in both lists failed, a selected id in neither list unconfirmed. No shared reader existed in `packages/spec` or the runtime (the console's lives under `ui/`, which the runtime cannot import), so this is the server's one copy, built on the same spec schema. - **The writer sites.** The invocation row is written from three places: the REST `POST /actions` door and a host's `dispatchAction` (`runResolvedActionAsRest`, `action-dispatch.ts`), the MCP `run_action` tool (`invokeBusinessAction`, `action-execution.ts`), and the MCP `resume_run` tool (`domains/mcp.ts`). The first two now hand the event a `bulk` member on an answered call; `AdmittedActionCall` carries the admitted `params` so both read the same bag. `resume_run` is unchanged: its request carries the screen's values, never `_selectedIds`, so the ruling's condition never holds there. The row itself is built by `buildActionInvocationAuditRow` (`plugin-audit`), which now writes the reading into the existing `metadata` JSON — `bulk_selected`, `bulk_succeeded`, `bulk_failed`, `bulk_unconfirmed`, or `bulk_unreadable: true` alone — on a `succeeded` row only. No new column; `sys_audit_log`'s declared fields are unchanged. - `ActionInvocationAuditEvent` gains an optional `bulk` member in both packages; `@objectstack/plugin-audit` exports `ActionInvocationBulkReading`. That is the public-surface widening `Clause-②: yes` declares. Nothing a metadata author writes changes (`Metadata-protocol: none`). ## Tests Pins sit in the two existing harness files as top-level `describe` blocks named for this card: - `packages/runtime/src/action-invocation-audit.test.ts`: on both the REST and MCP doors, a partial resolve (`3/1/1/1`), an all-succeeded resolve, an unreadable resolve, the resolve-nothing control (still `succeeded`, no counts), and a call with no `_selectedIds`; a throwing handler records `failed` and no counts; the four counting rules and the neither-member / neighbour-shape cases on the reader. - `packages/plugins/plugin-audit/src/action-invocation-audit.test.ts`: the row read back through a real engine for the counts and the unreadable mark; no bulk key without a reading, and none on a failed row. <details><summary>Readings at 78e4446 (tests, typecheck, ablation)</summary> - `pnpm --filter @objectstack/runtime test`: Test Files 631 passed (631), Tests 11662 passed, 25 skipped. `pnpm --filter @objectstack/plugin-audit test`: Test Files 103 passed (103), Tests 1727 passed. - `pnpm --filter @objectstack/plugin-audit typecheck` and `pnpm --filter @objectstack/runtime typecheck`: exit 0, both test layers OK. - Ablation, runtime (via `scripts/ablation-replace.mjs`, anchor 1 to 0, restored blob == HEAD): the reader made to record nothing for every call turns 8 of the 45 harness tests red: partial, all-succeeded and unreadable on both doors, the four counting rules and the neighbour-shape case. The resolve-nothing control, the no-`_selectedIds` case and the throwing handler stay green. - Ablation, plugin-audit (same tool, restored blob == HEAD): dropping the row's bulk keys turns 2 of 17 red: the partial counts and the unreadable mark. </details> ## Acceptance notes - `BulkActionResultSchema`'s docblock no longer carries `[PLANNED — not enforced]` on `origin/main` (the console reader's landing removed it), so this PR does not touch `packages/spec`. - An `api` action that forwards to another action route writes two rows; each records the counts its own door read off its own answer. ## Verification Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/action-invocation-audit.test.ts` — expect the `[#34292]` block green, 45 tests passing. Read first: `packages/runtime/src/action-invocation-audit.ts` (`actionInvocationBulkReading`, the counting rules), `packages/runtime/src/action-dispatch.ts` (`runResolvedActionAsRest`: counts only on an `answered` outcome), `packages/plugins/plugin-audit/src/action-invocation-audit.ts` (`bulkMetadata`, written on `succeeded` rows only). --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4890cd0 commit cceb5c6

8 files changed

Lines changed: 286 additions & 3 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/runtime': patch
3+
'@objectstack/plugin-audit': patch
4+
---
5+
6+
fix(audit): the action invocation row of an aggregate bulk call records how many selected rows succeeded, failed or were not confirmed
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
An `execution: 'aggregate'` bulk action is one call for the whole selection, with the ids in `params._selectedIds`. When its handler moved some rows and failed others, it resolves with a `BulkActionResult` (`{ succeeded: [ids], failed: [{ id, message }] }`, `@objectstack/spec/ui`) and does not throw. The `action_invocation` row in `sys_audit_log` recorded only `outcome: 'succeeded'` for that call, so the audit trail said a partly failed run fully succeeded.
12+
13+
The outcome stays `succeeded`. When the call carried `_selectedIds` and its resolve value carries a `succeeded` or `failed` member, the row's `metadata` now also records what that value reads as under `BulkActionResultSchema`, counted by the rules the console's bulk dialog counts with: an id outside the selection is dropped, a duplicate counts once, an id in both lists counts as failed, and a selected id in neither list is not confirmed.
14+
15+
- `bulk_selected`, `bulk_succeeded`, `bulk_failed` and `bulk_unconfirmed`, where `bulk_selected = bulk_succeeded + bulk_failed + bulk_unconfirmed`;
16+
- or, when the value carries a member but does not parse, `bulk_unreadable: true` alone and no succeeded count.
17+
18+
A handler that resolves with nothing, or with a value that has neither member (a summary, a download link), records the row as before. A call with no `_selectedIds`, a failed call and a `resume_run` add no bulk key. Both the REST `POST /actions/:object/:action` door (and a host's `dispatchAction`) and the MCP `run_action` tool record the counts.
19+
20+
`ActionInvocationAuditEvent` gains an optional `bulk` member in both packages, and `@objectstack/plugin-audit` exports its type, `ActionInvocationBulkReading`. A reader of the ledger that lists `metadata` keys sees the new keys on these rows only.

‎packages/plugins/plugin-audit/src/action-invocation-audit.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,51 @@ describe('[#33694] an in-product AI call is marked on the action_invocation row
348348
for (const key of PERFORMER_KEYS) expect(meta).not.toHaveProperty(key);
349349
});
350350
});
351+
352+
/**
353+
* [#34292 — seat ruling 7000299515, maintainer 「B 仍记成功,加行数」] An
354+
* answered aggregate bulk call keeps `outcome: 'succeeded'` and its row adds
355+
* the per-row counts the door read off the handler's resolve value; a value
356+
* that could not be read adds one mark and no succeeded count. Read back
357+
* through a real engine.
358+
*/
359+
describe('[#34292] an aggregate bulk call\'s row records its per-row counts', () => {
360+
const BULK: ActionInvocationAuditEvent = {
361+
context: { userId: 'usr_1', tenantId: 'org_1', surface: 'rest' },
362+
actionName: 'merge_leads', objectName: 'crm_lead', branch: 'script', outcome: 'succeeded',
363+
};
364+
365+
it('a partial run stays succeeded and records selected / succeeded / failed / unconfirmed', async () => {
366+
const engine = await boot();
367+
const writer = createActionInvocationAuditWriter({ getEngine: () => engine as any });
368+
369+
await writer.recordActionInvocation({ ...BULK, bulk: { selected: 3, succeeded: 1, failed: 1, unconfirmed: 1 } });
370+
371+
const [row] = await ledgerRows(engine);
372+
expect(JSON.parse(row.metadata)).toEqual({
373+
surface: 'rest', action_name: 'merge_leads', branch: 'script', outcome: 'succeeded',
374+
bulk_selected: 3, bulk_succeeded: 1, bulk_failed: 1, bulk_unconfirmed: 1,
375+
});
376+
});
377+
378+
it('an unreadable resolve value records one mark and no succeeded count', async () => {
379+
const engine = await boot();
380+
const writer = createActionInvocationAuditWriter({ getEngine: () => engine as any });
381+
382+
await writer.recordActionInvocation({ ...BULK, bulk: { unreadable: true } });
383+
384+
const [row] = await ledgerRows(engine);
385+
expect(JSON.parse(row.metadata)).toEqual({
386+
surface: 'rest', action_name: 'merge_leads', branch: 'script', outcome: 'succeeded', bulk_unreadable: true,
387+
});
388+
});
389+
390+
it('control: a call with no reading records no bulk key; a failed row records none either', () => {
391+
const keys = (event: ActionInvocationAuditEvent) =>
392+
Object.keys(JSON.parse(String(buildActionInvocationAuditRow(event).metadata))).filter((k) => k.startsWith('bulk_'));
393+
expect(keys(BULK)).toEqual([]);
394+
expect(keys({
395+
...BULK, outcome: 'failed', status: 409, bulk: { selected: 3, succeeded: 1, failed: 1, unconfirmed: 1 },
396+
})).toEqual([]);
397+
});
398+
});

‎packages/plugins/plugin-audit/src/action-invocation-audit.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
* arrived carrying (`<object>/<action>` of the outer action). The mark is
6060
* a HINT, not a surface: a caller can forge it, so it mislabels this key
6161
* and nothing else, and the inner row's `surface` stays its own door's.
62+
* - [#34292] an answered aggregate bulk call (it carried `_selectedIds`)
63+
* keeps `outcome: 'succeeded'` and adds what its resolve value read as
64+
* under `BulkActionResultSchema` (`event.bulk`, read by the door):
65+
* `bulk_selected`, `bulk_succeeded`, `bulk_failed` and `bulk_unconfirmed`
66+
* (`selected = succeeded + failed + unconfirmed`), or, for a value that
67+
* could not be read, `bulk_unreadable: true` alone and no succeeded count.
6268
*/
6369

6470
import type { IDataEngine } from '@objectstack/spec/contracts';
@@ -117,6 +123,29 @@ export interface ActionInvocationAuditEvent {
117123
target?: string;
118124
/** The forward mark the call arrived carrying (the inner row of a forward) — a hint only. */
119125
forwardedFrom?: string;
126+
/**
127+
* [#34292] An answered aggregate bulk call's per-row counts, or the mark of
128+
* a resolve value that could not be read. Recorded on a `succeeded` row only.
129+
*/
130+
bulk?: ActionInvocationBulkReading;
131+
}
132+
133+
/** What an aggregate bulk call's resolve value read as — the door reads it, this writer records it. */
134+
export type ActionInvocationBulkReading =
135+
| { selected: number; succeeded: number; failed: number; unconfirmed: number }
136+
| { unreadable: true };
137+
138+
function isCount(v: unknown): v is number {
139+
return typeof v === 'number' && Number.isInteger(v) && v >= 0;
140+
}
141+
142+
/** The row's bulk keys for one reading — none for a reading this writer cannot record whole. */
143+
function bulkMetadata(bulk: ActionInvocationBulkReading | undefined): Record<string, unknown> {
144+
if (!bulk || typeof bulk !== 'object') return {};
145+
if ('unreadable' in bulk) return bulk.unreadable === true ? { bulk_unreadable: true } : {};
146+
const { selected, succeeded, failed, unconfirmed } = bulk;
147+
if (![selected, succeeded, failed, unconfirmed].every(isCount)) return {};
148+
return { bulk_selected: selected, bulk_succeeded: succeeded, bulk_failed: failed, bulk_unconfirmed: unconfirmed };
120149
}
121150

122151
/** What {@link createActionInvocationAuditWriter} adds to the `audit` slot. */
@@ -171,6 +200,8 @@ export function buildActionInvocationAuditRow(
171200
if (typeof event.status === 'number') metadata.status = event.status;
172201
const errorCode = nonEmpty(event.errorCode);
173202
if (errorCode) metadata.error_code = errorCode;
203+
} else {
204+
Object.assign(metadata, bulkMetadata(event.bulk));
174205
}
175206
const runId = nonEmpty(event.runId);
176207
if (runId) metadata.run_id = runId;

‎packages/plugins/plugin-audit/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type {
2323
ActionInvocationAuditWriter,
2424
ActionInvocationAuditWriterOptions,
2525
ActionInvocationBranch,
26+
ActionInvocationBulkReading,
2627
ActionInvocationOutcome,
2728
} from './action-invocation-audit.js';
2829
// [#30955] The run-level `export` row writer the REST export door reaches

‎packages/runtime/src/action-dispatch.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import * as actionExec from './action-execution.js';
6565
import type { ActionExecutionDeps } from './action-execution.js';
6666
import {
6767
actionInvocationBranch,
68+
actionInvocationBulkReading,
6869
actionInvocationForwardedFrom,
6970
actionInvocationTarget,
7071
recordActionInvocation,
@@ -248,6 +249,12 @@ export interface AdmittedActionCall {
248249
objectName: string;
249250
actionName: string;
250251
recordId: unknown;
252+
/**
253+
* [#34292] The params bag the call was admitted with, read for its
254+
* `_selectedIds` by the invocation row's bulk counts
255+
* (`actionInvocationBulkReading`).
256+
*/
257+
params: Record<string, unknown>;
251258
}
252259

253260
/** What {@link runResolvedAction} answers. */
@@ -305,7 +312,10 @@ export async function runResolvedAction(
305312
}
306313
const outcome = await dispatchAdmittedAction(deps, requestContext, call, admission);
307314
return {
308-
admitted: { actionDef: admission.actionDef, objectName: call.objectName, actionName: call.actionName, recordId: admission.recordId },
315+
admitted: {
316+
actionDef: admission.actionDef, objectName: call.objectName, actionName: call.actionName,
317+
recordId: admission.recordId, params: admission.params,
318+
},
309319
outcome,
310320
};
311321
}
@@ -961,6 +971,11 @@ export async function runResolvedActionAsRest(
961971
// An api forward's two rows name each other (`action-invocation-audit.ts`).
962972
target: actionInvocationTarget(actionDef, actionExec.isDeclarativeUpdateAction(actionDef)),
963973
forwardedFrom: actionInvocationForwardedFrom(requestContext, actionExec.API_FORWARD_MARK_HEADER),
974+
// [#34292] An answered call that carried `_selectedIds`: the per-row
975+
// counts its resolve value reads as. The outcome stays `succeeded`.
976+
bulk: ok && run.outcome.kind === 'answered'
977+
? actionInvocationBulkReading(run.admitted.params, run.outcome.result)
978+
: undefined,
964979
});
965980
return { handled: true, response };
966981
}

‎packages/runtime/src/action-execution.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import { recordNotFoundError, omitInternalFieldsFromWriteResponse } from '@objec
9696
// [#31697] The environment store's rows are the resync's: a legacy organization's rows left out off the physical column.
9797
import { isTenantAuthored, readLegacyOrganizationRows } from '@objectstack/metadata-core';
9898
import { PLATFORM_SYSTEM_API, deriveThroughSeam, serveStoredMetadataRead, serveStoredMetadataReadsThrough } from './stored-metadata-reader-seam.js';
99-
import { actionInvocationBranch, actionInvocationFailure, actionInvocationTarget, recordActionInvocation, withActionSurface } from './action-invocation-audit.js';
99+
import { actionInvocationBranch, actionInvocationBulkReading, actionInvocationFailure, actionInvocationTarget, recordActionInvocation, withActionSurface } from './action-invocation-audit.js';
100100
import type { HttpProtocolContext } from './http-dispatcher.js';
101101
// The ONE admitted sequence every action door shares; `invokeBusinessAction`
102102
// below is its MCP door (posture `ai`).
@@ -5167,7 +5167,11 @@ export async function invokeBusinessAction(deps: ActionExecutionDeps,
51675167
});
51685168
const { outcome } = run;
51695169
if (outcome.kind === 'answered') {
5170-
await recordActionInvocation(deps, requestContext, envId, { ...invocation, outcome: 'succeeded' });
5170+
// [#34292] A call that carried `_selectedIds` adds the per-row counts
5171+
// its resolve value reads as; the outcome stays `succeeded`.
5172+
await recordActionInvocation(deps, requestContext, envId, {
5173+
...invocation, outcome: 'succeeded', bulk: actionInvocationBulkReading(run.admitted.params, outcome.result),
5174+
});
51715175
if (action?.type === 'api' && !declarative) {
51725176
// A credential rotation the target emitted (impersonation): the
51735177
// bearer pair ONLY — see {@link mcpRelayableForwardHeaders} for why

‎packages/runtime/src/action-invocation-audit.test.ts‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import { describe, it, expect, vi } from 'vitest';
2222
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';
23+
// Paid at collection, not inside a case's clocked window: the dispatcher's
24+
// reach loads `@objectstack/metadata` lazily (`check:test-source-alias`).
25+
import '@objectstack/metadata';
2326

2427
import { HttpDispatcher } from './http-dispatcher.js';
2528
import { API_FORWARD_MARK_HEADER } from './action-execution.js';
@@ -30,6 +33,7 @@ import {
3033
actionInvocationForwardedFrom,
3134
actionInvocationTarget,
3235
ACTION_FORWARD_MARK_MAX_LENGTH,
36+
actionInvocationBulkReading,
3337
} from './action-invocation-audit.js';
3438

3539
const OBJECT = 'aud_lead';
@@ -450,3 +454,100 @@ describe('[#27908] the helpers', () => {
450454
expect(actionInvocationFailure(new Error('x')).status).toBe(500);
451455
});
452456
});
457+
458+
/**
459+
* [#34292 — seat ruling 7000299515, maintainer 「B 仍记成功,加行数」] An
460+
* aggregate bulk call (it carries `params._selectedIds`) whose handler
461+
* RESOLVES with a `BulkActionResult` keeps `outcome: 'succeeded'` and hands
462+
* the writer the per-row counts that value reads as — counted by the rules the
463+
* console's aggregate reader counts with, so the dialog and the row agree.
464+
*/
465+
describe('[#34292] an aggregate bulk call\'s row records the per-row counts its resolve value reads as', () => {
466+
const SELECTED = ['l1', 'l2', 'l3'];
467+
const PARTIAL = { succeeded: ['l1'], failed: [{ id: 'l2', message: 'Locked.' }] };
468+
469+
/** The script handler resolves with `value`; the call carries `params` and no record. */
470+
async function run(door: 'rest' | 'mcp', value: unknown, params: Record<string, unknown>) {
471+
const rig = makeRig();
472+
rig.ql.executeAction.mockImplementation(async () => value);
473+
if (door === 'rest') {
474+
const res: any = await rig.dispatcher.handleActions(
475+
`/${OBJECT}/${SCRIPT.name}`, 'POST', { params }, rig.ctx({ userId: 'u_member' }),
476+
);
477+
expect(res.response.status).toBe(200);
478+
} else {
479+
const bridge = (rig.dispatcher as any).buildMcpBridge(rig.ctx({ userId: 'u_member' }));
480+
await bridge.runAction(SCRIPT.name, { objectName: OBJECT, params });
481+
}
482+
expect(rig.events).toHaveLength(1);
483+
return rig.events[0];
484+
}
485+
486+
describe.each(['rest', 'mcp'] as const)('%s door', (door) => {
487+
it('a partial resolve stays succeeded and records selected / succeeded / failed / unconfirmed', async () => {
488+
const event = await run(door, PARTIAL, { _selectedIds: SELECTED });
489+
expect(event.outcome).toBe('succeeded');
490+
expect(event.bulk).toEqual({ selected: 3, succeeded: 1, failed: 1, unconfirmed: 1 });
491+
});
492+
493+
it('an all-succeeded resolve records every selected row as succeeded', async () => {
494+
const event = await run(door, { succeeded: SELECTED, failed: [] }, { _selectedIds: SELECTED });
495+
expect(event.outcome).toBe('succeeded');
496+
expect(event.bulk).toEqual({ selected: 3, succeeded: 3, failed: 0, unconfirmed: 0 });
497+
});
498+
499+
it('a resolve value that carries a list and does not parse records one unreadable mark and no count', async () => {
500+
const event = await run(door, { succeeded: 'l1' }, { _selectedIds: SELECTED });
501+
expect(event.outcome).toBe('succeeded');
502+
expect(event.bulk).toEqual({ unreadable: true });
503+
});
504+
505+
it('control: a handler that resolves with nothing still records succeeded, with no counts', async () => {
506+
const event = await run(door, undefined, { _selectedIds: SELECTED });
507+
expect(event.outcome).toBe('succeeded');
508+
expect(event.bulk).toBeUndefined();
509+
});
510+
511+
it('a call with no `_selectedIds` records no counts, whatever its handler resolves with', async () => {
512+
const event = await run(door, PARTIAL, {});
513+
expect(event.outcome).toBe('succeeded');
514+
expect(event.bulk).toBeUndefined();
515+
});
516+
});
517+
518+
it('a handler that throws records failed and no counts', async () => {
519+
const rig = makeRig({ script: true });
520+
const res: any = await rig.dispatcher.handleActions(
521+
`/${OBJECT}/${SCRIPT.name}`, 'POST', { params: { _selectedIds: SELECTED } }, rig.ctx({ userId: 'u_member' }),
522+
);
523+
expect(res.response.status).toBe(409);
524+
expect(rig.events[0]).toMatchObject({ outcome: 'failed', status: 409 });
525+
expect(rig.events[0].bulk).toBeUndefined();
526+
});
527+
528+
it('the four counting rules: outside dropped, duplicate once, both lists failed, neither unconfirmed', () => {
529+
const read = (succeeded: string[], failed: string[]) => actionInvocationBulkReading(
530+
{ _selectedIds: ['a', 'b', 'c'] },
531+
{ succeeded, failed: failed.map((id) => ({ id, message: 'no' })) },
532+
);
533+
// An id outside the selection is dropped, counted nowhere.
534+
expect(read(['a', 'z'], ['y'])).toEqual({ selected: 3, succeeded: 1, failed: 0, unconfirmed: 2 });
535+
// A duplicate counts once, in either list.
536+
expect(read(['a', 'a'], ['b', 'b'])).toEqual({ selected: 3, succeeded: 1, failed: 1, unconfirmed: 1 });
537+
// An id in both lists counts as failed.
538+
expect(read(['a', 'b'], ['b'])).toEqual({ selected: 3, succeeded: 1, failed: 1, unconfirmed: 1 });
539+
// A selected id in neither list is not confirmed, never succeeded.
540+
expect(read([], [])).toEqual({ selected: 3, succeeded: 0, failed: 0, unconfirmed: 3 });
541+
});
542+
543+
it('a value with neither list keeps the one-outcome answer; a neighbour shape is unreadable', () => {
544+
const params = { _selectedIds: ['a'] };
545+
expect(actionInvocationBulkReading(params, { url: 'https://example.test/qr.zip' })).toBeUndefined();
546+
expect(actionInvocationBulkReading(params, null)).toBeUndefined();
547+
expect(actionInvocationBulkReading(params, ['a'])).toBeUndefined();
548+
// The data plane's batch answer spells the two as COUNTS: it does not parse.
549+
expect(actionInvocationBulkReading(params, { succeeded: 1, failed: 0, results: [] })).toEqual({ unreadable: true });
550+
// `_selectedIds` that is not an array is no selection.
551+
expect(actionInvocationBulkReading({ _selectedIds: 'a' }, { succeeded: ['a'], failed: [] })).toBeUndefined();
552+
});
553+
});

0 commit comments

Comments
 (0)