CodeSampleX

샘플

golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b: module.Check, module.EscapePath, module.UnescapePath

검증된 샘플 — golang golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b: module.Check, module.EscapePath, module.UnescapePath. go 1.26 · linux debian/x64 …

sha256:7783f4b35593356d90086913a247862fd37280d80e511407b23d4356ed6a86f8

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
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-10-19

케이스

HOW
목표
verify pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b
패키지
심벌
  • module.Check
  • module.EscapePath
  • module.UnescapePath
  • semver.Compare
  • semver.Canonical
생성일
2026-10-18T06:24:28Z

컨트랙트

  1. module.Check returns nil for a valid module path and semantic version
  2. module.Check returns nil for major version >= 2 when path includes matching /vN suffix
  3. module.Check returns InvalidVersionError when major version >= 2 lacks matching /vN path suffix
  4. semver.Compare orders semantic versions and treats build metadata as equal
  5. semver.Canonical normalizes valid semantic versions and strips build metadata
  6. module.EscapePath and module.UnescapePath round-trip uppercase characters in module paths

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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 pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b

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:bf7d754e6c7c99342ea5babd826c06f8140cd707831678509ac271649fb43a0c","contract":["module.Check returns nil for a valid module path and semantic version","module.Check returns nil for major version \u003e= 2 when path includes matching /vN suffix","module.Check returns InvalidVersionError when major version \u003e= 2 lacks matching /vN path suffix","semver.Compare orders semantic versions and treats build metadata as equal","semver.Canonical normalizes valid semantic versions and strips build metadata","module.EscapePath and module.UnescapePath round-trip uppercase characters in module paths"],"goal":"verify pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b","kind":"HOW","packages":["pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b"],"schemaVersion":1,"symbols":["module.Check","module.EscapePath","module.UnescapePath","semver.Compare","semver.Canonical"]},"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/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b","symbols":["module.Check","module.EscapePath","module.UnescapePath","semver.Compare","semver.Canonical"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.21

require golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b

require golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
go.sum
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b h1:GgiSbuUyC0BlbUmHQBgFqu32eiRR/CEYdjOjOd4zE6Y=
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
main.go
package main

import (
	"fmt"
	"log"

	"golang.org/x/mod/module"
	"golang.org/x/mod/semver"
)

func main() {
	modPath := "example.com/pkg/demo"
	ver := "v1.2.3"
	if err := module.Check(modPath, ver); err != nil {
		log.Fatalf("unexpected module.Check failure: %v", err)
	}
	if !semver.IsValid(ver) || semver.Compare("v1.0.0", ver) >= 0 {
		log.Fatalf("unexpected semver comparison result")
	}
	fmt.Printf("Verified %s@%s (major %s)\n", modPath, ver, semver.Major(ver))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/mod@v0.1.1-0.20191107180719-034126e5016b"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"os"

	"golang.org/x/mod/module"
	"golang.org/x/mod/semver"
)

func main() {
	// 1. module.Check returns nil for a valid module path and semantic version
	if err := module.Check("example.com/pkg/demo", "v1.2.3"); err != nil {
		fmt.Fprintf(os.Stderr, "expected nil for valid v1 module, got: %v\n", err)
		os.Exit(1)
	}

	// 2. module.Check returns nil for major version >= 2 when path includes matching /vN suffix
	if err := module.Check("example.com/pkg/demo/v2", "v2.1.0"); err != nil {
		fmt.Fprintf(os.Stderr, "expected nil for valid v2 module, got: %v\n", err)
		os.Exit(1)
	}

	// 3. module.Check returns InvalidVersionError when major version >= 2 lacks matching /vN path suffix
	errMismatch := module.Check("example.com/pkg/demo", "v2.1.0")
	var invVer *module.InvalidVersionError
	if errMismatch == nil || !errors.As(errMismatch, &invVer) {
		fmt.Fprintf(os.Stderr, "expected InvalidVersionError for v2 mismatch, got: %v\n", errMismatch)
		os.Exit(1)
	}

	// 4. semver.Compare orders semantic versions and treats build metadata as equal
	if semver.Compare("v1.2.0", "v1.10.0") != -1 {
		fmt.Fprintf(os.Stderr, "expected v1.2.0 < v1.10.0\n")
		os.Exit(1)
	}
	if semver.Compare("v1.2.3+build1", "v1.2.3+build2") != 0 {
		fmt.Fprintf(os.Stderr, "expected build metadata versions to compare equal\n")
		os.Exit(1)
	}

	// 5. semver.Canonical normalizes valid semantic versions and strips build metadata
	if got := semver.Canonical("v1.2.3+meta"); got != "v1.2.3" || semver.Canonical("v1.2") != "v1.2.0" {
		fmt.Fprintf(os.Stderr, "expected canonical v1.2.3, got %q\n", got)
		os.Exit(1)
	}

	// 6. module.EscapePath and module.UnescapePath round-trip uppercase characters in module paths
	origPath := "example.com/MyPkg/SubDir"
	escaped, err := module.EscapePath(origPath)
	if err != nil || escaped != "example.com/!my!pkg/!sub!dir" {
		fmt.Fprintf(os.Stderr, "unexpected EscapePath result: %q, %v\n", escaped, err)
		os.Exit(1)
	}
	unescaped, err := module.UnescapePath(escaped)
	if err != nil || unescaped != origPath {
		fmt.Fprintf(os.Stderr, "unexpected UnescapePath result: %q, %v\n", unescaped, err)
		os.Exit(1)
	}

	fmt.Println("Contract passed")
}

오리진 시더

익명