CodeSampleX

Sample

chromium-bidi 2.1.2: Session

Verified sample for npm chromium-bidi 2.1.2: Session. The contract ran on node 22 · linux alpine/x64 · docker and passed: Session.parseSubscribeParams parses…

sha256:2d9f3563b584f898c3beda3ea652b06191be3c5d0a9248efcd735c1828d7f11a

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
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-27

Case

HOW
Goal
verify chromium-bidi.Session in pkg:npm/chromium-bidi@2.1.2
Packages
Symbols
  • chromium-bidi.Session
Created
2026-08-27T11:07:20Z

Contract

  1. Session.parseSubscribeParams parses valid subscription requests with events and contexts
  2. Session.parseSubscribeParams throws InvalidArgumentException when given invalid parameters
  3. Session.parseUnsubscribeParams parses subscription IDs list
  4. Session.parseUnsubscribeParams parses unsubscribe request by event attributes
  5. Session.parseUnsubscribeParams throws InvalidArgumentException on invalid parameters
  6. SubscriptionManager subscribes channels to unrolled module events
  7. SubscriptionManager checks active subscriptions and retrieves subscribed channels
  8. SubscriptionManager unrolls BiDi module events into atomic event names
  9. SubscriptionManager unsubscribes active subscriptions by subscription ID

Files

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

Download the source artifact (tar.gz)

Source

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 chromium-bidi.Session in pkg:npm/chromium-bidi@2.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/chromium-bidi@2.1.2
Demonstrate these symbols/APIs:
  - chromium-bidi.Session

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:fcd856f351ac4b51ea417099f57572dd5a0a3332b53ed6e78da844c68616f8c4","contract":["Session.parseSubscribeParams parses valid subscription requests with events and contexts","Session.parseSubscribeParams throws InvalidArgumentException when given invalid parameters","Session.parseUnsubscribeParams parses subscription IDs list","Session.parseUnsubscribeParams parses unsubscribe request by event attributes","Session.parseUnsubscribeParams throws InvalidArgumentException on invalid parameters","SubscriptionManager subscribes channels to unrolled module events","SubscriptionManager checks active subscriptions and retrieves subscribed channels","SubscriptionManager unrolls BiDi module events into atomic event names","SubscriptionManager unsubscribes active subscriptions by subscription ID"],"goal":"verify chromium-bidi.Session in pkg:npm/chromium-bidi@2.1.2","kind":"HOW","packages":["pkg:npm/chromium-bidi@2.1.2"],"schemaVersion":1,"symbols":["chromium-bidi.Session"]},"contractCommand":["node","test/contract.js"],"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/chromium-bidi@2.1.2"],"schemaVersion":1,"subject":"pkg:npm/chromium-bidi@2.1.2","symbols":["chromium-bidi.Session"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const {
  SubscriptionManager,
  unrollEvents,
  cartesianProduct,
  difference,
} = require('chromium-bidi/lib/cjs/bidiMapper/modules/session/SubscriptionManager.js');
const {
  BrowsingContextStorage,
} = require('chromium-bidi/lib/cjs/bidiMapper/modules/context/BrowsingContextStorage.js');
const {
  Session,
} = require('chromium-bidi/lib/cjs/protocol-parser/protocol-parser.js');
const {
  ChromiumBidi,
  InvalidArgumentException,
} = require('chromium-bidi/lib/cjs/protocol/protocol.js');

function parseSubscribeParameters(params) {
  return Session.parseSubscribeParams(params);
}

function parseUnsubscribeParameters(params) {
  return Session.parseUnsubscribeParams(params);
}

function createSubscriptionManager(storage = new BrowsingContextStorage()) {
  return new SubscriptionManager(storage);
}

module.exports = {
  SubscriptionManager,
  unrollEvents,
  cartesianProduct,
  difference,
  BrowsingContextStorage,
  Session,
  ChromiumBidi,
  InvalidArgumentException,
  parseSubscribeParameters,
  parseUnsubscribeParameters,
  createSubscriptionManager,
};
package-lock.json
{
  "name": "sample-3365340674",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-3365340674",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "chromium-bidi": "2.1.2"
      }
    },
    "node_modules/chromium-bidi": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-2.1.2.tgz",
      "integrity": "sha512-vtRWBK2uImo5/W2oG6/cDkkHSm+2t6VHgnj+Rcwhb0pP74OoUb4GipyRX/T/y39gYQPhioP0DPShn+A7P6CHNw==",
      "license": "Apache-2.0",
      "dependencies": {
        "mitt": "^3.0.1",
        "zod": "^3.24.1"
      },
      "peerDependencies": {
        "devtools-protocol": "*"
      }
    },
    "node_modules/devtools-protocol": {
      "version": "0.0.1684464",
      "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1684464.tgz",
      "integrity": "sha512-QGCy1oIGCTLtFtJuNZaU6QhaUjMyvTmHWiL3fCiHpE4F2N8r6lyobhqFJQiEh1a6PoCBp/JkjckQy3Lx2i2lfg==",
      "license": "BSD-3-Clause",
      "peer": true
    },
    "node_modules/mitt": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz",
      "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==",
      "license": "MIT"
    },
    "node_modules/zod": {
      "version": "3.25.76",
      "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
      "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/colinhacks"
      }
    }
  }
}
package.json
{
  "name": "sample-3365340674",
  "version": "1.0.0",
  "description": "Minimal sample verifying chromium-bidi.Session in pkg:npm/chromium-bidi@2.1.2",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "keywords": [],
  "author": "",
  "license": "MIT-0",
  "dependencies": {
    "chromium-bidi": "2.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify chromium-bidi.Session in pkg:npm/chromium-bidi@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/chromium-bidi@2.1.2"
  ],
  "symbols": [
    "chromium-bidi.Session"
  ]
}
test/contract.js
'use strict';

const assert = require('assert');
const {
  SubscriptionManager,
  unrollEvents,
  BrowsingContextStorage,
  Session,
  ChromiumBidi,
  InvalidArgumentException,
  parseSubscribeParameters,
  parseUnsubscribeParameters,
  createSubscriptionManager,
} = require('../index.js');

async function runContract() {
  // 1. Session.parseSubscribeParams parses valid subscription requests with events and contexts
  const validSubParams = {
    events: ['log.entryAdded', 'browsingContext.domContentLoaded'],
    contexts: ['context-1'],
  };
  const parsedSub = parseSubscribeParameters(validSubParams);
  assert.deepStrictEqual(parsedSub.events, ['log.entryAdded', 'browsingContext.domContentLoaded']);
  assert.deepStrictEqual(parsedSub.contexts, ['context-1']);

  // 2. Session.parseSubscribeParams throws InvalidArgumentException when given invalid parameters
  assert.throws(
    () => {
      parseSubscribeParameters({ events: 'invalid-events-type' });
    },
    (err) => {
      assert(err instanceof InvalidArgumentException, 'Error must be InvalidArgumentException');
      assert.strictEqual(err.error, 'invalid argument');
      return true;
    }
  );

  // 3. Session.parseUnsubscribeParams parses subscription IDs list
  const validUnsubById = {
    subscriptions: ['sub-id-100', 'sub-id-200'],
  };
  const parsedUnsubById = parseUnsubscribeParameters(validUnsubById);
  assert.deepStrictEqual(parsedUnsubById.subscriptions, ['sub-id-100', 'sub-id-200']);

  // 4. Session.parseUnsubscribeParams parses unsubscribe request by event attributes
  const validUnsubByAttr = {
    events: ['log.entryAdded'],
    contexts: ['context-1'],
  };
  const parsedUnsubByAttr = parseUnsubscribeParameters(validUnsubByAttr);
  assert.deepStrictEqual(parsedUnsubByAttr.events, ['log.entryAdded']);
  assert.deepStrictEqual(parsedUnsubByAttr.contexts, ['context-1']);

  // 5. Session.parseUnsubscribeParams throws InvalidArgumentException on invalid parameters
  assert.throws(
    () => {
      parseUnsubscribeParameters({ unknownKey: 12345 });
    },
    (err) => {
      assert(err instanceof InvalidArgumentException, 'Error must be InvalidArgumentException');
      assert.strictEqual(err.error, 'invalid argument');
      return true;
    }
  );

  // 6. SubscriptionManager subscribes channels to unrolled module events
  const storage = new BrowsingContextStorage();
  const subManager = createSubscriptionManager(storage);
  const channel = { 'goog:channel': 'session-test-channel' };
  const subscription = subManager.subscribe([ChromiumBidi.BiDiModule.Log], [], [], channel);
  assert(typeof subscription.id === 'string' && subscription.id.length > 0);
  assert(subscription.eventNames.has('log.entryAdded'));
  assert.deepStrictEqual(subscription.channel, channel);

  // 7. SubscriptionManager checks active subscriptions and retrieves subscribed channels
  assert.strictEqual(subManager.isSubscribedTo('log.entryAdded', null), true);
  assert.strictEqual(subManager.isSubscribedTo('browsingContext.load', null), false);
  const subscribedChannels = subManager.getChannelsSubscribedToEventGlobally('log.entryAdded');
  assert.deepStrictEqual(subscribedChannels, [channel]);

  // 8. SubscriptionManager unrolls BiDi module events into atomic event names
  const unrolled = Array.from(unrollEvents([ChromiumBidi.BiDiModule.BrowsingContext]));
  assert(unrolled.includes('browsingContext.domContentLoaded'));
  assert(unrolled.includes('browsingContext.load'));
  assert(unrolled.includes('browsingContext.contextCreated'));

  // 9. SubscriptionManager unsubscribes active subscriptions by subscription ID
  subManager.unsubscribeById([subscription.id]);
  assert.strictEqual(subManager.isSubscribedTo('log.entryAdded', null), false);
  const channelsAfterUnsub = subManager.getChannelsSubscribedToEventGlobally('log.entryAdded');
  assert.deepStrictEqual(channelsAfterUnsub, []);

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

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Origin Seeder

anonymous