Exemplo
github.com/aws/aws-sdk-go-v2 v1.47.0: aws.NewConfig, aws.String, aws.ToString
Amostra verificada para golang github.com/aws/aws-sdk-go-v2 v1.47.0: aws.NewConfig, aws.String, aws.ToString. O contrato rodou em go 1.26 · linux debian/x64…
sha256:aac6d3b54000ae75a9c083358e36bcc5a054f61502ca4b2c22f02fc1760b18c9
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-10-09 |
Caso
HOW- Objetivo
- verify pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
- Símbolos
-
- aws.NewConfig
- aws.String
- aws.ToString
- aws.CredentialsProviderFunc
- aws.NewCredentialsCache
- aws.AnonymousCredentials
- Criado
- 2026-10-09T17:00:04Z
Contrato
- aws.NewConfig returns an initialized Config and Copy produces an independent shallow copy
- aws.String and aws.ToString correctly convert between string values and pointers with safe nil handling
- aws.CredentialsProviderFunc wraps a function satisfying CredentialsProvider interface and retrieves credentials
- aws.NewCredentialsCache caches credentials and delegates retrieval to underlying provider
- aws.AnonymousCredentials returns sentinel credentials and reports expected retrieval error
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.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 pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
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.
{"case":{"caseId":"case:sha256:070b271ad3c43f90b495d5e4a9578e69428a262d64c9d2697ee026e9ae67c8eb","contract":["aws.NewConfig returns an initialized Config and Copy produces an independent shallow copy","aws.String and aws.ToString correctly convert between string values and pointers with safe nil handling","aws.CredentialsProviderFunc wraps a function satisfying CredentialsProvider interface and retrieves credentials","aws.NewCredentialsCache caches credentials and delegates retrieval to underlying provider","aws.AnonymousCredentials returns sentinel credentials and reports expected retrieval error"],"goal":"verify pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0","kind":"HOW","packages":["pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0"],"schemaVersion":1,"symbols":["aws.NewConfig","aws.String","aws.ToString","aws.CredentialsProviderFunc","aws.NewCredentialsCache","aws.AnonymousCredentials"]},"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/github.com/aws/aws-sdk-go-v2@v1.47.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0","symbols":["aws.NewConfig","aws.String","aws.ToString","aws.CredentialsProviderFunc","aws.NewCredentialsCache","aws.AnonymousCredentials"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/aws/aws-sdk-go-v2 v1.47.0
require github.com/aws/smithy-go v1.28.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.47.0 h1:0jsHallhJCeaU0Ko48c/3FK1ctOQ7NpzggxriJOQ8MQ=
github.com/aws/aws-sdk-go-v2 v1.47.0/go.mod h1:bttEH6JqnUL8LepvDVfdrds/fZ5bCIxzpe3abyUrhDU=
github.com/aws/smithy-go v1.28.1 h1:R/nXH00c8qcfCzQVELtRw+eLQWtzv+VAIEFJ1/xxXlQ=
github.com/aws/smithy-go v1.28.1/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
package sample
import (
"context"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
)
// ClientConfigHolder wraps an aws.Config with helper methods.
type ClientConfigHolder struct {
Config aws.Config
}
// NewClientConfigHolder creates a new ClientConfigHolder with specified region and credentials provider.
func NewClientConfigHolder(region string, creds aws.CredentialsProvider) (*ClientConfigHolder, error) {
if region == "" {
return nil, fmt.Errorf("region cannot be empty")
}
cfg := aws.NewConfig()
cfg.Region = region
cfg.Credentials = creds
return &ClientConfigHolder{
Config: cfg.Copy(),
}, nil
}
// CreateStaticCredentialsProvider returns a CredentialsProvider that supplies static credentials.
func CreateStaticCredentialsProvider(accessKey, secretKey, sessionToken string) aws.CredentialsProvider {
return aws.CredentialsProviderFunc(func(ctx context.Context) (aws.Credentials, error) {
return aws.Credentials{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
SessionToken: sessionToken,
Source: "StaticCredentialsProvider",
}, nil
})
}
// CreateCachedCredentialsProvider wraps an underlying provider with a CredentialsCache.
func CreateCachedCredentialsProvider(provider aws.CredentialsProvider, expiryWindow time.Duration) *aws.CredentialsCache {
return aws.NewCredentialsCache(provider, func(options *aws.CredentialsCacheOptions) {
options.ExpiryWindow = expiryWindow
})
}
// SafeStringValue dereferences a string pointer using aws.ToString with a fallback.
func SafeStringValue(val *string, fallback string) string {
res := aws.ToString(val)
if res == "" {
return fallback
}
return res
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0"
]
}
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"sample"
)
func main() {
if err := runTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All AWS SDK Go v2 contract tests passed successfully.")
}
func runTests() error {
ctx := context.Background()
// 1. aws.NewConfig returns an initialized Config and Copy produces an independent shallow copy
{
cfg := aws.NewConfig()
if cfg == nil {
return fmt.Errorf("expected non-nil Config from aws.NewConfig")
}
cfg.Region = "us-east-1"
holder, err := sample.NewClientConfigHolder("us-west-2", nil)
if err != nil {
return fmt.Errorf("unexpected error creating ClientConfigHolder: %w", err)
}
if holder.Config.Region != "us-west-2" {
return fmt.Errorf("expected region us-west-2, got %q", holder.Config.Region)
}
copied := holder.Config.Copy()
if copied.Region != "us-west-2" {
return fmt.Errorf("expected copied region to be us-west-2, got %q", copied.Region)
}
}
// 2. aws.String and aws.ToString correctly convert between string values and pointers with safe nil handling
{
ptr := aws.String("example-endpoint")
if ptr == nil || *ptr != "example-endpoint" {
return fmt.Errorf("expected valid pointer from aws.String")
}
val := aws.ToString(ptr)
if val != "example-endpoint" {
return fmt.Errorf("expected 'example-endpoint' from aws.ToString, got %q", val)
}
nilVal := aws.ToString(nil)
if nilVal != "" {
return fmt.Errorf("expected empty string from aws.ToString(nil), got %q", nilVal)
}
fallback := sample.SafeStringValue(nil, "default-val")
if fallback != "default-val" {
return fmt.Errorf("expected fallback value, got %q", fallback)
}
}
// 3. aws.CredentialsProviderFunc wraps a function satisfying CredentialsProvider interface and retrieves credentials
{
staticProvider := sample.CreateStaticCredentialsProvider("test-access-key", "test-secret-key", "test-session-token")
creds, err := staticProvider.Retrieve(ctx)
if err != nil {
return fmt.Errorf("unexpected error retrieving credentials: %w", err)
}
if creds.AccessKeyID != "test-access-key" || creds.SecretAccessKey != "test-secret-key" {
return fmt.Errorf("credentials fields mismatch: %+v", creds)
}
if !creds.HasKeys() {
return fmt.Errorf("expected creds.HasKeys() to be true")
}
}
// 4. aws.NewCredentialsCache caches credentials and delegates retrieval to underlying provider
{
callCount := 0
customProvider := aws.CredentialsProviderFunc(func(c context.Context) (aws.Credentials, error) {
callCount++
return aws.Credentials{
AccessKeyID: fmt.Sprintf("key-%d", callCount),
SecretAccessKey: "secret-data",
CanExpire: true,
Expires: time.Now().Add(10 * time.Minute),
}, nil
})
cache := sample.CreateCachedCredentialsProvider(customProvider, 10*time.Second)
if cache == nil {
return fmt.Errorf("expected non-nil CredentialsCache")
}
first, err := cache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("error in first Retrieve: %w", err)
}
if callCount != 1 {
return fmt.Errorf("expected callCount 1, got %d", callCount)
}
second, err := cache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("error in second Retrieve: %w", err)
}
if callCount != 1 {
return fmt.Errorf("expected cached callCount to remain 1, got %d", callCount)
}
if second.AccessKeyID != first.AccessKeyID {
return fmt.Errorf("expected cached credentials to match")
}
}
// 5. aws.AnonymousCredentials returns sentinel credentials and reports expected retrieval error
{
anon := aws.AnonymousCredentials{}
creds, err := anon.Retrieve(ctx)
if err == nil {
return fmt.Errorf("expected error from AnonymousCredentials.Retrieve")
}
if creds.Source != "AnonymousCredentials" {
return fmt.Errorf("expected Source AnonymousCredentials, got %q", creds.Source)
}
}
return nil
}
Seeder de origem
anônimo