示例
pathe 2.0.3: resolve
已验证示例 — npm pathe 2.0.3: resolve. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: pathe.resolve resolves multiple path segments into a normalized…
sha256:52a9f5b4160a1ec69563512e658e53ba187df95789245d25ad58a482df5f607e
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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-26 |
案例
HOW- 目标
- verify pathe.resolve in pkg:npm/pathe@2.0.3
- 符号
-
- pathe.resolve
- 创建时间
- 2026-08-26T10:49:51Z
契约
- pathe.resolve resolves multiple path segments into a normalized POSIX path string
- pathe.resolve resolves relative path segments and parent directory navigation (..)
- pathe.resolve processes paths from right to left until an absolute path is constructed
- pathe.resolve strips trailing slashes from resolved paths unless resolving to root directory
- pathe.resolve normalizes redundant slashes and relative dot segments
- pathe.resolve defaults to the current working directory in POSIX format when given empty or no arguments
- pathe.resolve ignores empty string segments between non-empty path arguments
文件
- 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 pathe.resolve in pkg:npm/pathe@2.0.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/pathe@2.0.3
Demonstrate these symbols/APIs:
- pathe.resolve
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:3a2a6c2f7d37c0c0bd325a20386fd774557a8d1794c233fd1ba96e117a194392","contract":["pathe.resolve resolves multiple path segments into a normalized POSIX path string","pathe.resolve resolves relative path segments and parent directory navigation (..)","pathe.resolve processes paths from right to left until an absolute path is constructed","pathe.resolve strips trailing slashes from resolved paths unless resolving to root directory","pathe.resolve normalizes redundant slashes and relative dot segments","pathe.resolve defaults to the current working directory in POSIX format when given empty or no arguments","pathe.resolve ignores empty string segments between non-empty path arguments"],"goal":"verify pathe.resolve in pkg:npm/pathe@2.0.3","kind":"HOW","packages":["pkg:npm/pathe@2.0.3"],"schemaVersion":1,"symbols":["pathe.resolve"]},"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/pathe@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/pathe@2.0.3","symbols":["pathe.resolve"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-pathe-resolve",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-pathe-resolve",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"pathe": "2.0.3"
}
},
"node_modules/pathe": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
"integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
"license": "MIT"
}
}
}
{
"name": "sample-pathe-resolve",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for pathe.resolve in pathe@2.0.3",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"pathe": "2.0.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pathe.resolve in pkg:npm/pathe@2.0.3",
"kind": "HOW",
"packages": [
"pkg:npm/pathe@2.0.3"
],
"symbols": [
"pathe.resolve"
]
}
const pathe = require('pathe');
const { resolve, normalize } = pathe;
/**
* Resolves a sequence of paths or path segments into an absolute POSIX path.
*
* @param {...string} paths - Path segments to resolve.
* @returns {string} Normalized absolute POSIX path.
*/
function resolvePath(...paths) {
return resolve(...paths);
}
/**
* Resolves path segments relative to a specified base directory.
*
* @param {string} base - Base directory path.
* @param {...string} segments - Additional segments to resolve against the base.
* @returns {string} Resolved POSIX path.
*/
function resolveRelative(base, ...segments) {
return resolve(base, ...segments);
}
module.exports = {
pathe,
resolve,
normalize,
resolvePath,
resolveRelative
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { pathe, resolve, normalize, resolvePath, resolveRelative } = require('../src/index.js');
async function runTests() {
const cwd = normalize(process.cwd());
// 1. pathe.resolve resolves multiple path segments into a normalized POSIX path string
assert.equal(typeof pathe.resolve, 'function', 'pathe.resolve must be a function');
assert.equal(typeof resolve, 'function', 'resolve must be a function');
assert.equal(resolve('/a', 'b', 'c'), '/a/b/c', 'resolve should join and normalize path segments');
assert.equal(resolvePath('/foo', 'bar', 'baz'), '/foo/bar/baz', 'resolvePath helper should resolve segments');
// 2. pathe.resolve resolves relative path segments and parent directory navigation (..)
assert.equal(resolve('/foo/bar', '../baz'), '/foo/baz', 'resolve should handle .. navigation');
assert.equal(resolve('/a/b/c', 'd', '../e'), '/a/b/c/e', 'resolve should traverse relative parent correctly');
assert.equal(resolveRelative('/base/dir', './sub', '../other'), '/base/dir/other', 'resolveRelative helper should resolve ..');
// 3. pathe.resolve processes paths from right to left until an absolute path is constructed
assert.equal(resolve('/first/path', '/second/path'), '/second/path', 'Rightmost absolute path takes precedence');
assert.equal(resolve('/root', 'sub1', '/target', 'file.txt'), '/target/file.txt', 'Absolute segment overrides earlier segments');
// 4. pathe.resolve strips trailing slashes from resolved paths unless resolving to root directory
assert.equal(resolve('/foo/bar/'), '/foo/bar', 'Trailing slash should be removed for non-root paths');
assert.equal(resolve('/'), '/', 'Root slash must be preserved');
// 5. pathe.resolve normalizes redundant slashes and relative dot segments
assert.equal(resolve('/foo//bar///baz'), '/foo/bar/baz', 'Redundant slashes should be normalized');
assert.equal(resolve('/foo/./bar/../baz'), '/foo/baz', 'Dot segments should be resolved');
// 6. pathe.resolve defaults to the current working directory in POSIX format when given empty or no arguments
assert.equal(resolve(''), cwd, 'Empty string should resolve to normalized current working directory');
assert.equal(resolve(), cwd, 'No arguments should resolve to normalized current working directory');
// 7. pathe.resolve ignores empty string segments between non-empty path arguments
assert.equal(resolve('/foo', '', 'bar'), '/foo/bar', 'Empty string segments should be ignored');
assert.equal(resolve('/foo', '', '', 'bar'), '/foo/bar', 'Multiple empty string segments should be ignored');
console.log('All contract assertions for pathe.resolve passed successfully.');
}
runTests().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
原始种子者
匿名