CodeSampleX

Exemplo

collect-v8-coverage 1.0.3: collect v8 code coverage with CoverageInstrumenter

Amostra verificada para npm collect-v8-coverage 1.0.3: collect v8 code coverage with CoverageInstrumenter. O contrato rodou em node 22 · linux alpine/x64 …

sha256:8acf89122104e78542b76bca22e55abad4cfea3170d6808d9e5f6b8a6d5d6b72

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

Caso

HOW
Objetivo
collect v8 code coverage with CoverageInstrumenter
Pacotes
Símbolos
  • CoverageInstrumenter
Ambiente
node 22.23.2
Criado
2026-08-26T06:40:49Z

Contrato

  1. CoverageInstrumenter initializes with inspector session capabilities
  2. CoverageInstrumenter startInstrumenting connects inspector session and enables precise coverage
  3. CoverageInstrumenter stopInstrumenting returns script coverage array containing function ranges and invocation counts
  4. CoverageInstrumenter stopInstrumenting disables coverage tracking and profiler session

Arquivos

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

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: collect v8 code coverage with CoverageInstrumenter
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/collect-v8-coverage@1.0.3
Demonstrate these symbols/APIs:
  - CoverageInstrumenter

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:c74a49f0cc61223cdb1f38b5ed445fa09b525e1831d6a80b3e3ec417cfb30d1c","contract":["CoverageInstrumenter initializes with inspector session capabilities","CoverageInstrumenter startInstrumenting connects inspector session and enables precise coverage","CoverageInstrumenter stopInstrumenting returns script coverage array containing function ranges and invocation counts","CoverageInstrumenter stopInstrumenting disables coverage tracking and profiler session"],"goal":"collect v8 code coverage with CoverageInstrumenter","kind":"HOW","packages":["pkg:npm/collect-v8-coverage@1.0.3"],"schemaVersion":1,"symbols":["CoverageInstrumenter"]},"contractCommand":["node","test/contract.mjs"],"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/collect-v8-coverage@1.0.3"],"schemaVersion":1,"subject":"pkg:npm/collect-v8-coverage@1.0.3","symbols":["CoverageInstrumenter"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-collect-v8-coverage",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-collect-v8-coverage",
      "version": "1.0.0",
      "dependencies": {
        "collect-v8-coverage": "1.0.3"
      }
    },
    "node_modules/collect-v8-coverage": {
      "version": "1.0.3",
      "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.3.tgz",
      "integrity": "sha512-1L5aqIkwPfiodaMgQunkF1zRhNqifHBmtbbbxcr6yVxxBnliw4TDOW6NxpO8DJLgJ16OT+Y4ztZqP6p/FtXnAw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-collect-v8-coverage",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "collect-v8-coverage": "1.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "collect v8 code coverage with CoverageInstrumenter",
  "kind": "HOW",
  "packages": [
    "pkg:npm/collect-v8-coverage@1.0.3"
  ],
  "symbols": [
    "CoverageInstrumenter"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { CoverageInstrumenter } from 'collect-v8-coverage';

// 1. CoverageInstrumenter initializes with inspector session capabilities
{
  const instrumenter = new CoverageInstrumenter();
  assert.ok(instrumenter instanceof CoverageInstrumenter);
  assert.equal(typeof instrumenter.startInstrumenting, 'function');
  assert.equal(typeof instrumenter.stopInstrumenting, 'function');
}

// 2. CoverageInstrumenter startInstrumenting connects inspector session and enables precise coverage
// 3. CoverageInstrumenter stopInstrumenting returns script coverage array containing function ranges and invocation counts
{
  const instrumenter = new CoverageInstrumenter();
  await instrumenter.startInstrumenting();

  function sampleFunction(a, b) {
    if (a > b) {
      return a * 2;
    }
    return b * 2;
  }

  const result = sampleFunction(10, 5);
  assert.equal(result, 20);

  const coverage = await instrumenter.stopInstrumenting();
  assert.ok(Array.isArray(coverage));
  assert.ok(coverage.length > 0);

  for (const script of coverage) {
    assert.equal(typeof script.scriptId, 'string');
    assert.equal(typeof script.url, 'string');
    assert.ok(Array.isArray(script.functions));
    for (const fn of script.functions) {
      assert.equal(typeof fn.functionName, 'string');
      assert.ok(Array.isArray(fn.ranges));
      assert.equal(typeof fn.isBlockCoverage, 'boolean');
      for (const range of fn.ranges) {
        assert.equal(typeof range.startOffset, 'number');
        assert.equal(typeof range.endOffset, 'number');
        assert.equal(typeof range.count, 'number');
      }
    }
  }

  const contractCoverage = coverage.find(item => item.url && item.url.includes('contract.mjs'));
  assert.ok(contractCoverage, 'expected coverage to include contract.mjs');
  const targetFn = contractCoverage.functions.find(fn => fn.functionName === 'sampleFunction');
  assert.ok(targetFn, 'expected coverage to record sampleFunction');
  assert.ok(targetFn.ranges.length > 0);
  assert.equal(targetFn.ranges[0].count, 1);
}

// 4. CoverageInstrumenter stopInstrumenting disables coverage tracking and profiler session
{
  const instrumenter = new CoverageInstrumenter();
  await instrumenter.startInstrumenting();
  const coverage = await instrumenter.stopInstrumenting();
  assert.ok(Array.isArray(coverage));
}

console.log('Contract tests passed successfully.');

Seeder de origem

anônimo