CodeSampleX

Ejemplo

@xterm/addon-fit 0.10.0: FitAddon

Muestra verificada para npm @xterm/addon-fit 0.10.0: FitAddon. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:18f7ad0e45522822a3448be970b0c99828f43c8c2e8bb52d1cec769671e10bf1

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-23
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-07

Caso

HOW
Objetivo
verify @xterm/addon-fit.FitAddon in pkg:npm/%40xterm/addon-fit@0.10.0
Paquetes
Símbolos
  • @xterm/addon-fit.FitAddon
Creado
2026-08-23T15:00:32Z

Contrato

  1. new FitAddon() creates an instance with activate, dispose, fit, and proposeDimensions methods
  2. fitAddon.proposeDimensions() returns undefined when terminal is not attached or lacks DOM element
  3. fitAddon.proposeDimensions() calculates terminal cols and rows based on container dimensions and cell geometry
  4. fitAddon.fit() triggers terminal resize to proposed dimensions and clears renderer cache
  5. fitAddon.dispose() cleanly completes addon lifecycle

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 @xterm/addon-fit.FitAddon in pkg:npm/%40xterm/addon-fit@0.10.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40xterm/addon-fit@0.10.0
Demonstrate these symbols/APIs:
  - @xterm/addon-fit.FitAddon

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:a9f0c827dc451e1eb5b63f7194a5a33d4d3c6df1431b65f77f72723c5c42df27","contract":["new FitAddon() creates an instance with activate, dispose, fit, and proposeDimensions methods","fitAddon.proposeDimensions() returns undefined when terminal is not attached or lacks DOM element","fitAddon.proposeDimensions() calculates terminal cols and rows based on container dimensions and cell geometry","fitAddon.fit() triggers terminal resize to proposed dimensions and clears renderer cache","fitAddon.dispose() cleanly completes addon lifecycle"],"goal":"verify @xterm/addon-fit.FitAddon in pkg:npm/%40xterm/addon-fit@0.10.0","kind":"HOW","packages":["pkg:npm/%40xterm/addon-fit@0.10.0"],"schemaVersion":1,"symbols":["@xterm/addon-fit.FitAddon"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40xterm/addon-fit@0.10.0"],"schemaVersion":1,"subject":"pkg:npm/%40xterm/addon-fit@0.10.0","symbols":["@xterm/addon-fit.FitAddon"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-addon-fit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-addon-fit",
      "version": "1.0.0",
      "dependencies": {
        "@xterm/addon-fit": "0.10.0"
      }
    },
    "node_modules/@xterm/addon-fit": {
      "version": "0.10.0",
      "resolved": "https://registry.npmjs.org/@xterm/addon-fit/-/addon-fit-0.10.0.tgz",
      "integrity": "sha512-UFYkDm4HUahf2lnEyHvio51TNGiLK66mqP2JoATy7hRZeXaGMRDr00JiSF7m63vR5WKATF605yEggJKsw0JpMQ==",
      "license": "MIT",
      "peerDependencies": {
        "@xterm/xterm": "^5.0.0"
      }
    },
    "node_modules/@xterm/xterm": {
      "version": "5.5.0",
      "resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz",
      "integrity": "sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==",
      "license": "MIT",
      "peer": true
    }
  }
}
package.json
{
  "name": "sample-addon-fit",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "@xterm/addon-fit": "0.10.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @xterm/addon-fit.FitAddon in pkg:npm/%40xterm/addon-fit@0.10.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40xterm/addon-fit@0.10.0"
  ],
  "symbols": [
    "@xterm/addon-fit.FitAddon"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';

// Node.js compatibility: @xterm/addon-fit expects global `self` and `window`
globalThis.self = globalThis;

// Dynamic import ensures globalThis.self is defined before evaluating addon-fit module
const { FitAddon } = await import('@xterm/addon-fit');

// 1. Instantiation and API surface
const fitAddon = new FitAddon();
assert.equal(typeof fitAddon.activate, 'function');
assert.equal(typeof fitAddon.dispose, 'function');
assert.equal(typeof fitAddon.fit, 'function');
assert.equal(typeof fitAddon.proposeDimensions, 'function');

// 2. Propose dimensions without attached terminal
assert.equal(fitAddon.proposeDimensions(), undefined);

// 3. Propose dimensions when terminal lacks DOM element
const unattachedTerminal = {
  rows: 24,
  cols: 80,
  options: { scrollback: 1000 },
  _core: {}
};
fitAddon.activate(unattachedTerminal);
assert.equal(fitAddon.proposeDimensions(), undefined);

// 4. Fitting with mock DOM environment and terminal render dimensions
const parentElement = {};
const terminalElement = { parentElement };
let resizedCols = 0;
let resizedRows = 0;
let cleared = false;

const mockTerminal = {
  element: terminalElement,
  rows: 24,
  cols: 80,
  options: { scrollback: 1000 },
  _core: {
    _renderService: {
      dimensions: {
        css: {
          cell: { width: 9, height: 17 }
        }
      },
      clear: () => {
        cleared = true;
      }
    },
    viewport: { scrollBarWidth: 15 }
  },
  resize: (cols, rows) => {
    resizedCols = cols;
    resizedRows = rows;
    mockTerminal.cols = cols;
    mockTerminal.rows = rows;
  }
};

globalThis.window = {
  getComputedStyle: (el) => {
    if (el === parentElement) {
      return {
        getPropertyValue: (prop) => {
          if (prop === 'height') return '680px';
          if (prop === 'width') return '915px';
          return '0px';
        }
      };
    }
    if (el === terminalElement) {
      return {
        getPropertyValue: (prop) => '0px'
      };
    }
    return { getPropertyValue: () => '0px' };
  }
};

fitAddon.activate(mockTerminal);

// Propose dimensions calculation:
// availableWidth = 915 - 0 (padding) - 15 (scrollbar) = 900 -> cols = 900 / 9 = 100
// availableHeight = 680 - 0 (padding) = 680 -> rows = 680 / 17 = 40
const dimensions = fitAddon.proposeDimensions();
assert.deepEqual(dimensions, { cols: 100, rows: 40 });

// Trigger terminal fit and verify resize + render clear
fitAddon.fit();
assert.equal(resizedCols, 100);
assert.equal(resizedRows, 40);
assert.equal(cleared, true);

// 5. Dispose cleanup
fitAddon.dispose();

Seeder de origen

anónimo