CodeSampleX

Exemplo

run-parallel 1.2.0

Amostra verificada para npm run-parallel 1.2.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: runParallel executes an array of async…

sha256:475cf853a2c84686934b02103d94cc41f6007c94778d049f4f6098e687db1b80

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@1
2026-08-20

Caso

HOW
Objetivo
verify pkg:npm/run-parallel@1.2.0
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-20T14:30:34Z

Contrato

  1. runParallel executes an array of async functions concurrently and returns results in an ordered array
  2. runParallel executes an object of named async functions concurrently and returns results in a keyed object
  3. runParallel invokes callback with error immediately when any task fails and ignores later results
  4. runParallel handles empty array and empty object tasks by invoking callback with empty results
  5. runParallel handles synchronous task execution via queueMicrotask deferral

Arquivos

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

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/run-parallel@1.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/run-parallel@1.2.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:51c0df5baa7e541d6c6c7a6f41489a79ccffad71fc79c69a28460d89d1b97902","constraints":{"executionContext":"node"},"contract":["runParallel executes an array of async functions concurrently and returns results in an ordered array","runParallel executes an object of named async functions concurrently and returns results in a keyed object","runParallel invokes callback with error immediately when any task fails and ignores later results","runParallel handles empty array and empty object tasks by invoking callback with empty results","runParallel handles synchronous task execution via queueMicrotask deferral"],"goal":"verify pkg:npm/run-parallel@1.2.0","kind":"HOW","packages":["pkg:npm/run-parallel@1.2.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/run-parallel@1.2.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-run-parallel",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-run-parallel",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "run-parallel": "1.2.0"
      }
    },
    "node_modules/queue-microtask": {
      "version": "1.2.3",
      "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
      "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
      "license": "MIT"
    },
    "node_modules/run-parallel": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
      "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
      "license": "MIT",
      "dependencies": {
        "queue-microtask": "^1.2.2"
      }
    }
  }
}
package.json
{
  "name": "sample-run-parallel",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for run-parallel",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "run-parallel": "1.2.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/run-parallel@1.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/run-parallel@1.2.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const runParallel = require('run-parallel');

function executeTasks(tasks, cb) {
  return runParallel(tasks, cb);
}

module.exports = {
  runParallel,
  executeTasks
};
test/contract.js
const assert = require('node:assert');
const runParallel = require('run-parallel');
const { executeTasks } = require('../src/index.js');

async function runTests() {
  // 1. Array of async tasks: runs concurrently and returns results in original order
  await new Promise((resolve, reject) => {
    const order = [];
    const tasks = [
      (cb) => {
        setTimeout(() => {
          order.push('task1');
          cb(null, 'result1');
        }, 30);
      },
      (cb) => {
        setTimeout(() => {
          order.push('task2');
          cb(null, 'result2');
        }, 10);
      },
      (cb) => {
        setTimeout(() => {
          order.push('task3');
          cb(null, 'result3');
        }, 20);
      }
    ];

    runParallel(tasks, (err, results) => {
      try {
        assert.ifError(err);
        assert.deepStrictEqual(order, ['task2', 'task3', 'task1'], 'tasks should execute concurrently');
        assert.deepStrictEqual(results, ['result1', 'result2', 'result3'], 'results array must match task definition order');
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  // Verify executeTasks wrapper
  await new Promise((resolve, reject) => {
    const tasks = [
      (cb) => cb(null, 100),
      (cb) => cb(null, 200)
    ];
    executeTasks(tasks, (err, results) => {
      try {
        assert.ifError(err);
        assert.deepStrictEqual(results, [100, 200]);
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  // 2. Object of async tasks: runs concurrently and returns keyed results object
  await new Promise((resolve, reject) => {
    const tasks = {
      alpha: (cb) => {
        setTimeout(() => cb(null, 'value-alpha'), 20);
      },
      beta: (cb) => {
        setTimeout(() => cb(null, 'value-beta'), 10);
      },
      gamma: (cb) => {
        setTimeout(() => cb(null, 'value-gamma'), 30);
      }
    };

    runParallel(tasks, (err, results) => {
      try {
        assert.ifError(err);
        assert.deepStrictEqual(results, {
          alpha: 'value-alpha',
          beta: 'value-beta',
          gamma: 'value-gamma'
        }, 'results object must map each key to its task result');
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  // 3. Error handling: short-circuits on first error and ignores subsequent task completions
  await new Promise((resolve, reject) => {
    const expectedError = new Error('simulated task failure');
    let callCount = 0;

    const tasks = [
      (cb) => {
        setTimeout(() => cb(null, 'delayed success'), 50);
      },
      (cb) => {
        setTimeout(() => cb(expectedError), 10);
      },
      (cb) => {
        setTimeout(() => cb(new Error('secondary error')), 40);
      }
    ];

    runParallel(tasks, (err, results) => {
      callCount++;
      try {
        assert.strictEqual(err, expectedError, 'callback should receive first error');
      } catch (e) {
        return reject(e);
      }
    });

    setTimeout(() => {
      try {
        assert.strictEqual(callCount, 1, 'callback must be called exactly once despite later events');
        resolve();
      } catch (e) {
        reject(e);
      }
    }, 70);
  });

  // 4. Empty inputs: handles empty array and empty object
  await new Promise((resolve, reject) => {
    runParallel([], (err, results) => {
      try {
        assert.ifError(err);
        assert.deepStrictEqual(results, [], 'empty array tasks must return empty array results');
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  await new Promise((resolve, reject) => {
    runParallel({}, (err, results) => {
      try {
        assert.ifError(err);
        assert.deepStrictEqual(results, {}, 'empty object tasks must return empty object results');
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  // 5. Synchronous tasks: executed with queueMicrotask deferral
  await new Promise((resolve, reject) => {
    let syncFlag = false;
    const tasks = [
      (cb) => cb(null, 'sync1'),
      (cb) => cb(null, 'sync2')
    ];

    runParallel(tasks, (err, results) => {
      try {
        assert.ifError(err);
        assert.strictEqual(syncFlag, true, 'callback should be queued on microtask queue and not run inline synchronously');
        assert.deepStrictEqual(results, ['sync1', 'sync2']);
        resolve();
      } catch (e) {
        reject(e);
      }
    });

    syncFlag = true;
  });

  console.log('All run-parallel contract assertions passed successfully.');
}

runTests().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Seeder de origem

anônimo