CodeSampleX

Exemplo

scheduler 0.27.0

Amostra verificada para npm scheduler 0.27.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: unstable_ImmediatePriority…

sha256:633bd9bb5e7f1aa8b5f6777ee91711657d313fde1fb88e325a71e0d036e22fef

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-27

Caso

HOW
Objetivo
verify pkg:npm/scheduler@0.27.0
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-27T15:46:26Z

Contrato

  1. unstable_ImmediatePriority, unstable_UserBlockingPriority, unstable_NormalPriority, unstable_LowPriority, and unstable_IdlePriority are exported priority constants with integer values from 1 to 5
  2. unstable_getCurrentPriorityLevel returns active priority level defaulting to unstable_NormalPriority
  3. unstable_runWithPriority executes callback at specified priority level and restores previous priority level upon return
  4. unstable_wrapCallback binds a callback to current priority level for subsequent execution
  5. unstable_now returns a non-negative millisecond timestamp
  6. unstable_shouldYield returns a boolean indicating whether execution should yield to host
  7. unstable_scheduleCallback schedules tasks and returns a task descriptor with priority and callback
  8. unstable_cancelCallback cancels a scheduled task by setting its callback to null
  9. unstable_scheduleCallback supports delayed scheduling using options.delay
  10. unstable_scheduleCallback executes scheduled callbacks asynchronously in order of task priority

Arquivos

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

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/scheduler@0.27.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/scheduler@0.27.0
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:019edf74648e3750a03c560dc0a330f88de549be8ece5f539fca1d26c04e9472","constraints":{"executionContext":"node"},"contract":["unstable_ImmediatePriority, unstable_UserBlockingPriority, unstable_NormalPriority, unstable_LowPriority, and unstable_IdlePriority are exported priority constants with integer values from 1 to 5","unstable_getCurrentPriorityLevel returns active priority level defaulting to unstable_NormalPriority","unstable_runWithPriority executes callback at specified priority level and restores previous priority level upon return","unstable_wrapCallback binds a callback to current priority level for subsequent execution","unstable_now returns a non-negative millisecond timestamp","unstable_shouldYield returns a boolean indicating whether execution should yield to host","unstable_scheduleCallback schedules tasks and returns a task descriptor with priority and callback","unstable_cancelCallback cancels a scheduled task by setting its callback to null","unstable_scheduleCallback supports delayed scheduling using options.delay","unstable_scheduleCallback executes scheduled callbacks asynchronously in order of task priority"],"goal":"verify pkg:npm/scheduler@0.27.0","kind":"HOW","packages":["pkg:npm/scheduler@0.27.0"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/scheduler@0.27.0"],"schemaVersion":1,"subject":"pkg:npm/scheduler@0.27.0","verifierAdapter":"node-typescript@1"}
index.cjs
'use strict';

const scheduler = require('scheduler');

/**
 * Schedule a task with a given priority.
 * @param {number} priorityLevel
 * @param {Function} callback
 * @param {Object} [options]
 * @returns {Object}
 */
function scheduleTask(priorityLevel, callback, options) {
  return scheduler.unstable_scheduleCallback(priorityLevel, callback, options);
}

/**
 * Run a callback with a specified priority and restore previous priority.
 * @param {number} priorityLevel
 * @param {Function} callback
 * @returns {*}
 */
function runWithPriority(priorityLevel, callback) {
  return scheduler.unstable_runWithPriority(priorityLevel, callback);
}

/**
 * Wrap a callback bound to the current priority level.
 * @param {Function} callback
 * @returns {Function}
 */
function wrapCallback(callback) {
  return scheduler.unstable_wrapCallback(callback);
}

/**
 * Cancel a scheduled task.
 * @param {Object} task
 * @returns {void}
 */
function cancelTask(task) {
  scheduler.unstable_cancelCallback(task);
}

/**
 * Get the current scheduler time.
 * @returns {number}
 */
function getCurrentTime() {
  return scheduler.unstable_now();
}

/**
 * Check if the current task should yield to host.
 * @returns {boolean}
 */
function shouldYield() {
  return scheduler.unstable_shouldYield();
}

module.exports = {
  scheduler,
  scheduleTask,
  runWithPriority,
  wrapCallback,
  cancelTask,
  getCurrentTime,
  shouldYield
};
package-lock.json
{
  "name": "scheduler-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "scheduler-verification",
      "version": "1.0.0",
      "dependencies": {
        "scheduler": "0.27.0"
      }
    },
    "node_modules/scheduler": {
      "version": "0.27.0",
      "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
      "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "scheduler-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for scheduler",
  "dependencies": {
    "scheduler": "0.27.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/scheduler@0.27.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/scheduler@0.27.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const scheduler = require('scheduler');
const {
  scheduleTask,
  runWithPriority,
  wrapCallback,
  cancelTask,
  getCurrentTime,
  shouldYield
} = require('../index.cjs');

// 1. unstable_ImmediatePriority, unstable_UserBlockingPriority, unstable_NormalPriority, unstable_LowPriority, and unstable_IdlePriority are exported priority constants with integer values from 1 to 5
assert.equal(scheduler.unstable_ImmediatePriority, 1, 'unstable_ImmediatePriority must be 1');
assert.equal(scheduler.unstable_UserBlockingPriority, 2, 'unstable_UserBlockingPriority must be 2');
assert.equal(scheduler.unstable_NormalPriority, 3, 'unstable_NormalPriority must be 3');
assert.equal(scheduler.unstable_LowPriority, 4, 'unstable_LowPriority must be 4');
assert.equal(scheduler.unstable_IdlePriority, 5, 'unstable_IdlePriority must be 5');

// 2. unstable_getCurrentPriorityLevel returns active priority level defaulting to unstable_NormalPriority
assert.equal(
  scheduler.unstable_getCurrentPriorityLevel(),
  scheduler.unstable_NormalPriority,
  'Default priority level must be unstable_NormalPriority'
);

// 3. unstable_runWithPriority executes callback at specified priority level and restores previous priority level upon return
let observedPriority = null;
const returnValue = runWithPriority(scheduler.unstable_UserBlockingPriority, () => {
  observedPriority = scheduler.unstable_getCurrentPriorityLevel();
  return 'priority-test-result';
});
assert.equal(returnValue, 'priority-test-result');
assert.equal(observedPriority, scheduler.unstable_UserBlockingPriority);
assert.equal(
  scheduler.unstable_getCurrentPriorityLevel(),
  scheduler.unstable_NormalPriority,
  'Priority must be restored to NormalPriority after execution'
);

// Priority restoration after error throw
assert.throws(() => {
  runWithPriority(scheduler.unstable_ImmediatePriority, () => {
    throw new Error('priority-error');
  });
}, { message: 'priority-error' });
assert.equal(
  scheduler.unstable_getCurrentPriorityLevel(),
  scheduler.unstable_NormalPriority,
  'Priority must be restored to NormalPriority after thrown error'
);

// 4. unstable_wrapCallback binds a callback to current priority level for subsequent execution
const boundCallback = runWithPriority(scheduler.unstable_LowPriority, () => {
  return wrapCallback(() => {
    return scheduler.unstable_getCurrentPriorityLevel();
  });
});
assert.equal(scheduler.unstable_getCurrentPriorityLevel(), scheduler.unstable_NormalPriority);
assert.equal(boundCallback(), scheduler.unstable_LowPriority);
assert.equal(scheduler.unstable_getCurrentPriorityLevel(), scheduler.unstable_NormalPriority);

// 5. unstable_now returns a non-negative millisecond timestamp
const nowTime = getCurrentTime();
assert.equal(typeof nowTime, 'number');
assert.ok(nowTime >= 0, 'Timestamp must be non-negative');

// 6. unstable_shouldYield returns a boolean indicating whether execution should yield to host
const yieldFlag = shouldYield();
assert.equal(typeof yieldFlag, 'boolean');

// 7. unstable_scheduleCallback schedules tasks and returns a task descriptor with priority and callback
const dummyTask = scheduleTask(scheduler.unstable_NormalPriority, () => {});
assert.ok(dummyTask, 'scheduleCallback must return a task object');
assert.equal(typeof dummyTask.id, 'number');
assert.equal(dummyTask.priorityLevel, scheduler.unstable_NormalPriority);
assert.equal(typeof dummyTask.callback, 'function');

// 8. unstable_cancelCallback cancels a scheduled task by setting its callback to null
cancelTask(dummyTask);
assert.equal(dummyTask.callback, null, 'Cancelled task callback must be set to null');

// 9. unstable_scheduleCallback supports delayed scheduling using options.delay
const delayedTask = scheduleTask(
  scheduler.unstable_NormalPriority,
  () => {},
  { delay: 10000 }
);
assert.ok(delayedTask);
assert.ok(delayedTask.startTime >= nowTime);
cancelTask(delayedTask);

// 10. unstable_scheduleCallback executes scheduled callbacks asynchronously in order of task priority
const executionLog = [];
scheduleTask(scheduler.unstable_LowPriority, () => {
  executionLog.push('low');
});
scheduleTask(scheduler.unstable_ImmediatePriority, () => {
  executionLog.push('immediate');
});
scheduleTask(scheduler.unstable_UserBlockingPriority, () => {
  executionLog.push('user-blocking');
});

setTimeout(() => {
  assert.deepEqual(executionLog, ['immediate', 'user-blocking', 'low']);
  console.log('Contract test passed.');
}, 50);

Seeder de origem

anônimo