CodeSampleX

Exemple

bare-posix 1.0.1: getegid

Échantillon vérifié pour npm bare-posix 1.0.1: getegid. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:a283c9d87fcbd0408385ec21740b95b061f3d354583861b6b151278f6f378d49

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é linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

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

Cas

HOW
Objectif
verify bare-posix.getegid in pkg:npm/bare-posix@1.0.1
Paquets
Symboles
  • bare-posix.getegid
Créé
2026-09-07T01:48:33Z

Contrat

  1. package manifest specifies bare-posix 1.0.1 with Bare addon flag and subpath exports
  2. declares getegid() returning number and setegid in TypeScript definitions (index.d.ts)
  3. exports getegid function from binding and setegid wrapper in JavaScript interface
  4. native binding registers bare_posix_getegid returning POSIX getegid() as 32-bit unsigned integer
  5. unsupported platform fallback implements getegid() returning -1
  6. prebuilt native addon binaries exist across linux and darwin platforms
  7. posix.getegid() returns non-negative integer matching process effective group ID
  8. posix.setegid restores numeric effective group ID and resolves group name

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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 bare-posix.getegid 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.getegid

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:fd74837688cc3aa3cf7c5451d5d7546e793655e07391439ff52c79a9a6fed2ef","contract":["package manifest specifies bare-posix 1.0.1 with Bare addon flag and subpath exports","declares getegid() returning number and setegid in TypeScript definitions (index.d.ts)","exports getegid function from binding and setegid wrapper in JavaScript interface","native binding registers bare_posix_getegid returning POSIX getegid() as 32-bit unsigned integer","unsupported platform fallback implements getegid() returning -1","prebuilt native addon binaries exist across linux and darwin platforms","posix.getegid() returns non-negative integer matching process effective group ID","posix.setegid restores numeric effective group ID and resolves group name"],"goal":"verify bare-posix.getegid in pkg:npm/bare-posix@1.0.1","kind":"HOW","packages":["pkg:npm/bare-posix@1.0.1"],"schemaVersion":1,"symbols":["bare-posix.getegid"]},"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.getegid"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-posix-getegid",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-posix-getegid",
      "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-getegid",
  "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.getegid in pkg:npm/bare-posix@1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-posix@1.0.1"
  ],
  "symbols": [
    "bare-posix.getegid"
  ]
}
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 manifest and verify exports and metadata
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.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.equal(pkg.addon, true, 'Package must be marked as addon');

assert.ok(pkg.exports, 'Package must define exports map');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must have index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must have index.js default');
assert.equal(pkg.exports['.'].android, './unsupported.js', 'Android export must point to unsupported.js');
assert.equal(pkg.exports['.'].win32, './unsupported.js', 'Win32 export must point to unsupported.js');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to package.json');

const pkgDir = path.dirname(pkgPath);

// 2. Verify TypeScript declarations (index.d.ts) for getegid and setegid
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
assert.ok(
  indexDts.includes('export function getegid(): number'),
  'index.d.ts must declare export function getegid(): number'
);
assert.ok(
  indexDts.includes('export function setegid(id: number | string): void'),
  'index.d.ts must declare export function setegid(id: number | string): void'
);

// 3. Verify JavaScript implementation exports getegid and setegid wrapper logic
const indexJs = fs.readFileSync(path.join(pkgDir, 'index.js'), 'utf8');
assert.ok(
  indexJs.includes('exports.getegid = binding.getegid'),
  'index.js must export getegid from native binding'
);
assert.ok(
  indexJs.includes('exports.setegid = function setegid(id)'),
  'index.js must export setegid wrapper function'
);

// 4. Verify C native addon binding (binding.c) for bare_posix_getegid
const bindingC = fs.readFileSync(path.join(pkgDir, 'binding.c'), 'utf8');
assert.ok(
  bindingC.includes('bare_posix_getegid(js_env_t *env, js_callback_info_t *info)'),
  'binding.c must implement bare_posix_getegid'
);
assert.ok(
  bindingC.includes('err = js_create_uint32(env, getegid(), &result);'),
  'binding.c must create uint32 from POSIX getegid()'
);
assert.ok(
  bindingC.includes('V("getegid", bare_posix_getegid)'),
  'binding.c must export getegid symbol in bare_posix_exports'
);
assert.ok(
  bindingC.includes('BARE_MODULE(bare_posix, bare_posix_exports)'),
  'binding.c must register bare_posix module'
);

// 5. Verify unsupported platform fallback behavior (unsupported.js)
const unsupportedJs = fs.readFileSync(path.join(pkgDir, 'unsupported.js'), 'utf8');
assert.ok(
  unsupportedJs.includes('exports.getegid = function getegid() {\n  return -1\n}'),
  'unsupported.js must return -1 for getegid on unsupported platforms'
);

// 6. Verify prebuilt native addon artifacts exist for supported platforms
const prebuildsDir = path.join(pkgDir, 'prebuilds');
const expectedTargets = [
  'linux-x64',
  'linux-arm64',
  'darwin-x64',
  'darwin-arm64'
];
for (const target of expectedTargets) {
  const prebuildPath = path.join(prebuildsDir, target, 'bare-posix.bare');
  assert.ok(fs.existsSync(prebuildPath), `Prebuild binary for ${target} must exist`);
  const stats = fs.statSync(prebuildPath);
  assert.ok(stats.size > 0, `Prebuild binary for ${target} must not be empty`);
}

// 7. Verify runtime behavior of getegid and setegid using simulated native binding
const bindingPath = path.join(pkgDir, 'binding.js');
let currentEgid = typeof process.getegid === 'function' ? process.getegid() : 1000;
let lastSetEgid = null;

require.cache[bindingPath] = {
  id: bindingPath,
  filename: bindingPath,
  loaded: true,
  exports: {
    getegid: () => currentEgid,
    setegid: (id) => {
      if (typeof id !== 'number' || id < 0) {
        throw new Error('invalid gid');
      }
      lastSetEgid = id;
    },
    getgrnam: (name) => {
      if (name === 'currentgroup') {
        return { groupname: 'currentgroup', passwd: 'x', gid: currentEgid, members: [] };
      }
      return null;
    }
  }
};

const posix = require('bare-posix');
assert.equal(typeof posix.getegid, 'function', 'bare-posix must export getegid function');

// Verify getegid returns non-negative number
const egid = posix.getegid();
assert.equal(typeof egid, 'number', 'getegid() must return a number');
assert.ok(Number.isInteger(egid), 'getegid() must return an integer');
assert.ok(egid >= 0, 'getegid() must return a non-negative integer');
assert.equal(egid, currentEgid, 'getegid() must match current effective group ID');

// Verify setegid with current numeric egid
posix.setegid(egid);
assert.equal(lastSetEgid, egid, 'setegid must successfully set current numeric egid');

// Verify setegid resolving group name via getgrnam
posix.setegid('currentgroup');
assert.equal(lastSetEgid, currentEgid, 'setegid must resolve group name to gid and set it');

// Verify setegid with unknown group name throws TypeError
assert.throws(
  () => posix.setegid('nonexistent_group_test'),
  (err) => err instanceof TypeError,
  'setegid with unknown group name should throw TypeError accessing null.gid'
);

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

Seeder d'origine

anonyme