CodeSampleX

Exemplo

react-is 19.2.8: ContextProvider

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

sha256:2c414810585106ab22007dfc16ae09a38e94491940dc48d574365321f4fe8e6e

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-06

Caso

HOW
Objetivo
verify react-is.ContextProvider in pkg:npm/react-is@19.2.8
Pacotes
Símbolos
  • react-is.ContextProvider
Ambiente
node 22.23.2
Criado
2026-09-06T01:12:53Z

Contrato

  1. ContextProvider is exported as a symbol equal to Symbol.for('react.context')
  2. isContextProvider correctly identifies React 19 context provider elements
  3. typeOf returns ContextProvider symbol for context provider elements
  4. isContextProvider rejects standard HTML elements, fragment elements, and consumer elements
  5. isContextProvider rejects non-element values, plain objects, raw context objects, and primitives

Arquivos

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

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

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:ddd5a1ff3a2c57a9503ae3ca138f8cbac4acfdb1dc787d0c1afff56d93456a76","constraints":{"executionContext":"node"},"contract":["ContextProvider is exported as a symbol equal to Symbol.for('react.context')","isContextProvider correctly identifies React 19 context provider elements","typeOf returns ContextProvider symbol for context provider elements","isContextProvider rejects standard HTML elements, fragment elements, and consumer elements","isContextProvider rejects non-element values, plain objects, raw context objects, and primitives"],"goal":"verify react-is.ContextProvider in pkg:npm/react-is@19.2.8","kind":"HOW","packages":["pkg:npm/react-is@19.2.8"],"schemaVersion":1,"symbols":["react-is.ContextProvider"]},"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-is@19.2.8"],"schemaVersion":1,"subject":"pkg:npm/react-is@19.2.8","symbols":["react-is.ContextProvider"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-context-provider",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-context-provider",
      "version": "1.0.0",
      "dependencies": {
        "react-is": "19.2.8"
      }
    },
    "node_modules/react-is": {
      "version": "19.2.8",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.8.tgz",
      "integrity": "sha512-s5un28nYxKJw5gvUHyW5PCC28CvBqLu9r3cWgzHT4Vo/5fqqkFcdRYsGcKf50WMPpjjFZS5d76fn3YCo2njKwQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-context-provider",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is ContextProvider in React 19",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "19.2.8"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.ContextProvider in pkg:npm/react-is@19.2.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@19.2.8"
  ],
  "symbols": [
    "react-is.ContextProvider"
  ]
}
src/index.js
import {
  ContextProvider,
  isContextProvider,
  typeOf,
} from 'react-is';

/**
 * Return the ContextProvider symbol from react-is.
 * In React 19, this corresponds to Symbol.for('react.context').
 *
 * @returns {symbol} The ContextProvider symbol.
 */
export function getContextProviderSymbol() {
  return ContextProvider;
}

/**
 * Check if the given element is a React Context Provider element.
 *
 * @param {*} value - The value to inspect.
 * @returns {boolean} True if the value is a Context Provider element.
 */
export function checkIsContextProvider(value) {
  return isContextProvider(value);
}

/**
 * Determine the element type symbol of a given React element using typeOf.
 *
 * @param {*} value - The React element to inspect.
 * @returns {symbol|undefined} The matched React symbol or undefined for non-elements.
 */
export function identifyElementType(value) {
  return typeOf(value);
}

/**
 * Helper to construct a synthetic React 19 Context Provider element.
 *
 * @param {*} contextType - The context object with $$typeof matching ContextProvider.
 * @param {object} [props={}] - Element props.
 * @returns {object} Synthetic React 19 element.
 */
export function createSyntheticProviderElement(contextType, props = {}) {
  return {
    $$typeof: Symbol.for('react.transitional.element'),
    type: contextType,
    props,
    key: null,
    ref: null,
  };
}

export {
  ContextProvider,
  isContextProvider,
  typeOf,
};
test/contract.mjs
import assert from 'node:assert/strict';
import {
  ContextProvider,
  isContextProvider,
  typeOf,
  getContextProviderSymbol,
  checkIsContextProvider,
  identifyElementType,
  createSyntheticProviderElement,
} from '../src/index.js';

// 1. ContextProvider symbol export verification
assert.equal(typeof ContextProvider, 'symbol', 'ContextProvider must be exported as a symbol');
assert.equal(
  ContextProvider,
  Symbol.for('react.context'),
  'ContextProvider in React 19 must match Symbol.for("react.context")'
);
assert.equal(
  getContextProviderSymbol(),
  ContextProvider,
  'getContextProviderSymbol helper must return ContextProvider symbol'
);

// 2. isContextProvider function export verification
assert.equal(
  typeof isContextProvider,
  'function',
  'isContextProvider must be exported as a function'
);
assert.equal(
  typeof checkIsContextProvider,
  'function',
  'checkIsContextProvider helper must be exported as a function'
);

// 3. React 19 context provider element identification
const contextObject = {
  $$typeof: ContextProvider,
  _currentValue: 'default-test-value',
};

const providerElement = createSyntheticProviderElement(contextObject, {
  value: 'custom-provider-value',
});

assert.equal(
  isContextProvider(providerElement),
  true,
  'isContextProvider must return true for React 19 context provider elements'
);
assert.equal(
  checkIsContextProvider(providerElement),
  true,
  'checkIsContextProvider helper must return true for React 19 context provider elements'
);
assert.equal(
  typeOf(providerElement),
  ContextProvider,
  'typeOf must return ContextProvider symbol for context provider elements'
);
assert.equal(
  identifyElementType(providerElement),
  ContextProvider,
  'identifyElementType helper must return ContextProvider symbol'
);

// 4. Distinction from standard elements and other component types
const standardElement = {
  $$typeof: Symbol.for('react.transitional.element'),
  type: 'div',
  props: { className: 'test-class' },
  key: null,
  ref: null,
};
assert.equal(
  isContextProvider(standardElement),
  false,
  'isContextProvider must return false for standard HTML/DOM elements'
);
assert.notEqual(
  typeOf(standardElement),
  ContextProvider,
  'typeOf on standard elements must not equal ContextProvider'
);

const fragmentElement = {
  $$typeof: Symbol.for('react.transitional.element'),
  type: Symbol.for('react.fragment'),
  props: {},
  key: null,
  ref: null,
};
assert.equal(
  isContextProvider(fragmentElement),
  false,
  'isContextProvider must return false for fragment elements'
);

const consumerElement = {
  $$typeof: Symbol.for('react.transitional.element'),
  type: {
    $$typeof: Symbol.for('react.consumer'),
  },
  props: {},
  key: null,
  ref: null,
};
assert.equal(
  isContextProvider(consumerElement),
  false,
  'isContextProvider must return false for context consumer elements'
);

// 5. Non-element and invalid input rejection
assert.equal(isContextProvider(null), false, 'null is not a context provider');
assert.equal(isContextProvider(undefined), false, 'undefined is not a context provider');
assert.equal(isContextProvider({}), false, 'plain empty object is not a context provider');
assert.equal(isContextProvider('react.context'), false, 'string primitive is not a context provider');
assert.equal(isContextProvider(12345), false, 'number primitive is not a context provider');
assert.equal(isContextProvider(contextObject), false, 'raw context definition object without element wrapper is not a provider element');

assert.equal(typeOf(null), undefined, 'typeOf(null) must return undefined');
assert.equal(typeOf(undefined), undefined, 'typeOf(undefined) must return undefined');
assert.equal(typeOf({}), undefined, 'typeOf({}) must return undefined');

console.log('All react-is.ContextProvider contract checks passed successfully.');

Seeder de origem

anônimo