CodeSampleX

Exemplo

golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1: State

Amostra verificada para golang golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1: State. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:a913dfefca027021f81f0f04ba2c325b4a8ab1760bc97f3f7bfd998649f3d82a

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 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go 1.26 go 1

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-19

Caso

HOW
Objetivo
verify golang.org/x/term.State in pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1
Pacotes
Símbolos
  • golang.org/x/term.State
Ambiente
go 1.26.6
Criado
2026-09-17T23:02:34Z

Contrato

  1. golang.org/x/term.State can be allocated and passed to term.Restore
  2. golang.org/x/term.Restore returns an error when restoring state on a non-terminal pipe descriptor
  3. golang.org/x/term.Restore returns an error when restoring state on an invalid file descriptor
  4. golang.org/x/term.GetState returns an error on non-terminal file descriptors
  5. golang.org/x/term.MakeRaw returns an error and nil State on non-terminal file descriptors

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 golang.org/x/term.State in pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1
Demonstrate these symbols/APIs:
  - golang.org/x/term.State

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:780525b7d6eb0b76e2fb68eb5f1f51b1c705943041d2760ecdb3149406a9b330","contract":["golang.org/x/term.State can be allocated and passed to term.Restore","golang.org/x/term.Restore returns an error when restoring state on a non-terminal pipe descriptor","golang.org/x/term.Restore returns an error when restoring state on an invalid file descriptor","golang.org/x/term.GetState returns an error on non-terminal file descriptors","golang.org/x/term.MakeRaw returns an error and nil State on non-terminal file descriptors"],"goal":"verify golang.org/x/term.State in pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1","kind":"HOW","packages":["pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1"],"schemaVersion":1,"symbols":["golang.org/x/term.State"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","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/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1","symbols":["golang.org/x/term.State"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1

require golang.org/x/sys v0.48.0 // indirect
go.sum
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
main.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/term"
)

func main() {
	fd := int(os.Stdin.Fd())
	if term.IsTerminal(fd) {
		oldState, err := term.GetState(fd)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error getting terminal state: %v\n", err)
			os.Exit(1)
		}
		fmt.Printf("Captured terminal state: %v\n", oldState != nil)

		rawState, err := term.MakeRaw(fd)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error making raw: %v\n", err)
			os.Exit(1)
		}
		defer func() {
			if err := term.Restore(fd, rawState); err != nil {
				fmt.Fprintf(os.Stderr, "Error restoring terminal state: %v\n", err)
			}
		}()
	} else {
		// Non-terminal fallback demonstrating term.State handling
		var dummyState term.State
		err := term.Restore(fd, &dummyState)
		fmt.Printf("Stdin is not a terminal; restore returned expected error: %v\n", err != nil)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/term.State in pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1"
  ],
  "symbols": [
    "golang.org/x/term.State"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/term"
)

func main() {
	// Assertion 1: golang.org/x/term.State can be allocated and passed to term.Restore
	var state term.State
	if err := term.Restore(-1, &state); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Restore(-1, &state) succeeded unexpectedly\n")
		os.Exit(1)
	}

	// Assertion 2: golang.org/x/term.Restore returns an error when restoring state on a non-terminal pipe descriptor
	r, w, err := os.Pipe()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: os.Pipe failed: %v\n", err)
		os.Exit(1)
	}
	defer r.Close()
	defer w.Close()

	dummyState := &term.State{}
	if err := term.Restore(int(r.Fd()), dummyState); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Restore on pipe reader succeeded unexpectedly\n")
		os.Exit(1)
	}
	if err := term.Restore(int(w.Fd()), dummyState); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Restore on pipe writer succeeded unexpectedly\n")
		os.Exit(1)
	}

	// Assertion 3: golang.org/x/term.Restore returns an error when restoring state on an invalid file descriptor
	if err := term.Restore(-1, dummyState); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Restore on invalid fd -1 succeeded unexpectedly\n")
		os.Exit(1)
	}

	// Assertion 4: golang.org/x/term.GetState returns an error on non-terminal file descriptors
	if s, err := term.GetState(int(r.Fd())); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: GetState on pipe reader succeeded unexpectedly: %v\n", s)
		os.Exit(1)
	}
	if s, err := term.GetState(-1); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: GetState on invalid fd -1 succeeded unexpectedly: %v\n", s)
		os.Exit(1)
	}

	// Assertion 5: golang.org/x/term.MakeRaw returns an error and nil State on non-terminal file descriptors
	if rawState, err := term.MakeRaw(int(r.Fd())); err == nil || rawState != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MakeRaw on pipe reader succeeded unexpectedly: %v, %v\n", rawState, err)
		os.Exit(1)
	}
	if rawState, err := term.MakeRaw(-1); err == nil || rawState != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MakeRaw on invalid fd -1 succeeded unexpectedly: %v, %v\n", rawState, err)
		os.Exit(1)
	}

	fmt.Println("PASS: all contract assertions passed")
}

Seeder de origem

anônimo