CodeSampleX

샘플

github.com/klauspost/cpuid/v2 v2.2.10

검증된 샘플 — golang github.com/klauspost/cpuid/v2 v2.2.10. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: cpuid.CPU provides CPU architecture…

sha256:9cbf1bb03d7d7a36590206783f4a6ad1ecbb67ec10b025f8b824fb2b86519b3e

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-23
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-07

케이스

HOW
목표
verify pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10
패키지
환경
go 1.26.6
생성일
2026-08-23T17:14:49Z

컨트랙트

  1. cpuid.CPU provides CPU architecture, vendor information, cache line size, and core topology
  2. cpuid.ParseFeature parses string feature names and returns UNKNOWN for unrecognized names
  3. cpuid.CombineFeatures combines multiple FeatureID values into a flag set checked with cpuid.CPU.HasAll
  4. cpuid.CPUInfo instances support Enable, Disable, and Has for modifying and testing individual features
  5. cpuid.CPUInfo.Supports and cpuid.CPUInfo.AnyOf evaluate presence of multiple hardware feature flags
  6. cpuid.CPUInfo.FeatureSet returns a slice of string names for all enabled CPU features

파일

  • 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/github.com/klauspost/cpuid/v2@v2.2.10
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:97a4e9342480622f88dbd46d9b7389c16f73026e6717715715e08b00f28bb276","contract":["cpuid.CPU provides CPU architecture, vendor information, cache line size, and core topology","cpuid.ParseFeature parses string feature names and returns UNKNOWN for unrecognized names","cpuid.CombineFeatures combines multiple FeatureID values into a flag set checked with cpuid.CPU.HasAll","cpuid.CPUInfo instances support Enable, Disable, and Has for modifying and testing individual features","cpuid.CPUInfo.Supports and cpuid.CPUInfo.AnyOf evaluate presence of multiple hardware feature flags","cpuid.CPUInfo.FeatureSet returns a slice of string names for all enabled CPU features"],"goal":"verify pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10","kind":"HOW","packages":["pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10"],"schemaVersion":1},"contractCommand":["go","run","./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/klauspost/cpuid/v2@v2.2.10"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/klauspost/cpuid/v2 v2.2.10
go.sum
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
main.go
package main

import (
	"fmt"

	"github.com/klauspost/cpuid/v2"
)

func main() {
	// Query CPU brand and basic topology
	fmt.Printf("CPU: %s\n", cpuid.CPU.BrandName)
	fmt.Printf("Vendor: %s\n", cpuid.CPU.VendorString)
	fmt.Printf("Physical Cores: %d\n", cpuid.CPU.PhysicalCores)
	fmt.Printf("Logical Cores: %d\n", cpuid.CPU.LogicalCores)
	fmt.Printf("Cache Line: %d bytes\n", cpuid.CPU.CacheLine)

	// Check hardware feature support
	fmt.Printf("SSE2 supported: %v\n", cpuid.CPU.Supports(cpuid.SSE2))
	fmt.Printf("AVX supported: %v\n", cpuid.CPU.Supports(cpuid.AVX))

	// Parse feature name dynamically
	parsed := cpuid.ParseFeature("SSE2")
	fmt.Printf("Parsed SSE2 feature ID: %d\n", parsed)

	// Combine feature flags for compound checks
	flags := cpuid.CombineFeatures(cpuid.SSE, cpuid.SSE2)
	fmt.Printf("Has SSE & SSE2: %v\n", cpuid.CPU.HasAll(flags))

	// Work with independent CPUInfo instance
	var custom cpuid.CPUInfo
	custom.Enable(cpuid.AVX2, cpuid.FMA3)
	fmt.Printf("Custom features: %v\n", custom.FeatureSet())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/klauspost/cpuid/v2"
)

func main() {
	// Contract 1: cpuid.CPU provides CPU architecture, vendor information, cache line size, and core topology
	if cpuid.CPU.CacheLine < 0 {
		fmt.Fprintf(os.Stderr, "FAIL: CacheLine size cannot be negative: %d\n", cpuid.CPU.CacheLine)
		os.Exit(1)
	}
	if cpuid.CPU.ThreadsPerCore < 1 {
		fmt.Fprintf(os.Stderr, "FAIL: ThreadsPerCore must be at least 1: %d\n", cpuid.CPU.ThreadsPerCore)
		os.Exit(1)
	}
	if cpuid.CPU.PhysicalCores < 0 || cpuid.CPU.LogicalCores < 0 {
		fmt.Fprintf(os.Stderr, "FAIL: core count cannot be negative\n")
		os.Exit(1)
	}

	// Contract 2: cpuid.ParseFeature parses string feature names and returns UNKNOWN for unrecognized names
	sse2 := cpuid.ParseFeature("SSE2")
	if sse2 == cpuid.UNKNOWN || sse2 != cpuid.SSE2 {
		fmt.Fprintf(os.Stderr, "FAIL: ParseFeature(\"SSE2\") did not return cpuid.SSE2\n")
		os.Exit(1)
	}
	unknown := cpuid.ParseFeature("NON_EXISTENT_FEATURE_NAME")
	if unknown != cpuid.UNKNOWN {
		fmt.Fprintf(os.Stderr, "FAIL: ParseFeature with invalid name must return UNKNOWN, got %d\n", unknown)
		os.Exit(1)
	}

	// Contract 3: cpuid.CombineFeatures combines multiple FeatureID values into a flag set checked with cpuid.CPU.HasAll
	features := cpuid.CombineFeatures(cpuid.SSE, cpuid.SSE2)
	hasAll := cpuid.CPU.HasAll(features)
	hasBoth := cpuid.CPU.Has(cpuid.SSE) && cpuid.CPU.Has(cpuid.SSE2)
	if hasAll != hasBoth {
		fmt.Fprintf(os.Stderr, "FAIL: HasAll result (%v) does not match individual Has checks (%v)\n", hasAll, hasBoth)
		os.Exit(1)
	}

	// Contract 4: cpuid.CPUInfo instances support Enable, Disable, and Has for modifying and testing individual features
	var custom cpuid.CPUInfo
	if custom.Has(cpuid.AVX2) {
		fmt.Fprintf(os.Stderr, "FAIL: default zero CPUInfo should not have AVX2\n")
		os.Exit(1)
	}
	custom.Enable(cpuid.AVX2, cpuid.FMA3)
	if !custom.Has(cpuid.AVX2) || !custom.Has(cpuid.FMA3) {
		fmt.Fprintf(os.Stderr, "FAIL: custom CPUInfo missing enabled features after Enable\n")
		os.Exit(1)
	}
	custom.Disable(cpuid.AVX2)
	if custom.Has(cpuid.AVX2) {
		fmt.Fprintf(os.Stderr, "FAIL: Disable(AVX2) failed to clear AVX2 flag\n")
		os.Exit(1)
	}
	if !custom.Has(cpuid.FMA3) {
		fmt.Fprintf(os.Stderr, "FAIL: FMA3 should remain enabled after disabling AVX2\n")
		os.Exit(1)
	}

	// Contract 5: cpuid.CPUInfo.Supports and cpuid.CPUInfo.AnyOf evaluate presence of multiple hardware feature flags
	if !custom.Supports(cpuid.FMA3) {
		fmt.Fprintf(os.Stderr, "FAIL: Supports should return true for enabled feature FMA3\n")
		os.Exit(1)
	}
	if custom.Supports(cpuid.FMA3, cpuid.AVX2) {
		fmt.Fprintf(os.Stderr, "FAIL: Supports should return false when AVX2 is not enabled\n")
		os.Exit(1)
	}
	if !custom.AnyOf(cpuid.AVX2, cpuid.FMA3) {
		fmt.Fprintf(os.Stderr, "FAIL: AnyOf should return true when FMA3 is enabled\n")
		os.Exit(1)
	}
	if custom.AnyOf(cpuid.AVX2, cpuid.AVX512F) {
		fmt.Fprintf(os.Stderr, "FAIL: AnyOf should return false when none of the features are enabled\n")
		os.Exit(1)
	}

	// Contract 6: cpuid.CPUInfo.FeatureSet returns a slice of string names for all enabled CPU features
	featList := custom.FeatureSet()
	if len(featList) != 1 || featList[0] != "FMA3" {
		fmt.Fprintf(os.Stderr, "FAIL: FeatureSet returned unexpected features: %v\n", featList)
		os.Exit(1)
	}

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

오리진 시더

익명