CodeSampleX

샘플

eventsource 3.0.7: EventSource

검증된 샘플 — npm eventsource 3.0.7: EventSource. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: EventSource exposes readyState constants CONNECTING…

sha256:757ec10e71189f8ba907377d075863dded73f939403805700c8de05d5f96eecf

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/eventsource@3.0.7
패키지
심벌
  • EventSource
환경
node 22.23.2
생성일
2026-08-26T08:27:50Z

컨트랙트

  1. EventSource exposes readyState constants CONNECTING (0), OPEN (1), and CLOSED (2)
  2. EventSource initializes with CONNECTING readyState, the target URL, and default options
  3. EventSource connects to an SSE endpoint and dispatches open event with readyState OPEN
  4. EventSource receives and parses standard message events with event.data
  5. EventSource receives and dispatches custom named events via addEventListener
  6. EventSource.close() terminates the connection and transitions readyState to CLOSED

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/eventsource@3.0.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/eventsource@3.0.7
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:27b05d1f2852da43248c77d69324a8d2e072a9a19283d39763f468e5fcb9b5c6","constraints":{"executionContext":"node"},"contract":["EventSource exposes readyState constants CONNECTING (0), OPEN (1), and CLOSED (2)","EventSource initializes with CONNECTING readyState, the target URL, and default options","EventSource connects to an SSE endpoint and dispatches open event with readyState OPEN","EventSource receives and parses standard message events with event.data","EventSource receives and dispatches custom named events via addEventListener","EventSource.close() terminates the connection and transitions readyState to CLOSED"],"goal":"verify pkg:npm/eventsource@3.0.7","kind":"HOW","packages":["pkg:npm/eventsource@3.0.7"],"schemaVersion":1,"symbols":["EventSource"]},"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/eventsource@3.0.7"],"schemaVersion":1,"subject":"pkg:npm/eventsource@3.0.7","symbols":["EventSource"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-eventsource-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-eventsource-verify",
      "version": "1.0.0",
      "dependencies": {
        "eventsource": "3.0.7"
      }
    },
    "node_modules/eventsource": {
      "version": "3.0.7",
      "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz",
      "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==",
      "license": "MIT",
      "dependencies": {
        "eventsource-parser": "^3.0.1"
      },
      "engines": {
        "node": ">=18.0.0"
      }
    },
    "node_modules/eventsource-parser": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz",
      "integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==",
      "license": "MIT",
      "engines": {
        "node": ">=18.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-eventsource-verify",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "eventsource": "3.0.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/eventsource@3.0.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/eventsource@3.0.7"
  ],
  "symbols": [
    "EventSource"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import http from 'node:http';
import { EventSource } from 'eventsource';

// 1. EventSource exposes readyState constants CONNECTING (0), OPEN (1), and CLOSED (2)
{
  assert.equal(EventSource.CONNECTING, 0);
  assert.equal(EventSource.OPEN, 1);
  assert.equal(EventSource.CLOSED, 2);
}

// Helper to run offline HTTP SSE server for network contracts
async function createTestServer() {
  const server = http.createServer((req, res) => {
    res.writeHead(200, {
      'Content-Type': 'text/event-stream',
      'Cache-Control': 'no-cache',
      'Connection': 'keep-alive',
    });
    res.write('event: custom-event\ndata: payload-data\n\n');
    res.write('data: line1\ndata: line2\n\n');
  });

  await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
  const port = server.address().port;
  const url = `http://127.0.0.1:${port}/sse`;
  return { server, url };
}

const { server, url } = await createTestServer();

try {
  // 2. EventSource initializes with CONNECTING readyState, the target URL, and default options
  const es = new EventSource(url);
  assert.equal(es.readyState, EventSource.CONNECTING);
  assert.equal(es.url, url);
  assert.equal(es.withCredentials, false);
  assert.equal(es.CONNECTING, 0);
  assert.equal(es.OPEN, 1);
  assert.equal(es.CLOSED, 2);

  const receivedCustomEvents = [];
  const receivedMessages = [];

  await new Promise((resolve, reject) => {
    const timeout = setTimeout(() => {
      reject(new Error('Test timed out waiting for SSE events'));
    }, 5000);

    // 3. EventSource connects to an SSE endpoint and dispatches open event with readyState OPEN
    es.addEventListener('open', () => {
      assert.equal(es.readyState, EventSource.OPEN);
    });

    // 5. EventSource receives and dispatches custom named events via addEventListener
    es.addEventListener('custom-event', (event) => {
      receivedCustomEvents.push(event.data);
    });

    // 4. EventSource receives and parses standard message events with event.data
    es.addEventListener('message', (event) => {
      receivedMessages.push(event.data);
      if (receivedCustomEvents.length === 1 && receivedMessages.length === 1) {
        clearTimeout(timeout);
        resolve();
      }
    });

    es.addEventListener('error', (err) => {
      clearTimeout(timeout);
      reject(err);
    });
  });

  assert.deepEqual(receivedCustomEvents, ['payload-data']);
  assert.deepEqual(receivedMessages, ['line1\nline2']);

  // 6. EventSource.close() terminates the connection and transitions readyState to CLOSED
  es.close();
  assert.equal(es.readyState, EventSource.CLOSED);
} finally {
  await new Promise((resolve) => server.close(resolve));
}

오리진 시더

익명