CodeSampleX

サンプル

ci-info 3.9.0

検証済みサンプル — npm ci-info 3.9.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: isCI exports a boolean indicating whether execution is within a…

sha256:5dad303a1b160590413794b5626b09245e4a8d259c93b69a396dd93d77cdc10b

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

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21
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-08

ケース

HOW
ゴール
verify pkg:npm/ci-info@3.9.0
パッケージ
作成日
2026-08-21T11:58:29Z

コントラクト

  1. isCI exports a boolean indicating whether execution is within a continuous integration environment
  2. name exports a string or null indicating the detected continuous integration vendor name
  3. isPR exports a boolean or null indicating if a pull request is being tested
  4. vendor constants export boolean flags for specific CI providers including GITHUB_ACTIONS, TRAVIS, CIRCLE, and GITLAB
  5. _vendors exports an array of supported vendor constant identifiers
  6. evaluates environment variables dynamically on load to detect CI presence and vendor name

ファイル

  • 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/ci-info@3.9.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ci-info@3.9.0

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:89ba24dbffa9727da183019ee65dbfff6494a46c47d7a409f81fb7de8f0e3faf","contract":["isCI exports a boolean indicating whether execution is within a continuous integration environment","name exports a string or null indicating the detected continuous integration vendor name","isPR exports a boolean or null indicating if a pull request is being tested","vendor constants export boolean flags for specific CI providers including GITHUB_ACTIONS, TRAVIS, CIRCLE, and GITLAB","_vendors exports an array of supported vendor constant identifiers","evaluates environment variables dynamically on load to detect CI presence and vendor name"],"goal":"verify pkg:npm/ci-info@3.9.0","kind":"HOW","packages":["pkg:npm/ci-info@3.9.0"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/ci-info@3.9.0"],"schemaVersion":1,"subject":"pkg:npm/ci-info@3.9.0","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const ci = require('ci-info');

function isContinuousIntegration() {
  return ci.isCI;
}

function getCIName() {
  return ci.name;
}

function isPullRequest() {
  return ci.isPR;
}

function getSupportedVendors() {
  return ci._vendors || [];
}

module.exports = {
  isCI: ci.isCI,
  name: ci.name,
  isPR: ci.isPR,
  isContinuousIntegration,
  getCIName,
  isPullRequest,
  getSupportedVendors,
  ci
};
package-lock.json
{
  "name": "sample-ci-info",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ci-info",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ci-info": "3.9.0"
      }
    },
    "node_modules/ci-info": {
      "version": "3.9.0",
      "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz",
      "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-ci-info",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for ci-info",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "ci-info": "3.9.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/ci-info@3.9.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ci-info@3.9.0"
  ]
}
test/contract.cjs
'use strict';

const assert = require('node:assert');
const ci = require('ci-info');
const {
  isContinuousIntegration,
  getCIName,
  isPullRequest,
  getSupportedVendors,
  ci: exportedCI
} = require('../index.js');

// 1. isCI returns a boolean indicating CI environment detection
assert.strictEqual(typeof ci.isCI, 'boolean', 'isCI must be a boolean');
assert.strictEqual(typeof isContinuousIntegration(), 'boolean', 'helper isContinuousIntegration must return a boolean');

// 2. name returns a string or null indicating the detected CI vendor
assert.ok(
  ci.name === null || typeof ci.name === 'string',
  'name must be null or a string'
);
assert.ok(
  getCIName() === null || typeof getCIName() === 'string',
  'helper getCIName must return null or a string'
);

// 3. isPR returns a boolean or null indicating pull request status
assert.ok(
  ci.isPR === null || typeof ci.isPR === 'boolean',
  'isPR must be null or a boolean'
);
assert.ok(
  isPullRequest() === null || typeof isPullRequest() === 'boolean',
  'helper isPullRequest must return null or a boolean'
);

// 4. vendor constants are boolean flags for supported CI services
assert.strictEqual(typeof ci.GITHUB_ACTIONS, 'boolean', 'GITHUB_ACTIONS flag must be boolean');
assert.strictEqual(typeof ci.TRAVIS, 'boolean', 'TRAVIS flag must be boolean');
assert.strictEqual(typeof ci.CIRCLE, 'boolean', 'CIRCLE flag must be boolean');
assert.strictEqual(typeof ci.GITLAB, 'boolean', 'GITLAB flag must be boolean');

// 5. _vendors exports an array containing supported vendor constant identifiers
const vendors = getSupportedVendors();
assert.ok(Array.isArray(vendors), '_vendors must be an array');
assert.ok(vendors.includes('GITHUB_ACTIONS'), '_vendors must include GITHUB_ACTIONS');
assert.ok(vendors.includes('TRAVIS'), '_vendors must include TRAVIS');
assert.ok(vendors.includes('CIRCLE'), '_vendors must include CIRCLE');
assert.ok(vendors.includes('GITLAB'), '_vendors must include GITLAB');

// 6. Dynamic resolution: Simulating environment variables detects corresponding CI vendor
const ciPath = require.resolve('ci-info');
const origEnv = { ...process.env };

try {
  // Test GitHub Actions simulation
  delete require.cache[ciPath];
  process.env = { ...origEnv, CI: 'true', GITHUB_ACTIONS: 'true' };
  const ciGA = require(ciPath);
  assert.strictEqual(ciGA.isCI, true, 'isCI should be true when CI and GITHUB_ACTIONS are set');
  assert.strictEqual(ciGA.GITHUB_ACTIONS, true, 'GITHUB_ACTIONS should be true');
  assert.strictEqual(ciGA.name, 'GitHub Actions', 'name should be GitHub Actions');

  // Test non-CI environment simulation when CI is explicitly false
  delete require.cache[ciPath];
  const cleanEnv = {};
  for (const k in origEnv) {
    if (!k.includes('CI') && !k.includes('BUILD') && !k.includes('ACTION')) {
      cleanEnv[k] = origEnv[k];
    }
  }
  cleanEnv.CI = 'false';
  process.env = cleanEnv;
  const ciFalse = require(ciPath);
  assert.strictEqual(ciFalse.isCI, false, 'isCI should be false when CI is set to false');
} finally {
  process.env = origEnv;
  delete require.cache[ciPath];
}

console.log('Contract tests passed successfully.');

オリジンシーダー

匿名