CodeSampleX

샘플

bare-posix 1.0.1: geteuid

검증된 샘플 — npm bare-posix 1.0.1: geteuid. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: declares geteuid returning number and seteuid accepting…

sha256:8e311052ef07a8e2e6519bf53ee60d340d7620402949cc4d8391799ce7e254b9

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

케이스

HOW
목표
verify bare-posix.geteuid in pkg:npm/bare-posix@1.0.1
패키지
심벌
  • bare-posix.geteuid
생성일
2026-09-07T02:42:26Z

컨트랙트

  1. declares geteuid returning number and seteuid accepting number or string in TypeScript definition index.d.ts
  2. unsupported platform fallback implements geteuid returning -1 and seteuid throwing platform not supported error
  3. native C binding implements bare_posix_geteuid invoking POSIX geteuid and bare_posix_seteuid invoking seteuid
  4. module wrapper exports geteuid delegating to native binding returning effective user ID
  5. module wrapper seteuid accepts numeric user ID and forwards directly to native binding
  6. module wrapper seteuid resolves string username to UID via getpwnam before calling native binding

파일

  • PROMPT.md
  • csx.json
  • 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 bare-posix.geteuid in pkg:npm/bare-posix@1.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-posix@1.0.1
Demonstrate these symbols/APIs:
  - bare-posix.geteuid

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:a2aa3d417fb61c1bc578ea4ddc71ceb2d85ad61677cfce7140400caeb88ea4d8","contract":["declares geteuid returning number and seteuid accepting number or string in TypeScript definition index.d.ts","unsupported platform fallback implements geteuid returning -1 and seteuid throwing platform not supported error","native C binding implements bare_posix_geteuid invoking POSIX geteuid and bare_posix_seteuid invoking seteuid","module wrapper exports geteuid delegating to native binding returning effective user ID","module wrapper seteuid accepts numeric user ID and forwards directly to native binding","module wrapper seteuid resolves string username to UID via getpwnam before calling native binding"],"goal":"verify bare-posix.geteuid in pkg:npm/bare-posix@1.0.1","kind":"HOW","packages":["pkg:npm/bare-posix@1.0.1"],"schemaVersion":1,"symbols":["bare-posix.geteuid"]},"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/bare-posix@1.0.1"],"schemaVersion":1,"subject":"pkg:npm/bare-posix@1.0.1","symbols":["bare-posix.geteuid"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-posix-geteuid",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-posix-geteuid",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-posix": "1.0.1"
      }
    },
    "node_modules/bare-posix": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/bare-posix/-/bare-posix-1.0.1.tgz",
      "integrity": "sha512-b4quA8dyRVvX0aFIAIiev5zFATHwIUGr42Gmt+CqiBNg/bdsNkrj4bbkeotMOMiljJS4DCME5kywJO/TFwKo1A==",
      "license": "Apache-2.0"
    }
  }
}
package.json
{
  "name": "sample-bare-posix-geteuid",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-posix": "1.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-posix.geteuid in pkg:npm/bare-posix@1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-posix@1.0.1"
  ],
  "symbols": [
    "bare-posix.geteuid"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';

const require = createRequire(import.meta.url);

// 1. Resolve bare-posix package and verify manifest
const pkgPath = require.resolve('bare-posix/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'bare-posix', 'Package name must be bare-posix');
assert.equal(pkg.version, '1.0.1', 'Package version must be 1.0.1');
assert.equal(pkg.addon, true, 'Package must be marked as Bare addon');

const pkgDir = path.dirname(pkgPath);

// 2. Verify TypeScript declarations for bare-posix.geteuid and bare-posix.seteuid
const indexDtsPath = path.join(pkgDir, 'index.d.ts');
assert.ok(fs.existsSync(indexDtsPath), 'index.d.ts must exist');
const indexDts = fs.readFileSync(indexDtsPath, 'utf8');

assert.ok(indexDts.includes('export function geteuid(): number'), 'index.d.ts must declare geteuid');
assert.ok(indexDts.includes('export function seteuid(id: number | string): void'), 'index.d.ts must declare seteuid');

// 3. Verify unsupported platform fallback implementation in unsupported.js
const unsupportedPath = path.join(pkgDir, 'unsupported.js');
assert.ok(fs.existsSync(unsupportedPath), 'unsupported.js must exist');
const unsupported = require(unsupportedPath);

assert.equal(typeof unsupported.geteuid, 'function', 'unsupported.geteuid must be a function');
assert.equal(unsupported.geteuid(), -1, 'unsupported.geteuid() must return -1');
assert.throws(() => unsupported.seteuid(0), /Platform not supported/, 'unsupported.seteuid must throw Platform not supported');

// 4. Verify C native addon source in binding.c
const bindingCPath = path.join(pkgDir, 'binding.c');
assert.ok(fs.existsSync(bindingCPath), 'binding.c must exist');
const bindingC = fs.readFileSync(bindingCPath, 'utf8');

assert.ok(bindingC.includes('bare_posix_geteuid'), 'binding.c must implement bare_posix_geteuid');
assert.ok(bindingC.includes('geteuid()'), 'binding.c must call POSIX geteuid()');
assert.ok(bindingC.includes('bare_posix_seteuid'), 'binding.c must implement bare_posix_seteuid');
assert.ok(bindingC.includes('seteuid('), 'binding.c must call POSIX seteuid()');
assert.ok(bindingC.includes('BARE_MODULE(bare_posix, bare_posix_exports)'), 'binding.c must export BARE_MODULE');

// 5. Verify index.js wrapper logic with mock native binding
const bindingJsPath = path.join(pkgDir, 'binding.js');
const indexJsPath = path.join(pkgDir, 'index.js');
assert.ok(fs.existsSync(bindingJsPath), 'binding.js must exist');
assert.ok(fs.existsSync(indexJsPath), 'index.js must exist');

const mockCalls = [];
const mockBinding = {
  geteuid: () => 1000,
  seteuid: (id) => { mockCalls.push(['seteuid', id]); },
  getpwnam: (name) => {
    if (name === 'root') return { username: 'root', passwd: 'x', uid: 0, gid: 0, gecos: 'root', homedir: '/root', shell: '/bin/bash' };
    if (name === 'nobody') return { username: 'nobody', passwd: 'x', uid: 65534, gid: 65534, gecos: 'nobody', homedir: '/nonexistent', shell: '/usr/sbin/nologin' };
    return null;
  }
};

require.cache[bindingJsPath] = {
  id: bindingJsPath,
  filename: bindingJsPath,
  loaded: true,
  exports: mockBinding
};

delete require.cache[indexJsPath];
const posix = require(indexJsPath);

assert.equal(typeof posix.geteuid, 'function', 'posix.geteuid must be exported as a function');
assert.equal(posix.geteuid(), 1000, 'posix.geteuid() must delegate to binding.geteuid');

// Test seteuid with numeric ID
posix.seteuid(500);
assert.deepEqual(mockCalls[mockCalls.length - 1], ['seteuid', 500], 'posix.seteuid with numeric ID must pass integer directly to binding');

// Test seteuid with string username (delegating to getpwnam)
posix.seteuid('root');
assert.deepEqual(mockCalls[mockCalls.length - 1], ['seteuid', 0], 'posix.seteuid with root must resolve to uid 0');

posix.seteuid('nobody');
assert.deepEqual(mockCalls[mockCalls.length - 1], ['seteuid', 65534], 'posix.seteuid with nobody must resolve to uid 65534');

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

오리진 시더

익명