CodeSampleX

Exemplo

github.com/armon/go-radix v1.0.0

Amostra verificada para golang github.com/armon/go-radix v1.0.0. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.

sha256:8f11d87db6312a87b24f5d50b970a7a76533012bd878d51eef33d41b81ff3675

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 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-28

Caso

HOW
Objetivo
verify pkg:golang/github.com/armon/go-radix@v1.0.0
Pacotes
Criado
2026-08-28T00:40:02Z

Contrato

  1. radix.New initializes an empty radix tree with zero length, supporting key insertion with Insert and exact retrieval with Get
  2. radix.Tree.LongestPrefix returns the longest matching prefix and corresponding value for a query path
  3. radix.Tree.Minimum and radix.Tree.Maximum retrieve the lexicographically smallest and largest key-value pairs
  4. radix.Tree.WalkPrefix traverses only entries matching a specified key prefix in lexicographical order
  5. radix.Tree.Delete removes individual keys and radix.Tree.DeletePrefix removes all keys sharing a common prefix

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/armon/go-radix@v1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/armon/go-radix@v1.0.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.
csx.json
{"case":{"caseId":"case:sha256:02387653f0eb263189c29d9e24eef644d9bfd21bb095b01fb71a8f6ec97871a2","contract":["radix.New initializes an empty radix tree with zero length, supporting key insertion with Insert and exact retrieval with Get","radix.Tree.LongestPrefix returns the longest matching prefix and corresponding value for a query path","radix.Tree.Minimum and radix.Tree.Maximum retrieve the lexicographically smallest and largest key-value pairs","radix.Tree.WalkPrefix traverses only entries matching a specified key prefix in lexicographical order","radix.Tree.Delete removes individual keys and radix.Tree.DeletePrefix removes all keys sharing a common prefix"],"goal":"verify pkg:golang/github.com/armon/go-radix@v1.0.0","kind":"HOW","packages":["pkg:golang/github.com/armon/go-radix@v1.0.0"],"schemaVersion":1},"contractCommand":["go","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/armon/go-radix@v1.0.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/armon/go-radix@v1.0.0","verifierAdapter":"golang@1"}
go.mod
module example.com/radixdemo

go 1.26.6

require github.com/armon/go-radix v1.0.0
go.sum
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
main.go
package main

import (
	"fmt"

	"github.com/armon/go-radix"
)

func main() {
	tree := radix.New()

	// Insert keys
	tree.Insert("api/v1/users", "handler_users")
	tree.Insert("api/v1/orders", "handler_orders")
	tree.Insert("api/v2/items", "handler_items")

	// Exact lookup
	if val, ok := tree.Get("api/v1/users"); ok {
		fmt.Printf("Found exact: %s -> %v\n", "api/v1/users", val)
	}

	// Longest prefix match
	if prefix, val, ok := tree.LongestPrefix("api/v1/users/123"); ok {
		fmt.Printf("Longest prefix: %s -> %v\n", prefix, val)
	}

	// Prefix iteration
	fmt.Println("Prefix walk for api/v1:")
	tree.WalkPrefix("api/v1", func(s string, v interface{}) bool {
		fmt.Printf("  %s: %v\n", s, v)
		return false
	})
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/armon/go-radix@v1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/armon/go-radix@v1.0.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract_test.go
package test

import (
	"reflect"
	"testing"

	"github.com/armon/go-radix"
)

func TestRadixTreeInsertAndGet(t *testing.T) {
	tree := radix.New()
	if tree.Len() != 0 {
		t.Fatalf("expected empty tree to have length 0, got %d", tree.Len())
	}

	// Insert new keys
	oldVal, updated := tree.Insert("apple", 1)
	if updated || oldVal != nil {
		t.Fatalf("expected updated=false and oldVal=nil for new key, got updated=%v, oldVal=%v", updated, oldVal)
	}

	tree.Insert("app", 2)
	tree.Insert("application", 3)
	tree.Insert("banana", 4)

	if tree.Len() != 4 {
		t.Fatalf("expected tree length 4, got %d", tree.Len())
	}

	// Retrieve existing key
	val, ok := tree.Get("apple")
	if !ok || val != 1 {
		t.Fatalf("expected Get('apple') to return 1, true; got %v, %v", val, ok)
	}

	// Retrieve missing key
	_, ok = tree.Get("appl")
	if ok {
		t.Fatalf("expected Get('appl') to return ok=false")
	}

	// Update existing key
	oldVal, updated = tree.Insert("apple", 10)
	if !updated || oldVal != 1 {
		t.Fatalf("expected updated=true and oldVal=1 for existing key, got updated=%v, oldVal=%v", updated, oldVal)
	}

	val, ok = tree.Get("apple")
	if !ok || val != 10 {
		t.Fatalf("expected Get('apple') to return 10, true; got %v, %v", val, ok)
	}
}

func TestRadixTreeLongestPrefix(t *testing.T) {
	tree := radix.New()
	tree.Insert("/api", "root_api")
	tree.Insert("/api/v1", "v1")
	tree.Insert("/api/v1/users", "users")

	prefix, val, ok := tree.LongestPrefix("/api/v1/users/123/profile")
	if !ok || prefix != "/api/v1/users" || val != "users" {
		t.Fatalf("expected longest prefix '/api/v1/users' with value 'users', got prefix=%q, val=%v, ok=%v", prefix, val, ok)
	}

	prefix, val, ok = tree.LongestPrefix("/api/v2/orders")
	if !ok || prefix != "/api" || val != "root_api" {
		t.Fatalf("expected longest prefix '/api' with value 'root_api', got prefix=%q, val=%v, ok=%v", prefix, val, ok)
	}

	_, _, ok = tree.LongestPrefix("/health")
	if ok {
		t.Fatalf("expected ok=false for unmatched path")
	}
}

func TestRadixTreeMinMax(t *testing.T) {
	tree := radix.New()
	tree.Insert("car", 1)
	tree.Insert("cat", 2)
	tree.Insert("cart", 3)
	tree.Insert("bar", 4)
	tree.Insert("dog", 5)

	minKey, minVal, ok := tree.Minimum()
	if !ok || minKey != "bar" || minVal != 4 {
		t.Fatalf("expected Minimum() to return 'bar', 4; got %q, %v, %v", minKey, minVal, ok)
	}

	maxKey, maxVal, ok := tree.Maximum()
	if !ok || maxKey != "dog" || maxVal != 5 {
		t.Fatalf("expected Maximum() to return 'dog', 5; got %q, %v, %v", maxKey, maxVal, ok)
	}
}

func TestRadixTreeWalkPrefix(t *testing.T) {
	tree := radix.New()
	tree.Insert("sub.domain.com", 1)
	tree.Insert("sub.domain.org", 2)
	tree.Insert("sub.example.com", 3)
	tree.Insert("other.org", 4)

	var walkedKeys []string
	tree.WalkPrefix("sub.domain", func(s string, v interface{}) bool {
		walkedKeys = append(walkedKeys, s)
		return false
	})

	expected := []string{"sub.domain.com", "sub.domain.org"}
	if !reflect.DeepEqual(walkedKeys, expected) {
		t.Fatalf("expected walked keys %v, got %v", expected, walkedKeys)
	}
}

func TestRadixTreeDeleteAndPrefixDelete(t *testing.T) {
	tree := radix.New()
	tree.Insert("prefix_a", 1)
	tree.Insert("prefix_b", 2)
	tree.Insert("prefix_c", 3)
	tree.Insert("other", 4)

	// Single delete
	deletedVal, ok := tree.Delete("prefix_a")
	if !ok || deletedVal != 1 {
		t.Fatalf("expected Delete('prefix_a') to return 1, true; got %v, %v", deletedVal, ok)
	}
	if tree.Len() != 3 {
		t.Fatalf("expected tree length 3 after delete, got %d", tree.Len())
	}

	// Delete prefix
	numDeleted := tree.DeletePrefix("prefix_")
	if numDeleted != 2 {
		t.Fatalf("expected DeletePrefix('prefix_') to delete 2 elements, got %d", numDeleted)
	}
	if tree.Len() != 1 {
		t.Fatalf("expected tree length 1 after DeletePrefix, got %d", tree.Len())
	}

	val, ok := tree.Get("other")
	if !ok || val != 4 {
		t.Fatalf("expected Get('other') to return 4, true; got %v, %v", val, ok)
	}
}

Seeder de origem

anônimo