CodeSampleX

サンプル

chownr 2.0.0: sync

検証済みサンプル — npm chownr 2.0.0: sync. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: chownr.sync(path, uid, gid) synchronously changes ownership of…

sha256:520bb1d4a30f73c5696ee1c0a8519cafafdb2b5de19b8b14f36c8bf42bbb0f76

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify pkg:npm/chownr@2.0.0
パッケージ
シンボル
  • chownr
  • chownr.sync
作成日
2026-08-27T17:18:59Z

コントラクト

  1. chownr.sync(path, uid, gid) synchronously changes ownership of nested files and directories
  2. chownr(path, uid, gid, callback) asynchronously changes ownership of nested files and directories
  3. chownr.sync ignores ENOENT when path does not exist
  4. chownr ignores ENOENT when path does not exist

ファイル

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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/chownr@2.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/chownr@2.0.0
Demonstrate these symbols/APIs:
  - chownr
  - chownr.sync

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:201d81d5e64444fff0b94e8f97159e544e68b6092e249b4077221cd88cf76580","contract":["chownr.sync(path, uid, gid) synchronously changes ownership of nested files and directories","chownr(path, uid, gid, callback) asynchronously changes ownership of nested files and directories","chownr.sync ignores ENOENT when path does not exist","chownr ignores ENOENT when path does not exist"],"goal":"verify pkg:npm/chownr@2.0.0","kind":"HOW","packages":["pkg:npm/chownr@2.0.0"],"schemaVersion":1,"symbols":["chownr","chownr.sync"]},"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/chownr@2.0.0"],"schemaVersion":1,"subject":"pkg:npm/chownr@2.0.0","symbols":["chownr","chownr.sync"],"verifierAdapter":"node-typescript@1"}
index.mjs
import chownr from 'chownr';

/**
 * Asynchronously changes ownership of a path and all its contents recursively.
 * @param {string} targetPath - Path to change ownership for
 * @param {number} uid - User ID
 * @param {number} gid - Group ID
 * @returns {Promise<void>}
 */
export function changeOwnerTree(targetPath, uid, gid) {
  return new Promise((resolve, reject) => {
    chownr(targetPath, uid, gid, (err) => {
      if (err) reject(err);
      else resolve();
    });
  });
}

/**
 * Synchronously changes ownership of a path and all its contents recursively.
 * @param {string} targetPath - Path to change ownership for
 * @param {number} uid - User ID
 * @param {number} gid - Group ID
 */
export function changeOwnerTreeSync(targetPath, uid, gid) {
  chownr.sync(targetPath, uid, gid);
}

export { chownr };
package-lock.json
{
  "name": "verify-chownr",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-chownr",
      "version": "1.0.0",
      "dependencies": {
        "chownr": "2.0.0"
      }
    },
    "node_modules/chownr": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
      "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
      "license": "ISC",
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "verify-chownr",
  "version": "1.0.0",
  "description": "Clean-room verification sample for chownr 2.0.0",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "chownr": "2.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/chownr@2.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/chownr@2.0.0"
  ],
  "symbols": [
    "chownr",
    "chownr.sync"
  ]
}
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 chownr from 'chownr';

const uid = process.getuid ? process.getuid() : 1000;
const gid = process.getgid ? process.getgid() : 1000;

const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-chownr-test-'));

try {
  // Test 1: chownr.sync on a nested directory tree
  const syncDir = path.join(tmpRoot, 'sync-tree');
  fs.mkdirSync(path.join(syncDir, 'nested', 'deep'), { recursive: true });
  fs.writeFileSync(path.join(syncDir, 'file1.txt'), 'hello');
  fs.writeFileSync(path.join(syncDir, 'nested', 'file2.txt'), 'world');
  fs.writeFileSync(path.join(syncDir, 'nested', 'deep', 'file3.txt'), 'deep');

  chownr.sync(syncDir, uid, gid);

  const statSyncDir = fs.statSync(syncDir);
  const statSyncFile1 = fs.statSync(path.join(syncDir, 'file1.txt'));
  const statSyncFile2 = fs.statSync(path.join(syncDir, 'nested', 'file2.txt'));
  const statSyncFile3 = fs.statSync(path.join(syncDir, 'nested', 'deep', 'file3.txt'));

  assert.equal(statSyncDir.uid, uid);
  assert.equal(statSyncDir.gid, gid);
  assert.equal(statSyncFile1.uid, uid);
  assert.equal(statSyncFile1.gid, gid);
  assert.equal(statSyncFile2.uid, uid);
  assert.equal(statSyncFile2.gid, gid);
  assert.equal(statSyncFile3.uid, uid);
  assert.equal(statSyncFile3.gid, gid);

  // Test 2: chownr (async) on a nested directory tree
  const asyncDir = path.join(tmpRoot, 'async-tree');
  fs.mkdirSync(path.join(asyncDir, 'sub'), { recursive: true });
  fs.writeFileSync(path.join(asyncDir, 'async-file.txt'), 'async');
  fs.writeFileSync(path.join(asyncDir, 'sub', 'nested.txt'), 'nested');

  await new Promise((resolve, reject) => {
    chownr(asyncDir, uid, gid, (err) => {
      if (err) reject(err);
      else resolve();
    });
  });

  const statAsyncDir = fs.statSync(asyncDir);
  const statAsyncFile1 = fs.statSync(path.join(asyncDir, 'async-file.txt'));
  const statAsyncFile2 = fs.statSync(path.join(asyncDir, 'sub', 'nested.txt'));

  assert.equal(statAsyncDir.uid, uid);
  assert.equal(statAsyncDir.gid, gid);
  assert.equal(statAsyncFile1.uid, uid);
  assert.equal(statAsyncFile1.gid, gid);
  assert.equal(statAsyncFile2.uid, uid);
  assert.equal(statAsyncFile2.gid, gid);

  // Test 3: non-existent path handling (ENOENT is ignored / no error)
  const nonExistent = path.join(tmpRoot, 'does-not-exist');
  assert.doesNotThrow(() => {
    chownr.sync(nonExistent, uid, gid);
  });

  await new Promise((resolve, reject) => {
    chownr(nonExistent, uid, gid, (err) => {
      if (err) reject(err);
      else resolve();
    });
  });

  console.log('All chownr contract tests passed.');
} finally {
  fs.rmSync(tmpRoot, { recursive: true, force: true });
}

オリジンシーダー

匿名