Sample
github.com/Masterminds/semver/v3 v3.3.0: NewVersion
Verified sample for golang github.com/Masterminds/semver/v3 v3.3.0: NewVersion. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:89986496931157225c82dc897ff8c4c20e8c85e251e5d139a17a7702e6afe63d
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.NewVersion in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0
- Symbols
-
- github.com/Masterminds/semver/v3.NewVersion
- Created
- 2026-09-06T12:54:27Z
Contract
- semver.NewVersion parses valid semantic version strings into major, minor, and patch numeric components.
- semver.NewVersion accepts optional leading 'v' prefix, normalizing canonical output in String() while retaining input in Original().
- semver.NewVersion parses prerelease tags and build metadata segments into Prerelease() and Metadata().
- semver.NewVersion coerces short version strings with omitted minor or patch numbers by defaulting missing components to zero.
- semver.NewVersion returns ErrInvalidSemVer when provided an invalid or empty version string.
- Versions parsed with semver.NewVersion support precedence comparisons where build metadata is ignored for equality.
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
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.NewVersion 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.NewVersion
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.
{"case":{"caseId":"case:sha256:e23083e1f37e140e7de488d51c8a5d996abf4bb9b80701151848fbfaaaeba253","contract":["semver.NewVersion parses valid semantic version strings into major, minor, and patch numeric components.","semver.NewVersion accepts optional leading 'v' prefix, normalizing canonical output in String() while retaining input in Original().","semver.NewVersion parses prerelease tags and build metadata segments into Prerelease() and Metadata().","semver.NewVersion coerces short version strings with omitted minor or patch numbers by defaulting missing components to zero.","semver.NewVersion returns ErrInvalidSemVer when provided an invalid or empty version string.","Versions parsed with semver.NewVersion support precedence comparisons where build metadata is ignored for equality."],"goal":"verify github.com/Masterminds/semver/v3.NewVersion 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.NewVersion"]},"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.NewVersion"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/Masterminds/semver/v3 v3.3.0
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=
package main
import (
"errors"
"fmt"
"os"
"github.com/Masterminds/semver/v3"
)
func main() {
// Parse a semantic version string with prerelease and build metadata
v, err := semver.NewVersion("v1.5.0-rc.1+build.1024")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse version: %v\n", err)
os.Exit(1)
}
fmt.Printf("Original: %s\n", v.Original())
fmt.Printf("Normalized: %s\n", v.String())
fmt.Printf("Major: %d, Minor: %d, Patch: %d\n", v.Major(), v.Minor(), v.Patch())
fmt.Printf("Prerelease: %s\n", v.Prerelease())
fmt.Printf("Metadata: %s\n", v.Metadata())
// Compare with another version
other, err := semver.NewVersion("1.5.0")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse other version: %v\n", err)
os.Exit(1)
}
if v.LessThan(other) {
fmt.Printf("%s is less than %s\n", v, other)
}
// Handle invalid version strings
_, errInvalid := semver.NewVersion("invalid.version")
if errors.Is(errInvalid, semver.ErrInvalidSemVer) {
fmt.Println("Successfully caught ErrInvalidSemVer for invalid input")
}
}
{
"schemaVersion": 1,
"goal": "verify github.com/Masterminds/semver/v3.NewVersion 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.NewVersion"
]
}
package main
import (
"errors"
"fmt"
"os"
"github.com/Masterminds/semver/v3"
)
func main() {
if err := runContractTests(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: all contract assertions passed")
}
func runContractTests() error {
// 1. semver.NewVersion parses valid semantic version strings into major, minor, and patch numeric components.
{
v, err := semver.NewVersion("2.14.7")
if err != nil {
return fmt.Errorf("failed parsing valid version: %w", err)
}
if v.Major() != 2 {
return fmt.Errorf("expected Major 2, got %d", v.Major())
}
if v.Minor() != 14 {
return fmt.Errorf("expected Minor 14, got %d", v.Minor())
}
if v.Patch() != 7 {
return fmt.Errorf("expected Patch 7, got %d", v.Patch())
}
}
// 2. semver.NewVersion accepts optional leading 'v' prefix, normalizing canonical output in String() while retaining input in Original().
{
v, err := semver.NewVersion("v3.8.1")
if err != nil {
return fmt.Errorf("failed parsing version with v prefix: %w", err)
}
if v.Original() != "v3.8.1" {
return fmt.Errorf("expected Original 'v3.8.1', got %q", v.Original())
}
if v.String() != "3.8.1" {
return fmt.Errorf("expected String '3.8.1', got %q", v.String())
}
if v.Major() != 3 || v.Minor() != 8 || v.Patch() != 1 {
return fmt.Errorf("unexpected components: %d.%d.%d", v.Major(), v.Minor(), v.Patch())
}
}
// 3. semver.NewVersion parses prerelease tags and build metadata segments into Prerelease() and Metadata().
{
v, err := semver.NewVersion("1.0.0-alpha.1+exp.sha.5114f85")
if err != nil {
return fmt.Errorf("failed parsing prerelease and metadata: %w", err)
}
if v.Prerelease() != "alpha.1" {
return fmt.Errorf("expected Prerelease 'alpha.1', got %q", v.Prerelease())
}
if v.Metadata() != "exp.sha.5114f85" {
return fmt.Errorf("expected Metadata 'exp.sha.5114f85', got %q", v.Metadata())
}
}
// 4. semver.NewVersion coerces short version strings with omitted minor or patch numbers by defaulting missing components to zero.
{
v1, err := semver.NewVersion("4")
if err != nil {
return fmt.Errorf("failed parsing major-only version: %w", err)
}
if v1.Major() != 4 || v1.Minor() != 0 || v1.Patch() != 0 {
return fmt.Errorf("expected 4.0.0 for '4', got %d.%d.%d", v1.Major(), v1.Minor(), v1.Patch())
}
if v1.String() != "4.0.0" {
return fmt.Errorf("expected String '4.0.0', got %q", v1.String())
}
v2, err := semver.NewVersion("4.2")
if err != nil {
return fmt.Errorf("failed parsing major.minor version: %w", err)
}
if v2.Major() != 4 || v2.Minor() != 2 || v2.Patch() != 0 {
return fmt.Errorf("expected 4.2.0 for '4.2', got %d.%d.%d", v2.Major(), v2.Minor(), v2.Patch())
}
if v2.String() != "4.2.0" {
return fmt.Errorf("expected String '4.2.0', got %q", v2.String())
}
}
// 5. semver.NewVersion returns ErrInvalidSemVer when provided an invalid or empty version string.
{
invalidInputs := []string{"", "invalid-text", "1.2.3.4", "v.1.2"}
for _, input := range invalidInputs {
_, err := semver.NewVersion(input)
if err == nil {
return fmt.Errorf("expected error for input %q, but got nil", input)
}
if !errors.Is(err, semver.ErrInvalidSemVer) {
return fmt.Errorf("expected ErrInvalidSemVer for input %q, got: %w", input, err)
}
}
}
// 6. Versions parsed with semver.NewVersion support precedence comparisons where build metadata is ignored for equality.
{
vPre, err := semver.NewVersion("1.0.0-alpha")
if err != nil {
return fmt.Errorf("failed to parse vPre: %w", err)
}
vRelease, err := semver.NewVersion("1.0.0")
if err != nil {
return fmt.Errorf("failed to parse vRelease: %w", err)
}
vMeta1, err := semver.NewVersion("1.0.0+build.1")
if err != nil {
return fmt.Errorf("failed to parse vMeta1: %w", err)
}
vMeta2, err := semver.NewVersion("1.0.0+build.2")
if err != nil {
return fmt.Errorf("failed to parse vMeta2: %w", err)
}
if !vPre.LessThan(vRelease) {
return fmt.Errorf("expected %s < %s", vPre, vRelease)
}
if !vRelease.GreaterThan(vPre) {
return fmt.Errorf("expected %s > %s", vRelease, vPre)
}
if !vMeta1.Equal(vMeta2) {
return fmt.Errorf("expected %s == %s (ignoring metadata)", vMeta1, vMeta2)
}
if cmp := vMeta1.Compare(vMeta2); cmp != 0 {
return fmt.Errorf("expected Compare to return 0, got %d", cmp)
}
}
return nil
}
Origin Seeder
anonymous