CodeSampleX

샘플

yocto-queue 1.2.2

검증된 샘플 — npm yocto-queue 1.2.2. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Queue initializes empty with size 0 and peek returning undefined

sha256:259a4c02582cb95ab1c564c1909cb06bb921cdce6c7d750f37de0a2789422374

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/yocto-queue@1.2.2
패키지
환경
node 22.23.2
생성일
2026-08-23T16:04:19Z

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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/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.');

오리진 시더

익명