@steerable/agent-ui 0.12.8 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,203 @@
1
+ /**
2
+ * `<FactChainDrawer />`
3
+ *
4
+ * Read-only execution provenance & deliverable evidence drawer (wireframes W6 & W7).
5
+ * Displays only authoritative ledger facts:
6
+ * - `requestNode`: model, `policyDigest`, attachment hashes — or honest `status: 'gap'` notice.
7
+ * - `toolNodes`: real executed / `outcome_unknown` tool records — or explicit `no_tool_evidence`
8
+ * notice when the assistant answered from model parameters alone (never quoting prose as evidence).
9
+ * - `deliverableNode`: verifier results, `snapshotSha256`, live workspace drift warning
10
+ * (`'unchanged' | 'modified' | 'deleted'`), and immutable snapshot download URL.
11
+ */
12
+ import * as React from 'react';
13
+
14
+ export interface FactChainRequestNode {
15
+ readonly status: 'recorded' | 'gap';
16
+ readonly model?: string;
17
+ readonly policyDigest?: string;
18
+ readonly systemPromptSummary?: string;
19
+ readonly attachmentHashes?: readonly string[];
20
+ readonly gapReason?: string;
21
+ }
22
+
23
+ export interface FactChainToolNode {
24
+ readonly id: string;
25
+ readonly toolName: string;
26
+ readonly argsSummary: string;
27
+ readonly status: 'executed' | 'outcome_unknown' | 'failed';
28
+ readonly durationMs?: number;
29
+ }
30
+
31
+ export interface FactChainDeliverableNode {
32
+ readonly id: string;
33
+ readonly fileName: string;
34
+ readonly filePath: string;
35
+ readonly verificationStatus: 'verified' | 'warnings' | 'failed' | 'unverified';
36
+ readonly verifierSummary?: string | null;
37
+ readonly snapshotSha256: string;
38
+ readonly workspaceState: 'unchanged' | 'modified' | 'deleted';
39
+ readonly snapshotDownloadUrl?: string | null;
40
+ }
41
+
42
+ export interface FactChainGraph {
43
+ readonly chatId: string;
44
+ readonly targetKind: 'message' | 'tool' | 'deliverable';
45
+ readonly targetId: string;
46
+ readonly requestNode: FactChainRequestNode;
47
+ readonly evidenceStatus: 'recorded' | 'no_tool_evidence' | 'gap';
48
+ readonly toolNodes: readonly FactChainToolNode[];
49
+ readonly deliverableNode?: FactChainDeliverableNode | null;
50
+ }
51
+
52
+ export interface FactChainDrawerProps {
53
+ graph: FactChainGraph | null;
54
+ open: boolean;
55
+ onClose?: () => void;
56
+ className?: string;
57
+ }
58
+
59
+ export const FactChainDrawer: React.FC<FactChainDrawerProps> = ({
60
+ graph,
61
+ open,
62
+ onClose,
63
+ className = '',
64
+ }) => {
65
+ if (!open || !graph) return null;
66
+
67
+ const deliv = graph.deliverableNode;
68
+
69
+ return (
70
+ <aside
71
+ aria-label="Fact Chain"
72
+ data-testid="fact-chain-drawer"
73
+ className={`flex flex-col gap-4 rounded-xl border border-slate-200 bg-white p-4 text-xs shadow-lg dark:border-slate-800 dark:bg-slate-950 ${className}`.trim()}
74
+ >
75
+ <div className="flex items-center justify-between border-b border-slate-200 pb-2.5 dark:border-slate-800">
76
+ <span className="text-sm font-semibold text-slate-900 dark:text-slate-100">
77
+ Execution evidence chain (Fact Chain)
78
+ </span>
79
+ {onClose ? (
80
+ <button
81
+ type="button"
82
+ onClick={onClose}
83
+ data-testid="fact-chain-close"
84
+ className="rounded px-2 py-1 text-xs text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-900"
85
+ >
86
+ Close
87
+ </button>
88
+ ) : null}
89
+ </div>
90
+
91
+ {/* Workspace tamper / deletion warning */}
92
+ {deliv && deliv.workspaceState !== 'unchanged' ? (
93
+ <div
94
+ role="alert"
95
+ data-testid="fact-chain-workspace-drift"
96
+ className="rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-amber-950 dark:text-amber-200"
97
+ >
98
+ ⚠ Workspace file was {deliv.workspaceState} after verification. The immutable snapshot
99
+ link below still serves the exact bytes that passed verification.
100
+ </div>
101
+ ) : null}
102
+
103
+ {/* 1. Request context node */}
104
+ <section className="space-y-1 rounded-lg border border-slate-200 p-3 dark:border-slate-800">
105
+ <div className="font-semibold text-slate-800 dark:text-slate-200">
106
+ 1. Request snapshot
107
+ </div>
108
+ {graph.requestNode.status === 'gap' ? (
109
+ <p data-testid="fact-chain-request-gap" className="text-amber-700 dark:text-amber-300">
110
+ Missing record ({graph.requestNode.gapReason || 'imported_without_request_snapshot'})
111
+ </p>
112
+ ) : (
113
+ <div className="space-y-1 text-slate-600 dark:text-slate-400">
114
+ {graph.requestNode.model ? <div>Model: {graph.requestNode.model}</div> : null}
115
+ {graph.requestNode.policyDigest ? (
116
+ <div className="font-mono">
117
+ Policy digest: {graph.requestNode.policyDigest}
118
+ </div>
119
+ ) : null}
120
+ {graph.requestNode.attachmentHashes &&
121
+ graph.requestNode.attachmentHashes.length > 0 ? (
122
+ <div className="font-mono">
123
+ Input SHA-256: {graph.requestNode.attachmentHashes.join(', ')}
124
+ </div>
125
+ ) : null}
126
+ </div>
127
+ )}
128
+ </section>
129
+
130
+ {/* 2. Tool execution nodes */}
131
+ <section className="space-y-2 rounded-lg border border-slate-200 p-3 dark:border-slate-800">
132
+ <div className="font-semibold text-slate-800 dark:text-slate-200">
133
+ 2. Tool execution receipts
134
+ </div>
135
+ {graph.evidenceStatus === 'no_tool_evidence' || graph.toolNodes.length === 0 ? (
136
+ <p data-testid="fact-chain-no-tool-evidence" className="text-slate-500">
137
+ No tool evidence recorded for this response (generated without tool calls).
138
+ </p>
139
+ ) : (
140
+ <ul className="space-y-1.5">
141
+ {graph.toolNodes.map((node) => (
142
+ <li
143
+ key={node.id}
144
+ data-testid={`fact-chain-tool-${node.id}`}
145
+ className="rounded border border-slate-100 bg-slate-50/70 p-2 dark:border-slate-800 dark:bg-slate-900/50"
146
+ >
147
+ <div className="flex items-center justify-between gap-2">
148
+ <span className="font-mono font-medium">{node.toolName}</span>
149
+ <span
150
+ className={`rounded px-1.5 py-0.5 text-[10px] font-medium ${
151
+ node.status === 'executed'
152
+ ? 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-300'
153
+ : node.status === 'outcome_unknown'
154
+ ? 'bg-amber-500/20 text-amber-800 dark:text-amber-200'
155
+ : 'bg-rose-500/15 text-rose-700 dark:text-rose-300'
156
+ }`}
157
+ >
158
+ {node.status}
159
+ </span>
160
+ </div>
161
+ {node.argsSummary ? (
162
+ <div className="mt-1 truncate font-mono text-[11px] text-slate-500">
163
+ {node.argsSummary}
164
+ </div>
165
+ ) : null}
166
+ </li>
167
+ ))}
168
+ </ul>
169
+ )}
170
+ </section>
171
+
172
+ {/* 3. Deliverable verification & snapshot */}
173
+ {deliv ? (
174
+ <section
175
+ data-testid="fact-chain-deliverable"
176
+ className="space-y-1.5 rounded-lg border border-slate-200 p-3 dark:border-slate-800"
177
+ >
178
+ <div className="font-semibold text-slate-800 dark:text-slate-200">
179
+ 3. Verified deliverable snapshot
180
+ </div>
181
+ <div className="font-medium text-slate-900 dark:text-slate-100">
182
+ {deliv.fileName} ({deliv.verificationStatus})
183
+ </div>
184
+ {deliv.verifierSummary ? (
185
+ <div className="text-slate-600 dark:text-slate-400">{deliv.verifierSummary}</div>
186
+ ) : null}
187
+ <div className="font-mono text-[11px] text-slate-500">
188
+ Snapshot SHA-256: {deliv.snapshotSha256}
189
+ </div>
190
+ {deliv.snapshotDownloadUrl ? (
191
+ <a
192
+ href={deliv.snapshotDownloadUrl}
193
+ data-testid="fact-chain-download-snapshot"
194
+ className="inline-block rounded-md bg-slate-900 px-2.5 py-1 text-xs font-medium text-white hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900"
195
+ >
196
+ Download verified snapshot
197
+ </a>
198
+ ) : null}
199
+ </section>
200
+ ) : null}
201
+ </aside>
202
+ );
203
+ };
@@ -0,0 +1,61 @@
1
+ import * as React from 'react';
2
+ import { cleanup, fireEvent, render, screen } from '@testing-library/react';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
+ import { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
5
+
6
+ afterEach(() => {
7
+ cleanup();
8
+ });
9
+
10
+ describe('OutcomeReconcileCard (T-OUT-07)', () => {
11
+ it('renders amber reconciliation prompt and emits confirmed_not_executed / confirmed_succeeded without auto-retrying', () => {
12
+ const onReconcile = vi.fn();
13
+ render(
14
+ <OutcomeReconcileCard
15
+ payload={{
16
+ reconciliationId: 'rec_998877665544',
17
+ toolName: 'external_dispatch_order',
18
+ argsPreview: '{"orderId":"ORD-42"}',
19
+ errorDetail: 'timeout after 15.0s',
20
+ status: 'pending',
21
+ }}
22
+ onReconcile={onReconcile}
23
+ />,
24
+ );
25
+
26
+ expect(screen.getByTestId('outcome-reconcile-card')).toBeTruthy();
27
+ expect(screen.getByText('rec_998877665544')).toBeTruthy();
28
+ expect(screen.getByText('external_dispatch_order')).toBeTruthy();
29
+
30
+ fireEvent.change(
31
+ screen.getByLabelText('Optional operator verification note'),
32
+ { target: { value: 'Checked ERP queue: not created' } },
33
+ );
34
+ fireEvent.click(screen.getByTestId('reconcile-not-executed'));
35
+
36
+ expect(onReconcile).toHaveBeenCalledTimes(1);
37
+ expect(onReconcile).toHaveBeenCalledWith({
38
+ reconciliationId: 'rec_998877665544',
39
+ resolution: 'confirmed_not_executed',
40
+ note: 'Checked ERP queue: not created',
41
+ });
42
+ });
43
+
44
+ it('switches to read-only summary once resolved', () => {
45
+ render(
46
+ <OutcomeReconcileCard
47
+ payload={{
48
+ reconciliationId: 'rec_resolved_1',
49
+ toolName: 'external_dispatch_order',
50
+ status: 'confirmed_executed',
51
+ resolutionNote: 'Confirmed in console #88',
52
+ }}
53
+ />,
54
+ );
55
+
56
+ expect(screen.queryByTestId('reconcile-not-executed')).toBeNull();
57
+ expect(screen.getByTestId('reconcile-resolved-summary').textContent).toContain(
58
+ 'Confirmed in console #88',
59
+ );
60
+ });
61
+ });
@@ -0,0 +1,139 @@
1
+ /**
2
+ * `<OutcomeReconcileCard />`
3
+ *
4
+ * Amber stop-and-reconcile card rendered when a non-idempotent (`idempotent: false`)
5
+ * tool call times out, disconnects, or fails after crossing the dispatch boundary
6
+ * (`outcomeUnknown: true`).
7
+ *
8
+ * Neither reconciliation button re-executes the original tool:
9
+ * - `confirmed_not_executed` releases the session lock so a subsequent turn may try again;
10
+ * - `confirmed_succeeded` records external completion in the ledger and keeps duplicate calls blocked.
11
+ */
12
+ import * as React from 'react';
13
+ import type { OutcomeReconcilePayload } from '@steerable/agent-protocol';
14
+
15
+ export type OutcomeReconcileDecision =
16
+ | 'confirmed_succeeded'
17
+ | 'confirmed_not_executed';
18
+
19
+ export interface OutcomeReconcileCardProps {
20
+ payload: OutcomeReconcilePayload;
21
+ isSubmitting?: boolean;
22
+ onReconcile?: (decision: {
23
+ reconciliationId: string;
24
+ resolution: OutcomeReconcileDecision;
25
+ note?: string;
26
+ }) => void;
27
+ className?: string;
28
+ titleLabel?: React.ReactNode;
29
+ descriptionLabel?: React.ReactNode;
30
+ confirmNotExecutedLabel?: React.ReactNode;
31
+ confirmSucceededLabel?: React.ReactNode;
32
+ notePlaceholder?: string;
33
+ }
34
+
35
+ export const OutcomeReconcileCard: React.FC<OutcomeReconcileCardProps> = ({
36
+ payload,
37
+ isSubmitting = false,
38
+ onReconcile,
39
+ className = '',
40
+ titleLabel = 'External execution outcome unknown · automatic retry paused',
41
+ descriptionLabel,
42
+ confirmNotExecutedLabel = 'Confirm not executed, release lock',
43
+ confirmSucceededLabel = 'Confirm executed externally',
44
+ notePlaceholder = 'Optional operator verification note',
45
+ }) => {
46
+ const [note, setNote] = React.useState('');
47
+ const isPending = payload.status === 'pending';
48
+
49
+ const handleDecision = (resolution: OutcomeReconcileDecision) => {
50
+ if (!isPending || isSubmitting || !onReconcile) return;
51
+ const trimmed = note.trim();
52
+ onReconcile({
53
+ reconciliationId: payload.reconciliationId,
54
+ resolution,
55
+ ...(trimmed ? { note: trimmed } : {}),
56
+ });
57
+ };
58
+
59
+ return (
60
+ <div
61
+ data-testid="outcome-reconcile-card"
62
+ data-status={payload.status}
63
+ className={`rounded-xl border border-amber-500/40 bg-amber-500/10 p-4 text-sm ${className}`.trim()}
64
+ >
65
+ <div className="flex items-center justify-between gap-2">
66
+ <div className="flex items-center gap-2 font-medium text-amber-800 dark:text-amber-300">
67
+ <span aria-hidden="true">⚠</span>
68
+ <span>{titleLabel}</span>
69
+ </div>
70
+ <span className="rounded bg-amber-500/20 px-2 py-0.5 font-mono text-xs text-amber-900 dark:text-amber-200">
71
+ {payload.reconciliationId}
72
+ </span>
73
+ </div>
74
+
75
+ <p className="mt-2 text-xs leading-relaxed text-amber-900/90 dark:text-amber-100/90">
76
+ {descriptionLabel ?? (
77
+ <>
78
+ Tool <code className="rounded bg-amber-500/20 px-1 py-0.5 font-mono">{payload.toolName}</code>{' '}
79
+ did not return a definitive receipt
80
+ {payload.errorDetail ? ` (${payload.errorDetail})` : ''}. To prevent duplicate side effects,
81
+ further calls to this tool are locked until you verify its external state.
82
+ </>
83
+ )}
84
+ </p>
85
+
86
+ {payload.argsPreview ? (
87
+ <pre className="mt-2 max-h-28 overflow-auto rounded-lg border border-amber-500/20 bg-black/5 p-2 font-mono text-xs dark:bg-white/5">
88
+ {payload.argsPreview}
89
+ </pre>
90
+ ) : null}
91
+
92
+ {isPending ? (
93
+ <div className="mt-3 space-y-2.5">
94
+ <input
95
+ type="text"
96
+ value={note}
97
+ onChange={(e) => setNote(e.target.value)}
98
+ disabled={isSubmitting}
99
+ placeholder={notePlaceholder}
100
+ aria-label={notePlaceholder}
101
+ className="w-full rounded-lg border border-amber-500/30 bg-white/80 px-2.5 py-1.5 text-xs outline-none focus:border-amber-600 dark:bg-black/30"
102
+ />
103
+ <div className="flex flex-wrap items-center justify-between gap-2">
104
+ <button
105
+ type="button"
106
+ disabled={isSubmitting}
107
+ onClick={() => handleDecision('confirmed_not_executed')}
108
+ data-testid="reconcile-not-executed"
109
+ className="rounded-lg border border-amber-600/40 bg-white/70 px-3 py-1.5 text-xs font-medium text-amber-900 hover:bg-white disabled:opacity-50 dark:bg-black/30 dark:text-amber-200"
110
+ >
111
+ {confirmNotExecutedLabel}
112
+ </button>
113
+ <button
114
+ type="button"
115
+ disabled={isSubmitting}
116
+ onClick={() => handleDecision('confirmed_succeeded')}
117
+ data-testid="reconcile-confirmed-succeeded"
118
+ className="rounded-lg bg-amber-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-amber-700 disabled:opacity-50"
119
+ >
120
+ {confirmSucceededLabel}
121
+ </button>
122
+ </div>
123
+ </div>
124
+ ) : (
125
+ <div
126
+ data-testid="reconcile-resolved-summary"
127
+ className="mt-3 rounded-lg border border-amber-500/25 bg-white/50 px-3 py-2 text-xs text-amber-950 dark:bg-black/20 dark:text-amber-100"
128
+ >
129
+ <span className="font-medium">
130
+ {payload.status === 'confirmed_executed'
131
+ ? 'Confirmed executed externally (duplicate calls stay blocked)'
132
+ : 'Confirmed not executed (re-invocation lock released)'}
133
+ </span>
134
+ {payload.resolutionNote ? <span> — {payload.resolutionNote}</span> : null}
135
+ </div>
136
+ )}
137
+ </div>
138
+ );
139
+ };
@@ -0,0 +1,205 @@
1
+ import * as React from 'react';
2
+ import { cleanup, fireEvent, render, screen } from '@testing-library/react';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
+ import type { UiSurfacePayload } from '@steerable/agent-protocol';
5
+ import { resetAllUiSurfaceDraftsForTests } from './ui-surface-draft.js';
6
+ import { UiSurfaceCard } from './UiSurfaceCard.js';
7
+ import { UiSurfaceWorkbench } from './UiSurfaceWorkbench.js';
8
+ import { FactChainDrawer } from './FactChainDrawer.js';
9
+
10
+ afterEach(() => {
11
+ cleanup();
12
+ resetAllUiSurfaceDraftsForTests();
13
+ });
14
+
15
+ const SAMPLE_SURFACE: UiSurfacePayload = {
16
+ surfaceId: 'po-review',
17
+ revision: 1,
18
+ title: 'Purchase Order Workbench',
19
+ subtitle: 'Batch review & sign-off',
20
+ placement: 'workbench',
21
+ resolvedData: {
22
+ orders: [
23
+ { id: 'PO-1', supplier: 'Alpha Steel', total: '50,000' },
24
+ { id: 'PO-2', supplier: 'Nova Optics', total: '18,000' },
25
+ ],
26
+ },
27
+ sourceHashes: { orders: 'hash_v1' },
28
+ components: [
29
+ {
30
+ kind: 'steps',
31
+ id: 'st-1',
32
+ steps: [
33
+ { id: 's1', label: 'Ingest', status: 'completed' },
34
+ { id: 's2', label: 'Sign-off', status: 'active' },
35
+ ],
36
+ },
37
+ {
38
+ kind: 'table',
39
+ id: 'tb-1',
40
+ dataKey: 'orders',
41
+ rowIdField: 'id',
42
+ selectable: true,
43
+ columns: [
44
+ { key: 'id', label: 'Order ID' },
45
+ { key: 'supplier', label: 'Supplier' },
46
+ { key: 'total', label: 'Total' },
47
+ ],
48
+ },
49
+ {
50
+ kind: 'detail-card',
51
+ id: 'dc-1',
52
+ title: 'Policy Summary',
53
+ fields: [{ key: 'dept', label: 'Department', value: 'Manufacturing' }],
54
+ },
55
+ {
56
+ kind: 'form',
57
+ id: 'fm-1',
58
+ fields: [{ key: 'comment', label: 'Reviewer Comment', type: 'text', value: '' }],
59
+ },
60
+ {
61
+ kind: 'kv-diff',
62
+ id: 'kv-1',
63
+ diffs: [{ key: 'budget_code', label: 'Budget Code', before: 'B-2025', after: 'B-2026' }],
64
+ },
65
+ {
66
+ kind: 'artifact-card',
67
+ id: 'art-1',
68
+ artifact: {
69
+ name: 'po_summary.xlsx',
70
+ sha256: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
71
+ downloadUrl: '/api/v2/chats/chat-1/deliverables/d1/snapshot',
72
+ },
73
+ },
74
+ ],
75
+ actions: [
76
+ {
77
+ id: 'approve_batch',
78
+ label: 'Approve Selected',
79
+ toolName: 'approve_orders',
80
+ variant: 'primary',
81
+ requiresSelection: true,
82
+ checkpoint: 'outward',
83
+ },
84
+ ],
85
+ };
86
+
87
+ describe('UiSurfaceCard, UiSurfaceWorkbench & FactChainDrawer (T-UIS-01, T-UIS-03, T-UIS-05, T-VER-03, T-VER-05)', () => {
88
+ it('T-UIS-01 & T-UIS-05: renders all 6 closed components, retains draft across unmount/remount, and handles 409 UI_STALE + refresh', () => {
89
+ const onOpen = vi.fn();
90
+ render(<UiSurfaceCard payload={SAMPLE_SURFACE} onOpenWorkbench={onOpen} />);
91
+ fireEvent.click(screen.getByTestId('ui-surface-open-workbench'));
92
+ expect(onOpen).toHaveBeenCalledTimes(1);
93
+ cleanup();
94
+
95
+ const onDispatchAction = vi.fn();
96
+ const onRefreshSurface = vi.fn();
97
+
98
+ const { unmount } = render(
99
+ <UiSurfaceWorkbench
100
+ chatId="chat-1"
101
+ payload={SAMPLE_SURFACE}
102
+ onDispatchAction={onDispatchAction}
103
+ onRefreshSurface={onRefreshSurface}
104
+ />,
105
+ );
106
+
107
+ expect(screen.getByTestId('surface-steps-st-1')).toBeTruthy();
108
+ expect(screen.getByTestId('surface-table-tb-1')).toBeTruthy();
109
+ expect(screen.getByTestId('surface-detail-dc-1')).toBeTruthy();
110
+ expect(screen.getByTestId('surface-form-fm-1')).toBeTruthy();
111
+ expect(screen.getByTestId('surface-kvdiff-kv-1')).toBeTruthy();
112
+ expect(screen.getByTestId('surface-artifact-art-1')).toBeTruthy();
113
+
114
+ // Select PO-1 and fill Reviewer Comment
115
+ fireEvent.click(screen.getByLabelText('Select row PO-1'));
116
+ fireEvent.change(screen.getByTestId('surface-form-input-comment'), {
117
+ target: { value: 'Approved for Q4' },
118
+ });
119
+
120
+ // T-UIS-05: Unmount (tab switch) and remount -> selection & input draft remain intact!
121
+ unmount();
122
+ const { rerender } = render(
123
+ <UiSurfaceWorkbench
124
+ chatId="chat-1"
125
+ payload={SAMPLE_SURFACE}
126
+ staleBannerKeys={['orders']}
127
+ onDispatchAction={onDispatchAction}
128
+ onRefreshSurface={onRefreshSurface}
129
+ />,
130
+ );
131
+ expect((screen.getByLabelText('Select row PO-1') as HTMLInputElement).checked).toBe(true);
132
+ expect((screen.getByTestId('surface-form-input-comment') as HTMLInputElement).value).toBe(
133
+ 'Approved for Q4',
134
+ );
135
+ expect(screen.getByTestId('ui-surface-stale-banner')).toBeTruthy();
136
+
137
+ // Dispatch emits commandId + expectedRevision + sourceHashes + selectedRowIds (no forged row objects)
138
+ fireEvent.click(screen.getByTestId('ui-surface-action-approve_batch'));
139
+ expect(onDispatchAction).toHaveBeenCalledTimes(1);
140
+ const dispatched = onDispatchAction.mock.calls[0][0];
141
+ expect(dispatched.commandId).toMatch(/^cmd_po-review_approve_batch_/);
142
+ expect(dispatched.expectedRevision).toBe(1);
143
+ expect(dispatched.selectedRowIds).toEqual(['PO-1']);
144
+ expect(dispatched.rows).toBeUndefined();
145
+
146
+ // Click Refresh latest data -> triggers refresh callback; rerendering with revision 2 highlights changed cell!
147
+ fireEvent.click(screen.getByTestId('ui-surface-refresh-btn'));
148
+ expect(onRefreshSurface).toHaveBeenCalledWith('po-review');
149
+
150
+ rerender(
151
+ <UiSurfaceWorkbench
152
+ chatId="chat-1"
153
+ payload={{
154
+ ...SAMPLE_SURFACE,
155
+ revision: 2,
156
+ resolvedData: {
157
+ orders: [
158
+ { id: 'PO-1', supplier: 'Alpha Steel', total: '62,000' },
159
+ { id: 'PO-2', supplier: 'Nova Optics', total: '18,000' },
160
+ ],
161
+ },
162
+ sourceHashes: { orders: 'hash_v2' },
163
+ }}
164
+ staleBannerKeys={[]}
165
+ onDispatchAction={onDispatchAction}
166
+ onRefreshSurface={onRefreshSurface}
167
+ />,
168
+ );
169
+ expect(screen.queryByTestId('ui-surface-stale-banner')).toBeNull();
170
+ expect(screen.getByText('62,000').getAttribute('data-highlighted')).toBe('true');
171
+ });
172
+
173
+ it('T-VER-03 & T-VER-05: FactChainDrawer displays honest gap / no_tool_evidence states and modified-after-delivery warning with snapshot link', () => {
174
+ render(
175
+ <FactChainDrawer
176
+ open={true}
177
+ graph={{
178
+ chatId: 'c-1',
179
+ targetKind: 'deliverable',
180
+ targetId: 'deliv-1',
181
+ requestNode: { status: 'gap', gapReason: 'imported_without_request_snapshot' },
182
+ evidenceStatus: 'no_tool_evidence',
183
+ toolNodes: [],
184
+ deliverableNode: {
185
+ id: 'deliv-1',
186
+ fileName: 'masked_contract.docx',
187
+ filePath: '/tmp/masked_contract.docx',
188
+ verificationStatus: 'verified',
189
+ verifierSummary: 'Redaction verified',
190
+ snapshotSha256: '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08',
191
+ workspaceState: 'modified',
192
+ snapshotDownloadUrl: '/api/v2/chats/c-1/deliverables/deliv-1/snapshot',
193
+ },
194
+ }}
195
+ />,
196
+ );
197
+
198
+ expect(screen.getByTestId('fact-chain-request-gap')).toBeTruthy();
199
+ expect(screen.getByTestId('fact-chain-no-tool-evidence')).toBeTruthy();
200
+ expect(screen.getByTestId('fact-chain-workspace-drift')).toBeTruthy();
201
+ expect(screen.getByRole('link').getAttribute('href')).toBe(
202
+ '/api/v2/chats/c-1/deliverables/deliv-1/snapshot',
203
+ );
204
+ });
205
+ });