샘플
@emnapi/wasi-threads 1.2.2
검증된 샘플 — npm @emnapi/wasi-threads 1.2.2. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: isSharedArrayBuffer identifies SharedArrayBuffer…
sha256:0058c6d5052ca9b8155b5813c220b2704b65217dda70b4d56b013ccb234e3a6a
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-19 |
케이스
HOW- 목표
- verify pkg:npm/%40emnapi/wasi-threads@1.2.2
- 생성일
- 2026-09-18T20:32:22Z
컨트랙트
- isSharedArrayBuffer identifies SharedArrayBuffer instances and rejects other types
- isTrapError detects WebAssembly.RuntimeError instances and rejects standard Errors
- createInstanceProxy wraps a WebAssembly instance and preserves exports
- WASIThreads initializes main thread configuration and provides wasi thread-spawn import
- WASIThreads enforces postMessage requirement in child thread configuration
- ThreadMessageHandler validates postMessage handler and exposes message handling methods
- ThreadManager initializes worker pool and tracks worker identifiers
파일
- PROMPT.md
- csx.json
- index.mjs
- 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 pkg:npm/%40emnapi/wasi-threads@1.2.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40emnapi/wasi-threads@1.2.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:b1448bb1293d89be5a357297d80d0d72b737386813f7a25771f6398e6772bde0","contract":["isSharedArrayBuffer identifies SharedArrayBuffer instances and rejects other types","isTrapError detects WebAssembly.RuntimeError instances and rejects standard Errors","createInstanceProxy wraps a WebAssembly instance and preserves exports","WASIThreads initializes main thread configuration and provides wasi thread-spawn import","WASIThreads enforces postMessage requirement in child thread configuration","ThreadMessageHandler validates postMessage handler and exposes message handling methods","ThreadManager initializes worker pool and tracks worker identifiers"],"goal":"verify pkg:npm/%40emnapi/wasi-threads@1.2.2","kind":"HOW","packages":["pkg:npm/%40emnapi/wasi-threads@1.2.2"],"schemaVersion":1},"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/%40emnapi/wasi-threads@1.2.2"],"schemaVersion":1,"subject":"pkg:npm/%40emnapi/wasi-threads@1.2.2","verifierAdapter":"node-typescript@1"}
import {
WASIThreads,
ThreadManager,
ThreadMessageHandler,
createInstanceProxy,
isSharedArrayBuffer,
isTrapError
} from '@emnapi/wasi-threads';
/**
* Creates a WASIThreads manager configured for the given WASI instance.
*
* @param {object} wasi - WASI instance conforming to WASIInstance interface.
* @param {Function} onCreateWorker - Worker factory callback.
* @param {object} [options] - Additional configuration options.
* @returns {WASIThreads} Initialized WASIThreads instance.
*/
export function createWASIThreads(wasi, onCreateWorker, options = {}) {
return new WASIThreads({
wasi,
onCreateWorker,
...options
});
}
/**
* Checks whether a given buffer is a SharedArrayBuffer.
*
* @param {*} value - The value to test.
* @returns {boolean} True if the value is a SharedArrayBuffer.
*/
export function checkSharedArrayBuffer(value) {
return isSharedArrayBuffer(value);
}
/**
* Checks whether an error is a WebAssembly trap runtime error.
*
* @param {Error} error - The error to inspect.
* @returns {boolean} True if the error is a WebAssembly.RuntimeError.
*/
export function checkTrapError(error) {
return isTrapError(error);
}
export {
WASIThreads,
ThreadManager,
ThreadMessageHandler,
createInstanceProxy,
isSharedArrayBuffer,
isTrapError
};
{
"name": "sample-wasi-threads",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-wasi-threads",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@emnapi/wasi-threads": "1.2.2"
}
},
"node_modules/@emnapi/wasi-threads": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz",
"integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==",
"license": "MIT",
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
}
}
}
{
"name": "sample-wasi-threads",
"version": "1.0.0",
"type": "module",
"main": "index.mjs",
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@emnapi/wasi-threads": "1.2.2"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40emnapi/wasi-threads@1.2.2",
"kind": "HOW",
"packages": [
"pkg:npm/%40emnapi/wasi-threads@1.2.2"
]
}
import assert from 'node:assert/strict';
import {
WASIThreads,
ThreadManager,
ThreadMessageHandler,
createInstanceProxy,
isSharedArrayBuffer,
isTrapError,
createWASIThreads,
checkSharedArrayBuffer,
checkTrapError
} from '../index.mjs';
// 1. isSharedArrayBuffer identifies SharedArrayBuffer instances and rejects other types
assert.equal(isSharedArrayBuffer(new SharedArrayBuffer(16)), true);
assert.equal(isSharedArrayBuffer(new ArrayBuffer(16)), false);
assert.equal(isSharedArrayBuffer(null), false);
assert.equal(isSharedArrayBuffer({}), false);
assert.equal(isSharedArrayBuffer('string'), false);
assert.equal(checkSharedArrayBuffer(new SharedArrayBuffer(8)), true);
// 2. isTrapError detects WebAssembly.RuntimeError instances and rejects standard Errors
assert.equal(isTrapError(new WebAssembly.RuntimeError('unreachable')), true);
assert.equal(isTrapError(new Error('general error')), false);
assert.equal(isTrapError(new TypeError('type error')), false);
assert.equal(checkTrapError(new WebAssembly.RuntimeError('trap')), true);
// 3. createInstanceProxy wraps a WebAssembly instance and preserves exports
const wasmBytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
const wasmModule = new WebAssembly.Module(wasmBytes);
const wasmInstance = new WebAssembly.Instance(wasmModule);
const proxied = createInstanceProxy(wasmInstance);
assert.ok(typeof proxied === 'object' && proxied !== null);
// 4. WASIThreads initializes main thread configuration and provides wasi thread-spawn import
const mockWasi = { wasiImport: {}, initialize: () => {}, start: () => 0 };
const wtInstance = createWASIThreads(mockWasi, () => ({}));
assert.equal(wtInstance.childThread, false);
assert.ok(wtInstance.PThread instanceof ThreadManager);
const imports = wtInstance.getImportObject();
assert.equal(typeof imports.wasi['thread-spawn'], 'function');
// 5. WASIThreads enforces postMessage requirement in child thread configuration
assert.throws(
() => new WASIThreads({ wasi: mockWasi, childThread: true }),
{
name: 'TypeError',
message: 'options.postMessage is not a function'
}
);
const childWt = new WASIThreads({ wasi: mockWasi, childThread: true, postMessage: () => {} });
assert.equal(childWt.childThread, true);
assert.equal(childWt.PThread, undefined);
// 6. ThreadMessageHandler validates postMessage handler and exposes message handling methods
assert.throws(
() => new ThreadMessageHandler(),
{
name: 'TypeError',
message: 'options.postMessage is not a function'
}
);
const handler = new ThreadMessageHandler({ postMessage: () => {} });
assert.equal(typeof handler.handle, 'function');
assert.equal(typeof handler.instantiate, 'function');
// 7. ThreadManager initializes worker pool and tracks worker identifiers
const tm = new ThreadManager({ onCreateWorker: () => ({}) });
assert.deepEqual(tm.unusedWorkers, []);
assert.deepEqual(Object.keys(tm.pthreads), []);
assert.equal(typeof tm.nextWorkerID, 'number');
console.log('All @emnapi/wasi-threads contract assertions passed.');
오리진 시더
익명