CodeSampleX

Exemple

github.com/kr/pty v1.1.8: pty

Échantillon vérifié pour golang github.com/kr/pty v1.1.8: pty. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:f9d84a3ba6e10d54d89d67b4e49e8fe5a0c2530b3ef6aaf25eb664785d7ced78

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-09-15

Cas

HOW
Objectif
verify pty in pkg:golang/github.com/kr/pty@v1.1.8
Paquets
Symboles
  • pty
Créé
2026-09-15T00:05:28Z

Contrat

  1. pty.Open returns non-nil pty master and pts slave terminal files
  2. pty.Setsize and pty.Getsize configure and report terminal window rows and columns
  3. pty.GetsizeFull returns Winsize matching configured rows and columns
  4. pty.InheritSize propagates window dimensions from pty master to slave
  5. data written to slave terminal is received on pty master

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 pty in pkg:golang/github.com/kr/pty@v1.1.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/kr/pty@v1.1.8
Demonstrate these symbols/APIs:
  - pty

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:934ec249eb61c1b4087a0381f5533535861bf452645516259d56087276ebda94","contract":["pty.Open returns non-nil pty master and pts slave terminal files","pty.Setsize and pty.Getsize configure and report terminal window rows and columns","pty.GetsizeFull returns Winsize matching configured rows and columns","pty.InheritSize propagates window dimensions from pty master to slave","data written to slave terminal is received on pty master"],"goal":"verify pty in pkg:golang/github.com/kr/pty@v1.1.8","kind":"HOW","packages":["pkg:golang/github.com/kr/pty@v1.1.8"],"schemaVersion":1,"symbols":["pty"]},"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/github.com/kr/pty@v1.1.8"],"schemaVersion":1,"subject":"pkg:golang/github.com/kr/pty@v1.1.8","symbols":["pty"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/kr/pty v1.1.8

require (
	github.com/creack/pty v1.1.7 // indirect
	golang.org/x/sys v0.48.0 // indirect
)
go.sum
github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
main.go
package main

import (
	"fmt"
	"os"

	"github.com/kr/pty"
)

func main() {
	ptmx, pts, err := pty.Open()
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to open pty: %v\n", err)
		os.Exit(1)
	}
	defer ptmx.Close()
	defer pts.Close()

	size := &pty.Winsize{Rows: 24, Cols: 80}
	if err := pty.Setsize(ptmx, size); err != nil {
		fmt.Fprintf(os.Stderr, "failed to set size: %v\n", err)
		os.Exit(1)
	}

	rows, cols, err := pty.Getsize(ptmx)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get size: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("pty window size: rows=%d, cols=%d\n", rows, cols)

	message := []byte("hello from pty\n")
	if _, err := pts.Write(message); err != nil {
		fmt.Fprintf(os.Stderr, "failed to write to slave: %v\n", err)
		os.Exit(1)
	}

	buf := make([]byte, 64)
	n, err := ptmx.Read(buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to read from master: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("received on master: %s", string(buf[:n]))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pty in pkg:golang/github.com/kr/pty@v1.1.8",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/kr/pty@v1.1.8"
  ],
  "symbols": [
    "pty"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/kr/pty"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract assertions passed.")
}

func runContractTests() error {
	// 1. pty.Open returns non-nil pty master and pts slave terminal files
	ptmx, pts, err := pty.Open()
	if err != nil {
		return fmt.Errorf("pty.Open failed: %w", err)
	}
	defer ptmx.Close()
	defer pts.Close()

	if ptmx == nil || pts == nil {
		return fmt.Errorf("pty.Open returned nil file descriptor")
	}
	if ptmx.Fd() == 0 || pts.Fd() == 0 {
		return fmt.Errorf("invalid file descriptor returned")
	}

	// 2. pty.Setsize and pty.Getsize configure and report terminal window rows and columns
	initialSize := &pty.Winsize{Rows: 30, Cols: 100, X: 0, Y: 0}
	if err := pty.Setsize(ptmx, initialSize); err != nil {
		return fmt.Errorf("pty.Setsize failed: %w", err)
	}
	rows, cols, err := pty.Getsize(ptmx)
	if err != nil {
		return fmt.Errorf("pty.Getsize failed: %w", err)
	}
	if rows != 30 || cols != 100 {
		return fmt.Errorf("expected rows=30, cols=100; got rows=%d, cols=%d", rows, cols)
	}

	// 3. pty.GetsizeFull returns Winsize matching configured rows and columns
	fullSize, err := pty.GetsizeFull(ptmx)
	if err != nil {
		return fmt.Errorf("pty.GetsizeFull failed: %w", err)
	}
	if fullSize.Rows != 30 || fullSize.Cols != 100 {
		return fmt.Errorf("expected fullSize rows=30, cols=100; got rows=%d, cols=%d", fullSize.Rows, fullSize.Cols)
	}

	// 4. pty.InheritSize propagates window dimensions from pty master to slave
	newSize := &pty.Winsize{Rows: 48, Cols: 132, X: 1280, Y: 800}
	if err := pty.Setsize(ptmx, newSize); err != nil {
		return fmt.Errorf("pty.Setsize newSize failed: %w", err)
	}
	if err := pty.InheritSize(ptmx, pts); err != nil {
		return fmt.Errorf("pty.InheritSize failed: %w", err)
	}
	slaveRows, slaveCols, err := pty.Getsize(pts)
	if err != nil {
		return fmt.Errorf("pty.Getsize(pts) failed: %w", err)
	}
	if slaveRows != 48 || slaveCols != 132 {
		return fmt.Errorf("expected slave rows=48, cols=132; got rows=%d, cols=%d", slaveRows, slaveCols)
	}

	// 5. data written to slave terminal is received on pty master
	payload := []byte("CodeSampleX verification payload\n")
	if _, err := pts.Write(payload); err != nil {
		return fmt.Errorf("pts.Write failed: %w", err)
	}

	buf := make([]byte, 128)
	n, err := ptmx.Read(buf)
	if err != nil {
		return fmt.Errorf("ptmx.Read failed: %w", err)
	}
	if !bytes.Contains(buf[:n], []byte("CodeSampleX verification payload")) {
		return fmt.Errorf("expected ptmx buffer to contain payload, got: %q", string(buf[:n]))
	}

	return nil
}

Seeder d'origine

anonyme