CodeSampleX

Sample

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

Verified sample for golang github.com/klauspost/cpuid/v2 v2.2.10. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:9cbf1bb03d7d7a36590206783f4a6ad1ecbb67ec10b025f8b824fb2b86519b3e

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
2
Signing keys that built it
1
Declared environment go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10
Packages
Environment
go 1.26.6
Created
2026-08-23T17:14:49Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

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 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.")
}

Origin Seeder

anonymous