Skip to content

feat: make AST subprocess timeout injectable for test coverage #453

Description

@rhuanbarreto

Context

From PR #452 review: runAstSubprocess's AST_SUBPROCESS_TIMEOUT_MS (15s) timeout branch has no test coverage because the hardcoded constant makes it impractical to test without real-time waits.

Proposal

Add an optional timeoutMs parameter to runAstSubprocess() (defaulting to the module constant) so tests can inject a small value and exercise the timeout → kill → throw path deterministically.

// Before
export async function runAstSubprocess(cmd: string[]): Promise<...>

// After
export async function runAstSubprocess(cmd: string[], timeoutMs = AST_SUBPROCESS_TIMEOUT_MS): Promise<...>

Then add a test:

test("throws after the timeout and kills the subprocess", async () => {
  await expect(
    runAstSubprocess([process.execPath, "-e", "setTimeout(() => {}, 10000)"], 50)
  ).rejects.toThrow(/timed out/u);
});

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions