CodeSampleX

Exemplo

github.com/Masterminds/semver/v3 v3.3.0: ErrInvalidSemVer

Amostra verificada para golang github.com/Masterminds/semver/v3 v3.3.0: ErrInvalidSemVer. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:e56962c9910edf517595ca175e9171c3fb2e8ce9648d6403f8883fbceca84a3b

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify github.com/Masterminds/semver/v3.ErrInvalidSemVer in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0
Pacotes
Símbolos
  • github.com/Masterminds/semver/v3.ErrInvalidSemVer
Criado
2026-09-06T13:12:19Z

Contrato

  1. semver.NewVersion returns semver.ErrInvalidSemVer when given an invalid semantic version string
  2. errors.Is(err, semver.ErrInvalidSemVer) evaluates to true for errors returned by semver.NewVersion on invalid semantic version strings
  3. semver.ErrInvalidSemVer.Error() returns "Invalid Semantic Version"
  4. semver.NewVersion parses valid semantic versions without returning semver.ErrInvalidSemVer

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/Masterminds/semver/v3.ErrInvalidSemVer in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/Masterminds/semver/v3@v3.3.0
Demonstrate these symbols/APIs:
  - github.com/Masterminds/semver/v3.ErrInvalidSemVer

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:2e7fa501d8b5c4613e3dd8e193219b7b9ddcdab7b322a7714d59f8103016d5ef","contract":["semver.NewVersion returns semver.ErrInvalidSemVer when given an invalid semantic version string","errors.Is(err, semver.ErrInvalidSemVer) evaluates to true for errors returned by semver.NewVersion on invalid semantic version strings","semver.ErrInvalidSemVer.Error() returns \"Invalid Semantic Version\"","semver.NewVersion parses valid semantic versions without returning semver.ErrInvalidSemVer"],"goal":"verify github.com/Masterminds/semver/v3.ErrInvalidSemVer in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0","kind":"HOW","packages":["pkg:golang/github.com/Masterminds/semver/v3@v3.3.0"],"schemaVersion":1,"symbols":["github.com/Masterminds/semver/v3.ErrInvalidSemVer"]},"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/Masterminds/semver/v3@v3.3.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/Masterminds/semver/v3@v3.3.0","symbols":["github.com/Masterminds/semver/v3.ErrInvalidSemVer"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/Masterminds/semver/v3 v3.3.0
go.sum
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
main.go
package main

import (
	"errors"
	"fmt"

	"github.com/Masterminds/semver/v3"
)

// ValidateVersion attempts to parse a version string and returns true if valid,
// or false along with the error if it fails.
func ValidateVersion(v string) (*semver.Version, error) {
	ver, err := semver.NewVersion(v)
	if err != nil {
		if errors.Is(err, semver.ErrInvalidSemVer) {
			return nil, fmt.Errorf("invalid semantic version format: %w", err)
		}
		return nil, err
	}
	return ver, nil
}

func main() {
	validInput := "1.2.3"
	ver, err := ValidateVersion(validInput)
	if err != nil {
		fmt.Printf("Failed to parse %q: %v\n", validInput, err)
		return
	}
	fmt.Printf("Parsed valid version: %s (major=%d, minor=%d, patch=%d)\n",
		ver.String(), ver.Major(), ver.Minor(), ver.Patch())

	invalidInput := "not-a-semver"
	_, err = ValidateVersion(invalidInput)
	if errors.Is(err, semver.ErrInvalidSemVer) {
		fmt.Printf("Successfully caught ErrInvalidSemVer for input %q: %v\n", invalidInput, err)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/Masterminds/semver/v3.ErrInvalidSemVer in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/Masterminds/semver/v3@v3.3.0"
  ],
  "symbols": [
    "github.com/Masterminds/semver/v3.ErrInvalidSemVer"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"os"

	"github.com/Masterminds/semver/v3"
)

func main() {
	// Assertion 1: semver.NewVersion returns semver.ErrInvalidSemVer when given an invalid semantic version string
	{
		invalidCases := []string{"not-a-semver", "abc.def", "1.2.3.4.5"}
		for _, raw := range invalidCases {
			_, err := semver.NewVersion(raw)
			if err == nil {
				fmt.Fprintf(os.Stderr, "contract violation: expected error for invalid semver string %q, got nil\n", raw)
				os.Exit(1)
			}
			if !errors.Is(err, semver.ErrInvalidSemVer) {
				fmt.Fprintf(os.Stderr, "contract violation: expected errors.Is(err, semver.ErrInvalidSemVer) for %q, got %v\n", raw, err)
				os.Exit(1)
			}
		}
	}

	// Assertion 2: errors.Is(err, semver.ErrInvalidSemVer) evaluates to true for errors returned by semver.NewVersion on invalid semantic version strings
	{
		_, err := semver.NewVersion("invalid-format")
		if !errors.Is(err, semver.ErrInvalidSemVer) {
			fmt.Fprintf(os.Stderr, "contract violation: errors.Is(err, semver.ErrInvalidSemVer) must be true, got %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 3: semver.ErrInvalidSemVer.Error() returns "Invalid Semantic Version"
	{
		expectedMsg := "Invalid Semantic Version"
		actualMsg := semver.ErrInvalidSemVer.Error()
		if actualMsg != expectedMsg {
			fmt.Fprintf(os.Stderr, "contract violation: expected ErrInvalidSemVer.Error() to be %q, got %q\n", expectedMsg, actualMsg)
			os.Exit(1)
		}
	}

	// Assertion 4: semver.NewVersion parses valid semantic versions without returning semver.ErrInvalidSemVer
	{
		validCases := []string{"1.2.3", "v2.0.1", "0.1.0-alpha.1", "3.4.5+build.100"}
		for _, raw := range validCases {
			ver, err := semver.NewVersion(raw)
			if err != nil {
				fmt.Fprintf(os.Stderr, "contract violation: valid semver string %q returned unexpected error: %v\n", raw, err)
				os.Exit(1)
			}
			if ver == nil {
				fmt.Fprintf(os.Stderr, "contract violation: parsed version is nil for %q\n", raw)
				os.Exit(1)
			}
		}
	}

	fmt.Println("CONTRACT_PASS")
}

Seeder de origem

anônimo