CodeSampleX

Пример

@img/sharp-linuxmusl-x64 0.35.5

Проверенный пример — npm @img/sharp-linuxmusl-x64 0.35.5. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден…

sha256:828862c18c4225415866cc494310a3f6559a575952858875b720d98453d8988e

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux alpine · alpine · musl 1.2.6 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-11-29

Кейс

HOW
Цель
verify pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5
Пакеты
Окружение
node 22.23.2
Создан
2026-11-29T03:12:29Z

Контракт

  1. require('@img/sharp-linuxmusl-x64') throws ERR_PACKAGE_PATH_NOT_EXPORTED because the package exposes only ./sharp.node and ./package subpath exports
  2. require('@img/sharp-linuxmusl-x64/package') returns metadata with name '@img/sharp-linuxmusl-x64', version '0.35.5', os ['linux'], cpu ['x64'], and libc ['musl']
  3. require('@img/sharp-linuxmusl-x64/sharp.node').libvipsVersion() loads the prebuilt musl native addon and returns { semver: '8.18.7', isGlobal: false, isWasm: false }
  4. sharpNative.format() reports buffer input and output support for png, jpeg, and webp
  5. sharpNative.cache(50, 20, 100), sharpNative.concurrency(2), sharpNative.simd(false), and sharpNative.counters() configure and query the native libvips runtime
  6. sharpNative.metadata(options, cb) decodes an in-memory 1x1 RGB PNG buffer to { format: 'png', width: 1, height: 1, space: 'srgb', channels: 3, depth: 'uchar', hasAlpha: false }
  7. sharpNative.stats(options, cb) reports isOpaque: true, 3 channels, and [255, 0, 0] pixel bounds on a 1x1 red PNG buffer
  8. sharpNative.metadata(options, cb) passes an Error to the callback when given non-image bytes

Файлы

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

Скачать артефакт с исходным кодом (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 pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5
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:81e22cff48c36a215d18c9a5041be669a9bfa48960bbcbf01ae5561160ebe688","constraints":{"executionContext":"node"},"contract":["require('@img/sharp-linuxmusl-x64') throws ERR_PACKAGE_PATH_NOT_EXPORTED because the package exposes only ./sharp.node and ./package subpath exports","require('@img/sharp-linuxmusl-x64/package') returns metadata with name '@img/sharp-linuxmusl-x64', version '0.35.5', os ['linux'], cpu ['x64'], and libc ['musl']","require('@img/sharp-linuxmusl-x64/sharp.node').libvipsVersion() loads the prebuilt musl native addon and returns { semver: '8.18.7', isGlobal: false, isWasm: false }","sharpNative.format() reports buffer input and output support for png, jpeg, and webp","sharpNative.cache(50, 20, 100), sharpNative.concurrency(2), sharpNative.simd(false), and sharpNative.counters() configure and query the native libvips runtime","sharpNative.metadata(options, cb) decodes an in-memory 1x1 RGB PNG buffer to { format: 'png', width: 1, height: 1, space: 'srgb', channels: 3, depth: 'uchar', hasAlpha: false }","sharpNative.stats(options, cb) reports isOpaque: true, 3 channels, and [255, 0, 0] pixel bounds on a 1x1 red PNG buffer","sharpNative.metadata(options, cb) passes an Error to the callback when given non-image bytes"],"goal":"verify pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5","kind":"HOW","packages":["pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"musl","libcVersion":"1.2.6","moduleSystem":"cjs","os":"linux","osVersionBucket":"alpine","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5"],"schemaVersion":1,"subject":"pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const sharpNative = require('@img/sharp-linuxmusl-x64/sharp.node');
const pkgMeta = require('@img/sharp-linuxmusl-x64/package');

function makeInputOptions(buffer) {
  return {
    input: {
      buffer,
      failOn: 'warning',
      limitInputPixels: 268402689,
      limitInputChannels: 4,
      unlimited: false,
      autoOrient: false
    },
    debuglog: () => {}
  };
}

function readMetadata(buffer) {
  return new Promise((resolve, reject) => {
    sharpNative.metadata(makeInputOptions(buffer), (err, info) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(info);
    });
  });
}

function readStats(buffer) {
  return new Promise((resolve, reject) => {
    sharpNative.stats(makeInputOptions(buffer), (err, stats) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(stats);
    });
  });
}

module.exports = {
  sharpNative,
  pkgMeta,
  readMetadata,
  readStats
};
package-lock.json
{
  "name": "verify-sharp-linuxmusl-x64",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-sharp-linuxmusl-x64",
      "version": "1.0.0",
      "dependencies": {
        "@img/sharp-linuxmusl-x64": "0.35.5"
      }
    },
    "node_modules/@img/sharp-libvips-linuxmusl-x64": {
      "version": "1.3.4",
      "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.3.4.tgz",
      "integrity": "sha512-6zXKeE/p39I1AmA3cJG35eyBGNqNddLnUXjhwBnsGjFPWqf5VKkDBEqaEkPDoTEtkxwi2vv8Tcr2mDyP4So7Fg==",
      "cpu": [
        "x64"
      ],
      "license": "LGPL-3.0-or-later",
      "optional": true,
      "os": [
        "linux"
      ],
      "funding": {
        "url": "https://opencollective.com/libvips"
      }
    },
    "node_modules/@img/sharp-linuxmusl-x64": {
      "version": "0.35.5",
      "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.35.5.tgz",
      "integrity": "sha512-4KOphqB035HrVdqLZfCgMzzERrQkkzOwRhl4OAkRO1YCldbaFjySXMaK534Mo0V+LndnlJk+sbUyLeU0ULyD1A==",
      "cpu": [
        "x64"
      ],
      "license": "Apache-2.0",
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=20.9.0"
      },
      "funding": {
        "url": "https://opencollective.com/libvips"
      },
      "optionalDependencies": {
        "@img/sharp-libvips-linuxmusl-x64": "1.3.4"
      }
    }
  }
}
package.json
{
  "name": "verify-sharp-linuxmusl-x64",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@img/sharp-linuxmusl-x64": "0.35.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40img/sharp-linuxmusl-x64@0.35.5"
  ],
  "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 zlib = require('node:zlib');

const {
  sharpNative,
  pkgMeta,
  readMetadata,
  readStats
} = require('../index.js');

function crc32(buf) {
  let crc = 0xffffffff;
  for (let i = 0; i < buf.length; i += 1) {
    crc ^= buf[i];
    for (let bit = 0; bit < 8; bit += 1) {
      crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
    }
  }
  return (crc ^ 0xffffffff) >>> 0;
}

function makePngChunk(type, data) {
  const typeBuf = Buffer.from(type, 'ascii');
  const lenBuf = Buffer.alloc(4);
  lenBuf.writeUInt32BE(data.length, 0);
  const crcBuf = Buffer.alloc(4);
  crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])), 0);
  return Buffer.concat([lenBuf, typeBuf, data, crcBuf]);
}

function create1x1RedPng() {
  const signature = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  const ihdr = Buffer.alloc(13);
  ihdr.writeUInt32BE(1, 0); // width = 1
  ihdr.writeUInt32BE(1, 4); // height = 1
  ihdr[8] = 8; // bit depth = 8
  ihdr[9] = 2; // color type = RGB
  ihdr[10] = 0; // compression
  ihdr[11] = 0; // filter
  ihdr[12] = 0; // interlace
  const rawScanline = Buffer.from([0x00, 0xff, 0x00, 0x00]); // filter=0, R=255, G=0, B=0
  const idat = zlib.deflateSync(rawScanline);
  return Buffer.concat([
    signature,
    makePngChunk('IHDR', ihdr),
    makePngChunk('IDAT', idat),
    makePngChunk('IEND', Buffer.alloc(0))
  ]);
}

async function main() {
  // 1. Bare package import is rejected because only ./sharp.node and ./package are exported
  assert.throws(
    () => require('@img/sharp-linuxmusl-x64'),
    (err) => err && err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
  );

  // 2. ./package subpath export exposes package metadata targeting linux x64 musl
  assert.equal(pkgMeta.name, '@img/sharp-linuxmusl-x64');
  assert.equal(pkgMeta.version, '0.35.5');
  assert.deepEqual(pkgMeta.os, ['linux']);
  assert.deepEqual(pkgMeta.cpu, ['x64']);
  assert.deepEqual(pkgMeta.libc, ['musl']);

  // 3. ./sharp.node loads the native musl addon and reports libvips version
  const version = sharpNative.libvipsVersion();
  assert.equal(version.semver, '8.18.7');
  assert.equal(version.isGlobal, false);
  assert.equal(version.isWasm, false);

  // 4. format() reports buffer input/output support for png, jpeg, and webp
  const formats = sharpNative.format();
  for (const name of ['png', 'jpeg', 'webp']) {
    assert.equal(formats[name].input.buffer, true, `${name} input buffer`);
    assert.equal(formats[name].output.buffer, true, `${name} output buffer`);
  }

  // 5. Runtime configuration and counters APIs work on the native musl addon
  const cacheInfo = sharpNative.cache(50, 20, 100);
  assert.equal(typeof cacheInfo.memory.max, 'number');
  assert.equal(typeof cacheInfo.files.max, 'number');
  assert.equal(typeof cacheInfo.items.max, 'number');

  const concurrency = sharpNative.concurrency(2);
  assert.equal(concurrency, 2);

  const simdState = sharpNative.simd(false);
  assert.equal(simdState, false);

  const counters = sharpNative.counters();
  assert.equal(typeof counters.queue, 'number');
  assert.equal(typeof counters.process, 'number');

  // 6. metadata() decodes an in-memory 1x1 RGB PNG buffer
  const pngBuffer = create1x1RedPng();
  const meta = await readMetadata(pngBuffer);
  assert.equal(meta.format, 'png');
  assert.equal(meta.width, 1);
  assert.equal(meta.height, 1);
  assert.equal(meta.space, 'srgb');
  assert.equal(meta.channels, 3);
  assert.equal(meta.depth, 'uchar');
  assert.equal(meta.hasAlpha, false);

  // 7. stats() reports opaque 3-channel red pixel statistics
  const stats = await readStats(pngBuffer);
  assert.equal(stats.isOpaque, true);
  assert.equal(stats.channels.length, 3);
  assert.equal(stats.channels[0].min, 255);
  assert.equal(stats.channels[0].max, 255);
  assert.equal(stats.channels[1].max, 0);
  assert.equal(stats.channels[2].max, 0);

  // 8. metadata() rejects invalid image bytes via callback error
  await assert.rejects(
    () => readMetadata(Buffer.from('not-a-valid-image')),
    (err) => err instanceof Error && err.message.length > 0
  );
}

main().catch((err) => {
  console.error(err);
  process.exitCode = 1;
});

Исходный сидер

аноним