示例
github.com/kr/pty v1.1.8
已验证示例 — golang github.com/kr/pty v1.1.8. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: pty.Open opens a connected pseudo-terminal master and slave…
sha256:5eec50dc9e5762039dbc8a22dbd833e5fbfc52814156dcba806d8462b7bc3650
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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-09-14 |
案例
HOW- 目标
- verify pkg:golang/github.com/kr/pty@v1.1.8
- 环境
- go 1.26.6
- 创建时间
- 2026-09-14T23:31:03Z
契约
- pty.Open opens a connected pseudo-terminal master and slave pair returning valid file descriptors
- pty.Setsize configures terminal window dimensions and pty.Getsize retrieves the rows and columns
- pty.GetsizeFull retrieves complete terminal size description including row, column, and pixel dimensions
- pty.InheritSize propagates terminal window dimensions from pty master to slave tty
- pty.Winsize defines terminal geometry with rows, columns, and graphic pixel dimensions
- pty.Open enables attaching slave tty to command standard streams and capturing output from master pty
- pty.Start returns an error on modern Go runtimes due to child file descriptor constraints
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
源代码
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/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
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:b528b3906f4734c3c368636cd416d00ec894dd64e287c6105cbe818abe43b2ba","contract":["pty.Open opens a connected pseudo-terminal master and slave pair returning valid file descriptors","pty.Setsize configures terminal window dimensions and pty.Getsize retrieves the rows and columns","pty.GetsizeFull retrieves complete terminal size description including row, column, and pixel dimensions","pty.InheritSize propagates terminal window dimensions from pty master to slave tty","pty.Winsize defines terminal geometry with rows, columns, and graphic pixel dimensions","pty.Open enables attaching slave tty to command standard streams and capturing output from master pty","pty.Start returns an error on modern Go runtimes due to child file descriptor constraints"],"goal":"verify pkg:golang/github.com/kr/pty@v1.1.8","kind":"HOW","packages":["pkg:golang/github.com/kr/pty@v1.1.8"],"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","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","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","verifierAdapter":"golang@1"}
module 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
)
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=
package main
import (
"bytes"
"fmt"
"io"
"os/exec"
"github.com/kr/pty"
)
func runCommandInPty(name string, args ...string) (string, error) {
master, slave, err := pty.Open()
if err != nil {
return "", err
}
defer master.Close()
size := &pty.Winsize{
Rows: 24,
Cols: 80,
}
if err := pty.Setsize(master, size); err != nil {
slave.Close()
return "", err
}
cmd := exec.Command(name, args...)
cmd.Stdin = slave
cmd.Stdout = slave
cmd.Stderr = slave
if err := cmd.Start(); err != nil {
slave.Close()
return "", err
}
// Close slave in parent so EOF is triggered when command completes
slave.Close()
var buf bytes.Buffer
_, _ = io.Copy(&buf, master)
_ = cmd.Wait()
return buf.String(), nil
}
func main() {
// Demonstrate opening a standalone pty pair
master, slave, err := pty.Open()
if err != nil {
fmt.Printf("failed to open pty: %v\n", err)
return
}
defer master.Close()
defer slave.Close()
size := &pty.Winsize{Rows: 30, Cols: 100}
if err := pty.Setsize(master, size); err != nil {
fmt.Printf("failed to set size: %v\n", err)
return
}
rows, cols, err := pty.Getsize(master)
if err != nil {
fmt.Printf("failed to get size: %v\n", err)
return
}
fmt.Printf("PTY initialized: %dx%d\n", rows, cols)
// Run a command inside a pty
output, err := runCommandInPty("echo", "hello from pty")
if err != nil {
fmt.Printf("command failed: %v\n", err)
return
}
fmt.Printf("Command output: %s", output)
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/kr/pty@v1.1.8",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/kr/pty@v1.1.8"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"strings"
"github.com/kr/pty"
)
func main() {
// Assertion 1: pty.Open opens a connected pseudo-terminal master and slave pair returning valid file descriptors
{
ptyFile, ttyFile, err := pty.Open()
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: Open returned error: %v\n", err)
os.Exit(1)
}
if ptyFile == nil || ttyFile == nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: nil file pointer\n")
os.Exit(1)
}
if ptyFile.Fd() == 0 || ttyFile.Fd() == 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: invalid file descriptor\n")
os.Exit(1)
}
ptyFile.Close()
ttyFile.Close()
}
// Assertion 2: pty.Setsize configures terminal window dimensions and pty.Getsize retrieves the rows and columns
{
ptyFile, ttyFile, err := pty.Open()
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: Open returned error: %v\n", err)
os.Exit(1)
}
defer ptyFile.Close()
defer ttyFile.Close()
ws := &pty.Winsize{Rows: 24, Cols: 80}
if err := pty.Setsize(ptyFile, ws); err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: Setsize returned error: %v\n", err)
os.Exit(1)
}
rows, cols, err := pty.Getsize(ptyFile)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: Getsize returned error: %v\n", err)
os.Exit(1)
}
if rows != 24 || cols != 80 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 24x80, got %dx%d\n", rows, cols)
os.Exit(1)
}
}
// Assertion 3: pty.GetsizeFull retrieves complete terminal size description including row, column, and pixel dimensions
{
ptyFile, ttyFile, err := pty.Open()
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: Open returned error: %v\n", err)
os.Exit(1)
}
defer ptyFile.Close()
defer ttyFile.Close()
ws := &pty.Winsize{Rows: 30, Cols: 100, X: 800, Y: 600}
if err := pty.Setsize(ptyFile, ws); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: Setsize returned error: %v\n", err)
os.Exit(1)
}
fullSize, err := pty.GetsizeFull(ptyFile)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: GetsizeFull returned error: %v\n", err)
os.Exit(1)
}
if fullSize == nil || fullSize.Rows != 30 || fullSize.Cols != 100 || fullSize.X != 800 || fullSize.Y != 600 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected full size: %+v\n", fullSize)
os.Exit(1)
}
}
// Assertion 4: pty.InheritSize propagates terminal window dimensions from pty master to slave tty
{
ptyFile, ttyFile, err := pty.Open()
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: Open returned error: %v\n", err)
os.Exit(1)
}
defer ptyFile.Close()
defer ttyFile.Close()
ws := &pty.Winsize{Rows: 40, Cols: 120}
if err := pty.Setsize(ptyFile, ws); err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: Setsize returned error: %v\n", err)
os.Exit(1)
}
if err := pty.InheritSize(ptyFile, ttyFile); err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: InheritSize returned error: %v\n", err)
os.Exit(1)
}
rows, cols, err := pty.Getsize(ttyFile)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: Getsize on tty returned error: %v\n", err)
os.Exit(1)
}
if rows != 40 || cols != 120 {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected 40x120 on tty, got %dx%d\n", rows, cols)
os.Exit(1)
}
}
// Assertion 5: pty.Winsize defines terminal geometry with rows, columns, and graphic pixel dimensions
{
ws := pty.Winsize{
Rows: 25,
Cols: 80,
X: 640,
Y: 480,
}
if ws.Rows != 25 || ws.Cols != 80 || ws.X != 640 || ws.Y != 480 {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Winsize field mismatch: %+v\n", ws)
os.Exit(1)
}
}
// Assertion 6: pty.Open enables attaching slave tty to command standard streams and capturing output from master pty
{
ptyFile, ttyFile, err := pty.Open()
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Open returned error: %v\n", err)
os.Exit(1)
}
defer ptyFile.Close()
cmd := exec.Command("echo", "contract-test-output")
cmd.Stdin = ttyFile
cmd.Stdout = ttyFile
cmd.Stderr = ttyFile
if err := cmd.Start(); err != nil {
ttyFile.Close()
fmt.Fprintf(os.Stderr, "assertion 6 failed: cmd.Start returned error: %v\n", err)
os.Exit(1)
}
// Close tty in parent process so slave descriptor is exclusively owned by child,
// allowing EOF to be detected on ptyFile when child terminates.
ttyFile.Close()
var buf bytes.Buffer
_, _ = io.Copy(&buf, ptyFile)
if err := cmd.Wait(); err != nil {
fmt.Fprintf(os.Stderr, "assertion 6 failed: cmd.Wait returned error: %v\n", err)
os.Exit(1)
}
output := buf.String()
if !strings.Contains(output, "contract-test-output") {
fmt.Fprintf(os.Stderr, "assertion 6 failed: output %q did not contain expected text\n", output)
os.Exit(1)
}
}
// Assertion 7: pty.Start returns an error on modern Go runtimes due to child file descriptor constraints
{
cmd := exec.Command("echo", "test-pty-start")
f, err := pty.Start(cmd)
if err == nil {
f.Close()
fmt.Fprintf(os.Stderr, "assertion 7 failed: expected pty.Start to return error on Go 1.15+\n")
os.Exit(1)
}
}
fmt.Println("All contract assertions passed.")
}
原始种子者
匿名