Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.3 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";

// Regression: the shared interactive prompt helper (createPrompt) used rl.question
// without an EOF guard, so a non-interactive stdin (pipe, CI, `< /dev/null`) left
// the promise pending — Node then warned about an "unsettled top-level await" at
// exit and the command hung. ask/askSecret now resolve on the readline `close`
// event (fired on EOF) with the default / empty string instead of hanging. close()
// here simulates that EOF/non-interactive close.

test("createPrompt.ask resolves the default on EOF (non-interactive, no hang)", async () => {
  const { createPrompt } = await import("../../bin/cli/io.mjs");
  const p = createPrompt();
  const pending = p.ask("Name", "fallback");
  p.close();
  assert.equal(await pending, "fallback");
});

test("createPrompt.ask resolves empty when there is no default on EOF", async () => {
  const { createPrompt } = await import("../../bin/cli/io.mjs");
  const p = createPrompt();
  const pending = p.ask("Name");
  p.close();
  assert.equal(await pending, "");
});

test("createPrompt.askSecret resolves empty on EOF (no hang)", async () => {
  const { createPrompt } = await import("../../bin/cli/io.mjs");
  const p = createPrompt();
  const pending = p.askSecret("Secret");
  p.close();
  assert.equal(await pending, "");
});