CodeSampleX

샘플

github.com/chzyer/readline v1.5.1: NewEx

검증된 샘플 — golang github.com/chzyer/readline v1.5.1: NewEx. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: readline.NewEx creates a valid Instance…

sha256:2e8b97f27f0e940b10efa0c3e2729d0d9357aa6ac69f1f737418786e6fb57a0c

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 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-06

케이스

HOW
목표
verify github.com/chzyer/readline.NewEx in pkg:golang/github.com/chzyer/readline@v1.5.1
패키지
심벌
  • github.com/chzyer/readline.NewEx
환경
go 1.26.6
생성일
2026-09-06T02:27:53Z

컨트랙트

  1. readline.NewEx creates a valid Instance from a custom Config with specified Prompt and streams
  2. readline.NewEx reads sequential lines from configured custom Stdin
  3. readline.NewEx returns io.EOF on Readline when configured Stdin is exhausted
  4. readline.NewEx instance allows dynamic prompt updates via SetPrompt
  5. readline.NewEx accepts AutoComplete prefix completer in Config
  6. readline.NewEx instance generates masked password config via GenPasswordConfig
  7. readline.NewEx instance Close method cleanly releases terminal resources

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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 github.com/chzyer/readline.NewEx in pkg:golang/github.com/chzyer/readline@v1.5.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/chzyer/readline@v1.5.1
Demonstrate these symbols/APIs:
  - github.com/chzyer/readline.NewEx

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:6141b1523971cc4fcb4ae0e32f7205e17c1b945aae27e1ef4108dfd98b49aedd","contract":["readline.NewEx creates a valid Instance from a custom Config with specified Prompt and streams","readline.NewEx reads sequential lines from configured custom Stdin","readline.NewEx returns io.EOF on Readline when configured Stdin is exhausted","readline.NewEx instance allows dynamic prompt updates via SetPrompt","readline.NewEx accepts AutoComplete prefix completer in Config","readline.NewEx instance generates masked password config via GenPasswordConfig","readline.NewEx instance Close method cleanly releases terminal resources"],"goal":"verify github.com/chzyer/readline.NewEx in pkg:golang/github.com/chzyer/readline@v1.5.1","kind":"HOW","packages":["pkg:golang/github.com/chzyer/readline@v1.5.1"],"schemaVersion":1,"symbols":["github.com/chzyer/readline.NewEx"]},"contractCommand":["go","run","./test"],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","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/github.com/chzyer/readline@v1.5.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/chzyer/readline@v1.5.1","symbols":["github.com/chzyer/readline.NewEx"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/chzyer/readline v1.5.1

require golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
go.sum
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
main.go
package main

import (
	"bytes"
	"fmt"
	"io"
	"strings"

	"github.com/chzyer/readline"
)

func main() {
	// Demonstrates configuring and using readline.NewEx with custom parameters
	completer := readline.NewPrefixCompleter(
		readline.PcItem("help"),
		readline.PcItem("version"),
		readline.PcItem("exit"),
	)

	// In an interactive shell os.Stdin and os.Stdout are typically used,
	// but NewEx allows supplying custom io.ReadCloser and io.Writer streams.
	input := strings.NewReader("help\nversion\nexit\n")
	output := &bytes.Buffer{}

	cfg := &readline.Config{
		Prompt:                 "demo> ",
		Stdin:                  io.NopCloser(input),
		Stdout:                 output,
		AutoComplete:           completer,
		HistoryLimit:           100,
		DisableAutoSaveHistory: true,
	}

	rl, err := readline.NewEx(cfg)
	if err != nil {
		fmt.Printf("failed to initialize readline instance: %v\n", err)
		return
	}
	defer rl.Close()

	for {
		line, err := rl.Readline()
		if err != nil {
			if err == io.EOF {
				break
			}
			fmt.Printf("read error: %v\n", err)
			break
		}
		fmt.Printf("received line: %s\n", line)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/chzyer/readline.NewEx in pkg:golang/github.com/chzyer/readline@v1.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/chzyer/readline@v1.5.1"
  ],
  "symbols": [
    "github.com/chzyer/readline.NewEx"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"

	"github.com/chzyer/readline"
)

func main() {
	// Contract 1: readline.NewEx creates a valid Instance from a custom Config with specified Prompt and streams
	{
		in := io.NopCloser(strings.NewReader("ping\npong\n"))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "prompt> ",
			Stdin:                  in,
			Stdout:                 out,
			HistoryLimit:           50,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 1 failed: readline.NewEx returned error: %v\n", err)
			os.Exit(1)
		}
		if rl == nil {
			fmt.Fprintln(os.Stderr, "Contract 1 failed: readline.NewEx returned nil instance")
			os.Exit(1)
		}
		if rl.Config == nil || rl.Config.Prompt != "prompt> " {
			fmt.Fprintf(os.Stderr, "Contract 1 failed: rl.Config.Prompt got %q, want %q\n", rl.Config.Prompt, "prompt> ")
			_ = rl.Close()
			os.Exit(1)
		}
		_ = rl.Close()
	}

	// Contract 2: readline.NewEx reads sequential lines from configured custom Stdin
	{
		in := io.NopCloser(strings.NewReader("first line\nsecond line\n"))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "> ",
			Stdin:                  in,
			Stdout:                 out,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 2 failed: NewEx error: %v\n", err)
			os.Exit(1)
		}

		line1, err := rl.Readline()
		if err != nil || line1 != "first line" {
			fmt.Fprintf(os.Stderr, "Contract 2 failed: line 1 got %q (err: %v), want %q\n", line1, err, "first line")
			_ = rl.Close()
			os.Exit(1)
		}

		line2, err := rl.Readline()
		if err != nil || line2 != "second line" {
			fmt.Fprintf(os.Stderr, "Contract 2 failed: line 2 got %q (err: %v), want %q\n", line2, err, "second line")
			_ = rl.Close()
			os.Exit(1)
		}
		_ = rl.Close()
	}

	// Contract 3: readline.NewEx returns io.EOF on Readline when configured Stdin is exhausted
	{
		in := io.NopCloser(strings.NewReader("only-one\n"))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "> ",
			Stdin:                  in,
			Stdout:                 out,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: NewEx error: %v\n", err)
			os.Exit(1)
		}

		_, err = rl.Readline()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: first read error: %v\n", err)
			_ = rl.Close()
			os.Exit(1)
		}

		_, err = rl.Readline()
		if err != io.EOF {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: expected io.EOF, got: %v\n", err)
			_ = rl.Close()
			os.Exit(1)
		}
		_ = rl.Close()
	}

	// Contract 4: readline.NewEx instance allows dynamic prompt updates via SetPrompt
	{
		in := io.NopCloser(strings.NewReader("sample\n"))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "initial> ",
			Stdin:                  in,
			Stdout:                 out,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: NewEx error: %v\n", err)
			os.Exit(1)
		}

		rl.SetPrompt("updated> ")
		line, err := rl.Readline()
		if err != nil || line != "sample" {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: Readline after SetPrompt failed: %v\n", err)
			_ = rl.Close()
			os.Exit(1)
		}
		_ = rl.Close()
	}

	// Contract 5: readline.NewEx accepts AutoComplete prefix completer in Config
	{
		completer := readline.NewPrefixCompleter(
			readline.PcItem("get"),
			readline.PcItem("set"),
		)
		in := io.NopCloser(strings.NewReader("get\n"))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "> ",
			Stdin:                  in,
			Stdout:                 out,
			AutoComplete:           completer,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 5 failed: NewEx with AutoComplete failed: %v\n", err)
			os.Exit(1)
		}

		if rl.Config.AutoComplete == nil {
			fmt.Fprintln(os.Stderr, "Contract 5 failed: AutoComplete is nil in rl.Config")
			_ = rl.Close()
			os.Exit(1)
		}

		line, err := rl.Readline()
		if err != nil || line != "get" {
			fmt.Fprintf(os.Stderr, "Contract 5 failed: Readline got %q, want 'get'\n", line)
			_ = rl.Close()
			os.Exit(1)
		}
		_ = rl.Close()
	}

	// Contract 6: readline.NewEx instance generates masked password config via GenPasswordConfig
	{
		in := io.NopCloser(strings.NewReader("data\n"))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "pass> ",
			Stdin:                  in,
			Stdout:                 out,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 6 failed: NewEx error: %v\n", err)
			os.Exit(1)
		}

		pwdCfg := rl.GenPasswordConfig()
		if pwdCfg == nil {
			fmt.Fprintln(os.Stderr, "Contract 6 failed: GenPasswordConfig returned nil")
			_ = rl.Close()
			os.Exit(1)
		}
		if !pwdCfg.EnableMask {
			fmt.Fprintln(os.Stderr, "Contract 6 failed: EnableMask should be true in GenPasswordConfig")
			_ = rl.Close()
			os.Exit(1)
		}
		_ = rl.Close()
	}

	// Contract 7: readline.NewEx instance Close method cleanly releases terminal resources
	{
		in := io.NopCloser(strings.NewReader(""))
		out := &bytes.Buffer{}
		cfg := &readline.Config{
			Prompt:                 "> ",
			Stdin:                  in,
			Stdout:                 out,
			DisableAutoSaveHistory: true,
		}

		rl, err := readline.NewEx(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 7 failed: NewEx error: %v\n", err)
			os.Exit(1)
		}

		if err := rl.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 7 failed: rl.Close returned error: %v\n", err)
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

오리진 시더

익명