CodeSampleX

Beispiel

builder-util-runtime 9.7.0: CancellationError

Verifiziertes Beispiel für npm builder-util-runtime 9.7.0: CancellationError. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:a5d9bd829b07e59e98b7a574d09a81647827fb325891d7862bfd82bf5d6e2ebd

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify builder-util-runtime.CancellationError in pkg:npm/builder-util-runtime@9.7.0
Pakete
Symbole
  • builder-util-runtime.CancellationError
Erstellt
2026-08-23T13:45:39Z

Contract

  1. assert CancellationError is an instance of Error with default message cancelled
  2. assert CancellationToken rejects createPromise with CancellationError when cancelled
  3. assert already-cancelled CancellationToken immediately rejects createPromise with CancellationError

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 builder-util-runtime.CancellationError in pkg:npm/builder-util-runtime@9.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/builder-util-runtime@9.7.0
Demonstrate these symbols/APIs:
  - builder-util-runtime.CancellationError

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:6a253202ddb3beea04c6aa023c7f3d2473be51a23c10084177394b50b9f38e01","contract":["assert CancellationError is an instance of Error with default message cancelled","assert CancellationToken rejects createPromise with CancellationError when cancelled","assert already-cancelled CancellationToken immediately rejects createPromise with CancellationError"],"goal":"verify builder-util-runtime.CancellationError in pkg:npm/builder-util-runtime@9.7.0","kind":"HOW","packages":["pkg:npm/builder-util-runtime@9.7.0"],"schemaVersion":1,"symbols":["builder-util-runtime.CancellationError"]},"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/builder-util-runtime@9.7.0"],"schemaVersion":1,"subject":"pkg:npm/builder-util-runtime@9.7.0","symbols":["builder-util-runtime.CancellationError"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { CancellationError, CancellationToken } from 'builder-util-runtime';

/**
 * Creates a new CancellationError instance.
 * @returns {CancellationError}
 */
export function createCancellationError() {
  return new CancellationError();
}

/**
 * Checks if the given error is an instance of CancellationError.
 * @param {unknown} err
 * @returns {boolean}
 */
export function isCancellationError(err) {
  return err instanceof CancellationError;
}

/**
 * Executes a callback wrapped in a CancellationToken-managed promise.
 * @template T
 * @param {CancellationToken} token
 * @param {(resolve: (value: T) => void, reject: (reason?: any) => void, onCancel: (callback: () => void) => void) => void} callback
 * @returns {Promise<T>}
 */
export function withCancellation(token, callback) {
  return token.createPromise(callback);
}

export { CancellationError, CancellationToken };
package-lock.json
{
  "name": "builder-util-runtime-cancellation-error-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "builder-util-runtime-cancellation-error-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "builder-util-runtime": "9.7.0"
      }
    },
    "node_modules/builder-util-runtime": {
      "version": "9.7.0",
      "resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.7.0.tgz",
      "integrity": "sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4",
        "sax": "^1.2.4"
      },
      "engines": {
        "node": ">=12.0.0"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/sax": {
      "version": "1.6.1",
      "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz",
      "integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==",
      "license": "BlueOak-1.0.0",
      "engines": {
        "node": ">=11.0.0"
      }
    }
  }
}
package.json
{
  "name": "builder-util-runtime-cancellation-error-sample",
  "version": "1.0.0",
  "description": "Demonstrate builder-util-runtime.CancellationError usage and behavior",
  "main": "index.mjs",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "builder-util-runtime": "9.7.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify builder-util-runtime.CancellationError in pkg:npm/builder-util-runtime@9.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/builder-util-runtime@9.7.0"
  ],
  "symbols": [
    "builder-util-runtime.CancellationError"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { CancellationError, CancellationToken } from 'builder-util-runtime';
import { createCancellationError, isCancellationError, withCancellation } from '../index.mjs';

// 1. assert CancellationError is an instance of Error with default message cancelled
{
  const err = createCancellationError();
  assert.ok(err instanceof Error, 'CancellationError must be an instance of Error');
  assert.ok(err instanceof CancellationError, 'CancellationError must be an instance of CancellationError');
  assert.equal(err.message, 'cancelled', 'Default message must be cancelled');
  assert.equal(isCancellationError(err), true, 'isCancellationError helper must return true');

  const regularError = new Error('cancelled');
  assert.equal(isCancellationError(regularError), false, 'regular Error must not be CancellationError');
}

// 2. assert CancellationToken rejects createPromise with CancellationError when cancelled
{
  const token = new CancellationToken();
  let cleanupCalled = false;

  const promise = withCancellation(token, (resolve, _reject, onCancel) => {
    const timer = setTimeout(() => resolve('completed'), 1000);
    onCancel(() => {
      clearTimeout(timer);
      cleanupCalled = true;
    });
  });

  assert.equal(token.cancelled, false);
  token.cancel();
  assert.equal(token.cancelled, true);

  await assert.rejects(
    promise,
    (err) => {
      assert.ok(err instanceof CancellationError);
      assert.equal(err.message, 'cancelled');
      return true;
    },
    'Promise should reject with CancellationError when cancelled'
  );
  assert.equal(cleanupCalled, true, 'Cancellation cleanup handler should have fired');
}

// 3. assert already-cancelled CancellationToken immediately rejects createPromise with CancellationError
{
  const token = new CancellationToken();
  token.cancel();
  assert.equal(token.cancelled, true);

  let taskExecuted = false;
  const promise = withCancellation(token, (resolve) => {
    taskExecuted = true;
    resolve('done');
  });

  await assert.rejects(
    promise,
    CancellationError,
    'Already cancelled token should immediately reject with CancellationError'
  );
  assert.equal(taskExecuted, false, 'Task should not execute on already cancelled token');
}

console.log('All contract tests passed.');

Ursprungs-Seeder

anonym