CodeSampleX

Beispiel

github.com/spf13/afero v1.15.0

Verifiziertes Beispiel für golang github.com/spf13/afero v1.15.0. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:0de8df1625798f1c110e2b7573f79857baafc7ef0dd25c754581af3e724f1a90

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-19

Fall

HOW
Ziel
verify pkg:golang/github.com/spf13/afero@v1.15.0
Pakete
Umgebung
go 1.26.6
Erstellt
2026-09-19T12:49:07Z

Contract

  1. afero.NewMemMapFs creates an in-memory filesystem implementing afero.Fs
  2. afero.WriteFile and afero.ReadFile write and read data in an afero.Fs
  3. afero.Exists and afero.DirExists correctly detect files and directories
  4. afero.NewBasePathFs restricts filesystem operations to a base directory
  5. afero.NewReadOnlyFs prevents mutating write operations

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

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 pkg:golang/github.com/spf13/afero@v1.15.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/spf13/afero@v1.15.0
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

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:b2d0e1278e3702096bfe604260c845e10f61131362456763e460d5ae4d365be6","contract":["afero.NewMemMapFs creates an in-memory filesystem implementing afero.Fs","afero.WriteFile and afero.ReadFile write and read data in an afero.Fs","afero.Exists and afero.DirExists correctly detect files and directories","afero.NewBasePathFs restricts filesystem operations to a base directory","afero.NewReadOnlyFs prevents mutating write operations"],"goal":"verify pkg:golang/github.com/spf13/afero@v1.15.0","kind":"HOW","packages":["pkg:golang/github.com/spf13/afero@v1.15.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/spf13/afero@v1.15.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/spf13/afero@v1.15.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/spf13/afero v1.15.0

require golang.org/x/text v0.28.0 // indirect
go.sum
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
main.go
package main

import (
	"fmt"
	"os"

	"github.com/spf13/afero"
)

func main() {
	fs := afero.NewMemMapFs()
	filePath := "example.txt"
	data := []byte("afero in-memory filesystem")

	if err := afero.WriteFile(fs, filePath, data, 0644); err != nil {
		fmt.Fprintf(os.Stderr, "failed to write file: %v\n", err)
		os.Exit(1)
	}

	readBytes, err := afero.ReadFile(fs, filePath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to read file: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("File content: %s\n", string(readBytes))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/spf13/afero@v1.15.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/spf13/afero@v1.15.0"
  ],
  "runtimeConditions": {
    "ecosystem": "golang",
    "language": "go",
    "packageManager": "go@1.26.6",
    "runtime": "go@1.26.6"
  }
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/spf13/afero"
)

func main() {
	// 1. afero.NewMemMapFs creates an in-memory filesystem implementing afero.Fs
	fs := afero.NewMemMapFs()
	if fs == nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: NewMemMapFs returned nil\n")
		os.Exit(1)
	}
	var _ afero.Fs = fs

	// 2. afero.WriteFile and afero.ReadFile write and read data in an afero.Fs
	filePath := "data/test.txt"
	expectedData := []byte("contract-test-content")
	if err := afero.WriteFile(fs, filePath, expectedData, 0644); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: WriteFile returned error: %v\n", err)
		os.Exit(1)
	}
	readData, err := afero.ReadFile(fs, filePath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: ReadFile returned error: %v\n", err)
		os.Exit(1)
	}
	if !bytes.Equal(readData, expectedData) {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected %q, got %q\n", string(expectedData), string(readData))
		os.Exit(1)
	}

	// 3. afero.Exists and afero.DirExists correctly detect files and directories
	exists, err := afero.Exists(fs, filePath)
	if err != nil || !exists {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: Exists(%q) = (%v, %v), expected (true, nil)\n", filePath, exists, err)
		os.Exit(1)
	}
	notExists, err := afero.Exists(fs, "data/nonexistent.txt")
	if err != nil || notExists {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: Exists on nonexistent returned (%v, %v), expected (false, nil)\n", notExists, err)
		os.Exit(1)
	}
	dirExists, err := afero.DirExists(fs, "data")
	if err != nil || !dirExists {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: DirExists(\"data\") = (%v, %v), expected (true, nil)\n", dirExists, err)
		os.Exit(1)
	}
	fileNotDir, err := afero.DirExists(fs, filePath)
	if err != nil || fileNotDir {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: DirExists on file returned (%v, %v), expected (false, nil)\n", fileNotDir, err)
		os.Exit(1)
	}

	// 4. afero.NewBasePathFs restricts filesystem operations to a base directory
	baseFs := afero.NewBasePathFs(fs, "data")
	baseRead, err := afero.ReadFile(baseFs, "test.txt")
	if err != nil || !bytes.Equal(baseRead, expectedData) {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: ReadFile on BasePathFs returned %q, error: %v\n", string(baseRead), err)
		os.Exit(1)
	}
	if err := afero.WriteFile(baseFs, "nested.txt", []byte("nested-data"), 0644); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: WriteFile on BasePathFs returned error: %v\n", err)
		os.Exit(1)
	}
	rootHasNested, err := afero.Exists(fs, "data/nested.txt")
	if err != nil || !rootHasNested {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: expected file at \"data/nested.txt\" on root fs: %v\n", err)
		os.Exit(1)
	}

	// 5. afero.NewReadOnlyFs prevents mutating write operations
	roFs := afero.NewReadOnlyFs(fs)
	roData, err := afero.ReadFile(roFs, "data/test.txt")
	if err != nil || !bytes.Equal(roData, expectedData) {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: ReadFile on ReadOnlyFs failed: %v\n", err)
		os.Exit(1)
	}
	if err := afero.WriteFile(roFs, "data/ro_fail.txt", []byte("should-fail"), 0644); err == nil {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: WriteFile on ReadOnlyFs expected error, got nil\n")
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed successfully.")
}

Ursprungs-Seeder

anonym