CodeSampleX

Exemplo

golang.org/x/sys v0.14.0

Amostra verificada para golang golang.org/x/sys v0.14.0. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou: unix.Pipe2 creates a non-blocking…

sha256:fcced1eadda31241d37d0000892cc720c23f199682313a396f75726a15733d5a

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-28

Caso

HOW
Objetivo
verify pkg:golang/golang.org/x/sys@v0.14.0
Pacotes
Criado
2026-08-28T09:10:07Z

Contrato

  1. unix.Pipe2 creates a non-blocking pipe with close-on-exec flag transferring data between descriptors
  2. unix.Ftruncate resizes an open file descriptor to the specified byte length
  3. unix.ClockGettime retrieves current monotonic clock time with valid positive values
  4. unix.Gettid returns a positive caller thread ID

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/golang.org/x/sys@v0.14.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.14.0

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:ed7ac37c1b6a2c2a0e751c8f8ba2083453c03255b3701926dd3d46ee88ac65da","contract":["unix.Pipe2 creates a non-blocking pipe with close-on-exec flag transferring data between descriptors","unix.Ftruncate resizes an open file descriptor to the specified byte length","unix.ClockGettime retrieves current monotonic clock time with valid positive values","unix.Gettid returns a positive caller thread ID"],"goal":"verify pkg:golang/golang.org/x/sys@v0.14.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.14.0"],"schemaVersion":1},"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.14.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.14.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require golang.org/x/sys v0.14.0
go.sum
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
main.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

// CreateNonBlockingPipe creates a unidirectional pipe with O_CLOEXEC and O_NONBLOCK flags.
func CreateNonBlockingPipe() ([2]int, error) {
	var fds [2]int
	if err := unix.Pipe2(fds[:], unix.O_CLOEXEC|unix.O_NONBLOCK); err != nil {
		return fds, fmt.Errorf("pipe2 failed: %w", err)
	}
	return fds, nil
}

// TruncateFile resizes an open file descriptor to the specified size in bytes.
func TruncateFile(fd int, size int64) error {
	if err := unix.Ftruncate(fd, size); err != nil {
		return fmt.Errorf("ftruncate failed: %w", err)
	}
	return nil
}

// GetMonotonicTime retrieves the current time from CLOCK_MONOTONIC.
func GetMonotonicTime() (unix.Timespec, error) {
	var ts unix.Timespec
	if err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err != nil {
		return ts, fmt.Errorf("clock_gettime failed: %w", err)
	}
	return ts, nil
}

// GetThreadID retrieves the current thread ID using unix.Gettid.
func GetThreadID() int {
	return unix.Gettid()
}

func main() {
	// 1. Non-blocking pipe demonstration
	fds, err := CreateNonBlockingPipe()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating pipe: %v\n", err)
		os.Exit(1)
	}
	defer unix.Close(fds[0])
	defer unix.Close(fds[1])

	payload := []byte("golang.org/x/sys v0.14.0 demo")
	if _, err := unix.Write(fds[1], payload); err != nil {
		fmt.Fprintf(os.Stderr, "Error writing to pipe: %v\n", err)
		os.Exit(1)
	}

	buf := make([]byte, 64)
	n, err := unix.Read(fds[0], buf)
	if err != nil || !bytes.Equal(buf[:n], payload) {
		fmt.Fprintf(os.Stderr, "Error reading from pipe: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Pipe transferred %d bytes: %s\n", n, string(buf[:n]))

	// 2. Ftruncate demonstration
	tmpFile, err := os.CreateTemp("", "sys_demo_*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating temp file: %v\n", err)
		os.Exit(1)
	}
	defer func() {
		tmpFile.Close()
		os.Remove(tmpFile.Name())
	}()

	fd := int(tmpFile.Fd())
	targetSize := int64(1024)
	if err := TruncateFile(fd, targetSize); err != nil {
		fmt.Fprintf(os.Stderr, "Error truncating file: %v\n", err)
		os.Exit(1)
	}

	var stat unix.Stat_t
	if err := unix.Fstat(fd, &stat); err != nil {
		fmt.Fprintf(os.Stderr, "Error stating file: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("File size after truncate: %d bytes\n", stat.Size)

	// 3. ClockGettime demonstration
	ts, err := GetMonotonicTime()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error getting monotonic time: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Monotonic time: %d.%09d s\n", ts.Sec, ts.Nsec)

	// 4. Gettid demonstration
	tid := GetThreadID()
	fmt.Printf("Thread ID: %d\n", tid)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/sys@v0.14.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.14.0"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

func main() {
	// Assertion 1: unix.Pipe2 creates a non-blocking pipe with close-on-exec flag transferring data between descriptors
	var fds [2]int
	if err := unix.Pipe2(fds[:], unix.O_CLOEXEC|unix.O_NONBLOCK); 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])

	msg := []byte("sys-contract-pipe-test")
	n, err := unix.Write(fds[1], msg)
	if err != nil || n != len(msg) {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Write failed: n=%d, err=%v\n", n, err)
		os.Exit(1)
	}

	buf := make([]byte, 64)
	rn, err := unix.Read(fds[0], buf)
	if err != nil || rn != len(msg) || !bytes.Equal(buf[:rn], msg) {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Read failed: rn=%d, err=%v, data=%q\n", rn, err, string(buf[:rn]))
		os.Exit(1)
	}

	// Assertion 2: unix.Ftruncate resizes an open file descriptor to the specified byte length
	tmpFile, err := os.CreateTemp("", "contract_ftruncate_*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: os.CreateTemp failed: %v\n", err)
		os.Exit(1)
	}
	defer func() {
		tmpFile.Close()
		os.Remove(tmpFile.Name())
	}()

	fd := int(tmpFile.Fd())
	targetSize := int64(2048)
	if err := unix.Ftruncate(fd, targetSize); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Ftruncate failed: %v\n", err)
		os.Exit(1)
	}

	var stat unix.Stat_t
	if err := unix.Fstat(fd, &stat); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Fstat failed: %v\n", err)
		os.Exit(1)
	}
	if stat.Size != targetSize {
		fmt.Fprintf(os.Stderr, "FAIL: unexpected file size: got %d, expected %d\n", stat.Size, targetSize)
		os.Exit(1)
	}

	// Assertion 3: unix.ClockGettime retrieves current monotonic clock time with valid positive values
	var ts unix.Timespec
	if err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.ClockGettime failed: %v\n", err)
		os.Exit(1)
	}
	if ts.Sec < 0 || ts.Nsec < 0 || ts.Nsec >= 1000000000 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid monotonic timespec: sec=%d, nsec=%d\n", ts.Sec, ts.Nsec)
		os.Exit(1)
	}

	// Assertion 4: unix.Gettid returns a positive caller thread ID
	tid := unix.Gettid()
	if tid <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid thread ID from unix.Gettid: %d\n", tid)
		os.Exit(1)
	}

	fmt.Println("PASS: golang.org/x/sys contract passed")
}

Seeder de origem

anônimo