CodeSampleX

示例

robots-parser 3.0.1: isAllowed

已验证示例 — npm robots-parser 3.0.1: isAllowed. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: isAllowed returns true for paths matching an Allow…

sha256:c1e28b275235f9d6e8c0c8ae55da65afa99406bb02d148660ddf944cef1c9989

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-13

案例

HOW
目标
verify isAllowed in pkg:npm/robots-parser@3.0.1
包
符号
  • isAllowed
创建时间
2026-09-13T18:40:45Z

契约

  1. isAllowed returns true for paths matching an Allow directive and false for paths matching a Disallow directive
  2. isAllowed returns true by default when no matching rule is specified for a path
  3. isAllowed respects user-agent specific rules over wildcard rules
  4. isAllowed applies the longest matching rule when multiple rules match a path
  5. isAllowed prefers Allow directive over Disallow directive when rule patterns have equal length
  6. isAllowed supports wildcard (*) and end-of-line ($) pattern matching
  7. isAllowed returns undefined when the queried URL protocol, hostname, or port does not match the robots.txt base URL

文件

  • 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 isAllowed in pkg:npm/robots-parser@3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/robots-parser@3.0.1
Demonstrate these symbols/APIs:
  - isAllowed

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:5193029bf557b99d4126ad9ad55ec5e22fb83a9a788aa165c3d3130d40243530","contract":["isAllowed returns true for paths matching an Allow directive and false for paths matching a Disallow directive","isAllowed returns true by default when no matching rule is specified for a path","isAllowed respects user-agent specific rules over wildcard rules","isAllowed applies the longest matching rule when multiple rules match a path","isAllowed prefers Allow directive over Disallow directive when rule patterns have equal length","isAllowed supports wildcard (*) and end-of-line ($) pattern matching","isAllowed returns undefined when the queried URL protocol, hostname, or port does not match the robots.txt base URL"],"goal":"verify isAllowed in pkg:npm/robots-parser@3.0.1","kind":"HOW","packages":["pkg:npm/robots-parser@3.0.1"],"schemaVersion":1,"symbols":["isAllowed"]},"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/robots-parser@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/robots-parser@3.0.1","symbols":["isAllowed"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "robots-parser-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "robots-parser-sample",
      "version": "1.0.0",
      "dependencies": {
        "robots-parser": "3.0.1"
      }
    },
    "node_modules/robots-parser": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/robots-parser/-/robots-parser-3.0.1.tgz",
      "integrity": "sha512-s+pyvQeIKIZ0dx5iJiQk1tPLJAWln39+MI5jtM8wnyws+G5azk+dMnMX0qfbqNetKKNgcWWOdi0sfm+FbQbgdQ==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    }
  }
}
package.json
{
  "name": "robots-parser-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for robots-parser",
  "dependencies": {
    "robots-parser": "3.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify isAllowed in pkg:npm/robots-parser@3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/robots-parser@3.0.1"
  ],
  "symbols": [
    "isAllowed"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import robotsParser from 'robots-parser';

// 1. isAllowed returns true for paths matching an Allow directive and false for paths matching a Disallow directive
const robots1 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /admin/',
  'Allow: /public/'
].join('\n'));
assert.strictEqual(robots1.isAllowed('https://example.com/admin/dashboard'), false);
assert.strictEqual(robots1.isAllowed('https://example.com/public/about'), true);

// 2. isAllowed returns true by default when no matching rule is specified for a path
const robots2 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /private/'
].join('\n'));
assert.strictEqual(robots2.isAllowed('https://example.com/unrestricted/page.html'), true);

// 3. isAllowed respects user-agent specific rules over wildcard rules
const robots3 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /data/',
  'User-agent: TestBot',
  'Allow: /data/'
].join('\n'));
assert.strictEqual(robots3.isAllowed('https://example.com/data/report', 'TestBot/2.0'), true);
assert.strictEqual(robots3.isAllowed('https://example.com/data/report', 'OtherBot'), false);

// 4. isAllowed applies the longest matching rule when multiple rules match a path
const robots4 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /media/',
  'Allow: /media/public/'
].join('\n'));
assert.strictEqual(robots4.isAllowed('https://example.com/media/public/image.png'), true);
assert.strictEqual(robots4.isAllowed('https://example.com/media/private/image.png'), false);

// 5. isAllowed prefers Allow directive over Disallow directive when rule patterns have equal length
const robots5 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /shared',
  'Allow: /shared'
].join('\n'));
assert.strictEqual(robots5.isAllowed('https://example.com/shared'), true);

// 6. isAllowed supports wildcard (*) and end-of-line ($) pattern matching
const robots6 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /*.secret$',
  'Disallow: /temp/*/cache'
].join('\n'));
assert.strictEqual(robots6.isAllowed('https://example.com/file.secret'), false);
assert.strictEqual(robots6.isAllowed('https://example.com/file.secret.html'), true);
assert.strictEqual(robots6.isAllowed('https://example.com/temp/user123/cache'), false);
assert.strictEqual(robots6.isAllowed('https://example.com/temp/user123/other'), true);

// 7. isAllowed returns undefined when the queried URL protocol, hostname, or port does not match the robots.txt base URL
const robots7 = robotsParser('https://example.com/robots.txt', [
  'User-agent: *',
  'Disallow: /admin/'
].join('\n'));
assert.strictEqual(robots7.isAllowed('http://example.com/admin/'), undefined);
assert.strictEqual(robots7.isAllowed('https://different.example.com/admin/'), undefined);
assert.strictEqual(robots7.isAllowed('https://example.com:8080/admin/'), undefined);

console.log('Contract passed');

原始种子者

匿名