CodeSampleX

Пример

github.com/stretchr/testify v1.4.0

Проверенный пример — golang github.com/stretchr/testify v1.4.0. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.

sha256:d678717cca9686bf5abee3892e8d119101a0c62609ef9ce03ce0cdddd0e8f025

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go 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-04

Кейс

HOW
Цель
verify pkg:golang/github.com/stretchr/testify@v1.4.0
Пакеты
Окружение
go 1.26.6
Создан
2026-09-04T19:20:28Z

Контракт

  1. assert.Equal returns true and records no error on equal values, and returns false on inequality or type mismatch
  2. assert.NotEqual returns true when comparing distinct values and returns false when values are identical
  3. assert.Nil returns true for nil pointers and interfaces, and returns false for non-nil references
  4. assert.NotNil returns true for non-nil references and returns false for nil references
  5. assert.NoError returns true for nil errors, while assert.Error returns true on non-nil error and false on nil error
  6. assert.Panics returns true when target function triggers a panic and returns false when function completes normally
  7. assert.NotPanics returns true and records no error when executed function does not panic
  8. assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering
  9. assert.InDelta returns true when numeric difference is within delta threshold and returns false when exceeding threshold

Файлы

  • 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 pkg:golang/github.com/stretchr/testify@v1.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/stretchr/testify@v1.4.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.
csx.json
{"case":{"caseId":"case:sha256:4fc893f8c18575e4878c810f21cc00063423c94110cbd75ea66323bb20a6e94a","contract":["assert.Equal returns true and records no error on equal values, and returns false on inequality or type mismatch","assert.NotEqual returns true when comparing distinct values and returns false when values are identical","assert.Nil returns true for nil pointers and interfaces, and returns false for non-nil references","assert.NotNil returns true for non-nil references and returns false for nil references","assert.NoError returns true for nil errors, while assert.Error returns true on non-nil error and false on nil error","assert.Panics returns true when target function triggers a panic and returns false when function completes normally","assert.NotPanics returns true and records no error when executed function does not panic","assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering","assert.InDelta returns true when numeric difference is within delta threshold and returns false when exceeding threshold"],"goal":"verify pkg:golang/github.com/stretchr/testify@v1.4.0","kind":"HOW","packages":["pkg:golang/github.com/stretchr/testify@v1.4.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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/stretchr/testify@v1.4.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/stretchr/testify@v1.4.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/stretchr/testify v1.4.0

require (
	github.com/davecgh/go-spew v1.1.0 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	gopkg.in/yaml.v2 v2.2.2 // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
main.go
package main

import (
	"errors"
	"fmt"

	"github.com/stretchr/testify/assert"
)

// Reporter collects assertion failures without halting execution.
type Reporter struct {
	errors []string
}

func (r *Reporter) Errorf(format string, args ...interface{}) {
	r.errors = append(r.errors, fmt.Sprintf(format, args...))
}

// Config represents application configuration to validate.
type Config struct {
	Host    string
	Port    int
	Tags    []string
	Timeout float64
}

// ValidateConfig validates config values using testify assertions.
func ValidateConfig(t assert.TestingT, cfg *Config) bool {
	if !assert.NotNil(t, cfg, "config must not be nil") {
		return false
	}
	ok := true
	ok = assert.NotEmpty(t, cfg.Host, "host should not be empty") && ok
	ok = assert.True(t, cfg.Port > 0 && cfg.Port <= 65535, "port should be valid") && ok
	ok = assert.Contains(t, cfg.Tags, "service", "tags should contain service") && ok
	ok = assert.InDelta(t, 5.0, cfg.Timeout, 1.0, "timeout should be approximately 5.0s") && ok
	return ok
}

// Process processes the configuration.
func Process(cfg *Config) error {
	if cfg == nil {
		return errors.New("nil config")
	}
	return nil
}

func main() {
	r := &Reporter{}
	cfg := &Config{
		Host:    "localhost",
		Port:    8080,
		Tags:    []string{"web", "service"},
		Timeout: 5.2,
	}

	valid := ValidateConfig(r, cfg)
	if !valid || len(r.errors) > 0 {
		fmt.Printf("Validation failed with %d errors\n", len(r.errors))
		return
	}

	err := Process(cfg)
	assert.NoError(r, err, "Process should succeed without error")

	fmt.Println("Config validated and processed successfully.")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/stretchr/testify@v1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/stretchr/testify@v1.4.0"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"os"

	"github.com/stretchr/testify/assert"
)

type contractTestingT struct {
	errors []string
	failed bool
}

func (t *contractTestingT) Errorf(format string, args ...interface{}) {
	t.failed = true
	t.errors = append(t.errors, fmt.Sprintf(format, args...))
}

func main() {
	// Assertion 1: assert.Equal returns true and records no error on equal values, and returns false on inequality or type mismatch
	{
		t := &contractTestingT{}
		if !assert.Equal(t, "expected-string", "expected-string") || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: Equal should succeed on matching strings\n")
			os.Exit(1)
		}

		tMismatch := &contractTestingT{}
		if assert.Equal(tMismatch, "value1", "value2") || !tMismatch.failed || len(tMismatch.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: Equal should return false on mismatched values\n")
			os.Exit(1)
		}

		tTypeMismatch := &contractTestingT{}
		if assert.Equal(tTypeMismatch, int(42), int64(42)) || !tTypeMismatch.failed || len(tTypeMismatch.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: Equal should return false on type mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 2: assert.NotEqual returns true when comparing distinct values and returns false when values are identical
	{
		t := &contractTestingT{}
		if !assert.NotEqual(t, 10, 20) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: NotEqual should succeed on distinct values\n")
			os.Exit(1)
		}

		tEqual := &contractTestingT{}
		if assert.NotEqual(tEqual, 10, 10) || !tEqual.failed || len(tEqual.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: NotEqual should return false on identical values\n")
			os.Exit(1)
		}
	}

	// Assertion 3: assert.Nil returns true for nil pointers and interfaces, and returns false for non-nil references
	{
		t := &contractTestingT{}
		var ptr *int = nil
		if !assert.Nil(t, ptr) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: Nil should succeed on nil pointer\n")
			os.Exit(1)
		}

		val := 42
		tNotNil := &contractTestingT{}
		if assert.Nil(tNotNil, &val) || !tNotNil.failed || len(tNotNil.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: Nil should return false on non-nil pointer\n")
			os.Exit(1)
		}
	}

	// Assertion 4: assert.NotNil returns true for non-nil references and returns false for nil references
	{
		t := &contractTestingT{}
		val := "sample"
		if !assert.NotNil(t, &val) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: NotNil should succeed on non-nil value\n")
			os.Exit(1)
		}

		tNil := &contractTestingT{}
		var ptr *string = nil
		if assert.NotNil(tNil, ptr) || !tNil.failed || len(tNil.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: NotNil should return false on nil reference\n")
			os.Exit(1)
		}
	}

	// Assertion 5: assert.NoError returns true for nil errors, while assert.Error returns true on non-nil error and false on nil error
	{
		t := &contractTestingT{}
		if !assert.NoError(t, nil) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: NoError should succeed on nil error\n")
			os.Exit(1)
		}

		sampleErr := errors.New("operation failed")
		tErr := &contractTestingT{}
		if assert.NoError(tErr, sampleErr) || !tErr.failed || len(tErr.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: NoError should fail on non-nil error\n")
			os.Exit(1)
		}

		tErrorSuccess := &contractTestingT{}
		if !assert.Error(tErrorSuccess, sampleErr) || tErrorSuccess.failed || len(tErrorSuccess.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Error should return true on non-nil error\n")
			os.Exit(1)
		}

		tErrorFail := &contractTestingT{}
		if assert.Error(tErrorFail, nil) || !tErrorFail.failed || len(tErrorFail.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Error should return false on nil error\n")
			os.Exit(1)
		}
	}

	// Assertion 6: assert.Panics returns true when target function triggers a panic and returns false when function completes normally
	{
		t := &contractTestingT{}
		didPanic := assert.Panics(t, func() {
			panic("critical failure")
		})
		if !didPanic || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 6 failed: Panics should return true on panic\n")
			os.Exit(1)
		}

		tNoPanic := &contractTestingT{}
		didPanicClean := assert.Panics(tNoPanic, func() {
			// clean function
		})
		if didPanicClean || !tNoPanic.failed || len(tNoPanic.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 6 failed: Panics should return false on clean function\n")
			os.Exit(1)
		}
	}

	// Assertion 7: assert.NotPanics returns true and records no error when executed function does not panic
	{
		t := &contractTestingT{}
		noPanic := assert.NotPanics(t, func() {
			_ = 1 + 1
		})
		if !noPanic || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 7 failed: NotPanics should succeed when function does not panic\n")
			os.Exit(1)
		}

		tPanic := &contractTestingT{}
		noPanicOnCrash := assert.NotPanics(tPanic, func() {
			panic("crash")
		})
		if noPanicOnCrash || !tPanic.failed || len(tPanic.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 7 failed: NotPanics should return false when function panics\n")
			os.Exit(1)
		}
	}

	// Assertion 8: assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering
	{
		t := &contractTestingT{}
		sliceA := []string{"apple", "banana", "cherry"}
		sliceB := []string{"cherry", "apple", "banana"}
		if !assert.ElementsMatch(t, sliceA, sliceB) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 8 failed: ElementsMatch should succeed on permutations\n")
			os.Exit(1)
		}

		tDiff := &contractTestingT{}
		sliceC := []string{"apple", "cherry", "date"}
		if assert.ElementsMatch(tDiff, sliceA, sliceC) || !tDiff.failed || len(tDiff.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 8 failed: ElementsMatch should return false on mismatched elements\n")
			os.Exit(1)
		}
	}

	// Assertion 9: assert.InDelta returns true when numeric difference is within delta threshold and returns false when exceeding threshold
	{
		t := &contractTestingT{}
		if !assert.InDelta(t, 3.14159, 3.14, 0.01) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 9 failed: InDelta should succeed within threshold\n")
			os.Exit(1)
		}

		tExceed := &contractTestingT{}
		if assert.InDelta(tExceed, 3.14159, 3.10, 0.01) || !tExceed.failed || len(tExceed.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 9 failed: InDelta should return false when difference exceeds delta\n")
			os.Exit(1)
		}
	}

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

Исходный сидер

аноним