-
Notifications
You must be signed in to change notification settings - Fork 9
Feat/ts integration tests #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
luarss
merged 10 commits into
The-OpenROAD-Project:feat/ts-migration
from
kartikloops:feat/ts-integration-tests
Jul 8, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e65459d
add integration and performance vitest configs with separate timeout …
kartikloops 89b52b0
add pty integration tests for 10 real-subprocess scenarios ported fro…
kartikloops c86ece2
add performance benchmarks for session latency throughput concurrency…
kartikloops aa3aab9
add response sizes tests for token budget and compact JSON assertions
kartikloops 8f21e63
add memory monitoring tests for RSS leak detection and FD tracking
kartikloops 094fcce
add make targets and ci steps for typescript integration and performa…
kartikloops b889622
fix vacuous test assertions and dead CI env var in ts integration/per…
kartikloops 28d4874
code cleanup
kartikloops 4019f63
fix heap profiling threshold to account for per-string object overhead
kartikloops d14d60d
cap http body size, redact PATH from pty errors, narrow spawn-helper …
kartikloops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
typescript/__tests__/integration/pty_integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| import { describe, it, expect, beforeEach, afterEach } from "vitest"; | ||
| import * as os from "node:os"; | ||
| import * as fs from "node:fs"; | ||
| import * as path from "node:path"; | ||
| import { PtyHandler } from "../../src/interactive/pty_handler.js"; | ||
| import { PTYError } from "../../src/interactive/models.js"; | ||
| import { Settings } from "../../src/config/settings.js"; | ||
|
|
||
| const SETTINGS = new Settings({ ENABLE_COMMAND_VALIDATION: false }); | ||
|
|
||
| function makeCollector(): { chunks: string[]; output: () => string } { | ||
| const chunks: string[] = []; | ||
| return { chunks, output: () => chunks.join("") }; | ||
| } | ||
|
|
||
| async function waitUntil(check: () => boolean, deadlineMs: number, intervalMs = 50): Promise<boolean> { | ||
| const deadline = Date.now() + deadlineMs; | ||
| while (Date.now() < deadline) { | ||
| if (check()) return true; | ||
| await new Promise<void>((r) => setTimeout(r, intervalMs)); | ||
| } | ||
| return check(); | ||
| } | ||
|
|
||
| describe("PTY Integration", () => { | ||
| let handler: PtyHandler; | ||
|
|
||
| beforeEach(() => { | ||
| handler = new PtyHandler(SETTINGS); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await handler.cleanup(); | ||
| }); | ||
|
|
||
| it("basic echo command", async () => { | ||
| const { chunks, output } = makeCollector(); | ||
| await handler.createSession(["echo", "hello world"], undefined, undefined, (d) => chunks.push(d)); | ||
| const code = await handler.waitForExit(5000); | ||
| expect(code).toBe(0); | ||
| expect(output()).toContain("hello world"); | ||
| }); | ||
|
|
||
| it("interactive input/output via cat", async () => { | ||
| const { chunks, output } = makeCollector(); | ||
| await handler.createSession(["cat"], undefined, undefined, (d) => chunks.push(d)); | ||
| expect(handler.isProcessAlive()).toBe(true); | ||
|
|
||
| handler.writeInput("test line\n"); | ||
|
|
||
| const found = await waitUntil(() => output().includes("test line"), 5000); | ||
| expect(found).toBe(true); | ||
| expect(output()).toContain("test line"); | ||
|
|
||
| await handler.terminateProcess(false); | ||
| expect(handler.isProcessAlive()).toBe(false); | ||
| }); | ||
|
|
||
| it("multi-line output from bash", async () => { | ||
| const { chunks, output } = makeCollector(); | ||
| await handler.createSession( | ||
| ["bash", "-c", "echo line1; echo line2; echo line3"], | ||
| undefined, | ||
| undefined, | ||
| (d) => chunks.push(d), | ||
| ); | ||
| const code = await handler.waitForExit(5000); | ||
| expect(code).toBe(0); | ||
| expect(output()).toContain("line1"); | ||
| expect(output()).toContain("line2"); | ||
| expect(output()).toContain("line3"); | ||
| }); | ||
|
|
||
| it("process lifecycle: spawn, verify alive, terminate, cleanup idempotent", async () => { | ||
| await handler.createSession(["sleep", "10"]); | ||
| expect(handler.isProcessAlive()).toBe(true); | ||
|
|
||
| await handler.terminateProcess(false); | ||
| expect(handler.isProcessAlive()).toBe(false); | ||
|
|
||
| await expect(handler.cleanup()).resolves.not.toThrow(); | ||
| await expect(handler.cleanup()).resolves.not.toThrow(); | ||
| }); | ||
|
|
||
| it("error handling: invalid command throws PTYError or exits non-zero", async () => { | ||
| // node-pty behavior is platform-specific: on Linux spawn() throws synchronously | ||
| // for a missing executable; on macOS the process entry is created and onExit | ||
| // fires immediately with a non-zero code. | ||
| try { | ||
| await handler.createSession(["/nonexistent/command_xyz"]); | ||
| const code = await handler.waitForExit(2000); | ||
| expect(code).not.toBeNull(); | ||
| expect(code).not.toBe(0); | ||
| } catch (e) { | ||
| expect(e).toBeInstanceOf(PTYError); | ||
| } | ||
| }); | ||
|
|
||
| it("concurrent read/write via cat", async () => { | ||
| const { chunks, output } = makeCollector(); | ||
| await handler.createSession(["cat"], undefined, undefined, (d) => chunks.push(d)); | ||
|
|
||
| const lines = ["concurrent line 0", "concurrent line 1", "concurrent line 2"]; | ||
|
|
||
| const writer = (async () => { | ||
| for (const line of lines) { | ||
| handler.writeInput(`${line}\n`); | ||
| await new Promise<void>((r) => setTimeout(r, 50)); | ||
| } | ||
| await handler.terminateProcess(false); | ||
| })(); | ||
|
|
||
| const reader = (async () => { | ||
| const found = await waitUntil( | ||
| () => lines.every((l) => output().includes(l)), | ||
| 8000, | ||
| ); | ||
| return found; | ||
| })(); | ||
|
|
||
| const [, allFound] = await Promise.all([writer, reader]); | ||
| expect(allFound).toBe(true); | ||
| for (const line of lines) { | ||
| expect(output()).toContain(line); | ||
| } | ||
| }); | ||
|
|
||
| it("environment variable and working directory", async () => { | ||
| const tmpDir = os.tmpdir(); | ||
| const tmpFile = path.join(tmpDir, `pty_test_${Date.now()}.txt`); | ||
| fs.writeFileSync(tmpFile, ""); | ||
| const filename = path.basename(tmpFile); | ||
|
|
||
| try { | ||
| const { chunks, output } = makeCollector(); | ||
| await handler.createSession( | ||
| ["bash", "-c", `echo $TEST_VAR; ls ${filename}`], | ||
| { TEST_VAR: "env_test_value" }, | ||
| tmpDir, | ||
| (d) => chunks.push(d), | ||
| ); | ||
| const code = await handler.waitForExit(5000); | ||
| expect(code).toBe(0); | ||
| expect(output()).toContain("env_test_value"); | ||
| expect(output()).toContain(filename); | ||
| } finally { | ||
| fs.unlinkSync(tmpFile); | ||
| } | ||
| }); | ||
|
|
||
| it("large output handling: 100-line bash loop", async () => { | ||
| const { chunks, output } = makeCollector(); | ||
| await handler.createSession( | ||
| ["bash", "-c", 'for i in $(seq 1 100); do echo "This is line $i with some extra text"; done'], | ||
| undefined, | ||
| undefined, | ||
| (d) => chunks.push(d), | ||
| ); | ||
| const code = await handler.waitForExit(10000); | ||
| expect(code).toBe(0); | ||
| expect(output().length).toBeGreaterThan(1000); | ||
| expect(output()).toContain("line 1"); | ||
| expect(output()).toContain("line 100"); | ||
| }); | ||
|
|
||
| it("timeout behavior: waitForExit returns null before process exits", async () => { | ||
| await handler.createSession(["sleep", "10"]); | ||
|
|
||
| const result = await handler.waitForExit(100); | ||
| expect(result).toBeNull(); | ||
| expect(handler.isProcessAlive()).toBe(true); | ||
|
|
||
| await handler.terminateProcess(true); | ||
| await waitUntil(() => !handler.isProcessAlive(), 3000); | ||
| expect(handler.isProcessAlive()).toBe(false); | ||
| }); | ||
|
|
||
| it("sequential sessions: two independent sessions", async () => { | ||
| const handler1 = new PtyHandler(SETTINGS); | ||
| const collector1 = makeCollector(); | ||
| await handler1.createSession( | ||
| ["echo", "first_session_output"], | ||
| undefined, | ||
| undefined, | ||
| (d) => collector1.chunks.push(d), | ||
| ); | ||
| const code1 = await handler1.waitForExit(5000); | ||
| await handler1.cleanup(); | ||
|
|
||
| expect(code1).toBe(0); | ||
| expect(collector1.output()).toContain("first_session_output"); | ||
|
|
||
| const collector2 = makeCollector(); | ||
| await handler.createSession( | ||
| ["echo", "second_session_output"], | ||
| undefined, | ||
| undefined, | ||
| (d) => collector2.chunks.push(d), | ||
| ); | ||
| const code2 = await handler.waitForExit(5000); | ||
|
|
||
| expect(code2).toBe(0); | ||
| expect(collector2.output()).toContain("second_session_output"); | ||
| expect(collector1.output()).not.toContain("second_session_output"); | ||
| expect(collector2.output()).not.toContain("first_session_output"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.