CodeSampleX

サンプル

proper-lockfile 4.1.2: checkSync

検証済みサンプル — npm proper-lockfile 4.1.2: checkSync. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: proper-lockfile.checkSync returns false when a…

sha256:4df5b0572844339b453a195f17077357a833465f8746f7209002729701dafaee

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

実行証拠

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

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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-05

ケース

HOW
ゴール
verify proper-lockfile.checkSync in pkg:npm/proper-lockfile@4.1.2
パッケージ
シンボル
  • proper-lockfile.checkSync
作成日
2026-09-05T19:11:58Z

コントラクト

  1. proper-lockfile.checkSync returns false when a file is not locked
  2. proper-lockfile.checkSync returns true when a file has an active lock acquired via lockSync
  3. proper-lockfile.checkSync returns false after an active lock is released via the release function
  4. proper-lockfile.checkSync returns false after an active lock is released via unlockSync
  5. proper-lockfile.checkSync supports custom stale option to evaluate lock status
  6. proper-lockfile.checkSync synchronously returns a boolean value rather than a Promise
  7. proper-lockfile.checkSync throws ENOENT when checking a non-existent file with default realpath true
  8. proper-lockfile.checkSync returns false without throwing when checking a non-existent file with realpath false

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 proper-lockfile.checkSync in pkg:npm/proper-lockfile@4.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proper-lockfile@4.1.2
Demonstrate these symbols/APIs:
  - proper-lockfile.checkSync

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:d03d59361e31457803e949ecd96adbed8e751c854186cfc54acf0f8343b49b05","contract":["proper-lockfile.checkSync returns false when a file is not locked","proper-lockfile.checkSync returns true when a file has an active lock acquired via lockSync","proper-lockfile.checkSync returns false after an active lock is released via the release function","proper-lockfile.checkSync returns false after an active lock is released via unlockSync","proper-lockfile.checkSync supports custom stale option to evaluate lock status","proper-lockfile.checkSync synchronously returns a boolean value rather than a Promise","proper-lockfile.checkSync throws ENOENT when checking a non-existent file with default realpath true","proper-lockfile.checkSync returns false without throwing when checking a non-existent file with realpath false"],"goal":"verify proper-lockfile.checkSync in pkg:npm/proper-lockfile@4.1.2","kind":"HOW","packages":["pkg:npm/proper-lockfile@4.1.2"],"schemaVersion":1,"symbols":["proper-lockfile.checkSync"]},"contractCommand":["node","test/contract.mjs"],"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/proper-lockfile@4.1.2"],"schemaVersion":1,"subject":"pkg:npm/proper-lockfile@4.1.2","symbols":["proper-lockfile.checkSync"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-proper-lockfile-checksync",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-proper-lockfile-checksync",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "proper-lockfile": "4.1.2"
      }
    },
    "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/proper-lockfile": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz",
      "integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.4",
        "retry": "^0.12.0",
        "signal-exit": "^3.0.2"
      }
    },
    "node_modules/retry": {
      "version": "0.12.0",
      "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
      "integrity": "sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==",
      "license": "MIT",
      "engines": {
        "node": ">= 4"
      }
    },
    "node_modules/signal-exit": {
      "version": "3.0.7",
      "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
      "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-proper-lockfile-checksync",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "proper-lockfile": "4.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify proper-lockfile.checkSync in pkg:npm/proper-lockfile@4.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proper-lockfile@4.1.2"
  ],
  "symbols": [
    "proper-lockfile.checkSync"
  ]
}
src/index.mjs
import lockfile from 'proper-lockfile';

export const {
  lock,
  unlock,
  lockSync,
  unlockSync,
  check,
  checkSync
} = lockfile;

/**
 * Checks synchronously whether a given file path is locked.
 * @param {string} file Path to the file to check
 * @param {object} [options] Options passed to proper-lockfile.checkSync
 * @returns {boolean} True if locked, false otherwise
 */
export function isFileLocked(file, options) {
  return lockfile.checkSync(file, options);
}

export default lockfile;
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import lockfile, { checkSync, lockSync, unlockSync, isFileLocked } from '../src/index.mjs';

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-lockfile-contract-'));
const testFile = path.join(tmpDir, 'resource.txt');
fs.writeFileSync(testFile, 'test payload', 'utf8');

try {
  // 1. proper-lockfile.checkSync returns false when a file is not locked
  {
    const unlockedDirect = checkSync(testFile);
    assert.equal(unlockedDirect, false);

    const unlockedHelper = isFileLocked(testFile);
    assert.equal(unlockedHelper, false);
  }

  // 2. proper-lockfile.checkSync returns true when a file has an active lock acquired via lockSync
  {
    const release = lockSync(testFile);
    const lockedDirect = checkSync(testFile);
    assert.equal(lockedDirect, true);

    const lockedHelper = isFileLocked(testFile);
    assert.equal(lockedHelper, true);

    // 3. proper-lockfile.checkSync returns false after an active lock is released via the release function
    release();
    assert.equal(checkSync(testFile), false);
    assert.equal(isFileLocked(testFile), false);
  }

  // 4. proper-lockfile.checkSync returns false after an active lock is released via unlockSync
  {
    lockSync(testFile);
    assert.equal(checkSync(testFile), true);

    unlockSync(testFile);
    assert.equal(checkSync(testFile), false);
  }

  // 5. proper-lockfile.checkSync supports custom stale option to evaluate lock status
  {
    const release = lockSync(testFile, { stale: 6000 });
    assert.equal(checkSync(testFile, { stale: 6000 }), true);
    release();
    assert.equal(checkSync(testFile, { stale: 6000 }), false);
  }

  // 6. proper-lockfile.checkSync synchronously returns a boolean value rather than a Promise
  {
    const result = checkSync(testFile);
    assert.equal(typeof result, 'boolean');
    assert.equal(result instanceof Promise, false);
  }

  // 7. proper-lockfile.checkSync throws ENOENT when checking a non-existent file with default realpath true
  {
    const nonExistentFile = path.join(tmpDir, 'does-not-exist.txt');
    assert.throws(
      () => {
        checkSync(nonExistentFile);
      },
      (err) => {
        return err && err.code === 'ENOENT';
      }
    );
  }

  // 8. proper-lockfile.checkSync returns false without throwing when checking a non-existent file with realpath false
  {
    const nonExistentFile = path.join(tmpDir, 'does-not-exist.txt');
    const result = checkSync(nonExistentFile, { realpath: false });
    assert.equal(result, false);
  }

  console.log('Contract assertions passed.');
} finally {
  try {
    fs.rmSync(tmpDir, { recursive: true, force: true });
  } catch {
    // Ignore cleanup error
  }
}

オリジンシーダー

匿名