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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.');

オリジンシーダー

匿名