CodeSampleX

샘플

temp-file 3.4.0

검증된 샘플 — npm temp-file 3.4.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: getTempName generates unique temporary file names with optional…

sha256:7001b057032add8a9cc8c9cf5475e3ec274c596829fcb8c6ec3c2923fa6a4ade

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

케이스

HOW
목표
verify pkg:npm/temp-file@3.4.0
패키지
환경
node 22.23.2
생성일
2026-08-26T09:33:57Z

컨트랙트

  1. getTempName generates unique temporary file names with optional prefix
  2. TmpDir rootTempDir returns a promise resolving to the root temporary directory
  3. createTempDir creates a temporary directory on disk and returns its path
  4. getTempFile generates temporary file paths with optional prefix and suffix
  5. getTempDir returns a temporary directory path
  6. cleanup asynchronously deletes tracked temporary files and directories
  7. cleanupSync synchronously deletes tracked temporary files and directories
  8. custom disposer callback is invoked for tracked temporary files during cleanupSync

파일

  • 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 pkg:npm/temp-file@3.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/temp-file@3.4.0
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:8a8ad29dd9ce0f7deea5b50fbca1d832a97fe5caefe86c0b82aa8c7d767ee85c","constraints":{"executionContext":"node"},"contract":["getTempName generates unique temporary file names with optional prefix","TmpDir rootTempDir returns a promise resolving to the root temporary directory","createTempDir creates a temporary directory on disk and returns its path","getTempFile generates temporary file paths with optional prefix and suffix","getTempDir returns a temporary directory path","cleanup asynchronously deletes tracked temporary files and directories","cleanupSync synchronously deletes tracked temporary files and directories","custom disposer callback is invoked for tracked temporary files during cleanupSync"],"goal":"verify pkg:npm/temp-file@3.4.0","kind":"HOW","packages":["pkg:npm/temp-file@3.4.0"],"schemaVersion":1},"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-file@3.4.0"],"schemaVersion":1,"subject":"pkg:npm/temp-file@3.4.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-2202134067",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "dependencies": {
        "temp-file": "^3.4.0"
      }
    },
    "node_modules/async-exit-hook": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/async-exit-hook/-/async-exit-hook-2.0.1.tgz",
      "integrity": "sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==",
      "license": "MIT",
      "engines": {
        "node": ">=0.12.0"
      }
    },
    "node_modules/fs-extra": {
      "version": "10.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
      "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=12"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/jsonfile": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/temp-file": {
      "version": "3.4.0",
      "resolved": "https://registry.npmjs.org/temp-file/-/temp-file-3.4.0.tgz",
      "integrity": "sha512-C5tjlC/HCtVUOi3KWVokd4vHVViOmGjtLwIh4MuzPo/nMYTV/p1urt3RnMz2IWXDdKEGJH3k5+KPxtqRsUYGtg==",
      "license": "MIT",
      "dependencies": {
        "async-exit-hook": "^2.0.1",
        "fs-extra": "^10.0.0"
      }
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-temp-file",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of temp-file",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "temp-file": "3.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/temp-file@3.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/temp-file@3.4.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { TmpDir, getTempName } = require('temp-file');

/**
 * Generate a unique temporary name with an optional prefix.
 */
function createTempName(prefix) {
  return getTempName(prefix);
}

/**
 * Create a new TmpDir manager instance.
 */
function createTmpDirManager(debugName) {
  return new TmpDir(debugName);
}

module.exports = {
  TmpDir,
  getTempName,
  createTempName,
  createTmpDirManager
};
test/contract.mjs
import assert from 'node:assert';
import fs from 'node:fs';
import fsp from 'node:fs/promises';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  TmpDir,
  getTempName,
  createTempName,
  createTmpDirManager
} = require('../src/index.js');

async function runContract() {
  // 1. getTempName generates unique temporary file names with optional prefix
  const nameWithoutPrefix = createTempName();
  const nameWithPrefix = createTempName('myprefix');
  assert.strictEqual(typeof nameWithoutPrefix, 'string');
  assert.strictEqual(typeof nameWithPrefix, 'string');
  assert.ok(nameWithPrefix.startsWith('myprefix-'), 'Name should start with prefix');
  assert.notStrictEqual(nameWithoutPrefix, nameWithPrefix, 'Generated names should be distinct');

  // 2. TmpDir rootTempDir returns a promise resolving to the root temporary directory
  const manager = createTmpDirManager('test-manager-1');
  const rootDir = await manager.rootTempDir;
  assert.strictEqual(typeof rootDir, 'string');
  assert.ok(fs.existsSync(rootDir), 'Root temp directory should exist on disk');

  // 3. createTempDir creates a temporary directory on disk and returns its path
  const createdDir = await manager.createTempDir({ prefix: 'subdir', suffix: 'test' });
  assert.strictEqual(typeof createdDir, 'string');
  assert.ok(createdDir.startsWith(rootDir), 'Created dir should be under rootTempDir');
  assert.ok(fs.existsSync(createdDir), 'Created directory must exist on disk');
  const dirStat = await fsp.stat(createdDir);
  assert.ok(dirStat.isDirectory(), 'Path must be a directory');

  // 4. getTempFile generates temporary file paths with optional prefix and suffix
  const tempFilePath = await manager.getTempFile({ prefix: 'sample', suffix: '.txt' });
  assert.strictEqual(typeof tempFilePath, 'string');
  assert.ok(tempFilePath.startsWith(rootDir), 'Temp file path should be under rootTempDir');
  assert.ok(tempFilePath.endsWith('.txt'), 'Temp file path should have suffix .txt');
  await fsp.writeFile(tempFilePath, 'contract test content', 'utf8');
  assert.ok(fs.existsSync(tempFilePath), 'Written temp file should exist');

  // 5. getTempDir returns a temporary directory path
  const tempDirPath = await manager.getTempDir({ prefix: 'lazy-dir' });
  assert.strictEqual(typeof tempDirPath, 'string');
  assert.ok(tempDirPath.startsWith(rootDir), 'Temp dir path should be under rootTempDir');
  await fsp.mkdir(tempDirPath, { recursive: true });
  assert.ok(fs.existsSync(tempDirPath), 'Ensured temp dir should exist');

  // 6. cleanup asynchronously deletes tracked temporary files and directories
  await manager.cleanup();
  assert.strictEqual(fs.existsSync(tempFilePath), false, 'Temp file should be deleted after cleanup');
  assert.strictEqual(fs.existsSync(createdDir), false, 'Created dir should be deleted after cleanup');
  assert.strictEqual(fs.existsSync(tempDirPath), false, 'Temp dir should be deleted after cleanup');

  // 7. cleanupSync synchronously deletes tracked temporary files and directories
  const syncManager = new TmpDir('sync-manager');
  const syncFile = await syncManager.getTempFile({ prefix: 'sync', suffix: '.dat' });
  await fsp.writeFile(syncFile, 'sync content', 'utf8');
  assert.ok(fs.existsSync(syncFile), 'Sync file must exist before cleanupSync');
  syncManager.cleanupSync();
  assert.strictEqual(fs.existsSync(syncFile), false, 'Sync file must not exist after cleanupSync');

  // 8. custom disposer callback is invoked for tracked temporary files during cleanupSync
  let syncDisposerCalled = false;
  let syncDisposedPath = null;
  const syncDisposerManager = new TmpDir('sync-disposer-manager');
  const customSyncFile = await syncDisposerManager.getTempFile({
    prefix: 'custom-sync',
    disposer: async (file) => {
      syncDisposerCalled = true;
      syncDisposedPath = file;
      if (fs.existsSync(file)) {
        fs.unlinkSync(file);
      }
    }
  });
  await fsp.writeFile(customSyncFile, 'sync disposer test', 'utf8');
  assert.ok(fs.existsSync(customSyncFile), 'Custom sync file exists');
  syncDisposerManager.cleanupSync();
  assert.strictEqual(syncDisposerCalled, true, 'Disposer callback should be called during cleanupSync');
  assert.strictEqual(syncDisposedPath, customSyncFile, 'Disposer should receive the file path');
  assert.strictEqual(fs.existsSync(customSyncFile), false, 'Custom sync file should be removed');

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

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명