CodeSampleX

샘플

xmlhttprequest-ssl 2.1.2

검증된 샘플 — npm xmlhttprequest-ssl 2.1.2. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: XMLHttpRequest is exported as a constructor function

sha256:25c1a73d8bd1543c9db4c7043051cf24b6b505f957ac24fee045be5ca44a12f6

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

케이스

HOW
목표
verify pkg:npm/xmlhttprequest-ssl@2.1.2
패키지
환경
node 22.23.2
생성일
2026-08-27T14:15:04Z

컨트랙트

  1. XMLHttpRequest is exported as a constructor function
  2. XMLHttpRequest opens and executes an asynchronous HTTP GET request
  3. XMLHttpRequest sets request headers and sends HTTP POST with JSON body
  4. XMLHttpRequest onreadystatechange captures status, responseText, and response headers

파일

  • PROMPT.md
  • csx.json
  • index.js
  • 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/xmlhttprequest-ssl@2.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/xmlhttprequest-ssl@2.1.2
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:3f2ac4d47b3d7b418fbcaa368542a156a2a001d34865b3e11ba720eaa957f011","constraints":{"executionContext":"node"},"contract":["XMLHttpRequest is exported as a constructor function","XMLHttpRequest opens and executes an asynchronous HTTP GET request","XMLHttpRequest sets request headers and sends HTTP POST with JSON body","XMLHttpRequest onreadystatechange captures status, responseText, and response headers"],"goal":"verify pkg:npm/xmlhttprequest-ssl@2.1.2","kind":"HOW","packages":["pkg:npm/xmlhttprequest-ssl@2.1.2"],"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/xmlhttprequest-ssl@2.1.2"],"schemaVersion":1,"subject":"pkg:npm/xmlhttprequest-ssl@2.1.2","verifierAdapter":"node-typescript@1"}
index.js
const { XMLHttpRequest } = require('xmlhttprequest-ssl');

function createRequest(method, url, headers = {}, body = null) {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.open(method, url, true);

    for (const [key, value] of Object.entries(headers)) {
      xhr.setRequestHeader(key, value);
    }

    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
        if (xhr.status >= 200 && xhr.status < 300) {
          resolve({
            status: xhr.status,
            statusText: xhr.statusText,
            headers: xhr.getAllResponseHeaders(),
            body: xhr.responseText
          });
        } else {
          reject(new Error(`HTTP error ${xhr.status}: ${xhr.statusText}`));
        }
      }
    };

    xhr.onerror = function (err) {
      reject(err || new Error('Network error'));
    };

    xhr.send(body);
  });
}

module.exports = {
  XMLHttpRequest,
  createRequest
};
package-lock.json
{
  "name": "sample-xmlhttprequest-ssl",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-xmlhttprequest-ssl",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "xmlhttprequest-ssl": "2.1.2"
      }
    },
    "node_modules/xmlhttprequest-ssl": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.1.2.tgz",
      "integrity": "sha512-TEU+nJVUUnA4CYJFLvK5X9AOeH4KvDvhIfm0vV1GaQRtchnG0hgK5p8hw/xjv8cunWYCsiPCSDzObPyhEwq3KQ==",
      "engines": {
        "node": ">=0.4.0"
      }
    }
  }
}
package.json
{
  "name": "sample-xmlhttprequest-ssl",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for xmlhttprequest-ssl",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "xmlhttprequest-ssl": "2.1.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/xmlhttprequest-ssl@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/xmlhttprequest-ssl@2.1.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const http = require('http');
const assert = require('assert');
const { XMLHttpRequest, createRequest } = require('../index.js');

// Assertion 1: XMLHttpRequest is exported as a constructor function
assert.strictEqual(typeof XMLHttpRequest, 'function', 'XMLHttpRequest should be a constructor function');

const server = http.createServer((req, res) => {
  if (req.method === 'GET' && req.url === '/ping') {
    res.writeHead(200, {
      'Content-Type': 'application/json',
      'X-Server-Id': 'test-server'
    });
    res.end(JSON.stringify({ message: 'pong', ok: true }));
  } else if (req.method === 'POST' && req.url === '/echo') {
    let rawData = '';
    req.on('data', chunk => {
      rawData += chunk;
    });
    req.on('end', () => {
      res.writeHead(200, {
        'Content-Type': 'application/json',
        'X-Echo-Status': 'success'
      });
      res.end(JSON.stringify({ received: JSON.parse(rawData) }));
    });
  } else {
    res.writeHead(404);
    res.end();
  }
});

server.listen(0, '127.0.0.1', async () => {
  const port = server.address().port;
  const baseUrl = `http://127.0.0.1:${port}`;

  try {
    // Assertion 2: XMLHttpRequest opens and executes an asynchronous HTTP GET request
    const getRes = await createRequest('GET', `${baseUrl}/ping`, { 'Accept': 'application/json' });
    assert.strictEqual(getRes.status, 200, 'GET status should be 200');
    const getBody = JSON.parse(getRes.body);
    assert.strictEqual(getBody.ok, true, 'GET body.ok should be true');
    assert.strictEqual(getBody.message, 'pong', 'GET body.message should be pong');

    // Assertion 3: XMLHttpRequest sets request headers and sends HTTP POST with JSON body
    const postPayload = { testKey: 'testVal', count: 42 };
    const postRes = await createRequest('POST', `${baseUrl}/echo`, {
      'Content-Type': 'application/json',
      'X-Client-Id': 'client-42'
    }, JSON.stringify(postPayload));
    assert.strictEqual(postRes.status, 200, 'POST status should be 200');
    const postBody = JSON.parse(postRes.body);
    assert.deepStrictEqual(postBody.received, postPayload, 'POST body should echo sent payload');

    // Assertion 4: XMLHttpRequest onreadystatechange captures status, responseText, and response headers
    await new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();
      xhr.open('GET', `${baseUrl}/ping`, true);
      xhr.setRequestHeader('Accept', 'application/json');

      const statesSeen = [];
      xhr.onreadystatechange = function () {
        statesSeen.push(xhr.readyState);
        if (xhr.readyState === 4) {
          try {
            assert.strictEqual(xhr.status, 200, 'readyState 4 status should be 200');
            assert(xhr.responseText.includes('"ok":true'), 'responseText should include ok:true');
            const headers = xhr.getAllResponseHeaders();
            assert(headers.toLowerCase().includes('x-server-id'), 'response headers should include x-server-id');
            assert.strictEqual(xhr.getResponseHeader('X-Server-Id'), 'test-server', 'getResponseHeader should return header value');
            assert(statesSeen.includes(4), 'statesSeen should include 4');
            resolve();
          } catch (e) {
            reject(e);
          }
        }
      };
      xhr.onerror = function (err) {
        reject(err || new Error('XHR error'));
      };
      xhr.send();
    });

    console.log('Contract tests passed successfully.');
    server.close(() => {
      process.exit(0);
    });
  } catch (err) {
    console.error('Contract test failed:', err);
    server.close(() => {
      process.exit(1);
    });
  }
});

오리진 시더

익명