CodeSampleX

示例

github.com/prometheus/procfs v0.7.3: DefaultMountPoint

已验证示例 — golang github.com/prometheus/procfs v0.7.3: DefaultMountPoint. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: procfs.DefaultMountPoint…

sha256:e02d4395518fec935b1a9904c964bec4d0f04845bd913186c4acbb686fbc6729

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 go linux 24 · ubuntu · glibc 2.39 x64 go go go

验证运行环境

环境 契约 阶段 运行日期
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-27

案例

HOW
目标
verify github.com/prometheus/procfs.DefaultMountPoint in pkg:golang/github.com/prometheus/procfs@v0.7.3
包
符号
  • github.com/prometheus/procfs.DefaultMountPoint
环境
go
创建时间
2026-08-27T15:53:19Z

契约

  1. procfs.DefaultMountPoint defines the standard Linux proc filesystem mount path as "/proc".
  2. procfs.NewFS initializes an FS interface rooted at procfs.DefaultMountPoint to inspect process and system metrics.
  3. procfs.NewDefaultFS creates an FS instance using the DefaultMountPoint path.
  4. procfs.NewFS validates the specified path and returns an error when given a non-existent directory or regular file.

文件

  • NOTES.md
  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • procfs_test.go
  • spec.json

下载源代码构件 (tar.gz)

源代码

NOTES.md
# prometheus/procfs DefaultMountPoint Verification Notes

## Search Results
An initial search via `search_known_solution` for `pkg:golang/github.com/prometheus/procfs@v0.7.3` with `github.com/prometheus/procfs.DefaultMountPoint` returned reference-only match for v0.12.0.

## Pinned Version
- Package: `github.com/prometheus/procfs`
- Release: `v0.7.3` (in `go.mod` / `go.sum`)

## Observed Behavior
1. **DefaultMountPoint Constant**:
   - `procfs.DefaultMountPoint` is the default mount point string constant `"/proc"`.
2. **Mount Initialization**:
   - `procfs.NewFS(procfs.DefaultMountPoint)` initializes a pseudo-filesystem interface rooted at `/proc`, allowing access to process information via `fs.Self()` and system stats via `fs.Stat()`.
   - `procfs.NewDefaultFS()` initializes an identical `FS` rooted at `procfs.DefaultMountPoint`.
3. **Mount Point Validation**:
   - Initializing `procfs.NewFS` with a non-existent path or a non-directory regular file returns an error.
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 github.com/prometheus/procfs.DefaultMountPoint in pkg:golang/github.com/prometheus/procfs@v0.7.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/prometheus/procfs@v0.7.3
Demonstrate these symbols/APIs:
  - github.com/prometheus/procfs.DefaultMountPoint

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:f751bf3ef884438591c1c4f23bff558f5c2fd5c429314e8b79d429b33394917c","contract":["procfs.DefaultMountPoint defines the standard Linux proc filesystem mount path as \"/proc\".","procfs.NewFS initializes an FS interface rooted at procfs.DefaultMountPoint to inspect process and system metrics.","procfs.NewDefaultFS creates an FS instance using the DefaultMountPoint path.","procfs.NewFS validates the specified path and returns an error when given a non-existent directory or regular file."],"goal":"verify github.com/prometheus/procfs.DefaultMountPoint in pkg:golang/github.com/prometheus/procfs@v0.7.3","kind":"HOW","packages":["pkg:golang/github.com/prometheus/procfs@v0.7.3"],"schemaVersion":1,"symbols":["github.com/prometheus/procfs.DefaultMountPoint"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/prometheus/procfs@v0.7.3"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/procfs@v0.7.3","symbols":["github.com/prometheus/procfs.DefaultMountPoint"],"verifierAdapter":"golang@1"}
go.mod
module example.com/procfssample

go 1.20

require github.com/prometheus/procfs v0.7.3

require golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
go.sum
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
procfs_test.go
package procfssample_test

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/prometheus/procfs"
)

func TestDefaultMountPointValue(t *testing.T) {
	// Verify DefaultMountPoint is "/proc"
	if procfs.DefaultMountPoint != "/proc" {
		t.Fatalf("expected procfs.DefaultMountPoint to be %q, got %q", "/proc", procfs.DefaultMountPoint)
	}
}

func TestNewFSWithDefaultMountPoint(t *testing.T) {
	// Initialize FS explicitly with DefaultMountPoint
	fs, err := procfs.NewFS(procfs.DefaultMountPoint)
	if err != nil {
		t.Fatalf("unexpected error initializing procfs with DefaultMountPoint (%s): %v", procfs.DefaultMountPoint, err)
	}

	// Verify accessing /proc/self returns the current process
	selfProc, err := fs.Self()
	if err != nil {
		t.Fatalf("failed to retrieve current process via fs.Self(): %v", err)
	}

	if selfProc.PID != os.Getpid() {
		t.Errorf("expected self proc PID %d, got %d", os.Getpid(), selfProc.PID)
	}

	// Verify reading /proc/stat
	stat, err := fs.Stat()
	if err != nil {
		t.Fatalf("failed to read procfs stat: %v", err)
	}
	if stat.BootTime == 0 {
		t.Errorf("expected non-zero boot time in procfs stat")
	}
}

func TestNewDefaultFSMatchesDefaultMountPoint(t *testing.T) {
	// NewDefaultFS returns an FS mounted at DefaultMountPoint
	defaultFS, err := procfs.NewDefaultFS()
	if err != nil {
		t.Fatalf("unexpected error from NewDefaultFS(): %v", err)
	}

	explicitFS, err := procfs.NewFS(procfs.DefaultMountPoint)
	if err != nil {
		t.Fatalf("unexpected error from NewFS(DefaultMountPoint): %v", err)
	}

	// Both should query the same self process PID
	proc1, err1 := defaultFS.Self()
	proc2, err2 := explicitFS.Self()
	if err1 != nil || err2 != nil {
		t.Fatalf("errors querying Self(): err1=%v, err2=%v", err1, err2)
	}
	if proc1.PID != proc2.PID || proc1.PID != os.Getpid() {
		t.Errorf("expected matching PID %d, got proc1=%d, proc2=%d", os.Getpid(), proc1.PID, proc2.PID)
	}
}

func TestNewFSWithInvalidMountPoint(t *testing.T) {
	// Initializing procfs with a non-existent directory returns an error
	invalidPath := "/nonexistent/procfs/path"
	_, err := procfs.NewFS(invalidPath)
	if err == nil {
		t.Fatalf("expected error when initializing procfs with non-existent mountpoint %q, got nil", invalidPath)
	}

	// Initializing procfs with a regular file (not a directory) returns an error
	tmpFile := filepath.Join(t.TempDir(), "not_a_dir")
	if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
		t.Fatalf("failed to create temp file: %v", err)
	}
	_, err = procfs.NewFS(tmpFile)
	if err == nil {
		t.Fatalf("expected error when initializing procfs with regular file %q, got nil", tmpFile)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/prometheus/procfs.DefaultMountPoint in pkg:golang/github.com/prometheus/procfs@v0.7.3",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/prometheus/procfs@v0.7.3"
  ],
  "symbols": [
    "github.com/prometheus/procfs.DefaultMountPoint"
  ]
}

原始种子者

匿名