-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathstream.test.ts
More file actions
75 lines (67 loc) · 2.36 KB
/
stream.test.ts
File metadata and controls
75 lines (67 loc) · 2.36 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
import { describe, expect, test } from "bun:test";
import {
areRuntimeStatusEventsEqual,
areStreamLifecycleSnapshotsEqual,
copyRuntimeStatusEvent,
hasInFlightStreamLifecycle,
isTerminalRuntimeStatusPhase,
} from "./stream";
describe("stream shared helpers", () => {
test("compare stream lifecycle snapshots with nullish abort reasons", () => {
expect(
areStreamLifecycleSnapshotsEqual(
{ phase: "failed", hadAnyOutput: false },
{ phase: "failed", hadAnyOutput: false }
)
).toBe(true);
expect(
areStreamLifecycleSnapshotsEqual(
{ phase: "failed", hadAnyOutput: false, abortReason: "user" },
{ phase: "failed", hadAnyOutput: false }
)
).toBe(false);
});
test("copy runtime-status events and compare optional fields nullishly", () => {
const copied = copyRuntimeStatusEvent({
type: "runtime-status",
workspaceId: "ws-1",
phase: "starting",
runtimeType: "ssh",
detail: "Checking workspace runtime...",
});
expect(copied).toEqual({
type: "runtime-status",
workspaceId: "ws-1",
phase: "starting",
runtimeType: "ssh",
detail: "Checking workspace runtime...",
});
expect(copied).not.toBe(copyRuntimeStatusEvent(copied));
expect("source" in copied).toBe(false);
expect(
areRuntimeStatusEventsEqual(copied, {
phase: "starting",
runtimeType: "ssh",
detail: "Checking workspace runtime...",
})
).toBe(true);
expect(
areRuntimeStatusEventsEqual(copied, {
phase: "starting",
runtimeType: "ssh",
detail: "Loading tools...",
})
).toBe(false);
});
test("share terminal runtime-status and in-flight lifecycle semantics", () => {
expect(isTerminalRuntimeStatusPhase("ready")).toBe(true);
expect(isTerminalRuntimeStatusPhase("error")).toBe(true);
expect(isTerminalRuntimeStatusPhase("starting")).toBe(false);
expect(hasInFlightStreamLifecycle({ phase: "preparing" })).toBe(true);
expect(hasInFlightStreamLifecycle({ phase: "streaming" })).toBe(true);
expect(hasInFlightStreamLifecycle({ phase: "completing" })).toBe(true);
expect(hasInFlightStreamLifecycle({ phase: "failed" })).toBe(false);
expect(hasInFlightStreamLifecycle({ phase: "interrupted" })).toBe(false);
expect(hasInFlightStreamLifecycle(null)).toBe(false);
});
});