Пример
bare-os 3.9.3: setPriority
Проверенный пример — npm bare-os 3.9.3: setPriority. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: package manifest specifies Bare…
sha256:2822eed7974a0bb5db87f8e11c9465d205d3044e742bdf6b5b4ebc9de5e2e442
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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 setPriority in pkg:npm/bare-os@3.9.3
- Пакеты
- Символы
-
- setPriority
- Окружение
- node 22.23.2
- Создан
- 2026-08-27T09:06:02Z
Контракт
- package manifest specifies Bare addon configuration, Bare engine requirement, and exports root and subpaths for bare-os@3.9.3
- declares setPriority with single-argument priority and two-argument pid/priority overloads and getPriority in index.d.ts
- declares priority constants map in lib/constants.d.ts
- binding.c implements bare_os_set_priority via uv_os_setpriority and exports PRIORITY constants
- setPriority defaults pid to 0 when called with single priority argument and forwards pid and priority to native binding
- setPriority validates pid and priority arguments throwing TypeError when non-integer values are provided
Файлы
- 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 setPriority in pkg:npm/bare-os@3.9.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/bare-os@3.9.3
Demonstrate these symbols/APIs:
- setPriority
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: esm
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:a1bf910aad6f0f818475e604eaccf6a85f89ec5d5bd9d579714276f7cb434106","constraints":{"executionContext":"node"},"contract":["package manifest specifies Bare addon configuration, Bare engine requirement, and exports root and subpaths for bare-os@3.9.3","declares setPriority with single-argument priority and two-argument pid/priority overloads and getPriority in index.d.ts","declares priority constants map in lib/constants.d.ts","binding.c implements bare_os_set_priority via uv_os_setpriority and exports PRIORITY constants","setPriority defaults pid to 0 when called with single priority argument and forwards pid and priority to native binding","setPriority validates pid and priority arguments throwing TypeError when non-integer values are provided"],"goal":"verify setPriority in pkg:npm/bare-os@3.9.3","kind":"HOW","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"symbols":["setPriority"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"subject":"pkg:npm/bare-os@3.9.3","symbols":["setPriority"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-bare-os-setpriority",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-os-setpriority",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"bare-os": "3.9.3"
}
},
"node_modules/bare-os": {
"version": "3.9.3",
"resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.9.3.tgz",
"integrity": "sha512-fF4Q7QsyKVF5Rj0qvI8BgUNjqzC2JvQlpTaPLjVJVxYVUX5Zr9un+y3w1HmA4nNKdFmRBT8z/WmrjvXzXVerKQ==",
"license": "Apache-2.0",
"engines": {
"bare": ">=1.14.0"
}
}
}
}
{
"name": "sample-bare-os-setpriority",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"bare-os": "3.9.3"
}
}
{
"schemaVersion": 1,
"goal": "verify setPriority in pkg:npm/bare-os@3.9.3",
"kind": "HOW",
"packages": [
"pkg:npm/bare-os@3.9.3"
],
"symbols": [
"setPriority"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "esm",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import Module from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
const require = Module.createRequire(import.meta.url);
// 1. Resolve bare-os package manifest and metadata
const pkgPath = require.resolve('bare-os/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const pkgDir = path.dirname(pkgPath);
assert.equal(pkg.name, 'bare-os', 'Package name must be bare-os');
assert.equal(pkg.version, '3.9.3', 'Package version must be 3.9.3');
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.equal(pkg.engines?.bare, '>=1.14.0', 'Package must specify Bare engine >=1.14.0');
assert.ok(pkg.exports, 'Package must define exports');
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['./constants'].types, './lib/constants.d.ts', 'Constants export must have constants.d.ts types');
assert.equal(pkg.exports['./constants'].default, './lib/constants.js', 'Constants export must have constants.js default');
// 2. Verify TypeScript declarations for setPriority, getPriority and priority constants
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
const constantsDts = fs.readFileSync(path.join(pkgDir, 'lib', 'constants.d.ts'), 'utf8');
assert.ok(indexDts.includes('export function setPriority(priority: number): void'), 'index.d.ts must declare setPriority(priority: number)');
assert.ok(indexDts.includes('export function setPriority(pid: number, priority: number): void'), 'index.d.ts must declare setPriority(pid: number, priority: number)');
assert.ok(indexDts.includes('export function getPriority(pid?: number): number'), 'index.d.ts must declare getPriority(pid?: number)');
assert.ok(constantsDts.includes('priority: Record<string, number>'), 'lib/constants.d.ts must declare priority record');
// 3. Verify C native addon source and build configuration
const bindingC = fs.readFileSync(path.join(pkgDir, 'binding.c'), 'utf8');
assert.ok(bindingC.includes('bare_os_set_priority'), 'binding.c must implement bare_os_set_priority');
assert.ok(bindingC.includes('uv_os_setpriority(pid, priority)'), 'binding.c must invoke uv_os_setpriority');
assert.ok(bindingC.includes('V("setPriority", bare_os_set_priority)'), 'binding.c must export setPriority function');
assert.ok(bindingC.includes('V(PRIORITY_LOW)'), 'binding.c must export PRIORITY_LOW');
assert.ok(bindingC.includes('V(PRIORITY_NORMAL)'), 'binding.c must export PRIORITY_NORMAL');
assert.ok(bindingC.includes('V(PRIORITY_HIGH)'), 'binding.c must export PRIORITY_HIGH');
// 4. Verify JS wrapper execution and argument validation with mocked binding
const calls = [];
const mockBinding = {
setPriority(pid, priority) {
calls.push({ pid, priority });
},
getPriority(pid) {
return 0;
},
signals: {},
errnos: {},
priority: {
PRIORITY_LOW: 19,
PRIORITY_BELOW_NORMAL: 10,
PRIORITY_NORMAL: 0,
PRIORITY_ABOVE_NORMAL: -10,
PRIORITY_HIGH: -15,
PRIORITY_HIGHEST: -20
}
};
const bindingPath = path.join(pkgDir, 'binding.js');
require.cache[bindingPath] = {
id: bindingPath,
filename: bindingPath,
loaded: true,
exports: mockBinding
};
const bareOs = require('bare-os');
assert.equal(typeof bareOs.setPriority, 'function', 'bare-os must export setPriority function');
assert.equal(typeof bareOs.getPriority, 'function', 'bare-os must export getPriority function');
// Test single argument overload: setPriority(priority) -> defaults pid to 0
calls.length = 0;
bareOs.setPriority(10);
assert.equal(calls.length, 1);
assert.deepEqual(calls[0], { pid: 0, priority: 10 }, 'Single argument setPriority must pass pid=0');
// Test two argument overload: setPriority(pid, priority)
calls.length = 0;
bareOs.setPriority(4567, -10);
assert.equal(calls.length, 1);
assert.deepEqual(calls[0], { pid: 4567, priority: -10 }, 'Two argument setPriority must pass provided pid and priority');
// Test constants.priority values
assert.equal(bareOs.constants.priority.PRIORITY_LOW, 19);
assert.equal(bareOs.constants.priority.PRIORITY_NORMAL, 0);
assert.equal(bareOs.constants.priority.PRIORITY_HIGH, -15);
assert.equal(bareOs.constants.priority.PRIORITY_HIGHEST, -20);
// Test argument validation
assert.throws(() => bareOs.setPriority('invalid'), {
name: 'TypeError',
message: 'Priority must be an integer. Received type string (invalid)'
}, 'setPriority must reject non-integer priority in single-argument form');
assert.throws(() => bareOs.setPriority('invalid_pid', 0), {
name: 'TypeError',
message: 'Process ID must be an integer. Received type string (invalid_pid)'
}, 'setPriority must reject non-integer pid in two-argument form');
assert.throws(() => bareOs.setPriority(1234, 'invalid_priority'), {
name: 'TypeError',
message: 'Priority must be an integer. Received type string (invalid_priority)'
}, 'setPriority must reject non-integer priority in two-argument form');
assert.throws(() => bareOs.setPriority(1.5), {
name: 'TypeError',
message: 'Priority must be an integer. Received type number (1.5)'
}, 'setPriority must reject float priority');
console.log('Contract tests passed successfully.');
Исходный сидер
аноним