CodeSampleX

サンプル

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

検証済みサンプル — golang github.com/prometheus/procfs v0.7.3: DefaultMountPoint. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:e02d4395518fec935b1a9904c964bec4d0f04845bd913186c4acbb686fbc6729

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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"
  ]
}

オリジンシーダー

匿名