CodeSampleX

示例

bluebird 3.7.2: resolve

已验证示例 — npm bluebird 3.7.2: resolve. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert Promise.resolve resolves primitive and object values into…

sha256:011b481c29f17f1222e7480a6e2c8c6d582803b2f33f0715244c036314498859

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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-06

案例

HOW
目标
verify bluebird.resolve in pkg:npm/bluebird@3.7.2
包
符号
  • bluebird.resolve
环境
node 22.23.2
创建时间
2026-09-06T18:25:40Z

契约

  1. assert Promise.resolve resolves primitive and object values into a Bluebird Promise instance
  2. assert Promise.resolve called without arguments resolves to undefined
  3. assert Promise.resolve preserves identity when given an existing Bluebird Promise
  4. assert Promise.resolve unwraps native promises and foreign thenables into Bluebird Promise instances
  5. assert Promise.resolve propagates rejections and errors from assimilated thenables and promises
  6. assert Promise.resolve produces an immediately fulfilled promise with synchronous inspection capabilities
  7. assert resolveValue, resolveAll, and assimilateThenable helper functions produce resolved Bluebird promises

文件

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 bluebird.resolve in pkg:npm/bluebird@3.7.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bluebird@3.7.2
Demonstrate these symbols/APIs:
  - bluebird.resolve

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:50eb02b5f292c38923fd86e11f10293f57aa84863d3a8eadd8c553926762c843","contract":["assert Promise.resolve resolves primitive and object values into a Bluebird Promise instance","assert Promise.resolve called without arguments resolves to undefined","assert Promise.resolve preserves identity when given an existing Bluebird Promise","assert Promise.resolve unwraps native promises and foreign thenables into Bluebird Promise instances","assert Promise.resolve propagates rejections and errors from assimilated thenables and promises","assert Promise.resolve produces an immediately fulfilled promise with synchronous inspection capabilities","assert resolveValue, resolveAll, and assimilateThenable helper functions produce resolved Bluebird promises"],"goal":"verify bluebird.resolve in pkg:npm/bluebird@3.7.2","kind":"HOW","packages":["pkg:npm/bluebird@3.7.2"],"schemaVersion":1,"symbols":["bluebird.resolve"]},"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/bluebird@3.7.2"],"schemaVersion":1,"subject":"pkg:npm/bluebird@3.7.2","symbols":["bluebird.resolve"],"verifierAdapter":"node-typescript@1"}
index.mjs
import Promise from 'bluebird';

/**
 * Resolves a value, existing promise, or thenable into a Bluebird promise.
 *
 * @param {any} [value] - Value, Promise, or thenable to resolve.
 * @returns {Promise<any>} A Bluebird promise resolved with the value.
 */
export function resolveValue(value) {
  return Promise.resolve(value);
}

/**
 * Resolves an array of values, promises, or thenables into Bluebird promises.
 *
 * @param {Array<any>} items - Array of items to resolve.
 * @returns {Array<Promise<any>>} Array of Bluebird promises.
 */
export function resolveAll(items) {
  return items.map((item) => Promise.resolve(item));
}

/**
 * Unwraps or converts a foreign thenable into a Bluebird promise.
 *
 * @param {PromiseLike<any>} thenable - A foreign thenable.
 * @returns {Promise<any>} An assimilated Bluebird promise.
 */
export function assimilateThenable(thenable) {
  return Promise.resolve(thenable);
}

export { Promise };
export default Promise;
package-lock.json
{
  "name": "sample-bluebird-resolve",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bluebird-resolve",
      "version": "1.0.0",
      "dependencies": {
        "bluebird": "3.7.2"
      }
    },
    "node_modules/bluebird": {
      "version": "3.7.2",
      "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
      "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-bluebird-resolve",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "bluebird": "3.7.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bluebird.resolve in pkg:npm/bluebird@3.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bluebird@3.7.2"
  ],
  "symbols": [
    "bluebird.resolve"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import Promise, { resolveValue, resolveAll, assimilateThenable } from '../index.mjs';

async function testAll() {
  // 1. Export verification
  assert.strictEqual(typeof Promise, 'function', 'Promise export must be a function');
  assert.strictEqual(typeof Promise.resolve, 'function', 'Promise.resolve must be a function');
  assert.strictEqual(typeof resolveValue, 'function', 'resolveValue helper must be a function');
  assert.strictEqual(typeof resolveAll, 'function', 'resolveAll helper must be a function');
  assert.strictEqual(typeof assimilateThenable, 'function', 'assimilateThenable helper must be a function');

  // 2. Resolving primitive values
  {
    const pNumber = Promise.resolve(42);
    assert.ok(pNumber instanceof Promise, 'Promise.resolve(number) must return a Bluebird Promise');
    assert.strictEqual(await pNumber, 42, 'Promise.resolve(42) must resolve to 42');

    const pString = Promise.resolve('hello world');
    assert.ok(pString instanceof Promise, 'Promise.resolve(string) must return a Bluebird Promise');
    assert.strictEqual(await pString, 'hello world', 'Promise.resolve(string) must resolve to string value');

    const pBool = Promise.resolve(true);
    assert.ok(pBool instanceof Promise, 'Promise.resolve(boolean) must return a Bluebird Promise');
    assert.strictEqual(await pBool, true, 'Promise.resolve(boolean) must resolve to boolean value');

    const pNull = Promise.resolve(null);
    assert.ok(pNull instanceof Promise, 'Promise.resolve(null) must return a Bluebird Promise');
    assert.strictEqual(await pNull, null, 'Promise.resolve(null) must resolve to null');

    const pObj = Promise.resolve({ key: 'value' });
    assert.ok(pObj instanceof Promise, 'Promise.resolve(object) must return a Bluebird Promise');
    assert.deepStrictEqual(await pObj, { key: 'value' }, 'Promise.resolve(object) must resolve to deep equal object');
  }

  // 3. Resolving undefined / no argument
  {
    const pUndefined = Promise.resolve();
    assert.ok(pUndefined instanceof Promise, 'Promise.resolve() must return a Bluebird Promise');
    assert.strictEqual(await pUndefined, undefined, 'Promise.resolve() without args must resolve to undefined');

    const pExplicitUndefined = Promise.resolve(undefined);
    assert.ok(pExplicitUndefined instanceof Promise, 'Promise.resolve(undefined) must return a Bluebird Promise');
    assert.strictEqual(await pExplicitUndefined, undefined, 'Promise.resolve(undefined) must resolve to undefined');
  }

  // 4. Identity when given an existing Bluebird Promise
  {
    const original = new Promise((resolve) => resolve('sample'));
    const resolved = Promise.resolve(original);
    assert.strictEqual(resolved, original, 'Promise.resolve must return the exact same instance if given a Bluebird Promise');
    assert.strictEqual(await resolved, 'sample', 'resolved promise must yield the expected value');
  }

  // 5. Unwrapping / assimilating native promises and foreign thenables
  {
    // Native Promise
    const nativePromise = global.Promise.resolve('from native');
    const assimilatedNative = Promise.resolve(nativePromise);
    assert.ok(assimilatedNative instanceof Promise, 'assimilated native promise must be an instance of Bluebird Promise');
    assert.notStrictEqual(assimilatedNative, nativePromise, 'assimilated native promise must not be identical to native promise');
    assert.strictEqual(await assimilatedNative, 'from native', 'assimilated native promise must resolve with native resolved value');

    // Custom thenable
    let thenCalled = false;
    const customThenable = {
      then(onFulfilled) {
        thenCalled = true;
        onFulfilled('from custom thenable');
      }
    };
    const assimilatedThenable = Promise.resolve(customThenable);
    assert.ok(assimilatedThenable instanceof Promise, 'assimilated thenable must be a Bluebird Promise');
    assert.strictEqual(await assimilatedThenable, 'from custom thenable', 'assimilated thenable must resolve with thenable value');
    assert.strictEqual(thenCalled, true, 'then method must have been invoked');
  }

  // 6. Propagation of errors and rejections from thenables
  {
    // Rejected native promise
    const rejectedNative = global.Promise.reject(new Error('native failure'));
    await assert.rejects(
      async () => {
        await Promise.resolve(rejectedNative);
      },
      {
        name: 'Error',
        message: 'native failure'
      },
      'Promise.resolve must propagate native rejection'
    );

    // Rejected custom thenable
    const rejectedThenable = {
      then(onFulfilled, onRejected) {
        onRejected(new Error('thenable rejection'));
      }
    };
    await assert.rejects(
      async () => {
        await Promise.resolve(rejectedThenable);
      },
      {
        name: 'Error',
        message: 'thenable rejection'
      },
      'Promise.resolve must propagate custom thenable rejection'
    );

    // Exception thrown in then method
    const throwingThenable = {
      then() {
        throw new Error('thrown from thenable');
      }
    };
    await assert.rejects(
      async () => {
        await Promise.resolve(throwingThenable);
      },
      {
        name: 'Error',
        message: 'thrown from thenable'
      },
      'Promise.resolve must propagate thrown exceptions during thenable assimilation'
    );
  }

  // 7. Synchronous inspection capabilities on resolved Bluebird Promise
  {
    const syncP = Promise.resolve('inspection-test');
    assert.strictEqual(syncP.isFulfilled(), true, 'synchronously resolved promise should be fulfilled');
    assert.strictEqual(syncP.isPending(), false, 'synchronously resolved promise should not be pending');
    assert.strictEqual(syncP.isRejected(), false, 'synchronously resolved promise should not be rejected');
    assert.strictEqual(syncP.value(), 'inspection-test', 'synchronously resolved promise value() returns payload');
  }

  // 8. Helper functions verification
  {
    const single = await resolveValue(999);
    assert.strictEqual(single, 999, 'resolveValue helper should resolve single value');

    const multi = await Promise.all(resolveAll([1, 2, 3]));
    assert.deepStrictEqual(multi, [1, 2, 3], 'resolveAll helper should resolve all values');

    const thenable = { then(res) { res('assimilated'); } };
    const assimilated = await assimilateThenable(thenable);
    assert.strictEqual(assimilated, 'assimilated', 'assimilateThenable helper should unwrap thenable');
  }

  console.log('All bluebird.resolve contract assertions passed.');
}

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

原始种子者

匿名