Ejemplo
bare-buffer 3.7.0: Buffer.prototype.writeFloatBE
Muestra verificada para npm bare-buffer 3.7.0: Buffer.prototype.writeFloatBE. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.
sha256:1a1460e6b385d34a0ccee794c0b0fafb57c76c05dc27d0bbd790da959fee7dce
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify Buffer.prototype.writeFloatBE in pkg:npm/bare-buffer@3.7.0
- Paquetes
- Símbolos
-
- Buffer.prototype.writeFloatBE
- Creado
- 2026-08-27T05:42:14Z
Contrato
- package manifest defines exports for root, global, constants, and package subpaths with addon configuration and Bare engine >=1.20.0
- index.d.ts declares writeFloatBE method on Buffer taking value and optional offset and returning next byte offset
- Buffer.prototype.writeFloatBE writes 32-bit big-endian IEEE 754 float values including zero, signed zero, positive, negative, and special float values
- Buffer.prototype.writeFloatBE returns next byte offset (offset + 4) and defaults offset to 0 when omitted
- Buffer.prototype.writeFloatBE throws TypeError for non-number offset and RangeError for non-integer or out-of-bounds offsets
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código fuente
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 Buffer.prototype.writeFloatBE in pkg:npm/bare-buffer@3.7.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/bare-buffer@3.7.0
Demonstrate these symbols/APIs:
- Buffer.prototype.writeFloatBE
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:86a75aa5ba364c2da968e49dd9f9de548d31efe990f2a8522b0c53d841050124","contract":["package manifest defines exports for root, global, constants, and package subpaths with addon configuration and Bare engine \u003e=1.20.0","index.d.ts declares writeFloatBE method on Buffer taking value and optional offset and returning next byte offset","Buffer.prototype.writeFloatBE writes 32-bit big-endian IEEE 754 float values including zero, signed zero, positive, negative, and special float values","Buffer.prototype.writeFloatBE returns next byte offset (offset + 4) and defaults offset to 0 when omitted","Buffer.prototype.writeFloatBE throws TypeError for non-number offset and RangeError for non-integer or out-of-bounds offsets"],"goal":"verify Buffer.prototype.writeFloatBE in pkg:npm/bare-buffer@3.7.0","kind":"HOW","packages":["pkg:npm/bare-buffer@3.7.0"],"schemaVersion":1,"symbols":["Buffer.prototype.writeFloatBE"]},"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-buffer@3.7.0"],"schemaVersion":1,"subject":"pkg:npm/bare-buffer@3.7.0","symbols":["Buffer.prototype.writeFloatBE"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-bare-buffer",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-buffer",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"bare-buffer": "3.7.0"
}
},
"node_modules/bare-buffer": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/bare-buffer/-/bare-buffer-3.7.0.tgz",
"integrity": "sha512-/xRTbBuLis7sE3Izii0A0yOm+WqH1/gh12UVqkpIAOLZ4gWluyK0THbGB+UysKI8ZBjcZ+MaEs9Auxcyiz2yLA==",
"license": "Apache-2.0",
"engines": {
"bare": ">=1.20.0"
}
}
}
}
{
"name": "sample-bare-buffer",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"bare-buffer": "3.7.0"
}
}
{
"schemaVersion": 1,
"goal": "verify Buffer.prototype.writeFloatBE in pkg:npm/bare-buffer@3.7.0",
"kind": "HOW",
"packages": [
"pkg:npm/bare-buffer@3.7.0"
],
"symbols": [
"Buffer.prototype.writeFloatBE"
]
}
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-buffer package manifest and verify exports and metadata
const pkgPath = require.resolve('bare-buffer/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
assert.equal(pkg.name, 'bare-buffer', 'Package name must be bare-buffer');
assert.equal(pkg.version, '3.7.0', 'Package version must be 3.7.0');
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.20.0', 'Package must specify Bare engine >=1.20.0');
assert.ok(pkg.exports, 'Package must define exports');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must declare index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must declare index.js default');
assert.equal(pkg.exports['./global'].types, './global.d.ts', 'Global export must declare global.d.ts types');
assert.equal(pkg.exports['./global'].default, './global.js', 'Global export must declare global.js default');
assert.equal(pkg.exports['./constants'].types, './lib/constants.d.ts', 'Constants export must declare constants.d.ts types');
assert.equal(pkg.exports['./constants'].default, './lib/constants.js', 'Constants export must declare constants.js default');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to package.json');
const pkgDir = path.dirname(pkgPath);
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
// Verify TypeScript declaration for Buffer.prototype.writeFloatBE
assert.ok(
indexDts.includes('writeFloatBE(value: number, offset?: number): number'),
'index.d.ts must declare writeFloatBE(value: number, offset?: number): number'
);
// 2. Setup binding mock in require.cache to instantiate and execute Bare Buffer methods under Node
const bindingPath = path.join(pkgDir, 'binding.js');
require.cache[bindingPath] = {
id: bindingPath,
filename: bindingPath,
loaded: true,
exports: {
constants: {
MAX_LENGTH: 2147483647,
MAX_STRING_LENGTH: 536870888
},
alloc(size) { return new ArrayBuffer(size); },
allocUnsafe(size) { return new ArrayBuffer(size); },
compare() { return 0; },
swap16() {},
swap32() {},
swap64() {},
indexOf() { return -1; },
lastIndexOf() { return -1; }
}
};
const Buffer = require('bare-buffer');
// 3. Verify Buffer.prototype.writeFloatBE existence and interface
assert.equal(typeof Buffer.prototype.writeFloatBE, 'function', 'Buffer.prototype.writeFloatBE must be a function');
assert.equal(Buffer.prototype.writeFloatBE.length, 1, 'writeFloatBE should have parameter length 1 (with default offset)');
// 4. Verify IEEE 754 32-bit big-endian float binary encoding
const buffer = new Buffer(16);
// Test 0.0 -> [0x00, 0x00, 0x00, 0x00]
let nextOffset = buffer.writeFloatBE(0.0, 0);
assert.equal(nextOffset, 4, 'writeFloatBE must return offset + 4');
assert.deepEqual(Array.from(buffer.subarray(0, 4)), [0x00, 0x00, 0x00, 0x00]);
assert.equal(buffer.readFloatBE(0), 0.0);
// Test -0.0 -> [0x80, 0x00, 0x00, 0x00]
nextOffset = buffer.writeFloatBE(-0.0, 4);
assert.equal(nextOffset, 8, 'writeFloatBE must return offset + 4');
assert.deepEqual(Array.from(buffer.subarray(4, 8)), [0x80, 0x00, 0x00, 0x00]);
assert.ok(Object.is(buffer.readFloatBE(4), -0.0));
// Test 1.0 -> [0x3f, 0x80, 0x00, 0x00]
nextOffset = buffer.writeFloatBE(1.0, 8);
assert.equal(nextOffset, 12, 'writeFloatBE must return offset + 4');
assert.deepEqual(Array.from(buffer.subarray(8, 12)), [0x3f, 0x80, 0x00, 0x00]);
assert.equal(buffer.readFloatBE(8), 1.0);
// Test -1.0 -> [0xbf, 0x80, 0x00, 0x00]
nextOffset = buffer.writeFloatBE(-1.0, 12);
assert.equal(nextOffset, 16, 'writeFloatBE must return offset + 4');
assert.deepEqual(Array.from(buffer.subarray(12, 16)), [0xbf, 0x80, 0x00, 0x00]);
assert.equal(buffer.readFloatBE(12), -1.0);
// 5. Test default offset parameter (offset defaults to 0)
const defaultBuf = new Buffer(8);
const ret = defaultBuf.writeFloatBE(1.0);
assert.equal(ret, 4, 'writeFloatBE with default offset must return 4');
assert.deepEqual(Array.from(defaultBuf.subarray(0, 4)), [0x3f, 0x80, 0x00, 0x00]);
// 6. Test special float values: Infinity, -Infinity, NaN
const specialBuf = new Buffer(12);
specialBuf.writeFloatBE(Infinity, 0);
assert.deepEqual(Array.from(specialBuf.subarray(0, 4)), [0x7f, 0x80, 0x00, 0x00]);
assert.equal(specialBuf.readFloatBE(0), Infinity);
specialBuf.writeFloatBE(-Infinity, 4);
assert.deepEqual(Array.from(specialBuf.subarray(4, 8)), [0xff, 0x80, 0x00, 0x00]);
assert.equal(specialBuf.readFloatBE(4), -Infinity);
specialBuf.writeFloatBE(NaN, 8);
assert.ok(Number.isNaN(specialBuf.readFloatBE(8)));
// 7. Test sequential writing with offset chaining
const seqBuf = new Buffer(8);
let pos = 0;
pos = seqBuf.writeFloatBE(10.5, pos);
assert.equal(pos, 4);
pos = seqBuf.writeFloatBE(20.25, pos);
assert.equal(pos, 8);
assert.equal(seqBuf.readFloatBE(0), 10.5);
assert.equal(seqBuf.readFloatBE(4), 20.25);
// 8. Test error handling on invalid offset types and out of bounds
const errBuf = new Buffer(4);
// Non-number offset should throw TypeError
assert.throws(
() => errBuf.writeFloatBE(1.0, '0'),
{ name: 'TypeError' }
);
assert.throws(
() => errBuf.writeFloatBE(1.0, null),
{ name: 'TypeError' }
);
// Non-integer offset should throw RangeError
assert.throws(
() => errBuf.writeFloatBE(1.0, 1.5),
{ name: 'RangeError' }
);
// Out of bounds offset should throw RangeError
assert.throws(
() => errBuf.writeFloatBE(1.0, -1),
{ name: 'RangeError' }
);
assert.throws(
() => errBuf.writeFloatBE(1.0, 1),
{ name: 'RangeError' }
);
assert.throws(
() => errBuf.writeFloatBE(1.0, 5),
{ name: 'RangeError' }
);
console.log('Contract tests passed successfully.');
Seeder de origen
anónimo