CodeSampleX

Ejemplo

fast-uri 3.1.4: serialize

Muestra verificada para npm fast-uri 3.1.4: serialize. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: fastUri.serialize serializes…

sha256:81173c994bf36436208baf9b6aeb30e62354369848dffe49a8ff20c11d9b12c9

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-17

Caso

HOW
Objetivo
verify fast-uri.serialize in pkg:npm/fast-uri@3.1.4
Paquetes
Símbolos
  • fast-uri.serialize
Creado
2026-09-17T04:09:29Z

Contrato

  1. fastUri.serialize serializes complete URIComponent with scheme, host, port, path, query and fragment
  2. fastUri.serialize serializes minimal hierarchical URI components
  3. fastUri.serialize serializes relative URI references and query-only or fragment-only components
  4. fastUri.serialize formats IPv6 host references with brackets
  5. fastUri.serialize percent-encodes illegal path characters according to RFC 3986
  6. fastUri.serialize round-trips parsed URI strings through parse and serialize
  7. fastUri.serialize handles empty component by returning empty string

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 fast-uri.serialize in pkg:npm/fast-uri@3.1.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fast-uri@3.1.4
Demonstrate these symbols/APIs:
  - fast-uri.serialize

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:c2801b6c49607e20fcfad9042979edbef7ccce0acb2a9fb1aef5f184b1e951a7","contract":["fastUri.serialize serializes complete URIComponent with scheme, host, port, path, query and fragment","fastUri.serialize serializes minimal hierarchical URI components","fastUri.serialize serializes relative URI references and query-only or fragment-only components","fastUri.serialize formats IPv6 host references with brackets","fastUri.serialize percent-encodes illegal path characters according to RFC 3986","fastUri.serialize round-trips parsed URI strings through parse and serialize","fastUri.serialize handles empty component by returning empty string"],"goal":"verify fast-uri.serialize in pkg:npm/fast-uri@3.1.4","kind":"HOW","packages":["pkg:npm/fast-uri@3.1.4"],"schemaVersion":1,"symbols":["fast-uri.serialize"]},"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/fast-uri@3.1.4"],"schemaVersion":1,"subject":"pkg:npm/fast-uri@3.1.4","symbols":["fast-uri.serialize"],"verifierAdapter":"node-typescript@1"}
index.js
const fastUri = require('fast-uri');

/**
 * Serializes a parsed URIComponent object into an RFC 3986 URI string.
 *
 * @param {Object} component - Parsed URI component object.
 * @param {Object} [options] - Optional serialization options.
 * @returns {string} The serialized URI string.
 */
function serializeUri(component, options) {
  return fastUri.serialize(component, options);
}

module.exports = {
  serializeUri,
  serialize: fastUri.serialize,
  fastUri,
};
package-lock.json
{
  "name": "fast-uri-serialize-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "fast-uri-serialize-verification",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "fast-uri": "3.1.4"
      }
    },
    "node_modules/fast-uri": {
      "version": "3.1.4",
      "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.4.tgz",
      "integrity": "sha512-8JnbkQ4juDyvYs4mgFGQqg4yCYtFDtUtmp2QIQq11ZZe5CFQ5wcqm1rqDgAh/QdMySuBnPzMUiJUNZG5N/AiQw==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/fastify"
        },
        {
          "type": "opencollective",
          "url": "https://opencollective.com/fastify"
        }
      ],
      "license": "BSD-3-Clause"
    }
  }
}
package.json
{
  "name": "fast-uri-serialize-verification",
  "version": "1.0.0",
  "description": "Clean-room verification of fast-uri.serialize in pkg:npm/fast-uri@3.1.4",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "fast-uri": "3.1.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify fast-uri.serialize in pkg:npm/fast-uri@3.1.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fast-uri@3.1.4"
  ],
  "symbols": [
    "fast-uri.serialize"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import fastUri from 'fast-uri';
import { serializeUri, serialize } from '../index.js';

// 1. fastUri.serialize serializes complete URIComponent with scheme, host, port, path, query and fragment
const fullUri = fastUri.serialize({
  scheme: 'https',
  host: 'example.com',
  port: 8080,
  path: '/api/v1/resource',
  query: 'key=value&foo=bar',
  fragment: 'section1'
});
assert.strictEqual(
  fullUri,
  'https://example.com:8080/api/v1/resource?key=value&foo=bar#section1',
  'fastUri.serialize serializes complete URIComponent with scheme, host, port, path, query and fragment'
);
assert.strictEqual(
  serializeUri({
    scheme: 'https',
    host: 'example.com',
    port: 8080,
    path: '/api/v1/resource',
    query: 'key=value&foo=bar',
    fragment: 'section1'
  }),
  fullUri
);

// 2. fastUri.serialize serializes minimal hierarchical URI components
const minimalUri = fastUri.serialize({
  scheme: 'http',
  host: 'example.com',
  path: '/test'
});
assert.strictEqual(
  minimalUri,
  'http://example.com/test',
  'fastUri.serialize serializes minimal hierarchical URI components'
);

// 3. fastUri.serialize serializes relative URI references and query-only or fragment-only components
const relUri = fastUri.serialize({ path: 'foo/bar' });
assert.strictEqual(
  relUri,
  'foo/bar',
  'fastUri.serialize serializes relative URI references'
);

const queryFrag = fastUri.serialize({ query: 'q=search', fragment: 'top' });
assert.strictEqual(
  queryFrag,
  '?q=search#top',
  'fastUri.serialize serializes query-only or fragment-only components'
);

// 4. fastUri.serialize formats IPv6 host references with brackets
const ipv6Uri = fastUri.serialize({ scheme: 'http', host: '::1', port: 8080, path: '/' });
assert.strictEqual(
  ipv6Uri,
  'http://[::1]:8080/',
  'fastUri.serialize formats IPv6 host references with brackets'
);

// 5. fastUri.serialize percent-encodes illegal path characters according to RFC 3986
const encodedUri = fastUri.serialize({ scheme: 'http', host: 'example.com', path: '/hello world' });
assert.strictEqual(
  encodedUri,
  'http://example.com/hello%20world',
  'fastUri.serialize percent-encodes illegal path characters according to RFC 3986'
);

// 6. fastUri.serialize round-trips parsed URI strings through parse and serialize
const original = 'https://example.com:8443/items?limit=10#details';
const roundTrip = fastUri.serialize(fastUri.parse(original));
assert.strictEqual(
  roundTrip,
  original,
  'fastUri.serialize round-trips parsed URI strings through parse and serialize'
);

// 7. fastUri.serialize handles empty component by returning empty string
assert.strictEqual(
  fastUri.serialize({}),
  '',
  'fastUri.serialize handles empty component by returning empty string'
);

console.log('Contract passed');

Seeder de origen

anónimo