-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathsharedRuntimeManager.test.ts
More file actions
121 lines (106 loc) · 4.08 KB
/
sharedRuntimeManager.test.ts
File metadata and controls
121 lines (106 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { describe, expect, it } from "vitest";
import { SharedRuntimeManager } from "./sharedRuntimeManager.js";
import { CompletedWaitpoint } from "../schemas/index.js";
describe("SharedRuntimeManager", () => {
const mockIpc = {
send: () => { },
} as any;
const manager = new SharedRuntimeManager(mockIpc, false);
// Access private method
const waitpointToResult = (manager as any).waitpointToTaskRunExecutionResult.bind(manager);
describe("waitpointToTaskRunExecutionResult", () => {
it("should use the taskIdentifier from the waitpoint if present (success)", () => {
const waitpoint: CompletedWaitpoint = {
id: "wp_1",
friendlyId: "wp_1",
type: "RUN",
completedAt: new Date(),
outputIsError: false,
output: JSON.stringify({ foo: "bar" }),
outputType: "application/json",
completedByTaskRun: {
id: "run_1",
friendlyId: "run_1",
taskIdentifier: "my-task",
},
};
const result = waitpointToResult(waitpoint);
expect(result).toEqual({
ok: true,
id: "run_1",
taskIdentifier: "my-task",
output: JSON.stringify({ foo: "bar" }),
outputType: "application/json",
});
});
it("should default taskIdentifier to 'unknown' if missing (success)", () => {
const waitpoint: CompletedWaitpoint = {
id: "wp_2",
friendlyId: "wp_2",
type: "RUN",
completedAt: new Date(),
outputIsError: false,
output: JSON.stringify({ foo: "bar" }),
outputType: "application/json",
completedByTaskRun: {
id: "run_2",
friendlyId: "run_2",
// database/legacy object missing taskIdentifier
} as any,
};
const result = waitpointToResult(waitpoint);
expect(result).toEqual({
ok: true,
id: "run_2",
taskIdentifier: "unknown",
output: JSON.stringify({ foo: "bar" }),
outputType: "application/json",
});
});
it("should use the taskIdentifier from the waitpoint if present (failure)", () => {
const waitpoint: CompletedWaitpoint = {
id: "wp_3",
friendlyId: "wp_3",
type: "RUN",
completedAt: new Date(),
outputIsError: true,
output: JSON.stringify({ message: "Boom" }),
outputType: "application/json",
completedByTaskRun: {
id: "run_3",
friendlyId: "run_3",
taskIdentifier: "my-failed-task",
},
};
const result = waitpointToResult(waitpoint);
expect(result).toEqual({
ok: false,
id: "run_3",
taskIdentifier: "my-failed-task",
error: { message: "Boom" },
});
});
it("should default taskIdentifier to 'unknown' if missing (failure)", () => {
const waitpoint: CompletedWaitpoint = {
id: "wp_4",
friendlyId: "wp_4",
type: "RUN",
completedAt: new Date(),
outputIsError: true,
output: JSON.stringify({ message: "Boom" }),
outputType: "application/json",
completedByTaskRun: {
id: "run_4",
friendlyId: "run_4",
} as any,
};
const result = waitpointToResult(waitpoint);
expect(result).toEqual({
ok: false,
id: "run_4",
taskIdentifier: "unknown",
error: { message: "Boom" },
});
});
});
});