CodeSampleX

Beispiel

golang.org/x/term v0.42.0: IsTerminal

Verifiziertes Beispiel für golang golang.org/x/term v0.42.0: IsTerminal. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:8003580c522d4dfd130a0aedc0c3c2c776a7d010d50dfe13080a8773ee9ba257

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify pkg:golang/golang.org/x/term@v0.42.0
Pakete
Symbole
  • term.IsTerminal
Erstellt
2026-09-18T13:46:52Z

Contract

  1. term.IsTerminal returns false for invalid file descriptors
  2. term.IsTerminal returns false for regular file descriptors
  3. term.IsTerminal returns false for pipe file descriptors
  4. term.IsTerminal evaluates standard stream file descriptors without panicking

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/term@v0.42.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/term@v0.42.0
Demonstrate these symbols/APIs:
  - term.IsTerminal

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:c64541ce1fbb061af44c2e98241668524b47a0aae11b67548a98a4d79313c9d4","contract":["term.IsTerminal returns false for invalid file descriptors","term.IsTerminal returns false for regular file descriptors","term.IsTerminal returns false for pipe file descriptors","term.IsTerminal evaluates standard stream file descriptors without panicking"],"goal":"verify pkg:golang/golang.org/x/term@v0.42.0","kind":"HOW","packages":["pkg:golang/golang.org/x/term@v0.42.0"],"schemaVersion":1,"symbols":["term.IsTerminal"]},"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/term@v0.42.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/term@v0.42.0","symbols":["term.IsTerminal"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/term v0.42.0

require golang.org/x/sys v0.43.0 // indirect
go.sum
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.42.0 h1:UiKe+zDFmJobeJ5ggPwOshJIVt6/Ft0rcfrXZDLWAWY=
golang.org/x/term v0.42.0/go.mod h1:Dq/D+snpsbazcBG5+F9Q1n2rXV8Ma+71xEjTRufARgY=
main.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/term"
)

// CheckTerminal checks whether the provided file descriptor refers to a terminal.
func CheckTerminal(fd int) bool {
	return term.IsTerminal(fd)
}

func main() {
	stdinFd := int(os.Stdin.Fd())
	stdoutFd := int(os.Stdout.Fd())
	stderrFd := int(os.Stderr.Fd())

	fmt.Printf("Stdin (fd=%d) is terminal: %v\n", stdinFd, CheckTerminal(stdinFd))
	fmt.Printf("Stdout (fd=%d) is terminal: %v\n", stdoutFd, CheckTerminal(stdoutFd))
	fmt.Printf("Stderr (fd=%d) is terminal: %v\n", stderrFd, CheckTerminal(stderrFd))
	fmt.Printf("Invalid fd (-1) is terminal: %v\n", CheckTerminal(-1))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/term@v0.42.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/term@v0.42.0"
  ],
  "symbols": [
    "term.IsTerminal"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/term"
)

func main() {
	// Assertion 1: term.IsTerminal returns false for invalid file descriptors
	if term.IsTerminal(-1) {
		fmt.Fprintf(os.Stderr, "FAIL: expected false for fd=-1, got true\n")
		os.Exit(1)
	}
	if term.IsTerminal(-999) {
		fmt.Fprintf(os.Stderr, "FAIL: expected false for fd=-999, got true\n")
		os.Exit(1)
	}

	// Assertion 2: term.IsTerminal returns false for regular file descriptors
	tmpFile, err := os.CreateTemp("", "contract_term_test_*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: failed to create temporary file: %v\n", err)
		os.Exit(1)
	}
	defer os.Remove(tmpFile.Name())
	defer tmpFile.Close()

	if term.IsTerminal(int(tmpFile.Fd())) {
		fmt.Fprintf(os.Stderr, "FAIL: expected false for regular file fd, got true\n")
		os.Exit(1)
	}

	// Assertion 3: term.IsTerminal returns false for pipe file descriptors
	r, w, err := os.Pipe()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: failed to create pipe: %v\n", err)
		os.Exit(1)
	}
	defer r.Close()
	defer w.Close()

	if term.IsTerminal(int(r.Fd())) {
		fmt.Fprintf(os.Stderr, "FAIL: expected false for pipe reader fd, got true\n")
		os.Exit(1)
	}
	if term.IsTerminal(int(w.Fd())) {
		fmt.Fprintf(os.Stderr, "FAIL: expected false for pipe writer fd, got true\n")
		os.Exit(1)
	}

	// Assertion 4: term.IsTerminal evaluates standard stream file descriptors without panicking
	_ = term.IsTerminal(int(os.Stdin.Fd()))
	_ = term.IsTerminal(int(os.Stdout.Fd()))
	_ = term.IsTerminal(int(os.Stderr.Fd()))

	fmt.Println("PASS: term.IsTerminal contract verified")
}

Ursprungs-Seeder

anonym