CodeSampleX

Exemplo

react-refresh 0.18.0: react-refresh

Amostra verificada para npm react-refresh 0.18.0: react-refresh. O contrato rodou em node 22 · linux debian/x64 · docker e passou.

sha256:0095c8e0a004d11ab1bc766033f7f9861323829ab560501aaaaa1b1ad60f523d

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-09-01

Caso

HOW
Objetivo
verify react-refresh in pkg:npm/react-refresh@0.18.0
Pacotes
Símbolos
  • react-refresh
Ambiente
node 22.23.2
Criado
2026-09-01T11:20:08Z

Contrato

  1. isLikelyComponentType returns true for component functions with uppercase names, React.forwardRef, and React.memo objects
  2. isLikelyComponentType returns false for helper functions with lowercase names, primitives, and plain objects
  3. register assigns a component to a family by unique ID, retrievable via getFamilyByID and getFamilyByType
  4. performReactRefresh applies pending updates to component families and tracks updated families
  5. createSignatureFunctionForTransform creates signature helper for hook tracking and hasUnrecoverableErrors returns false

Arquivos

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

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 react-refresh in pkg:npm/react-refresh@0.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-refresh@0.18.0
Demonstrate these symbols/APIs:
  - react-refresh
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:feffc064e5a7fc6498c434560a314baea762def7311b26d9a893ba76d05436af","constraints":{"executionContext":"node"},"contract":["isLikelyComponentType returns true for component functions with uppercase names, React.forwardRef, and React.memo objects","isLikelyComponentType returns false for helper functions with lowercase names, primitives, and plain objects","register assigns a component to a family by unique ID, retrievable via getFamilyByID and getFamilyByType","performReactRefresh applies pending updates to component families and tracks updated families","createSignatureFunctionForTransform creates signature helper for hook tracking and hasUnrecoverableErrors returns false"],"goal":"verify react-refresh in pkg:npm/react-refresh@0.18.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.18.0"],"schemaVersion":1,"symbols":["react-refresh"]},"contractCommand":["node","test/contract.cjs"],"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/react-refresh@0.18.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.18.0","symbols":["react-refresh"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-refresh",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-refresh",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react-refresh": "0.18.0"
      }
    },
    "node_modules/react-refresh": {
      "version": "0.18.0",
      "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.18.0.tgz",
      "integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-refresh",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "react-refresh": "0.18.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh in pkg:npm/react-refresh@0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.18.0"
  ],
  "symbols": [
    "react-refresh"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const Refresh = require('react-refresh');

function isLikelyComponent(type) {
  return Refresh.isLikelyComponentType(type);
}

function registerComponent(type, id) {
  Refresh.register(type, id);
}

function getFamilyByID(id) {
  return Refresh.getFamilyByID(id);
}

function getFamilyByType(type) {
  return Refresh.getFamilyByType(type);
}

function performRefresh() {
  return Refresh.performReactRefresh();
}

function createSignature() {
  return Refresh.createSignatureFunctionForTransform();
}

function hasErrors() {
  return Refresh.hasUnrecoverableErrors();
}

module.exports = {
  Refresh,
  isLikelyComponent,
  registerComponent,
  getFamilyByID,
  getFamilyByType,
  performRefresh,
  createSignature,
  hasErrors
};
test/contract.cjs
const assert = require('node:assert/strict');
const Refresh = require('react-refresh');
const {
  isLikelyComponent,
  registerComponent,
  getFamilyByID,
  getFamilyByType,
  performRefresh,
  createSignature,
  hasErrors
} = require('../src/index.js');

// 1. Verify component type detection
function HeaderComponent() {
  return 'header';
}

function helperFunction() {
  return 'helper';
}

const forwardRefComponent = {
  $$typeof: Symbol.for('react.forward_ref'),
  render: HeaderComponent
};

const memoComponent = {
  $$typeof: Symbol.for('react.memo'),
  type: HeaderComponent
};

assert.equal(
  isLikelyComponent(HeaderComponent),
  true,
  'Functions with uppercase names should be recognized as components'
);
assert.equal(
  isLikelyComponent(forwardRefComponent),
  true,
  'React forwardRef objects should be recognized as components'
);
assert.equal(
  isLikelyComponent(memoComponent),
  true,
  'React memo objects should be recognized as components'
);

assert.equal(
  isLikelyComponent(helperFunction),
  false,
  'Functions with lowercase names should not be recognized as components'
);
assert.equal(
  isLikelyComponent(null),
  false,
  'null should not be recognized as component'
);
assert.equal(
  isLikelyComponent(undefined),
  false,
  'undefined should not be recognized as component'
);
assert.equal(
  isLikelyComponent({}),
  false,
  'Plain objects should not be recognized as components'
);

// 2. Verify component registration and family retrieval
const componentId = 'src/components/Header.js %exports% HeaderComponent';
registerComponent(HeaderComponent, componentId);

const familyFromId = getFamilyByID(componentId);
assert.ok(familyFromId, 'Family should exist for registered component ID');
assert.equal(
  familyFromId.current,
  HeaderComponent,
  'Family current type should match registered component'
);

const familyFromType = getFamilyByType(HeaderComponent);
assert.equal(
  familyFromType,
  familyFromId,
  'getFamilyByType should return the same family reference as getFamilyByID'
);

// 3. Verify hot reload replacement with performRefresh
function HeaderComponentV2() {
  return 'header v2';
}

registerComponent(HeaderComponentV2, componentId);

// Before performRefresh, family.current is still original component
assert.equal(
  familyFromId.current,
  HeaderComponent,
  'family.current should not change before performRefresh'
);

const refreshResult = performRefresh();
assert.ok(refreshResult, 'performRefresh should return update result');
assert.equal(
  familyFromId.current,
  HeaderComponentV2,
  'family.current should update to new component after performRefresh'
);
assert.equal(
  refreshResult.updatedFamilies.has(familyFromId),
  true,
  'updatedFamilies should contain updated component family'
);

// 4. Verify signature function for transform and error state
const sig = createSignature();
assert.equal(
  typeof sig,
  'function',
  'createSignature should return a transform helper function'
);

function CounterComponent() {
  return 0;
}
sig(CounterComponent, 'useState{[count, setCount](0)}');
sig();

assert.equal(
  isLikelyComponent(CounterComponent),
  true,
  'Signature-wrapped component remains a likely component'
);
assert.equal(
  hasErrors(),
  false,
  'hasUnrecoverableErrors should return false'
);

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

Seeder de origem

anônimo