CodeSampleX

Exemple

neo-async 2.6.2: async.series

Échantillon vérifié pour npm neo-async 2.6.2: async.series. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:8f7938a21cf299f53e2290a9923b516b81742693bb895f57f42c0d48d0b81c8f

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-02

Cas

HOW
Objectif
verify async.series in pkg:npm/neo-async@2.6.2
Paquets
Symboles
  • async.series
Environnement
node 22.23.2
Créé
2026-09-02T06:50:12Z

Contrat

  1. series executes an array of async functions in sequential order and returns results array
  2. series executes an object of named async functions in sequence and returns results object with matching keys
  3. series short-circuits execution on error and immediately passes error to final callback
  4. series guarantees sequential execution without running subsequent tasks concurrently
  5. series handles empty task collection by invoking callback immediately with empty results
  6. seriesPromise wraps async.series to resolve results in async/await workflows

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 async.series in pkg:npm/neo-async@2.6.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/neo-async@2.6.2
Demonstrate these symbols/APIs:
  - async.series
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:3d58f48c5e0bc110e7d82e3f38bbd17909e2a19a2c4d4d23007e45f223b93212","constraints":{"executionContext":"node"},"contract":["series executes an array of async functions in sequential order and returns results array","series executes an object of named async functions in sequence and returns results object with matching keys","series short-circuits execution on error and immediately passes error to final callback","series guarantees sequential execution without running subsequent tasks concurrently","series handles empty task collection by invoking callback immediately with empty results","seriesPromise wraps async.series to resolve results in async/await workflows"],"goal":"verify async.series in pkg:npm/neo-async@2.6.2","kind":"HOW","packages":["pkg:npm/neo-async@2.6.2"],"schemaVersion":1,"symbols":["async.series"]},"contractCommand":["node","test/contract.mjs"],"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/neo-async@2.6.2"],"schemaVersion":1,"subject":"pkg:npm/neo-async@2.6.2","symbols":["async.series"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-neo-async-series",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-neo-async-series",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "neo-async": "2.6.2"
      }
    },
    "node_modules/neo-async": {
      "version": "2.6.2",
      "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
      "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-neo-async-series",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "neo-async": "2.6.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify async.series in pkg:npm/neo-async@2.6.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/neo-async@2.6.2"
  ],
  "symbols": [
    "async.series"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import async from 'neo-async';

const { series } = async;

/**
 * Executes an array or object of asynchronous task functions in series.
 * Each task receives a callback(err, result).
 *
 * @param {Array<Function>|Object.<string, Function>} tasks Array or dictionary of async functions.
 * @param {Function} [callback] Final callback(err, results).
 */
export function executeSeries(tasks, callback) {
  return series(tasks, callback);
}

/**
 * Promisified wrapper for async.series to support async/await workflows.
 *
 * @param {Array<Function>|Object.<string, Function>} tasks Array or dictionary of async functions.
 * @returns {Promise<Array<*>|Object.<string, *>>} Resolved results or rejected error.
 */
export function seriesPromise(tasks) {
  return new Promise((resolve, reject) => {
    series(tasks, (err, results) => {
      if (err) {
        return reject(err);
      }
      resolve(results);
    });
  });
}

export { series };
export default async;
test/contract.mjs
import assert from 'node:assert/strict';
import async from 'neo-async';
import { executeSeries, seriesPromise, series } from '../src/index.mjs';

// 1. series executes an array of async functions in sequential order and returns results array
{
  const order = [];
  const tasks = [
    (callback) => {
      setTimeout(() => {
        order.push(1);
        callback(null, 'step1');
      }, 20);
    },
    (callback) => {
      setTimeout(() => {
        order.push(2);
        callback(null, 'step2');
      }, 10);
    },
    (callback) => {
      order.push(3);
      callback(null, 'step3');
    }
  ];

  const results = await new Promise((resolve, reject) => {
    series(tasks, (err, res) => {
      if (err) reject(err);
      else resolve(res);
    });
  });

  assert.deepEqual(results, ['step1', 'step2', 'step3']);
  assert.deepEqual(order, [1, 2, 3]);
}

// 2. series executes an object of named async functions in sequence and returns results object with matching keys
{
  const order = [];
  const tasks = {
    first: (callback) => {
      setTimeout(() => {
        order.push('first');
        callback(null, { id: 100 });
      }, 15);
    },
    second: (callback) => {
      order.push('second');
      callback(null, { id: 200 });
    }
  };

  const results = await new Promise((resolve, reject) => {
    executeSeries(tasks, (err, res) => {
      if (err) reject(err);
      else resolve(res);
    });
  });

  assert.deepEqual(results, { first: { id: 100 }, second: { id: 200 } });
  assert.deepEqual(order, ['first', 'second']);
}

// 3. series short-circuits execution on error and immediately passes error to final callback
{
  let thirdTaskRan = false;
  const tasks = [
    (callback) => {
      callback(null, 'ok');
    },
    (callback) => {
      callback(new Error('step 2 failed'));
    },
    (callback) => {
      thirdTaskRan = true;
      callback(null, 'unreachable');
    }
  ];

  const error = await new Promise((resolve) => {
    series(tasks, (err) => {
      resolve(err);
    });
  });

  assert.ok(error instanceof Error);
  assert.equal(error.message, 'step 2 failed');
  assert.equal(thirdTaskRan, false);
}

// 4. series guarantees sequential execution without running subsequent tasks concurrently
{
  let activeCount = 0;
  let maxActive = 0;

  const makeTask = (val) => (callback) => {
    activeCount++;
    maxActive = Math.max(maxActive, activeCount);
    setTimeout(() => {
      activeCount--;
      callback(null, val);
    }, 15);
  };

  const tasks = [makeTask(1), makeTask(2), makeTask(3)];
  const results = await new Promise((resolve, reject) => {
    series(tasks, (err, res) => {
      if (err) reject(err);
      else resolve(res);
    });
  });

  assert.deepEqual(results, [1, 2, 3]);
  assert.equal(maxActive, 1);
  assert.equal(activeCount, 0);
}

// 5. series handles empty task collection by invoking callback immediately with empty results
{
  const emptyArrayResults = await new Promise((resolve, reject) => {
    series([], (err, res) => {
      if (err) reject(err);
      else resolve(res);
    });
  });
  assert.deepEqual(emptyArrayResults, []);

  const emptyObjectResults = await new Promise((resolve, reject) => {
    series({}, (err, res) => {
      if (err) reject(err);
      else resolve(res);
    });
  });
  assert.deepEqual(emptyObjectResults, {});
}

// 6. seriesPromise wraps async.series to resolve results in async/await workflows
{
  const resArray = await seriesPromise([
    (cb) => cb(null, 'a'),
    (cb) => cb(null, 'b')
  ]);
  assert.deepEqual(resArray, ['a', 'b']);

  const resObj = await seriesPromise({
    foo: (cb) => cb(null, 42),
    bar: (cb) => cb(null, 99)
  });
  assert.deepEqual(resObj, { foo: 42, bar: 99 });

  await assert.rejects(
    async () => {
      await seriesPromise([
        (cb) => cb(new Error('async rejected'))
      ]);
    },
    {
      name: 'Error',
      message: 'async rejected'
    }
  );
}

console.log('Contract tests passed successfully.');

Seeder d'origine

anonyme