CodeSampleX

サンプル

temp 0.9.4: openSync

検証済みサンプル — npm temp 0.9.4: openSync. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: temp.openSync creates a temporary file and returns an object…

sha256:059eeaf4fde4fd0318cb7e38c13c969a0d2563f78670d517a40cdbd69c9565e5

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-04

ケース

HOW
ゴール
verify temp.openSync in pkg:npm/temp@0.9.4
パッケージ
シンボル
  • temp.openSync
環境
node 22.23.2
作成日
2026-09-04T14:08:33Z

コントラクト

  1. temp.openSync creates a temporary file and returns an object with fd and path using default prefix
  2. temp.openSync accepts a string prefix to customize generated file path
  3. temp.openSync accepts an options object specifying prefix, suffix, and directory
  4. temp.openSync returns a writable file descriptor that can be closed and verified on disk
  5. temp.openSync throws an error when called with invalid affix types

ファイル

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

ソースアーティファクトをダウンロード (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 temp.openSync in pkg:npm/temp@0.9.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/temp@0.9.4
Demonstrate these symbols/APIs:
  - temp.openSync

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:d7f7ff0e970713498537d2356cfa03862c513a22a8a096e4afe1205f5ee6b721","contract":["temp.openSync creates a temporary file and returns an object with fd and path using default prefix","temp.openSync accepts a string prefix to customize generated file path","temp.openSync accepts an options object specifying prefix, suffix, and directory","temp.openSync returns a writable file descriptor that can be closed and verified on disk","temp.openSync throws an error when called with invalid affix types"],"goal":"verify temp.openSync in pkg:npm/temp@0.9.4","kind":"HOW","packages":["pkg:npm/temp@0.9.4"],"schemaVersion":1,"symbols":["temp.openSync"]},"contractCommand":["node","test/contract.mjs"],"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/temp@0.9.4"],"schemaVersion":1,"subject":"pkg:npm/temp@0.9.4","symbols":["temp.openSync"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-temp-open-sync",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-temp-open-sync",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "temp": "0.9.4"
      }
    },
    "node_modules/balanced-match": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
      "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
      "license": "MIT"
    },
    "node_modules/brace-expansion": {
      "version": "1.1.18",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz",
      "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==",
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "node_modules/concat-map": {
      "version": "0.0.1",
      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
      "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
      "license": "MIT"
    },
    "node_modules/fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
      "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
      "license": "ISC"
    },
    "node_modules/glob": {
      "version": "7.2.3",
      "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
      "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
      "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
      "license": "ISC",
      "dependencies": {
        "fs.realpath": "^1.0.0",
        "inflight": "^1.0.4",
        "inherits": "2",
        "minimatch": "^3.1.1",
        "once": "^1.3.0",
        "path-is-absolute": "^1.0.0"
      },
      "engines": {
        "node": "*"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    },
    "node_modules/inflight": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
      "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
      "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.",
      "license": "ISC",
      "dependencies": {
        "once": "^1.3.0",
        "wrappy": "1"
      }
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/minimatch": {
      "version": "3.1.5",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz",
      "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==",
      "license": "ISC",
      "dependencies": {
        "brace-expansion": "^1.1.7"
      },
      "engines": {
        "node": "*"
      }
    },
    "node_modules/minimist": {
      "version": "1.2.8",
      "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
      "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/mkdirp": {
      "version": "0.5.6",
      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
      "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
      "license": "MIT",
      "dependencies": {
        "minimist": "^1.2.6"
      },
      "bin": {
        "mkdirp": "bin/cmd.js"
      }
    },
    "node_modules/once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
      "license": "ISC",
      "dependencies": {
        "wrappy": "1"
      }
    },
    "node_modules/path-is-absolute": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
      "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/rimraf": {
      "version": "2.6.3",
      "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
      "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
      "deprecated": "Rimraf versions prior to v4 are no longer supported",
      "license": "ISC",
      "dependencies": {
        "glob": "^7.1.3"
      },
      "bin": {
        "rimraf": "bin.js"
      }
    },
    "node_modules/temp": {
      "version": "0.9.4",
      "resolved": "https://registry.npmjs.org/temp/-/temp-0.9.4.tgz",
      "integrity": "sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==",
      "license": "MIT",
      "dependencies": {
        "mkdirp": "^0.5.1",
        "rimraf": "~2.6.2"
      },
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-temp-open-sync",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for temp.openSync in temp@0.9.4",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "temp": "0.9.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify temp.openSync in pkg:npm/temp@0.9.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/temp@0.9.4"
  ],
  "symbols": [
    "temp.openSync"
  ]
}
src/index.js
const temp = require('temp');

/**
 * Creates and opens a temporary file synchronously using temp.openSync.
 *
 * @param {string|Object} [affixes] - Prefix string or options object { prefix, suffix, dir }.
 * @returns {{path: string, fd: number}} Object containing open file descriptor and path.
 */
function openTempSync(affixes) {
  return temp.openSync(affixes);
}

module.exports = {
  temp,
  openTempSync
};
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { temp, openTempSync } = require('../src/index.js');

function testAll() {
  // 1. temp.openSync creates a temporary file and returns an object with fd and path using default prefix
  const file1 = openTempSync();
  assert.ok(typeof file1.fd === 'number' && file1.fd > 0, 'file1.fd must be a positive integer');
  assert.ok(typeof file1.path === 'string' && file1.path.length > 0, 'file1.path must be a non-empty string');
  assert.ok(fs.existsSync(file1.path), 'file1 must exist on disk');
  assert.ok(path.basename(file1.path).startsWith('f-'), 'file1 default prefix should start with f-');
  fs.writeSync(file1.fd, 'test-default-sync');
  fs.closeSync(file1.fd);
  assert.equal(fs.readFileSync(file1.path, 'utf8'), 'test-default-sync');
  fs.unlinkSync(file1.path);

  // 2. temp.openSync accepts a string prefix to customize generated file path
  const file2 = openTempSync('custom-sync-prefix-');
  assert.ok(typeof file2.fd === 'number' && file2.fd > 0, 'file2.fd must be a positive integer');
  assert.ok(fs.existsSync(file2.path), 'file2 must exist on disk');
  assert.ok(path.basename(file2.path).startsWith('custom-sync-prefix-'), 'file2 should use custom prefix');
  fs.writeSync(file2.fd, 'test-string-prefix');
  fs.closeSync(file2.fd);
  assert.equal(fs.readFileSync(file2.path, 'utf8'), 'test-string-prefix');
  fs.unlinkSync(file2.path);

  // 3. temp.openSync accepts an options object specifying prefix, suffix, and directory
  const customDir = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-open-sync-test-'));
  const file3 = openTempSync({ prefix: 'opts-sync-prefix-', suffix: '.tmp', dir: customDir });
  assert.ok(typeof file3.fd === 'number' && file3.fd > 0, 'file3.fd must be a positive integer');
  assert.ok(fs.existsSync(file3.path), 'file3 must exist on disk');
  assert.ok(file3.path.startsWith(customDir), 'file3 must be inside custom directory');
  assert.ok(path.basename(file3.path).startsWith('opts-sync-prefix-'), 'file3 must start with opts-sync-prefix-');
  assert.ok(file3.path.endsWith('.tmp'), 'file3 must end with suffix .tmp');
  fs.writeSync(file3.fd, 'test-options-object');
  fs.closeSync(file3.fd);
  assert.equal(fs.readFileSync(file3.path, 'utf8'), 'test-options-object');
  fs.unlinkSync(file3.path);
  fs.rmdirSync(customDir);

  // 4. temp.openSync returns a writable file descriptor that can be closed and verified on disk
  const file4 = openTempSync({ prefix: 'data-sync-' });
  const buffer = Buffer.from('hello temp openSync');
  const bytesWritten = fs.writeSync(file4.fd, buffer, 0, buffer.length);
  assert.equal(bytesWritten, buffer.length, 'all bytes should be written');
  fs.closeSync(file4.fd);
  assert.equal(fs.readFileSync(file4.path, 'utf8'), 'hello temp openSync');
  fs.unlinkSync(file4.path);

  // 5. temp.openSync throws an error when called with invalid affix types
  assert.throws(() => {
    temp.openSync(12345);
  }, /Unknown affix declaration/);

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

try {
  testAll();
} catch (err) {
  console.error('Contract test failure:', err);
  process.exit(1);
}

オリジンシーダー

匿名