Ejemplo
golang.org/x/sys v0.31.0: unix.O_NONBLOCK
Muestra verificada para golang golang.org/x/sys v0.31.0: unix.O_NONBLOCK. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y pasó.
sha256:888befe5b3ac471c808afb049f6f34acaf4d0ca3886b67ba5cc299ae1104790e
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
- 2
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | FAIL | compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-30 |
| go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-30 |
Caso
HOW- Objetivo
- verify golang.org/x/sys/unix.O_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0
- Paquetes
- Símbolos
-
- golang.org/x/sys/unix.O_NONBLOCK
- Creado
- 2026-08-30T16:57:19Z
Contrato
- unix.O_NONBLOCK is a non-zero integer constant representing the non-blocking file descriptor flag
- unix.Pipe2 with unix.O_NONBLOCK creates pipe descriptors that return EAGAIN or EWOULDBLOCK on empty read
- unix.SetNonblock enables the O_NONBLOCK status flag on an existing file descriptor verifiable via FcntlInt F_GETFL
- unix.Write and unix.Read transfer data through non-blocking pipe descriptors without blocking
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 golang.org/x/sys/unix.O_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/sys@v0.31.0
Demonstrate these symbols/APIs:
- golang.org/x/sys/unix.O_NONBLOCK
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:0ca253b25c98fbb71ce398066d1797c1205b49789c0ced2e7abb41aba0e65344","contract":["unix.O_NONBLOCK is a non-zero integer constant representing the non-blocking file descriptor flag","unix.Pipe2 with unix.O_NONBLOCK creates pipe descriptors that return EAGAIN or EWOULDBLOCK on empty read","unix.SetNonblock enables the O_NONBLOCK status flag on an existing file descriptor verifiable via FcntlInt F_GETFL","unix.Write and unix.Read transfer data through non-blocking pipe descriptors without blocking"],"goal":"verify golang.org/x/sys/unix.O_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"symbols":["golang.org/x/sys/unix.O_NONBLOCK"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.31.0","symbols":["golang.org/x/sys/unix.O_NONBLOCK"],"verifierAdapter":"golang@1"}
module sample
go 1.25.0
require golang.org/x/sys v0.31.0
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
package main
import (
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
// CreateNonBlockingPipe initializes a unidirectional pipe with O_NONBLOCK and O_CLOEXEC flags.
func CreateNonBlockingPipe() ([2]int, error) {
var fds [2]int
if err := unix.Pipe2(fds[:], unix.O_NONBLOCK|unix.O_CLOEXEC); err != nil {
return fds, fmt.Errorf("pipe2 failed: %w", err)
}
return fds, nil
}
// SetDescriptorNonBlocking applies unix.O_NONBLOCK mode to an open file descriptor.
func SetDescriptorNonBlocking(fd int, nonblocking bool) error {
if err := unix.SetNonblock(fd, nonblocking); err != nil {
return fmt.Errorf("setnonblock failed: %w", err)
}
return nil
}
// IsDescriptorNonBlocking checks if O_NONBLOCK flag is active on the given file descriptor.
func IsDescriptorNonBlocking(fd int) (bool, error) {
flags, err := unix.FcntlInt(uintptr(fd), unix.F_GETFL, 0)
if err != nil {
return false, fmt.Errorf("fcntl F_GETFL failed: %w", err)
}
return (flags & unix.O_NONBLOCK) != 0, nil
}
// ReadNonBlocking attempts to read from a non-blocking descriptor. Returns true if EAGAIN/EWOULDBLOCK occurred.
func ReadNonBlocking(fd int, buf []byte) (int, bool, error) {
n, err := unix.Read(fd, buf)
if err != nil {
if errors.Is(err, unix.EAGAIN) || errors.Is(err, unix.EWOULDBLOCK) {
return 0, true, nil
}
return 0, false, fmt.Errorf("read failed: %w", err)
}
return n, false, nil
}
func main() {
fds, err := CreateNonBlockingPipe()
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating non-blocking pipe: %v\n", err)
os.Exit(1)
}
defer unix.Close(fds[0])
defer unix.Close(fds[1])
isNB, err := IsDescriptorNonBlocking(fds[0])
if err != nil || !isNB {
fmt.Fprintf(os.Stderr, "Error verifying non-blocking status: %v\n", err)
os.Exit(1)
}
buf := make([]byte, 128)
n, wouldBlock, err := ReadNonBlocking(fds[0], buf)
if err != nil || !wouldBlock {
fmt.Fprintf(os.Stderr, "Expected empty read to return wouldBlock, got n=%d, err=%v\n", n, err)
os.Exit(1)
}
msg := []byte("hello non-blocking pipe")
if _, err := unix.Write(fds[1], msg); err != nil {
fmt.Fprintf(os.Stderr, "Error writing: %v\n", err)
os.Exit(1)
}
n, wouldBlock, err = ReadNonBlocking(fds[0], buf)
if err != nil || wouldBlock || n != len(msg) {
fmt.Fprintf(os.Stderr, "Error reading message: %v\n", err)
os.Exit(1)
}
fmt.Printf("Successfully read %d bytes from non-blocking pipe: %s\n", n, string(buf[:n]))
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/sys/unix.O_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/sys@v0.31.0"
],
"symbols": [
"golang.org/x/sys/unix.O_NONBLOCK"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
func main() {
// Assertion 1: unix.O_NONBLOCK is a non-zero integer constant representing the non-blocking file descriptor flag
if unix.O_NONBLOCK == 0 {
fmt.Fprintf(os.Stderr, "FAIL: unix.O_NONBLOCK is 0\n")
os.Exit(1)
}
// Assertion 2: unix.Pipe2 with unix.O_NONBLOCK creates pipe descriptors that return EAGAIN or EWOULDBLOCK on empty read
var fds [2]int
if err := unix.Pipe2(fds[:], unix.O_NONBLOCK|unix.O_CLOEXEC); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe2 failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(fds[0])
defer unix.Close(fds[1])
buf := make([]byte, 64)
n, err := unix.Read(fds[0], buf)
if err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected error on empty non-blocking read, got %d bytes\n", n)
os.Exit(1)
}
if !errors.Is(err, unix.EAGAIN) && !errors.Is(err, unix.EWOULDBLOCK) {
fmt.Fprintf(os.Stderr, "FAIL: expected EAGAIN or EWOULDBLOCK, got %v\n", err)
os.Exit(1)
}
// Assertion 3: unix.SetNonblock enables the O_NONBLOCK status flag on an existing file descriptor verifiable via FcntlInt F_GETFL
var blockingFds [2]int
if err := unix.Pipe2(blockingFds[:], unix.O_CLOEXEC); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: pipe creation failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(blockingFds[0])
defer unix.Close(blockingFds[1])
flagsBefore, err := unix.FcntlInt(uintptr(blockingFds[0]), unix.F_GETFL, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: fcntl F_GETFL before SetNonblock failed: %v\n", err)
os.Exit(1)
}
if (flagsBefore & unix.O_NONBLOCK) != 0 {
fmt.Fprintf(os.Stderr, "FAIL: initial pipe descriptor should not have O_NONBLOCK set\n")
os.Exit(1)
}
if err := unix.SetNonblock(blockingFds[0], true); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.SetNonblock failed: %v\n", err)
os.Exit(1)
}
flagsAfter, err := unix.FcntlInt(uintptr(blockingFds[0]), unix.F_GETFL, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: fcntl F_GETFL after SetNonblock failed: %v\n", err)
os.Exit(1)
}
if (flagsAfter & unix.O_NONBLOCK) == 0 {
fmt.Fprintf(os.Stderr, "FAIL: O_NONBLOCK flag was not set after unix.SetNonblock\n")
os.Exit(1)
}
// Assertion 4: unix.Write and unix.Read transfer data through non-blocking pipe descriptors without blocking
payload := []byte("non-blocking-contract-test")
wn, err := unix.Write(fds[1], payload)
if err != nil || wn != len(payload) {
fmt.Fprintf(os.Stderr, "FAIL: unix.Write failed: wn=%d, err=%v\n", wn, err)
os.Exit(1)
}
readBuf := make([]byte, 64)
rn, err := unix.Read(fds[0], readBuf)
if err != nil || rn != len(payload) || !bytes.Equal(readBuf[:rn], payload) {
fmt.Fprintf(os.Stderr, "FAIL: unix.Read failed: rn=%d, err=%v, data=%q\n", rn, err, string(readBuf[:rn]))
os.Exit(1)
}
fmt.Println("PASS: all contract assertions passed")
}
Seeder de origen
anónimo