CodeSampleX

Sample

send 0.19.0: send

Verified sample for npm send 0.19.0: send. The contract ran on node 22 · linux debian/x64 · docker and passed: send(req, path, { root }) streams the static…

sha256:ace1c3ebd0c9c52aabb639759b926168b766eec0035e45fce4cb333ceb5d0b5c

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-19

Case

HOW
Goal
verify pkg:npm/send@0.19.0
Packages
Symbols
  • send
Created
2026-09-18T22:18:33Z

Contract

  1. send(req, path, { root }) streams the static file to HTTP response with correct headers
  2. send(req, path, { root, index: 'home.html' }) serves custom index file when requesting a directory
  3. send(req, path, { root, extensions: ['html', 'txt'] }) serves file with matching extension when omitted from path
  4. send(req, path, { root, immutable: true, maxAge: 86400000 }) sets Cache-Control header with max-age and immutable directive
  5. send(req, path, { root }) returns HTTP 304 Not Modified for conditional GET request when If-None-Match matches ETag
  6. send(req, path, { root }) returns HTTP 206 Partial Content with Content-Range header for Range byte request
  7. send(req, path, { root, acceptRanges: false }) omits Accept-Ranges header and ignores Range request headers
  8. send(req, path, { root, cacheControl: false, etag: false, lastModified: false }) suppresses Cache-Control, ETag, and Last-Modified headers
  9. send(req, path, { root }) emits an error with status 404 when requested file does not exist
  10. send(req, path, { root, dotfiles: 'ignore' }) emits an error with status 404 when accessing dotfiles with ignore option
  11. send(req, path, { root, dotfiles: 'deny' }) emits an error with status 403 when accessing dotfiles with deny option
  12. send(req, path, { root, index: false }).on('directory', fn) emits directory event when requesting directory with index disabled

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • public/.secret
  • public/app.js
  • public/docs.txt
  • public/home.html
  • public/subdir/index.html
  • 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: verify pkg:npm/send@0.19.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/send@0.19.0
Demonstrate these symbols/APIs:
  - send

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:0e8a44dfe09821a19c99890db23c1eca82be1a3df1ccb9d23bdc1e3b5301f4b6","contract":["send(req, path, { root }) streams the static file to HTTP response with correct headers","send(req, path, { root, index: 'home.html' }) serves custom index file when requesting a directory","send(req, path, { root, extensions: ['html', 'txt'] }) serves file with matching extension when omitted from path","send(req, path, { root, immutable: true, maxAge: 86400000 }) sets Cache-Control header with max-age and immutable directive","send(req, path, { root }) returns HTTP 304 Not Modified for conditional GET request when If-None-Match matches ETag","send(req, path, { root }) returns HTTP 206 Partial Content with Content-Range header for Range byte request","send(req, path, { root, acceptRanges: false }) omits Accept-Ranges header and ignores Range request headers","send(req, path, { root, cacheControl: false, etag: false, lastModified: false }) suppresses Cache-Control, ETag, and Last-Modified headers","send(req, path, { root }) emits an error with status 404 when requested file does not exist","send(req, path, { root, dotfiles: 'ignore' }) emits an error with status 404 when accessing dotfiles with ignore option","send(req, path, { root, dotfiles: 'deny' }) emits an error with status 403 when accessing dotfiles with deny option","send(req, path, { root, index: false }).on('directory', fn) emits directory event when requesting directory with index disabled"],"goal":"verify pkg:npm/send@0.19.0","kind":"HOW","packages":["pkg:npm/send@0.19.0"],"schemaVersion":1,"symbols":["send"]},"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/send@0.19.0"],"schemaVersion":1,"subject":"pkg:npm/send@0.19.0","symbols":["send"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "send-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "send-sample",
      "version": "1.0.0",
      "dependencies": {
        "send": "0.19.0"
      }
    },
    "node_modules/debug": {
      "version": "2.6.9",
      "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
      "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
      "license": "MIT",
      "dependencies": {
        "ms": "2.0.0"
      }
    },
    "node_modules/debug/node_modules/ms": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
      "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
      "license": "MIT"
    },
    "node_modules/depd": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
      "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/destroy": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
      "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8",
        "npm": "1.2.8000 || >= 1.4.16"
      }
    },
    "node_modules/ee-first": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
      "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
      "license": "MIT"
    },
    "node_modules/encodeurl": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
      "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/escape-html": {
      "version": "1.0.3",
      "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
      "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
      "license": "MIT"
    },
    "node_modules/etag": {
      "version": "1.8.1",
      "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
      "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/fresh": {
      "version": "0.5.2",
      "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
      "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/http-errors": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
      "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
      "license": "MIT",
      "dependencies": {
        "depd": "2.0.0",
        "inherits": "2.0.4",
        "setprototypeof": "1.2.0",
        "statuses": "2.0.1",
        "toidentifier": "1.0.1"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "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/mime": {
      "version": "1.6.0",
      "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
      "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
      "license": "MIT",
      "bin": {
        "mime": "cli.js"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/on-finished": {
      "version": "2.4.1",
      "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
      "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
      "license": "MIT",
      "dependencies": {
        "ee-first": "1.1.1"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/range-parser": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
      "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/send": {
      "version": "0.19.0",
      "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz",
      "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
      "license": "MIT",
      "dependencies": {
        "debug": "2.6.9",
        "depd": "2.0.0",
        "destroy": "1.2.0",
        "encodeurl": "~1.0.2",
        "escape-html": "~1.0.3",
        "etag": "~1.8.1",
        "fresh": "0.5.2",
        "http-errors": "2.0.0",
        "mime": "1.6.0",
        "ms": "2.1.3",
        "on-finished": "2.4.1",
        "range-parser": "~1.2.1",
        "statuses": "2.0.1"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/setprototypeof": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
      "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
      "license": "ISC"
    },
    "node_modules/statuses": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
      "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/toidentifier": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
      "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
      "license": "MIT",
      "engines": {
        "node": ">=0.6"
      }
    }
  }
}
package.json
{
  "name": "send-sample",
  "version": "1.0.0",
  "description": "Verify pkg:npm/send@0.19.0",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "send": "0.19.0"
  }
}
public/.secret
restricted dotfile content
public/app.js
console.log("sample app script");
public/docs.txt
Sample documentation content for send verification.
public/home.html
<!DOCTYPE html>
<html><head><title>Home</title></head><body><h1>Home Page</h1></body></html>
public/subdir/index.html
<!DOCTYPE html>
<html><body>Subdir Index</body></html>
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/send@0.19.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/send@0.19.0"
  ],
  "symbols": [
    "send"
  ]
}
src/index.mjs
import send from 'send';

/**
 * Creates an HTTP request listener configured with send static streaming.
 *
 * @param {string} rootDir
 * @param {object} [options]
 * @returns {import('node:http').RequestListener}
 */
export function createStaticServer(rootDir, options = {}) {
  return function requestListener(req, res) {
    const url = new URL(req.url, 'http://localhost');
    const pathname = decodeURIComponent(url.pathname);
    const sendOptions = {
      root: rootDir,
      ...options
    };

    const stream = send(req, pathname, sendOptions);

    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });

    stream.pipe(res);
  };
}
test/contract.mjs
import http from 'node:http';
import path from 'node:path';
import assert from 'node:assert/strict';
import { fileURLToPath } from 'node:url';
import send from 'send';
import { createStaticServer } from '../src/index.mjs';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PUBLIC_DIR = path.resolve(__dirname, '../public');

function request(port, pathname, headers = {}) {
  return new Promise((resolve, reject) => {
    const req = http.request(
      {
        hostname: '127.0.0.1',
        port,
        path: pathname,
        method: 'GET',
        headers
      },
      (res) => {
        let body = '';
        res.setEncoding('utf8');
        res.on('data', (chunk) => {
          body += chunk;
        });
        res.on('end', () => {
          resolve({
            statusCode: res.statusCode,
            headers: res.headers,
            body
          });
        });
      }
    );
    req.on('error', reject);
    req.end();
  });
}

const server = http.createServer((req, res) => {
  const url = new URL(req.url, 'http://localhost');
  const pathname = decodeURIComponent(url.pathname);
  const testCase = url.searchParams.get('case');

  if (testCase === 'basic') {
    const stream = send(req, pathname, { root: PUBLIC_DIR });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'custom-index') {
    const handler = createStaticServer(PUBLIC_DIR, { index: 'home.html' });
    handler(req, res);
  } else if (testCase === 'extensions') {
    const stream = send(req, pathname, { root: PUBLIC_DIR, extensions: ['html', 'txt'] });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'immutable') {
    const stream = send(req, pathname, { root: PUBLIC_DIR, immutable: true, maxAge: 86400000 });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'conditional-etag') {
    const stream = send(req, pathname, { root: PUBLIC_DIR });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'range') {
    const stream = send(req, pathname, { root: PUBLIC_DIR });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'no-ranges') {
    const stream = send(req, pathname, { root: PUBLIC_DIR, acceptRanges: false });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'suppressed-headers') {
    const stream = send(req, pathname, {
      root: PUBLIC_DIR,
      cacheControl: false,
      etag: false,
      lastModified: false
    });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'not-found') {
    const stream = send(req, pathname, { root: PUBLIC_DIR });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'dotfiles-ignore') {
    const stream = send(req, pathname, { root: PUBLIC_DIR, dotfiles: 'ignore' });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'dotfiles-deny') {
    const stream = send(req, pathname, { root: PUBLIC_DIR, dotfiles: 'deny' });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else if (testCase === 'directory-event') {
    const stream = send(req, pathname, { root: PUBLIC_DIR, index: false });
    stream.on('directory', () => {
      res.statusCode = 200;
      res.setHeader('X-Directory-Event', 'true');
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end('Directory listing handled');
    });
    stream.on('error', (err) => {
      res.statusCode = err.status || 500;
      res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
      res.end(err.message);
    });
    stream.pipe(res);
  } else {
    res.statusCode = 400;
    res.end('Unknown case');
  }
});

async function runContractTests() {
  await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
  const port = server.address().port;

  try {
    // 1. send(req, path, { root }) streams the static file to HTTP response with correct headers
    {
      const res = await request(port, '/home.html?case=basic');
      assert.equal(res.statusCode, 200, 'Expected 200 OK');
      assert.match(res.body, /Home Page/, 'Body must match file content');
      assert.equal(res.headers['content-type'], 'text/html; charset=UTF-8');
      assert.ok(res.headers['content-length'], 'Content-Length must be present');
      assert.ok(res.headers['etag'], 'ETag must be present');
      assert.ok(res.headers['last-modified'], 'Last-Modified must be present');
      assert.equal(res.headers['accept-ranges'], 'bytes');
    }

    // 2. send(req, path, { root, index: 'home.html' }) serves custom index file when requesting a directory
    {
      const res = await request(port, '/?case=custom-index');
      assert.equal(res.statusCode, 200, 'Expected 200 OK for custom index');
      assert.match(res.body, /Home Page/, 'Body must match home.html');
      assert.equal(res.headers['content-type'], 'text/html; charset=UTF-8');
    }

    // 3. send(req, path, { root, extensions: ['html', 'txt'] }) serves file with matching extension when omitted from path
    {
      const res = await request(port, '/docs?case=extensions');
      assert.equal(res.statusCode, 200, 'Expected 200 OK for extension match');
      assert.match(res.body, /Sample documentation content/, 'Body must match docs.txt');
      assert.equal(res.headers['content-type'], 'text/plain; charset=UTF-8');
    }

    // 4. send(req, path, { root, immutable: true, maxAge: 86400000 }) sets Cache-Control header with max-age and immutable directive
    {
      const res = await request(port, '/app.js?case=immutable');
      assert.equal(res.statusCode, 200, 'Expected 200 OK for immutable resource');
      assert.equal(res.headers['cache-control'], 'public, max-age=86400, immutable');
    }

    // 5. send(req, path, { root }) returns HTTP 304 Not Modified for conditional GET request when If-None-Match matches ETag
    {
      const initial = await request(port, '/home.html?case=conditional-etag');
      const etag = initial.headers['etag'];
      assert.ok(etag, 'ETag must be returned');

      const conditional = await request(port, '/home.html?case=conditional-etag', {
        'if-none-match': etag
      });
      assert.equal(conditional.statusCode, 304, 'Expected 304 Not Modified');
      assert.equal(conditional.body, '', '304 response must have empty body');
    }

    // 6. send(req, path, { root }) returns HTTP 206 Partial Content with Content-Range header for Range byte request
    {
      const res = await request(port, '/docs.txt?case=range', {
        range: 'bytes=0-5'
      });
      assert.equal(res.statusCode, 206, 'Expected 206 Partial Content');
      assert.ok(res.headers['content-range'], 'Content-Range must be present');
      assert.equal(res.body, 'Sample');
    }

    // 7. send(req, path, { root, acceptRanges: false }) omits Accept-Ranges header and ignores Range request headers
    {
      const res = await request(port, '/docs.txt?case=no-ranges', {
        range: 'bytes=0-5'
      });
      assert.equal(res.statusCode, 200, 'Expected 200 OK when ranges are disabled');
      assert.equal(res.headers['accept-ranges'], undefined, 'Accept-Ranges must be omitted');
      assert.match(res.body, /Sample documentation content/, 'Full content must be returned');
    }

    // 8. send(req, path, { root, cacheControl: false, etag: false, lastModified: false }) suppresses Cache-Control, ETag, and Last-Modified headers
    {
      const res = await request(port, '/docs.txt?case=suppressed-headers');
      assert.equal(res.statusCode, 200, 'Expected 200 OK');
      assert.equal(res.headers['cache-control'], undefined, 'Cache-Control header must be omitted');
      assert.equal(res.headers['etag'], undefined, 'ETag header must be omitted');
      assert.equal(res.headers['last-modified'], undefined, 'Last-Modified header must be omitted');
    }

    // 9. send(req, path, { root }) emits an error with status 404 when requested file does not exist
    {
      const res = await request(port, '/nonexistent.txt?case=not-found');
      assert.equal(res.statusCode, 404, 'Expected 404 Not Found');
    }

    // 10. send(req, path, { root, dotfiles: 'ignore' }) emits an error with status 404 when accessing dotfiles with ignore option
    {
      const res = await request(port, '/.secret?case=dotfiles-ignore');
      assert.equal(res.statusCode, 404, 'Expected 404 Not Found for ignored dotfile');
    }

    // 11. send(req, path, { root, dotfiles: 'deny' }) emits an error with status 403 when accessing dotfiles with deny option
    {
      const res = await request(port, '/.secret?case=dotfiles-deny');
      assert.equal(res.statusCode, 403, 'Expected 403 Forbidden for denied dotfile');
    }

    // 12. send(req, path, { root, index: false }).on('directory', fn) emits directory event when requesting directory with index disabled
    {
      const res = await request(port, '/subdir?case=directory-event');
      assert.equal(res.statusCode, 200, 'Expected 200 OK handled by directory event');
      assert.equal(res.headers['x-directory-event'], 'true', 'Custom directory header must be present');
      assert.equal(res.body, 'Directory listing handled');
    }

    console.log('All 12 contract assertions passed.');
  } finally {
    server.close();
  }
}

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

Origin Seeder

anonymous