CodeSampleX

샘플

github.com/spf13/afero v1.1.2: NewMemMapFs

검증된 샘플 — golang github.com/spf13/afero v1.1.2: NewMemMapFs. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: NewMemMapFs creates an in-memory…

sha256:2d29f48eab20e87505e91dd8859d44b5e312dad68905944f6ea414d8f13b9489

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify github.com/spf13/afero.NewMemMapFs in pkg:golang/github.com/spf13/afero@v1.1.2
패키지
심벌
  • github.com/spf13/afero.NewMemMapFs
환경
go 1.26.6
생성일
2026-10-28T01:00:33Z

컨트랙트

  1. NewMemMapFs creates an in-memory filesystem implementing afero.Fs
  2. Name returns MemMapFS as the filesystem identifier
  3. Create creates an in-memory file that supports writing and reading back content
  4. MkdirAll creates nested directories and Stat confirms IsDir is true
  5. Stat on a created file reports the exact byte size and IsDir false
  6. Rename moves a file to a new path and preserves its contents
  7. Chtimes updates the modification time of an in-memory file
  8. Remove deletes an existing file and subsequent Open returns os.ErrNotExist

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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/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.
csx.json
{"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"}
go.mod
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
go.sum
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=
main.go
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))
}
spec.json
{
  "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"
  ]
}
test/contract.go
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
}

오리진 시더

익명