CodeSampleX

Sample

bare-tty 5.1.2

Verified sample for npm bare-tty 5.1.2. The contract ran on node 22 · linux alpine/x64 · docker and passed: package manifest specifies bare-tty 5.1.2 with…

sha256:04638a81df89079da4ebb392a22aaad983d4c2d133332e3acde5eb7a5af3c663

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Case

HOW
Goal
verify pkg:npm/bare-tty@5.1.2
Packages
Environment
node 22.23.2
Created
2026-08-27T14:45:37Z

Contract

  1. package manifest specifies bare-tty 5.1.2 with Bare native addon configuration, Apache-2.0 license, and exports for root, package, and constants subpaths
  2. declares ReadStream, WriteStream, isTTY, isatty, and constants in TypeScript definitions (index.d.ts and lib/constants.d.ts)
  3. defines constants module with mode (NORMAL, RAW, IO) and state (READING, CLOSING) bitflags
  4. implements ReadStream and WriteStream extending bare-stream Readable and Writable with TTY properties, mode configuration, and SIGWINCH resize handling
  5. implements native Bare module binding bare_tty with CMakeLists.txt build definition and provides multi-platform precompiled .bare addon binaries

Files

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

Download the source artifact (tar.gz)

Source

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/bare-tty@5.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-tty@5.1.2
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:e15b2d178b54bd7b884c19a66d6f3b3778cfb5b0c805f5561ca43548e0415c2e","constraints":{"executionContext":"node"},"contract":["package manifest specifies bare-tty 5.1.2 with Bare native addon configuration, Apache-2.0 license, and exports for root, package, and constants subpaths","declares ReadStream, WriteStream, isTTY, isatty, and constants in TypeScript definitions (index.d.ts and lib/constants.d.ts)","defines constants module with mode (NORMAL, RAW, IO) and state (READING, CLOSING) bitflags","implements ReadStream and WriteStream extending bare-stream Readable and Writable with TTY properties, mode configuration, and SIGWINCH resize handling","implements native Bare module binding bare_tty with CMakeLists.txt build definition and provides multi-platform precompiled .bare addon binaries"],"goal":"verify pkg:npm/bare-tty@5.1.2","kind":"HOW","packages":["pkg:npm/bare-tty@5.1.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bare-tty@5.1.2"],"schemaVersion":1,"subject":"pkg:npm/bare-tty@5.1.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-tty",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-tty",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-tty": "5.1.2"
      }
    },
    "node_modules/b4a": {
      "version": "1.8.1",
      "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.8.1.tgz",
      "integrity": "sha512-aiqre1Nr0B/6DgE2N5vwTc+2/oQZ4Wh1t4NznYY4E00y8LCt6NqdRv81so00oo27D8MVKTpUa/MwUUtBLXCoDw==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "react-native-b4a": "*"
      },
      "peerDependenciesMeta": {
        "react-native-b4a": {
          "optional": true
        }
      }
    },
    "node_modules/bare-events": {
      "version": "2.9.2",
      "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.2.tgz",
      "integrity": "sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "bare-abort-controller": "*"
      },
      "peerDependenciesMeta": {
        "bare-abort-controller": {
          "optional": true
        }
      }
    },
    "node_modules/bare-signals": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/bare-signals/-/bare-signals-5.0.0.tgz",
      "integrity": "sha512-8Gn8bBFUh2AUCJ9wWWFjSGWIo1HIUSIQnXRJGSm/f7GCDMqsuJhRmR1dT+HtDaDBkeu2l8Koxt2JLurfJ5yHVw==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-events": "^2.5.3"
      },
      "engines": {
        "bare": ">=1.7.0"
      }
    },
    "node_modules/bare-stream": {
      "version": "2.13.4",
      "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.13.4.tgz",
      "integrity": "sha512-PcrQ8lVLbiJscNm1Kez+Yp4Gy4AHGcN1lzwjvf5NybWen7VvEgUfyfnXYJ2zNqWnzOfCb1Abq6lH8ti0syQszA==",
      "license": "Apache-2.0",
      "dependencies": {
        "b4a": "^1.8.1",
        "streamx": "^2.25.0",
        "teex": "^1.0.1"
      },
      "peerDependencies": {
        "bare-abort-controller": "*",
        "bare-buffer": "*",
        "bare-events": "*"
      },
      "peerDependenciesMeta": {
        "bare-abort-controller": {
          "optional": true
        },
        "bare-buffer": {
          "optional": true
        },
        "bare-events": {
          "optional": true
        }
      }
    },
    "node_modules/bare-tty": {
      "version": "5.1.2",
      "resolved": "https://registry.npmjs.org/bare-tty/-/bare-tty-5.1.2.tgz",
      "integrity": "sha512-wDHPU/yVQtrDCUrKVdIVOLmfIw7dFPETz30UayuFlROvgz8Juv2SmISSMhqxYQVO+fVnG/1ZoLcbGh/35eAjDA==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-events": "^2.2.0",
        "bare-signals": "^5.0.0",
        "bare-stream": "^2.0.0"
      },
      "engines": {
        "bare": ">=1.16.0"
      }
    },
    "node_modules/events-universal": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/events-universal/-/events-universal-1.0.1.tgz",
      "integrity": "sha512-LUd5euvbMLpwOF8m6ivPCbhQeSiYVNb8Vs0fQ8QjXo0JTkEHpz8pxdQf0gStltaPpw0Cca8b39KxvK9cfKRiAw==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-events": "^2.7.0"
      }
    },
    "node_modules/fast-fifo": {
      "version": "1.3.2",
      "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz",
      "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==",
      "license": "MIT"
    },
    "node_modules/streamx": {
      "version": "2.28.1",
      "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.28.1.tgz",
      "integrity": "sha512-zEzXb0s5Cds7tqMH6rhZ05lcJydCWiQPEwiNngVqzsxCc962vLY4Uw+mW7od8kDH258k2Uz/JrOkdIAAhSh9VA==",
      "license": "MIT",
      "dependencies": {
        "events-universal": "^1.0.0",
        "fast-fifo": "^1.3.2",
        "text-decoder": "^1.1.0"
      }
    },
    "node_modules/teex": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/teex/-/teex-1.0.1.tgz",
      "integrity": "sha512-eYE6iEI62Ni1H8oIa7KlDU6uQBtqr4Eajni3wX7rpfXD8ysFx8z0+dri+KWEPWpBsxXfxu58x/0jvTVT1ekOSg==",
      "license": "MIT",
      "dependencies": {
        "streamx": "^2.12.5"
      }
    },
    "node_modules/text-decoder": {
      "version": "1.2.7",
      "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.7.tgz",
      "integrity": "sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==",
      "license": "Apache-2.0",
      "dependencies": {
        "b4a": "^1.6.4"
      }
    }
  }
}
package.json
{
  "name": "sample-bare-tty",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-tty": "5.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-tty@5.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-tty@5.1.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';

const require = createRequire(import.meta.url);

// 1. Resolve bare-tty package manifest and verify exports and metadata
const pkgPath = require.resolve('bare-tty/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'bare-tty', 'Package name must be bare-tty');
assert.equal(pkg.version, '5.1.2', 'Package version must be 5.1.2');
assert.equal(pkg.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.equal(pkg.addon, true, 'Package must be marked as addon');
assert.equal(pkg.engines?.bare, '>=1.16.0', 'Package must specify Bare engine >=1.16.0');

assert.ok(pkg.exports, 'Package must define exports');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must specify ./index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must specify ./index.js default');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to ./package.json');
assert.equal(pkg.exports['./constants'], './lib/constants.js', 'Constants export must point to ./lib/constants.js');

assert.deepEqual(
  pkg.files,
  ['index.js', 'index.d.ts', 'binding.c', 'binding.js', 'CMakeLists.txt', 'lib', 'prebuilds'],
  'Package files array must contain expected source and build files'
);

assert.ok(pkg.dependencies['bare-events'], 'bare-events must be a dependency');
assert.ok(pkg.dependencies['bare-signals'], 'bare-signals must be a dependency');
assert.ok(pkg.dependencies['bare-stream'], 'bare-stream must be a dependency');

const pkgDir = path.dirname(pkgPath);

// 2. Verify TypeScript declarations (index.d.ts and lib/constants.d.ts)
const indexDtsPath = path.join(pkgDir, 'index.d.ts');
assert.ok(fs.existsSync(indexDtsPath), 'index.d.ts must exist');
const indexDts = fs.readFileSync(indexDtsPath, 'utf8');

assert.ok(indexDts.includes("interface ReadStream extends Readable"), 'index.d.ts must declare ReadStream extending Readable');
assert.ok(indexDts.includes("readonly fd: number"), 'index.d.ts must declare fd property');
assert.ok(indexDts.includes("readonly isTTY: true"), 'index.d.ts must declare isTTY property');
assert.ok(indexDts.includes("setMode(mode: number): this"), 'index.d.ts must declare setMode');
assert.ok(indexDts.includes("setRawMode(mode: boolean): this"), 'index.d.ts must declare setRawMode');
assert.ok(indexDts.includes("interface WriteStreamEvents extends WritableEvents"), 'index.d.ts must declare WriteStreamEvents');
assert.ok(indexDts.includes("readonly columns: number"), 'index.d.ts must declare columns property');
assert.ok(indexDts.includes("readonly rows: number"), 'index.d.ts must declare rows property');
assert.ok(indexDts.includes("getWindowSize(): [width: number, height: number]"), 'index.d.ts must declare getWindowSize');
assert.ok(indexDts.includes("declare function isTTY(fd: number): boolean"), 'index.d.ts must declare isTTY function');
assert.ok(indexDts.includes("export { ReadStream, WriteStream, isTTY, isTTY as isatty, constants }"), 'index.d.ts must export symbols');

const constantsDtsPath = path.join(pkgDir, 'lib', 'constants.d.ts');
assert.ok(fs.existsSync(constantsDtsPath), 'lib/constants.d.ts must exist');
const constantsDts = fs.readFileSync(constantsDtsPath, 'utf8');
assert.ok(constantsDts.includes("mode: { NORMAL: number; RAW: number; IO: number }"), 'constants.d.ts must declare mode constants');
assert.ok(constantsDts.includes("state: { READING: number; CLOSING: number }"), 'constants.d.ts must declare state bitflags');

// 3. Verify JavaScript module files (lib/constants.js, index.js, binding.js)
const constantsJsPath = path.join(pkgDir, 'lib', 'constants.js');
assert.ok(fs.existsSync(constantsJsPath), 'lib/constants.js must exist');
const constantsJs = fs.readFileSync(constantsJsPath, 'utf8');
assert.ok(constantsJs.includes("READING: 0x1"), 'constants.js must define READING state bitflag 0x1');
assert.ok(constantsJs.includes("CLOSING: 0x2"), 'constants.js must define CLOSING state bitflag 0x2');
assert.ok(constantsJs.includes("NORMAL: binding.MODE_NORMAL"), 'constants.js must map MODE_NORMAL');
assert.ok(constantsJs.includes("RAW: binding.MODE_RAW"), 'constants.js must map MODE_RAW');

const indexJsPath = path.join(pkgDir, 'index.js');
assert.ok(fs.existsSync(indexJsPath), 'index.js must exist');
const indexJs = fs.readFileSync(indexJsPath, 'utf8');
assert.ok(indexJs.includes("require('bare-stream')"), 'index.js must require bare-stream');
assert.ok(indexJs.includes("require('bare-signals')"), 'index.js must require bare-signals');
assert.ok(indexJs.includes("require('./binding')"), 'index.js must require ./binding');
assert.ok(indexJs.includes("require('./lib/constants')"), 'index.js must require ./lib/constants');
assert.ok(indexJs.includes("exports.ReadStream = class TTYReadStream extends Readable"), 'index.js must export ReadStream class');
assert.ok(indexJs.includes("exports.WriteStream = class TTYWriteStream extends Writable"), 'index.js must export WriteStream class');
assert.ok(indexJs.includes("exports.isTTY = binding.isTTY"), 'index.js must export isTTY');
assert.ok(indexJs.includes("exports.isatty = exports.isTTY"), 'index.js must alias isatty to isTTY');

const bindingJsPath = path.join(pkgDir, 'binding.js');
assert.ok(fs.existsSync(bindingJsPath), 'binding.js must exist');
const bindingJs = fs.readFileSync(bindingJsPath, 'utf8');
assert.ok(bindingJs.includes('require.addon()'), 'binding.js must invoke require.addon()');

// 4. Verify C native addon source and build configuration
const bindingCPath = path.join(pkgDir, 'binding.c');
assert.ok(fs.existsSync(bindingCPath), 'binding.c must exist');
const bindingC = fs.readFileSync(bindingCPath, 'utf8');
assert.ok(bindingC.includes('#include <bare.h>'), 'binding.c must include <bare.h>');
assert.ok(bindingC.includes('#include <js.h>'), 'binding.c must include <js.h>');
assert.ok(bindingC.includes('#include <uv.h>'), 'binding.c must include <uv.h>');
assert.ok(bindingC.includes('bare_tty_init'), 'binding.c must implement bare_tty_init');
assert.ok(bindingC.includes('bare_tty_writev'), 'binding.c must implement bare_tty_writev');
assert.ok(bindingC.includes('bare_tty_resume'), 'binding.c must implement bare_tty_resume');
assert.ok(bindingC.includes('bare_tty_pause'), 'binding.c must implement bare_tty_pause');
assert.ok(bindingC.includes('bare_tty_close'), 'binding.c must implement bare_tty_close');
assert.ok(bindingC.includes('bare_tty_set_mode'), 'binding.c must implement bare_tty_set_mode');
assert.ok(bindingC.includes('bare_tty_get_window_size'), 'binding.c must implement bare_tty_get_window_size');
assert.ok(bindingC.includes('bare_tty_is_tty'), 'binding.c must implement bare_tty_is_tty');
assert.ok(bindingC.includes('BARE_MODULE(bare_tty, bare_tty_exports)'), 'binding.c must define BARE_MODULE');

const cmakePath = path.join(pkgDir, 'CMakeLists.txt');
assert.ok(fs.existsSync(cmakePath), 'CMakeLists.txt must exist');
const cmake = fs.readFileSync(cmakePath, 'utf8');
assert.ok(cmake.includes('project(bare_tty C)'), 'CMakeLists.txt must define project bare_tty');
assert.ok(cmake.includes('add_bare_module(bare_tty)'), 'CMakeLists.txt must declare bare module');
assert.ok(cmake.includes('binding.c'), 'CMakeLists.txt must include binding.c');

// 5. Verify prebuilt native binaries across architectures
const prebuildsDir = path.join(pkgDir, 'prebuilds');
assert.ok(fs.existsSync(prebuildsDir), 'prebuilds directory must exist');

const expectedTargets = [
  'android-arm',
  'android-arm64',
  'android-ia32',
  'android-x64',
  'darwin-arm64',
  'darwin-x64',
  'ios-arm64-simulator',
  'ios-arm64',
  'ios-x64-simulator',
  'linux-arm64',
  'linux-x64',
  'win32-arm64',
  'win32-x64'
];

for (const target of expectedTargets) {
  const binaryPath = path.join(prebuildsDir, target, 'bare-tty.bare');
  assert.ok(fs.existsSync(binaryPath), `Prebuild binary must exist for target: ${target}`);
  const stat = fs.statSync(binaryPath);
  assert.ok(stat.size > 0, `Prebuild binary for ${target} must not be empty`);
}

const linuxX64Binary = fs.readFileSync(path.join(prebuildsDir, 'linux-x64', 'bare-tty.bare'));
assert.ok(linuxX64Binary.length > 1000, 'linux-x64 prebuild binary size must exceed 1000 bytes');

// 6. Verify runtime API behavior with mocked native addon binding
const bareSignalsPkgPath = require.resolve('bare-signals/package');
const bareSignalsDir = path.dirname(bareSignalsPkgPath);
const bareSignalsBindingPath = path.join(bareSignalsDir, 'binding.js');

require.cache[bareSignalsBindingPath] = {
  id: bareSignalsBindingPath,
  filename: bareSignalsBindingPath,
  loaded: true,
  exports: {
    signals: {
      SIGWINCH: 28
    },
    init: (ctx, onsignal, onclose) => ({ ctx, onsignal, onclose }),
    start: (handle, signum) => {},
    stop: (handle) => {},
    ref: (handle) => {},
    unref: (handle) => {},
    close: (handle) => {}
  }
};

const mockBinding = {
  MODE_NORMAL: 0,
  MODE_RAW: 1,
  MODE_IO: 2,
  init: (fd, buffer, ctx, onwrite, onread, onclose) => {
    return {
      fd,
      buffer,
      ctx,
      mode: 0,
      resumed: false,
      closed: false,
      winsize: [120, 40]
    };
  },
  setMode: (handle, mode) => {
    handle.mode = mode;
  },
  getWindowSize: (handle) => {
    return handle ? handle.winsize : [80, 24];
  },
  isTTY: (fd) => {
    return typeof fd === 'number' && fd >= 0 && fd <= 2;
  },
  resume: (handle) => {
    handle.resumed = true;
  },
  pause: (handle) => {
    handle.resumed = false;
  },
  writev: (handle, bufs) => {},
  close: (handle) => {
    handle.closed = true;
  }
};

require.cache[bindingJsPath] = {
  id: bindingJsPath,
  filename: bindingJsPath,
  loaded: true,
  exports: mockBinding
};

delete require.cache[constantsJsPath];
delete require.cache[indexJsPath];

const bareTty = require(indexJsPath);

// Verify exported symbols
assert.ok(bareTty.ReadStream, 'bare-tty must export ReadStream');
assert.ok(bareTty.WriteStream, 'bare-tty must export WriteStream');
assert.ok(bareTty.isTTY, 'bare-tty must export isTTY');
assert.strictEqual(bareTty.isatty, bareTty.isTTY, 'bare-tty isatty must be identical to isTTY');
assert.ok(bareTty.constants, 'bare-tty must export constants');

// Verify constants values
assert.equal(bareTty.constants.mode.NORMAL, 0, 'mode.NORMAL must match binding.MODE_NORMAL (0)');
assert.equal(bareTty.constants.mode.RAW, 1, 'mode.RAW must match binding.MODE_RAW (1)');
assert.equal(bareTty.constants.mode.IO, 2, 'mode.IO must match binding.MODE_IO (2)');
assert.equal(bareTty.constants.state.READING, 1, 'state.READING must be 1');
assert.equal(bareTty.constants.state.CLOSING, 2, 'state.CLOSING must be 2');

// Verify isTTY detection
assert.equal(bareTty.isTTY(0), true, 'isTTY(0) must return true for stdin');
assert.equal(bareTty.isTTY(1), true, 'isTTY(1) must return true for stdout');
assert.equal(bareTty.isTTY(2), true, 'isTTY(2) must return true for stderr');
assert.equal(bareTty.isTTY(3), false, 'isTTY(3) must return false for non-tty fd');
assert.equal(bareTty.isatty(0), true, 'isatty(0) must return true for stdin');

// Verify ReadStream creation and mode manipulation
const readStream = new bareTty.ReadStream(0);
assert.equal(readStream.fd, 0, 'ReadStream fd must be 0');
assert.equal(readStream.isTTY, true, 'ReadStream isTTY must be true');

readStream.setRawMode(true);
assert.equal(readStream._handle.mode, bareTty.constants.mode.RAW, 'setRawMode(true) must set mode to RAW');

readStream.setRawMode(false);
assert.equal(readStream._handle.mode, bareTty.constants.mode.NORMAL, 'setRawMode(false) must set mode to NORMAL');

readStream.setMode(2);
assert.equal(readStream._handle.mode, 2, 'setMode(2) must pass mode directly to handle');

// Verify WriteStream creation and geometry inspection
const writeStream = new bareTty.WriteStream(1);
assert.equal(writeStream.fd, 1, 'WriteStream fd must be 1');
assert.equal(writeStream.isTTY, true, 'WriteStream isTTY must be true');
assert.equal(writeStream.columns, 120, 'WriteStream columns must equal window width');
assert.equal(writeStream.rows, 40, 'WriteStream rows must equal window height');
assert.deepEqual(writeStream.getWindowSize(), [120, 40], 'getWindowSize must return [width, height]');

// Verify WriteStream resize event handling
let resizeEventFired = false;
writeStream.on('resize', () => {
  resizeEventFired = true;
});

writeStream._handle.winsize = [160, 50];
writeStream._onresize();
assert.equal(resizeEventFired, true, 'WriteStream _onresize must trigger resize event');
assert.equal(writeStream.columns, 160, 'columns must update after resize');
assert.equal(writeStream.rows, 50, 'rows must update after resize');

console.log('Contract tests passed successfully.');

Origin Seeder

anonymous