CodeSampleX

샘플

pngjs 6.0.0

검증된 샘플 — npm pngjs 6.0.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: PNG constructor initializes RGBA data buffer with size width * height *…

sha256:3bd49de30ad57b70e139a252119044a55b177798f9edcc7ed00326cf169f5f7d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 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-08-28

케이스

HOW
목표
verify pkg:npm/pngjs@6.0.0
패키지
환경
node 22.23.2
생성일
2026-08-28T07:33:11Z

컨트랙트

  1. PNG constructor initializes RGBA data buffer with size width * height * 4
  2. PNG.sync.write encodes image to PNG buffer and PNG.sync.read parses it back preserving pixel RGBA data
  3. PNG.prototype.pack and PNG.prototype.parse stream and asynchronously decode PNG image data
  4. PNG.bitblt copies a rectangular pixel block from source to destination PNG instance
  5. PNG.adjustGamma corrects gamma on pixel buffer

파일

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

소스 아티팩트 내려받기 (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/pngjs@6.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pngjs@6.0.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:9b35234af19965718d35f826947de3a4f5186a7d472f3d132798e351c11eaec7","constraints":{"executionContext":"node"},"contract":["PNG constructor initializes RGBA data buffer with size width * height * 4","PNG.sync.write encodes image to PNG buffer and PNG.sync.read parses it back preserving pixel RGBA data","PNG.prototype.pack and PNG.prototype.parse stream and asynchronously decode PNG image data","PNG.bitblt copies a rectangular pixel block from source to destination PNG instance","PNG.adjustGamma corrects gamma on pixel buffer"],"goal":"verify pkg:npm/pngjs@6.0.0","kind":"HOW","packages":["pkg:npm/pngjs@6.0.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/pngjs@6.0.0"],"schemaVersion":1,"subject":"pkg:npm/pngjs@6.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-pngjs",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-pngjs",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "pngjs": "6.0.0"
      }
    },
    "node_modules/pngjs": {
      "version": "6.0.0",
      "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz",
      "integrity": "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==",
      "license": "MIT",
      "engines": {
        "node": ">=12.13.0"
      }
    }
  }
}
package.json
{
  "name": "csx-sample-pngjs",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for pngjs 6.0.0",
  "main": "test/contract.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "pngjs": "6.0.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/pngjs@6.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pngjs@6.0.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require('assert');
const { PNG } = require('pngjs');

async function runTests() {
  // Test 1: PNG constructor initializes RGBA data buffer with size width * height * 4
  {
    const width = 4;
    const height = 4;
    const png = new PNG({ width, height, fill: true });

    assert.strictEqual(png.width, width, 'width should match constructor option');
    assert.strictEqual(png.height, height, 'height should match constructor option');
    assert(Buffer.isBuffer(png.data), 'png.data must be a Buffer');
    assert.strictEqual(png.data.length, width * height * 4, 'data buffer length must be 4 * width * height');

    // fill: true initializes all bytes to 0
    for (let i = 0; i < png.data.length; i++) {
      assert.strictEqual(png.data[i], 0, 'data buffer bytes should be filled with 0');
    }
  }

  // Test 2: PNG.sync.write encodes image to PNG buffer and PNG.sync.read parses it back preserving pixel RGBA data
  {
    const width = 2;
    const height = 2;
    const png = new PNG({ width, height });

    // Set pixel (0, 0) = Red [255, 0, 0, 255]
    // Set pixel (1, 0) = Green [0, 255, 0, 255]
    // Set pixel (0, 1) = Blue [0, 0, 255, 255]
    // Set pixel (1, 1) = Yellow [255, 255, 0, 255]
    const pixels = [
      [255, 0, 0, 255],
      [0, 255, 0, 255],
      [0, 0, 255, 255],
      [255, 255, 0, 255]
    ];

    for (let i = 0; i < 4; i++) {
      const idx = i * 4;
      png.data[idx] = pixels[i][0];
      png.data[idx + 1] = pixels[i][1];
      png.data[idx + 2] = pixels[i][2];
      png.data[idx + 3] = pixels[i][3];
    }

    const encodedBuffer = PNG.sync.write(png);
    assert(Buffer.isBuffer(encodedBuffer), 'PNG.sync.write must return a Buffer');
    // PNG signature: 89 50 4E 47 0D 0A 1A 0A
    assert.strictEqual(encodedBuffer[0], 0x89, 'PNG magic byte 0');
    assert.strictEqual(encodedBuffer[1], 0x50, 'PNG magic byte 1 (P)');
    assert.strictEqual(encodedBuffer[2], 0x4e, 'PNG magic byte 2 (N)');
    assert.strictEqual(encodedBuffer[3], 0x47, 'PNG magic byte 3 (G)');

    const decoded = PNG.sync.read(encodedBuffer);
    assert.strictEqual(decoded.width, width, 'decoded width must match original');
    assert.strictEqual(decoded.height, height, 'decoded height must match original');
    assert.strictEqual(decoded.data.length, width * height * 4, 'decoded data length must match');

    for (let i = 0; i < 4; i++) {
      const idx = i * 4;
      assert.strictEqual(decoded.data[idx], pixels[i][0], `pixel ${i} Red mismatch`);
      assert.strictEqual(decoded.data[idx + 1], pixels[i][1], `pixel ${i} Green mismatch`);
      assert.strictEqual(decoded.data[idx + 2], pixels[i][2], `pixel ${i} Blue mismatch`);
      assert.strictEqual(decoded.data[idx + 3], pixels[i][3], `pixel ${i} Alpha mismatch`);
    }
  }

  // Test 3: PNG.prototype.pack and PNG.prototype.parse stream and asynchronously decode PNG image data
  await new Promise((resolve, reject) => {
    const width = 3;
    const height = 3;
    const png = new PNG({ width, height });

    for (let y = 0; y < height; y++) {
      for (let x = 0; x < width; x++) {
        const idx = (width * y + x) << 2;
        png.data[idx] = x * 80;
        png.data[idx + 1] = y * 80;
        png.data[idx + 2] = 128;
        png.data[idx + 3] = 255;
      }
    }

    const chunks = [];
    const stream = png.pack();

    stream.on('data', (chunk) => chunks.push(chunk));
    stream.on('error', reject);
    stream.on('end', () => {
      const packedBuffer = Buffer.concat(chunks);
      assert(packedBuffer.length > 0, 'packed PNG stream should produce non-empty buffer');

      const asyncReader = new PNG();
      asyncReader.parse(packedBuffer, (err, parsedData) => {
        if (err) return reject(err);

        assert.strictEqual(parsedData.width, width, 'async parsed width mismatch');
        assert.strictEqual(parsedData.height, height, 'async parsed height mismatch');

        for (let y = 0; y < height; y++) {
          for (let x = 0; x < width; x++) {
            const idx = (width * y + x) << 2;
            assert.strictEqual(parsedData.data[idx], x * 80);
            assert.strictEqual(parsedData.data[idx + 1], y * 80);
            assert.strictEqual(parsedData.data[idx + 2], 128);
            assert.strictEqual(parsedData.data[idx + 3], 255);
          }
        }
        resolve();
      });
    });
  });

  // Test 4: PNG.bitblt copies a rectangular pixel block from source to destination PNG instance
  {
    const src = new PNG({ width: 4, height: 4 });
    src.data.fill(255);

    const dst = new PNG({ width: 8, height: 8 });
    dst.data.fill(0);

    // Copy 2x2 area from src (offset 1,1) to dst (offset 3,3)
    PNG.bitblt(src, dst, 1, 1, 2, 2, 3, 3);

    for (let y = 0; y < 8; y++) {
      for (let x = 0; x < 8; x++) {
        const idx = (8 * y + x) << 2;
        const isInsideCopiedArea = x >= 3 && x < 5 && y >= 3 && y < 5;
        if (isInsideCopiedArea) {
          assert.strictEqual(dst.data[idx], 255, `expected 255 at (${x},${y})`);
          assert.strictEqual(dst.data[idx + 1], 255, `expected 255 at (${x},${y})`);
          assert.strictEqual(dst.data[idx + 2], 255, `expected 255 at (${x},${y})`);
          assert.strictEqual(dst.data[idx + 3], 255, `expected 255 at (${x},${y})`);
        } else {
          assert.strictEqual(dst.data[idx], 0, `expected 0 at (${x},${y})`);
          assert.strictEqual(dst.data[idx + 1], 0, `expected 0 at (${x},${y})`);
          assert.strictEqual(dst.data[idx + 2], 0, `expected 0 at (${x},${y})`);
          assert.strictEqual(dst.data[idx + 3], 0, `expected 0 at (${x},${y})`);
        }
      }
    }
  }

  // Test 5: PNG.adjustGamma corrects gamma on pixel buffer
  {
    const png = new PNG({ width: 2, height: 2 });
    png.data.fill(128);
    // adjustGamma modifies in-place
    PNG.adjustGamma(png);
    // After gamma adjustment on 128, pixel values should change deterministically
    assert.notStrictEqual(png.data[0], 0, 'gamma adjusted value should be non-zero');
  }

  console.log('All pngjs contract assertions passed successfully.');
}

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

오리진 시더

익명