Exemple
golang.org/x/sync v0.22.0: syncmap.Map
Échantillon vérifié pour golang golang.org/x/sync v0.22.0: syncmap.Map. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.
sha256:790af6712925de14871c37b6dff75594fa6d129fee8ec89b8da639a4bd86fc09
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 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-27 |
Cas
HOW- Objectif
- verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0
- Paquets
- Symboles
-
- golang.org/x/sync/syncmap.Map
- Créé
- 2026-08-27T22:02:28Z
Contrat
- syncmap.Map Store stores key-value pair and Load retrieves it
- syncmap.Map Load on nonexistent key returns ok=false
- syncmap.Map LoadOrStore returns existing value if present without modifying
- syncmap.Map LoadOrStore stores and returns new value when key is absent
- syncmap.Map LoadAndDelete deletes key and returns previous value and loaded=true
- syncmap.Map Delete removes key from map
- syncmap.Map Swap replaces value and returns previous value
- syncmap.Map CompareAndSwap conditionally replaces value when old matches
- syncmap.Map CompareAndDelete conditionally deletes key when old matches
- syncmap.Map Range iterates over entries and stops when callback returns false
- syncmap.Map safely handles concurrent reads and writes from multiple goroutines
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Code source
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 golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/sync@v0.22.0
Demonstrate these symbols/APIs:
- golang.org/x/sync/syncmap.Map
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:bfe72d6d8164687b2e49dea302c46696ee259baf497617b8aeaa93c283fb0385","contract":["syncmap.Map Store stores key-value pair and Load retrieves it","syncmap.Map Load on nonexistent key returns ok=false","syncmap.Map LoadOrStore returns existing value if present without modifying","syncmap.Map LoadOrStore stores and returns new value when key is absent","syncmap.Map LoadAndDelete deletes key and returns previous value and loaded=true","syncmap.Map Delete removes key from map","syncmap.Map Swap replaces value and returns previous value","syncmap.Map CompareAndSwap conditionally replaces value when old matches","syncmap.Map CompareAndDelete conditionally deletes key when old matches","syncmap.Map Range iterates over entries and stops when callback returns false","syncmap.Map safely handles concurrent reads and writes from multiple goroutines"],"goal":"verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sync@v0.22.0"],"schemaVersion":1,"symbols":["golang.org/x/sync/syncmap.Map"]},"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/sync@v0.22.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sync@v0.22.0","symbols":["golang.org/x/sync/syncmap.Map"],"verifierAdapter":"golang@1"}
module sample
go 1.25.0
require golang.org/x/sync v0.22.0
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
package main
import (
"fmt"
"golang.org/x/sync/syncmap"
)
func main() {
var m syncmap.Map
m.Store("greeting", "hello world")
if val, ok := m.Load("greeting"); ok {
fmt.Println(val)
}
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/sync@v0.22.0"
],
"symbols": [
"golang.org/x/sync/syncmap.Map"
]
}
package main
import (
"fmt"
"sync"
"golang.org/x/sync/syncmap"
)
func assert(cond bool, msg string) {
if !cond {
panic("assertion failed: " + msg)
}
}
func main() {
// Test 1: Store and Load
{
var m syncmap.Map
m.Store("key1", "val1")
val, ok := m.Load("key1")
assert(ok && val == "val1", "Store and Load should return stored value")
_, ok = m.Load("nonexistent")
assert(!ok, "Load on nonexistent key should return ok=false")
}
// Test 2: LoadOrStore
{
var m syncmap.Map
actual, loaded := m.LoadOrStore("key1", "val1")
assert(!loaded && actual == "val1", "LoadOrStore should insert new entry when key is missing")
actual, loaded = m.LoadOrStore("key1", "val2")
assert(loaded && actual == "val1", "LoadOrStore should return existing entry without modifying")
}
// Test 3: LoadAndDelete and Delete
{
var m syncmap.Map
m.Store("key1", "val1")
val, loaded := m.LoadAndDelete("key1")
assert(loaded && val == "val1", "LoadAndDelete should return previous value and loaded=true")
_, loaded = m.LoadAndDelete("key1")
assert(!loaded, "LoadAndDelete on missing key should return loaded=false")
m.Store("key2", "val2")
m.Delete("key2")
_, ok := m.Load("key2")
assert(!ok, "Delete should remove entry")
}
// Test 4: Swap
{
var m syncmap.Map
prev, loaded := m.Swap("key1", "val1")
assert(!loaded && prev == nil, "Swap on new key should return loaded=false and prev=nil")
prev, loaded = m.Swap("key1", "val2")
assert(loaded && prev == "val1", "Swap on existing key should return previous value")
val, ok := m.Load("key1")
assert(ok && val == "val2", "Load should reflect swapped value")
}
// Test 5: CompareAndSwap
{
var m syncmap.Map
m.Store("key1", "val1")
swapped := m.CompareAndSwap("key1", "wrong", "val2")
assert(!swapped, "CompareAndSwap with mismatched old value should return false")
val, ok := m.Load("key1")
assert(ok && val == "val1", "CompareAndSwap failure should leave value untouched")
swapped = m.CompareAndSwap("key1", "val1", "val2")
assert(swapped, "CompareAndSwap with matching old value should return true")
val, ok = m.Load("key1")
assert(ok && val == "val2", "CompareAndSwap success should update value")
}
// Test 6: CompareAndDelete
{
var m syncmap.Map
m.Store("key1", "val1")
deleted := m.CompareAndDelete("key1", "wrong")
assert(!deleted, "CompareAndDelete with mismatched old value should return false")
val, ok := m.Load("key1")
assert(ok && val == "val1", "CompareAndDelete failure should leave key intact")
deleted = m.CompareAndDelete("key1", "val1")
assert(deleted, "CompareAndDelete with matching old value should return true")
_, ok = m.Load("key1")
assert(!ok, "CompareAndDelete success should remove key")
}
// Test 7: Range
{
var m syncmap.Map
m.Store("k1", 1)
m.Store("k2", 2)
m.Store("k3", 3)
visited := make(map[string]int)
m.Range(func(k, v any) bool {
visited[k.(string)] = v.(int)
return true
})
assert(len(visited) == 3 && visited["k1"] == 1 && visited["k2"] == 2 && visited["k3"] == 3, "Range should visit all entries")
count := 0
m.Range(func(k, v any) bool {
count++
return false // stop early
})
assert(count == 1, "Range should stop when false is returned")
}
// Test 8: Concurrent read/write safety
{
var m syncmap.Map
var wg sync.WaitGroup
const numGoroutines = 50
const iters = 100
for i := 0; i < numGoroutines; i++ {
wg.Add(1)
go func(gid int) {
defer wg.Done()
for j := 0; j < iters; j++ {
key := fmt.Sprintf("k-%d", (gid+j)%10)
m.Store(key, j)
m.Load(key)
m.LoadOrStore(key, j)
if j%2 == 0 {
m.Delete(key)
}
}
}(i)
}
wg.Wait()
}
fmt.Println("Contract verification passed successfully")
}
Seeder d'origine
anonyme