@outputai/cli 0.17.1-next.78fc808.0 → 0.18.0
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/dist/assets/docker/docker-compose-dev.yml +1 -1
- package/dist/commands/workflow/dataset/generate.d.ts +8 -6
- package/dist/commands/workflow/dataset/generate.js +46 -80
- package/dist/commands/workflow/dataset/generate.spec.js +154 -83
- package/dist/commands/workflow/debug.d.ts +8 -3
- package/dist/commands/workflow/debug.js +35 -25
- package/dist/commands/workflow/debug.spec.js +76 -22
- package/dist/commands/workflow/test.js +0 -3
- package/dist/commands/workflow/test.spec.js +19 -0
- package/dist/generated/framework_version.json +1 -1
- package/dist/services/datasets.d.ts +1 -3
- package/dist/services/datasets.js +1 -19
- package/dist/services/datasets.test.js +45 -3
- package/dist/services/temporal_client.d.ts +50 -0
- package/dist/services/temporal_client.js +84 -0
- package/dist/services/temporal_client.spec.d.ts +1 -0
- package/dist/services/temporal_client.spec.js +129 -0
- package/dist/services/workflow_debug.d.ts +68 -0
- package/dist/services/workflow_debug.js +273 -0
- package/dist/services/workflow_debug.spec.d.ts +1 -0
- package/dist/services/workflow_debug.spec.js +363 -0
- package/dist/services/workflow_run_data.d.ts +26 -0
- package/dist/services/workflow_run_data.js +67 -0
- package/dist/services/workflow_run_data.spec.d.ts +1 -0
- package/dist/services/workflow_run_data.spec.js +190 -0
- package/dist/types/trace.d.ts +1 -73
- package/dist/types/trace.js +1 -12
- package/dist/utils/payload_truncator.d.ts +23 -0
- package/dist/utils/payload_truncator.js +92 -0
- package/dist/utils/payload_truncator.spec.d.ts +1 -0
- package/dist/utils/payload_truncator.spec.js +51 -0
- package/dist/utils/temporal_flags.d.ts +14 -0
- package/dist/utils/temporal_flags.js +16 -0
- package/oclif.manifest.json +80 -36
- package/package.json +10 -2
- package/dist/utils/trace_extractor.d.ts +0 -27
- package/dist/utils/trace_extractor.js +0 -53
- package/dist/utils/trace_formatter.d.ts +0 -11
- package/dist/utils/trace_formatter.js +0 -401
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { WorkflowNotFoundError } from '@temporalio/client';
|
|
2
|
+
import { defaultPayloadConverter } from '@temporalio/common';
|
|
3
|
+
import { historyToJSON, JSONToPayload } from '@temporalio/common/lib/proto-utils.js';
|
|
4
|
+
import { callTemporal } from '#services/temporal_client.js';
|
|
5
|
+
import { truncateStack, truncateValue } from '#utils/payload_truncator.js';
|
|
6
|
+
const PAGE_SIZE = 1000;
|
|
7
|
+
const DEFAULT_PAGE_BUDGET = 1000;
|
|
8
|
+
const DEFAULT_EVENT_BUDGET = 100_000;
|
|
9
|
+
const DEFAULT_CONCURRENCY = 5;
|
|
10
|
+
const GRPC_NOT_FOUND = 5;
|
|
11
|
+
const CLOSING_EVENT = /^EVENT_TYPE_WORKFLOW_EXECUTION_(COMPLETED|FAILED|TIMED_OUT|CANCELED|TERMINATED|CONTINUED_AS_NEW)$/;
|
|
12
|
+
const RUNNING_STATUS = 'WORKFLOW_EXECUTION_STATUS_RUNNING';
|
|
13
|
+
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
14
|
+
const isPayload = (value) => {
|
|
15
|
+
if (!isObject(value) || !Object.keys(value).every(key => key === 'metadata' || key === 'data')) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return isObject(value.metadata) && typeof value.metadata.encoding === 'string';
|
|
19
|
+
};
|
|
20
|
+
const decodePayload = (payload) => {
|
|
21
|
+
try {
|
|
22
|
+
const decoded = defaultPayloadConverter.fromPayload(JSONToPayload(payload));
|
|
23
|
+
return decoded instanceof Uint8Array ? `[Binary Payload: ${decoded.byteLength} bytes]` : decoded;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
const encoding = Buffer.from(payload.metadata?.encoding ?? '', 'base64').toString();
|
|
27
|
+
return `[Undecodable Payload: ${encoding}]`;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Walks Temporal's JSON for an event (or any message) and replaces every payload with its decoded, truncated value.
|
|
32
|
+
* Everything else keeps Temporal's own shape; only stack traces are cut to their first lines.
|
|
33
|
+
*
|
|
34
|
+
* @param node - Value from Temporal's JSON
|
|
35
|
+
* @returns A copy with decoded payloads
|
|
36
|
+
*/
|
|
37
|
+
export const decodeNode = (node) => {
|
|
38
|
+
if (isPayload(node)) {
|
|
39
|
+
return truncateValue(decodePayload(node));
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(node)) {
|
|
42
|
+
return node.map(decodeNode);
|
|
43
|
+
}
|
|
44
|
+
if (!isObject(node)) {
|
|
45
|
+
return node;
|
|
46
|
+
}
|
|
47
|
+
return Object.fromEntries(Object.entries(node).map(([key, value]) => [
|
|
48
|
+
key,
|
|
49
|
+
key === 'stackTrace' && typeof value === 'string' ? truncateStack(value) : decodeNode(value)
|
|
50
|
+
]));
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Orders events by their parsed server time. Compares seconds and nanos, since ISO strings with
|
|
54
|
+
* different fraction lengths do not sort as text.
|
|
55
|
+
*
|
|
56
|
+
* @param a - Timestamp key of the first event
|
|
57
|
+
* @param b - Timestamp key of the second event
|
|
58
|
+
* @returns Negative, zero or positive for sorting
|
|
59
|
+
*/
|
|
60
|
+
const compareByEventTime = (a, b) => {
|
|
61
|
+
if (a === b) {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
return a < b ? -1 : 1;
|
|
65
|
+
};
|
|
66
|
+
const buildTimeKey = (time) => (BigInt(String(time?.seconds ?? 0)) * 1000000000n) + BigInt(time?.nanos ?? 0);
|
|
67
|
+
/** Temporal responses are protobufjs messages; `toJSON` gives enum names and string ids */
|
|
68
|
+
const toJson = (message) => message?.toJSON?.() ?? {};
|
|
69
|
+
const isNotFound = (error) => error instanceof WorkflowNotFoundError || error?.code === GRPC_NOT_FOUND;
|
|
70
|
+
const fetchWorkflowMeta = async (client, workflowId, runId) => {
|
|
71
|
+
const description = await callTemporal(client, () => client.workflow.getHandle(workflowId, runId).describe());
|
|
72
|
+
const info = toJson(description.raw.workflowExecutionInfo);
|
|
73
|
+
return {
|
|
74
|
+
runId: description.runId,
|
|
75
|
+
workflowType: description.type,
|
|
76
|
+
status: info.status,
|
|
77
|
+
pendingActivities: (description.raw.pendingActivities ?? []).map(activity => {
|
|
78
|
+
const json = toJson(activity);
|
|
79
|
+
return decodeNode({
|
|
80
|
+
activityId: json.activityId,
|
|
81
|
+
activityType: json.activityType?.name,
|
|
82
|
+
state: json.state,
|
|
83
|
+
attempt: json.attempt,
|
|
84
|
+
lastFailure: json.lastFailure
|
|
85
|
+
});
|
|
86
|
+
}),
|
|
87
|
+
pendingChildren: (description.raw.pendingChildren ?? []).map(child => ({
|
|
88
|
+
workflowId: child.workflowId,
|
|
89
|
+
runId: child.runId,
|
|
90
|
+
workflowType: child.workflowTypeName
|
|
91
|
+
}))
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const fetchPage = async (client, target) => {
|
|
95
|
+
const response = await callTemporal(client, () => client.connection.workflowService.getWorkflowExecutionHistory({
|
|
96
|
+
namespace: client.options.namespace,
|
|
97
|
+
execution: { workflowId: target.entry.workflowId, runId: target.entry.runId },
|
|
98
|
+
maximumPageSize: PAGE_SIZE,
|
|
99
|
+
nextPageToken: target.nextPageToken
|
|
100
|
+
}));
|
|
101
|
+
const events = response.history?.events ?? [];
|
|
102
|
+
const json = (JSON.parse(historyToJSON({ events })).events ?? []);
|
|
103
|
+
const tagged = json.map((event, i) => Object.assign(event, { timeKey: buildTimeKey(events[i].eventTime) }));
|
|
104
|
+
return { events: tagged, nextPageToken: response.nextPageToken?.length ? response.nextPageToken : undefined };
|
|
105
|
+
};
|
|
106
|
+
const buildEntry = (ids, workflowType, parent) => ({
|
|
107
|
+
workflowId: ids.workflowId,
|
|
108
|
+
runId: ids.runId,
|
|
109
|
+
workflowType,
|
|
110
|
+
status: null,
|
|
111
|
+
...(parent ? { parent } : {}),
|
|
112
|
+
pendingActivities: [],
|
|
113
|
+
pendingChildren: [],
|
|
114
|
+
events: []
|
|
115
|
+
});
|
|
116
|
+
const findChildren = (events, parent) => events.flatMap(event => {
|
|
117
|
+
const attributes = event.childWorkflowExecutionStartedEventAttributes;
|
|
118
|
+
const execution = attributes?.workflowExecution;
|
|
119
|
+
if (!execution?.workflowId || !execution?.runId) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const { workflowId, runId } = parent.entry;
|
|
123
|
+
return [{
|
|
124
|
+
entry: buildEntry(execution, attributes.workflowType?.name ?? '', { workflowId, runId }),
|
|
125
|
+
startKey: event.timeKey
|
|
126
|
+
}];
|
|
127
|
+
});
|
|
128
|
+
/**
|
|
129
|
+
* When a run continues as new, the next run is read as its own entry (same workflow id, new run id, same parent, if any),
|
|
130
|
+
* ordered by the time the previous run continued. A parent's events name only the first run of a child, so this is also
|
|
131
|
+
* how the rest of a child's runs are found. Runs share the page and event budgets with everything else.
|
|
132
|
+
*/
|
|
133
|
+
const findContinuation = (events, target) => events.flatMap(event => {
|
|
134
|
+
const runId = event.workflowExecutionContinuedAsNewEventAttributes?.newExecutionRunId;
|
|
135
|
+
if (!runId) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
const { workflowId, workflowType, parent } = target.entry;
|
|
139
|
+
return [{ entry: buildEntry({ workflowId, runId }, workflowType, parent), startKey: event.timeKey }];
|
|
140
|
+
});
|
|
141
|
+
const formatWorkflowLabel = ({ parent }) => (parent ? 'Child workflow' : 'Workflow');
|
|
142
|
+
const formatReason = (error) => (error instanceof Error ? error.message : String(error));
|
|
143
|
+
const formatWarning = {
|
|
144
|
+
unavailable: (entry) => [
|
|
145
|
+
`${formatWorkflowLabel(entry)} ${entry.workflowId} (run ${entry.runId}) is no longer in Temporal:`,
|
|
146
|
+
'closed histories are deleted after the namespace retention period. Its entry has no events.'
|
|
147
|
+
].join(' '),
|
|
148
|
+
notRead: (entry, limit) => [
|
|
149
|
+
`${formatWorkflowLabel(entry)} ${entry.workflowId} (run ${entry.runId}) was not read:`,
|
|
150
|
+
`the limit of ${limit} for the whole tree was reached. Its entry has no events.`
|
|
151
|
+
].join(' '),
|
|
152
|
+
failed: (entry, error) => {
|
|
153
|
+
return [
|
|
154
|
+
`${formatWorkflowLabel(entry)} ${entry.workflowId} (run ${entry.runId}) could not be read: ${formatReason(error)}.`,
|
|
155
|
+
entry.events.length ? 'Its entry has the events read so far.' : 'Its entry has no events.'
|
|
156
|
+
].join(' ');
|
|
157
|
+
},
|
|
158
|
+
closedWhileReading: (entry) => [
|
|
159
|
+
`${formatWorkflowLabel(entry)} ${entry.workflowId} (run ${entry.runId}) finished while it was being read:`,
|
|
160
|
+
'its events stop before the end. Run the command again.'
|
|
161
|
+
].join(' '),
|
|
162
|
+
noStatus: (entry, error) => [
|
|
163
|
+
`${formatWorkflowLabel(entry)} ${entry.workflowId} (run ${entry.runId}) could not be described: ${formatReason(error)}.`,
|
|
164
|
+
'Its status and pending lists may be missing or out of date.'
|
|
165
|
+
].join(' '),
|
|
166
|
+
partial: (entry, limit) => [
|
|
167
|
+
`${formatWorkflowLabel(entry)} ${entry.workflowId} (run ${entry.runId}) was read only in part:`,
|
|
168
|
+
`the limit of ${limit} for the whole tree was reached. Its entry has the events read so far.`
|
|
169
|
+
].join(' ')
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Reads one workflow run from Temporal, with every child it started and every run that continues from it.
|
|
173
|
+
* The result has one entry per run.
|
|
174
|
+
* Events keep Temporal's default JSON form with payloads decoded and truncated, and nothing added.
|
|
175
|
+
* The status and pending lists are described after every history was read, so they are never older than the events.
|
|
176
|
+
* Paging is breadth-first under one page budget and one event budget for the whole tree. A failure on the requested run's first page throws;
|
|
177
|
+
* any other read failure becomes a warning and the entry keeps what was read.
|
|
178
|
+
*
|
|
179
|
+
* @param client - Temporal client
|
|
180
|
+
* @param params - What to read and where it lives
|
|
181
|
+
* @param params.address - Address the client uses, echoed in the result
|
|
182
|
+
* @param params.namespace - Namespace the client uses, echoed in the result
|
|
183
|
+
* @param params.workflowId - Workflow to read
|
|
184
|
+
* @param params.runId - Run to start from; the latest run when omitted
|
|
185
|
+
* @param options - Page budget, event budget and concurrency
|
|
186
|
+
* @returns The workflow entries, plus `complete` and the warnings for anything that was left out
|
|
187
|
+
*/
|
|
188
|
+
export async function collectWorkflowDebug(client, params, options = {}) {
|
|
189
|
+
const { pageBudget = DEFAULT_PAGE_BUDGET, eventBudget = DEFAULT_EVENT_BUDGET, concurrency = DEFAULT_CONCURRENCY } = options;
|
|
190
|
+
const { runId: rootRunId, ...rootMeta } = await fetchWorkflowMeta(client, params.workflowId, params.runId);
|
|
191
|
+
const root = {
|
|
192
|
+
entry: Object.assign(buildEntry({ workflowId: params.workflowId, runId: rootRunId }, rootMeta.workflowType), rootMeta),
|
|
193
|
+
startKey: 0n
|
|
194
|
+
};
|
|
195
|
+
const unstarted = [root];
|
|
196
|
+
const inProgress = [];
|
|
197
|
+
const children = [];
|
|
198
|
+
const seen = new Set([`${params.workflowId}/${rootRunId}`]);
|
|
199
|
+
const warnings = [];
|
|
200
|
+
const progress = { pagesRead: 0, eventsRead: 0 };
|
|
201
|
+
const failed = new Set();
|
|
202
|
+
const readPage = async (target) => fetchPage(client, target).catch((error) => ({ error }));
|
|
203
|
+
while ((unstarted.length || inProgress.length) && progress.pagesRead < pageBudget && progress.eventsRead < eventBudget) {
|
|
204
|
+
const room = Math.min(concurrency, pageBudget - progress.pagesRead);
|
|
205
|
+
// Every child gets its first page before any history gets a second one
|
|
206
|
+
const first = unstarted.splice(0, room);
|
|
207
|
+
const next = inProgress.splice(0, room - first.length);
|
|
208
|
+
progress.pagesRead += first.length + next.length;
|
|
209
|
+
const results = await Promise.all([...first, ...next].map(readPage));
|
|
210
|
+
[...first, ...next].forEach((target, i) => {
|
|
211
|
+
const result = results[i];
|
|
212
|
+
if ('error' in result) {
|
|
213
|
+
// Nothing can be shown without the first page of the requested run
|
|
214
|
+
if (target === root && !target.nextPageToken) {
|
|
215
|
+
throw result.error;
|
|
216
|
+
}
|
|
217
|
+
failed.add(target);
|
|
218
|
+
const isGone = isNotFound(result.error) && !target.entry.events.length;
|
|
219
|
+
warnings.push(isGone ? formatWarning.unavailable(target.entry) : formatWarning.failed(target.entry, result.error));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// The last page read is cut to what is left of the event budget
|
|
223
|
+
const kept = result.events.slice(0, eventBudget - progress.eventsRead);
|
|
224
|
+
const isCut = kept.length < result.events.length;
|
|
225
|
+
progress.eventsRead += kept.length;
|
|
226
|
+
target.entry.events.push(...kept.map(({ timeKey, ...event }) => decodeNode(event)));
|
|
227
|
+
const discovered = [...findChildren(kept, target), ...findContinuation(kept, target)];
|
|
228
|
+
for (const child of discovered) {
|
|
229
|
+
const key = `${child.entry.workflowId}/${child.entry.runId}`;
|
|
230
|
+
if (!seen.has(key)) {
|
|
231
|
+
seen.add(key);
|
|
232
|
+
unstarted.push(child);
|
|
233
|
+
children.push(child);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (isCut && !target.entry.events.length) {
|
|
237
|
+
unstarted.push(target);
|
|
238
|
+
}
|
|
239
|
+
else if (isCut || result.nextPageToken) {
|
|
240
|
+
inProgress.push(Object.assign(target, { nextPageToken: result.nextPageToken }));
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const unfinished = new Set([...failed, ...inProgress]);
|
|
245
|
+
const limit = progress.eventsRead >= eventBudget ? `${eventBudget} events` : `${pageBudget} pages`;
|
|
246
|
+
warnings.push(...unstarted.map(target => formatWarning.notRead(target.entry, limit)), ...inProgress.map(target => formatWarning.partial(target.entry, limit)));
|
|
247
|
+
// The description is read after the events, so it is never older than they are
|
|
248
|
+
const refresh = async (target) => {
|
|
249
|
+
try {
|
|
250
|
+
const meta = await fetchWorkflowMeta(client, target.entry.workflowId, target.entry.runId);
|
|
251
|
+
Object.assign(target.entry, meta);
|
|
252
|
+
const isClosed = Boolean(meta.status) && meta.status !== RUNNING_STATUS;
|
|
253
|
+
const isMissingEnd = !unfinished.has(target) && !target.entry.events.some(event => CLOSING_EVENT.test(event.eventType));
|
|
254
|
+
return isClosed && isMissingEnd ? formatWarning.closedWhileReading(target.entry) : undefined;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
return formatWarning.noStatus(target.entry, error);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const described = [root, ...children].filter(target => target.entry.events.length);
|
|
261
|
+
const batches = Array.from({ length: Math.ceil(described.length / concurrency) }, (_, i) => described.slice(i * concurrency, (i + 1) * concurrency));
|
|
262
|
+
for (const batch of batches) {
|
|
263
|
+
warnings.push(...(await Promise.all(batch.map(refresh))).filter((warning) => Boolean(warning)));
|
|
264
|
+
}
|
|
265
|
+
// Array.prototype.sort is stable: children reported at the same time keep their discovery order
|
|
266
|
+
const ordered = children.sort((a, b) => compareByEventTime(a.startKey, b.startKey));
|
|
267
|
+
return {
|
|
268
|
+
complete: warnings.length === 0,
|
|
269
|
+
warnings,
|
|
270
|
+
temporal: { address: params.address, namespace: params.namespace },
|
|
271
|
+
workflows: [root.entry, ...ordered.map(target => target.entry)]
|
|
272
|
+
};
|
|
273
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { collectWorkflowDebug, decodeNode } from './workflow_debug.js';
|
|
3
|
+
const encode = (encoding, data) => ({
|
|
4
|
+
metadata: { encoding: Buffer.from(encoding).toString('base64') },
|
|
5
|
+
...(data === undefined ? {} : { data: Buffer.from(data).toString('base64') })
|
|
6
|
+
});
|
|
7
|
+
const event = (eventId, seconds, nanos, extra = {}) => ({
|
|
8
|
+
eventId,
|
|
9
|
+
eventTime: { seconds, nanos },
|
|
10
|
+
eventType: 'EVENT_TYPE_TIMER_FIRED',
|
|
11
|
+
...extra
|
|
12
|
+
});
|
|
13
|
+
const childStarted = (eventId, seconds, nanos, workflowId, runId) => event(eventId, seconds, nanos, {
|
|
14
|
+
eventType: 'EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_STARTED',
|
|
15
|
+
childWorkflowExecutionStartedEventAttributes: { workflowExecution: { workflowId, runId }, workflowType: { name: 'child_type' } }
|
|
16
|
+
});
|
|
17
|
+
const continuedAsNew = (eventId, seconds, nanos, newExecutionRunId) => event(eventId, seconds, nanos, {
|
|
18
|
+
eventType: 'EVENT_TYPE_WORKFLOW_EXECUTION_CONTINUED_AS_NEW',
|
|
19
|
+
workflowExecutionContinuedAsNewEventAttributes: { newExecutionRunId }
|
|
20
|
+
});
|
|
21
|
+
const buildClient = (histories, statuses = {}, pending = {}) => {
|
|
22
|
+
const getWorkflowExecutionHistory = vi.fn(async ({ execution, nextPageToken }) => {
|
|
23
|
+
const history = histories[`${execution.workflowId}/${execution.runId}`] ?? histories[execution.workflowId];
|
|
24
|
+
if (history instanceof Error) {
|
|
25
|
+
throw history;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(history)) {
|
|
28
|
+
return { history: { events: history }, nextPageToken: new Uint8Array() };
|
|
29
|
+
}
|
|
30
|
+
const index = nextPageToken?.length ? Number(Buffer.from(nextPageToken).toString()) : 0;
|
|
31
|
+
const page = history.pages[index];
|
|
32
|
+
if (page instanceof Error) {
|
|
33
|
+
throw page;
|
|
34
|
+
}
|
|
35
|
+
const hasMore = index + 1 < history.pages.length;
|
|
36
|
+
return { history: { events: page }, nextPageToken: hasMore ? Buffer.from(String(index + 1)) : new Uint8Array() };
|
|
37
|
+
});
|
|
38
|
+
const withDeadline = vi.fn(async (_deadline, fn) => fn());
|
|
39
|
+
const client = {
|
|
40
|
+
options: { namespace: 'default' },
|
|
41
|
+
connection: { withDeadline, workflowService: { getWorkflowExecutionHistory } },
|
|
42
|
+
workflow: {
|
|
43
|
+
getHandle: (workflowId, runId) => ({
|
|
44
|
+
describe: async () => ({
|
|
45
|
+
workflowId,
|
|
46
|
+
runId: runId ?? 'run-root',
|
|
47
|
+
type: workflowId === 'root' ? 'root_type' : 'child_type',
|
|
48
|
+
raw: {
|
|
49
|
+
workflowExecutionInfo: { toJSON: () => ({ status: statuses[workflowId] ?? 'WORKFLOW_EXECUTION_STATUS_RUNNING' }) },
|
|
50
|
+
pendingActivities: pending[workflowId]?.pendingActivities ?? [],
|
|
51
|
+
pendingChildren: pending[workflowId]?.pendingChildren ?? []
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return { client, getWorkflowExecutionHistory, withDeadline };
|
|
58
|
+
};
|
|
59
|
+
const params = { address: 'localhost:7233', namespace: 'default', workflowId: 'root' };
|
|
60
|
+
describe('decodeNode', () => {
|
|
61
|
+
it('decodes json payloads and keeps the rest of Temporal\'s shape', () => {
|
|
62
|
+
const node = { activityTaskScheduledEventAttributes: { activityId: '5', input: { payloads: [encode('json/plain', '{"a":1}')] } } };
|
|
63
|
+
expect(decodeNode(node)).toEqual({ activityTaskScheduledEventAttributes: { activityId: '5', input: { payloads: [{ a: 1 }] } } });
|
|
64
|
+
});
|
|
65
|
+
it('cuts stack traces to their first lines wherever they appear', () => {
|
|
66
|
+
const stackTrace = Array.from({ length: 12 }, (_, i) => `at line ${i}`).join('\n');
|
|
67
|
+
const { failure } = decodeNode({ failure: { message: 'boom', stackTrace } });
|
|
68
|
+
expect(failure.message).toBe('boom');
|
|
69
|
+
expect(failure.stackTrace.split('\n')).toHaveLength(11);
|
|
70
|
+
expect(failure.stackTrace).toContain('... [2 more lines omitted]');
|
|
71
|
+
});
|
|
72
|
+
it('summarizes binary payloads instead of printing them', () => {
|
|
73
|
+
expect(decodeNode(encode('binary/plain', 'abc'))).toBe('[Binary Payload: 3 bytes]');
|
|
74
|
+
});
|
|
75
|
+
it('prints a marker for payloads it cannot decode', () => {
|
|
76
|
+
expect(decodeNode(encode('binary/encrypted', 'x'))).toBe('[Undecodable Payload: binary/encrypted]');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('collectWorkflowDebug', () => {
|
|
80
|
+
it('gives each workflow its own entry, root first, and adds nothing to the events', async () => {
|
|
81
|
+
const { client } = buildClient({
|
|
82
|
+
root: [event(1, 10, 0), childStarted(2, 20, 0, 'child', 'run-child'), event(3, 40, 0)],
|
|
83
|
+
child: [event(1, 30, 0)]
|
|
84
|
+
});
|
|
85
|
+
const result = await collectWorkflowDebug(client, params);
|
|
86
|
+
expect(result).toMatchObject({ complete: true, warnings: [], temporal: { address: 'localhost:7233', namespace: 'default' } });
|
|
87
|
+
expect(result.workflows.map(w => [w.workflowId, w.runId, w.workflowType])).toEqual([
|
|
88
|
+
['root', 'run-root', 'root_type'],
|
|
89
|
+
['child', 'run-child', 'child_type']
|
|
90
|
+
]);
|
|
91
|
+
expect(result.workflows[0]).not.toHaveProperty('parent');
|
|
92
|
+
expect(result.workflows[1].parent).toEqual({ workflowId: 'root', runId: 'run-root' });
|
|
93
|
+
expect(result.workflows[1].events).toEqual([{ eventId: '1', eventTime: expect.any(String), eventType: 'EVENT_TYPE_TIMER_FIRED' }]);
|
|
94
|
+
});
|
|
95
|
+
it('takes each child\'s status from its own description', async () => {
|
|
96
|
+
const { client } = buildClient({ root: [childStarted(1, 10, 0, 'child', 'run-child')], child: [event(1, 20, 0)] }, { root: 'WORKFLOW_EXECUTION_STATUS_RUNNING', child: 'WORKFLOW_EXECUTION_STATUS_FAILED' });
|
|
97
|
+
const { workflows } = await collectWorkflowDebug(client, params);
|
|
98
|
+
expect(workflows.map(w => w.status)).toEqual(['WORKFLOW_EXECUTION_STATUS_RUNNING', 'WORKFLOW_EXECUTION_STATUS_FAILED']);
|
|
99
|
+
});
|
|
100
|
+
it('orders children by the parsed time their parent reports them started, not by discovery or ISO text', async () => {
|
|
101
|
+
const { client } = buildClient({
|
|
102
|
+
root: [childStarted(1, 10, 500_000_000, 'late', 'run-late'), childStarted(2, 10, 0, 'early', 'run-early')],
|
|
103
|
+
late: [event(1, 20, 0)],
|
|
104
|
+
early: [event(1, 20, 0)]
|
|
105
|
+
});
|
|
106
|
+
const { workflows } = await collectWorkflowDebug(client, params);
|
|
107
|
+
expect(workflows.map(w => w.workflowId)).toEqual(['root', 'early', 'late']);
|
|
108
|
+
});
|
|
109
|
+
it('warns about a child whose history is gone, keeps its entry empty and still succeeds', async () => {
|
|
110
|
+
const notFound = Object.assign(new Error('not found'), { code: 5 });
|
|
111
|
+
const { client } = buildClient({ root: [childStarted(1, 10, 0, 'child', 'run-child')], child: notFound });
|
|
112
|
+
const result = await collectWorkflowDebug(client, params);
|
|
113
|
+
expect(result.complete).toBe(false);
|
|
114
|
+
expect(result.warnings).toHaveLength(1);
|
|
115
|
+
expect(result.warnings[0]).toContain('child (run run-child)');
|
|
116
|
+
expect(result.workflows[1]).toMatchObject({ workflowId: 'child', workflowType: 'child_type', status: null, events: [] });
|
|
117
|
+
});
|
|
118
|
+
it('stops at the page budget and warns about the child it never read', async () => {
|
|
119
|
+
const { client } = buildClient({
|
|
120
|
+
root: [childStarted(1, 10, 0, 'a', 'run-a'), childStarted(2, 11, 0, 'b', 'run-b')],
|
|
121
|
+
a: [event(1, 20, 0)],
|
|
122
|
+
b: [event(1, 21, 0)]
|
|
123
|
+
});
|
|
124
|
+
const result = await collectWorkflowDebug(client, params, { pageBudget: 2, concurrency: 1 });
|
|
125
|
+
expect(result.complete).toBe(false);
|
|
126
|
+
expect(result.warnings).toEqual([expect.stringContaining('Child workflow b (run run-b) was not read')]);
|
|
127
|
+
expect(result.workflows.find(w => w.workflowId === 'b')?.events).toEqual([]);
|
|
128
|
+
expect(result.workflows.find(w => w.workflowId === 'a')?.events).toHaveLength(1);
|
|
129
|
+
});
|
|
130
|
+
it('warns about a history read only in part and keeps the events it read', async () => {
|
|
131
|
+
const { client } = buildClient({ root: { pages: [[event(1, 10, 0)], [event(2, 11, 0)]] } });
|
|
132
|
+
const result = await collectWorkflowDebug(client, params, { pageBudget: 1 });
|
|
133
|
+
expect(result.warnings).toEqual([expect.stringContaining('Workflow root (run run-root) was read only in part')]);
|
|
134
|
+
expect(result.workflows[0].events.map(e => e.eventId)).toEqual(['1']);
|
|
135
|
+
});
|
|
136
|
+
it('cuts the last page to the event budget and names the events limit', async () => {
|
|
137
|
+
const { client } = buildClient({ root: [event(1, 10, 0), event(2, 11, 0), event(3, 12, 0)] });
|
|
138
|
+
const result = await collectWorkflowDebug(client, params, { eventBudget: 2 });
|
|
139
|
+
expect(result.complete).toBe(false);
|
|
140
|
+
expect(result.workflows[0].events.map(e => e.eventId)).toEqual(['1', '2']);
|
|
141
|
+
expect(result.warnings).toEqual([expect.stringMatching(/Workflow root \(run run-root\) was read only in part.*2 events/)]);
|
|
142
|
+
});
|
|
143
|
+
it('does not read children once the event budget is spent', async () => {
|
|
144
|
+
const { client } = buildClient({
|
|
145
|
+
root: [childStarted(1, 10, 0, 'a', 'run-a')],
|
|
146
|
+
a: [event(1, 20, 0)]
|
|
147
|
+
});
|
|
148
|
+
const result = await collectWorkflowDebug(client, params, { eventBudget: 1 });
|
|
149
|
+
expect(result.warnings).toEqual([expect.stringMatching(/Child workflow a \(run run-a\) was not read.*1 events/)]);
|
|
150
|
+
expect(result.workflows[1].events).toEqual([]);
|
|
151
|
+
});
|
|
152
|
+
it('is complete when the history exactly fills the event budget', async () => {
|
|
153
|
+
const { client } = buildClient({ root: [event(1, 10, 0), event(2, 11, 0)] });
|
|
154
|
+
const result = await collectWorkflowDebug(client, params, { eventBudget: 2 });
|
|
155
|
+
expect(result.complete).toBe(true);
|
|
156
|
+
expect(result.workflows[0].events).toHaveLength(2);
|
|
157
|
+
});
|
|
158
|
+
it('warns when a workflow is closed but its events stop before the end', async () => {
|
|
159
|
+
const { client } = buildClient({ root: [event(1, 10, 0)] }, { root: 'WORKFLOW_EXECUTION_STATUS_COMPLETED' });
|
|
160
|
+
const result = await collectWorkflowDebug(client, params);
|
|
161
|
+
expect(result.complete).toBe(false);
|
|
162
|
+
expect(result.warnings).toEqual([expect.stringContaining('Workflow root (run run-root) finished while it was being read')]);
|
|
163
|
+
});
|
|
164
|
+
it('does not warn when a closed workflow ends with its closing event', async () => {
|
|
165
|
+
const closing = event(2, 11, 0, { eventType: 'EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED' });
|
|
166
|
+
const { client } = buildClient({ root: [event(1, 10, 0), closing] }, { root: 'WORKFLOW_EXECUTION_STATUS_COMPLETED' });
|
|
167
|
+
const result = await collectWorkflowDebug(client, params);
|
|
168
|
+
expect(result).toMatchObject({ complete: true, warnings: [] });
|
|
169
|
+
});
|
|
170
|
+
it('describes each workflow after its history was read', async () => {
|
|
171
|
+
const { client, getWorkflowExecutionHistory } = buildClient({ root: [event(1, 10, 0)] });
|
|
172
|
+
const order = [];
|
|
173
|
+
getWorkflowExecutionHistory.mockImplementationOnce(async () => {
|
|
174
|
+
order.push('history');
|
|
175
|
+
return { history: { events: [event(1, 10, 0)] }, nextPageToken: new Uint8Array() };
|
|
176
|
+
});
|
|
177
|
+
const { getHandle } = client.workflow;
|
|
178
|
+
client.workflow.getHandle = ((...args) => {
|
|
179
|
+
const handle = getHandle(...args);
|
|
180
|
+
return {
|
|
181
|
+
describe: async () => {
|
|
182
|
+
order.push('describe');
|
|
183
|
+
return handle.describe();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
await collectWorkflowDebug(client, params);
|
|
188
|
+
expect(order).toEqual(['describe', 'history', 'describe']);
|
|
189
|
+
});
|
|
190
|
+
it('keeps the events and warns when a workflow cannot be described after they were read', async () => {
|
|
191
|
+
const { client } = buildClient({ root: [event(1, 10, 0)] });
|
|
192
|
+
const { getHandle } = client.workflow;
|
|
193
|
+
const calls = { count: 0 };
|
|
194
|
+
client.workflow.getHandle = ((...args) => ({
|
|
195
|
+
describe: async () => {
|
|
196
|
+
calls.count += 1;
|
|
197
|
+
if (calls.count > 1) {
|
|
198
|
+
throw new Error('boom');
|
|
199
|
+
}
|
|
200
|
+
return getHandle(...args).describe();
|
|
201
|
+
}
|
|
202
|
+
}));
|
|
203
|
+
const result = await collectWorkflowDebug(client, params);
|
|
204
|
+
expect(result.warnings).toEqual([expect.stringContaining('Workflow root (run run-root) could not be described: boom')]);
|
|
205
|
+
expect(result.workflows[0].events).toHaveLength(1);
|
|
206
|
+
});
|
|
207
|
+
it('reads every page of a long history', async () => {
|
|
208
|
+
const { client } = buildClient({ root: { pages: [[event(1, 10, 0)], [event(2, 11, 0)]] } });
|
|
209
|
+
const result = await collectWorkflowDebug(client, params);
|
|
210
|
+
expect(result.complete).toBe(true);
|
|
211
|
+
expect(result.workflows[0].events.map(e => e.eventId)).toEqual(['1', '2']);
|
|
212
|
+
});
|
|
213
|
+
it('follows a child that continues as new, one entry per run, in time order and with the same parent', async () => {
|
|
214
|
+
const { client } = buildClient({
|
|
215
|
+
root: [childStarted(1, 10, 0, 'child', 'run-1'), childStarted(2, 12, 0, 'other', 'run-other')],
|
|
216
|
+
'child/run-1': [event(1, 20, 0), continuedAsNew(2, 21, 0, 'run-2')],
|
|
217
|
+
'child/run-2': [event(1, 22, 0), continuedAsNew(2, 23, 0, 'run-3')],
|
|
218
|
+
'child/run-3': [event(1, 24, 0)],
|
|
219
|
+
other: [event(1, 30, 0)]
|
|
220
|
+
});
|
|
221
|
+
const result = await collectWorkflowDebug(client, params);
|
|
222
|
+
expect(result.complete).toBe(true);
|
|
223
|
+
expect(result.workflows.map(w => `${w.workflowId}/${w.runId}`)).toEqual([
|
|
224
|
+
'root/run-root', 'child/run-1', 'other/run-other', 'child/run-2', 'child/run-3'
|
|
225
|
+
]);
|
|
226
|
+
expect(result.workflows.slice(1).map(w => w.parent)).toEqual(Array(4).fill({ workflowId: 'root', runId: 'run-root' }));
|
|
227
|
+
expect(result.workflows[3].workflowType).toBe('child_type');
|
|
228
|
+
});
|
|
229
|
+
it('reads a continued child run even when it is a child of a continued run', async () => {
|
|
230
|
+
const { client } = buildClient({
|
|
231
|
+
root: [childStarted(1, 10, 0, 'child', 'run-1')],
|
|
232
|
+
'child/run-1': [continuedAsNew(1, 20, 0, 'run-2')],
|
|
233
|
+
'child/run-2': [childStarted(1, 30, 0, 'grandchild', 'run-g')],
|
|
234
|
+
grandchild: [event(1, 40, 0)]
|
|
235
|
+
});
|
|
236
|
+
const { workflows } = await collectWorkflowDebug(client, params);
|
|
237
|
+
expect(workflows.map(w => `${w.workflowId}/${w.runId}`)).toEqual(['root/run-root', 'child/run-1', 'child/run-2', 'grandchild/run-g']);
|
|
238
|
+
expect(workflows[3].parent).toEqual({ workflowId: 'child', runId: 'run-2' });
|
|
239
|
+
});
|
|
240
|
+
it('warns when the next run of a continued child is gone', async () => {
|
|
241
|
+
const notFound = Object.assign(new Error('not found'), { code: 5 });
|
|
242
|
+
const { client } = buildClient({
|
|
243
|
+
root: [childStarted(1, 10, 0, 'child', 'run-1')],
|
|
244
|
+
'child/run-1': [continuedAsNew(1, 20, 0, 'run-2')],
|
|
245
|
+
'child/run-2': notFound
|
|
246
|
+
});
|
|
247
|
+
const result = await collectWorkflowDebug(client, params);
|
|
248
|
+
expect(result.complete).toBe(false);
|
|
249
|
+
expect(result.warnings).toEqual([expect.stringContaining('child (run run-2) is no longer in Temporal')]);
|
|
250
|
+
expect(result.workflows.at(-1)?.events).toEqual([]);
|
|
251
|
+
});
|
|
252
|
+
it('follows the continuation of the root too, with no parent, placed by time among the children', async () => {
|
|
253
|
+
const { client } = buildClient({
|
|
254
|
+
'root/run-root': [childStarted(1, 10, 0, 'a', 'run-a'), continuedAsNew(2, 20, 0, 'run-2')],
|
|
255
|
+
'root/run-2': [childStarted(1, 30, 0, 'b', 'run-b')],
|
|
256
|
+
a: [event(1, 15, 0)],
|
|
257
|
+
b: [event(1, 35, 0)]
|
|
258
|
+
});
|
|
259
|
+
const { workflows } = await collectWorkflowDebug(client, params);
|
|
260
|
+
expect(workflows.map(w => `${w.workflowId}/${w.runId}`)).toEqual(['root/run-root', 'a/run-a', 'root/run-2', 'b/run-b']);
|
|
261
|
+
expect(workflows[2]).not.toHaveProperty('parent');
|
|
262
|
+
expect(workflows[3].parent).toEqual({ workflowId: 'root', runId: 'run-2' });
|
|
263
|
+
});
|
|
264
|
+
it('starts from the requested run and follows its continuations to the latest', async () => {
|
|
265
|
+
const { client } = buildClient({
|
|
266
|
+
'root/run-old': [continuedAsNew(1, 10, 0, 'run-new')],
|
|
267
|
+
'root/run-new': [event(1, 20, 0)]
|
|
268
|
+
});
|
|
269
|
+
const { workflows } = await collectWorkflowDebug(client, { ...params, runId: 'run-old' });
|
|
270
|
+
expect(workflows.map(w => w.runId)).toEqual(['run-old', 'run-new']);
|
|
271
|
+
});
|
|
272
|
+
it('counts continued runs against the shared page budget and warns about the ones not read', async () => {
|
|
273
|
+
const { client, getWorkflowExecutionHistory } = buildClient({
|
|
274
|
+
'root/run-root': [continuedAsNew(1, 10, 0, 'run-2')],
|
|
275
|
+
'root/run-2': [continuedAsNew(1, 20, 0, 'run-3')],
|
|
276
|
+
'root/run-3': [event(1, 30, 0)]
|
|
277
|
+
});
|
|
278
|
+
const result = await collectWorkflowDebug(client, params, { pageBudget: 2 });
|
|
279
|
+
expect(getWorkflowExecutionHistory).toHaveBeenCalledTimes(2);
|
|
280
|
+
expect(result.complete).toBe(false);
|
|
281
|
+
expect(result.warnings).toEqual([expect.stringMatching(/^Workflow root \(run run-3\) was not read: the limit of 2 pages/)]);
|
|
282
|
+
expect(result.workflows.at(-1)?.events).toEqual([]);
|
|
283
|
+
});
|
|
284
|
+
it('reports the pending activities and children Temporal describes, with decoded failures', async () => {
|
|
285
|
+
const lastFailure = { message: 'Foo', stackTrace: 'Error: Foo', details: { payloads: [encode('json/plain', '{"code":7}')] } };
|
|
286
|
+
const activity = {
|
|
287
|
+
activityId: '2',
|
|
288
|
+
activityType: { name: 'wf#step' },
|
|
289
|
+
state: 'PENDING_ACTIVITY_STATE_SCHEDULED',
|
|
290
|
+
attempt: 2,
|
|
291
|
+
lastFailure,
|
|
292
|
+
ignored: true
|
|
293
|
+
};
|
|
294
|
+
const pendingChild = { workflowId: 'child', runId: 'run-c', workflowTypeName: 'child_type', ignored: true };
|
|
295
|
+
const pending = {
|
|
296
|
+
root: {
|
|
297
|
+
pendingActivities: [{ toJSON: () => activity }],
|
|
298
|
+
pendingChildren: [pendingChild]
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const { client } = buildClient({ root: [event(1, 10, 0)] }, {}, pending);
|
|
302
|
+
const [root] = (await collectWorkflowDebug(client, params)).workflows;
|
|
303
|
+
expect(root.pendingActivities).toEqual([{
|
|
304
|
+
activityId: '2',
|
|
305
|
+
activityType: 'wf#step',
|
|
306
|
+
state: 'PENDING_ACTIVITY_STATE_SCHEDULED',
|
|
307
|
+
attempt: 2,
|
|
308
|
+
lastFailure: { message: 'Foo', stackTrace: 'Error: Foo', details: { payloads: [{ code: 7 }] } }
|
|
309
|
+
}]);
|
|
310
|
+
expect(root.pendingChildren).toEqual([{ workflowId: 'child', runId: 'run-c', workflowType: 'child_type' }]);
|
|
311
|
+
});
|
|
312
|
+
it('reads a child once even when its parent reports it twice', async () => {
|
|
313
|
+
const { client, getWorkflowExecutionHistory } = buildClient({
|
|
314
|
+
root: [childStarted(1, 10, 0, 'child', 'run-c'), childStarted(2, 11, 0, 'child', 'run-c')],
|
|
315
|
+
child: [event(1, 20, 0)]
|
|
316
|
+
});
|
|
317
|
+
const { workflows } = await collectWorkflowDebug(client, params);
|
|
318
|
+
expect(workflows.map(w => w.workflowId)).toEqual(['root', 'child']);
|
|
319
|
+
expect(getWorkflowExecutionHistory).toHaveBeenCalledTimes(2);
|
|
320
|
+
});
|
|
321
|
+
it('throws when the requested run cannot be read at all', async () => {
|
|
322
|
+
const { client } = buildClient({ root: new Error('boom') });
|
|
323
|
+
await expect(collectWorkflowDebug(client, params)).rejects.toThrow('boom');
|
|
324
|
+
});
|
|
325
|
+
it('turns any other failure on a child into a warning and keeps reading the rest', async () => {
|
|
326
|
+
const { client } = buildClient({
|
|
327
|
+
root: [childStarted(1, 10, 0, 'bad', 'run-bad'), childStarted(2, 11, 0, 'good', 'run-good')],
|
|
328
|
+
bad: new Error('permission denied'),
|
|
329
|
+
good: [event(1, 20, 0)]
|
|
330
|
+
});
|
|
331
|
+
const result = await collectWorkflowDebug(client, params);
|
|
332
|
+
expect(result.complete).toBe(false);
|
|
333
|
+
expect(result.warnings).toEqual(['Child workflow bad (run run-bad) could not be read: permission denied. Its entry has no events.']);
|
|
334
|
+
expect(result.workflows.map(w => [w.workflowId, w.events.length])).toEqual([['root', 2], ['bad', 0], ['good', 1]]);
|
|
335
|
+
});
|
|
336
|
+
it('keeps the events already read when a later page fails, for the requested run too', async () => {
|
|
337
|
+
const { client } = buildClient({ root: { pages: [[event(1, 10, 0)], new Error('unavailable')] } });
|
|
338
|
+
const result = await collectWorkflowDebug(client, params);
|
|
339
|
+
expect(result.complete).toBe(false);
|
|
340
|
+
expect(result.warnings).toEqual(['Workflow root (run run-root) could not be read: unavailable. Its entry has the events read so far.']);
|
|
341
|
+
expect(result.workflows[0].events.map(e => e.eventId)).toEqual(['1']);
|
|
342
|
+
});
|
|
343
|
+
it('runs every Temporal call under a deadline', async () => {
|
|
344
|
+
const { client, withDeadline, getWorkflowExecutionHistory } = buildClient({ root: [event(1, 10, 0)] });
|
|
345
|
+
await collectWorkflowDebug(client, params);
|
|
346
|
+
// the first describe, one history page and the describe after it
|
|
347
|
+
expect(withDeadline).toHaveBeenCalledTimes(3);
|
|
348
|
+
expect(getWorkflowExecutionHistory).toHaveBeenCalledTimes(1);
|
|
349
|
+
expect(withDeadline.mock.calls[0][0]).toBeGreaterThan(Date.now());
|
|
350
|
+
});
|
|
351
|
+
it('says so when Temporal does not answer in time', async () => {
|
|
352
|
+
const deadline = Object.assign(new Error('4 DEADLINE_EXCEEDED: Deadline exceeded'), { code: 4 });
|
|
353
|
+
const { client } = buildClient({ root: deadline });
|
|
354
|
+
await expect(collectWorkflowDebug(client, params)).rejects.toThrow('Temporal did not answer within 30s');
|
|
355
|
+
});
|
|
356
|
+
it('serializes the summary first and the events last in each workflow', async () => {
|
|
357
|
+
const { client } = buildClient({ root: [event(1, 10, 0)] });
|
|
358
|
+
const result = await collectWorkflowDebug(client, params);
|
|
359
|
+
const parsed = JSON.parse(JSON.stringify(result));
|
|
360
|
+
expect(Object.keys(parsed)).toEqual(['complete', 'warnings', 'temporal', 'workflows']);
|
|
361
|
+
expect(Object.keys(parsed.workflows[0]).at(-1)).toBe('events');
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Client } from '@temporalio/client';
|
|
2
|
+
export interface WorkflowRunDataOptions {
|
|
3
|
+
/** The workflow type the run must have */
|
|
4
|
+
workflowName: string;
|
|
5
|
+
workflowId: string;
|
|
6
|
+
/** Defaults to the latest run of the workflow id */
|
|
7
|
+
runId?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkflowRunData {
|
|
10
|
+
workflowId: string;
|
|
11
|
+
runId: string;
|
|
12
|
+
/** The run whose start input was read: the first run of the chain when `runId` continued as new from earlier runs */
|
|
13
|
+
inputRunId: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
/** `null` when the workflow returned nothing */
|
|
16
|
+
output: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads the start input and the result of a completed workflow run from Temporal, to turn it into a dataset case.
|
|
20
|
+
* Nothing is truncated. A run that is missing, of another workflow type or not completed is an error.
|
|
21
|
+
*
|
|
22
|
+
* @param client - The Temporal client
|
|
23
|
+
* @param options - The run to read
|
|
24
|
+
* @returns The run's ids, the run its input was read from, its input (an object) and its output
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectWorkflowRunData(client: Client, { workflowName, workflowId, runId }: WorkflowRunDataOptions): Promise<WorkflowRunData>;
|