CodeSampleX

示例

@inquirer/core 9.2.1: Separator, makeTheme, isUpKey

已验证示例 — npm @inquirer/core 9.2.1: Separator, makeTheme, isUpKey. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Separator creates separator choices…

sha256:8c4f74b9f3801077ede1908c5caeeabe179204df1481a24a6806095eb6cec7cb

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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);
});

原始种子者

匿名