Ejemplo
github.com/Masterminds/semver/v3 v3.3.0: StrictNewVersion
Muestra verificada para golang github.com/Masterminds/semver/v3 v3.3.0: StrictNewVersion. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y…
sha256:c611bfa6326627cf0c27145f5806efcd0f7fe83f859e0903ac4938ed5ba47d24
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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.StrictNewVersion in pkg:golang/github.com/Masterminds/semver/v3@v3.3.0
- Símbolos
-
- github.com/Masterminds/semver/v3.StrictNewVersion
- Entorno
- go 1.26.6
- Creado
- 2026-09-06T15:17:38Z
Contrato
- semver.StrictNewVersion parses strictly valid SemVer 2.0.0 strings including prerelease and metadata components
- semver.StrictNewVersion rejects version strings with leading v prefix unlike loose NewVersion
- semver.StrictNewVersion rejects invalid SemVer specifications returning sentinel errors
- semver.StrictNewVersion preserves original version string and produces comparable Version instances
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract_test.go
Código fuente
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.StrictNewVersion 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.StrictNewVersion
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:ffb0232f900f0bf85b06d0bcc8f556927671d11722ef2f81dc05583d6fd8c1bd","contract":["semver.StrictNewVersion parses strictly valid SemVer 2.0.0 strings including prerelease and metadata components","semver.StrictNewVersion rejects version strings with leading v prefix unlike loose NewVersion","semver.StrictNewVersion rejects invalid SemVer specifications returning sentinel errors","semver.StrictNewVersion preserves original version string and produces comparable Version instances"],"goal":"verify github.com/Masterminds/semver/v3.StrictNewVersion 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.StrictNewVersion"]},"contractCommand":["go","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/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.StrictNewVersion"],"verifierAdapter":"golang@1"}
module example.com/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 sample
import (
"fmt"
"github.com/Masterminds/semver/v3"
)
// ParseStrict parses a semantic version string strictly adhering to SemVer 2.0.0.
// Unlike NewVersion, it rejects leading 'v' prefixes and numbers with leading zeros.
func ParseStrict(raw string) (*semver.Version, error) {
v, err := semver.StrictNewVersion(raw)
if err != nil {
return nil, fmt.Errorf("invalid strict semver %q: %w", raw, err)
}
return v, nil
}
// CompareParsers demonstrates the difference between NewVersion and StrictNewVersion.
// NewVersion allows loose versions (e.g. "v1.2.3"), while StrictNewVersion requires strict compliance.
func CompareParsers(raw string) (looseOk bool, strictOk bool, strictErr error) {
_, looseErr := semver.NewVersion(raw)
vStrict, strictErr := semver.StrictNewVersion(raw)
return looseErr == nil, strictErr == nil && vStrict != nil, strictErr
}
{
"schemaVersion": 1,
"goal": "verify github.com/Masterminds/semver/v3.StrictNewVersion 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.StrictNewVersion"
]
}
package test
import (
"errors"
"testing"
"example.com/sample"
"github.com/Masterminds/semver/v3"
)
func TestStrictNewVersionValid(t *testing.T) {
testCases := []struct {
input string
major uint64
minor uint64
patch uint64
prerelease string
metadata string
}{
{
input: "1.2.3",
major: 1,
minor: 2,
patch: 3,
prerelease: "",
metadata: "",
},
{
input: "0.1.0",
major: 0,
minor: 1,
patch: 0,
prerelease: "",
metadata: "",
},
{
input: "2.0.1-alpha.1",
major: 2,
minor: 0,
patch: 1,
prerelease: "alpha.1",
metadata: "",
},
{
input: "1.0.0-beta.2+exp.sha.5114f85",
major: 1,
minor: 0,
patch: 0,
prerelease: "beta.2",
metadata: "exp.sha.5114f85",
},
{
input: "1.0.0+20130313144700",
major: 1,
minor: 0,
patch: 0,
prerelease: "",
metadata: "20130313144700",
},
}
for _, tc := range testCases {
v, err := sample.ParseStrict(tc.input)
if err != nil {
t.Fatalf("expected valid strict version for %q, got error: %v", tc.input, err)
}
if v.Major() != tc.major || v.Minor() != tc.minor || v.Patch() != tc.patch {
t.Errorf("for %q, expected %d.%d.%d, got %d.%d.%d",
tc.input, tc.major, tc.minor, tc.patch, v.Major(), v.Minor(), v.Patch())
}
if v.Prerelease() != tc.prerelease {
t.Errorf("for %q, expected prerelease %q, got %q", tc.input, tc.prerelease, v.Prerelease())
}
if v.Metadata() != tc.metadata {
t.Errorf("for %q, expected metadata %q, got %q", tc.input, tc.metadata, v.Metadata())
}
if v.Original() != tc.input {
t.Errorf("for %q, expected Original() %q, got %q", tc.input, tc.input, v.Original())
}
}
}
func TestStrictNewVersionRejectsPrefixV(t *testing.T) {
input := "v1.2.3"
looseOk, strictOk, strictErr := sample.CompareParsers(input)
if !looseOk {
t.Fatalf("expected NewVersion to accept %q", input)
}
if strictOk || strictErr == nil {
t.Fatalf("expected StrictNewVersion to reject %q with 'v' prefix", input)
}
if !errors.Is(strictErr, semver.ErrInvalidCharacters) {
t.Errorf("expected ErrInvalidCharacters for %q, got %v", input, strictErr)
}
upperInput := "V2.0.0"
_, err := semver.StrictNewVersion(upperInput)
if err == nil {
t.Fatalf("expected StrictNewVersion to reject %q with 'V' prefix", upperInput)
}
if !errors.Is(err, semver.ErrInvalidCharacters) {
t.Errorf("expected ErrInvalidCharacters for %q, got %v", upperInput, err)
}
}
func TestStrictNewVersionSentinelErrors(t *testing.T) {
testCases := []struct {
input string
expectedErr error
}{
{"", semver.ErrEmptyString},
{"1.2", semver.ErrInvalidSemVer},
{"1", semver.ErrInvalidSemVer},
{"01.2.3", semver.ErrSegmentStartsZero},
{"1.02.3", semver.ErrSegmentStartsZero},
{"1.2.03", semver.ErrSegmentStartsZero},
{"1.2.3-01", semver.ErrSegmentStartsZero},
{" 1.2.3", semver.ErrInvalidCharacters},
{"1.2.3 ", semver.ErrInvalidCharacters},
{"1.2.3.4", semver.ErrInvalidCharacters},
{"alpha", semver.ErrInvalidSemVer},
{"1.2.3+invalid@meta", semver.ErrInvalidMetadata},
{"1.2.3-invalid@pre", semver.ErrInvalidPrerelease},
}
for _, tc := range testCases {
_, err := semver.StrictNewVersion(tc.input)
if err == nil {
t.Errorf("expected error for input %q, but got nil", tc.input)
continue
}
if !errors.Is(err, tc.expectedErr) {
t.Errorf("for %q, expected %v, got %v", tc.input, tc.expectedErr, err)
}
}
}
func TestStrictNewVersionPrecedence(t *testing.T) {
v1, err := sample.ParseStrict("1.0.0-alpha")
if err != nil {
t.Fatalf("unexpected error parsing v1: %v", err)
}
v2, err := sample.ParseStrict("1.0.0-beta")
if err != nil {
t.Fatalf("unexpected error parsing v2: %v", err)
}
v3, err := sample.ParseStrict("1.0.0")
if err != nil {
t.Fatalf("unexpected error parsing v3: %v", err)
}
if v1.Compare(v2) >= 0 {
t.Errorf("expected %s < %s", v1, v2)
}
if v2.Compare(v3) >= 0 {
t.Errorf("expected %s < %s", v2, v3)
}
if !v1.LessThan(v2) {
t.Errorf("expected v1.LessThan(v2) == true")
}
}
Seeder de origen
anónimo