CodeSampleX

샘플

get-uri 6.0.5: getUri, isValidProtocol

검증된 샘플 — npm get-uri 6.0.5: getUri, isValidProtocol. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: isValidProtocol returns true for built-in…

sha256:2ccf09d38e20a35672d06a936b6c10e1fd7b57c43874b2891f22c797799ac6df

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify pkg:npm/get-uri@6.0.5
패키지
심벌
  • getUri
  • isValidProtocol
생성일
2026-08-23T15:37:07Z

컨트랙트

  1. isValidProtocol returns true for built-in protocols and false for unsupported protocols
  2. getUri reads data URIs into a Readable stream outputting the decoded payload
  3. getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged data URI
  4. getUri reads local file URIs into a Readable stream outputting the file content
  5. getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged file URI
  6. getUri throws TypeError when passed an empty URI
  7. getUri throws TypeError when passed a URI with an unsupported protocol
  8. getUri throws ENOTFOUND error when attempting to read a non-existent file URI

파일

  • 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/get-uri@6.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/get-uri@6.0.5

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:d161b35701bf5155997ac0a3277bcba2a64ff5866717f811bb4128b490eec9ea","contract":["isValidProtocol returns true for built-in protocols and false for unsupported protocols","getUri reads data URIs into a Readable stream outputting the decoded payload","getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged data URI","getUri reads local file URIs into a Readable stream outputting the file content","getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged file URI","getUri throws TypeError when passed an empty URI","getUri throws TypeError when passed a URI with an unsupported protocol","getUri throws ENOTFOUND error when attempting to read a non-existent file URI"],"goal":"verify pkg:npm/get-uri@6.0.5","kind":"HOW","packages":["pkg:npm/get-uri@6.0.5"],"schemaVersion":1,"symbols":["getUri","isValidProtocol"]},"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/get-uri@6.0.5"],"schemaVersion":1,"subject":"pkg:npm/get-uri@6.0.5","symbols":["getUri","isValidProtocol"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-get-uri",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-get-uri",
      "version": "1.0.0",
      "dependencies": {
        "get-uri": "6.0.5"
      }
    },
    "node_modules/basic-ftp": {
      "version": "5.3.1",
      "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.3.1.tgz",
      "integrity": "sha512-bopVNp6ugyA150DDuZfPFdt1KZ5a94ZDiwX4hMgZDzF+GttD80lEy8kj98kbyhLXnPvhtIo93mdnLIjpCAeeOw==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    },
    "node_modules/data-uri-to-buffer": {
      "version": "6.0.2",
      "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz",
      "integrity": "sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==",
      "license": "MIT",
      "engines": {
        "node": ">= 14"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/get-uri": {
      "version": "6.0.5",
      "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.5.tgz",
      "integrity": "sha512-b1O07XYq8eRuVzBNgJLstU6FYc1tS6wnMtF1I1D9lE8LxZSOGZ7LhxN54yPP6mGw5f2CkXY2BQUL9Fx41qvcIg==",
      "license": "MIT",
      "dependencies": {
        "basic-ftp": "^5.0.2",
        "data-uri-to-buffer": "^6.0.2",
        "debug": "^4.3.4"
      },
      "engines": {
        "node": ">= 14"
      }
    },
    "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"
    }
  }
}
package.json
{
  "name": "sample-get-uri",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "get-uri": "6.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/get-uri@6.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/get-uri@6.0.5"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { promises as fs } from 'node:fs';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { getUri, isValidProtocol, protocols } from 'get-uri';

async function streamToBuffer(stream) {
  const chunks = [];
  for await (const chunk of stream) {
    chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
  }
  return Buffer.concat(chunks);
}

// 1. isValidProtocol returns true for built-in protocols and false for unsupported protocols
assert.equal(isValidProtocol('data'), true);
assert.equal(isValidProtocol('file'), true);
assert.equal(isValidProtocol('ftp'), true);
assert.equal(isValidProtocol('http'), true);
assert.equal(isValidProtocol('https'), true);
assert.equal(isValidProtocol('unsupported'), false);
assert.ok(typeof protocols.data === 'function');
assert.ok(typeof protocols.file === 'function');

// 2. getUri reads data URIs into a Readable stream outputting the decoded payload
const dataUri = 'data:text/plain;charset=utf-8,Hello%20World';
const dataStream = await getUri(dataUri);
const dataPayload = await streamToBuffer(dataStream);
assert.equal(dataPayload.toString('utf8'), 'Hello World');

// 3. getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged data URI
await assert.rejects(
  async () => {
    await getUri(dataUri, { cache: dataStream });
  },
  (err) => {
    assert.equal(err.code, 'ENOTMODIFIED');
    return true;
  }
);

// 4. getUri reads local file URIs into a Readable stream outputting the file content
const tempFilePath = path.resolve('test-temp.txt');
await fs.writeFile(tempFilePath, 'contract test content', 'utf8');

try {
  const fileUri = pathToFileURL(tempFilePath).href;
  const fileStream = await getUri(fileUri);
  const filePayload = await streamToBuffer(fileStream);
  assert.equal(filePayload.toString('utf8'), 'contract test content');

  // 5. getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged file URI
  await assert.rejects(
    async () => {
      await getUri(fileUri, { cache: fileStream });
    },
    (err) => {
      assert.equal(err.code, 'ENOTMODIFIED');
      return true;
    }
  );
} finally {
  await fs.unlink(tempFilePath).catch(() => {});
}

// 6. getUri throws TypeError when passed an empty URI
await assert.rejects(
  async () => {
    await getUri('');
  },
  {
    name: 'TypeError',
    message: 'Must pass in a URI to "getUri()"'
  }
);

// 7. getUri throws TypeError when passed a URI with an unsupported protocol
await assert.rejects(
  async () => {
    await getUri('gopher://localhost/test');
  },
  {
    name: 'TypeError',
    message: 'Unsupported protocol "gopher" specified in URI: "gopher://localhost/test"'
  }
);

// 8. getUri throws ENOTFOUND error when attempting to read a non-existent file URI
const nonExistentUri = pathToFileURL(path.resolve('non-existent-contract-file.txt')).href;
await assert.rejects(
  async () => {
    await getUri(nonExistentUri);
  },
  (err) => {
    assert.equal(err.code, 'ENOTFOUND');
    return true;
  }
);

오리진 시더

익명