Exemple
dunce 1.0.5: dunce::canonicalize
Échantillon vérifié pour cargo dunce 1.0.5: dunce::canonicalize. Le contrat s'est exécuté sur rust 1 · linux alpine/x64 · docker et a réussi.
sha256:ad823d7f638a9c899890749901ff8bd30d06347156835c56998722da4f624364
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 · alpine · musl x64 cargo
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-11-22 |
Cas
HOW- Objectif
- verify dunce::canonicalize in pkg:cargo/dunce@1.0.5
- Paquets
- Symboles
-
- dunce::canonicalize
- Créé
- 2026-11-22T00:52:12Z
Contrat
- dunce::canonicalize resolves an existing file path to an absolute canonical PathBuf without '.' or '..' components
- dunce::canonicalize resolves paths containing redundant '.' and '..' segments to the same canonical PathBuf as the direct path
- dunce::canonicalize resolves an existing directory path matching the parent directory of a file inside it
- dunce::canonicalize accepts &Path, owned PathBuf, and &str arguments via AsRef<Path>
- dunce::canonicalize resolves symlinks on Unix to the canonical target file path
- dunce::canonicalize returns Err with io::ErrorKind::NotFound for a non-existent path
Fichiers
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Code source
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "dunce"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
[[package]]
name = "sample-dunce-canonicalize"
version = "1.0.0"
dependencies = [
"dunce",
]
[package]
name = "sample-dunce-canonicalize"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
dunce = "=1.0.5"
[[bin]]
name = "contract"
path = "test/contract.rs"
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 dunce::canonicalize in pkg:cargo/dunce@1.0.5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/dunce@1.0.5
Demonstrate these symbols/APIs:
- dunce::canonicalize
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:68f75f17d2f3eecd236691fe62e905a2d13b33d63acd184539909c9c9768c97b","contract":["dunce::canonicalize resolves an existing file path to an absolute canonical PathBuf without '.' or '..' components","dunce::canonicalize resolves paths containing redundant '.' and '..' segments to the same canonical PathBuf as the direct path","dunce::canonicalize resolves an existing directory path matching the parent directory of a file inside it","dunce::canonicalize accepts \u0026Path, owned PathBuf, and \u0026str arguments via AsRef\u003cPath\u003e","dunce::canonicalize resolves symlinks on Unix to the canonical target file path","dunce::canonicalize returns Err with io::ErrorKind::NotFound for a non-existent path"],"goal":"verify dunce::canonicalize in pkg:cargo/dunce@1.0.5","kind":"HOW","packages":["pkg:cargo/dunce@1.0.5"],"schemaVersion":1,"symbols":["dunce::canonicalize"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/dunce@1.0.5"],"schemaVersion":1,"subject":"pkg:cargo/dunce@1.0.5","symbols":["dunce::canonicalize"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify dunce::canonicalize in pkg:cargo/dunce@1.0.5",
"kind": "HOW",
"packages": [
"pkg:cargo/dunce@1.0.5"
],
"symbols": [
"dunce::canonicalize"
]
}
use std::io;
use std::path::{Path, PathBuf};
/// Canonicalizes a filesystem path using `dunce::canonicalize`.
///
/// Resolves `.`, `..`, and symlinks to an absolute canonical path while
/// avoiding unnecessary Windows UNC (`\\?\`) prefixes on Windows targets.
pub fn canonicalize_path<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
dunce::canonicalize(path)
}
use std::fs;
use std::io::ErrorKind;
use std::path::{Component, Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
use sample_dunce_canonicalize::canonicalize_path;
struct TempDirGuard(PathBuf);
impl TempDirGuard {
fn new() -> Self {
let nanos = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system clock after unix epoch")
.as_nanos();
let dir = std::env::temp_dir().join(format!(
"csx-dunce-canonicalize-{}-{}",
std::process::id(),
nanos
));
fs::create_dir_all(&dir).expect("create temp directory");
Self(dir)
}
fn path(&self) -> &Path {
&self.0
}
}
impl Drop for TempDirGuard {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
fn has_dot_components(path: &Path) -> bool {
path.components()
.any(|c| matches!(c, Component::CurDir | Component::ParentDir))
}
fn main() {
let temp = TempDirGuard::new();
let nested_dir = temp.path().join("alpha").join("beta");
fs::create_dir_all(&nested_dir).expect("create nested directory");
let target_file = nested_dir.join("item.txt");
fs::write(&target_file, b"payload").expect("write target file");
// 1. Canonicalizes an existing file to an absolute path without '.' or '..'.
let canon_file = dunce::canonicalize(&target_file).expect("canonicalize existing file");
assert!(canon_file.is_absolute(), "canonical path must be absolute");
assert!(
!has_dot_components(&canon_file),
"canonical path must not contain '.' or '..'"
);
assert!(canon_file.is_file(), "canonical path must refer to a file");
assert_eq!(
canon_file.file_name().and_then(|n| n.to_str()),
Some("item.txt")
);
// 2. Resolves redundant '.' and '..' segments to the same canonical path.
let dot_path = temp
.path()
.join("alpha")
.join(".")
.join("beta")
.join("..")
.join("beta")
.join("item.txt");
let canon_from_dots = canonicalize_path(&dot_path).expect("canonicalize path with dot segments");
assert_eq!(canon_from_dots, canon_file);
// 3. Canonicalizes an existing directory and matches the parent of the canonical file.
let canon_dir = dunce::canonicalize(&nested_dir).expect("canonicalize existing directory");
assert!(canon_dir.is_dir(), "canonical directory path must be a directory");
assert_eq!(canon_file.parent(), Some(canon_dir.as_path()));
// 4. Accepts owned PathBuf and &str inputs via AsRef<Path>.
let canon_from_owned =
dunce::canonicalize(target_file.clone()).expect("canonicalize owned PathBuf");
assert_eq!(canon_from_owned, canon_file);
if let Some(as_str) = target_file.to_str() {
let canon_from_str = dunce::canonicalize(as_str).expect("canonicalize &str path");
assert_eq!(canon_from_str, canon_file);
}
// 5. Resolves symlinks to the canonical target path on Unix platforms.
#[cfg(unix)]
{
use std::os::unix::fs::symlink;
let link_path = temp.path().join("alpha").join("link-to-item.txt");
symlink(&target_file, &link_path).expect("create symlink");
let canon_link = dunce::canonicalize(&link_path).expect("canonicalize symlink");
assert_eq!(canon_link, canon_file);
}
// 6. Returns io::ErrorKind::NotFound for a non-existent path.
let missing = temp.path().join("does-not-exist.txt");
let err = dunce::canonicalize(&missing).expect_err("missing path must return Err");
assert_eq!(err.kind(), ErrorKind::NotFound);
println!("contract passed");
}
Seeder d'origine
anonyme