Ejemplo
modernc.org/httpfs v1.0.6
Muestra verificada para golang modernc.org/httpfs v1.0.6. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:4c7aeb403ec29219a03bd56b6f06399f5b9cd01ab6b7c9f70065ed098bb8e77c
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
linux 24 · ubuntu · glibc 2.39 x64 go go
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-11-23 |
Caso
HOW- Objetivo
- verify pkg:golang/modernc.org/httpfs@v1.0.6
- Paquetes
- Creado
- 2026-11-22T21:11:40Z
Contrato
- httpfs.NewFileSystem constructs an http.FileSystem from rooted slash-separated map keys and applies the given modTime to opened files and directories
- FileSystem.Open reads exact file bytes until io.EOF and Stat reports matching Name, Size, IsDir=false, Mode=0, ModTime, and Sys=nil
- Opened http.File supports Seek with io.SeekStart, io.SeekCurrent, and io.SeekEnd and rejects negative or past-EOF offsets without mutating the current offset
- Directory Open requires a trailing slash, sets Stat IsDir=true and Mode=os.ModeDir, and Readdir(-1) returns sorted deduplicated entries with subdirectories suffixed by '/' while omitting the trailing slash returns an error
- FileSystem.Open returns a plain error (not wrapping os.ErrNotExist) for nonexistent files and nonexistent directories
- http.FileServer serves files from httpfs.FileSystem offline with HTTP 200 and Last-Modified, serves HTTP Range requests with 206 Partial Content, and returns HTTP 500 for missing paths because Open does not wrap 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 pkg:golang/modernc.org/httpfs@v1.0.6
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/modernc.org/httpfs@v1.0.6
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:7b365674e0d51d27c932aa9d306ce7a067617a171fdd5f78739f92c46a332ca1","contract":["httpfs.NewFileSystem constructs an http.FileSystem from rooted slash-separated map keys and applies the given modTime to opened files and directories","FileSystem.Open reads exact file bytes until io.EOF and Stat reports matching Name, Size, IsDir=false, Mode=0, ModTime, and Sys=nil","Opened http.File supports Seek with io.SeekStart, io.SeekCurrent, and io.SeekEnd and rejects negative or past-EOF offsets without mutating the current offset","Directory Open requires a trailing slash, sets Stat IsDir=true and Mode=os.ModeDir, and Readdir(-1) returns sorted deduplicated entries with subdirectories suffixed by '/' while omitting the trailing slash returns an error","FileSystem.Open returns a plain error (not wrapping os.ErrNotExist) for nonexistent files and nonexistent directories","http.FileServer serves files from httpfs.FileSystem offline with HTTP 200 and Last-Modified, serves HTTP Range requests with 206 Partial Content, and returns HTTP 500 for missing paths because Open does not wrap os.ErrNotExist"],"goal":"verify pkg:golang/modernc.org/httpfs@v1.0.6","kind":"HOW","packages":["pkg:golang/modernc.org/httpfs@v1.0.6"],"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","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/modernc.org/httpfs@v1.0.6"],"schemaVersion":1,"subject":"pkg:golang/modernc.org/httpfs@v1.0.6","verifierAdapter":"golang@1"}
module sample
go 1.22
require modernc.org/httpfs v1.0.6
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
package main
import (
"fmt"
"io"
"log"
"time"
"modernc.org/httpfs"
)
func main() {
modTime := time.Date(2025, time.March, 10, 8, 30, 0, 0, time.UTC)
fs := httpfs.NewFileSystem(map[string]string{
"/site/index.html": "<!doctype html><p>ok</p>",
"/site/css/style.css": "body{margin:0}",
}, modTime)
f, err := fs.Open("/site/index.html")
if err != nil {
log.Fatal(err)
}
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", content)
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/modernc.org/httpfs@v1.0.6",
"kind": "HOW",
"packages": [
"pkg:golang/modernc.org/httpfs@v1.0.6"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"time"
"modernc.org/httpfs"
)
func must(cond bool, format string, args ...any) {
if !cond {
fmt.Fprintf(os.Stderr, "contract failed: "+format+"\n", args...)
os.Exit(1)
}
}
func main() {
modTime := time.Date(2025, time.March, 10, 8, 30, 0, 0, time.UTC)
files := map[string]string{
"/root.txt": "root-body",
"/static/b.txt": "0123456789",
"/static/a.txt": "alpha",
"/static/sub/one.txt": "1",
"/static/sub/two.txt": "22",
}
var fs http.FileSystem = httpfs.NewFileSystem(files, modTime)
// 1. Open file, verify Stat metadata, sequential Read, and EOF.
f, err := fs.Open("/static/b.txt")
must(err == nil, "Open existing file returned error: %v", err)
defer f.Close()
fi, err := f.Stat()
must(err == nil, "Stat on file returned error: %v", err)
must(fi.Name() == "/static/b.txt", "expected Name /static/b.txt, got %q", fi.Name())
must(fi.Size() == 10, "expected Size 10, got %d", fi.Size())
must(!fi.IsDir(), "expected file IsDir() == false")
must(fi.Mode() == 0, "expected file Mode() == 0, got %v", fi.Mode())
must(fi.ModTime().Equal(modTime), "expected ModTime %v, got %v", modTime, fi.ModTime())
must(fi.Sys() == nil, "expected Sys() == nil, got %v", fi.Sys())
got, err := io.ReadAll(f)
must(err == nil, "ReadAll returned error: %v", err)
must(string(got) == "0123456789", "unexpected file body: %q", string(got))
eofBuf := make([]byte, 4)
n, err := f.Read(eofBuf)
must(n == 0 && err == io.EOF, "expected (0, io.EOF) at end of file, got (%d, %v)", n, err)
// 2. Verify SeekStart, SeekCurrent, SeekEnd, and invalid offset rollback.
pos, err := f.Seek(2, io.SeekStart)
must(err == nil && pos == 2, "SeekStart(2) failed: pos=%d err=%v", pos, err)
chunk := make([]byte, 3)
n, err = f.Read(chunk)
must(err == nil && n == 3 && string(chunk) == "234", "Read after SeekStart failed: n=%d chunk=%q err=%v", n, string(chunk), err)
pos, err = f.Seek(2, io.SeekCurrent)
must(err == nil && pos == 7, "SeekCurrent(2) failed: pos=%d err=%v", pos, err)
pos, err = f.Seek(-4, io.SeekEnd)
must(err == nil && pos == 6, "SeekEnd(-4) failed: pos=%d err=%v", pos, err)
badPos, err := f.Seek(-1, io.SeekStart)
must(err != nil && badPos == 6, "negative Seek should fail and preserve pos 6, got pos=%d err=%v", badPos, err)
badPos, err = f.Seek(11, io.SeekStart)
must(err != nil && badPos == 6, "Seek past EOF should fail and preserve pos 6, got pos=%d err=%v", badPos, err)
// 3. Virtual directory open requires trailing slash and returns sorted, deduplicated entries.
_, err = fs.Open("/static")
must(err != nil, "Open directory without trailing slash should fail")
dir, err := fs.Open("/static/")
must(err == nil, "Open /static/ returned error: %v", err)
defer dir.Close()
dirInfo, err := dir.Stat()
must(err == nil, "Stat on directory returned error: %v", err)
must(dirInfo.IsDir(), "expected directory IsDir() == true")
must(dirInfo.Mode() == os.ModeDir, "expected directory Mode() == os.ModeDir, got %v", dirInfo.Mode())
must(dirInfo.ModTime().Equal(modTime), "expected directory ModTime %v, got %v", modTime, dirInfo.ModTime())
entries, err := dir.Readdir(-1)
must(err == nil, "Readdir(-1) returned error: %v", err)
must(len(entries) == 3, "expected 3 entries in /static/, got %d", len(entries))
wantNames := []string{"/static/a.txt", "/static/b.txt", "/static/sub/"}
wantDirs := []bool{false, false, true}
wantSizes := []int64{5, 10, 0}
for i := range wantNames {
must(entries[i].Name() == wantNames[i], "entry[%d] Name: got %q want %q", i, entries[i].Name(), wantNames[i])
must(entries[i].IsDir() == wantDirs[i], "entry[%d] IsDir: got %v want %v", i, entries[i].IsDir(), wantDirs[i])
must(entries[i].Size() == wantSizes[i], "entry[%d] Size: got %d want %d", i, entries[i].Size(), wantSizes[i])
}
rootDir, err := fs.Open("/")
must(err == nil, "Open / returned error: %v", err)
defer rootDir.Close()
rootEntries, err := rootDir.Readdir(-1)
must(err == nil && len(rootEntries) == 2, "expected 2 root entries, got %d err=%v", len(rootEntries), err)
must(rootEntries[0].Name() == "/root.txt" && rootEntries[1].Name() == "/static/", "unexpected root entries: %q, %q", rootEntries[0].Name(), rootEntries[1].Name())
// 4. Missing file and missing directory return plain errors (not wrapping os.ErrNotExist).
_, err = fs.Open("/does-not-exist.txt")
must(err != nil, "expected error for missing file")
must(!errors.Is(err, os.ErrNotExist), "httpfs v1.0.6 returns a plain error, not os.ErrNotExist")
_, err = fs.Open("/does-not-exist/")
must(err != nil, "expected error for missing directory")
// 5. Offline net/http.FileServer serving: 200 OK, 206 Partial Content via Range,
// and 500 Internal Server Error for missing paths (because Open does not wrap os.ErrNotExist).
handler := http.FileServer(fs)
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/static/a.txt", nil))
res := rec.Result()
body, err := io.ReadAll(res.Body)
res.Body.Close()
must(err == nil && res.StatusCode == http.StatusOK, "expected 200 OK, got %d err=%v", res.StatusCode, err)
must(string(body) == "alpha", "expected body 'alpha', got %q", string(body))
must(res.Header.Get("Last-Modified") == modTime.UTC().Format(http.TimeFormat), "unexpected Last-Modified: %q", res.Header.Get("Last-Modified"))
rangeReq := httptest.NewRequest(http.MethodGet, "/static/b.txt", nil)
rangeReq.Header.Set("Range", "bytes=3-6")
rangeRec := httptest.NewRecorder()
handler.ServeHTTP(rangeRec, rangeReq)
rangeRes := rangeRec.Result()
rangeBody, err := io.ReadAll(rangeRes.Body)
rangeRes.Body.Close()
must(err == nil && rangeRes.StatusCode == http.StatusPartialContent, "expected 206 Partial Content, got %d err=%v", rangeRes.StatusCode, err)
must(string(rangeBody) == "3456", "expected range body '3456', got %q", string(rangeBody))
missingRec := httptest.NewRecorder()
handler.ServeHTTP(missingRec, httptest.NewRequest(http.MethodGet, "/missing.txt", nil))
must(missingRec.Result().StatusCode == http.StatusInternalServerError, "expected 500 Internal Server Error from FileServer for missing path, got %d", missingRec.Result().StatusCode)
}
Seeder de origen
anónimo