@cephalization/math 0.3.2 → 0.4.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.
@@ -1,228 +0,0 @@
1
- import { test, expect, describe } from "bun:test";
2
- import type { WebSocketMessage } from "./server";
3
- import type { BufferLogEntry, BufferAgentOutput } from "./buffer";
4
-
5
- /**
6
- * Tests for the React app module.
7
- * Since the app is primarily UI code that mounts to the DOM,
8
- * we test that the module exports correctly and the types align.
9
- */
10
-
11
- describe("app.tsx", () => {
12
- test("module exists and can be imported", async () => {
13
- // The app module should exist at the expected path
14
- const file = Bun.file("./src/ui/app.tsx");
15
- const exists = await file.exists();
16
- expect(exists).toBe(true);
17
- });
18
-
19
- test("imports react and react-dom", async () => {
20
- const content = await Bun.file("./src/ui/app.tsx").text();
21
-
22
- expect(content).toContain('from "react"');
23
- expect(content).toContain('from "react-dom/client"');
24
- });
25
-
26
- test("uses createRoot for React 18", async () => {
27
- const content = await Bun.file("./src/ui/app.tsx").text();
28
-
29
- expect(content).toContain("createRoot");
30
- expect(content).toContain('document.getElementById("root")');
31
- });
32
-
33
- test("connects to WebSocket at /ws", async () => {
34
- const content = await Bun.file("./src/ui/app.tsx").text();
35
-
36
- expect(content).toContain("WebSocket");
37
- expect(content).toContain("/ws");
38
- });
39
-
40
- test("renders Loop Status section", async () => {
41
- const content = await Bun.file("./src/ui/app.tsx").text();
42
-
43
- expect(content).toContain("Loop Status");
44
- });
45
-
46
- test("renders Agent Output section", async () => {
47
- const content = await Bun.file("./src/ui/app.tsx").text();
48
-
49
- expect(content).toContain("Agent Output");
50
- });
51
-
52
- test("handles WebSocket message types", async () => {
53
- const content = await Bun.file("./src/ui/app.tsx").text();
54
-
55
- // Should handle all message types from server
56
- expect(content).toContain('"connected"');
57
- expect(content).toContain('"history"');
58
- expect(content).toContain('"log"');
59
- expect(content).toContain('"output"');
60
- });
61
-
62
- test("stores logs and output in state", async () => {
63
- const content = await Bun.file("./src/ui/app.tsx").text();
64
-
65
- // Should use useState for logs and output
66
- expect(content).toContain("useState<BufferLogEntry[]>");
67
- expect(content).toContain("useState<BufferAgentOutput[]>");
68
- });
69
-
70
- test("shows connection status", async () => {
71
- const content = await Bun.file("./src/ui/app.tsx").text();
72
-
73
- expect(content).toContain("Connected");
74
- expect(content).toContain("Disconnected");
75
- });
76
- });
77
-
78
- describe("stream-display features", () => {
79
- test("defines category colors for all log types", async () => {
80
- const content = await Bun.file("./src/ui/app.tsx").text();
81
-
82
- // Should define colors for all categories
83
- expect(content).toContain("categoryColors");
84
- expect(content).toContain("info:");
85
- expect(content).toContain("success:");
86
- expect(content).toContain("warning:");
87
- expect(content).toContain("error:");
88
- });
89
-
90
- test("uses correct terminal colors for categories", async () => {
91
- const content = await Bun.file("./src/ui/app.tsx").text();
92
-
93
- // Blue for info
94
- expect(content).toMatch(/info.*#60a5fa|#60a5fa.*info/i);
95
- // Green for success
96
- expect(content).toMatch(/success.*#4ade80|#4ade80.*success/i);
97
- // Yellow for warning
98
- expect(content).toMatch(/warning.*#facc15|#facc15.*warning/i);
99
- // Red for error
100
- expect(content).toMatch(/error.*#f87171|#f87171.*error/i);
101
- });
102
-
103
- test("has refs for auto-scroll containers", async () => {
104
- const content = await Bun.file("./src/ui/app.tsx").text();
105
-
106
- // Should use refs for both containers
107
- expect(content).toContain("logContainerRef");
108
- expect(content).toContain("outputContainerRef");
109
- expect(content).toContain("useRef<HTMLDivElement>");
110
- });
111
-
112
- test("implements auto-scroll on content changes", async () => {
113
- const content = await Bun.file("./src/ui/app.tsx").text();
114
-
115
- // Should scroll to bottom on logs and output changes
116
- expect(content).toContain("scrollTop");
117
- expect(content).toContain("scrollHeight");
118
-
119
- // Should have useEffect hooks with appropriate dependencies
120
- // The pattern: useEffect that uses logContainerRef and depends on [logs]
121
- expect(content).toContain("logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight");
122
- expect(content).toContain("}, [logs])");
123
-
124
- // The pattern: useEffect that uses outputContainerRef and depends on [output]
125
- expect(content).toContain("outputContainerRef.current.scrollTop = outputContainerRef.current.scrollHeight");
126
- expect(content).toContain("}, [output])");
127
- });
128
-
129
- test("renders preformatted monospace agent output", async () => {
130
- const content = await Bun.file("./src/ui/app.tsx").text();
131
-
132
- // Should use <pre> tag for agent output
133
- expect(content).toContain("<pre");
134
- // Should have monospace font for output
135
- expect(content).toContain("fontFamily: \"monospace\"");
136
- // Should preserve whitespace
137
- expect(content).toContain("pre-wrap");
138
- });
139
-
140
- test("has visual connection status indicator", async () => {
141
- const content = await Bun.file("./src/ui/app.tsx").text();
142
-
143
- // Should have a status dot element
144
- expect(content).toContain("statusDot");
145
- // Should use different colors based on connection
146
- expect(content).toContain("backgroundColor:");
147
- // Should have a container for status
148
- expect(content).toContain("statusContainer");
149
- });
150
-
151
- test("applies category color to timestamp and category label", async () => {
152
- const content = await Bun.file("./src/ui/app.tsx").text();
153
-
154
- // Should apply color to timestamp
155
- expect(content).toContain("getCategoryColor(log.category)");
156
- // Should be used in style objects
157
- expect(content).toMatch(/color:\s*getCategoryColor/);
158
- });
159
-
160
- test("imports LogCategory type", async () => {
161
- const content = await Bun.file("./src/ui/app.tsx").text();
162
-
163
- // Should import LogCategory from agent
164
- expect(content).toContain('import type { LogCategory } from "../agent"');
165
- });
166
- });
167
-
168
- describe("WebSocketMessage type compatibility", () => {
169
- test("history message has correct structure", () => {
170
- const logs: BufferLogEntry[] = [
171
- { timestamp: new Date(), category: "info", message: "test" },
172
- ];
173
- const output: BufferAgentOutput[] = [
174
- { timestamp: new Date(), text: "output" },
175
- ];
176
-
177
- const message: WebSocketMessage = {
178
- type: "history",
179
- logs,
180
- output,
181
- };
182
-
183
- expect(message.type).toBe("history");
184
- expect(message.logs).toHaveLength(1);
185
- expect(message.output).toHaveLength(1);
186
- });
187
-
188
- test("log message has correct structure", () => {
189
- const entry: BufferLogEntry = {
190
- timestamp: new Date(),
191
- category: "error",
192
- message: "test error",
193
- };
194
-
195
- const message: WebSocketMessage = {
196
- type: "log",
197
- entry,
198
- };
199
-
200
- expect(message.type).toBe("log");
201
- expect(message.entry.category).toBe("error");
202
- });
203
-
204
- test("output message has correct structure", () => {
205
- const entry: BufferAgentOutput = {
206
- timestamp: new Date(),
207
- text: "agent text",
208
- };
209
-
210
- const message: WebSocketMessage = {
211
- type: "output",
212
- entry,
213
- };
214
-
215
- expect(message.type).toBe("output");
216
- expect(message.entry.text).toBe("agent text");
217
- });
218
-
219
- test("connected message has correct structure", () => {
220
- const message: WebSocketMessage = {
221
- type: "connected",
222
- id: "test-uuid",
223
- };
224
-
225
- expect(message.type).toBe("connected");
226
- expect(message.id).toBe("test-uuid");
227
- });
228
- });