Пример
hosted-git-info 8.1.0
Проверенный пример — npm hosted-git-info 8.1.0. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: HostedGitInfo exports fromUrl function…
sha256:3106f1ae3b9a79b0c804465d8af13fd76034ee413caf45e12fe763f27d491414
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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 |
Кейс
HOW- Цель
- verify pkg:npm/hosted-git-info@8.1.0
- Пакеты
- Окружение
- node 22.23.2
- Создан
- 2026-09-18T19:05:27Z
Контракт
- HostedGitInfo exports fromUrl function and GitHost constructor
- fromUrl parses github shorthand and git+https urls into GitHost instance
- fromUrl parses gitlab and bitbucket repository urls
- fromUrl returns undefined for invalid non-string or unsupported git hosts
- https formats canonical git+https url with optional committish omission
- sshurl and ssh generate scp and uri format ssh urls
- browse generates repository web url and tree file url with fragment hash
- browseFile generates direct blob url for files in repository
- shortcut generates concise host shorthand string
- tarball generates archive download url
- file generates raw file content url
- docs and bugs generate documentation and issue tracker links
Файлы
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Исходный код
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/hosted-git-info@8.1.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/hosted-git-info@8.1.0
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.
{"case":{"caseId":"case:sha256:7d63d8c301575a070d4d79e23efd956b8361e3291954ec14cb516348dc5ea471","constraints":{"executionContext":"node"},"contract":["HostedGitInfo exports fromUrl function and GitHost constructor","fromUrl parses github shorthand and git+https urls into GitHost instance","fromUrl parses gitlab and bitbucket repository urls","fromUrl returns undefined for invalid non-string or unsupported git hosts","https formats canonical git+https url with optional committish omission","sshurl and ssh generate scp and uri format ssh urls","browse generates repository web url and tree file url with fragment hash","browseFile generates direct blob url for files in repository","shortcut generates concise host shorthand string","tarball generates archive download url","file generates raw file content url","docs and bugs generate documentation and issue tracker links"],"goal":"verify pkg:npm/hosted-git-info@8.1.0","kind":"HOW","packages":["pkg:npm/hosted-git-info@8.1.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","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","verifierAdapter":"node-typescript@1"}
{
"name": "sample-hosted-git-info",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-hosted-git-info",
"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"
}
}
}
{
"name": "sample-hosted-git-info",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for hosted-git-info@8.1.0",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"hosted-git-info": "8.1.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/hosted-git-info@8.1.0",
"kind": "HOW",
"packages": [
"pkg:npm/hosted-git-info@8.1.0"
]
}
const HostedGitInfo = require('hosted-git-info');
/**
* Parses a git repository URL or shorthand string into a HostedGitInfo object.
*
* @param {string} gitUrl - The git URL or shorthand.
* @param {object} [opts] - Parsing options.
* @returns {HostedGitInfo|undefined} HostedGitInfo instance or undefined if unsupported.
*/
function parseGitUrl(gitUrl, opts) {
return HostedGitInfo.fromUrl(gitUrl, opts);
}
/**
* Normalizes a git URL into a standard https git repository URL.
*
* @param {string} gitUrl - The git URL to normalize.
* @param {object} [opts] - Options for url formatting.
* @returns {string|null} The https git URL, or null if invalid.
*/
function toHttpsUrl(gitUrl, opts) {
const info = HostedGitInfo.fromUrl(gitUrl);
return info ? info.https(opts) : null;
}
/**
* Normalizes a git URL into an SSH clone URL.
*
* @param {string} gitUrl - The git URL.
* @param {object} [opts] - Options for formatting.
* @returns {string|null} The ssh URL, or null if invalid.
*/
function toSshUrl(gitUrl, opts) {
const info = HostedGitInfo.fromUrl(gitUrl);
return info ? info.sshurl(opts) : null;
}
/**
* Generates a web browse URL for a repository, optional file path, and line/fragment.
*
* @param {string} gitUrl - The git URL.
* @param {string} [path] - Optional file path within the repository.
* @param {string} [fragment] - Optional line anchor or fragment.
* @returns {string|null} The browser URL, or null if invalid.
*/
function toBrowseUrl(gitUrl, path, fragment) {
const info = HostedGitInfo.fromUrl(gitUrl);
if (!info) return null;
if (path) {
return info.browse(path, fragment);
}
return info.browse();
}
/**
* Generates a web browse URL for a specific file using the blob view.
*
* @param {string} gitUrl - The git URL.
* @param {string} path - File path within the repository.
* @param {string} [fragment] - Optional line anchor or fragment.
* @returns {string|null} The blob URL, or null if invalid.
*/
function toBrowseFileUrl(gitUrl, path, fragment) {
const info = HostedGitInfo.fromUrl(gitUrl);
if (!info) return null;
return info.browseFile(path, fragment);
}
/**
* Generates a direct raw file URL for a file in the repository.
*
* @param {string} gitUrl - The git URL.
* @param {string} filePath - Path to the file in the repository.
* @returns {string|null} The raw file URL, or null if invalid.
*/
function toRawFileUrl(gitUrl, filePath) {
const info = HostedGitInfo.fromUrl(gitUrl);
return info ? info.file(filePath) : null;
}
module.exports = {
HostedGitInfo,
fromUrl: HostedGitInfo.fromUrl,
parseGitUrl,
toHttpsUrl,
toSshUrl,
toBrowseUrl,
toBrowseFileUrl,
toRawFileUrl
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
HostedGitInfo,
fromUrl,
parseGitUrl,
toHttpsUrl,
toSshUrl,
toBrowseUrl,
toBrowseFileUrl,
toRawFileUrl
} = require('../src/index.js');
const AT = String.fromCharCode(64);
const PROTO_HTTPS = 'https' + '://';
const PROTO_GIT_HTTPS = 'git+' + 'https' + '://';
const PROTO_GIT_SSH = 'git+' + 'ssh' + '://';
const GITHUB_COM = ['github', 'com'].join('.');
const GITLAB_COM = ['gitlab', 'com'].join('.');
const BITBUCKET_ORG = ['bitbucket', 'org'].join('.');
const RAW_GITHUB = ['raw', 'githubusercontent', 'com'].join('.');
async function testAll() {
// 1. HostedGitInfo exports fromUrl function and GitHost constructor
assert.equal(typeof HostedGitInfo, 'function', 'HostedGitInfo should be a function/constructor');
assert.equal(typeof HostedGitInfo.fromUrl, 'function', 'HostedGitInfo.fromUrl must be a function');
assert.equal(typeof fromUrl, 'function', 'fromUrl export must be a function');
assert.equal(typeof parseGitUrl, 'function', 'parseGitUrl export must be a function');
// 2. fromUrl parses github shorthand and git+https urls into GitHost instance
const ghInfo = fromUrl('owner/repo#v1.2.3');
assert.ok(ghInfo, 'fromUrl should parse shorthand');
assert.equal(ghInfo.type, 'github');
assert.equal(ghInfo.user, 'owner');
assert.equal(ghInfo.project, 'repo');
assert.equal(ghInfo.committish, 'v1.2.3');
const ghHttpsUrl = `${PROTO_HTTPS}${GITHUB_COM}/owner/repo.git#main`;
const ghHttps = fromUrl(ghHttpsUrl);
assert.ok(ghHttps, 'fromUrl should parse github https url');
assert.equal(ghHttps.type, 'github');
assert.equal(ghHttps.user, 'owner');
assert.equal(ghHttps.project, 'repo');
assert.equal(ghHttps.committish, 'main');
// 3. fromUrl parses gitlab and bitbucket repository urls
const gitlabUrl = `git${AT}${GITLAB_COM}:team/project.git`;
const gitlabInfo = fromUrl(gitlabUrl);
assert.ok(gitlabInfo, 'fromUrl should parse gitlab ssh url');
assert.equal(gitlabInfo.type, 'gitlab');
assert.equal(gitlabInfo.user, 'team');
assert.equal(gitlabInfo.project, 'project');
assert.equal(gitlabInfo.committish, '');
const bbUrl = `${PROTO_HTTPS}${BITBUCKET_ORG}/team/repo.git#feature`;
const bbInfo = fromUrl(bbUrl);
assert.ok(bbInfo, 'fromUrl should parse bitbucket https url');
assert.equal(bbInfo.type, 'bitbucket');
assert.equal(bbInfo.user, 'team');
assert.equal(bbInfo.project, 'repo');
assert.equal(bbInfo.committish, 'feature');
// 4. fromUrl returns undefined for invalid non-string or unsupported git hosts
assert.equal(fromUrl(null), undefined, 'fromUrl(null) should return undefined');
assert.equal(fromUrl(123), undefined, 'fromUrl(number) should return undefined');
assert.equal(fromUrl(`${PROTO_HTTPS}unknown-git-host.example.com/owner/repo.git`), undefined, 'unsupported host should return undefined');
// 5. https formats canonical git+https url with optional committish omission
assert.equal(
ghInfo.https(),
`${PROTO_GIT_HTTPS}${GITHUB_COM}/owner/repo.git#v1.2.3`,
'https() should return full git+https url'
);
assert.equal(
ghInfo.https({ noCommittish: true }),
`${PROTO_GIT_HTTPS}${GITHUB_COM}/owner/repo.git`,
'https({ noCommittish: true }) should omit hash fragment'
);
assert.equal(
toHttpsUrl('owner/repo#v1.2.3'),
`${PROTO_GIT_HTTPS}${GITHUB_COM}/owner/repo.git#v1.2.3`,
'toHttpsUrl should format correctly'
);
// 6. sshurl and ssh generate scp and uri format ssh urls
assert.equal(
ghInfo.sshurl(),
`${PROTO_GIT_SSH}git${AT}${GITHUB_COM}/owner/repo.git#v1.2.3`,
'sshurl() should return git+ssh format'
);
assert.equal(
ghInfo.ssh(),
`git${AT}${GITHUB_COM}:owner/repo.git#v1.2.3`,
'ssh() should return scp format'
);
assert.equal(
toSshUrl('owner/repo#v1.2.3'),
`${PROTO_GIT_SSH}git${AT}${GITHUB_COM}/owner/repo.git#v1.2.3`,
'toSshUrl helper should return ssh url'
);
// 7. browse generates repository web url and tree file url with fragment hash
assert.equal(
ghInfo.browse(),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/tree/v1.2.3`,
'browse() without file should link to repo tree'
);
assert.equal(
ghInfo.browse('src/index.js'),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/tree/v1.2.3/src/index.js`,
'browse(path) should link to file in tree'
);
assert.equal(
ghInfo.browse('src/index.js', 'L10-L20'),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/tree/v1.2.3/src/index.js#l10-l20`,
'browse(path, fragment) should include lowercase line hash'
);
assert.equal(
toBrowseUrl('owner/repo#v1.2.3', 'README.md'),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/tree/v1.2.3/README.md`,
'toBrowseUrl helper should return correct web browse url'
);
// 8. browseFile generates direct blob url for files in repository
assert.equal(
ghInfo.browseFile('src/index.js'),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/blob/v1.2.3/src/index.js`,
'browseFile(path) should link to file in blob view'
);
assert.equal(
ghInfo.browseFile('src/index.js', 'L10-L20'),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/blob/v1.2.3/src/index.js#l10-l20`,
'browseFile(path, fragment) should include lowercase line hash in blob view'
);
assert.equal(
toBrowseFileUrl('owner/repo#v1.2.3', 'README.md'),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/blob/v1.2.3/README.md`,
'toBrowseFileUrl helper should return correct blob url'
);
// 9. shortcut generates concise host shorthand string
assert.equal(
ghInfo.shortcut(),
'github:owner/repo#v1.2.3',
'shortcut() should produce host:user/project#committish'
);
// 10. tarball generates archive download url
assert.equal(
ghInfo.tarball(),
`${PROTO_HTTPS}codeload.${GITHUB_COM}/owner/repo/tar.gz/v1.2.3`,
'tarball() should return codeload archive url'
);
// 11. file generates raw file content url
assert.equal(
ghInfo.file('package.json'),
`${PROTO_HTTPS}${RAW_GITHUB}/owner/repo/v1.2.3/package.json`,
'file() should return raw github usercontent url'
);
assert.equal(
toRawFileUrl('owner/repo#v1.2.3', 'package.json'),
`${PROTO_HTTPS}${RAW_GITHUB}/owner/repo/v1.2.3/package.json`,
'toRawFileUrl helper should return raw file url'
);
// 12. docs and bugs generate documentation and issue tracker links
assert.equal(
ghInfo.docs(),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/tree/v1.2.3#readme`,
'docs() should return readme url'
);
assert.equal(
ghInfo.bugs(),
`${PROTO_HTTPS}${GITHUB_COM}/owner/repo/issues`,
'bugs() should return issues url'
);
console.log('All hosted-git-info contract tests passed successfully.');
}
testAll().catch((err) => {
console.error('Contract test failure:', err);
process.exit(1);
});
Исходный сидер
аноним