CodeSampleX

Пример

react-refresh 0.17.0: hasUnrecoverableErrors

Проверенный пример — npm react-refresh 0.17.0: hasUnrecoverableErrors. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.

sha256:3588ea779a92d3b285a825aabf650a6f190c82f7ce1325ffe76251126e182c9c

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-05

Кейс

HOW
Цель
verify react-refresh.hasUnrecoverableErrors in pkg:npm/react-refresh@0.17.0
Пакеты
Символы
  • react-refresh.hasUnrecoverableErrors
Окружение
node 22.23.2
Создан
2026-09-05T01:31:22Z

Контракт

  1. hasUnrecoverableErrors returns false initially when no errors have occurred
  2. hasUnrecoverableErrors returns false after registering component types
  3. hasUnrecoverableErrors returns false after performing refresh cycle with performReactRefresh
  4. hasUnrecoverableErrors returns false when invoked repeatedly across multiple calls
  5. hasUnrecoverableErrors returns false and does not throw when invoked with arbitrary arguments

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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

Use EXACTLY these public packages and versions:
  - pkg:npm/react-refresh@0.17.0
Demonstrate these symbols/APIs:
  - react-refresh.hasUnrecoverableErrors
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:19b4bdc69ff3a63d6f6201fd33e41583ba8d0a1636bb6db2c88e12a503aa3874","constraints":{"executionContext":"node"},"contract":["hasUnrecoverableErrors returns false initially when no errors have occurred","hasUnrecoverableErrors returns false after registering component types","hasUnrecoverableErrors returns false after performing refresh cycle with performReactRefresh","hasUnrecoverableErrors returns false when invoked repeatedly across multiple calls","hasUnrecoverableErrors returns false and does not throw when invoked with arbitrary arguments"],"goal":"verify react-refresh.hasUnrecoverableErrors in pkg:npm/react-refresh@0.17.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.17.0"],"schemaVersion":1,"symbols":["react-refresh.hasUnrecoverableErrors"]},"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/react-refresh@0.17.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.17.0","symbols":["react-refresh.hasUnrecoverableErrors"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-refresh-has-unrecoverable-errors",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-refresh-has-unrecoverable-errors",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react-refresh": "0.17.0"
      }
    },
    "node_modules/react-refresh": {
      "version": "0.17.0",
      "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
      "integrity": "sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-refresh-has-unrecoverable-errors",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "react-refresh": "0.17.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh.hasUnrecoverableErrors in pkg:npm/react-refresh@0.17.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.17.0"
  ],
  "symbols": [
    "react-refresh.hasUnrecoverableErrors"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import refreshRuntimeModule from "react-refresh/runtime";

export const RefreshRuntime =
  refreshRuntimeModule && typeof refreshRuntimeModule === "object" && "default" in refreshRuntimeModule
    ? refreshRuntimeModule.default
    : refreshRuntimeModule;

/**
 * Checks whether Fast Refresh runtime has encountered unrecoverable errors.
 *
 * @param {...any} args - Optional arguments passed to the check function.
 * @returns {boolean} False when the runtime has no unrecoverable errors.
 */
export function hasUnrecoverableErrors(...args) {
  return RefreshRuntime.hasUnrecoverableErrors(...args);
}

/**
 * Registers a component type with a persistent identifier for Fast Refresh.
 *
 * @param {any} type - The component function or object
 * @param {string} id - Persistent identifier for the component family
 */
export function register(type, id) {
  RefreshRuntime.register(type, id);
}

/**
 * Triggers a Fast Refresh cycle across registered components and renderers.
 *
 * @returns {object|null} Refresh cycle result or null if nothing was refreshed
 */
export function performReactRefresh() {
  return RefreshRuntime.performReactRefresh();
}
test/contract.mjs
import assert from "node:assert/strict";
import refreshRuntimeModule from "react-refresh/runtime";
import {
  RefreshRuntime,
  hasUnrecoverableErrors,
  register,
  performReactRefresh
} from "../src/index.mjs";

const rawRuntime =
  refreshRuntimeModule && typeof refreshRuntimeModule === "object" && "default" in refreshRuntimeModule
    ? refreshRuntimeModule.default
    : refreshRuntimeModule;

// Contract 1: hasUnrecoverableErrors returns false initially when no errors have occurred
{
  assert.equal(typeof hasUnrecoverableErrors(), "boolean");
  assert.equal(hasUnrecoverableErrors(), false);
  assert.equal(typeof rawRuntime.hasUnrecoverableErrors, "function");
  assert.equal(rawRuntime.hasUnrecoverableErrors(), false);
}

// Contract 2: hasUnrecoverableErrors returns false after registering component types
{
  function HeaderComponent() {
    return "Header";
  }
  register(HeaderComponent, "HeaderId");
  assert.equal(hasUnrecoverableErrors(), false);
  assert.equal(rawRuntime.hasUnrecoverableErrors(), false);
}

// Contract 3: hasUnrecoverableErrors returns false after performing refresh cycle with performReactRefresh
{
  performReactRefresh();
  assert.equal(hasUnrecoverableErrors(), false);
  assert.equal(rawRuntime.hasUnrecoverableErrors(), false);
}

// Contract 4: hasUnrecoverableErrors returns false when invoked repeatedly across multiple calls
{
  for (let i = 0; i < 5; i++) {
    assert.equal(hasUnrecoverableErrors(), false);
    assert.equal(rawRuntime.hasUnrecoverableErrors(), false);
  }
}

// Contract 5: hasUnrecoverableErrors returns false and does not throw when invoked with arbitrary arguments
{
  assert.equal(hasUnrecoverableErrors(null), false);
  assert.equal(hasUnrecoverableErrors(undefined), false);
  assert.equal(hasUnrecoverableErrors(new Error("simulated runtime error")), false);
  assert.equal(hasUnrecoverableErrors("unexpected string", 123), false);
  assert.equal(hasUnrecoverableErrors({ error: true }), false);
  assert.equal(rawRuntime.hasUnrecoverableErrors(new Error("raw test")), false);
}

console.log("All react-refresh.hasUnrecoverableErrors contract tests passed successfully.");

Исходный сидер

аноним