Ejemplo
github.com/spf13/afero v1.1.2: NewMemMapFs
Muestra verificada para golang github.com/spf13/afero v1.1.2: NewMemMapFs. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:2d29f48eab20e87505e91dd8859d44b5e312dad68905944f6ea414d8f13b9489
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-10-28 |
Caso
HOW- Objetivo
- verify github.com/spf13/afero.NewMemMapFs in pkg:golang/github.com/spf13/afero@v1.1.2
- Paquetes
- Símbolos
-
- github.com/spf13/afero.NewMemMapFs
- Entorno
- go 1.26.6
- Creado
- 2026-10-28T01:00:33Z
Contrato
- NewMemMapFs creates an in-memory filesystem implementing afero.Fs
- Name returns MemMapFS as the filesystem identifier
- Create creates an in-memory file that supports writing and reading back content
- MkdirAll creates nested directories and Stat confirms IsDir is true
- Stat on a created file reports the exact byte size and IsDir false
- Rename moves a file to a new path and preserves its contents
- Chtimes updates the modification time of an in-memory file
- Remove deletes an existing file and subsequent Open returns os.ErrNotExist
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código fuente
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/spf13/afero.NewMemMapFs in pkg:golang/github.com/spf13/afero@v1.1.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/spf13/afero@v1.1.2
Demonstrate these symbols/APIs:
- github.com/spf13/afero.NewMemMapFs
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:f114bdda91452f01b8ef89dfe22a62535dae74c7783b2392edee8bcbdf0e73f0","contract":["NewMemMapFs creates an in-memory filesystem implementing afero.Fs","Name returns MemMapFS as the filesystem identifier","Create creates an in-memory file that supports writing and reading back content","MkdirAll creates nested directories and Stat confirms IsDir is true","Stat on a created file reports the exact byte size and IsDir false","Rename moves a file to a new path and preserves its contents","Chtimes updates the modification time of an in-memory file","Remove deletes an existing file and subsequent Open returns os.ErrNotExist"],"goal":"verify github.com/spf13/afero.NewMemMapFs in pkg:golang/github.com/spf13/afero@v1.1.2","kind":"HOW","packages":["pkg:golang/github.com/spf13/afero@v1.1.2"],"schemaVersion":1,"symbols":["github.com/spf13/afero.NewMemMapFs"]},"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.1.2"],"schemaVersion":1,"subject":"pkg:golang/github.com/spf13/afero@v1.1.2","symbols":["github.com/spf13/afero.NewMemMapFs"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/spf13/afero v1.1.2
require golang.org/x/text v0.43.0 // indirect
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
package main
import (
"fmt"
"io"
"log"
"github.com/spf13/afero"
)
func main() {
fs := afero.NewMemMapFs()
fmt.Printf("Initialized in-memory filesystem: %s\n", fs.Name())
if err := fs.MkdirAll("/app/config", 0755); err != nil {
log.Fatalf("mkdir failed: %v", err)
}
f, err := fs.Create("/app/config/settings.txt")
if err != nil {
log.Fatalf("create failed: %v", err)
}
if _, err := f.Write([]byte("mode=memory")); err != nil {
f.Close()
log.Fatalf("write failed: %v", err)
}
if err := f.Close(); err != nil {
log.Fatalf("close failed: %v", err)
}
rf, err := fs.Open("/app/config/settings.txt")
if err != nil {
log.Fatalf("open failed: %v", err)
}
defer rf.Close()
data, err := io.ReadAll(rf)
if err != nil {
log.Fatalf("read failed: %v", err)
}
fmt.Printf("Read content: %s\n", string(data))
}
{
"schemaVersion": 1,
"goal": "verify github.com/spf13/afero.NewMemMapFs in pkg:golang/github.com/spf13/afero@v1.1.2",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/spf13/afero@v1.1.2"
],
"symbols": [
"github.com/spf13/afero.NewMemMapFs"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"time"
"github.com/spf13/afero"
)
func main() {
if err := verifyNewMemMapFs(); err != nil {
fmt.Fprintf(os.Stderr, "Contract failure: %v\n", err)
os.Exit(1)
}
fmt.Println("Contract passed for github.com/spf13/afero.NewMemMapFs")
}
func verifyNewMemMapFs() error {
// 1. NewMemMapFs creates an in-memory filesystem implementing afero.Fs
var fs afero.Fs = afero.NewMemMapFs()
if fs == nil {
return fmt.Errorf("NewMemMapFs returned nil")
}
// 2. Name returns MemMapFS as the filesystem identifier
if got := fs.Name(); got != "MemMapFS" {
return fmt.Errorf("expected Name() == MemMapFS, got %q", got)
}
// 3. Create creates an in-memory file that supports writing and reading back content
const filePath = "/sample.txt"
payload := []byte("in-memory file content for afero v1.1.2")
wFile, err := fs.Create(filePath)
if err != nil {
return fmt.Errorf("Create failed: %w", err)
}
n, err := wFile.Write(payload)
if err != nil || n != len(payload) {
wFile.Close()
return fmt.Errorf("Write failed: n=%d, err=%v", n, err)
}
if err := wFile.Close(); err != nil {
return fmt.Errorf("Close failed: %w", err)
}
rFile, err := fs.Open(filePath)
if err != nil {
return fmt.Errorf("Open failed: %w", err)
}
readBytes, err := io.ReadAll(rFile)
rFile.Close()
if err != nil {
return fmt.Errorf("ReadAll failed: %w", err)
}
if !bytes.Equal(readBytes, payload) {
return fmt.Errorf("content mismatch: got %q, want %q", string(readBytes), string(payload))
}
// 4. MkdirAll creates nested directories and Stat confirms IsDir is true
const nestedDir = "/a/b/c"
if err := fs.MkdirAll(nestedDir, 0755); err != nil {
return fmt.Errorf("MkdirAll failed: %w", err)
}
dirStat, err := fs.Stat(nestedDir)
if err != nil {
return fmt.Errorf("Stat on directory failed: %w", err)
}
if !dirStat.IsDir() {
return fmt.Errorf("expected %s to be a directory", nestedDir)
}
// 5. Stat on a created file reports the exact byte size and IsDir false
fileStat, err := fs.Stat(filePath)
if err != nil {
return fmt.Errorf("Stat on file failed: %w", err)
}
if fileStat.Size() != int64(len(payload)) {
return fmt.Errorf("expected file size %d, got %d", len(payload), fileStat.Size())
}
if fileStat.IsDir() {
return fmt.Errorf("expected %s not to be a directory", filePath)
}
// 6. Rename moves a file to a new path and preserves its contents
const movedPath = "/a/b/c/moved.txt"
if err := fs.Rename(filePath, movedPath); err != nil {
return fmt.Errorf("Rename failed: %w", err)
}
if _, err := fs.Open(filePath); !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("expected old path to return os.ErrNotExist after Rename, got %v", err)
}
movedFile, err := fs.Open(movedPath)
if err != nil {
return fmt.Errorf("Open moved file failed: %w", err)
}
movedBytes, err := io.ReadAll(movedFile)
movedFile.Close()
if err != nil {
return fmt.Errorf("ReadAll moved file failed: %w", err)
}
if !bytes.Equal(movedBytes, payload) {
return fmt.Errorf("moved content mismatch: got %q, want %q", string(movedBytes), string(payload))
}
// 7. Chtimes updates the modification time of an in-memory file
targetTime := time.Date(2024, 6, 15, 10, 30, 0, 0, time.UTC)
if err := fs.Chtimes(movedPath, targetTime, targetTime); err != nil {
return fmt.Errorf("Chtimes failed: %w", err)
}
updatedStat, err := fs.Stat(movedPath)
if err != nil {
return fmt.Errorf("Stat after Chtimes failed: %w", err)
}
if !updatedStat.ModTime().Equal(targetTime) {
return fmt.Errorf("expected ModTime %v, got %v", targetTime, updatedStat.ModTime())
}
// 8. Remove deletes an existing file and subsequent Open returns os.ErrNotExist
if err := fs.Remove(movedPath); err != nil {
return fmt.Errorf("Remove failed: %w", err)
}
if _, err := fs.Open(movedPath); !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("expected os.ErrNotExist after Remove, got %v", err)
}
return nil
}
Seeder de origen
anónimo