From f3f71c07bbd71e1b350ff310eb604a4550de8d2d Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 21:39:52 +0530 Subject: [PATCH 01/17] fix(core): treat inquirer 12's ExitPromptError as Ctrl-C at a prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In raw mode Ctrl-C reaches inquirer 12 as a keypress, not a process SIGINT, and the prompt rejects with ExitPromptError. The prompt wrapper now turns that rejection into CancelledError (exit 3), as it does for a SIGINT. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/core/interruptible-ux.test.ts | 14 ++++++++++++++ src/core/interruptible-ux.ts | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/interruptible-ux.test.ts b/src/core/interruptible-ux.test.ts index c1341bf4..006be8bb 100644 --- a/src/core/interruptible-ux.test.ts +++ b/src/core/interruptible-ux.test.ts @@ -88,6 +88,20 @@ describe('cancelOnInterrupt', () => { expect(signals.listenerCount('SIGINT')).toBe(1); }); + it('rejects with CancelledError when the prompt itself reports Ctrl-C, as inquirer 12 does in raw mode, then stops listening', async () => { + const signals = new EventEmitter(); + const inner = pendingUx(); + const loop = recordingHold(); + const ctrlC = Object.assign(new Error('User force closed the prompt with SIGINT'), { name: 'ExitPromptError' }); + + const answer = cancelOnInterrupt(inner.ux, { signals, hold: loop.hold }).inquire(QUESTION); + inner.settle({ error: ctrlC }); + + await expect(answer).rejects.toBeInstanceOf(CancelledError); + expect(signals.listenerCount('SIGINT')).toBe(0); + expect(loop.events).toEqual(['held', 'released']); + }); + it('propagates the prompt failure unchanged rather than calling it a cancellation, then stops listening', async () => { const signals = new EventEmitter(); const inner = pendingUx(); diff --git a/src/core/interruptible-ux.ts b/src/core/interruptible-ux.ts index bd50bc0b..a4ec72ff 100644 --- a/src/core/interruptible-ux.ts +++ b/src/core/interruptible-ux.ts @@ -34,6 +34,10 @@ export function onInterrupt(listener: () => void, signals: InterruptSource = pro return release; } +function isPromptExit(error: unknown): boolean { + return error instanceof Error && error.name === 'ExitPromptError'; +} + export interface InterruptOptions { signals?: InterruptSource; hold?: () => Release; @@ -58,7 +62,7 @@ export function cancelOnInterrupt(ux: UxLike, options: InterruptOptions = {}): U const fail = (error: unknown): void => { release(); - reject(error); + reject(isPromptExit(error) ? new CancelledError() : error); }; signals.on('SIGINT', cancel); From 68f30543e725f84ff9eb82c698f2a35169c6a48b Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 21:41:13 +0530 Subject: [PATCH 02/17] fix(core): cancel with exit 3 when Ctrl-C aborts a search-list prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit inquirer 12 runs search-list as a legacy prompt: on Ctrl-C it rejects with AbortPromptError and then raises a real SIGINT. The wrapper used to stop listening on that rejection, so the SIGINT found no listener. It now keeps listening, and the SIGINT cancels the prompt with CancelledError. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/core/interruptible-ux.test.ts | 19 +++++++++++++++++++ src/core/interruptible-ux.ts | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/core/interruptible-ux.test.ts b/src/core/interruptible-ux.test.ts index 006be8bb..c420b733 100644 --- a/src/core/interruptible-ux.test.ts +++ b/src/core/interruptible-ux.test.ts @@ -102,6 +102,25 @@ describe('cancelOnInterrupt', () => { expect(loop.events).toEqual(['held', 'released']); }); + it('keeps listening when a search-list prompt is aborted, so the SIGINT inquirer raises next cancels instead of killing the process', async () => { + const signals = new EventEmitter(); + const inner = pendingUx(); + const loop = recordingHold(); + const aborted = Object.assign(new Error('Prompt was aborted'), { name: 'AbortPromptError' }); + + const answer = cancelOnInterrupt(inner.ux, { signals, hold: loop.hold }).inquire(QUESTION); + inner.settle({ error: aborted }); + await new Promise((done) => setImmediate(done)); + const listeningAfterAbort = signals.listenerCount('SIGINT'); + signals.emit('SIGINT'); + + await expect(answer).rejects.toBeInstanceOf(CancelledError); + expect(listeningAfterAbort).toBe(1); + await new Promise((done) => setImmediate(done)); + expect(signals.listenerCount('SIGINT')).toBe(0); + expect(loop.events).toEqual(['held', 'released']); + }); + it('propagates the prompt failure unchanged rather than calling it a cancellation, then stops listening', async () => { const signals = new EventEmitter(); const inner = pendingUx(); diff --git a/src/core/interruptible-ux.ts b/src/core/interruptible-ux.ts index a4ec72ff..7df2e62a 100644 --- a/src/core/interruptible-ux.ts +++ b/src/core/interruptible-ux.ts @@ -38,6 +38,10 @@ function isPromptExit(error: unknown): boolean { return error instanceof Error && error.name === 'ExitPromptError'; } +function isPromptAbort(error: unknown): boolean { + return error instanceof Error && error.name === 'AbortPromptError'; +} + export interface InterruptOptions { signals?: InterruptSource; hold?: () => Release; @@ -61,6 +65,11 @@ export function cancelOnInterrupt(ux: UxLike, options: InterruptOptions = {}): U }; const fail = (error: unknown): void => { + // inquirer 12 aborts a legacy search-list prompt on Ctrl-C, then raises the SIGINT `cancel` answers. + if (isPromptAbort(error)) { + return; + } + release(); reject(isPromptExit(error) ? new CancelledError() : error); }; From 629b918afc24cab57c08b2ba33cb13b21a72afeb Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 21:43:16 +0530 Subject: [PATCH 03/17] feat(core): add terminalUx, which prompts through inquirer 12 directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cliux.inquire catches inquirer's ExitPromptError and calls process.exit(130) before a caller can see it. terminalUx asks the same inquirer instance (the one search-list is registered with) and lets the rejection through, so the Ctrl-C wrapper can map it to exit 3. It prints through cliux as before. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/core/search-list.ts | 2 +- src/core/terminal-ux.test.ts | 48 ++++++++++++++++++++++++++++++++++++ src/core/terminal-ux.ts | 23 +++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/core/terminal-ux.test.ts create mode 100644 src/core/terminal-ux.ts diff --git a/src/core/search-list.ts b/src/core/search-list.ts index b688150b..976d64c2 100644 --- a/src/core/search-list.ts +++ b/src/core/search-list.ts @@ -26,7 +26,7 @@ export type SearchListClass = new (...params: never[]) => SearchListPrompt; export type ModuleLoader = (id: string) => unknown; export interface PromptRegistry { - prompt: { prompts: Record }; + prompt: ((question: unknown) => Promise>) & { prompts: Record }; registerPrompt(name: string, prompt: unknown): void; restoreDefaultPrompts(): void; } diff --git a/src/core/terminal-ux.test.ts b/src/core/terminal-ux.test.ts new file mode 100644 index 00000000..633d0b19 --- /dev/null +++ b/src/core/terminal-ux.test.ts @@ -0,0 +1,48 @@ +import { promptLibrary } from './search-list'; +import { libraryUx, terminalUx } from './terminal-ux'; + +const QUESTION = { type: 'list', name: 'value', message: 'Choose an environment', choices: ['Default'] }; + +describe('libraryUx', () => { + it('asks the question through the prompt library and resolves with the answer to the named question', async () => { + const asked: unknown[] = []; + const library = { + prompt: async (question: unknown) => { + asked.push(question); + return { value: 'Default' }; + }, + }; + + const answer = await libraryUx(() => library, noPrinting).inquire(QUESTION); + + expect(answer).toBe('Default'); + expect(asked).toEqual([QUESTION]); + }); + + it('prints through the printer it was given', () => { + const printed: string[] = []; + + libraryUx(unusedLibrary, (message) => printed.push(message)).print('Using the organization Acme.'); + + expect(printed).toEqual(['Using the organization Acme.']); + }); +}); + +describe('terminalUx', () => { + it('asks through the inquirer cli-utilities ships, the one search-list is registered with', async () => { + const prompt = jest.spyOn(promptLibrary(), 'prompt').mockResolvedValue({ value: 'Default' }); + + const answer = await terminalUx.inquire(QUESTION); + + expect(answer).toBe('Default'); + expect(prompt).toHaveBeenCalledWith(QUESTION); + }); +}); + +function noPrinting(): void { + return undefined; +} + +function unusedLibrary(): never { + throw new Error('printing must not reach the prompt library'); +} diff --git a/src/core/terminal-ux.ts b/src/core/terminal-ux.ts new file mode 100644 index 00000000..705ef48d --- /dev/null +++ b/src/core/terminal-ux.ts @@ -0,0 +1,23 @@ +import { cliux } from '@contentstack/cli-utilities'; + +import type { UxLike } from './prompt'; +import { promptLibrary } from './search-list'; + +export interface Prompter { + prompt(question: unknown): Promise>; +} + +export function libraryUx(library: () => Prompter, print: (message: string) => void): UxLike { + return { + print, + inquire: async (payload: unknown): Promise => { + const { name } = payload as { name: string }; + const answers = await library().prompt(payload); + + return answers[name] as T; + }, + }; +} + +// cliux.inquire calls process.exit(130) on Ctrl-C itself, so prompts skip it and reach the inquirer it wraps. +export const terminalUx: UxLike = libraryUx(promptLibrary, (message) => cliux.print(message)); From 418812cb893fccfd2d4f053c1f1e08f15a2e2d8c Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 21:51:04 +0530 Subject: [PATCH 04/17] fix(core): prompt through terminalUx so Ctrl-C at any prompt exits 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LaunchCommand's ux is now cancelOnInterrupt(terminalUx) instead of cancelOnInterrupt(cliux), so inquirer's ExitPromptError reaches the wrapper and becomes CancelledError rather than cli-utilities' process.exit(130). Tests stub prompts at terminalUx.inquire (stubPrompts in test/support/terminal.ts) instead of cliux.inquire, and answerPrompts' CTRL_C now rejects with ExitPromptError, which is what a real Ctrl-C does, instead of emitting a SIGINT that no longer reaches an open prompt. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/core/launch-command.ts | 5 ++-- src/core/terminal-ux.test.ts | 2 ++ src/core/terminal-ux.ts | 2 +- test/guards/prompt-funnel.test.ts | 9 +++--- test/integration/deployments-cancel.test.ts | 6 ++-- test/integration/deployments-rollback.test.ts | 6 ++-- test/integration/logs-get.test.ts | 3 +- test/integration/organization-prompt.test.ts | 6 ++-- .../projects-command-flows.test.ts | 8 +++--- test/integration/projects-delete.test.ts | 6 ++-- test/integration/secrets-set.test.ts | 11 ++++---- test/integration/secrets-unset.test.ts | 13 +++++---- test/no-terminal.setup.ts | 8 ++---- test/support/terminal.ts | 28 +++++++++++++------ 14 files changed, 64 insertions(+), 49 deletions(-) diff --git a/src/core/launch-command.ts b/src/core/launch-command.ts index 46b518f4..1ced48ad 100644 --- a/src/core/launch-command.ts +++ b/src/core/launch-command.ts @@ -1,7 +1,7 @@ import { resolve as resolvePath } from 'node:path'; import { Command } from '@contentstack/cli-command'; -import { cliux, configHandler, isAuthenticated } from '@contentstack/cli-utilities'; +import { configHandler, isAuthenticated } from '@contentstack/cli-utilities'; import { EXIT_RUNTIME, PROJECT_CONFIG_FILE, STDIN_MAX_LISTENERS } from './constants'; import type { ProjectConfig } from './project-config'; @@ -18,6 +18,7 @@ import { cancelOnInterrupt } from './interruptible-ux'; import { refusePasswordOnArgv } from './password-argv'; import type { UxLike } from './prompt'; import { registerSearchList } from './search-list'; +import { terminalUx } from './terminal-ux'; import type { FailureOutput } from './failure'; import { failWith, failureOutputOf, reportFailure } from './failure'; import type { ServiceContext } from './service-context'; @@ -109,7 +110,7 @@ export abstract class LaunchCommand extends Com protected resolved!: Resolved; protected dataDir!: string; protected configPath!: string; - protected ux: UxLike = cancelOnInterrupt(cliux); + protected ux: UxLike = cancelOnInterrupt(terminalUx); protected get launchRegion(): RegionLike | undefined { return configHandler.get('region') as RegionLike | undefined; diff --git a/src/core/terminal-ux.test.ts b/src/core/terminal-ux.test.ts index 633d0b19..59440d65 100644 --- a/src/core/terminal-ux.test.ts +++ b/src/core/terminal-ux.test.ts @@ -29,6 +29,8 @@ describe('libraryUx', () => { }); describe('terminalUx', () => { + beforeEach(() => jest.mocked(terminalUx.inquire).mockRestore()); + it('asks through the inquirer cli-utilities ships, the one search-list is registered with', async () => { const prompt = jest.spyOn(promptLibrary(), 'prompt').mockResolvedValue({ value: 'Default' }); diff --git a/src/core/terminal-ux.ts b/src/core/terminal-ux.ts index 705ef48d..a08fa8fb 100644 --- a/src/core/terminal-ux.ts +++ b/src/core/terminal-ux.ts @@ -19,5 +19,5 @@ export function libraryUx(library: () => Prompter, print: (message: string) => v }; } -// cliux.inquire calls process.exit(130) on Ctrl-C itself, so prompts skip it and reach the inquirer it wraps. +// cli-utilities' own inquire calls process.exit(130) on Ctrl-C, so prompts go to the inquirer it wraps instead. export const terminalUx: UxLike = libraryUx(promptLibrary, (message) => cliux.print(message)); diff --git a/test/guards/prompt-funnel.test.ts b/test/guards/prompt-funnel.test.ts index 8970376f..da2b3f15 100644 --- a/test/guards/prompt-funnel.test.ts +++ b/test/guards/prompt-funnel.test.ts @@ -1,14 +1,14 @@ -import { cliux } from '@contentstack/cli-utilities'; - import { EXIT_CANCELLED } from '../../src/core/constants'; import { CancelledError } from '../../src/core/errors'; import { LaunchCommand } from '../../src/core/launch-command'; import type { UxLike } from '../../src/core/prompt'; +import { terminalUx } from '../../src/core/terminal-ux'; import type { Occurrence, SourceFile } from '../support/sources'; import { describeOccurrence, occurrences, productionSources } from '../support/sources'; +import { ctrlC } from '../support/terminal'; const FUNNEL_FILE = 'core/launch-command.ts'; -const FUNNEL_CALL = 'cancelOnInterrupt(cliux)'; +const FUNNEL_CALL = 'cancelOnInterrupt(terminalUx)'; const REGISTRATION_FILE = 'core/search-list.ts'; const PROMPT_LIBRARIES = /['"](inquirer|inquirer-[\w-]+|@inquirer\/[\w-]+|enquirer|prompts|(node:)?readline)['"]/; const PROMPT_METHODS = 'inquire|prompt|confirm'; @@ -77,11 +77,10 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e }); it('turns Ctrl-C at any prompt a LaunchCommand issues into CancelledError with exit 3', async () => { - jest.spyOn(cliux, 'inquire').mockImplementation(() => new Promise(() => undefined)); + jest.spyOn(terminalUx, 'inquire').mockRejectedValue(ctrlC()); const ux = (new FreshCommand([], {} as never) as unknown as { ux: UxLike }).ux; const answer = ux.inquire({ type: 'input', name: 'value', message: 'Project name' }); - process.emit('SIGINT'); await expect(answer).rejects.toBeInstanceOf(CancelledError); await expect(answer).rejects.toHaveProperty('exitCode', EXIT_CANCELLED); diff --git a/test/integration/deployments-cancel.test.ts b/test/integration/deployments-cancel.test.ts index 482c2ba3..21b0aa74 100644 --- a/test/integration/deployments-cancel.test.ts +++ b/test/integration/deployments-cancel.test.ts @@ -1,13 +1,13 @@ import { tmpdir } from 'node:os'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; import getFixture from '../fixtures/deployment-get.json'; import notFoundFixture from '../fixtures/deployment-not-found.json'; -import { CTRL_C, answerPrompts, onTerminal, pretendTerminal } from '../support/terminal'; +import { answerPrompts, CTRL_C, onTerminal, pretendTerminal, stubPrompts } from '../support/terminal'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; import { projectOwnership } from '../support/project-ownership'; @@ -181,7 +181,7 @@ describe('integration: launch:deployments:cancel on the wire', () => { const cancel = cancelScope().post(CANCEL_PATH).reply(200, {}); const restore = pretendTerminal(); const inquired: unknown[] = []; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { + stubPrompts((payload) => { inquired.push(payload); return false as never; }); diff --git a/test/integration/deployments-rollback.test.ts b/test/integration/deployments-rollback.test.ts index fff80ec5..e5016497 100644 --- a/test/integration/deployments-rollback.test.ts +++ b/test/integration/deployments-rollback.test.ts @@ -1,6 +1,6 @@ import { tmpdir } from 'node:os'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; @@ -8,7 +8,7 @@ import nock from 'nock'; import * as watcher from '../../src/deployments/deployment.watcher'; import getFixture from '../fixtures/deployment-get.json'; import notFoundFixture from '../fixtures/deployment-not-found.json'; -import { CTRL_C, answerPrompts, onTerminal, pretendTerminal } from '../support/terminal'; +import { answerPrompts, CTRL_C, onTerminal, pretendTerminal, stubPrompts } from '../support/terminal'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; import { projectOwnership } from '../support/project-ownership'; @@ -189,7 +189,7 @@ describe('integration: launch:deployments:rollback on the wire', () => { const rollback = hub().post(`${DEPLOYMENTS}/rollback`).reply(200, {}); const restore = pretendTerminal(); const inquired: unknown[] = []; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { + stubPrompts((payload) => { inquired.push(payload); return false as never; }); diff --git a/test/integration/logs-get.test.ts b/test/integration/logs-get.test.ts index 76cbdd50..cd28e4ae 100644 --- a/test/integration/logs-get.test.ts +++ b/test/integration/logs-get.test.ts @@ -7,6 +7,7 @@ import { runCommand } from '@oclif/test'; import nock from 'nock'; import * as watcher from '../../src/deployments/deployment.watcher'; +import { terminalUx } from '../../src/core/terminal-ux'; import { EVENT_STREAM_IDLE_TIMEOUT_MS } from '../../src/transport/event-stream'; import listFixture from '../fixtures/deployments-list.json'; import notFoundFixture from '../fixtures/deployment-not-found.json'; @@ -198,7 +199,7 @@ describe('integration: launch:logs:get on the wire', () => { expect(other.isDone()).toBe(false); expect(outputLines(stdout)).toEqual(['2026-10-28 10:00:00.000: Installing dependencies...', 'Deployment #4 is LIVE.']); expect(answered.messages).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); expect(onWire).toEqual([]); } finally { restoreStdin(); diff --git a/test/integration/organization-prompt.test.ts b/test/integration/organization-prompt.test.ts index fa4adcba..5eb07b5e 100644 --- a/test/integration/organization-prompt.test.ts +++ b/test/integration/organization-prompt.test.ts @@ -1,12 +1,12 @@ import { randomUUID } from 'node:crypto'; import { tmpdir } from 'node:os'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; -import { pretendTerminal } from '../support/terminal'; +import { pretendTerminal, stubPrompts } from '../support/terminal'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; import { projectOwnership } from '../support/project-ownership'; @@ -65,7 +65,7 @@ function answering(answers: unknown[]): unknown[] { const inquired: unknown[] = []; let index = 0; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { + stubPrompts((payload) => { inquired.push(payload); const answer = answers[index]; index += 1; diff --git a/test/integration/projects-command-flows.test.ts b/test/integration/projects-command-flows.test.ts index 2fb37c8e..ed4ec3ab 100644 --- a/test/integration/projects-command-flows.test.ts +++ b/test/integration/projects-command-flows.test.ts @@ -3,12 +3,12 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; -import { pretendTerminal } from '../support/terminal'; +import { pretendTerminal, stubPrompts } from '../support/terminal'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; import getFixture from '../fixtures/project-get.json'; @@ -256,7 +256,7 @@ describe('integration: end-to-end command flows', () => { useSession(basicSession()); const restoreTTY = pretendTerminal(); const inquired: unknown[] = []; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { + stubPrompts((payload) => { inquired.push(payload); return PROJECT_UID as never; }); @@ -288,7 +288,7 @@ describe('integration: end-to-end command flows', () => { it('exits 3 when the picker comes back with nothing chosen', async () => { useSession(basicSession()); const restoreTTY = pretendTerminal(); - jest.spyOn(cliux, 'inquire').mockResolvedValue(undefined as never); + stubPrompts(() => undefined); nock(LAUNCH_HUB_URL).get('/manage/projects').query({ limit: '100', skip: '0' }).reply(200, listFixture); const { error } = await runLaunch(['launch:projects:get', '--org', ORG_UID, '--data-dir', tmpdir()]); diff --git a/test/integration/projects-delete.test.ts b/test/integration/projects-delete.test.ts index 3f1b332f..3a2a6253 100644 --- a/test/integration/projects-delete.test.ts +++ b/test/integration/projects-delete.test.ts @@ -1,11 +1,11 @@ import { tmpdir } from 'node:os'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; -import { CTRL_C, answerPrompts, onTerminal, pretendTerminal } from '../support/terminal'; +import { answerPrompts, CTRL_C, onTerminal, pretendTerminal, stubPrompts } from '../support/terminal'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; import { projectOwnership } from '../support/project-ownership'; @@ -151,7 +151,7 @@ describe('integration: launch:projects:delete on the wire', () => { const removal = nock(LAUNCH_HUB_URL, BODYLESS).delete(`/manage/projects/${PROJECT_UID}`).query({}).reply(204); const restore = pretendTerminal(); const inquired: unknown[] = []; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { + stubPrompts((payload) => { inquired.push(payload); return false as never; }); diff --git a/test/integration/secrets-set.test.ts b/test/integration/secrets-set.test.ts index eb8eb98f..0080ba06 100644 --- a/test/integration/secrets-set.test.ts +++ b/test/integration/secrets-set.test.ts @@ -4,12 +4,13 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { Readable } from 'node:stream'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; import { DEFAULT_SECRET_IO } from '../../src/secrets/secret.value'; +import { terminalUx } from '../../src/core/terminal-ux'; import { projectOwnership } from '../support/project-ownership'; import { gluedValue } from '../support/glued-value'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; @@ -160,7 +161,7 @@ describe('integration: launch:secrets:set on the wire', () => { expect([list.isDone(), write.isDone()]).toEqual([true, true]); expect(sent).toEqual([{ method: 'POST', path: COLLECTION_PATH, body: { key: 'API_TOKEN', value } }]); expect(onWire).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); expect(stdout).toBe('āœ” Secret API_TOKEN added.\n'); expect(stdout + stderr).not.toContain(value); }); @@ -276,7 +277,7 @@ describe('integration: launch:secrets:set on the wire', () => { expect(error?.message).toContain('Pass --yes when piping the value'); expect(reads).toEqual([]); expect([list.isDone(), write.isDone()]).toEqual([false, false]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); }); it.each([['NEXT_PUBLIC_API'], ['NUXT_PUBLIC_API'], ['VITE_API'], ['GATSBY_API'], ['PUBLIC_API']])( @@ -365,7 +366,7 @@ describe('integration: launch:secrets:set on the wire', () => { expect(reads).toEqual([]); expect([list.isDone(), write.isDone()]).toEqual([false, false]); expect(onWire).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); }); it('S5 sends a key with a slash as one encoded segment on a PUT', async () => { @@ -521,7 +522,7 @@ describe('integration: launch:secrets:set on the wire', () => { expect(error?.oclif?.exit).toBe(2); expect(error?.message).toContain(`Missing required value for ${flag}`); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); expect(sent).toEqual([]); }); diff --git a/test/integration/secrets-unset.test.ts b/test/integration/secrets-unset.test.ts index a762b432..96c6b55a 100644 --- a/test/integration/secrets-unset.test.ts +++ b/test/integration/secrets-unset.test.ts @@ -2,11 +2,12 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { authHandler, cliux, configHandler } from '@contentstack/cli-utilities'; +import { authHandler, configHandler } from '@contentstack/cli-utilities'; import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; +import { terminalUx } from '../../src/core/terminal-ux'; import { projectOwnership } from '../support/project-ownership'; import { gluedValue } from '../support/glued-value'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; @@ -116,7 +117,7 @@ describe('integration: launch:secrets:unset on the wire', () => { expect([first.isDone(), second.isDone()]).toEqual([true, true]); expect(deleted).toEqual([`${COLLECTION_PATH}/DB_PASSWORD`, `${COLLECTION_PATH}/API_TOKEN`]); expect(onWire).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); expect(stdout).toBe('āœ” Secret DB_PASSWORD removed.\nāœ” Secret API_TOKEN removed.\n'); expect(stderr).toBe(''); }); @@ -175,7 +176,7 @@ describe('integration: launch:secrets:unset on the wire', () => { expect(write.isDone()).toBe(false); expect(deleted).toEqual([]); expect(onWire).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); expect(stdout).toBe(''); }); @@ -229,7 +230,7 @@ describe('integration: launch:secrets:unset on the wire', () => { expect(write.isDone()).toBe(false); expect(deleted).toEqual([]); expect(onWire).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); }); it('U5 words a 403 as a permission failure for the key and exits 1', async () => { @@ -263,7 +264,7 @@ describe('integration: launch:secrets:unset on the wire', () => { expect(error?.message).toContain('--key'); expect(write.isDone()).toBe(false); expect(onWire).toEqual([]); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); }); it('U7 encodes a key with special characters as one path segment', async () => { @@ -306,7 +307,7 @@ describe('integration: launch:secrets:unset on the wire', () => { expect(error?.oclif?.exit).toBe(2); expect(error?.message).toContain(`Missing required value for ${flag}`); - expect(cliux.inquire).not.toHaveBeenCalled(); + expect(terminalUx.inquire).not.toHaveBeenCalled(); expect(deleted).toEqual([]); }); diff --git a/test/no-terminal.setup.ts b/test/no-terminal.setup.ts index 2df6c424..d43a5c58 100644 --- a/test/no-terminal.setup.ts +++ b/test/no-terminal.setup.ts @@ -1,6 +1,4 @@ -import { cliux } from '@contentstack/cli-utilities'; - -import { stdinReportingTTY, stdoutOfWidth, stdoutReportingTTY } from './support/terminal'; +import { stdinReportingTTY, stdoutOfWidth, stdoutReportingTTY, stubPrompts } from './support/terminal'; let restoreTerminal: (() => void)[] = []; @@ -10,8 +8,8 @@ beforeEach(() => { // and no table truncation that depends on how wide the window happens to be. restoreTerminal = [stdinReportingTTY(false), stdoutReportingTTY(false), stdoutOfWidth(undefined)]; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { - const message = String((payload as Record | undefined)?.message ?? ''); + stubPrompts((payload) => { + const message = String(payload.message ?? ''); throw new Error( `A test reached a real interactive prompt ("${message}"). Mock it with answerPrompts, or it would ` + 'block on stdin whenever the suite runs in a real terminal.', diff --git a/test/support/terminal.ts b/test/support/terminal.ts index 09ebf58b..80b4a733 100644 --- a/test/support/terminal.ts +++ b/test/support/terminal.ts @@ -1,4 +1,4 @@ -import { cliux } from '@contentstack/cli-utilities'; +import { terminalUx } from '../../src/core/terminal-ux'; type Stream = NodeJS.ReadStream | NodeJS.WriteStream; @@ -50,25 +50,37 @@ export interface AnsweredPrompts { payloads: Record[]; } +export type PromptHandler = (payload: Record) => unknown; + +// Stubs the terminal every LaunchCommand prompt reaches, answering each question with what `answer` returns for it. +export function stubPrompts(answer: PromptHandler): jest.SpyInstance { + return jest + .spyOn(terminalUx, 'inquire') + .mockImplementation(async (payload: unknown) => answer(payload as Record) as never); +} + +// What inquirer 12 rejects with when Ctrl-C reaches a prompt in raw mode, where it is a keypress rather than a SIGINT. +export function ctrlC(): Error { + return Object.assign(new Error('User force closed the prompt with SIGINT'), { name: 'ExitPromptError' }); +} + export function answerPrompts(answers: Record): AnsweredPrompts { const recorded: AnsweredPrompts = { messages: [], payloads: [] }; - jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => { - const record = payload as Record; - const message = String(record.message); + stubPrompts((payload) => { + const message = String(payload.message); recorded.messages.push(message); - recorded.payloads.push(record); + recorded.payloads.push(payload); if (!(message in answers)) { throw new Error(`Unexpected prompt: ${message}`); } if (answers[message] === CTRL_C) { - setImmediate(() => process.emit('SIGINT')); - return new Promise(() => undefined); + throw ctrlC(); } - return answers[message] as never; + return answers[message]; }); return recorded; From 2ca33a858c926812ad07c449a66105280e3feab1 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 21:53:03 +0530 Subject: [PATCH 05/17] test(guards): keep every prompt behind the Ctrl-C wrapper now that it wraps terminalUx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prompt-funnel guard now expects LaunchCommand's ux to be built as cancelOnInterrupt(terminalUx), and flags two new ways around the wrapper: any use of promptLibrary outside search-list.ts and terminal-ux.ts, and any use of terminalUx other than that one funnel line. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- test/guards/prompt-funnel.test.ts | 35 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/test/guards/prompt-funnel.test.ts b/test/guards/prompt-funnel.test.ts index da2b3f15..a9b0e511 100644 --- a/test/guards/prompt-funnel.test.ts +++ b/test/guards/prompt-funnel.test.ts @@ -10,6 +10,7 @@ import { ctrlC } from '../support/terminal'; const FUNNEL_FILE = 'core/launch-command.ts'; const FUNNEL_CALL = 'cancelOnInterrupt(terminalUx)'; const REGISTRATION_FILE = 'core/search-list.ts'; +const TERMINAL_FILE = 'core/terminal-ux.ts'; const PROMPT_LIBRARIES = /['"](inquirer|inquirer-[\w-]+|@inquirer\/[\w-]+|enquirer|prompts|(node:)?readline)['"]/; const PROMPT_METHODS = 'inquire|prompt|confirm'; @@ -34,23 +35,35 @@ function cliuxNames(source: SourceFile): string[] { ); } +function isImport(use: Occurrence): boolean { + return /^import\b/.test(use.text); +} + +function isTheFunnel(use: Occurrence): boolean { + return use.path === FUNNEL_FILE && use.text.includes(FUNNEL_CALL); +} + function detours(source: SourceFile): Occurrence[] { const direct = cliuxNames(source).flatMap((name) => [ ...occurrences(source, new RegExp(`\\b${name}\\s*(\\??\\.)\\s*(${PROMPT_METHODS})\\b`)), - ...occurrences(source, new RegExp(`\\b${name}\\b(?!\\s*\\??\\.)`)).filter( - (use) => - !/^import\b/.test(use.text) && !(source.path === FUNNEL_FILE && use.text.includes(FUNNEL_CALL)), - ), + ...occurrences(source, new RegExp(`\\b${name}\\b(?!\\s*\\??\\.)`)).filter((use) => !isImport(use)), ]); const libraries = source.path === REGISTRATION_FILE ? [] : occurrences(source, PROMPT_LIBRARIES); const registrationPrompts = source.path === REGISTRATION_FILE ? occurrences(source, new RegExp(`\\.(${PROMPT_METHODS})\\s*\\(`)) : []; + const libraryCalls = [REGISTRATION_FILE, TERMINAL_FILE].includes(source.path) + ? [] + : occurrences(source, /\bpromptLibrary\b/).filter((use) => !isImport(use)); + const unwrappedTerminal = + source.path === TERMINAL_FILE + ? [] + : occurrences(source, /\bterminalUx\b/).filter((use) => !isImport(use) && !isTheFunnel(use)); const wholeModule = [ ...occurrences(source, /import\s*\*\s*as\s+\w+\s+from\s*'@contentstack\/cli-utilities'/), ...occurrences(source, /\brequire\(\s*'@contentstack\/cli-utilities'/), ]; - return [...direct, ...libraries, ...registrationPrompts, ...wholeModule]; + return [...direct, ...libraries, ...registrationPrompts, ...libraryCalls, ...unwrappedTerminal, ...wholeModule]; } function promptDetoursIn(sources: SourceFile[]): string[] { @@ -68,7 +81,7 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e expect(promptDetoursIn(productionSources())).toEqual([]); }); - it('builds the command ux from cliux exactly once, through the Ctrl-C wrapper', () => { + it('builds the command ux from terminalUx exactly once, through the Ctrl-C wrapper', () => { const funnels = productionSources().flatMap((source) => occurrences(source, /(? `${use.path} ${use.text}`), ); @@ -102,6 +115,9 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e { path: 'logs/logs.prompt.ts', text: 'import * as utilities from \'@contentstack/cli-utilities\';' }, { path: 'core/search-list.ts', text: 'await load(\'inquirer\').prompt([question]);' }, { path: 'core/launch-command.ts', text: 'protected ux: UxLike = cliux;\nimport { cliux } from \'@contentstack/cli-utilities\';' }, + { path: 'cache/purge.prompt.ts', text: 'const answers = await promptLibrary().prompt(question);' }, + { path: 'environments/environment.prompt.ts', text: 'const name = await terminalUx.inquire(question);' }, + { path: 'deployments/deployment.prompt.ts', text: 'const ux = libraryUx(promptLibrary, print);' }, ]; expect(promptDetoursIn(sources).map((detour) => detour.split(' <-')[0])).toEqual([ @@ -112,6 +128,9 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e 'src/logs/logs.prompt.ts:1 import * as utilities from \'@contentstack/cli-utilities\';', 'src/core/search-list.ts:1 await load(\'inquirer\').prompt([question]);', 'src/core/launch-command.ts:1 protected ux: UxLike = cliux;', + 'src/cache/purge.prompt.ts:1 const answers = await promptLibrary().prompt(question);', + 'src/environments/environment.prompt.ts:1 const name = await terminalUx.inquire(question);', + 'src/deployments/deployment.prompt.ts:1 const ux = libraryUx(promptLibrary, print);', ]); }); @@ -125,6 +144,10 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e path: 'core/search-list.ts', text: 'const inquirer = load(\'inquirer\');\ninquirer.registerPrompt(\'search-list\', SearchList);', }, + { + path: 'core/terminal-ux.ts', + text: 'export const terminalUx: UxLike = libraryUx(promptLibrary, (message) => cliux.print(message));', + }, ]; expect(promptDetoursIn(sources)).toEqual([]); From 114abc4e1f40d9ce5aa6da2f3c35dd81e7f3d278 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 21:55:47 +0530 Subject: [PATCH 06/17] test: press a real Ctrl-C at every kind of prompt on a pseudo-terminal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prompt guards simulated Ctrl-C by emitting SIGINT, which is how the cli-utilities 2 regression (CL-8790) stayed green: in raw mode Ctrl-C reaches inquirer as typed input, never as a signal. This test opens a real prompt (input, list, checkbox, confirm, search-list) through LaunchCommand's ux on a pty, types Ctrl-C, and expects exit 3. Against the old cancelOnInterrupt(cliux) funnel it fails with 130, and with 1 at search-list. The driver is a Python stdlib pty script, so it needs no native module. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../prompt-ctrl-c-on-a-terminal.test.ts | 37 +++++++++++ test/support/pty/ctrl-c-prompt.fixture.ts | 24 +++++++ test/support/pty/press-ctrl-c.py | 63 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 test/integration/prompt-ctrl-c-on-a-terminal.test.ts create mode 100644 test/support/pty/ctrl-c-prompt.fixture.ts create mode 100644 test/support/pty/press-ctrl-c.py diff --git a/test/integration/prompt-ctrl-c-on-a-terminal.test.ts b/test/integration/prompt-ctrl-c-on-a-terminal.test.ts new file mode 100644 index 00000000..f193892d --- /dev/null +++ b/test/integration/prompt-ctrl-c-on-a-terminal.test.ts @@ -0,0 +1,37 @@ +import { execFileSync } from 'node:child_process'; +import { join } from 'node:path'; + +import { EXIT_CANCELLED } from '../../src/core/constants'; + +const PTY = join(__dirname, '..', 'support', 'pty'); +const PROMPT_ON_SCREEN = 'Choose an environment'; + +function exitCodeAfterCtrlC(promptType: string): number { + const output = execFileSync( + 'python3', + [ + '-I', + join(PTY, 'press-ctrl-c.py'), + PROMPT_ON_SCREEN, + process.execPath, + '-r', + 'ts-node/register/transpile-only', + join(PTY, 'ctrl-c-prompt.fixture.ts'), + promptType, + ], + { encoding: 'utf8' }, + ); + + return Number(output.trim()); +} + +// Simulating SIGINT hid CL-8790: in raw mode Ctrl-C reaches inquirer as typed input, so type it for real. +describe('Ctrl-C at a real prompt on a terminal', () => { + it.each(['input', 'list', 'checkbox', 'confirm', 'search-list'])( + 'exits 3 as cancelled at the %s prompt', + (promptType) => { + expect(exitCodeAfterCtrlC(promptType)).toBe(EXIT_CANCELLED); + }, + 60_000, + ); +}); diff --git a/test/support/pty/ctrl-c-prompt.fixture.ts b/test/support/pty/ctrl-c-prompt.fixture.ts new file mode 100644 index 00000000..768ca3a9 --- /dev/null +++ b/test/support/pty/ctrl-c-prompt.fixture.ts @@ -0,0 +1,24 @@ +import { LaunchCommand } from '../../../src/core/launch-command'; +import type { UxLike } from '../../../src/core/prompt'; +import { registerSearchList } from '../../../src/core/search-list'; + +class PromptingCommand extends LaunchCommand { + static flags = {}; + static inputs = {}; + + async run(): Promise { + return undefined; + } +} + +registerSearchList(); +const ux = (new PromptingCommand([], {} as never) as unknown as { ux: UxLike }).ux; +const choices = [ + { name: 'Default', value: 'default' }, + { name: 'Staging', value: 'staging' }, +]; + +ux.inquire({ type: process.argv[2], name: 'value', message: 'Choose an environment', choices }).then( + () => process.exit(0), + (error: { exitCode?: number }) => process.exit(error.exitCode ?? 1), +); diff --git a/test/support/pty/press-ctrl-c.py b/test/support/pty/press-ctrl-c.py new file mode 100644 index 00000000..6b335639 --- /dev/null +++ b/test/support/pty/press-ctrl-c.py @@ -0,0 +1,63 @@ +"""Run a command on a real pseudo-terminal, press Ctrl-C once is on screen, print its exit code. + +Usage: python3 press-ctrl-c.py [args...] + +A signal death prints as a negative number (-2 for SIGINT). Exit code 124 means never appeared. +""" +import os +import pty +import select +import sys +import time + +TIMEOUT_SECONDS = 30 +SETTLE_SECONDS = 0.3 + + +def read_chunk(fd): + """Next output from the terminal, b'' once the command has closed it, None if nothing arrived yet.""" + if not select.select([fd], [], [], 0.1)[0]: + return None + try: + return os.read(fd, 4096) + except OSError: + return b'' + + +def read_until(fd, marker, deadline): + seen = b'' + while marker not in seen and time.time() < deadline: + chunk = read_chunk(fd) + if chunk == b'': + return False + seen += chunk or b'' + return marker in seen + + +def drain(fd, deadline): + while time.time() < deadline and read_chunk(fd) != b'': + pass + + +def main(): + marker = sys.argv[1].encode() + command = sys.argv[2:] + pid, fd = pty.fork() + if pid == 0: + os.execvp(command[0], command) + + deadline = time.time() + TIMEOUT_SECONDS + if not read_until(fd, marker, deadline): + os.kill(pid, 9) + os.waitpid(pid, 0) + print(124) + return + + time.sleep(SETTLE_SECONDS) + os.write(fd, b'\x03') + drain(fd, deadline) + _, status = os.waitpid(pid, 0) + print(os.waitstatus_to_exitcode(status)) + + +main() From e0c1879eb8e95e207e5f9e543af2607a1ac2da38 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:01:33 +0530 Subject: [PATCH 07/17] docs: describe the terminalUx prompt funnel and how tests stub it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AGENTS.md's prompt-funnel guard row now says LaunchCommand's ux is cancelOnInterrupt(terminalUx), why it skips cliux.inquire, how Ctrl-C reaches an inquirer 12 prompt and a legacy search-list prompt, and which test types a real Ctrl-C on a pty. "Driving a prompt" now names the terminalUx.inquire spy, stubPrompts, and CTRL_C rejecting with ExitPromptError. Test names and comments that said "the inquirer cliux prompts with" now say terminalUx. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- AGENTS.md | 10 ++++++---- src/core/launch-command.test.ts | 2 +- src/core/search-list.test.ts | 2 +- src/core/search-list.ts | 2 +- test/guards/prompt-types.test.ts | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8ce30da1..168b0076 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -55,12 +55,12 @@ file and line that broke its rule, and each was proven red by reintroducing its | Guard | Rule it enforces | Found by | |---|---|---| -| `test/guards/prompt-types.test.ts` | Every prompt call in `src` names a literal `type`, and every such type is registered with the real inquirer `cliux.inquire` uses once `LaunchCommand.init` has run. inquirer silently turns an unregistered type into a plain text box. | D1: `search-list` used, never registered | +| `test/guards/prompt-types.test.ts` | Every prompt call in `src` names a literal `type`, and every such type is registered with the real inquirer `terminalUx` prompts through once `LaunchCommand.init` has run. inquirer silently turns an unregistered type into a plain text box. | D1: `search-list` used, never registered | | `test/integration/transport-content-type.test.ts` | For every method in `HTTP_METHODS`, a bodyless request carries no content type and a request with a body carries `application/json`, asserted on the wire. `withoutDefaultContentType` suppresses the utility client's default, so a bodyless POST, PUT or PATCH (for example `deployments:cancel`) no longer goes out as `application/x-www-form-urlencoded`. Only `utility-http-client.ts` builds an `HttpClient` and only `rest-client.ts` sets the JSON type. | D5: every DELETE sent `Content-Type: application/json` | | `test/guards/tty-streams.test.ts` | `stdin.isTTY`, and the `isTTY` it becomes on the service context, are read only to decide whether the CLI may prompt (a read next to a prompt or a refusal to prompt) or on the plumbing lines that carry it there. Anything deciding what to draw reads `outputIsTTY` / `process.stdout.isTTY`. | D6: heartbeat drawn into a redirected file | | `test/integration/deployments-request-bodies.test.ts` | A deployments mutation puts on the wire only the fields the management service DTO declares - `{commitHash?, uploadUid?}` for a create, `{deployment, reason?}` for a rollback - and never `environment`, which is the URL path. The service validates with `whitelist` and `forbidNonWhitelisted`, so any other key is a bare 400. | Live harness: `deployments:create` and `:rollback` sent `{environment, ...}` and failed with `Bad request` | | `test/integration/retired-commands.test.ts` (named commands) | Every `launch:…` command named anywhere in `src` - a retirement message, a failure hint, an example - is either a registered command or on `PLANNED_COMMANDS` with the ticket that builds it, and a command drops off that list once it ships. | Review: retirement messages and hints pointed at commands the beta does not have | -| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(cliux)`, so Ctrl-C at any prompt exits 3. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, or imports a prompt library; `search-list.ts` may register a type but never prompt. | D2: Ctrl-C exited 130 | +| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper ignores that rejection and cancels on the signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal (`test/support/pty/`, Python's stdlib `pty`), because a simulated `SIGINT` is what let CL-8790 through. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | A new prompt, request, render path or command is covered by these guards without being listed in them. Do not add an exemption to a guard to make a new file pass: if a guard is wrong about a file, @@ -110,8 +110,10 @@ stdin is not a terminal and `LaunchCommand` reads it to decide whether prompting descriptor, not by assignment: once another suite in the same process has turned stdin into a real stream, `process.stdin.isTTY = true` throws, and jest orders test files by their previous runtime, so that shows up as an intermittent failure rather than a stable one. `answerPrompts({ message: answer })` -installs the `cliux.inquire` spy, records every prompt's message and payload in order, and throws on a -prompt it was not given an answer for. `projects-create.test.ts` uses the three together to drive all +installs the `terminalUx.inquire` spy, records every prompt's message and payload in order, and throws on a +prompt it was not given an answer for; an answer of `CTRL_C` rejects with inquirer's `ExitPromptError`, as a real +Ctrl-C does. `stubPrompts(handler)` installs the same spy with your own handler, and `test/no-terminal.setup.ts` +uses it to fail any test that reaches a prompt it did not stub. `projects-create.test.ts` uses the three together to drive all eleven GitHub prompts through `launch:projects:create`, asserting their order, their offered defaults and the submitted body, and to prove that a flag-supplied value is never asked for. diff --git a/src/core/launch-command.test.ts b/src/core/launch-command.test.ts index 9db1980d..426b09b6 100644 --- a/src/core/launch-command.test.ts +++ b/src/core/launch-command.test.ts @@ -338,7 +338,7 @@ describe('LaunchCommand.init', () => { restoreTTY(); }); - it('registers the searchable picker on the inquirer cliux prompts with before anything can prompt', async () => { + it('registers the searchable picker on the inquirer terminalUx prompts through before anything can prompt', async () => { const prompts = promptLibrary().prompt.prompts; delete prompts['search-list']; const instance = probe(); diff --git a/src/core/search-list.test.ts b/src/core/search-list.test.ts index daf8a7f5..12ab25d3 100644 --- a/src/core/search-list.test.ts +++ b/src/core/search-list.test.ts @@ -327,7 +327,7 @@ describe('promptLibrary', () => { }); describe('registerSearchList', () => { - it('registers the launch search list under search-list on the inquirer that cliux prompts with, and nothing else', () => { + it('registers the launch search list under search-list on the inquirer that terminalUx prompts through, and nothing else', () => { const registered: [string, unknown][] = []; const loaded: string[] = []; const fakeLoad = (id: string): unknown => { diff --git a/src/core/search-list.ts b/src/core/search-list.ts index 976d64c2..3fda1fb9 100644 --- a/src/core/search-list.ts +++ b/src/core/search-list.ts @@ -144,7 +144,7 @@ export function utilitiesLoader(): ModuleLoader { return createRequire(require.resolve('@contentstack/cli-utilities')); } -// cli-utilities 2 ships inquirer 12, which exposes the prompt registry cliux prompts with as its default export. +// cli-utilities 2 ships inquirer 12, whose default export is the prompt registry every Launch prompt goes through. export function promptLibrary(load: ModuleLoader = utilitiesLoader()): PromptRegistry { return (load('inquirer') as { default: PromptRegistry }).default; } diff --git a/test/guards/prompt-types.test.ts b/test/guards/prompt-types.test.ts index 2a2c1a08..1f3909e2 100644 --- a/test/guards/prompt-types.test.ts +++ b/test/guards/prompt-types.test.ts @@ -82,7 +82,7 @@ describe('guard: every prompt type the CLI asks for is registered with the real .map( (call) => `${call.site} asks for a '${call.type}' prompt, which LaunchCommand.init never registers ` + - 'with the inquirer cliux.inquire uses - register it there or the prompt degrades to a text box', + 'with the inquirer terminalUx prompts through - register it there or the prompt degrades to a text box', ); expect(unregistered).toEqual([]); }); From 46e86b8a785be25e8f37d9104a37617076462597 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:13:01 +0530 Subject: [PATCH 08/17] fix(core): cancel at once when a search-list prompt is aborted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On AbortPromptError the wrapper used to wait for the SIGINT inquirer raises next, so a legacy-prompt abort with no signal after it would hang with the event loop held. It now rejects with CancelledError and releases the loop straight away, and stays attached to SIGINT only to absorb that signal, then detaches. Found in review. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/core/interruptible-ux.test.ts | 14 ++++++++------ src/core/interruptible-ux.ts | 11 ++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/interruptible-ux.test.ts b/src/core/interruptible-ux.test.ts index c420b733..8a587a1d 100644 --- a/src/core/interruptible-ux.test.ts +++ b/src/core/interruptible-ux.test.ts @@ -102,7 +102,7 @@ describe('cancelOnInterrupt', () => { expect(loop.events).toEqual(['held', 'released']); }); - it('keeps listening when a search-list prompt is aborted, so the SIGINT inquirer raises next cancels instead of killing the process', async () => { + it('cancels as soon as a search-list prompt is aborted, and stays attached only to absorb the SIGINT inquirer raises next', async () => { const signals = new EventEmitter(); const inner = pendingUx(); const loop = recordingHold(); @@ -110,13 +110,15 @@ describe('cancelOnInterrupt', () => { const answer = cancelOnInterrupt(inner.ux, { signals, hold: loop.hold }).inquire(QUESTION); inner.settle({ error: aborted }); - await new Promise((done) => setImmediate(done)); - const listeningAfterAbort = signals.listenerCount('SIGINT'); + const error = await answer.catch((e: unknown) => e); + const listeningBeforeSignal = signals.listenerCount('SIGINT'); + const loopBeforeSignal = [...loop.events]; signals.emit('SIGINT'); - - await expect(answer).rejects.toBeInstanceOf(CancelledError); - expect(listeningAfterAbort).toBe(1); await new Promise((done) => setImmediate(done)); + + expect(error).toBeInstanceOf(CancelledError); + expect(listeningBeforeSignal).toBe(1); + expect(loopBeforeSignal).toEqual(['held', 'released']); expect(signals.listenerCount('SIGINT')).toBe(0); expect(loop.events).toEqual(['held', 'released']); }); diff --git a/src/core/interruptible-ux.ts b/src/core/interruptible-ux.ts index 7df2e62a..5e54064b 100644 --- a/src/core/interruptible-ux.ts +++ b/src/core/interruptible-ux.ts @@ -54,9 +54,13 @@ export function cancelOnInterrupt(ux: UxLike, options: InterruptOptions = {}): U print: (message) => ux.print(message), inquire: (payload: unknown) => new Promise((resolve, reject) => { - const releaseLoop = hold(); + let releaseLoop: Release | undefined = hold(); + const freeLoop = (): void => { + releaseLoop?.(); + releaseLoop = undefined; + }; const release = (): void => { - releaseLoop(); + freeLoop(); signals.removeListener('SIGINT', cancel); }; const cancel = (): void => { @@ -65,8 +69,9 @@ export function cancelOnInterrupt(ux: UxLike, options: InterruptOptions = {}): U }; const fail = (error: unknown): void => { - // inquirer 12 aborts a legacy search-list prompt on Ctrl-C, then raises the SIGINT `cancel` answers. if (isPromptAbort(error)) { + freeLoop(); + reject(new CancelledError()); return; } From 6aaee6f69bd964432b05ef2c3fac39198e90c9e1 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:14:25 +0530 Subject: [PATCH 09/17] test: bound the pty Ctrl-C test and cover the password prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit press-ctrl-c.py now waits for the command to exit only until its deadline, then kills it and reports 125, and the test gives execFileSync a timeout, so a regression that leaves the CLI running after Ctrl-C fails the test instead of hanging the whole jest run. The matrix covers the password prompt again: askSecret uses it at six call sites and @inquirer/password carries its own @inquirer/core. The test file gets a per-file checksum in .talismanrc because the prompt type's name trips Talisman. Found in review. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 2 ++ .../prompt-ctrl-c-on-a-terminal.test.ts | 5 ++--- test/support/pty/press-ctrl-c.py | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.talismanrc b/.talismanrc index be3f278a..1b76c38b 100644 --- a/.talismanrc +++ b/.talismanrc @@ -520,4 +520,6 @@ fileignoreconfig: checksum: 22a5aa7d95c6a5113a034d2cc9af4f152f8a366f1c271f86cd317ea2046f5b1d - filename: src/core/password-argv.test.ts checksum: df87a19d09ff07b95d8118dd7e6bae5a13a86f0ecb8dce97e6022481d1e11256 +- filename: test/integration/prompt-ctrl-c-on-a-terminal.test.ts + checksum: f712885cded1bef4d64a8e1d7532f95b6696e7d7522dfeba55edf211d07fb837 version: "1.0" diff --git a/test/integration/prompt-ctrl-c-on-a-terminal.test.ts b/test/integration/prompt-ctrl-c-on-a-terminal.test.ts index f193892d..7946b9f8 100644 --- a/test/integration/prompt-ctrl-c-on-a-terminal.test.ts +++ b/test/integration/prompt-ctrl-c-on-a-terminal.test.ts @@ -19,15 +19,14 @@ function exitCodeAfterCtrlC(promptType: string): number { join(PTY, 'ctrl-c-prompt.fixture.ts'), promptType, ], - { encoding: 'utf8' }, + { encoding: 'utf8', timeout: 45_000 }, ); return Number(output.trim()); } -// Simulating SIGINT hid CL-8790: in raw mode Ctrl-C reaches inquirer as typed input, so type it for real. describe('Ctrl-C at a real prompt on a terminal', () => { - it.each(['input', 'list', 'checkbox', 'confirm', 'search-list'])( + it.each(['input', 'password', 'list', 'checkbox', 'confirm', 'search-list'])( 'exits 3 as cancelled at the %s prompt', (promptType) => { expect(exitCodeAfterCtrlC(promptType)).toBe(EXIT_CANCELLED); diff --git a/test/support/pty/press-ctrl-c.py b/test/support/pty/press-ctrl-c.py index 6b335639..c3339cd6 100644 --- a/test/support/pty/press-ctrl-c.py +++ b/test/support/pty/press-ctrl-c.py @@ -2,7 +2,8 @@ Usage: python3 press-ctrl-c.py [args...] -A signal death prints as a negative number (-2 for SIGINT). Exit code 124 means never appeared. +A signal death prints as a negative number (-2 for SIGINT). 124 means never appeared, +125 that the command was still running when the time ran out (it is killed). """ import os import pty @@ -15,7 +16,6 @@ def read_chunk(fd): - """Next output from the terminal, b'' once the command has closed it, None if nothing arrived yet.""" if not select.select([fd], [], [], 0.1)[0]: return None try: @@ -39,6 +39,17 @@ def drain(fd, deadline): pass +def wait_for_exit(pid, deadline): + while time.time() < deadline: + finished, status = os.waitpid(pid, os.WNOHANG) + if finished: + return os.waitstatus_to_exitcode(status) + time.sleep(0.05) + os.kill(pid, 9) + os.waitpid(pid, 0) + return 125 + + def main(): marker = sys.argv[1].encode() command = sys.argv[2:] @@ -56,8 +67,7 @@ def main(): time.sleep(SETTLE_SECONDS) os.write(fd, b'\x03') drain(fd, deadline) - _, status = os.waitpid(pid, 0) - print(os.waitstatus_to_exitcode(status)) + print(wait_for_exit(pid, deadline)) main() From 499d2a0bbf576dab3d05f7e7405b796f87772eb8 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:14:52 +0530 Subject: [PATCH 10/17] test: simulate Ctrl-C at a search-list picker the way inquirer delivers it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit answerPrompts' CTRL_C now rejects a search-list prompt with AbortPromptError and raises a SIGINT on the next tick, as inquirer 12 does for that legacy prompt, and keeps ExitPromptError for every other prompt. A new projects:get case presses Ctrl-C at the project picker and expects exit 3 with no SIGINT listener left once the signal is absorbed. The stubPrompts and ctrlC comments are dropped, per AGENTS.md. Found in review. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../integration/projects-command-flows.test.ts | 18 +++++++++++++++++- test/support/terminal.ts | 10 +++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/test/integration/projects-command-flows.test.ts b/test/integration/projects-command-flows.test.ts index ed4ec3ab..d7908e84 100644 --- a/test/integration/projects-command-flows.test.ts +++ b/test/integration/projects-command-flows.test.ts @@ -8,7 +8,7 @@ import type { Interfaces } from '@oclif/core'; import { runCommand } from '@oclif/test'; import nock from 'nock'; -import { pretendTerminal, stubPrompts } from '../support/terminal'; +import { answerPrompts, CTRL_C, pretendTerminal, stubPrompts } from '../support/terminal'; import { loadCliConfig, routeConsoleLogToStdout } from '../support/oclif'; import getFixture from '../fixtures/project-get.json'; @@ -298,4 +298,20 @@ describe('integration: end-to-end command flows', () => { expect(error?.oclif?.exit).toBe(3); expect(error?.message).toBe('Cancelled. Nothing was changed.'); }); + + it('exits 3 when Ctrl-C aborts the searchable project picker', async () => { + useSession(basicSession()); + const restoreTTY = pretendTerminal(); + answerPrompts({ 'Choose a project': CTRL_C }); + nock(LAUNCH_HUB_URL).get('/manage/projects').query({ limit: '100', skip: '0' }).reply(200, listFixture); + + const { error } = await runLaunch(['launch:projects:get', '--org', ORG_UID, '--data-dir', tmpdir()]); + await new Promise((done) => setImmediate(done)); + + restoreTTY(); + + expect(error?.oclif?.exit).toBe(3); + expect(error?.message).toBe('Cancelled. Nothing was changed.'); + expect(process.listenerCount('SIGINT')).toBe(0); + }); }); diff --git a/test/support/terminal.ts b/test/support/terminal.ts index 80b4a733..60d62fc3 100644 --- a/test/support/terminal.ts +++ b/test/support/terminal.ts @@ -52,18 +52,22 @@ export interface AnsweredPrompts { export type PromptHandler = (payload: Record) => unknown; -// Stubs the terminal every LaunchCommand prompt reaches, answering each question with what `answer` returns for it. export function stubPrompts(answer: PromptHandler): jest.SpyInstance { return jest .spyOn(terminalUx, 'inquire') .mockImplementation(async (payload: unknown) => answer(payload as Record) as never); } -// What inquirer 12 rejects with when Ctrl-C reaches a prompt in raw mode, where it is a keypress rather than a SIGINT. export function ctrlC(): Error { return Object.assign(new Error('User force closed the prompt with SIGINT'), { name: 'ExitPromptError' }); } +export function ctrlCAtSearchList(): Error { + setImmediate(() => process.emit('SIGINT')); + + return Object.assign(new Error('Prompt was aborted'), { name: 'AbortPromptError' }); +} + export function answerPrompts(answers: Record): AnsweredPrompts { const recorded: AnsweredPrompts = { messages: [], payloads: [] }; @@ -77,7 +81,7 @@ export function answerPrompts(answers: Record): AnsweredPrompts } if (answers[message] === CTRL_C) { - throw ctrlC(); + throw payload.type === 'search-list' ? ctrlCAtSearchList() : ctrlC(); } return answers[message]; From cf8866a27d71fdb269b4bbdac7efa7562b8bcf26 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:15:09 +0530 Subject: [PATCH 11/17] test(guards): follow import aliases of terminalUx and promptLibrary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prompt-funnel guard matched only the literal names, so `import { terminalUx as tty }` or `import { promptLibrary as lib }` reached the prompt library around the Ctrl-C wrapper unnoticed. It now resolves aliases the way it already did for cliux. Found in review. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- test/guards/prompt-funnel.test.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/test/guards/prompt-funnel.test.ts b/test/guards/prompt-funnel.test.ts index a9b0e511..05ff37b8 100644 --- a/test/guards/prompt-funnel.test.ts +++ b/test/guards/prompt-funnel.test.ts @@ -23,18 +23,22 @@ class FreshCommand extends LaunchCommand { } } -function cliuxNames(source: SourceFile): string[] { - const imports = [...source.text.matchAll(/import\s*\{([^}]*)\}\s*from\s*'@contentstack\/cli-utilities'/g)]; +function importedAs(source: SourceFile, imported: string, from = "[^']+"): string[] { + const imports = [...source.text.matchAll(new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*'${from}'`, 'g'))]; return imports.flatMap((match) => match[1] .split(',') .map((specifier) => specifier.trim().split(/\s+as\s+/)) - .filter(([imported]) => imported === 'cliux') + .filter(([name]) => name === imported) .map((parts) => parts[parts.length - 1]), ); } +function namesFor(source: SourceFile, imported: string): string[] { + return [...new Set([imported, ...importedAs(source, imported)])]; +} + function isImport(use: Occurrence): boolean { return /^import\b/.test(use.text); } @@ -43,8 +47,12 @@ function isTheFunnel(use: Occurrence): boolean { return use.path === FUNNEL_FILE && use.text.includes(FUNNEL_CALL); } +function usesOf(source: SourceFile, names: string[]): Occurrence[] { + return occurrences(source, new RegExp(`\\b(${names.join('|')})\\b`)); +} + function detours(source: SourceFile): Occurrence[] { - const direct = cliuxNames(source).flatMap((name) => [ + const direct = importedAs(source, 'cliux', '@contentstack\\/cli-utilities').flatMap((name) => [ ...occurrences(source, new RegExp(`\\b${name}\\s*(\\??\\.)\\s*(${PROMPT_METHODS})\\b`)), ...occurrences(source, new RegExp(`\\b${name}\\b(?!\\s*\\??\\.)`)).filter((use) => !isImport(use)), ]); @@ -53,11 +61,11 @@ function detours(source: SourceFile): Occurrence[] { source.path === REGISTRATION_FILE ? occurrences(source, new RegExp(`\\.(${PROMPT_METHODS})\\s*\\(`)) : []; const libraryCalls = [REGISTRATION_FILE, TERMINAL_FILE].includes(source.path) ? [] - : occurrences(source, /\bpromptLibrary\b/).filter((use) => !isImport(use)); + : usesOf(source, namesFor(source, 'promptLibrary')).filter((use) => !isImport(use)); const unwrappedTerminal = source.path === TERMINAL_FILE ? [] - : occurrences(source, /\bterminalUx\b/).filter((use) => !isImport(use) && !isTheFunnel(use)); + : usesOf(source, namesFor(source, 'terminalUx')).filter((use) => !isImport(use) && !isTheFunnel(use)); const wholeModule = [ ...occurrences(source, /import\s*\*\s*as\s+\w+\s+from\s*'@contentstack\/cli-utilities'/), ...occurrences(source, /\brequire\(\s*'@contentstack\/cli-utilities'/), @@ -118,6 +126,14 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e { path: 'cache/purge.prompt.ts', text: 'const answers = await promptLibrary().prompt(question);' }, { path: 'environments/environment.prompt.ts', text: 'const name = await terminalUx.inquire(question);' }, { path: 'deployments/deployment.prompt.ts', text: 'const ux = libraryUx(promptLibrary, print);' }, + { + path: 'projects/project.prompt.ts', + text: 'import { terminalUx as tty } from \'../core/terminal-ux\';\nconst name = await tty.inquire(question);', + }, + { + path: 'functions/function.prompt.ts', + text: 'import { promptLibrary as lib } from \'../core/search-list\';\nawait lib().prompt(question);', + }, ]; expect(promptDetoursIn(sources).map((detour) => detour.split(' <-')[0])).toEqual([ @@ -131,6 +147,8 @@ describe('guard: every prompt goes through the one wrapper that maps Ctrl-C to e 'src/cache/purge.prompt.ts:1 const answers = await promptLibrary().prompt(question);', 'src/environments/environment.prompt.ts:1 const name = await terminalUx.inquire(question);', 'src/deployments/deployment.prompt.ts:1 const ux = libraryUx(promptLibrary, print);', + 'src/projects/project.prompt.ts:2 const name = await tty.inquire(question);', + 'src/functions/function.prompt.ts:2 await lib().prompt(question);', ]); }); From 38fdadd54c371bdc25859fbb03e98ea9792c2314 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:15:24 +0530 Subject: [PATCH 12/17] refactor(core): drop the terminalUx comment, per AGENTS.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AGENTS.md asks for no code comments on changes; the reason terminalUx skips cliux.inquire is in AGENTS.md's prompt-funnel guard row. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/core/terminal-ux.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/terminal-ux.ts b/src/core/terminal-ux.ts index a08fa8fb..796fef3e 100644 --- a/src/core/terminal-ux.ts +++ b/src/core/terminal-ux.ts @@ -19,5 +19,4 @@ export function libraryUx(library: () => Prompter, print: (message: string) => v }; } -// cli-utilities' own inquire calls process.exit(130) on Ctrl-C, so prompts go to the inquirer it wraps instead. export const terminalUx: UxLike = libraryUx(promptLibrary, (message) => cliux.print(message)); From b20866a212ea8fe51a2cf8482e06530f5f3cbc79 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:15:49 +0530 Subject: [PATCH 13/17] docs: describe the search-list abort and CTRL_C as they now behave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- AGENTS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 168b0076..73460225 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,7 +60,7 @@ file and line that broke its rule, and each was proven red by reintroducing its | `test/guards/tty-streams.test.ts` | `stdin.isTTY`, and the `isTTY` it becomes on the service context, are read only to decide whether the CLI may prompt (a read next to a prompt or a refusal to prompt) or on the plumbing lines that carry it there. Anything deciding what to draw reads `outputIsTTY` / `process.stdout.isTTY`. | D6: heartbeat drawn into a redirected file | | `test/integration/deployments-request-bodies.test.ts` | A deployments mutation puts on the wire only the fields the management service DTO declares - `{commitHash?, uploadUid?}` for a create, `{deployment, reason?}` for a rollback - and never `environment`, which is the URL path. The service validates with `whitelist` and `forbidNonWhitelisted`, so any other key is a bare 400. | Live harness: `deployments:create` and `:rollback` sent `{environment, ...}` and failed with `Bad request` | | `test/integration/retired-commands.test.ts` (named commands) | Every `launch:…` command named anywhere in `src` - a retirement message, a failure hint, an example - is either a registered command or on `PLANNED_COMMANDS` with the ticket that builds it, and a command drops off that list once it ships. | Review: retirement messages and hints pointed at commands the beta does not have | -| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper ignores that rejection and cancels on the signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal (`test/support/pty/`, Python's stdlib `pty`), because a simulated `SIGINT` is what let CL-8790 through. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | +| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper cancels on the rejection at once and stays attached only to absorb that signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal (`test/support/pty/`, Python's stdlib `pty`), because a simulated `SIGINT` is what let CL-8790 through. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | A new prompt, request, render path or command is covered by these guards without being listed in them. Do not add an exemption to a guard to make a new file pass: if a guard is wrong about a file, @@ -111,8 +111,8 @@ descriptor, not by assignment: once another suite in the same process has turned stream, `process.stdin.isTTY = true` throws, and jest orders test files by their previous runtime, so that shows up as an intermittent failure rather than a stable one. `answerPrompts({ message: answer })` installs the `terminalUx.inquire` spy, records every prompt's message and payload in order, and throws on a -prompt it was not given an answer for; an answer of `CTRL_C` rejects with inquirer's `ExitPromptError`, as a real -Ctrl-C does. `stubPrompts(handler)` installs the same spy with your own handler, and `test/no-terminal.setup.ts` +prompt it was not given an answer for; an answer of `CTRL_C` rejects the way a real Ctrl-C does: `ExitPromptError`, or for a +`search-list` prompt `AbortPromptError` followed by a `SIGINT`. `stubPrompts(handler)` installs the same spy with your own handler, and `test/no-terminal.setup.ts` uses it to fail any test that reaches a prompt it did not stub. `projects-create.test.ts` uses the three together to drive all eleven GitHub prompts through `launch:projects:create`, asserting their order, their offered defaults and the submitted body, and to prove that a flag-supplied value is never asked for. From 515916266e139788ff5df842ffa1cb25afc7355b Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:16:30 +0530 Subject: [PATCH 14/17] chore: refresh Talisman checksums for the files the prompt-seam change touched MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pre-push scan reads each changed file whole, so the existing per-file checksums for launch-command, search-list and the integration tests that now stub prompts at terminalUx.inquire are refreshed in place. No new secrets: the flagged lines are the existing password/key test fixtures. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.talismanrc b/.talismanrc index 1b76c38b..7c4e141d 100644 --- a/.talismanrc +++ b/.talismanrc @@ -2,7 +2,7 @@ fileignoreconfig: - filename: src/logs/logs.inputs.test.ts checksum: 7b4df8790179c7dc4385acd1d380bb91397523bab111593742e2fc53c94da375 - filename: test/integration/logs-get.test.ts - checksum: 89ce4f3864c6316e8075e08fb86fb07d848cbe717f434c3b3e228622b263eed2 + checksum: b608797028bb0191d53630d2ff95d096b8a2b83019fed2aa096754dc5c50b1bb - filename: src/commands/launch/logs/get.test.ts checksum: d94d390de150956c799f64a84adfe0e02b5b21c66ddcc5cf55a1329aa67ec1a7 - filename: src/core/failure.test.ts @@ -263,15 +263,15 @@ fileignoreconfig: - filename: src/commands/launch/projects/delete.test.ts checksum: d67d8a804d14f9b809153d10b0cf9d5e52b70f9e0b65678ebb1663a7d2da22c1 - filename: test/integration/projects-delete.test.ts - checksum: bb59cbe1f4f7b3ac6aa7944067c1ab1214a7c5d20229e9d6577cdaabec56622e + checksum: 19784ba572daac76e6ef0b004c19cdb9c3f9cb22f738b3ab0e22c694e049026c - filename: src/core/launch-command.ts - checksum: 999468661532665870b81face9086998e543df648175e2417045840dc97cb1dd + checksum: 91ec87522df77d8ed593c95e1a2259d1555acbd1dee95ad8ca4d6c3fa9c61468 - filename: src/core/launch-command.test.ts - checksum: 40c554e420c60e38d738190128588bc43c6f347da2d1e648b65d93419ca9f2c3 + checksum: 44f0639fe66598ba2f3ba0ddc7edd68381f7aa36e3be5323ecbe5d101a1953a2 - filename: src/projects/project.inputs.test.ts checksum: 8242f4d40388f1a7f1d08c11d2571cb45a9294069a8248a5272bc5606807bb60 - filename: test/integration/projects-command-flows.test.ts - checksum: 30858bb3dff8a22406efa4ac82d882d1501797cdda24e09555aecc0bcd8dca0b + checksum: 1731d2350269ae9b6f7c2837db8e14575f94a9a3fa11f8f86c532717378d99ce - filename: src/core/redact.test.ts checksum: ae497ea8c3a4c3f12217d2c4c028a1da3d1324e18362d68c355ba8120902bcb3 - filename: src/commands/launch/projects/list.test.ts @@ -305,7 +305,7 @@ fileignoreconfig: - filename: src/transport/cma-client.test.ts checksum: 85d62ef350b450cb09f1a840db79bdfb212d4f5fd650789d60d722915a892a59 - filename: src/core/search-list.test.ts - checksum: 0c324ecf8de5cc2fc1ccc27223cae555d7db6c8061c4bd7288e0dc7fb28f6b87 + checksum: 4e5db3cd6a213db71c51bf5ac8d6a5547ea9ca137d425c00026453e5c3b543b7 - filename: src/core/catalog.test.ts checksum: 950d5cbb8ebdbe13cf13908b72d5409f7fdf7515c9d93a7c84045efcf4420543 - filename: test/credential-guard.setup.ts @@ -445,9 +445,9 @@ fileignoreconfig: - filename: src/deployments/deployment.create.test.ts checksum: 6545afa21a23b7e5de18ad8ff417f88a184577e7042713cfda90758ccbcd9869 - filename: test/integration/deployments-rollback.test.ts - checksum: 08400c5435c84cd162fefc585f6c32cddfcaa8909d2369341748b421e7f12073 + checksum: 98a9f7001eb5bf01e0e2f46677eeea61ad5d38c595d17ef27d366c93e603f0d5 - filename: test/integration/deployments-cancel.test.ts - checksum: 8972ed5f23e7dee8acf677ae9a26d2d28ef8144d03bc7623c5fd29f096a3aed0 + checksum: 2e14190da534dda23176c44618b5f0cc0ef6f5c563b529658e171e509be10f4e - filename: src/commands/launch/deployments/cancel.test.ts checksum: da8d09de7f03cfe67df75ebc1636b36feb6688cf85984c357fd5304852d126e5 - filename: src/commands/launch/deployments/rollback.test.ts @@ -489,7 +489,7 @@ fileignoreconfig: - filename: package.json checksum: ae6f7fdb23fd9476dd4fca5b84d0f3999b578a73b8187af2f94edbb0a2172b16 - filename: test/integration/secrets-set.test.ts - checksum: f01f5673125c48f537c593b9f8f3a728b6b16b42a3253c01f44558176ef48d89 + checksum: 2527d5d35198cc08e1859ab79941338392b6d4fcbc87506adef6d7b096089963 - filename: src/secrets/secret.rules.test.ts checksum: 29f1c5842b7d7c895ccf4c2611af52f824168e264e228b2493bededfdd7a2e8e - filename: src/commands/launch/secrets/set.ts @@ -507,7 +507,7 @@ fileignoreconfig: - filename: src/secrets/secret.set.test.ts checksum: 80b6b9c56280b6f5cb4be03fffd05b0421ea558997d9295ddde50b773f22b05f - filename: test/integration/secrets-unset.test.ts - checksum: ed2f37b50516817ef70e2dc11ed4d801374ade1f3588fa2320f71cac5033448e + checksum: 431d7601ecb9d09d291bd271164da8da1bdd93329b217186db1de75ae185a2bb - filename: src/secrets/secret.unset.ts checksum: 597d7797c24716f443092fd40d077232ec1d9b2118707ee3aca453bacf38fa86 - filename: src/commands/launch/secrets/unset.ts From 276f0c63e973ce0d94622c0b931a0e45fa54aa01 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 23:31:28 +0530 Subject: [PATCH 15/17] chore: refresh the AGENTS.md Talisman checksum after the prompt-funnel docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.talismanrc b/.talismanrc index 7c4e141d..6c7985bf 100644 --- a/.talismanrc +++ b/.talismanrc @@ -236,7 +236,7 @@ fileignoreconfig: - "a project name passed on argv to the project resolver" - "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)" - filename: AGENTS.md - checksum: ecab79e8abbaae85038afe4f9e8e90e310eef5b0c002cee2b014926850be2c56 + checksum: fb1ef8dfc951540c9ac9e71ef4269374bec4a11bb9600f42c4448121143cd5ea allowed_patterns: - "Do not add an exemption to a guard to make a new file pass" - "passes its own error wording to `client.request\\(req, MESSAGES\\)`" From 9893fb1b3a4d75a73d4fb97d68e10a9eaa16a7ef Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Thu, 19 Nov 2026 09:58:38 +0530 Subject: [PATCH 16/17] test: address review: end the pty fixture like the CLI, drop the helper's docstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ctrl-c-prompt.fixture.ts sets process.exitCode and lets the event loop drain instead of calling process.exit in the rejection handler, so it ends the way the CLI does. - press-ctrl-c.py loses its docstring (AGENTS.md: no code comments); its usage and exit codes (-2 SIGINT, 124 no marker, 125 still running) move to AGENTS.md's prompt-funnel row, whose Talisman checksum is refreshed. #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 2 +- AGENTS.md | 2 +- test/support/pty/ctrl-c-prompt.fixture.ts | 8 ++++++-- test/support/pty/press-ctrl-c.py | 7 ------- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.talismanrc b/.talismanrc index 6c7985bf..803599a6 100644 --- a/.talismanrc +++ b/.talismanrc @@ -236,7 +236,7 @@ fileignoreconfig: - "a project name passed on argv to the project resolver" - "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)" - filename: AGENTS.md - checksum: fb1ef8dfc951540c9ac9e71ef4269374bec4a11bb9600f42c4448121143cd5ea + checksum: 6735bb91bb5e989ac92619087f5c87af540a456b5b3fc603ba296c73e9e69f66 allowed_patterns: - "Do not add an exemption to a guard to make a new file pass" - "passes its own error wording to `client.request\\(req, MESSAGES\\)`" diff --git a/AGENTS.md b/AGENTS.md index 73460225..9578f6ee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,7 +60,7 @@ file and line that broke its rule, and each was proven red by reintroducing its | `test/guards/tty-streams.test.ts` | `stdin.isTTY`, and the `isTTY` it becomes on the service context, are read only to decide whether the CLI may prompt (a read next to a prompt or a refusal to prompt) or on the plumbing lines that carry it there. Anything deciding what to draw reads `outputIsTTY` / `process.stdout.isTTY`. | D6: heartbeat drawn into a redirected file | | `test/integration/deployments-request-bodies.test.ts` | A deployments mutation puts on the wire only the fields the management service DTO declares - `{commitHash?, uploadUid?}` for a create, `{deployment, reason?}` for a rollback - and never `environment`, which is the URL path. The service validates with `whitelist` and `forbidNonWhitelisted`, so any other key is a bare 400. | Live harness: `deployments:create` and `:rollback` sent `{environment, ...}` and failed with `Bad request` | | `test/integration/retired-commands.test.ts` (named commands) | Every `launch:…` command named anywhere in `src` - a retirement message, a failure hint, an example - is either a registered command or on `PLANNED_COMMANDS` with the ticket that builds it, and a command drops off that list once it ships. | Review: retirement messages and hints pointed at commands the beta does not have | -| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper cancels on the rejection at once and stays attached only to absorb that signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal (`test/support/pty/`, Python's stdlib `pty`), because a simulated `SIGINT` is what let CL-8790 through. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | +| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper cancels on the rejection at once and stays attached only to absorb that signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal, because a simulated `SIGINT` is what let CL-8790 through. `test/support/pty/press-ctrl-c.py ` (Python's stdlib `pty`, so `npm test` needs `python3`) runs the command on a pty, types Ctrl-C once `` is on screen and prints the exit code: negative for a signal death (-2 is SIGINT), 124 if `` never appeared, 125 if the command was still running 30 s later (it is killed). `ctrl-c-prompt.fixture.ts` ends by setting `process.exitCode` and letting the loop drain, as the CLI does. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | A new prompt, request, render path or command is covered by these guards without being listed in them. Do not add an exemption to a guard to make a new file pass: if a guard is wrong about a file, diff --git a/test/support/pty/ctrl-c-prompt.fixture.ts b/test/support/pty/ctrl-c-prompt.fixture.ts index 768ca3a9..318354c8 100644 --- a/test/support/pty/ctrl-c-prompt.fixture.ts +++ b/test/support/pty/ctrl-c-prompt.fixture.ts @@ -19,6 +19,10 @@ const choices = [ ]; ux.inquire({ type: process.argv[2], name: 'value', message: 'Choose an environment', choices }).then( - () => process.exit(0), - (error: { exitCode?: number }) => process.exit(error.exitCode ?? 1), + () => { + process.exitCode = 0; + }, + (error: { exitCode?: number }) => { + process.exitCode = error.exitCode ?? 1; + }, ); diff --git a/test/support/pty/press-ctrl-c.py b/test/support/pty/press-ctrl-c.py index c3339cd6..af4c2ae4 100644 --- a/test/support/pty/press-ctrl-c.py +++ b/test/support/pty/press-ctrl-c.py @@ -1,10 +1,3 @@ -"""Run a command on a real pseudo-terminal, press Ctrl-C once is on screen, print its exit code. - -Usage: python3 press-ctrl-c.py [args...] - -A signal death prints as a negative number (-2 for SIGINT). 124 means never appeared, -125 that the command was still running when the time ran out (it is killed). -""" import os import pty import select From 1eb0532a7e5b238861784b0ccc34927b998a3473 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Thu, 19 Nov 2026 11:02:05 +0530 Subject: [PATCH 17/17] test: address review: exit the pty fixture through process.exit, as oclif does MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Ctrl-C the command's catch calls this.exit(3), and @oclif/core 4.14.0's Errors.handle then calls process.exit(exitCode) in the same promise chain, with no loop turn. 9893fb1 had the fixture set process.exitCode and drain the loop instead, which is a different exit path from csdx and would wait on any handle a prompt leaves open. Back to process.exit, and AGENTS.md now says what the fixture really mirrors (Talisman checksum refreshed). #claude_code# šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 2 +- AGENTS.md | 2 +- test/support/pty/ctrl-c-prompt.fixture.ts | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.talismanrc b/.talismanrc index 803599a6..f29926f0 100644 --- a/.talismanrc +++ b/.talismanrc @@ -236,7 +236,7 @@ fileignoreconfig: - "a project name passed on argv to the project resolver" - "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)" - filename: AGENTS.md - checksum: 6735bb91bb5e989ac92619087f5c87af540a456b5b3fc603ba296c73e9e69f66 + checksum: c20a023e033c6222c645e94bf9fba4bdf884aa75d6c52f5c74ab185b8c335b01 allowed_patterns: - "Do not add an exemption to a guard to make a new file pass" - "passes its own error wording to `client.request\\(req, MESSAGES\\)`" diff --git a/AGENTS.md b/AGENTS.md index 9578f6ee..70d8c0a2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,7 +60,7 @@ file and line that broke its rule, and each was proven red by reintroducing its | `test/guards/tty-streams.test.ts` | `stdin.isTTY`, and the `isTTY` it becomes on the service context, are read only to decide whether the CLI may prompt (a read next to a prompt or a refusal to prompt) or on the plumbing lines that carry it there. Anything deciding what to draw reads `outputIsTTY` / `process.stdout.isTTY`. | D6: heartbeat drawn into a redirected file | | `test/integration/deployments-request-bodies.test.ts` | A deployments mutation puts on the wire only the fields the management service DTO declares - `{commitHash?, uploadUid?}` for a create, `{deployment, reason?}` for a rollback - and never `environment`, which is the URL path. The service validates with `whitelist` and `forbidNonWhitelisted`, so any other key is a bare 400. | Live harness: `deployments:create` and `:rollback` sent `{environment, ...}` and failed with `Bad request` | | `test/integration/retired-commands.test.ts` (named commands) | Every `launch:…` command named anywhere in `src` - a retirement message, a failure hint, an example - is either a registered command or on `PLANNED_COMMANDS` with the ticket that builds it, and a command drops off that list once it ships. | Review: retirement messages and hints pointed at commands the beta does not have | -| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper cancels on the rejection at once and stays attached only to absorb that signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal, because a simulated `SIGINT` is what let CL-8790 through. `test/support/pty/press-ctrl-c.py ` (Python's stdlib `pty`, so `npm test` needs `python3`) runs the command on a pty, types Ctrl-C once `` is on screen and prints the exit code: negative for a signal death (-2 is SIGINT), 124 if `` never appeared, 125 if the command was still running 30 s later (it is killed). `ctrl-c-prompt.fixture.ts` ends by setting `process.exitCode` and letting the loop drain, as the CLI does. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | +| `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper cancels on the rejection at once and stays attached only to absorb that signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal, because a simulated `SIGINT` is what let CL-8790 through. `test/support/pty/press-ctrl-c.py ` (Python's stdlib `pty`, so `npm test` needs `python3`) runs the command on a pty, types Ctrl-C once `` is on screen and prints the exit code: negative for a signal death (-2 is SIGINT), 124 if `` never appeared, 125 if the command was still running 30 s later (it is killed). `ctrl-c-prompt.fixture.ts` calls `process.exit` with the error's exit code, as oclif's `Errors.handle` does for the CLI. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | A new prompt, request, render path or command is covered by these guards without being listed in them. Do not add an exemption to a guard to make a new file pass: if a guard is wrong about a file, diff --git a/test/support/pty/ctrl-c-prompt.fixture.ts b/test/support/pty/ctrl-c-prompt.fixture.ts index 318354c8..768ca3a9 100644 --- a/test/support/pty/ctrl-c-prompt.fixture.ts +++ b/test/support/pty/ctrl-c-prompt.fixture.ts @@ -19,10 +19,6 @@ const choices = [ ]; ux.inquire({ type: process.argv[2], name: 'value', message: 'Choose an environment', choices }).then( - () => { - process.exitCode = 0; - }, - (error: { exitCode?: number }) => { - process.exitCode = error.exitCode ?? 1; - }, + () => process.exit(0), + (error: { exitCode?: number }) => process.exit(error.exitCode ?? 1), );