Пример
bare-posix 1.0.1: getegid
Проверенный пример — npm bare-posix 1.0.1: getegid. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: package manifest specifies bare-posix…
sha256:a283c9d87fcbd0408385ec21740b95b061f3d354583861b6b151278f6f378d49
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
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.getegid in pkg:npm/bare-posix@1.0.1
- Пакеты
- Символы
-
- bare-posix.getegid
- Создан
- 2026-09-07T01:48:33Z
Контракт
- 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
Файлы
- PROMPT.md
- csx.json
- 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 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.
{"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"}
{
"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"
}
}
}
{
"name": "sample-bare-posix-getegid",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"bare-posix": "1.0.1"
}
}
{
"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"
]
}
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.');
Исходный сидер
аноним