CodeSampleX

Exemplo

uuid 8.3.2: stringify

Amostra verificada para npm uuid 8.3.2: stringify. O contrato rodou em node 22 · linux debian/x64 · docker e passou: uuid.stringify formats 16 valid RFC 4122…

sha256:89b6bd9236abbb575fd0232d2169ad5fb98d1d7440a47431697ea72996da1a69

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-11-22

Caso

HOW
Objetivo
verify uuid.stringify in pkg:npm/uuid@8.3.2
Pacotes
Símbolos
  • uuid.stringify
Ambiente
node 22.23.2
Criado
2026-11-22T16:16:09Z

Contrato

  1. uuid.stringify formats 16 valid RFC 4122 v1-v5 UUID bytes from Uint8Array, Buffer, or plain Array into a lowercase hyphenated UUID string
  2. uuid.stringify(arr, offset) reads 16 bytes starting at the given offset within a larger buffer
  3. uuid.stringify accepts 16 zero bytes and returns the NIL UUID 00000000-0000-0000-0000-000000000000
  4. uuid.stringify validates the output in uuid@8.3.2 and throws TypeError('Stringified UUID is invalid') for unsupported version/variant bits (such as version 7 or all-0xff bytes), buffers with fewer than 16 bytes from offset, or out-of-range byte values

Arquivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 uuid.stringify in pkg:npm/uuid@8.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/uuid@8.3.2
Demonstrate these symbols/APIs:
  - uuid.stringify
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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.
csx.json
{"case":{"caseId":"case:sha256:9d7f51b3bab803a9a359760da2c6dcabe99e8a2885bf4d2573de75569323af06","constraints":{"executionContext":"node"},"contract":["uuid.stringify formats 16 valid RFC 4122 v1-v5 UUID bytes from Uint8Array, Buffer, or plain Array into a lowercase hyphenated UUID string","uuid.stringify(arr, offset) reads 16 bytes starting at the given offset within a larger buffer","uuid.stringify accepts 16 zero bytes and returns the NIL UUID 00000000-0000-0000-0000-000000000000","uuid.stringify validates the output in uuid@8.3.2 and throws TypeError('Stringified UUID is invalid') for unsupported version/variant bits (such as version 7 or all-0xff bytes), buffers with fewer than 16 bytes from offset, or out-of-range byte values"],"goal":"verify uuid.stringify in pkg:npm/uuid@8.3.2","kind":"HOW","packages":["pkg:npm/uuid@8.3.2"],"schemaVersion":1,"symbols":["uuid.stringify"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/uuid@8.3.2"],"schemaVersion":1,"subject":"pkg:npm/uuid@8.3.2","symbols":["uuid.stringify"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "uuid-stringify-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "uuid-stringify-sample",
      "version": "1.0.0",
      "dependencies": {
        "uuid": "8.3.2"
      }
    },
    "node_modules/uuid": {
      "version": "8.3.2",
      "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
      "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
      "deprecated": "uuid@10 and below is no longer supported.  For ESM codebases, update to uuid@latest.  For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).",
      "license": "MIT",
      "bin": {
        "uuid": "dist/bin/uuid"
      }
    }
  }
}
package.json
{
  "name": "uuid-stringify-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Verify uuid.stringify in pkg:npm/uuid@8.3.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "uuid": "8.3.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify uuid.stringify in pkg:npm/uuid@8.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/uuid@8.3.2"
  ],
  "symbols": [
    "uuid.stringify"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const { stringify } = require('uuid');

/**
 * Format 16 bytes starting at `offset` into a canonical lowercase UUID string
 * using `uuid.stringify` from `uuid@8.3.2`.
 */
function formatUuidBytes(bytes, offset = 0) {
  return stringify(bytes, offset);
}

module.exports = {
  formatUuidBytes,
};
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const uuid = require('uuid');
const { formatUuidBytes } = require('../src/index.js');

// Canonical RFC 4122 v4 UUID bytes: 6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b
const v4Bytes = [
  0x6e, 0xc0, 0xbd, 0x7f,
  0x11, 0xc0,
  0x43, 0xda,
  0x97, 0x5e,
  0x2a, 0x8a, 0xd9, 0xeb, 0xae, 0x0b,
];
const expectedV4 = '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b';

// 1. Direct Uint8Array, Buffer, and plain Array inputs
assert.equal(uuid.stringify(Uint8Array.from(v4Bytes)), expectedV4);
assert.equal(uuid.stringify(Buffer.from(v4Bytes)), expectedV4);
assert.equal(formatUuidBytes(v4Bytes), expectedV4);

// 2. Reading 16 bytes from a non-zero offset inside a larger Uint8Array
const padded = Uint8Array.from([0xaa, 0xbb, 0xcc, ...v4Bytes, 0xdd]);
assert.equal(uuid.stringify(padded, 3), expectedV4);
assert.equal(formatUuidBytes(padded, 3), expectedV4);

// 3. NIL UUID (16 zero bytes) is accepted by uuid@8.3.2
assert.equal(
  uuid.stringify(new Uint8Array(16)),
  '00000000-0000-0000-0000-000000000000',
);

// 4. Invalid RFC 4122 version/variant bytes throw TypeError in uuid@8.3.2
// (uuid@8.3.2 validates strictly against versions 1-5 and variant [89ab], or NIL)
const invalidVersionBytes = Uint8Array.from(v4Bytes);
invalidVersionBytes[6] = 0x73; // version 7 is not accepted in uuid@8.3.2
assert.throws(
  () => uuid.stringify(invalidVersionBytes),
  { name: 'TypeError', message: 'Stringified UUID is invalid' },
);

const allFF = new Uint8Array(16).fill(0xff);
assert.throws(
  () => uuid.stringify(allFF),
  { name: 'TypeError', message: 'Stringified UUID is invalid' },
);

// 5. Fewer than 16 bytes remaining from offset throws TypeError
assert.throws(
  () => uuid.stringify(Uint8Array.from(v4Bytes.slice(0, 15))),
  { name: 'TypeError', message: 'Stringified UUID is invalid' },
);
assert.throws(
  () => uuid.stringify(padded, 5),
  { name: 'TypeError', message: 'Stringified UUID is invalid' },
);

// 6. Out-of-range byte value in plain Array throws TypeError
const outOfRange = [...v4Bytes];
outOfRange[0] = 256;
assert.throws(
  () => uuid.stringify(outOfRange),
  { name: 'TypeError', message: 'Stringified UUID is invalid' },
);

console.log('uuid.stringify contract passed');

Seeder de origem

anônimo