CodeSampleX

Ejemplo

github.com/fatih/color v1.9.0

Muestra verificada para golang github.com/fatih/color v1.9.0. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:5a2f80d1b2f40db1c50a8926d58aab8b8c02770d0cfededf9a28d9782cd742e0

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:golang/github.com/fatih/color@v1.9.0
Paquetes
Creado
2026-10-23T19:40:33Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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")
}

Seeder de origen

anónimo