CodeSampleX

샘플

@inquirer/core 9.2.1: Separator, makeTheme, isUpKey

검증된 샘플 — npm @inquirer/core 9.2.1: Separator, makeTheme, isUpKey. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Separator creates separator…

sha256:8c4f74b9f3801077ede1908c5caeeabe179204df1481a24a6806095eb6cec7cb

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-16

케이스

HOW
목표
verify pkg:npm/%40inquirer/core@9.2.1
패키지
심벌
  • @inquirer/core.Separator
  • @inquirer/core.makeTheme
  • @inquirer/core.isUpKey
  • @inquirer/core.isDownKey
  • @inquirer/core.AbortPromptError
  • @inquirer/core.createPrompt
환경
node 22.23.2
생성일
2026-09-16T12:51:32Z

컨트랙트

  1. Separator creates separator choices and recognizes separator duck typing
  2. makeTheme produces default theme with prompt styling functions and deep-merges overrides
  3. key helpers detect navigation and control keypress events including vim bindings
  4. error hierarchy includes AbortPromptError, CancelPromptError, and ExitPromptError
  5. createPrompt builds headless prompt function executable with mock streams and supports abort signals

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/%40inquirer/core@9.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40inquirer/core@9.2.1

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:79d4c6ae7f2baaceb5d5b5d1525ae5c58051ac1f0373bbf6737e110150880b77","contract":["Separator creates separator choices and recognizes separator duck typing","makeTheme produces default theme with prompt styling functions and deep-merges overrides","key helpers detect navigation and control keypress events including vim bindings","error hierarchy includes AbortPromptError, CancelPromptError, and ExitPromptError","createPrompt builds headless prompt function executable with mock streams and supports abort signals"],"goal":"verify pkg:npm/%40inquirer/core@9.2.1","kind":"HOW","packages":["pkg:npm/%40inquirer/core@9.2.1"],"schemaVersion":1,"symbols":["@inquirer/core.Separator","@inquirer/core.makeTheme","@inquirer/core.isUpKey","@inquirer/core.isDownKey","@inquirer/core.AbortPromptError","@inquirer/core.createPrompt"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40inquirer/core@9.2.1"],"schemaVersion":1,"subject":"pkg:npm/%40inquirer/core@9.2.1","symbols":["@inquirer/core.Separator","@inquirer/core.makeTheme","@inquirer/core.isUpKey","@inquirer/core.isDownKey","@inquirer/core.AbortPromptError","@inquirer/core.createPrompt"],"verifierAdapter":"node-typescript@1"}
index.mjs
import {
  createPrompt,
  Separator,
  makeTheme,
  isUpKey,
  isDownKey,
  isSpaceKey,
  isBackspaceKey,
  isNumberKey,
  isEnterKey,
  AbortPromptError,
  CancelPromptError,
  ExitPromptError,
  HookError,
  ValidationError
} from '@inquirer/core';

/**
 * Creates a custom Separator instance with optional label.
 *
 * @param {string} [separator] - Separator label or delimiter.
 * @returns {Separator}
 */
export function createCustomSeparator(separator) {
  return new Separator(separator);
}

/**
 * Builds a prompt theme by merging overrides onto defaultTheme.
 *
 * @param {object} [customizations] - Theme customizations.
 * @returns {object}
 */
export function buildPromptTheme(customizations) {
  return makeTheme(customizations);
}

export {
  createPrompt,
  Separator,
  makeTheme,
  isUpKey,
  isDownKey,
  isSpaceKey,
  isBackspaceKey,
  isNumberKey,
  isEnterKey,
  AbortPromptError,
  CancelPromptError,
  ExitPromptError,
  HookError,
  ValidationError
};

export default {
  createPrompt,
  Separator,
  makeTheme,
  createCustomSeparator,
  buildPromptTheme,
  isUpKey,
  isDownKey,
  isSpaceKey,
  isBackspaceKey,
  isNumberKey,
  isEnterKey,
  AbortPromptError,
  CancelPromptError,
  ExitPromptError,
  HookError,
  ValidationError
};
package-lock.json
{
  "name": "sample-inquirer-core",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-inquirer-core",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@inquirer/core": "9.2.1"
      }
    },
    "node_modules/@inquirer/core": {
      "version": "9.2.1",
      "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-9.2.1.tgz",
      "integrity": "sha512-F2VBt7W/mwqEU4bL0RnHNZmC/OxzNx9cOYxHqnXX3MP6ruYvZUZAW9imgN9+h/uBT/oP8Gh888J2OZSbjSeWcg==",
      "license": "MIT",
      "dependencies": {
        "@inquirer/figures": "^1.0.6",
        "@inquirer/type": "^2.0.0",
        "@types/mute-stream": "^0.0.4",
        "@types/node": "^22.5.5",
        "@types/wrap-ansi": "^3.0.0",
        "ansi-escapes": "^4.3.2",
        "cli-width": "^4.1.0",
        "mute-stream": "^1.0.0",
        "signal-exit": "^4.1.0",
        "strip-ansi": "^6.0.1",
        "wrap-ansi": "^6.2.0",
        "yoctocolors-cjs": "^2.1.2"
      },
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@inquirer/figures": {
      "version": "1.0.15",
      "resolved": "https://registry.npmjs.org/@inquirer/figures/-/figures-1.0.15.tgz",
      "integrity": "sha512-t2IEY+unGHOzAaVM5Xx6DEWKeXlDDcNPeDyUpsRc6CUhBfU3VQOEl+Vssh7VNp1dR8MdUJBWhuObjXCsVpjN5g==",
      "license": "MIT",
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@inquirer/type": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-2.0.0.tgz",
      "integrity": "sha512-XvJRx+2KR3YXyYtPUUy+qd9i7p+GO9Ko6VIIpWlBrpWwXDv8WLFeHTxz35CfQFUiBMLXlGHhGzys7lqit9gWag==",
      "license": "MIT",
      "dependencies": {
        "mute-stream": "^1.0.0"
      },
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@types/mute-stream": {
      "version": "0.0.4",
      "resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz",
      "integrity": "sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==",
      "license": "MIT",
      "dependencies": {
        "@types/node": "*"
      }
    },
    "node_modules/@types/node": {
      "version": "22.20.3",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.3.tgz",
      "integrity": "sha512-DZmzkmwHzXrLPAXPyKNDzlIwMMUZCVacoD25ywdy5YTKGbOx/2ld+Q38Im2zJ0vBuZP5Prd3VZutKZyXwkOS8A==",
      "license": "MIT",
      "dependencies": {
        "undici-types": "~6.21.0"
      }
    },
    "node_modules/@types/wrap-ansi": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz",
      "integrity": "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==",
      "license": "MIT"
    },
    "node_modules/ansi-escapes": {
      "version": "4.3.2",
      "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
      "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==",
      "license": "MIT",
      "dependencies": {
        "type-fest": "^0.21.3"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/ansi-regex": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
      "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/ansi-styles": {
      "version": "4.3.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
      "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
      "license": "MIT",
      "dependencies": {
        "color-convert": "^2.0.1"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/cli-width": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz",
      "integrity": "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==",
      "license": "ISC",
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/color-convert": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
      "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
      "license": "MIT",
      "dependencies": {
        "color-name": "~1.1.4"
      },
      "engines": {
        "node": ">=7.0.0"
      }
    },
    "node_modules/color-name": {
      "version": "1.1.4",
      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
      "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
      "license": "MIT"
    },
    "node_modules/emoji-regex": {
      "version": "8.0.0",
      "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
      "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
      "license": "MIT"
    },
    "node_modules/is-fullwidth-code-point": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
      "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/mute-stream": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-1.0.0.tgz",
      "integrity": "sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==",
      "license": "ISC",
      "engines": {
        "node": "^14.17.0 || ^16.13.0 || >=18.0.0"
      }
    },
    "node_modules/signal-exit": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
      "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
      "license": "ISC",
      "engines": {
        "node": ">=14"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    },
    "node_modules/string-width": {
      "version": "4.2.3",
      "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
      "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
      "license": "MIT",
      "dependencies": {
        "emoji-regex": "^8.0.0",
        "is-fullwidth-code-point": "^3.0.0",
        "strip-ansi": "^6.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/strip-ansi": {
      "version": "6.0.1",
      "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
      "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^5.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/type-fest": {
      "version": "0.21.3",
      "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz",
      "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
      "license": "(MIT OR CC0-1.0)",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/undici-types": {
      "version": "6.21.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
      "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
      "license": "MIT"
    },
    "node_modules/wrap-ansi": {
      "version": "6.2.0",
      "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
      "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^4.0.0",
        "string-width": "^4.1.0",
        "strip-ansi": "^6.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/yoctocolors-cjs": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/yoctocolors-cjs/-/yoctocolors-cjs-2.1.3.tgz",
      "integrity": "sha512-U/PBtDf35ff0D8X8D0jfdzHYEPFxAI7jJlxZXwCSez5M3190m+QobIfh+sWDWSHMCWWJN2AWamkegn6vr6YBTw==",
      "license": "MIT",
      "engines": {
        "node": ">=18"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    }
  }
}
package.json
{
  "name": "sample-inquirer-core",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "@inquirer/core": "9.2.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40inquirer/core@9.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40inquirer/core@9.2.1"
  ],
  "symbols": [
    "@inquirer/core.Separator",
    "@inquirer/core.makeTheme",
    "@inquirer/core.isUpKey",
    "@inquirer/core.isDownKey",
    "@inquirer/core.AbortPromptError",
    "@inquirer/core.createPrompt"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { Readable, Writable } from 'node:stream';
import {
  createPrompt,
  Separator,
  makeTheme,
  createCustomSeparator,
  buildPromptTheme,
  isUpKey,
  isDownKey,
  isSpaceKey,
  isBackspaceKey,
  isNumberKey,
  isEnterKey,
  AbortPromptError,
  CancelPromptError,
  ExitPromptError,
  HookError,
  ValidationError
} from '../index.mjs';

async function testAll() {
  // Contract 1: assert Separator creates separator choices and recognizes separator duck typing
  {
    const defaultSep = new Separator();
    assert.equal(defaultSep.type, 'separator');
    assert.ok(defaultSep.separator.length > 0);
    assert.equal(Separator.isSeparator(defaultSep), true);
    assert.equal(Separator.isSeparator({ type: 'separator' }), true);
    assert.equal(Separator.isSeparator({ type: 'choice' }), false);
    assert.equal(Separator.isSeparator(null), false);
    assert.equal(Separator.isSeparator(undefined), false);
    assert.equal(Separator.isSeparator('separator'), false);

    const customSep = createCustomSeparator('--- options ---');
    assert.equal(customSep.type, 'separator');
    assert.equal(customSep.separator, '--- options ---');
    assert.equal(Separator.isSeparator(customSep), true);
  }

  // Contract 2: assert makeTheme produces default theme with prompt styling functions and deep-merges overrides
  {
    const defaultTheme = makeTheme();
    assert.equal(typeof defaultTheme.prefix, 'object');
    assert.ok('idle' in defaultTheme.prefix);
    assert.ok('done' in defaultTheme.prefix);
    assert.equal(typeof defaultTheme.spinner, 'object');
    assert.equal(defaultTheme.spinner.interval, 80);
    assert.ok(Array.isArray(defaultTheme.spinner.frames));
    assert.equal(typeof defaultTheme.style.message, 'function');
    assert.equal(typeof defaultTheme.style.answer, 'function');
    assert.equal(typeof defaultTheme.style.error, 'function');
    assert.equal(typeof defaultTheme.style.defaultAnswer, 'function');
    assert.equal(typeof defaultTheme.style.help, 'function');
    assert.equal(typeof defaultTheme.style.highlight, 'function');
    assert.equal(typeof defaultTheme.style.key, 'function');

    const customTheme = buildPromptTheme({ prefix: '>>' });
    assert.equal(customTheme.prefix, '>>');
    assert.equal(typeof customTheme.style.message, 'function');

    const deepTheme = makeTheme({
      prefix: { idle: '?' },
      spinner: { interval: 100 }
    });
    assert.equal(deepTheme.prefix.idle, '?');
    assert.equal(deepTheme.prefix.done, defaultTheme.prefix.done);
    assert.equal(deepTheme.spinner.interval, 100);
  }

  // Contract 3: assert key helpers detect navigation and control keypress events including vim bindings
  {
    assert.equal(isUpKey({ name: 'up', ctrl: false }), true);
    assert.equal(isUpKey({ name: 'k', ctrl: false }), true);
    assert.equal(isUpKey({ name: 'p', ctrl: true }), true);
    assert.equal(isUpKey({ name: 'down', ctrl: false }), false);

    assert.equal(isDownKey({ name: 'down', ctrl: false }), true);
    assert.equal(isDownKey({ name: 'j', ctrl: false }), true);
    assert.equal(isDownKey({ name: 'n', ctrl: true }), true);
    assert.equal(isDownKey({ name: 'up', ctrl: false }), false);

    assert.equal(isSpaceKey({ name: 'space', ctrl: false }), true);
    assert.equal(isSpaceKey({ name: 'enter', ctrl: false }), false);

    assert.equal(isBackspaceKey({ name: 'backspace', ctrl: false }), true);
    assert.equal(isBackspaceKey({ name: 'delete', ctrl: false }), false);

    assert.equal(isNumberKey({ name: '1', ctrl: false }), true);
    assert.equal(isNumberKey({ name: '9', ctrl: false }), true);
    assert.equal(isNumberKey({ name: '0', ctrl: false }), false);
    assert.equal(isNumberKey({ name: 'a', ctrl: false }), false);

    assert.equal(isEnterKey({ name: 'return', ctrl: false }), true);
    assert.equal(isEnterKey({ name: 'enter', ctrl: false }), true);
    assert.equal(isEnterKey({ name: 'space', ctrl: false }), false);
  }

  // Contract 4: assert error hierarchy includes AbortPromptError, CancelPromptError, and ExitPromptError
  {
    const abortErr = new AbortPromptError({ cause: 'timeout' });
    assert.ok(abortErr instanceof Error);
    assert.ok(abortErr instanceof AbortPromptError);
    assert.equal(abortErr.name, 'AbortPromptError');

    const cancelErr = new CancelPromptError('prompt cancelled');
    assert.ok(cancelErr instanceof Error);
    assert.ok(cancelErr instanceof CancelPromptError);
    assert.equal(cancelErr.name, 'CancelPromptError');

    const exitErr = new ExitPromptError('prompt exited');
    assert.ok(exitErr instanceof Error);
    assert.ok(exitErr instanceof ExitPromptError);
    assert.equal(exitErr.name, 'ExitPromptError');

    const hookErr = new HookError('hook error');
    assert.ok(hookErr instanceof Error);
    assert.ok(hookErr instanceof HookError);
    assert.equal(hookErr.name, 'HookError');

    const valErr = new ValidationError('validation failed');
    assert.ok(valErr instanceof Error);
    assert.ok(valErr instanceof ValidationError);
    assert.equal(valErr.name, 'ValidationError');
  }

  // Contract 5: assert createPrompt builds headless prompt function executable with mock streams and supports abort signals
  {
    const samplePrompt = createPrompt((config, done) => {
      done(`result:${config.message}`);
      return `Message: ${config.message}`;
    });

    const mockInput = new Readable({ read() {} });
    const mockOutput = new Writable({ write(_chunk, _enc, cb) { cb(); } });

    const answer = await samplePrompt(
      { message: 'contract-test' },
      { input: mockInput, output: mockOutput }
    );
    assert.equal(answer, 'result:contract-test');

    const abortController = new AbortController();
    abortController.abort();
    const abortInput = new Readable({ read() {} });
    const abortOutput = new Writable({ write(_chunk, _enc, cb) { cb(); } });

    await assert.rejects(
      async () => {
        await samplePrompt(
          { message: 'aborted-test' },
          { input: abortInput, output: abortOutput, signal: abortController.signal }
        );
      },
      (err) => err instanceof AbortPromptError
    );
  }

  console.log('All @inquirer/core contract tests passed.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

오리진 시더

익명