CodeSampleX

Exemple

github.com/fatih/color v1.9.0

Échantillon vérifié pour golang github.com/fatih/color v1.9.0. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:5a2f80d1b2f40db1c50a8926d58aab8b8c02770d0cfededf9a28d9782cd742e0

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:golang/github.com/fatih/color@v1.9.0
Paquets
Créé
2026-10-23T19:40:33Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 d'origine

anonyme