CodeSampleX

Beispiel

jest-worker 30.4.1: PriorityQueue

Verifiziertes Beispiel für npm jest-worker 30.4.1: PriorityQueue. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:5ee0e438df85bd57ebeb1583dc2512d3f8572290ccb8a82d90a2330603e8628b

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 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

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

Fall

HOW
Ziel
verify jest-worker.PriorityQueue in pkg:npm/jest-worker@30.4.1
Pakete
Symbole
  • jest-worker.PriorityQueue
Umgebung
node 22.23.2
Erstellt
2026-09-03T05:16:32Z

Contract

  1. PriorityQueue class is exported by jest-worker and instantiable with a computePriority callback
  2. computePriority callback receives task method name and arguments to calculate numeric priority
  3. enqueue without workerId enqueues tasks into shared queue and dequeue retrieves lower priority numbers first
  4. enqueue with workerId enqueues tasks into worker-specific queue and dequeue isolates tasks per worker
  5. dequeue prioritizes worker-specific tasks over shared tasks when they have the same priority
  6. dequeue returns null when both worker-specific and shared queues are empty

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 jest-worker.PriorityQueue in pkg:npm/jest-worker@30.4.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/jest-worker@30.4.1
Demonstrate these symbols/APIs:
  - jest-worker.PriorityQueue

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:c0a9aadac742fde5a978aa3453573c2834dc4b66f629741c23cccedac6627b0e","contract":["PriorityQueue class is exported by jest-worker and instantiable with a computePriority callback","computePriority callback receives task method name and arguments to calculate numeric priority","enqueue without workerId enqueues tasks into shared queue and dequeue retrieves lower priority numbers first","enqueue with workerId enqueues tasks into worker-specific queue and dequeue isolates tasks per worker","dequeue prioritizes worker-specific tasks over shared tasks when they have the same priority","dequeue returns null when both worker-specific and shared queues are empty"],"goal":"verify jest-worker.PriorityQueue in pkg:npm/jest-worker@30.4.1","kind":"HOW","packages":["pkg:npm/jest-worker@30.4.1"],"schemaVersion":1,"symbols":["jest-worker.PriorityQueue"]},"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/jest-worker@30.4.1"],"schemaVersion":1,"subject":"pkg:npm/jest-worker@30.4.1","symbols":["jest-worker.PriorityQueue"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { PriorityQueue } from 'jest-worker';

export { PriorityQueue };

/**
 * Instantiates a new PriorityQueue with the given priority computation function.
 *
 * @param {Function} computePriority - Function that receives (method, ...args) and returns numeric priority
 * @returns {PriorityQueue}
 */
export function createPriorityQueue(computePriority) {
  return new PriorityQueue(computePriority);
}

/**
 * Creates a mock child message task structure compatible with jest-worker QueueChildMessage.
 *
 * @param {string|number} id - Task identifier
 * @param {string} [methodName='runTask'] - Method name in the child message call
 * @param {Array<unknown>} [args=[]] - Arguments array
 * @returns {object} QueueChildMessage task
 */
export function createQueueTask(id, methodName = 'runTask', args = []) {
  return {
    request: [1, false, methodName, args],
    onStart: () => {},
    onEnd: () => {},
    onCustomMessage: () => {},
    id,
  };
}

/**
 * Enqueues a task into a PriorityQueue.
 *
 * @param {PriorityQueue} queue - Queue instance
 * @param {object} task - Task to enqueue
 * @param {number} [workerId] - Target worker ID
 */
export function enqueueTask(queue, task, workerId) {
  queue.enqueue(task, workerId);
}

/**
 * Dequeues the highest-priority task from a PriorityQueue for the given worker.
 *
 * @param {PriorityQueue} queue - Queue instance
 * @param {number} workerId - Worker ID
 * @returns {object|null} Next task or null
 */
export function dequeueTask(queue, workerId) {
  return queue.dequeue(workerId);
}
package-lock.json
{
  "name": "sample-jest-worker-priority-queue",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-worker-priority-queue",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "jest-worker": "30.4.1"
      }
    },
    "node_modules/@jest/pattern": {
      "version": "30.4.0",
      "resolved": "https://registry.npmjs.org/@jest/pattern/-/pattern-30.4.0.tgz",
      "integrity": "sha512-RAWn3+f9u8BsHijKJ71uHcFp6vmyEt6VvoWXkl6hKF3qVIuWNmudVjg12DlBPGup/frIl5UcUlH5HfEuvHpEXg==",
      "license": "MIT",
      "dependencies": {
        "@types/node": "*",
        "jest-regex-util": "30.4.0"
      },
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/@jest/schemas": {
      "version": "30.4.1",
      "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-30.4.1.tgz",
      "integrity": "sha512-i6b4qw5qnP8c5FEeBJg/uZQ4ddrkN6Ca8qISJh0pr7a5hfn3h3v5x60BEbOC7OYAGZNMs1LfFLwnW2CuK8F57Q==",
      "license": "MIT",
      "dependencies": {
        "@sinclair/typebox": "^0.34.0"
      },
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/@jest/types": {
      "version": "30.4.1",
      "resolved": "https://registry.npmjs.org/@jest/types/-/types-30.4.1.tgz",
      "integrity": "sha512-f1x/vJXIfjOlEmejYpbkbgw1gOqpPECwMvMEtBqe47j7H2Hg8h8w3o3ikhSXq3MI15kg+oQ0exWO0uCtTNJLoQ==",
      "license": "MIT",
      "dependencies": {
        "@jest/pattern": "30.4.0",
        "@jest/schemas": "30.4.1",
        "@types/istanbul-lib-coverage": "^2.0.6",
        "@types/istanbul-reports": "^3.0.4",
        "@types/node": "*",
        "@types/yargs": "^17.0.33",
        "chalk": "^4.1.2"
      },
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/@sinclair/typebox": {
      "version": "0.34.52",
      "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.52.tgz",
      "integrity": "sha512-XiMQh7qqVlxZzcVD+kkGMNGMzcTrDMLWI7S4x7z1MkCkbDPrekpZXEUK0eZqZFMuHQg2a2DZOcDIh9o5v3Gonw==",
      "license": "MIT"
    },
    "node_modules/@types/istanbul-lib-coverage": {
      "version": "2.0.6",
      "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz",
      "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==",
      "license": "MIT"
    },
    "node_modules/@types/istanbul-lib-report": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz",
      "integrity": "sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==",
      "license": "MIT",
      "dependencies": {
        "@types/istanbul-lib-coverage": "*"
      }
    },
    "node_modules/@types/istanbul-reports": {
      "version": "3.0.4",
      "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz",
      "integrity": "sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==",
      "license": "MIT",
      "dependencies": {
        "@types/istanbul-lib-report": "*"
      }
    },
    "node_modules/@types/node": {
      "version": "26.4.1",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-26.4.1.tgz",
      "integrity": "sha512-k97ENvZWtvA6yqz5/FS6a7duDgOPEeOQOc2iKS/nY6mX6qJUKtLnWzQS+Xj6tXweyj6ZcTAK2Qecetnvi9nCLA==",
      "license": "MIT",
      "dependencies": {
        "undici-types": "~8.3.0"
      }
    },
    "node_modules/@types/yargs": {
      "version": "17.0.35",
      "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.35.tgz",
      "integrity": "sha512-qUHkeCyQFxMXg79wQfTtfndEC+N9ZZg76HJftDJp+qH2tV7Gj4OJi7l+PiWwJ+pWtW8GwSmqsDj/oymhrTWXjg==",
      "license": "MIT",
      "dependencies": {
        "@types/yargs-parser": "*"
      }
    },
    "node_modules/@types/yargs-parser": {
      "version": "21.0.3",
      "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz",
      "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==",
      "license": "MIT"
    },
    "node_modules/@ungap/structured-clone": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.4.0.tgz",
      "integrity": "sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==",
      "license": "ISC"
    },
    "node_modules/ansi-styles": {
      "version": "4.3.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
      "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
      "license": "MIT",
      "dependencies": {
        "color-convert": "^2.0.1"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/chalk": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
      "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^4.1.0",
        "supports-color": "^7.1.0"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/chalk?sponsor=1"
      }
    },
    "node_modules/chalk/node_modules/supports-color": {
      "version": "7.2.0",
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
      "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
      "license": "MIT",
      "dependencies": {
        "has-flag": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/ci-info": {
      "version": "4.4.0",
      "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.4.0.tgz",
      "integrity": "sha512-77PSwercCZU2Fc4sX94eF8k8Pxte6JAwL4/ICZLFjJLqegs7kCuAsqqj/70NQF6TvDpgFjkubQB2FW2ZZddvQg==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/sibiraj-s"
        }
      ],
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/color-convert": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
      "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
      "license": "MIT",
      "dependencies": {
        "color-name": "~1.1.4"
      },
      "engines": {
        "node": ">=7.0.0"
      }
    },
    "node_modules/color-name": {
      "version": "1.1.4",
      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
      "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
      "license": "MIT"
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/has-flag": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
      "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/jest-regex-util": {
      "version": "30.4.0",
      "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-30.4.0.tgz",
      "integrity": "sha512-mWlvLviKIgIQ8VCuM1xRdD0TWp3zlzionlmDBjuXVBs+VkmXq6FgW9T4Emr7oGz/Rk6feDCGyiugolcQEyp3mg==",
      "license": "MIT",
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/jest-util": {
      "version": "30.4.1",
      "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-30.4.1.tgz",
      "integrity": "sha512-vjQb1sACEiv13DKJMDToJpzVW0joCsIQrmbg0fi7CyOOt+g9jTuQl2A216pWRBYhOVt53XbL/2LbMKg1BECWOw==",
      "license": "MIT",
      "dependencies": {
        "@jest/types": "30.4.1",
        "@types/node": "*",
        "chalk": "^4.1.2",
        "ci-info": "^4.2.0",
        "graceful-fs": "^4.2.11",
        "picomatch": "^4.0.3"
      },
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/jest-worker": {
      "version": "30.4.1",
      "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-30.4.1.tgz",
      "integrity": "sha512-SHynN/q/QD++iNyvMdy+WMmbCGk8jIsNcRxycXbWubSOhvo6T+j2afcfUSl+3hYsiBebOTo0cT7c2H7CXugu1g==",
      "license": "MIT",
      "dependencies": {
        "@types/node": "*",
        "@ungap/structured-clone": "^1.3.0",
        "jest-util": "30.4.1",
        "merge-stream": "^2.0.0",
        "supports-color": "^8.1.1"
      },
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/merge-stream": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
      "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
      "license": "MIT"
    },
    "node_modules/picomatch": {
      "version": "4.0.7",
      "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
      "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      },
      "funding": {
        "url": "https://github.com/sponsors/jonschlinkert"
      }
    },
    "node_modules/supports-color": {
      "version": "8.1.1",
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
      "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
      "license": "MIT",
      "dependencies": {
        "has-flag": "^4.0.0"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/supports-color?sponsor=1"
      }
    },
    "node_modules/undici-types": {
      "version": "8.3.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
      "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-jest-worker-priority-queue",
  "version": "1.0.0",
  "description": "Clean-room verification sample for jest-worker.PriorityQueue",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "jest-worker": "30.4.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify jest-worker.PriorityQueue in pkg:npm/jest-worker@30.4.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/jest-worker@30.4.1"
  ],
  "symbols": [
    "jest-worker.PriorityQueue"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  PriorityQueue,
  createPriorityQueue,
  createQueueTask,
  enqueueTask,
  dequeueTask,
} from '../index.mjs';

// Contract 1: PriorityQueue class is exported by jest-worker and instantiable with a computePriority callback
{
  assert.strictEqual(typeof PriorityQueue, 'function');
  const queue = createPriorityQueue((method, ...args) => 0);
  assert.ok(queue instanceof PriorityQueue);
  assert.strictEqual(typeof queue.enqueue, 'function');
  assert.strictEqual(typeof queue.dequeue, 'function');
}

// Contract 2: computePriority callback receives task method name and arguments to calculate numeric priority
{
  const queue = createPriorityQueue((method, basePriority) => {
    if (method === 'urgent') return 1;
    if (method === 'normal') return basePriority;
    return 100;
  });

  const taskNormal = createQueueTask('task-normal', 'normal', [10]);
  const taskUrgent = createQueueTask('task-urgent', 'urgent', []);
  const taskFallback = createQueueTask('task-fallback', 'other', []);

  enqueueTask(queue, taskFallback);
  enqueueTask(queue, taskNormal);
  enqueueTask(queue, taskUrgent);

  assert.strictEqual(dequeueTask(queue, 0), taskUrgent);
  assert.strictEqual(dequeueTask(queue, 0), taskNormal);
  assert.strictEqual(dequeueTask(queue, 0), taskFallback);
}

// Contract 3: enqueue without workerId enqueues tasks into shared queue and dequeue retrieves lower priority numbers first
{
  const queue = createPriorityQueue((method, priority) => priority);
  const taskLow = createQueueTask('task-low', 'run', [100]);
  const taskMed = createQueueTask('task-med', 'run', [50]);
  const taskHigh = createQueueTask('task-high', 'run', [10]);

  enqueueTask(queue, taskLow);
  enqueueTask(queue, taskHigh);
  enqueueTask(queue, taskMed);

  assert.strictEqual(dequeueTask(queue, 0), taskHigh);
  assert.strictEqual(dequeueTask(queue, 1), taskMed);
  assert.strictEqual(dequeueTask(queue, 2), taskLow);
  assert.strictEqual(dequeueTask(queue, 0), null);
}

// Contract 4: enqueue with workerId enqueues tasks into worker-specific queue and dequeue isolates tasks per worker
{
  const queue = createPriorityQueue((method, priority) => priority);
  const taskW0 = createQueueTask('w0-task', 'run', [10]);
  const taskW1 = createQueueTask('w1-task', 'run', [10]);

  enqueueTask(queue, taskW0, 0);
  enqueueTask(queue, taskW1, 1);

  assert.strictEqual(dequeueTask(queue, 0), taskW0);
  assert.strictEqual(dequeueTask(queue, 0), null);

  assert.strictEqual(dequeueTask(queue, 1), taskW1);
  assert.strictEqual(dequeueTask(queue, 1), null);
}

// Contract 5: dequeue prioritizes worker-specific tasks over shared tasks when they have the same priority
{
  const queue = createPriorityQueue((method, priority) => priority);
  const sharedTask = createQueueTask('shared-task', 'run', [10]);
  const workerTask = createQueueTask('worker-task', 'run', [10]);

  enqueueTask(queue, sharedTask);
  enqueueTask(queue, workerTask, 0);

  const first = dequeueTask(queue, 0);
  assert.strictEqual(first, workerTask);

  const second = dequeueTask(queue, 0);
  assert.strictEqual(second, sharedTask);
}

// Contract 6: dequeue returns null when both worker-specific and shared queues are empty
{
  const queue = createPriorityQueue((method, priority) => 0);
  assert.strictEqual(dequeueTask(queue, 0), null);
  assert.strictEqual(dequeueTask(queue, 1), null);
  assert.strictEqual(dequeueTask(queue, 42), null);
}

console.log('All jest-worker.PriorityQueue contract assertions passed.');

Ursprungs-Seeder

anonym