Skip to content

Commit ea30af4

Browse files
committed
code cleanup
1 parent 4eed4db commit ea30af4

21 files changed

Lines changed: 158 additions & 467 deletions

typescript/__tests__/config/command_whitelist.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
isQueryCommand,
1010
} from "../../src/config/command_whitelist.js";
1111

12-
// extractVerb
13-
1412
describe("extractVerb", () => {
1513
it("returns a simple command", () => {
1614
expect(extractVerb("report_checks")).toBe("report_checks");
@@ -53,8 +51,6 @@ describe("extractVerb", () => {
5351
});
5452
});
5553

56-
// Pattern set membership
57-
5854
describe("pattern sets", () => {
5955
it("READONLY contains report/get/check globs", () => {
6056
expect(READONLY_PATTERNS).toContain("report_*");
@@ -119,8 +115,6 @@ describe("pattern sets", () => {
119115
});
120116
});
121117

122-
// isQueryCommand
123-
124118
describe("isQueryCommand", () => {
125119
it("allows report_*", () => {
126120
expect(isQueryCommand("report_checks -path_delay max")).toEqual([true, null]);
@@ -243,8 +237,6 @@ describe("isQueryCommand", () => {
243237
});
244238
});
245239

246-
// isExecCommand
247-
248240
describe("isExecCommand", () => {
249241
it("allows set_clock_period", () => {
250242
expect(isExecCommand("set_clock_period -name clk 2.0")).toEqual([true, null]);
@@ -306,8 +298,6 @@ describe("isExecCommand", () => {
306298
});
307299
});
308300

309-
// isCommandAllowed (backward-compat alias)
310-
311301
describe("isCommandAllowed", () => {
312302
it("mirrors isExecCommand for allowed commands", () => {
313303
expect(isCommandAllowed("report_checks -path_delay max")).toEqual([true, null]);
@@ -328,18 +318,15 @@ describe("isCommandAllowed", () => {
328318
});
329319
});
330320

331-
// minimatch vs fnmatch parity
332321

333322
describe("glob parity (minimatch vs fnmatch)", () => {
334323
it("matches star-suffix against the empty remainder", () => {
335-
// report_ / set_ / read_ match report_* / set_* / read_* (star matches empty)
336324
expect(isQueryCommand("report_")).toEqual([true, null]);
337325
expect(isExecCommand("set_")).toEqual([true, null]);
338326
expect(isExecCommand("read_")).toEqual([true, null]);
339327
});
340328

341329
it("is case-sensitive like POSIX fnmatch on verbs", () => {
342-
// Report_Checks (capitalized) does not match report_* and is unknown -> blocked in query
343330
expect(isQueryCommand("Report_Checks")).toEqual([false, "Report_Checks"]);
344331
});
345332
});

typescript/__tests__/interactive/buffer.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ describe("CircularBuffer", () => {
143143
// Start waitForData (fast-path sees _dataAvailable = false and enters the Promise)
144144
const waiter = buf.waitForData(5000);
145145

146-
// append() fires here — before runExclusive's callback has a chance to push
147-
// wakeUp into _resolvers. Without the re-check inside runExclusive, wakeUp
148-
// would be pushed after append() already drained an empty _resolvers, and
146+
// append() fires before runExclusive's callback can push wakeUp into
147+
// _resolvers. Without the re-check inside runExclusive, wakeUp would
148+
// land in _resolvers after append() already drained an empty list, and
149149
// the caller would wait the full 5-second timeout.
150150
await buf.append("raced data");
151151

@@ -168,7 +168,7 @@ describe("CircularBuffer", () => {
168168
it("wakes pending waitForData() immediately with false so callers do not hang", async () => {
169169
const buf = new CircularBuffer(100);
170170

171-
// waitForData with a large timeoutclear() must unblock it before the timeout fires
171+
// Large timeout: clear() must unblock waitForData before it fires.
172172
const waiter = buf.waitForData(5000);
173173
await buf.clear();
174174

typescript/__tests__/interactive/session.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ describe("InteractiveSession", () => {
217217
await session.outputBuffer.append("% Exiting OpenROAD\r\n");
218218
session.state = SessionState.TERMINATED;
219219

220-
// Must NOT throw even though the session is terminated
221220
const result = await session.readOutput(100);
222221

223222
expect(result.output).toContain("Exiting OpenROAD");
@@ -227,8 +226,8 @@ describe("InteractiveSession", () => {
227226

228227
it("signals shutdown when readOutput detects terminated session so writer task does not loop indefinitely", async () => {
229228
// Spy on the private method to verify readOutput() calls it directly.
230-
// Scenario: _state was flipped to TERMINATED externally (e.g. via the setter)
231-
// without calling _signalShutdown() — the exact gap @luarss identified.
229+
// Scenario: _state was flipped to TERMINATED externally (e.g. via the
230+
// setter) without calling _signalShutdown().
232231
const signalShutdown = vi.spyOn(session as unknown as { _signalShutdown: () => void }, "_signalShutdown");
233232

234233
session.state = SessionState.TERMINATED;
@@ -327,12 +326,11 @@ describe("InteractiveSession", () => {
327326
it("calls pty.cleanup() so listeners and pending resolvers are disposed without a subsequent session.cleanup()", async () => {
328327
session.state = SessionState.ACTIVE;
329328

330-
// terminate() without any follow-up cleanup() call
331329
await session.terminate(false);
332330

333-
// pty.cleanup() must have been called to dispose _dataDisposable,
334-
// _exitDisposable, and drain _exitResolversotherwise post-kill
335-
// data bursts keep appending and waitForExit() callers hang forever
331+
// pty.cleanup() must run to dispose _dataDisposable, _exitDisposable,
332+
// and drain _exitResolvers; otherwise post-kill data bursts keep
333+
// appending and waitForExit() callers hang forever.
336334
expect(mockPty.cleanup).toHaveBeenCalledOnce();
337335
});
338336
});
@@ -420,7 +418,6 @@ describe("InteractiveSession", () => {
420418
await session.start(["echo"]);
421419
session.state = SessionState.TERMINATED;
422420

423-
// Should not throw or double-signal shutdown
424421
capturedOnExit?.(0);
425422
expect(session.state).toBe(SessionState.TERMINATED);
426423
});

typescript/__tests__/tools/interactive.test.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { SessionNotFoundError, SessionTerminatedError, SessionError } from "../.
66
import { SessionState } from "../../src/core/models.js";
77
import type { InteractiveExecResult, InteractiveSessionInfo, SessionDetailedMetrics, ManagerMetrics } from "../../src/core/models.js";
88

9-
// ---------------------------------------------------------------------------
10-
// Mock helpers
11-
// ---------------------------------------------------------------------------
12-
139
const NOW = "2024-01-01T00:00:00.000Z";
1410

1511
function makeExecResult(overrides: Partial<InteractiveExecResult> = {}): InteractiveExecResult {
@@ -87,10 +83,6 @@ function makeMockManager(): MockManager {
8783
};
8884
}
8985

90-
// ---------------------------------------------------------------------------
91-
// QueryShellTool
92-
// ---------------------------------------------------------------------------
93-
9486
describe("QueryShellTool", () => {
9587
let mgr: MockManager;
9688
let tool: QueryShellTool;
@@ -149,7 +141,6 @@ describe("QueryShellTool", () => {
149141
});
150142

151143
it("blocks dangerous commands when whitelist is enabled", async () => {
152-
// `quit` is in BLOCKED_COMMANDS
153144
const raw = await tool.execute("quit");
154145
const result = JSON.parse(raw);
155146
expect(result.error).toMatch(/CommandBlocked/);
@@ -161,10 +152,6 @@ describe("QueryShellTool", () => {
161152
});
162153
});
163154

164-
// ---------------------------------------------------------------------------
165-
// ExecShellTool
166-
// ---------------------------------------------------------------------------
167-
168155
describe("ExecShellTool", () => {
169156
let mgr: MockManager;
170157
let tool: ExecShellTool;
@@ -195,10 +182,6 @@ describe("ExecShellTool", () => {
195182
});
196183
});
197184

198-
// ---------------------------------------------------------------------------
199-
// ListSessionsTool
200-
// ---------------------------------------------------------------------------
201-
202185
describe("ListSessionsTool", () => {
203186
let mgr: MockManager;
204187
let tool: ListSessionsTool;
@@ -238,10 +221,6 @@ describe("ListSessionsTool", () => {
238221
});
239222
});
240223

241-
// ---------------------------------------------------------------------------
242-
// CreateSessionTool
243-
// ---------------------------------------------------------------------------
244-
245224
describe("CreateSessionTool", () => {
246225
let mgr: MockManager;
247226
let tool: CreateSessionTool;
@@ -278,10 +257,6 @@ describe("CreateSessionTool", () => {
278257
});
279258
});
280259

281-
// ---------------------------------------------------------------------------
282-
// TerminateSessionTool
283-
// ---------------------------------------------------------------------------
284-
285260
describe("TerminateSessionTool", () => {
286261
let mgr: MockManager;
287262
let tool: TerminateSessionTool;
@@ -325,10 +300,6 @@ describe("TerminateSessionTool", () => {
325300
});
326301
});
327302

328-
// ---------------------------------------------------------------------------
329-
// InspectSessionTool
330-
// ---------------------------------------------------------------------------
331-
332303
describe("InspectSessionTool", () => {
333304
let mgr: MockManager;
334305
let tool: InspectSessionTool;
@@ -363,10 +334,6 @@ describe("InspectSessionTool", () => {
363334
});
364335
});
365336

366-
// ---------------------------------------------------------------------------
367-
// SessionHistoryTool
368-
// ---------------------------------------------------------------------------
369-
370337
describe("SessionHistoryTool", () => {
371338
let mgr: MockManager;
372339
let tool: SessionHistoryTool;
@@ -410,10 +377,6 @@ describe("SessionHistoryTool", () => {
410377
});
411378
});
412379

413-
// ---------------------------------------------------------------------------
414-
// SessionMetricsTool
415-
// ---------------------------------------------------------------------------
416-
417380
describe("SessionMetricsTool", () => {
418381
let mgr: MockManager;
419382
let tool: SessionMetricsTool;
@@ -440,12 +403,8 @@ describe("SessionMetricsTool", () => {
440403
});
441404
});
442405

443-
// ---------------------------------------------------------------------------
444-
// Integration: full workflow
445-
// ---------------------------------------------------------------------------
446-
447406
describe("Integration: session workflow", () => {
448-
it("createexecutelist terminate", async () => {
407+
it("create, execute, list, terminate", async () => {
449408
const mgr = makeMockManager();
450409
mgr.listSessions.mockResolvedValue([makeSessionInfo()]);
451410

@@ -476,9 +435,7 @@ describe("Integration: session workflow", () => {
476435
});
477436
});
478437

479-
// ---------------------------------------------------------------------------
480438
// Snapshot: one representative output per tool
481-
// ---------------------------------------------------------------------------
482439

483440
describe("Snapshots: wire format stability", () => {
484441
it("QueryShellTool success output", async () => {

0 commit comments

Comments
 (0)