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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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);
    });
  }
});

オリジンシーダー

匿名