CodeSampleX

Exemplo

yocto-queue 1.2.2

Amostra verificada para npm yocto-queue 1.2.2. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: Queue initializes empty with size 0 and peek…

sha256:259a4c02582cb95ab1c564c1909cb06bb921cdce6c7d750f37de0a2789422374

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify pkg:npm/yocto-queue@1.2.2
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-23T16:04:19Z

Contrato

  1. Queue initializes empty with size 0 and peek returning undefined
  2. enqueue adds items to queue and increments size
  3. dequeue removes and returns items in FIFO order until empty
  4. peek returns the next item without removing it
  5. clear resets queue to empty size 0
  6. Queue instance is iterable with for...of and spread without mutating queue
  7. drain yields and removes all items in FIFO order until queue is empty

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/yocto-queue@1.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/yocto-queue@1.2.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:c333258b2d1d4a18bc240fc8f8bee2b3e31e4392898788b5e250b566ea8d0392","constraints":{"executionContext":"node"},"contract":["Queue initializes empty with size 0 and peek returning undefined","enqueue adds items to queue and increments size","dequeue removes and returns items in FIFO order until empty","peek returns the next item without removing it","clear resets queue to empty size 0","Queue instance is iterable with for...of and spread without mutating queue","drain yields and removes all items in FIFO order until queue is empty"],"goal":"verify pkg:npm/yocto-queue@1.2.2","kind":"HOW","packages":["pkg:npm/yocto-queue@1.2.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":"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/yocto-queue@1.2.2"],"schemaVersion":1,"subject":"pkg:npm/yocto-queue@1.2.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-yocto-queue",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-yocto-queue",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "yocto-queue": "1.2.2"
      }
    },
    "node_modules/yocto-queue": {
      "version": "1.2.2",
      "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz",
      "integrity": "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==",
      "license": "MIT",
      "engines": {
        "node": ">=12.20"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    }
  }
}
package.json
{
  "name": "sample-yocto-queue",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "yocto-queue": "1.2.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/yocto-queue@1.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/yocto-queue@1.2.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import Queue from 'yocto-queue';

/**
 * Creates a new Queue instance.
 * @returns {Queue} A new empty Queue instance.
 */
export function createQueue() {
  return new Queue();
}

/**
 * Creates a Queue instance populated with items from an iterable.
 * @param {Iterable} items Items to enqueue.
 * @returns {Queue} A populated Queue instance.
 */
export function fromIterable(items) {
  const queue = new Queue();
  for (const item of items) {
    queue.enqueue(item);
  }
  return queue;
}

/**
 * Drains all items from a queue into an array.
 * @param {Queue} queue The queue to drain.
 * @returns {Array} Array of drained items.
 */
export function drainToArray(queue) {
  return [...queue.drain()];
}

export { Queue };
export default Queue;
test/contract.mjs
import assert from 'node:assert/strict';
import Queue from 'yocto-queue';
import { createQueue, fromIterable, drainToArray } from '../src/index.mjs';

// 1. Queue initializes empty with size 0 and peek returning undefined
{
  const queue = new Queue();
  assert.equal(queue.size, 0);
  assert.equal(queue.peek(), undefined);
  assert.equal(queue.dequeue(), undefined);

  const helperQueue = createQueue();
  assert.equal(helperQueue.size, 0);
  assert.equal(helperQueue.peek(), undefined);
}

// 2. enqueue adds items to queue and increments size
{
  const queue = new Queue();
  queue.enqueue('item1');
  assert.equal(queue.size, 1);
  queue.enqueue('item2');
  assert.equal(queue.size, 2);
  queue.enqueue('item3');
  assert.equal(queue.size, 3);
}

// 3. dequeue removes and returns items in FIFO order until empty
{
  const queue = new Queue();
  queue.enqueue(10);
  queue.enqueue(20);
  queue.enqueue(30);

  assert.equal(queue.dequeue(), 10);
  assert.equal(queue.size, 2);
  assert.equal(queue.dequeue(), 20);
  assert.equal(queue.size, 1);
  assert.equal(queue.dequeue(), 30);
  assert.equal(queue.size, 0);
  assert.equal(queue.dequeue(), undefined);
  assert.equal(queue.size, 0);
}

// 4. peek returns the next item without removing it
{
  const queue = new Queue();
  queue.enqueue('first');
  queue.enqueue('second');

  assert.equal(queue.peek(), 'first');
  assert.equal(queue.size, 2);
  assert.equal(queue.peek(), 'first');
  assert.equal(queue.dequeue(), 'first');
  assert.equal(queue.peek(), 'second');
  assert.equal(queue.size, 1);
}

// 5. clear resets queue to empty size 0
{
  const queue = new Queue();
  queue.enqueue('a');
  queue.enqueue('b');
  assert.equal(queue.size, 2);

  queue.clear();
  assert.equal(queue.size, 0);
  assert.equal(queue.peek(), undefined);
  assert.equal(queue.dequeue(), undefined);

  queue.enqueue('c');
  assert.equal(queue.size, 1);
  assert.equal(queue.dequeue(), 'c');
}

// 6. Queue instance is iterable with for...of and spread without mutating queue
{
  const queue = fromIterable(['x', 'y', 'z']);
  assert.equal(queue.size, 3);

  const collected = [];
  for (const item of queue) {
    collected.push(item);
  }
  assert.deepEqual(collected, ['x', 'y', 'z']);
  assert.deepEqual([...queue], ['x', 'y', 'z']);
  assert.equal(queue.size, 3);
  assert.equal(queue.dequeue(), 'x');
  assert.equal(queue.size, 2);
}

// 7. drain yields and removes all items in FIFO order until queue is empty
{
  const queue = fromIterable(['alpha', 'beta', 'gamma']);
  assert.equal(queue.size, 3);

  const drained = drainToArray(queue);
  assert.deepEqual(drained, ['alpha', 'beta', 'gamma']);
  assert.equal(queue.size, 0);
  assert.equal(queue.peek(), undefined);
  assert.equal(queue.dequeue(), undefined);
}

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

Seeder de origem

anônimo