CodeSampleX

Sample

test-exclude 6.0.0: filter files with shouldInstrument based on include and exclude patterns

Verified sample for npm test-exclude 6.0.0: filter files with shouldInstrument based on include and exclude patterns. The contract ran on node 22 · linux…

sha256:d43138d0c081315fa4a94824f7f1dda1c4a8efb477206d46fc326486b46ea578

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 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

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

Case

HOW
Goal
filter files with shouldInstrument based on include and exclude patterns
Packages
Symbols
  • shouldInstrument
Environment
node 22.23.2
Created
2026-08-26T14:20:58Z

Contract

  1. TestExclude.prototype.shouldInstrument returns true for files matching explicit include patterns
  2. TestExclude.prototype.shouldInstrument returns false for files matching explicit exclude patterns
  3. TestExclude.prototype.shouldInstrument excludes default test and config patterns when exclude is not customized
  4. TestExclude.prototype.shouldInstrument excludes node_modules by default
  5. TestExclude.prototype.shouldInstrument returns false for files outside configured working directory
  6. TestExclude.prototype.shouldInstrument returns false for file extensions outside configured extension list
  7. TestExclude.prototype.shouldInstrument supports negation patterns in exclude rules

Files

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

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: filter files with shouldInstrument based on include and exclude patterns
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/test-exclude@6.0.0
Demonstrate these symbols/APIs:
  - shouldInstrument

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:8255d3058bb3582742ab8881f89d43ddffcd479dda1a0962cf033438ea19b02c","contract":["TestExclude.prototype.shouldInstrument returns true for files matching explicit include patterns","TestExclude.prototype.shouldInstrument returns false for files matching explicit exclude patterns","TestExclude.prototype.shouldInstrument excludes default test and config patterns when exclude is not customized","TestExclude.prototype.shouldInstrument excludes node_modules by default","TestExclude.prototype.shouldInstrument returns false for files outside configured working directory","TestExclude.prototype.shouldInstrument returns false for file extensions outside configured extension list","TestExclude.prototype.shouldInstrument supports negation patterns in exclude rules"],"goal":"filter files with shouldInstrument based on include and exclude patterns","kind":"HOW","packages":["pkg:npm/test-exclude@6.0.0"],"schemaVersion":1,"symbols":["shouldInstrument"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/test-exclude@6.0.0"],"schemaVersion":1,"subject":"pkg:npm/test-exclude@6.0.0","symbols":["shouldInstrument"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-test-exclude",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-test-exclude",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "test-exclude": "6.0.0"
      }
    },
    "node_modules/@istanbuljs/schema": {
      "version": "0.1.6",
      "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.6.tgz",
      "integrity": "sha512-+Sg6GCR/wy1oSmQDFq4LQDAhm3ETKnorxN+y5nbLULOR3P0c14f2Wurzj3/xqPXtasLFfHd5iRFQ7AJt4KH2cw==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/balanced-match": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
      "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
      "license": "MIT"
    },
    "node_modules/brace-expansion": {
      "version": "1.1.18",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz",
      "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==",
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "node_modules/concat-map": {
      "version": "0.0.1",
      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
      "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
      "license": "MIT"
    },
    "node_modules/fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
      "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
      "license": "ISC"
    },
    "node_modules/glob": {
      "version": "7.2.3",
      "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
      "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
      "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
      "license": "ISC",
      "dependencies": {
        "fs.realpath": "^1.0.0",
        "inflight": "^1.0.4",
        "inherits": "2",
        "minimatch": "^3.1.1",
        "once": "^1.3.0",
        "path-is-absolute": "^1.0.0"
      },
      "engines": {
        "node": "*"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    },
    "node_modules/inflight": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
      "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
      "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.",
      "license": "ISC",
      "dependencies": {
        "once": "^1.3.0",
        "wrappy": "1"
      }
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/minimatch": {
      "version": "3.1.5",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz",
      "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==",
      "license": "ISC",
      "dependencies": {
        "brace-expansion": "^1.1.7"
      },
      "engines": {
        "node": "*"
      }
    },
    "node_modules/once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
      "license": "ISC",
      "dependencies": {
        "wrappy": "1"
      }
    },
    "node_modules/path-is-absolute": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
      "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/test-exclude": {
      "version": "6.0.0",
      "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz",
      "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==",
      "license": "ISC",
      "dependencies": {
        "@istanbuljs/schema": "^0.1.2",
        "glob": "^7.1.4",
        "minimatch": "^3.0.4"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-test-exclude",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "test-exclude": "6.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "filter files with shouldInstrument based on include and exclude patterns",
  "kind": "HOW",
  "packages": [
    "pkg:npm/test-exclude@6.0.0"
  ],
  "symbols": [
    "shouldInstrument"
  ]
}
src/index.mjs
import TestExclude from 'test-exclude';

/**
 * Create a new TestExclude filter instance.
 * @param {Object} [options] - TestExclude configuration options.
 * @returns {TestExclude} TestExclude instance.
 */
export function createExcludeFilter(options = {}) {
  return new TestExclude(options);
}

/**
 * Check whether a target file path should be instrumented based on given options.
 * @param {string} filename - Target file path to check.
 * @param {Object} [options] - TestExclude configuration options.
 * @returns {boolean} True if file should be instrumented, false otherwise.
 */
export function isFileInstrumented(filename, options = {}) {
  const filter = new TestExclude(options);
  return filter.shouldInstrument(filename);
}

export { TestExclude };
export default TestExclude;
test/contract.mjs
import assert from 'node:assert';
import { TestExclude, createExcludeFilter, isFileInstrumented } from '../src/index.mjs';

const cwd = '/workspace/app';

// 1. TestExclude.prototype.shouldInstrument returns true for files matching explicit include patterns
const filter1 = createExcludeFilter({
  cwd,
  include: ['src/**/*.js', 'lib/**/*.js']
});
assert.strictEqual(filter1.shouldInstrument('/workspace/app/src/index.js'), true);
assert.strictEqual(filter1.shouldInstrument('/workspace/app/lib/util.js'), true);
assert.strictEqual(filter1.shouldInstrument('/workspace/app/other/helper.js'), false);
assert.strictEqual(isFileInstrumented('/workspace/app/src/index.js', { cwd, include: ['src/**/*.js'] }), true);

// 2. TestExclude.prototype.shouldInstrument returns false for files matching explicit exclude patterns
const filter2 = createExcludeFilter({
  cwd,
  include: ['src/**'],
  exclude: ['src/**/*.test.js', 'src/**/__tests__/**']
});
assert.strictEqual(filter2.shouldInstrument('/workspace/app/src/service.js'), true);
assert.strictEqual(filter2.shouldInstrument('/workspace/app/src/service.test.js'), false);
assert.strictEqual(filter2.shouldInstrument('/workspace/app/src/__tests__/unit.js'), false);

// 3. TestExclude.prototype.shouldInstrument excludes default test and config patterns when exclude is not customized
const defaultFilter = createExcludeFilter({ cwd });
assert.strictEqual(defaultFilter.shouldInstrument('/workspace/app/src/index.js'), true);
assert.strictEqual(defaultFilter.shouldInstrument('/workspace/app/test/index.js'), false);
assert.strictEqual(defaultFilter.shouldInstrument('/workspace/app/jest.config.js'), false);
assert.strictEqual(defaultFilter.shouldInstrument('/workspace/app/coverage/lcov.js'), false);

// 4. TestExclude.prototype.shouldInstrument excludes node_modules by default
assert.strictEqual(defaultFilter.shouldInstrument('/workspace/app/node_modules/pkg/index.js'), false);

// 5. TestExclude.prototype.shouldInstrument returns false for files outside configured working directory
assert.strictEqual(defaultFilter.shouldInstrument('/other-workspace/src/index.js'), false);

// 6. TestExclude.prototype.shouldInstrument returns false for file extensions outside configured extension list
const extFilter = createExcludeFilter({
  cwd,
  extension: ['.js', '.ts']
});
assert.strictEqual(extFilter.shouldInstrument('/workspace/app/src/index.js'), true);
assert.strictEqual(extFilter.shouldInstrument('/workspace/app/src/index.ts'), true);
assert.strictEqual(extFilter.shouldInstrument('/workspace/app/src/index.py'), false);
assert.strictEqual(extFilter.shouldInstrument('/workspace/app/src/index.txt'), false);

// 7. TestExclude.prototype.shouldInstrument supports negation patterns in exclude rules
const negationFilter = createExcludeFilter({
  cwd,
  exclude: ['test/**', '!test/keep.js']
});
assert.strictEqual(negationFilter.shouldInstrument('/workspace/app/test/ignored.js'), false);
assert.strictEqual(negationFilter.shouldInstrument('/workspace/app/test/keep.js'), true);

console.log('All contract assertions passed.');

Origin Seeder

anonymous