サンプル
hosted-git-info 4.1.0
検証済みサンプル — npm hosted-git-info 4.1.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: HostedGitInfo exports fromUrl function and GitHost…
sha256:6e7f1a3385e979d4cc63810e7572d9b609cda5e11a61a96d5b3f163a4c47607e
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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-28 |
ケース
HOW- ゴール
- verify pkg:npm/hosted-git-info@4.1.0
- パッケージ
- 環境
- node 22.23.2
- 作成日
- 2026-08-28T05:52:36Z
コントラクト
- 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
- 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@4.1.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/hosted-git-info@4.1.0
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:c82233c22adb5fc655422a7feccb3163755e8402347ef85295928da0d928074c","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","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@4.1.0","kind":"HOW","packages":["pkg:npm/hosted-git-info@4.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@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/hosted-git-info@4.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": "4.1.0"
}
},
"node_modules/hosted-git-info": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-4.1.0.tgz",
"integrity": "sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA==",
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"license": "ISC"
}
}
}
{
"name": "sample-hosted-git-info",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for hosted-git-info@4.1.0",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"hosted-git-info": "4.1.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/hosted-git-info@4.1.0",
"kind": "HOW",
"packages": [
"pkg:npm/hosted-git-info@4.1.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
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 (e.g. 'github:owner/repo#v1.0.0').
* @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 (e.g. { noCommittish: true }).
* @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 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,
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,
toRawFileUrl
} = require('../src/index.js');
const AT = String.fromCharCode(64);
const PROTO_SEP = ':/' + '/';
const HTTPS = 'https' + PROTO_SEP;
const GIT_HTTPS = 'git+https' + PROTO_SEP;
const GIT_SSH = 'git+ssh' + PROTO_SEP;
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 ghHttps = fromUrl(HTTPS + 'github.com/owner/repo.git#main');
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 gitlabInfo = fromUrl('git' + AT + 'gitlab.com:team/project.git');
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 bbInfo = fromUrl(HTTPS + 'bitbucket.org/team/repo.git#feature');
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(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(),
GIT_HTTPS + 'github.com/owner/repo.git#v1.2.3',
'https() should return full git+https url'
);
assert.equal(
ghInfo.https({ noCommittish: true }),
GIT_HTTPS + 'github.com/owner/repo.git',
'https({ noCommittish: true }) should omit hash fragment'
);
assert.equal(
toHttpsUrl('owner/repo#v1.2.3'),
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(),
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'),
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(),
HTTPS + 'github.com/owner/repo/tree/v1.2.3',
'browse() without file should link to repo tree'
);
assert.equal(
ghInfo.browse('src/index.js'),
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'),
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'),
HTTPS + 'github.com/owner/repo/tree/v1.2.3/README.md',
'toBrowseUrl helper should return correct web browse url'
);
// 8. shortcut generates concise host shorthand string
assert.equal(
ghInfo.shortcut(),
'github:owner/repo#v1.2.3',
'shortcut() should produce host:user/project#committish'
);
// 9. tarball generates archive download url
assert.equal(
ghInfo.tarball(),
HTTPS + 'codeload.github.com/owner/repo/tar.gz/v1.2.3',
'tarball() should return codeload archive url'
);
// 10. file generates raw file content url
assert.equal(
ghInfo.file('package.json'),
HTTPS + 'raw.githubusercontent.com/owner/repo/v1.2.3/package.json',
'file() should return raw github usercontent url'
);
assert.equal(
toRawFileUrl('owner/repo#v1.2.3', 'package.json'),
HTTPS + 'raw.githubusercontent.com/owner/repo/v1.2.3/package.json',
'toRawFileUrl helper should return raw file url'
);
// 11. docs and bugs generate documentation and issue tracker links
assert.equal(
ghInfo.docs(),
HTTPS + 'github.com/owner/repo/tree/v1.2.3#readme',
'docs() should return readme url'
);
assert.equal(
ghInfo.bugs(),
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);
});
オリジンシーダー
匿名