CodeSampleX

Exemple

hosted-git-info 8.1.0: fromUrl

Échantillon vérifié pour npm hosted-git-info 8.1.0: fromUrl. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:943264d94ce6a8a2886a0f0d8b11fa9071117f71689d57bd803b034c0242ec34

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-20

Cas

HOW
Objectif
verify hosted-git-info.fromUrl in pkg:npm/hosted-git-info@8.1.0
Paquets
Symboles
  • hosted-git-info.fromUrl
Créé
2026-09-20T06:55:25Z

Contrat

  1. hosted-git-info.fromUrl is exported as a function
  2. hosted-git-info.fromUrl parses standard HTTPS GitHub repository URLs and extracts user and project
  3. hosted-git-info.fromUrl parses git protocol URLs and committish fragments for GitHub repositories
  4. hosted-git-info.fromUrl parses git shortcut strings such as github:user/repo
  5. hosted-git-info.fromUrl parses GitLab and Bitbucket repository shortcuts correctly
  6. hosted-git-info.fromUrl returns undefined for unsupported hosts or malformed inputs

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 hosted-git-info.fromUrl in pkg:npm/hosted-git-info@8.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/hosted-git-info@8.1.0
Demonstrate these symbols/APIs:
  - hosted-git-info.fromUrl

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:2a9fafdd7938eb1306e0dc9b477bb9a03f39b173e2591416792edd54270474d8","contract":["hosted-git-info.fromUrl is exported as a function","hosted-git-info.fromUrl parses standard HTTPS GitHub repository URLs and extracts user and project","hosted-git-info.fromUrl parses git protocol URLs and committish fragments for GitHub repositories","hosted-git-info.fromUrl parses git shortcut strings such as github:user/repo","hosted-git-info.fromUrl parses GitLab and Bitbucket repository shortcuts correctly","hosted-git-info.fromUrl returns undefined for unsupported hosts or malformed inputs"],"goal":"verify hosted-git-info.fromUrl in pkg:npm/hosted-git-info@8.1.0","kind":"HOW","packages":["pkg:npm/hosted-git-info@8.1.0"],"schemaVersion":1,"symbols":["hosted-git-info.fromUrl"]},"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/hosted-git-info@8.1.0"],"schemaVersion":1,"subject":"pkg:npm/hosted-git-info@8.1.0","symbols":["hosted-git-info.fromUrl"],"verifierAdapter":"node-typescript@1"}
index.mjs
import hostedGitInfo from 'hosted-git-info';

export const fromUrl = hostedGitInfo.fromUrl;

/**
 * Parses a git repository URL and returns a GitHost instance or undefined.
 *
 * @param {string} gitUrl - The repository URL or shorthand.
 * @param {object} [opts] - Optional parsing options.
 * @returns {object|undefined} Parsed GitHost instance or undefined if unsupported.
 */
export function parseGitUrl(gitUrl, opts) {
  return hostedGitInfo.fromUrl(gitUrl, opts);
}

export default hostedGitInfo;
package-lock.json
{
  "name": "sample-hosted-git-info-from-url",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hosted-git-info-from-url",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "hosted-git-info": "8.1.0"
      }
    },
    "node_modules/hosted-git-info": {
      "version": "8.1.0",
      "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-8.1.0.tgz",
      "integrity": "sha512-Rw/B2DNQaPBICNXEm8balFz9a6WpZrkCGpcWFpy7nCj+NyhSdqXipmfvtmWt9xGfp0wZnBxB+iVpLmQMYt47Tw==",
      "license": "ISC",
      "dependencies": {
        "lru-cache": "^10.0.1"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/lru-cache": {
      "version": "10.4.3",
      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
      "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-hosted-git-info-from-url",
  "version": "1.0.0",
  "type": "module",
  "main": "index.mjs",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "hosted-git-info": "8.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify hosted-git-info.fromUrl in pkg:npm/hosted-git-info@8.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/hosted-git-info@8.1.0"
  ],
  "symbols": [
    "hosted-git-info.fromUrl"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import hostedGitInfo from 'hosted-git-info';
import { fromUrl, parseGitUrl } from '../index.mjs';

// 1. hosted-git-info.fromUrl is exported as a function
assert.equal(typeof hostedGitInfo.fromUrl, 'function');
assert.equal(typeof fromUrl, 'function');
assert.equal(typeof parseGitUrl, 'function');

// 2. hosted-git-info.fromUrl parses standard HTTPS GitHub repository URLs and extracts user and project
const infoHttps = fromUrl('https://github.com/example-user/example-repo.git');
assert.ok(infoHttps);
assert.equal(infoHttps.type, 'github');
assert.equal(infoHttps.user, 'example-user');
assert.equal(infoHttps.project, 'example-repo');
assert.equal(infoHttps.default, 'https');
assert.equal(infoHttps.https(), 'git+https://github.com/example-user/example-repo.git');
assert.equal(infoHttps.browse(), 'https://github.com/example-user/example-repo');
assert.equal(infoHttps.shortcut(), 'github:example-user/example-repo');

// 3. hosted-git-info.fromUrl parses git protocol URLs and committish fragments for GitHub repositories
const infoGit = fromUrl('git://github.com/example-user/example-repo.git#v1.0.0');
assert.ok(infoGit);
assert.equal(infoGit.type, 'github');
assert.equal(infoGit.user, 'example-user');
assert.equal(infoGit.project, 'example-repo');
assert.equal(infoGit.committish, 'v1.0.0');
assert.equal(infoGit.browse(), 'https://github.com/example-user/example-repo/tree/v1.0.0');

// 4. hosted-git-info.fromUrl parses git shortcut strings such as github:user/repo
const infoShortcut = fromUrl('github:example-user/example-repo#main');
assert.ok(infoShortcut);
assert.equal(infoShortcut.type, 'github');
assert.equal(infoShortcut.user, 'example-user');
assert.equal(infoShortcut.project, 'example-repo');
assert.equal(infoShortcut.committish, 'main');
assert.equal(infoShortcut.default, 'shortcut');
assert.equal(infoShortcut.shortcut(), 'github:example-user/example-repo#main');
assert.equal(infoShortcut.browse(), 'https://github.com/example-user/example-repo/tree/main');

// 5. hosted-git-info.fromUrl parses GitLab and Bitbucket repository shortcuts correctly
const infoGitlab = fromUrl('gitlab:example-group/example-repo');
assert.ok(infoGitlab);
assert.equal(infoGitlab.type, 'gitlab');
assert.equal(infoGitlab.user, 'example-group');
assert.equal(infoGitlab.project, 'example-repo');
assert.equal(infoGitlab.default, 'shortcut');
assert.equal(infoGitlab.shortcut(), 'gitlab:example-group/example-repo');

const infoBitbucket = fromUrl('bitbucket:example-owner/example-repo');
assert.ok(infoBitbucket);
assert.equal(infoBitbucket.type, 'bitbucket');
assert.equal(infoBitbucket.user, 'example-owner');
assert.equal(infoBitbucket.project, 'example-repo');
assert.equal(infoBitbucket.default, 'shortcut');
assert.equal(infoBitbucket.shortcut(), 'bitbucket:example-owner/example-repo');

// 6. hosted-git-info.fromUrl returns undefined for unsupported hosts or malformed inputs
assert.equal(fromUrl('https://example.com/not-a-repo'), undefined);
assert.equal(fromUrl('invalid-url-string'), undefined);
assert.equal(fromUrl(null), undefined);
assert.equal(fromUrl(undefined), undefined);
assert.equal(fromUrl(123), undefined);

// 7. module index wrapper matches hostedGitInfo.fromUrl output
assert.equal(parseGitUrl('https://example.com/not-a-repo'), undefined);
const wrappedInfo = parseGitUrl('https://github.com/example-user/example-repo.git');
assert.ok(wrappedInfo);
assert.equal(wrappedInfo.project, 'example-repo');

console.log('All hosted-git-info.fromUrl contract assertions passed.');

Seeder d'origine

anonyme