CodeSampleX

サンプル

tmp 0.2.7

検証済みサンプル — npm tmp 0.2.7. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: tmp.fileSync creates a temporary file synchronously returning name, fd…

sha256:cec058791603add11e4bacc8a622c8e35561e6dfda019b59fc340ffa9c31a330

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

実行証拠

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

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
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@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

ケース

HOW
ゴール
verify pkg:npm/tmp@0.2.7
パッケージ
作成日
2026-08-28T05:06:31Z

コントラクト

  1. tmp.fileSync creates a temporary file synchronously returning name, fd, and removeCallback
  2. tmp.dirSync creates a temporary directory synchronously and removeCallback removes it
  3. tmp.file creates a temporary file asynchronously and passes path, fd, and cleanupCallback to the callback
  4. tmp.dir creates a temporary directory asynchronously and passes path and cleanupCallback to the callback
  5. tmp.tmpNameSync generates a unique temporary path matching prefix and postfix options

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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/tmp@0.2.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tmp@0.2.7

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:e567298fe4893cc68dfa3389ba9b6a44eed7b9ce885fb93e0c1de33ce89227c8","contract":["tmp.fileSync creates a temporary file synchronously returning name, fd, and removeCallback","tmp.dirSync creates a temporary directory synchronously and removeCallback removes it","tmp.file creates a temporary file asynchronously and passes path, fd, and cleanupCallback to the callback","tmp.dir creates a temporary directory asynchronously and passes path and cleanupCallback to the callback","tmp.tmpNameSync generates a unique temporary path matching prefix and postfix options"],"goal":"verify pkg:npm/tmp@0.2.7","kind":"HOW","packages":["pkg:npm/tmp@0.2.7"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/tmp@0.2.7"],"schemaVersion":1,"subject":"pkg:npm/tmp@0.2.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-tmp",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tmp",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tmp": "0.2.7"
      }
    },
    "node_modules/tmp": {
      "version": "0.2.7",
      "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz",
      "integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw==",
      "license": "MIT",
      "engines": {
        "node": ">=14.14"
      }
    }
  }
}
package.json
{
  "name": "sample-tmp",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for tmp",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "tmp": "0.2.7"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/tmp@0.2.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tmp@0.2.7"
  ]
}
src/index.js
const tmp = require('tmp');

function createTempFile(options) {
  return tmp.fileSync(options);
}

function createTempDir(options) {
  return tmp.dirSync(options);
}

function generateTempName(options) {
  return tmp.tmpNameSync(options);
}

module.exports = {
  createTempFile,
  createTempDir,
  generateTempName,
  tmp
};
test/contract.js
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const tmp = require('tmp');
const { createTempFile, createTempDir, generateTempName } = require('../src/index.js');

async function runTests() {
  // 1. tmp.fileSync creates a temporary file and returns name, fd, and removeCallback
  const tmpFile = createTempFile({ prefix: 'test-file-', postfix: '.tmp' });
  assert.strictEqual(typeof tmpFile.name, 'string', 'tmpFile.name should be a string');
  assert.strictEqual(typeof tmpFile.fd, 'number', 'tmpFile.fd should be a number');
  assert.strictEqual(typeof tmpFile.removeCallback, 'function', 'tmpFile.removeCallback should be a function');
  assert.strictEqual(fs.existsSync(tmpFile.name), true, 'temporary file should exist on disk');

  fs.writeSync(tmpFile.fd, Buffer.from('test data'));
  tmpFile.removeCallback();
  assert.strictEqual(fs.existsSync(tmpFile.name), false, 'temporary file should be removed after sync cleanup');

  // 2. tmp.dirSync creates a temporary directory and removeCallback removes it
  const tmpDir = createTempDir({ prefix: 'test-dir-', unsafeCleanup: true });
  assert.strictEqual(typeof tmpDir.name, 'string', 'tmpDir.name should be a string');
  assert.strictEqual(typeof tmpDir.removeCallback, 'function', 'tmpDir.removeCallback should be a function');
  assert.strictEqual(fs.existsSync(tmpDir.name), true, 'temporary directory should exist on disk');

  const nestedFile = path.join(tmpDir.name, 'nested.txt');
  fs.writeFileSync(nestedFile, 'nested content');
  assert.strictEqual(fs.existsSync(nestedFile), true, 'nested file should exist in temp dir');

  tmpDir.removeCallback();
  assert.strictEqual(fs.existsSync(tmpDir.name), false, 'temporary directory should be removed after sync cleanup');

  // 3. tmp.file creates a temporary file asynchronously and cleanupCallback removes it
  await new Promise((resolve, reject) => {
    tmp.file({ prefix: 'async-file-', postfix: '.dat' }, (err, filePath, fd, cleanupCallback) => {
      if (err) return reject(err);
      try {
        assert.strictEqual(typeof filePath, 'string', 'filePath should be a string');
        assert.strictEqual(typeof fd, 'number', 'fd should be a number');
        assert.strictEqual(typeof cleanupCallback, 'function', 'cleanupCallback should be a function');
        assert.strictEqual(fs.existsSync(filePath), true, 'async temporary file should exist');

        cleanupCallback((cleanupErr) => {
          if (cleanupErr) return reject(cleanupErr);
          try {
            assert.strictEqual(fs.existsSync(filePath), false, 'async temporary file should be removed after async cleanup');
            resolve();
          } catch (e) {
            reject(e);
          }
        });
      } catch (e) {
        reject(e);
      }
    });
  });

  // 4. tmp.dir creates a temporary directory asynchronously and cleanupCallback removes it
  await new Promise((resolve, reject) => {
    tmp.dir({ prefix: 'async-dir-', unsafeCleanup: true }, (err, dirPath, cleanupCallback) => {
      if (err) return reject(err);
      try {
        assert.strictEqual(typeof dirPath, 'string', 'dirPath should be a string');
        assert.strictEqual(typeof cleanupCallback, 'function', 'cleanupCallback should be a function');
        assert.strictEqual(fs.existsSync(dirPath), true, 'async temporary directory should exist');

        cleanupCallback((cleanupErr) => {
          if (cleanupErr) return reject(cleanupErr);
          try {
            assert.strictEqual(fs.existsSync(dirPath), false, 'async temporary directory should be removed after async cleanup');
            resolve();
          } catch (e) {
            reject(e);
          }
        });
      } catch (e) {
        reject(e);
      }
    });
  });

  // 5. tmp.tmpNameSync generates a unique temporary path matching prefix and postfix options
  const generatedName = generateTempName({ prefix: 'custom-pref-', postfix: '.custom' });
  assert.strictEqual(typeof generatedName, 'string', 'generatedName should be a string');
  assert.strictEqual(path.basename(generatedName).startsWith('custom-pref-'), true, 'name should start with prefix');
  assert.strictEqual(generatedName.endsWith('.custom'), true, 'name should end with postfix');
  assert.strictEqual(fs.existsSync(generatedName), false, 'generated tempName should not exist prior to creation');

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

runTests().catch(err => {
  console.error(err);
  process.exit(1);
});

オリジンシーダー

匿名