CodeSampleX

Exemple

github.com/Masterminds/semver/v3 v3.2.0: semver.IncMajor

Échantillon vérifié pour golang github.com/Masterminds/semver/v3 v3.2.0: semver.IncMajor. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et…

sha256:72b37f3d6158b15d79ee76ae522d3e0710cd88e85bd1c0e9d0bf9643dae054d4

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-01

Cas

HOW
Objectif
verify semver.IncMajor in pkg:golang/github.com/Masterminds/semver/v3@v3.2.0
Paquets
Symboles
  • semver.IncMajor
Créé
2026-09-01T01:22:03Z

Contrat

  1. semver.Version.IncMajor increments the major version number by one and resets minor and patch numbers to zero
  2. semver.Version.IncMajor removes any prerelease and build metadata from the resulting version
  3. semver.Version.IncMajor returns a new Version instance without mutating the original Version

Fichiers

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

Télécharger l’artefact source (tar.gz)

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

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

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:df9f557b5c7c928f9f40f4e116f3caf8ab2e596ca5cddecb0d1028351829ad1a","contract":["semver.Version.IncMajor increments the major version number by one and resets minor and patch numbers to zero","semver.Version.IncMajor removes any prerelease and build metadata from the resulting version","semver.Version.IncMajor returns a new Version instance without mutating the original Version"],"goal":"verify semver.IncMajor in pkg:golang/github.com/Masterminds/semver/v3@v3.2.0","kind":"HOW","packages":["pkg:golang/github.com/Masterminds/semver/v3@v3.2.0"],"schemaVersion":1,"symbols":["semver.IncMajor"]},"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.2.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/Masterminds/semver/v3@v3.2.0","symbols":["semver.IncMajor"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26

require github.com/Masterminds/semver/v3 v3.2.0
go.sum
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
main.go
package main

import (
	"fmt"
	"os"

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

func main() {
	v, err := semver.NewVersion("1.4.2-beta.1+exp.sha.5114f85")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to parse version: %v\n", err)
		os.Exit(1)
	}

	nextMajor := v.IncMajor()
	fmt.Printf("Original version:   %s\n", v.String())
	fmt.Printf("Next major version: %s\n", nextMajor.String())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify semver.IncMajor in pkg:golang/github.com/Masterminds/semver/v3@v3.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/Masterminds/semver/v3@v3.2.0"
  ],
  "symbols": [
    "semver.IncMajor"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

func main() {
	// Assertion 1: semver.Version.IncMajor increments the major version number by one and resets minor and patch numbers to zero
	v1, err := semver.NewVersion("1.4.2")
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed to parse: %v\n", err)
		os.Exit(1)
	}
	inc1 := v1.IncMajor()
	if inc1.Major() != 2 || inc1.Minor() != 0 || inc1.Patch() != 0 {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected 2.0.0, got %s\n", inc1.String())
		os.Exit(1)
	}
	if inc1.String() != "2.0.0" {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected string '2.0.0', got %q\n", inc1.String())
		os.Exit(1)
	}

	// Assertion 2: semver.Version.IncMajor removes any prerelease and build metadata from the resulting version
	v2, err := semver.NewVersion("1.2.3-alpha.1+build.10")
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed to parse: %v\n", err)
		os.Exit(1)
	}
	inc2 := v2.IncMajor()
	if inc2.Prerelease() != "" {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected empty prerelease, got %q\n", inc2.Prerelease())
		os.Exit(1)
	}
	if inc2.Metadata() != "" {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected empty metadata, got %q\n", inc2.Metadata())
		os.Exit(1)
	}
	if inc2.String() != "2.0.0" {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected string '2.0.0', got %q\n", inc2.String())
		os.Exit(1)
	}

	// Assertion 3: semver.Version.IncMajor returns a new Version instance without mutating the original Version
	v3, err := semver.NewVersion("3.5.7-rc.2+sha.abcdef")
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 3 failed to parse: %v\n", err)
		os.Exit(1)
	}
	_ = v3.IncMajor()
	if v3.Major() != 3 || v3.Minor() != 5 || v3.Patch() != 7 || v3.Prerelease() != "rc.2" || v3.Metadata() != "sha.abcdef" {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: original version was mutated: %s\n", v3.String())
		os.Exit(1)
	}
	if v3.String() != "3.5.7-rc.2+sha.abcdef" {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: original version string changed: %s\n", v3.String())
		os.Exit(1)
	}

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

Seeder d'origine

anonyme