CodeSampleX

샘플

github.com/fatih/color v1.9.0

검증된 샘플 — golang github.com/fatih/color v1.9.0. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: color.New with EnableColor wraps strings in ANSI…

sha256:5a2f80d1b2f40db1c50a8926d58aab8b8c02770d0cfededf9a28d9782cd742e0

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
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-10-23

케이스

HOW
목표
verify pkg:golang/github.com/fatih/color@v1.9.0
패키지
생성일
2026-10-23T19:40:33Z

컨트랙트

  1. color.New with EnableColor wraps strings in ANSI SGR escape sequences for single and combined Attribute values via SprintFunc
  2. Color.DisableColor suppresses ANSI escape sequences and returns the plain input string
  3. color.RedString respects the global color.NoColor boolean flag to toggle ANSI formatting
  4. Color.Add appends additional Attribute values to an existing Color instance and SprintfFunc formats combined SGR sequences
  5. Color.Fprint writes ANSI-formatted output to a provided io.Writer

파일

  • PROMPT.md
  • color_sample.go
  • csx.json
  • go.mod
  • go.sum
  • 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 pkg:golang/github.com/fatih/color@v1.9.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/fatih/color@v1.9.0

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.
color_sample.go
package sample

import (
	"bytes"

	"github.com/fatih/color"
)

// FormatColored returns a string formatted with the given color attributes when color output is enabled.
func FormatColored(text string, attrs ...color.Attribute) string {
	c := color.New(attrs...)
	c.EnableColor()
	return c.SprintFunc()(text)
}

// FormatPlain returns a string with color output explicitly disabled on the Color instance.
func FormatPlain(text string, attrs ...color.Attribute) string {
	c := color.New(attrs...)
	c.DisableColor()
	return c.SprintFunc()(text)
}

// WriteColored writes colored output to a bytes.Buffer using Fprint.
func WriteColored(text string, attrs ...color.Attribute) string {
	var buf bytes.Buffer
	c := color.New(attrs...)
	c.EnableColor()
	_, _ = c.Fprint(&buf, text)
	return buf.String()
}
csx.json
{"case":{"caseId":"case:sha256:54ad4d0f4b1cb12aa2339ad771dc2844816b93e0194d9502bcc7ebdbe94ad88b","contract":["color.New with EnableColor wraps strings in ANSI SGR escape sequences for single and combined Attribute values via SprintFunc","Color.DisableColor suppresses ANSI escape sequences and returns the plain input string","color.RedString respects the global color.NoColor boolean flag to toggle ANSI formatting","Color.Add appends additional Attribute values to an existing Color instance and SprintfFunc formats combined SGR sequences","Color.Fprint writes ANSI-formatted output to a provided io.Writer"],"goal":"verify pkg:golang/github.com/fatih/color@v1.9.0","kind":"HOW","packages":["pkg:golang/github.com/fatih/color@v1.9.0"],"schemaVersion":1},"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/fatih/color@v1.9.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/fatih/color@v1.9.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/fatih/color v1.9.0

require (
	github.com/mattn/go-colorable v0.1.4 // indirect
	github.com/mattn/go-isatty v0.0.11 // indirect
	golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
)
go.sum
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/fatih/color@v1.9.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/fatih/color@v1.9.0"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/fatih/color"
	"sample"
)

func main() {
	// Ensure deterministic global state for tests
	color.NoColor = false

	// Assertion 1: color.New with EnableColor wraps text in expected ANSI SGR sequences
	gotRed := sample.FormatColored("alert", color.FgRed)
	expectedRed := "\x1b[31malert\x1b[0m"
	if gotRed != expectedRed {
		fmt.Fprintf(os.Stderr, "FAIL: FormatColored FgRed got %q, want %q\n", gotRed, expectedRed)
		os.Exit(1)
	}

	gotBoldGreen := sample.FormatColored("ok", color.FgGreen, color.Bold)
	expectedBoldGreen := "\x1b[32;1mok\x1b[0m"
	if gotBoldGreen != expectedBoldGreen {
		fmt.Fprintf(os.Stderr, "FAIL: FormatColored FgGreen+Bold got %q, want %q\n", gotBoldGreen, expectedBoldGreen)
		os.Exit(1)
	}

	// Assertion 2: DisableColor suppresses ANSI escape sequences on a Color instance
	gotPlain := sample.FormatPlain("plain", color.FgRed, color.Underline)
	if gotPlain != "plain" {
		fmt.Fprintf(os.Stderr, "FAIL: FormatPlain got %q, want %q\n", gotPlain, "plain")
		os.Exit(1)
	}

	// Assertion 3: Package-level string helpers respect color.NoColor toggle
	color.NoColor = false
	if s := color.RedString("err-%d", 42); s != "\x1b[31merr-42\x1b[0m" {
		fmt.Fprintf(os.Stderr, "FAIL: RedString with NoColor=false got %q\n", s)
		os.Exit(1)
	}
	color.NoColor = true
	if s := color.RedString("err-%d", 42); s != "err-42" {
		fmt.Fprintf(os.Stderr, "FAIL: RedString with NoColor=true got %q\n", s)
		os.Exit(1)
	}
	color.NoColor = false

	// Assertion 4: Color.Add chains attributes and Color.Fprint writes ANSI output to io.Writer
	c := color.New(color.FgCyan)
	c.EnableColor()
	c.Add(color.Underline)
	sprintfFn := c.SprintfFunc()
	if s := sprintfFn("item=%s", "x"); s != "\x1b[36;4mitem=x\x1b[0m" {
		fmt.Fprintf(os.Stderr, "FAIL: SprintfFunc after Add got %q\n", s)
		os.Exit(1)
	}

	written := sample.WriteColored("stream", color.FgYellow)
	if written != "\x1b[33mstream\x1b[0m" {
		fmt.Fprintf(os.Stderr, "FAIL: WriteColored got %q\n", written)
		os.Exit(1)
	}

	fmt.Println("PASS: github.com/fatih/color@v1.9.0 contract verified")
}

오리진 시더

익명