@workflow/web-shared 5.0.8 → 5.1.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.
- package/README.md +8 -0
- package/dist/components/error-boundary.js +1 -1
- package/dist/components/event-list/event-details-panel.d.ts +25 -0
- package/dist/components/event-list/event-details-panel.d.ts.map +1 -0
- package/dist/components/event-list/event-details-panel.js +156 -0
- package/dist/components/event-list/event-list-toolbar.d.ts +6 -0
- package/dist/components/event-list/event-list-toolbar.d.ts.map +1 -0
- package/dist/components/event-list/event-list-toolbar.js +15 -0
- package/dist/components/event-list/event-row.d.ts +29 -0
- package/dist/components/event-list/event-row.d.ts.map +1 -0
- package/dist/components/event-list/event-row.js +102 -0
- package/dist/components/event-list/use-event-search.d.ts +14 -0
- package/dist/components/event-list/use-event-search.d.ts.map +1 -0
- package/dist/components/event-list/use-event-search.js +74 -0
- package/dist/components/event-list-view.d.ts +10 -67
- package/dist/components/event-list-view.d.ts.map +1 -1
- package/dist/components/event-list-view.js +112 -984
- package/dist/components/hook-actions.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/sidebar/attribute-panel.d.ts +2 -2
- package/dist/components/sidebar/attribute-panel.d.ts.map +1 -1
- package/dist/components/sidebar/attribute-panel.js +1 -1
- package/dist/components/sidebar/attributes-block.d.ts +5 -5
- package/dist/components/sidebar/attributes-block.d.ts.map +1 -1
- package/dist/components/sidebar/attributes-block.js +1 -1
- package/dist/components/sidebar/conversation-view.d.ts +1 -1
- package/dist/components/sidebar/conversation-view.d.ts.map +1 -1
- package/dist/components/sidebar/conversation-view.js +1 -1
- package/dist/components/sidebar/copyable-data-block.d.ts +2 -2
- package/dist/components/sidebar/copyable-data-block.d.ts.map +1 -1
- package/dist/components/sidebar/copyable-data-block.js +1 -1
- package/dist/components/sidebar/entity-detail-panel.js +1 -1
- package/dist/components/sidebar/events-list.d.ts +1 -1
- package/dist/components/sidebar/events-list.d.ts.map +1 -1
- package/dist/components/sidebar/events-list.js +1 -1
- package/dist/components/sidebar/resolve-hook-modal.js +1 -1
- package/dist/components/sidebar/sidebar-data-context.d.ts +1 -1
- package/dist/components/sidebar/sidebar-data-context.d.ts.map +1 -1
- package/dist/components/sidebar/sidebar-data-context.js +1 -1
- package/dist/components/sidebar/span-detail-merge.js +1 -1
- package/dist/components/sidebar/use-selected-span-detail.js +1 -1
- package/dist/components/stream-image-preview.d.ts +4 -0
- package/dist/components/stream-image-preview.d.ts.map +1 -0
- package/dist/components/stream-image-preview.js +21 -0
- package/dist/components/stream-viewer-skeleton.d.ts +1 -1
- package/dist/components/stream-viewer-skeleton.d.ts.map +1 -1
- package/dist/components/stream-viewer-skeleton.js +1 -1
- package/dist/components/stream-viewer.d.ts +2 -1
- package/dist/components/stream-viewer.d.ts.map +1 -1
- package/dist/components/stream-viewer.js +7 -2
- package/dist/components/trace-viewer/components/copy-button.js +1 -1
- package/dist/components/trace-viewer/components/detail-panel-shell.d.ts +22 -0
- package/dist/components/trace-viewer/components/detail-panel-shell.d.ts.map +1 -0
- package/dist/components/trace-viewer/components/detail-panel-shell.js +49 -0
- package/dist/components/trace-viewer/components/detail-panel-width.js +1 -1
- package/dist/components/trace-viewer/components/detail-panel.d.ts +4 -4
- package/dist/components/trace-viewer/components/detail-panel.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/detail-panel.js +11 -51
- package/dist/components/trace-viewer/components/draggable-border.d.ts +1 -1
- package/dist/components/trace-viewer/components/draggable-border.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/draggable-border.js +1 -1
- package/dist/components/trace-viewer/components/event-list.d.ts +10 -1
- package/dist/components/trace-viewer/components/event-list.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/event-list.js +10 -3
- package/dist/components/trace-viewer/components/middle-truncate/copy-selection.js +1 -1
- package/dist/components/trace-viewer/components/middle-truncate/measurement-batch.js +1 -1
- package/dist/components/trace-viewer/components/middle-truncate/middle-truncate.js +1 -1
- package/dist/components/trace-viewer/components/middle-truncate/truncate.js +1 -1
- package/dist/components/trace-viewer/components/middle-truncate/use-middle-truncate.js +1 -1
- package/dist/components/trace-viewer/components/minimap.js +1 -1
- package/dist/components/trace-viewer/components/pane-constants.js +1 -1
- package/dist/components/trace-viewer/components/span-markers.js +1 -1
- package/dist/components/trace-viewer/components/split-pane.d.ts +1 -1
- package/dist/components/trace-viewer/components/split-pane.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/split-pane.js +1 -1
- package/dist/components/trace-viewer/components/timeline.js +1 -1
- package/dist/components/trace-viewer/components/trace-shortcut-helper.d.ts +1 -1
- package/dist/components/trace-viewer/components/trace-shortcut-helper.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/trace-shortcut-helper.js +1 -1
- package/dist/components/trace-viewer/components/trace-viewer-skeleton.d.ts +1 -1
- package/dist/components/trace-viewer/components/trace-viewer-skeleton.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/trace-viewer-skeleton.js +1 -1
- package/dist/components/trace-viewer/components/use-alt-held.d.ts +1 -0
- package/dist/components/trace-viewer/components/use-alt-held.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/use-alt-held.js +2 -2
- package/dist/components/trace-viewer/components/use-detail-panel-width.d.ts +19 -0
- package/dist/components/trace-viewer/components/use-detail-panel-width.d.ts.map +1 -0
- package/dist/components/trace-viewer/components/use-detail-panel-width.js +26 -0
- package/dist/components/trace-viewer/components/use-element-width.js +1 -1
- package/dist/components/trace-viewer/components/use-row-window.js +1 -1
- package/dist/components/trace-viewer/context.d.ts +3 -2
- package/dist/components/trace-viewer/context.d.ts.map +1 -1
- package/dist/components/trace-viewer/context.js +3 -3
- package/dist/components/trace-viewer/icons.d.ts +4 -4
- package/dist/components/trace-viewer/icons.d.ts.map +1 -1
- package/dist/components/trace-viewer/icons.js +1 -1
- package/dist/components/trace-viewer/search.js +1 -1
- package/dist/components/trace-viewer/trace-viewer.d.ts +2 -1
- package/dist/components/trace-viewer/trace-viewer.d.ts.map +1 -1
- package/dist/components/trace-viewer/trace-viewer.js +3 -12
- package/dist/components/trace-viewer/types.js +1 -1
- package/dist/components/trace-viewer/util/timing.js +1 -1
- package/dist/components/trace-viewer/utils.d.ts.map +1 -1
- package/dist/components/trace-viewer/utils.js +12 -3
- package/dist/components/trace-viewer.d.ts +3 -2
- package/dist/components/trace-viewer.d.ts.map +1 -1
- package/dist/components/trace-viewer.js +3 -3
- package/dist/components/ui/alert.js +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/card.js +1 -1
- package/dist/components/ui/collapsible.d.ts +6 -4
- package/dist/components/ui/collapsible.d.ts.map +1 -1
- package/dist/components/ui/collapsible.js +3 -3
- package/dist/components/ui/context-card.js +1 -1
- package/dist/components/ui/data-inspector.js +1 -1
- package/dist/components/ui/data-inspector.styles.js +1 -1
- package/dist/components/ui/decrypt-button.d.ts +1 -1
- package/dist/components/ui/decrypt-button.d.ts.map +1 -1
- package/dist/components/ui/decrypt-button.js +2 -2
- package/dist/components/ui/duplicate-event-tooltip.js +1 -1
- package/dist/components/ui/error-card.d.ts +1 -1
- package/dist/components/ui/error-card.d.ts.map +1 -1
- package/dist/components/ui/error-card.js +2 -2
- package/dist/components/ui/error-stack-block.d.ts +1 -1
- package/dist/components/ui/error-stack-block.d.ts.map +1 -1
- package/dist/components/ui/error-stack-block.js +1 -1
- package/dist/components/ui/icon-button.d.ts +2 -2
- package/dist/components/ui/icon-button.js +1 -1
- package/dist/components/ui/kbd.d.ts +1 -1
- package/dist/components/ui/kbd.js +1 -1
- package/dist/components/ui/load-more-button.d.ts +1 -1
- package/dist/components/ui/load-more-button.d.ts.map +1 -1
- package/dist/components/ui/load-more-button.js +1 -1
- package/dist/components/ui/menu-dropdown.d.ts +1 -1
- package/dist/components/ui/menu-dropdown.d.ts.map +1 -1
- package/dist/components/ui/menu-dropdown.js +1 -1
- package/dist/components/ui/skeleton.d.ts +1 -1
- package/dist/components/ui/skeleton.d.ts.map +1 -1
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/spinner.d.ts +1 -1
- package/dist/components/ui/spinner.d.ts.map +1 -1
- package/dist/components/ui/spinner.js +1 -1
- package/dist/components/ui/timestamp-tooltip.js +1 -1
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/components/workflow-traces/event-colors.js +1 -1
- package/dist/components/workflow-traces/trace-span-construction.d.ts +8 -2
- package/dist/components/workflow-traces/trace-span-construction.d.ts.map +1 -1
- package/dist/components/workflow-traces/trace-span-construction.js +29 -11
- package/dist/components/workflow-traces/trace-time-utils.js +1 -1
- package/dist/hooks/use-dark-mode.js +1 -1
- package/dist/hooks/use-intersection-observer.js +1 -1
- package/dist/hooks/use-load-more-on-scroll.js +1 -1
- package/dist/hooks/use-reduced-motion.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/cn.js +1 -1
- package/dist/lib/duplicate-events.js +1 -1
- package/dist/lib/event-analysis.d.ts.map +1 -1
- package/dist/lib/event-analysis.js +10 -2
- package/dist/lib/event-list-model.d.ts +179 -0
- package/dist/lib/event-list-model.d.ts.map +1 -0
- package/dist/lib/event-list-model.js +459 -0
- package/dist/lib/event-materialization.d.ts +4 -0
- package/dist/lib/event-materialization.d.ts.map +1 -1
- package/dist/lib/event-materialization.js +25 -7
- package/dist/lib/exact-event-search-id.js +1 -1
- package/dist/lib/hydration.d.ts +5 -3
- package/dist/lib/hydration.d.ts.map +1 -1
- package/dist/lib/hydration.js +10 -6
- package/dist/lib/run-limit-guidance.js +1 -1
- package/dist/lib/sealed-events.js +1 -1
- package/dist/lib/start-hook.d.ts +30 -0
- package/dist/lib/start-hook.d.ts.map +1 -0
- package/dist/lib/start-hook.js +50 -0
- package/dist/lib/state-hydration.d.ts +37 -0
- package/dist/lib/state-hydration.d.ts.map +1 -0
- package/dist/lib/state-hydration.js +148 -0
- package/dist/lib/stream-display.js +1 -1
- package/dist/lib/stream-image.d.ts +3 -0
- package/dist/lib/stream-image.d.ts.map +1 -0
- package/dist/lib/stream-image.js +23 -0
- package/dist/lib/toast.js +1 -1
- package/dist/lib/trace-builder.d.ts +1 -0
- package/dist/lib/trace-builder.d.ts.map +1 -1
- package/dist/lib/trace-builder.js +16 -5
- package/dist/lib/trace-types.js +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/zstd-browser-decoder.js +1 -1
- package/package.json +22 -19
- package/src/components/event-list/event-details-panel.tsx +407 -0
- package/src/components/event-list/event-list-toolbar.tsx +47 -0
- package/src/components/event-list/event-row.tsx +348 -0
- package/src/components/event-list/use-event-search.ts +104 -0
- package/src/components/event-list-view.tsx +258 -1848
- package/src/components/stream-image-preview.tsx +54 -0
- package/src/components/stream-viewer.tsx +16 -6
- package/src/components/trace-viewer/components/detail-panel-shell.tsx +143 -0
- package/src/components/trace-viewer/components/detail-panel.tsx +37 -176
- package/src/components/trace-viewer/components/event-list.tsx +35 -14
- package/src/components/trace-viewer/components/use-alt-held.ts +1 -1
- package/src/components/trace-viewer/components/use-detail-panel-width.ts +53 -0
- package/src/components/trace-viewer/context.tsx +5 -1
- package/src/components/trace-viewer/trace-viewer.tsx +6 -11
- package/src/components/trace-viewer/utils.ts +14 -2
- package/src/components/trace-viewer.tsx +3 -0
- package/src/components/ui/collapsible.tsx +11 -0
- package/src/components/ui/decrypt-button.tsx +1 -1
- package/src/components/ui/error-card.tsx +1 -1
- package/src/components/workflow-traces/trace-span-construction.ts +34 -11
- package/src/index.ts +7 -0
- package/src/lib/event-analysis.ts +9 -0
- package/src/lib/event-list-model.ts +684 -0
- package/src/lib/event-materialization.ts +26 -7
- package/src/lib/hydration.ts +11 -5
- package/src/lib/start-hook.ts +82 -0
- package/src/lib/state-hydration.ts +208 -0
- package/src/lib/stream-image.ts +21 -0
- package/src/lib/trace-builder.ts +22 -2
- package/src/components/event-list-view.test.ts +0 -51
- package/src/components/trace-viewer/components/detail-panel-width.test.ts +0 -123
- package/src/components/trace-viewer/utils.test.ts +0 -468
- package/src/components/workflow-traces/event-colors.test.ts +0 -14
- package/src/components/workflow-traces/trace-span-construction.test.ts +0 -172
- package/src/lib/duplicate-events.test.ts +0 -336
- package/src/lib/event-materialization.test.ts +0 -136
- package/src/lib/hydration.test.ts +0 -63
- package/src/lib/run-limit-guidance.test.ts +0 -90
- package/src/lib/trace-builder.test.ts +0 -143
- package/src/lib/utils.test.ts +0 -33
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type StepStatus,
|
|
19
19
|
} from '@workflow/world';
|
|
20
20
|
import { findDuplicateEventIds } from './duplicate-events';
|
|
21
|
+
import { findStartHookCreation } from './start-hook';
|
|
21
22
|
|
|
22
23
|
// ---------------------------------------------------------------------------
|
|
23
24
|
// Materialized entity types
|
|
@@ -198,14 +199,35 @@ export function materializeSteps(
|
|
|
198
199
|
|
|
199
200
|
/**
|
|
200
201
|
* Group hook_* events by correlationId and build Hook-like entities.
|
|
202
|
+
*
|
|
203
|
+
* A run's start Hook has no `hook_created`: the run's creation event stands
|
|
204
|
+
* for it (see {@link findStartHookCreation}), so it is materialized from that
|
|
205
|
+
* even before anything is delivered to it.
|
|
201
206
|
*/
|
|
202
207
|
export function materializeHooks(events: Event[]): MaterializedHook[] {
|
|
203
208
|
const groups = groupByCorrelationId(events, isHookLifecycleEventType);
|
|
204
209
|
const hooks: MaterializedHook[] = [];
|
|
205
210
|
|
|
211
|
+
const startHook = findStartHookCreation(events);
|
|
212
|
+
if (startHook && !groups.has(startHook.hookId)) {
|
|
213
|
+
groups.set(startHook.hookId, []);
|
|
214
|
+
}
|
|
215
|
+
|
|
206
216
|
for (const [correlationId, hookEvents] of groups) {
|
|
207
217
|
const created = hookEvents.find((e) => e.eventType === 'hook_created');
|
|
208
|
-
|
|
218
|
+
const creation = created
|
|
219
|
+
? {
|
|
220
|
+
runId: created.runId,
|
|
221
|
+
token:
|
|
222
|
+
created.eventType === 'hook_created'
|
|
223
|
+
? created.eventData?.token
|
|
224
|
+
: undefined,
|
|
225
|
+
createdAt: getEventTimestamp(created) ?? created.createdAt,
|
|
226
|
+
}
|
|
227
|
+
: correlationId === startHook?.hookId
|
|
228
|
+
? startHook
|
|
229
|
+
: undefined;
|
|
230
|
+
if (!creation) continue;
|
|
209
231
|
|
|
210
232
|
const receivedEvents = hookEvents.filter(
|
|
211
233
|
(e) => e.eventType === 'hook_received'
|
|
@@ -215,12 +237,9 @@ export function materializeHooks(events: Event[]): MaterializedHook[] {
|
|
|
215
237
|
|
|
216
238
|
hooks.push({
|
|
217
239
|
hookId: correlationId,
|
|
218
|
-
runId:
|
|
219
|
-
token:
|
|
220
|
-
|
|
221
|
-
? created.eventData?.token
|
|
222
|
-
: undefined,
|
|
223
|
-
createdAt: getEventTimestamp(created) ?? created.createdAt,
|
|
240
|
+
runId: creation.runId,
|
|
241
|
+
token: creation.token,
|
|
242
|
+
createdAt: creation.createdAt,
|
|
224
243
|
receivedCount: receivedEvents.length,
|
|
225
244
|
lastReceivedAt: getEventTimestamp(lastReceived),
|
|
226
245
|
disposedAt: getEventTimestamp(disposed),
|
package/src/lib/hydration.ts
CHANGED
|
@@ -530,9 +530,10 @@ function replaceEncryptedAndExpiredWithMarkers<T>(resource: T): T {
|
|
|
530
530
|
*/
|
|
531
531
|
export async function hydrateResourceIOWithKey<T>(
|
|
532
532
|
resource: T,
|
|
533
|
-
key: Uint8Array
|
|
533
|
+
key: Uint8Array,
|
|
534
|
+
extraRevivers?: Revivers
|
|
534
535
|
): Promise<T> {
|
|
535
|
-
return hydrateResourceIOAsync(resource, key);
|
|
536
|
+
return hydrateResourceIOAsync(resource, key, extraRevivers);
|
|
536
537
|
}
|
|
537
538
|
|
|
538
539
|
/**
|
|
@@ -541,11 +542,14 @@ export async function hydrateResourceIOWithKey<T>(
|
|
|
541
542
|
* This follows the same resource-field mapping as {@link hydrateResourceIO},
|
|
542
543
|
* but can also inflate compressed browser payloads through the registered
|
|
543
544
|
* zstd WASM decoder. When a key is provided, encrypted fields are decrypted
|
|
544
|
-
* first and then inflated/hydrated.
|
|
545
|
+
* first and then inflated/hydrated. `extraRevivers` are merged over the web
|
|
546
|
+
* revivers, for example a run's frozen state revivers (see
|
|
547
|
+
* `createRunStateHydrator`).
|
|
545
548
|
*/
|
|
546
549
|
export async function hydrateResourceIOAsync<T>(
|
|
547
550
|
resource: T,
|
|
548
|
-
key?: Uint8Array
|
|
551
|
+
key?: Uint8Array,
|
|
552
|
+
extraRevivers?: Revivers
|
|
549
553
|
): Promise<T> {
|
|
550
554
|
const { hydrateDataWithKey, deriveRunPayloadKeys } = await import(
|
|
551
555
|
'@workflow/core/serialization-format'
|
|
@@ -563,7 +567,9 @@ export async function hydrateResourceIOAsync<T>(
|
|
|
563
567
|
// run's X25519 scalar in addition to its AES key. Both derive from the same
|
|
564
568
|
// 32 bytes the key-retrieval endpoint returns.
|
|
565
569
|
const cryptoKey = key ? await deriveRunPayloadKeys(key) : undefined;
|
|
566
|
-
const revivers =
|
|
570
|
+
const revivers = extraRevivers
|
|
571
|
+
? { ...getRevivers(), ...extraRevivers }
|
|
572
|
+
: getRevivers();
|
|
567
573
|
|
|
568
574
|
async function hydrateField(value: unknown): Promise<unknown> {
|
|
569
575
|
// Already-hydrated: encrypted marker with stored bytes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Event,
|
|
3
|
+
isHookLifecycleEventType,
|
|
4
|
+
isRunCreationEvent,
|
|
5
|
+
startHookId,
|
|
6
|
+
type WorkflowRun,
|
|
7
|
+
} from '@workflow/world';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The creation of a run's start Hook (`start(workflow, args, { hook })`).
|
|
11
|
+
*
|
|
12
|
+
* A start Hook has no `hook_created` of its own: the World creates it while
|
|
13
|
+
* it admits the run, and the run's creation event (`run_created`, or the
|
|
14
|
+
* `run_started` holding the first slot) stands for it, carrying
|
|
15
|
+
* `eventData.startHook`. Its deliveries are ordinary `hook_received` events
|
|
16
|
+
* under {@link startHookId}`(runId)`, and it ends with an ordinary
|
|
17
|
+
* `hook_disposed`. Anything that rebuilds Hooks from the log has to seed the
|
|
18
|
+
* start Hook from here, or it drops the Hook and every delivery to it.
|
|
19
|
+
*/
|
|
20
|
+
export interface StartHookCreation {
|
|
21
|
+
hookId: string;
|
|
22
|
+
runId: string;
|
|
23
|
+
token?: string;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function eventTimestamp(event: Event | undefined): Date | undefined {
|
|
28
|
+
const value = event?.occurredAt ?? event?.createdAt;
|
|
29
|
+
if (!value) return undefined;
|
|
30
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
31
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function tokenOf(startHook: unknown): string | undefined {
|
|
35
|
+
if (!startHook || typeof startHook !== 'object') return undefined;
|
|
36
|
+
const { token } = startHook as { token?: unknown };
|
|
37
|
+
return typeof token === 'string' && token.length > 0 ? token : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The run's start Hook, or `undefined` for a run started without one.
|
|
42
|
+
*
|
|
43
|
+
* Read from the creation event's `eventData.startHook`, falling back to
|
|
44
|
+
* `run.startHook`. Events listed without their data still identify the start
|
|
45
|
+
* Hook by its id, so a run whose log holds an event for
|
|
46
|
+
* {@link startHookId}`(runId)` has one even when no token is known.
|
|
47
|
+
*/
|
|
48
|
+
export function findStartHookCreation(
|
|
49
|
+
events: readonly Event[],
|
|
50
|
+
run?: Pick<WorkflowRun, 'runId' | 'createdAt'> & { startHook?: unknown }
|
|
51
|
+
): StartHookCreation | undefined {
|
|
52
|
+
const creationEvent = events.find(isRunCreationEvent);
|
|
53
|
+
const runId = run?.runId ?? creationEvent?.runId ?? events[0]?.runId;
|
|
54
|
+
if (!runId?.startsWith('wrun_') || runId.length <= 'wrun_'.length) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const hookId = startHookId(runId);
|
|
58
|
+
const token =
|
|
59
|
+
tokenOf(
|
|
60
|
+
creationEvent && 'eventData' in creationEvent
|
|
61
|
+
? (creationEvent.eventData as { startHook?: unknown } | undefined)
|
|
62
|
+
?.startHook
|
|
63
|
+
: undefined
|
|
64
|
+
) ?? tokenOf(run?.startHook);
|
|
65
|
+
const hookEvents = events.filter(
|
|
66
|
+
(event) =>
|
|
67
|
+
event.correlationId === hookId &&
|
|
68
|
+
isHookLifecycleEventType(event.eventType)
|
|
69
|
+
);
|
|
70
|
+
if (token === undefined && hookEvents.length === 0) return undefined;
|
|
71
|
+
// `hook_created` for a start Hook's id is refused by every World, so one in
|
|
72
|
+
// the log means this is not a start Hook after all.
|
|
73
|
+
if (hookEvents.some((event) => event.eventType === 'hook_created')) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const createdAt =
|
|
77
|
+
eventTimestamp(creationEvent) ??
|
|
78
|
+
(run?.createdAt ? new Date(run.createdAt) : undefined) ??
|
|
79
|
+
eventTimestamp(hookEvents[0]);
|
|
80
|
+
if (!createdAt) return undefined;
|
|
81
|
+
return { hookId, runId, token, createdAt };
|
|
82
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shows the actual values of frozen state stored by reference.
|
|
3
|
+
*
|
|
4
|
+
* A step input can be a reference to frozen state an earlier step
|
|
5
|
+
* stored, and a step output only its change from that state.
|
|
6
|
+
* Rebuilding them needs the run's earlier payloads. A run state hydrator reads
|
|
7
|
+
* them once, only when a hydrated value needs them, and reuses them for every
|
|
8
|
+
* later inspection of the run.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
createStateResolver,
|
|
13
|
+
decodePayloadWithKey,
|
|
14
|
+
deriveRunPayloadKeys,
|
|
15
|
+
type StateResolver,
|
|
16
|
+
stateSourceId,
|
|
17
|
+
} from '@workflow/core/serialization-format';
|
|
18
|
+
import { getWebRevivers, hydrateResourceIOAsync } from './hydration';
|
|
19
|
+
|
|
20
|
+
/** One page of a run's events, oldest first, with their data. */
|
|
21
|
+
export interface StateHistoryPage {
|
|
22
|
+
data: readonly unknown[];
|
|
23
|
+
cursor?: string | null;
|
|
24
|
+
hasMore?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RunStateHydratorOptions {
|
|
28
|
+
/** The run's `input`, as stored (`resolveData: 'all'`). */
|
|
29
|
+
loadRunInput: () => Promise<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* A page of the run's events in ascending order, with their data, starting
|
|
32
|
+
* after `cursor` (or at the start without one).
|
|
33
|
+
*/
|
|
34
|
+
loadEvents: (cursor: string | undefined) => Promise<StateHistoryPage>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface RunStateHydrator {
|
|
38
|
+
/**
|
|
39
|
+
* Like `hydrateResourceIOAsync`, but also rebuilds frozen state values,
|
|
40
|
+
* reading the run's history the first time a value needs it.
|
|
41
|
+
*/
|
|
42
|
+
hydrate<T>(resource: T, key?: Uint8Array): Promise<T>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type Dict = Record<string, unknown>;
|
|
46
|
+
|
|
47
|
+
/** Like the runtime's cold recovery, never read more than this many pages per read. */
|
|
48
|
+
const MAX_PAGES = 1000;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The payload of an event that frozen state values can build on, and the
|
|
52
|
+
* id later state refers to its strings by (hook payloads only).
|
|
53
|
+
*/
|
|
54
|
+
function stateSourceOf(
|
|
55
|
+
event: unknown
|
|
56
|
+
): { value: unknown; source?: string } | undefined {
|
|
57
|
+
if (event === null || typeof event !== 'object') return undefined;
|
|
58
|
+
const { eventType, eventData, eventId } = event as Dict;
|
|
59
|
+
if (eventData === null || typeof eventData !== 'object') return undefined;
|
|
60
|
+
if (eventType === 'hook_received')
|
|
61
|
+
return {
|
|
62
|
+
value: (eventData as Dict).payload,
|
|
63
|
+
source: stateSourceId({
|
|
64
|
+
eventType,
|
|
65
|
+
eventId: typeof eventId === 'string' ? eventId : undefined,
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
if (eventType === 'step_completed')
|
|
69
|
+
return { value: (eventData as Dict).result };
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Creates the state hydrator for one run. Keep it for as long as the run is on
|
|
75
|
+
* screen and hydrate every resource of the run through it.
|
|
76
|
+
*/
|
|
77
|
+
export function createRunStateHydrator(
|
|
78
|
+
options: RunStateHydratorOptions
|
|
79
|
+
): RunStateHydrator {
|
|
80
|
+
// A different key can open different payloads, so each key gets its own.
|
|
81
|
+
let state:
|
|
82
|
+
| {
|
|
83
|
+
key: Uint8Array | undefined;
|
|
84
|
+
resolver: StateResolver;
|
|
85
|
+
cursor: string | undefined;
|
|
86
|
+
startedInput: boolean;
|
|
87
|
+
seen: Set<string>;
|
|
88
|
+
/** Set once the whole history has been read. */
|
|
89
|
+
complete: boolean;
|
|
90
|
+
reading: Promise<void> | undefined;
|
|
91
|
+
}
|
|
92
|
+
| undefined;
|
|
93
|
+
|
|
94
|
+
const stateFor = (key: Uint8Array | undefined) => {
|
|
95
|
+
if (!state || state.key !== key)
|
|
96
|
+
state = {
|
|
97
|
+
key,
|
|
98
|
+
resolver: createStateResolver(getWebRevivers()),
|
|
99
|
+
cursor: undefined,
|
|
100
|
+
startedInput: false,
|
|
101
|
+
seen: new Set(),
|
|
102
|
+
complete: false,
|
|
103
|
+
reading: undefined,
|
|
104
|
+
};
|
|
105
|
+
return state;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const add = async (
|
|
109
|
+
resolver: StateResolver,
|
|
110
|
+
value: unknown,
|
|
111
|
+
key: Awaited<ReturnType<typeof deriveRunPayloadKeys>> | undefined,
|
|
112
|
+
source?: string
|
|
113
|
+
) => {
|
|
114
|
+
if (value === undefined || value === null) return;
|
|
115
|
+
try {
|
|
116
|
+
resolver.add(await decodePayloadWithKey(value, key), source);
|
|
117
|
+
} catch {
|
|
118
|
+
// A payload that cannot be read leaves the values built on it as
|
|
119
|
+
// placeholders.
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Reads the events added since the last read, in log order, a page at a
|
|
125
|
+
* time, until `resolved` says the value being inspected no longer needs
|
|
126
|
+
* more. Inspecting an early step reads only the start of a long run, and
|
|
127
|
+
* the next inspection continues from there.
|
|
128
|
+
*/
|
|
129
|
+
const readHistory = async (
|
|
130
|
+
current: NonNullable<typeof state>,
|
|
131
|
+
resolved: () => Promise<boolean>
|
|
132
|
+
) => {
|
|
133
|
+
const key = current.key
|
|
134
|
+
? await deriveRunPayloadKeys(current.key)
|
|
135
|
+
: undefined;
|
|
136
|
+
if (!current.startedInput) {
|
|
137
|
+
// The run input only supplies strings later state may refer to; a run
|
|
138
|
+
// whose input can't be read still rebuilds everything else.
|
|
139
|
+
await add(
|
|
140
|
+
current.resolver,
|
|
141
|
+
await options.loadRunInput().catch(() => undefined),
|
|
142
|
+
key,
|
|
143
|
+
stateSourceId('run-input')
|
|
144
|
+
);
|
|
145
|
+
current.startedInput = true;
|
|
146
|
+
}
|
|
147
|
+
// A cursor that repeats would otherwise loop forever in the browser.
|
|
148
|
+
const cursors = new Set<string>();
|
|
149
|
+
for (let pages = 0; pages < MAX_PAGES; pages++) {
|
|
150
|
+
const page = await options.loadEvents(current.cursor);
|
|
151
|
+
for (const event of page.data) {
|
|
152
|
+
// A re-read from the last cursor can repeat events.
|
|
153
|
+
const id = (event as Dict | null)?.eventId;
|
|
154
|
+
if (typeof id === 'string') {
|
|
155
|
+
if (current.seen.has(id)) continue;
|
|
156
|
+
current.seen.add(id);
|
|
157
|
+
}
|
|
158
|
+
const payload = stateSourceOf(event);
|
|
159
|
+
if (payload)
|
|
160
|
+
await add(current.resolver, payload.value, key, payload.source);
|
|
161
|
+
}
|
|
162
|
+
if (page.cursor) current.cursor = page.cursor;
|
|
163
|
+
if (!page.hasMore) current.complete = true;
|
|
164
|
+
if (!page.hasMore || !page.cursor || cursors.has(page.cursor)) return;
|
|
165
|
+
cursors.add(page.cursor);
|
|
166
|
+
if (await resolved()) return;
|
|
167
|
+
// Let the page paint and respond between pages of a long run.
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
async hydrate(resource, key) {
|
|
174
|
+
const current = stateFor(key);
|
|
175
|
+
const missed = current.resolver.unresolved;
|
|
176
|
+
const hydrated = await hydrateResourceIOAsync(
|
|
177
|
+
resource,
|
|
178
|
+
key,
|
|
179
|
+
current.resolver.revivers
|
|
180
|
+
);
|
|
181
|
+
if (current.resolver.unresolved === missed) return hydrated;
|
|
182
|
+
// Whether what has been read so far rebuilds this resource.
|
|
183
|
+
const resolved = async () => {
|
|
184
|
+
const before = current.resolver.unresolved;
|
|
185
|
+
await hydrateResourceIOAsync(resource, key, current.resolver.revivers);
|
|
186
|
+
return current.resolver.unresolved === before;
|
|
187
|
+
};
|
|
188
|
+
// Concurrent inspections share one read. One started by another
|
|
189
|
+
// inspection may stop before this resource's records, so read on until
|
|
190
|
+
// this resource resolves or the history has been read to the end. Each
|
|
191
|
+
// pass reads at least one page, so this ends.
|
|
192
|
+
for (let pass = 0; pass < MAX_PAGES; pass++) {
|
|
193
|
+
const shared = current.reading !== undefined;
|
|
194
|
+
if (!current.reading)
|
|
195
|
+
current.reading = readHistory(current, resolved).finally(() => {
|
|
196
|
+
current.reading = undefined;
|
|
197
|
+
});
|
|
198
|
+
try {
|
|
199
|
+
await current.reading;
|
|
200
|
+
} catch {
|
|
201
|
+
return hydrated;
|
|
202
|
+
}
|
|
203
|
+
if (!shared || current.complete || (await resolved())) break;
|
|
204
|
+
}
|
|
205
|
+
return hydrateResourceIOAsync(resource, key, current.resolver.revivers);
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const ascii = (text: string) => Array.from(text, (char) => char.charCodeAt(0));
|
|
2
|
+
|
|
3
|
+
const PNG = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
4
|
+
const JPEG = [0xff, 0xd8, 0xff];
|
|
5
|
+
const GIF87A = ascii('GIF87a');
|
|
6
|
+
const GIF89A = ascii('GIF89a');
|
|
7
|
+
const RIFF = ascii('RIFF');
|
|
8
|
+
const WEBP = ascii('WEBP');
|
|
9
|
+
|
|
10
|
+
/** Raster image signatures; stream names and caller-supplied types are untrusted. */
|
|
11
|
+
export function getStreamImageType(data: Uint8Array): string | null {
|
|
12
|
+
// Compare raw bytes: a WebP's RIFF size field (bytes 4-7) is binary and
|
|
13
|
+
// can form multi-byte UTF-8, so decoding the header as text misaligns it.
|
|
14
|
+
const matches = (signature: number[], offset = 0) =>
|
|
15
|
+
signature.every((byte, index) => data[offset + index] === byte);
|
|
16
|
+
if (matches(PNG)) return 'image/png';
|
|
17
|
+
if (matches(JPEG)) return 'image/jpeg';
|
|
18
|
+
if (matches(GIF87A) || matches(GIF89A)) return 'image/gif';
|
|
19
|
+
if (matches(RIFF) && matches(WEBP, 8)) return 'image/webp';
|
|
20
|
+
return null;
|
|
21
|
+
}
|
package/src/lib/trace-builder.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import { otelTimeToMs } from '../components/workflow-traces/trace-time-utils';
|
|
26
26
|
import { findDuplicateEventIds } from './duplicate-events';
|
|
27
27
|
import { isSealedNoopEvent } from './sealed-events';
|
|
28
|
+
import { findStartHookCreation, type StartHookCreation } from './start-hook';
|
|
28
29
|
import type { Span } from './trace-types';
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -58,6 +59,11 @@ export function filterSpanRawEvents(
|
|
|
58
59
|
return events.filter((e) => e.correlationId === spanId);
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
export function getEventSpanId(event: Event): string {
|
|
63
|
+
const { correlationId } = event;
|
|
64
|
+
return correlationId && !isRunLevelEvent(event) ? correlationId : event.runId;
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
// ---------------------------------------------------------------------------
|
|
62
68
|
// Event grouping
|
|
63
69
|
// ---------------------------------------------------------------------------
|
|
@@ -139,6 +145,7 @@ function buildSpans(
|
|
|
139
145
|
groupedEvents: GroupedEvents,
|
|
140
146
|
now: Date,
|
|
141
147
|
latestKnownTime: Date,
|
|
148
|
+
startHook: StartHookCreation | undefined,
|
|
142
149
|
getStepAttributes?: GetStepAttributes
|
|
143
150
|
) {
|
|
144
151
|
// Active child spans cap at latestKnownTime so they don't extend into
|
|
@@ -151,8 +158,20 @@ function buildSpans(
|
|
|
151
158
|
.map((events) => stepToSpan(events, childMaxEnd, getStepAttributes))
|
|
152
159
|
.filter((span): span is Span => span !== null);
|
|
153
160
|
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
// A start Hook exists from the run's creation, before (and whether or not)
|
|
162
|
+
// anything is delivered to it, and has no `hook_created` of its own.
|
|
163
|
+
const hookEventGroups = new Map(groupedEvents.hookEvents);
|
|
164
|
+
if (startHook && !hookEventGroups.has(startHook.hookId)) {
|
|
165
|
+
hookEventGroups.set(startHook.hookId, []);
|
|
166
|
+
}
|
|
167
|
+
const hookSpans = Array.from(hookEventGroups)
|
|
168
|
+
.map(([hookId, events]) =>
|
|
169
|
+
hookToSpan(
|
|
170
|
+
events,
|
|
171
|
+
childMaxEnd,
|
|
172
|
+
hookId === startHook?.hookId ? startHook : undefined
|
|
173
|
+
)
|
|
174
|
+
)
|
|
156
175
|
.filter((span): span is Span => span !== null);
|
|
157
176
|
|
|
158
177
|
const waitSpans = Array.from(groupedEvents.timerEvents.values())
|
|
@@ -241,6 +260,7 @@ export function buildTrace(
|
|
|
241
260
|
groupedEvents,
|
|
242
261
|
now,
|
|
243
262
|
latestKnownTime,
|
|
263
|
+
findStartHookCreation(actedOnEvents, run),
|
|
244
264
|
getStepAttributes
|
|
245
265
|
);
|
|
246
266
|
const sortedCascadingSpans = cascadeSpans(runSpan, spans);
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { Event } from '@workflow/world';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { buildNameMaps } from './event-list-view';
|
|
4
|
-
|
|
5
|
-
function event(
|
|
6
|
-
eventType: Event['eventType'],
|
|
7
|
-
correlationId: string,
|
|
8
|
-
eventData: Record<string, unknown>
|
|
9
|
-
): Event {
|
|
10
|
-
return {
|
|
11
|
-
eventId: `evt_${eventType}_${correlationId}`,
|
|
12
|
-
runId: 'run_1',
|
|
13
|
-
eventType,
|
|
14
|
-
correlationId,
|
|
15
|
-
createdAt: new Date(0),
|
|
16
|
-
eventData,
|
|
17
|
-
} as unknown as Event;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe('buildNameMaps', () => {
|
|
21
|
-
it('names a step whose creation is recorded on its step_started', () => {
|
|
22
|
-
const { correlationNameMap } = buildNameMaps(
|
|
23
|
-
[
|
|
24
|
-
event('step_started', 'step_a', {
|
|
25
|
-
stepName: 'step//src/billing.ts//fetchInvoices',
|
|
26
|
-
}),
|
|
27
|
-
],
|
|
28
|
-
null
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(correlationNameMap.get('step_a')).toBe('fetchInvoices');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('prefers the step_created name in either list order', () => {
|
|
35
|
-
const created = event('step_created', 'step_a', {
|
|
36
|
-
stepName: 'step//src/billing.ts//fetchInvoices',
|
|
37
|
-
input: null,
|
|
38
|
-
});
|
|
39
|
-
const started = event('step_started', 'step_a', {
|
|
40
|
-
stepName: 'step//src/billing.ts//somethingElse',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
for (const events of [
|
|
44
|
-
[created, started],
|
|
45
|
-
[started, created],
|
|
46
|
-
]) {
|
|
47
|
-
const { correlationNameMap } = buildNameMaps(events, null);
|
|
48
|
-
expect(correlationNameMap.get('step_a')).toBe('fetchInvoices');
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
clampPanelWidth,
|
|
4
|
-
computeMaxPanelWidth,
|
|
5
|
-
MAIN_MIN_WIDTH,
|
|
6
|
-
PANEL_DEFAULT_WIDTH,
|
|
7
|
-
PANEL_HARD_MAX_WIDTH,
|
|
8
|
-
PANEL_MIN_WIDTH,
|
|
9
|
-
PANEL_WIDTH_STORAGE_KEY,
|
|
10
|
-
readStoredPanelWidth,
|
|
11
|
-
writeStoredPanelWidth,
|
|
12
|
-
} from './detail-panel-width';
|
|
13
|
-
|
|
14
|
-
function stubLocalStorage(overrides: Partial<Storage> = {}) {
|
|
15
|
-
const storage = {
|
|
16
|
-
getItem: vi.fn().mockReturnValue(null),
|
|
17
|
-
setItem: vi.fn(),
|
|
18
|
-
...overrides,
|
|
19
|
-
};
|
|
20
|
-
vi.stubGlobal('window', { localStorage: storage });
|
|
21
|
-
return storage;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
vi.unstubAllGlobals();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('computeMaxPanelWidth', () => {
|
|
29
|
-
it('falls back to the hard max when the container is unmeasured', () => {
|
|
30
|
-
expect(computeMaxPanelWidth(0)).toBe(PANEL_HARD_MAX_WIDTH);
|
|
31
|
-
expect(computeMaxPanelWidth(-5)).toBe(PANEL_HARD_MAX_WIDTH);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('reserves the main-area minimum', () => {
|
|
35
|
-
expect(computeMaxPanelWidth(1000)).toBe(1000 - MAIN_MIN_WIDTH);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('caps at the hard max on very wide containers', () => {
|
|
39
|
-
expect(computeMaxPanelWidth(5000)).toBe(PANEL_HARD_MAX_WIDTH);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('bottoms out at 0 when the container is smaller than the main minimum', () => {
|
|
43
|
-
expect(computeMaxPanelWidth(MAIN_MIN_WIDTH - 50)).toBe(0);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('clampPanelWidth', () => {
|
|
48
|
-
it('passes through widths within bounds', () => {
|
|
49
|
-
expect(clampPanelWidth(360, 1000)).toBe(360);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('clamps to the panel minimum', () => {
|
|
53
|
-
expect(clampPanelWidth(100, 1000)).toBe(PANEL_MIN_WIDTH);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('clamps to the container-relative maximum', () => {
|
|
57
|
-
expect(clampPanelWidth(900, 1000)).toBe(1000 - MAIN_MIN_WIDTH);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('lets the max win below the crossover so the panel gives way, not the main area', () => {
|
|
61
|
-
// Container too small for both floors: panel compresses below its own min.
|
|
62
|
-
const available = PANEL_MIN_WIDTH + MAIN_MIN_WIDTH - 100;
|
|
63
|
-
expect(clampPanelWidth(360, available)).toBe(available - MAIN_MIN_WIDTH);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('readStoredPanelWidth', () => {
|
|
68
|
-
it('returns the default when window is unavailable (SSR)', () => {
|
|
69
|
-
expect(readStoredPanelWidth()).toBe(PANEL_DEFAULT_WIDTH);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('returns the stored value when valid', () => {
|
|
73
|
-
stubLocalStorage({ getItem: vi.fn().mockReturnValue('512') });
|
|
74
|
-
expect(readStoredPanelWidth()).toBe(512);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('returns the default for missing or unparseable values', () => {
|
|
78
|
-
stubLocalStorage({ getItem: vi.fn().mockReturnValue(null) });
|
|
79
|
-
expect(readStoredPanelWidth()).toBe(PANEL_DEFAULT_WIDTH);
|
|
80
|
-
stubLocalStorage({ getItem: vi.fn().mockReturnValue('not-a-number') });
|
|
81
|
-
expect(readStoredPanelWidth()).toBe(PANEL_DEFAULT_WIDTH);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('clamps stored values to absolute bounds only', () => {
|
|
85
|
-
stubLocalStorage({ getItem: vi.fn().mockReturnValue('-20') });
|
|
86
|
-
expect(readStoredPanelWidth()).toBe(PANEL_MIN_WIDTH);
|
|
87
|
-
stubLocalStorage({ getItem: vi.fn().mockReturnValue('99999') });
|
|
88
|
-
expect(readStoredPanelWidth()).toBe(PANEL_HARD_MAX_WIDTH);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('returns the default when storage access throws', () => {
|
|
92
|
-
stubLocalStorage({
|
|
93
|
-
getItem: vi.fn().mockImplementation(() => {
|
|
94
|
-
throw new Error('denied');
|
|
95
|
-
}),
|
|
96
|
-
});
|
|
97
|
-
expect(readStoredPanelWidth()).toBe(PANEL_DEFAULT_WIDTH);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('writeStoredPanelWidth', () => {
|
|
102
|
-
it('is a no-op when window is unavailable (SSR)', () => {
|
|
103
|
-
expect(() => writeStoredPanelWidth(400)).not.toThrow();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('rounds and writes the value', () => {
|
|
107
|
-
const storage = stubLocalStorage();
|
|
108
|
-
writeStoredPanelWidth(412.6);
|
|
109
|
-
expect(storage.setItem).toHaveBeenCalledWith(
|
|
110
|
-
PANEL_WIDTH_STORAGE_KEY,
|
|
111
|
-
'413'
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('swallows storage errors (private mode, quota)', () => {
|
|
116
|
-
stubLocalStorage({
|
|
117
|
-
setItem: vi.fn().mockImplementation(() => {
|
|
118
|
-
throw new Error('quota');
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
expect(() => writeStoredPanelWidth(400)).not.toThrow();
|
|
122
|
-
});
|
|
123
|
-
});
|