Exemplo
golang.org/x/time v0.15.0: rate.Every
Amostra verificada para golang golang.org/x/time v0.15.0: rate.Every. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.
sha256:714578e63a5d4c45b34247c03d4046157e64bb6a08f8cbb8356e4284ca0ddbf3
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify rate.Every in pkg:golang/golang.org/x/time@v0.15.0
- Pacotes
- Símbolos
-
- rate.Every
- Criado
- 2026-09-01T10:38:03Z
Contrato
- rate.Every(100 * time.Millisecond) returns Limit(10.0)
- rate.Every(1 * time.Second) returns Limit(1.0)
- rate.Every(500 * time.Millisecond) returns Limit(2.0)
- rate.Every(0) returns rate.Inf
- rate.Every(-5 * time.Second) returns rate.Inf
- rate.NewLimiter(rate.Every(200 * time.Millisecond), 3) creates limiter with Limit(5.0) and Burst(3)
- limiter.SetLimit(rate.Every(50 * time.Millisecond)) updates limit to Limit(20.0)
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- rate_every.go
- spec.json
- test/contract.go
Código-fonte
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 rate.Every in pkg:golang/golang.org/x/time@v0.15.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/time@v0.15.0
Demonstrate these symbols/APIs:
- rate.Every
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:d16c4e4b6caae41e4278f5e5a186d408bf23d658496d5ab18eb9f68a84bbad97","contract":["rate.Every(100 * time.Millisecond) returns Limit(10.0)","rate.Every(1 * time.Second) returns Limit(1.0)","rate.Every(500 * time.Millisecond) returns Limit(2.0)","rate.Every(0) returns rate.Inf","rate.Every(-5 * time.Second) returns rate.Inf","rate.NewLimiter(rate.Every(200 * time.Millisecond), 3) creates limiter with Limit(5.0) and Burst(3)","limiter.SetLimit(rate.Every(50 * time.Millisecond)) updates limit to Limit(20.0)"],"goal":"verify rate.Every in pkg:golang/golang.org/x/time@v0.15.0","kind":"HOW","packages":["pkg:golang/golang.org/x/time@v0.15.0"],"schemaVersion":1,"symbols":["rate.Every"]},"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/time@v0.15.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/time@v0.15.0","symbols":["rate.Every"],"verifierAdapter":"golang@1"}
module example.com/rate-every-sample
go 1.25.0
require golang.org/x/time v0.15.0
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
package rateexample
import (
"time"
"golang.org/x/time/rate"
)
// IntervalToLimit converts a minimum duration interval between events to a rate.Limit.
func IntervalToLimit(interval time.Duration) rate.Limit {
return rate.Every(interval)
}
// NewIntervalLimiter creates a new rate.Limiter configured with a per-interval rate and burst size.
func NewIntervalLimiter(interval time.Duration, burst int) *rate.Limiter {
return rate.NewLimiter(rate.Every(interval), burst)
}
{
"schemaVersion": 1,
"goal": "verify rate.Every in pkg:golang/golang.org/x/time@v0.15.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/time@v0.15.0"
],
"symbols": [
"rate.Every"
]
}
package main
import (
"fmt"
"math"
"os"
"time"
"golang.org/x/time/rate"
rateexample "example.com/rate-every-sample"
)
func main() {
if err := runContractTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
func runContractTests() error {
// Assertion 1: Positive intervals convert to reciprocal frequency (events per second)
// 100ms interval => 10 events/second
l100ms := rateexample.IntervalToLimit(100 * time.Millisecond)
if math.Abs(float64(l100ms)-10.0) > 1e-6 {
return fmt.Errorf("expected 10.0 limit for 100ms, got %v", l100ms)
}
// Assertion 2: 1 second interval => 1 event/second
l1s := rate.Every(1 * time.Second)
if math.Abs(float64(l1s)-1.0) > 1e-6 {
return fmt.Errorf("expected 1.0 limit for 1s, got %v", l1s)
}
// Assertion 3: 500ms interval => 2 events/second
l500ms := rate.Every(500 * time.Millisecond)
if math.Abs(float64(l500ms)-2.0) > 1e-6 {
return fmt.Errorf("expected 2.0 limit for 500ms, got %v", l500ms)
}
// Assertion 4: 0 duration returns rate.Inf (infinite rate, no limit)
l0 := rate.Every(0)
if l0 != rate.Inf {
return fmt.Errorf("expected rate.Inf for 0 duration, got %v", l0)
}
// Assertion 5: Negative duration returns rate.Inf
lNeg := rate.Every(-5 * time.Second)
if lNeg != rate.Inf {
return fmt.Errorf("expected rate.Inf for negative duration, got %v", lNeg)
}
// Assertion 6: rate.NewLimiter with rate.Every sets the expected Limit and Burst
limiter := rateexample.NewIntervalLimiter(200*time.Millisecond, 3)
if limiter.Limit() != rate.Limit(5.0) {
return fmt.Errorf("expected limiter limit 5.0, got %v", limiter.Limit())
}
if limiter.Burst() != 3 {
return fmt.Errorf("expected limiter burst 3, got %d", limiter.Burst())
}
// Assertion 7: Dynamic limit updates with rate.Every
limiter.SetLimit(rate.Every(50 * time.Millisecond))
if math.Abs(float64(limiter.Limit())-20.0) > 1e-6 {
return fmt.Errorf("expected updated limit 20.0, got %v", limiter.Limit())
}
return nil
}
Seeder de origem
anônimo