CodeSampleX

Sample

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

Verified sample for golang github.com/Masterminds/semver/v3 v3.3.0: ErrInvalidSemVer. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:e56962c9910edf517595ca175e9171c3fb2e8ce9648d6403f8883fbceca84a3b

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify github.com/Masterminds/semver/v3.ErrInvalidSemVer in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0
Packages
Symbols
  • github.com/Masterminds/semver/v3.ErrInvalidSemVer
Created
2026-09-06T13:12:19Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

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

Origin Seeder

anonymous