샘플
tmp 0.2.7: file
검증된 샘플 — npm tmp 0.2.7: file. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert tmp.file is a function exported by tmp
sha256:92b767250ed01fcd62982062e58856f8485fc31607732c05891b8aca29fcec60
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-01 |
케이스
HOW- 목표
- verify tmp.file in pkg:npm/tmp@0.2.7
- 패키지
- 심벌
-
- tmp.file
- 환경
- node 22.23.2
- 생성일
- 2026-09-01T20:42:05Z
컨트랙트
- assert tmp.file is a function exported by tmp
- assert tmp.file creates a temporary file on disk with a valid file descriptor
- assert tmp.file respects prefix and postfix options
- assert tmp.file respects discardDescriptor option by returning undefined file descriptor
- assert tmp.file respects mode option when creating the file
- assert tmp.file cleanup callback is idempotent and safely ignored on subsequent calls
파일
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
소스
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 tmp.file in pkg:npm/tmp@0.2.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/tmp@0.2.7
Demonstrate these symbols/APIs:
- tmp.file
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.
{"case":{"caseId":"case:sha256:6b7f036b52ba99d5833c80df9058fb2aadbcbace9ac28e17ce0364e21e43991f","contract":["assert tmp.file is a function exported by tmp","assert tmp.file creates a temporary file on disk with a valid file descriptor","assert tmp.file respects prefix and postfix options","assert tmp.file respects discardDescriptor option by returning undefined file descriptor","assert tmp.file respects mode option when creating the file","assert tmp.file cleanup callback is idempotent and safely ignored on subsequent calls"],"goal":"verify tmp.file in pkg:npm/tmp@0.2.7","kind":"HOW","packages":["pkg:npm/tmp@0.2.7"],"schemaVersion":1,"symbols":["tmp.file"]},"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/tmp@0.2.7"],"schemaVersion":1,"subject":"pkg:npm/tmp@0.2.7","symbols":["tmp.file"],"verifierAdapter":"node-typescript@1"}
'use strict';
const tmp = require('tmp');
/**
* Creates a temporary file asynchronously with default or custom options.
*
* @param {Object|Function} [options] - Options or callback.
* @param {Function} [callback] - Callback function (err, path, fd, cleanupCallback).
*/
function createTempFile(options, callback) {
if (typeof options === 'function') {
return tmp.file(options);
}
return tmp.file(options, callback);
}
/**
* Promise-based helper to create a temporary file using tmp.file.
*
* @param {Object} [options] - Options for tmp.file.
* @returns {Promise<{path: string, fd: number|undefined, cleanup: Function, cleanupAsync: Function}>}
*/
function createTempFileAsync(options = {}) {
return new Promise((resolve, reject) => {
tmp.file(options, (err, path, fd, cleanupCallback) => {
if (err) {
return reject(err);
}
const cleanupAsync = () =>
new Promise((res, rej) => {
cleanupCallback((cleanErr) => {
if (cleanErr) rej(cleanErr);
else res();
});
});
resolve({ path, fd, cleanup: cleanupCallback, cleanupAsync });
});
});
}
module.exports = {
tmp,
file: tmp.file,
createTempFile,
createTempFileAsync,
};
{
"name": "sample-tmp-file",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-tmp-file",
"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"
}
}
}
}
{
"name": "sample-tmp-file",
"version": "1.0.0",
"description": "Clean-room sample verifying tmp.file in tmp",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"tmp": "0.2.7"
}
}
{
"schemaVersion": 1,
"goal": "verify tmp.file in pkg:npm/tmp@0.2.7",
"kind": "HOW",
"packages": [
"pkg:npm/tmp@0.2.7"
],
"symbols": [
"tmp.file"
]
}
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import tmpPkg from 'tmp';
import samplePkg from '../index.js';
const tmp = tmpPkg.default || tmpPkg;
const {
file,
createTempFile,
createTempFileAsync,
} = samplePkg;
// 1. assert tmp.file is a function exported by tmp
assert.strictEqual(typeof tmp.file, 'function', 'tmp.file must be a function');
assert.strictEqual(typeof file, 'function', 'file exported by index.js must be a function');
assert.strictEqual(typeof createTempFile, 'function', 'createTempFile must be a function');
assert.strictEqual(typeof createTempFileAsync, 'function', 'createTempFileAsync must be a function');
assert.strictEqual(file, tmp.file, 're-exported file must match tmp.file');
// 2. assert tmp.file creates a temporary file on disk with a valid file descriptor
await new Promise((resolve, reject) => {
tmp.file((err, filePath, fd, cleanupCallback) => {
if (err) return reject(err);
try {
assert.strictEqual(typeof filePath, 'string', 'filePath must be a string');
assert.strictEqual(typeof fd, 'number', 'fd must be a valid numeric file descriptor');
assert.ok(fs.existsSync(filePath), 'temporary file must exist on disk');
// Write data to the file descriptor to prove it is open and writable
fs.writeSync(fd, 'tmp-file-contract-test\n');
const content = fs.readFileSync(filePath, 'utf8');
assert.strictEqual(content, 'tmp-file-contract-test\n', 'written content must match');
// Asynchronously cleanup
cleanupCallback((cleanErr) => {
if (cleanErr) return reject(cleanErr);
try {
assert.strictEqual(fs.existsSync(filePath), false, 'temporary file must be removed after cleanup');
resolve();
} catch (assertErr) {
reject(assertErr);
}
});
} catch (e) {
cleanupCallback(() => reject(e));
}
});
});
// 3. assert tmp.file respects prefix and postfix options
await new Promise((resolve, reject) => {
tmp.file({ prefix: 'contract-prefix-', postfix: '.contract-suffix' }, (err, filePath, fd, cleanupCallback) => {
if (err) return reject(err);
try {
const baseName = path.basename(filePath);
assert.ok(baseName.startsWith('contract-prefix-'), `File basename should start with prefix: ${baseName}`);
assert.ok(baseName.endsWith('.contract-suffix'), `File basename should end with postfix: ${baseName}`);
assert.ok(fs.existsSync(filePath), 'temporary file with custom prefix/postfix must exist');
cleanupCallback((cleanErr) => {
if (cleanErr) return reject(cleanErr);
try {
assert.strictEqual(fs.existsSync(filePath), false, 'file must be deleted after cleanup');
resolve();
} catch (assertErr) {
reject(assertErr);
}
});
} catch (e) {
cleanupCallback(() => reject(e));
}
});
});
// 4. assert tmp.file respects discardDescriptor option by returning undefined file descriptor
await new Promise((resolve, reject) => {
tmp.file({ discardDescriptor: true }, (err, filePath, fd, cleanupCallback) => {
if (err) return reject(err);
try {
assert.strictEqual(fd, undefined, 'fd should be undefined when discardDescriptor is true');
assert.ok(fs.existsSync(filePath), 'file should exist even if descriptor is discarded');
cleanupCallback((cleanErr) => {
if (cleanErr) return reject(cleanErr);
try {
assert.strictEqual(fs.existsSync(filePath), false, 'file must be removed after cleanup');
resolve();
} catch (assertErr) {
reject(assertErr);
}
});
} catch (e) {
cleanupCallback(() => reject(e));
}
});
});
// 5. assert tmp.file respects mode option when creating the file
await new Promise((resolve, reject) => {
tmp.file({ mode: 0o640, discardDescriptor: true }, (err, filePath, fd, cleanupCallback) => {
if (err) return reject(err);
try {
const stat = fs.statSync(filePath);
assert.strictEqual(stat.mode & 0o777, 0o640, 'file mode should match requested mode 0o640');
cleanupCallback((cleanErr) => {
if (cleanErr) return reject(cleanErr);
try {
assert.strictEqual(fs.existsSync(filePath), false, 'file must be removed after cleanup');
resolve();
} catch (assertErr) {
reject(assertErr);
}
});
} catch (e) {
cleanupCallback(() => reject(e));
}
});
});
// 6. assert tmp.file cleanup callback is idempotent and safely ignored on subsequent calls
await new Promise((resolve, reject) => {
createTempFile((err, filePath, fd, cleanupCallback) => {
if (err) return reject(err);
try {
assert.ok(fs.existsSync(filePath), 'temporary file must exist');
cleanupCallback((cleanErr1) => {
if (cleanErr1) return reject(cleanErr1);
try {
assert.strictEqual(fs.existsSync(filePath), false, 'temporary file must be removed by first cleanup');
// Second invocation is a no-op and does not throw
assert.doesNotThrow(() => {
cleanupCallback();
}, 'subsequent cleanupCallback invocation must not throw');
resolve();
} catch (assertErr) {
reject(assertErr);
}
});
} catch (e) {
cleanupCallback(() => reject(e));
}
});
});
// 7. Verify async Promise helper
const asyncResult = await createTempFileAsync({ prefix: 'promise-test-' });
assert.ok(fs.existsSync(asyncResult.path), 'async created file must exist');
await asyncResult.cleanupAsync();
assert.strictEqual(fs.existsSync(asyncResult.path), false, 'async created file must be removed after cleanup');
console.log('All tmp.file contract assertions passed.');
오리진 시더
익명