CodeSampleX

Пример

react-is 17.0.2: Portal

Проверенный пример — npm react-is 17.0.2: Portal. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: Portal is exported as a symbol matching…

sha256:6b83b8ef9c6a3c10d2c28f4abf701d06c6c7668ac6c6acf559c02ead1046ea5a

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

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

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

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

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

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

Кейс

HOW
Цель
verify react-is.Portal in pkg:npm/react-is@17.0.2
Пакеты
Символы
  • react-is.Portal
Создан
2026-09-06T09:31:36Z

Контракт

  1. Portal is exported as a symbol matching Symbol.for('react.portal')
  2. Portal represents the $$typeof identifier used for React portal objects
  3. isPortal returns true for objects with $$typeof equal to Portal
  4. typeOf returns Portal for React portal objects and distinguishes them from non-portals or other React types

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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-is.Portal in pkg:npm/react-is@17.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-is@17.0.2
Demonstrate these symbols/APIs:
  - react-is.Portal

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:905fa0dcff18155c975e9cd28fde18385439b479c9ce7ca67d85ca09a5df8de5","contract":["Portal is exported as a symbol matching Symbol.for('react.portal')","Portal represents the $$typeof identifier used for React portal objects","isPortal returns true for objects with $$typeof equal to Portal","typeOf returns Portal for React portal objects and distinguishes them from non-portals or other React types"],"goal":"verify react-is.Portal in pkg:npm/react-is@17.0.2","kind":"HOW","packages":["pkg:npm/react-is@17.0.2"],"schemaVersion":1,"symbols":["react-is.Portal"]},"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/react-is@17.0.2"],"schemaVersion":1,"subject":"pkg:npm/react-is@17.0.2","symbols":["react-is.Portal"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-portal",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-portal",
      "version": "1.0.0",
      "dependencies": {
        "react-is": "17.0.2"
      }
    },
    "node_modules/react-is": {
      "version": "17.0.2",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
      "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-portal",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is.Portal in react-is 17.0.2",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "17.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.Portal in pkg:npm/react-is@17.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@17.0.2"
  ],
  "symbols": [
    "react-is.Portal"
  ]
}
src/index.js
import { Portal, isPortal, typeOf } from 'react-is';

/**
 * Return the Portal symbol exported by react-is.
 *
 * @returns {symbol} The React portal identifier symbol.
 */
export function getPortalSymbol() {
  return Portal;
}

/**
 * Check if the provided symbol matches react-is Portal.
 *
 * @param {*} sym - Symbol or value to compare.
 * @returns {boolean} True if matching react-is Portal.
 */
export function isMatchingPortalSymbol(sym) {
  return sym === Portal;
}

/**
 * Create a mock React portal object tagged with the Portal symbol.
 *
 * @param {*} children - Portal child elements.
 * @param {*} containerInfo - Target DOM node or container representation.
 * @param {string|null} key - Optional key for the portal.
 * @returns {object} Object with $$typeof set to Portal.
 */
export function createPortalDescriptor(children = [], containerInfo = {}, key = null) {
  return {
    $$typeof: Portal,
    key: key == null ? null : String(key),
    children,
    containerInfo,
    implementation: null,
  };
}

/**
 * Verify whether an object is recognized as a React portal.
 *
 * @param {*} value - The value to inspect.
 * @returns {boolean} True if the value is a React portal.
 */
export function checkIsPortal(value) {
  return isPortal(value);
}

/**
 * Identify whether the typeOf helper resolves the value to the Portal symbol.
 *
 * @param {*} value - The value to inspect.
 * @returns {boolean} True if typeOf(value) === Portal.
 */
export function isPortalTypeOf(value) {
  return typeOf(value) === Portal;
}

export { Portal, isPortal, typeOf };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Portal,
  isPortal,
  typeOf,
  getPortalSymbol,
  isMatchingPortalSymbol,
  createPortalDescriptor,
  checkIsPortal,
  isPortalTypeOf,
} from '../src/index.js';

// 1. Portal export assertion
assert.equal(typeof Portal, 'symbol', 'Portal must be exported as a symbol');
assert.equal(Portal, Symbol.for('react.portal'), 'Portal must equal Symbol.for("react.portal")');
assert.equal(getPortalSymbol(), Portal, 'getPortalSymbol helper must return Portal');
assert.equal(isMatchingPortalSymbol(Portal), true, 'isMatchingPortalSymbol must return true for Portal');
assert.equal(isMatchingPortalSymbol(Symbol.for('react.portal')), true, 'isMatchingPortalSymbol must return true for Symbol.for("react.portal")');
assert.equal(isMatchingPortalSymbol(Symbol.for('react.fragment')), false, 'isMatchingPortalSymbol must return false for other symbols');

// 2. Portal detection with isPortal
const portalObj = createPortalDescriptor([], {}, null);
assert.equal(portalObj.$$typeof, Portal, 'Created descriptor must have $$typeof equal to Portal');
assert.equal(isPortal(portalObj), true, 'isPortal must return true for object with $$typeof Portal');
assert.equal(checkIsPortal(portalObj), true, 'checkIsPortal helper must return true');

const nonPortalObj = { type: 'div', props: {} };
assert.equal(isPortal(nonPortalObj), false, 'Plain object must not be recognized as portal');
assert.equal(checkIsPortal(null), false, 'null must not be recognized as portal');
assert.equal(checkIsPortal(undefined), false, 'undefined must not be recognized as portal');

// 3. typeOf identification matching Portal
assert.equal(typeOf(portalObj), Portal, 'typeOf must return Portal for object with $$typeof Portal');
assert.equal(isPortalTypeOf(portalObj), true, 'isPortalTypeOf helper must return true for portal object');
assert.equal(typeOf(nonPortalObj), undefined, 'typeOf must return undefined for plain object without $$typeof');
assert.equal(isPortalTypeOf(nonPortalObj), false, 'isPortalTypeOf helper must return false for non-portal');

// 4. Distinction from other React symbols
const elementObj = {
  $$typeof: Symbol.for('react.element'),
  type: 'div',
  props: {},
  key: null,
  ref: null,
};
assert.notEqual(typeOf(elementObj), Portal, 'typeOf for standard element must not equal Portal');
assert.equal(isPortal(elementObj), false, 'isPortal must return false for standard React element');
assert.equal(isPortalTypeOf(elementObj), false, 'isPortalTypeOf helper must return false for standard React element');

console.log('Contract passed: react-is.Portal verified successfully.');

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

аноним