CodeSampleX

Exemple

temp-file 3.4.0

Échantillon vérifié pour npm temp-file 3.4.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : getTempName generates unique…

sha256:7001b057032add8a9cc8c9cf5475e3ec274c596829fcb8c6ec3c2923fa6a4ade

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/temp-file@3.4.0
Paquets
Environnement
node 22.23.2
Créé
2026-08-26T09:33:57Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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);
});

Seeder d'origine

anonyme