CodeSampleX

샘플

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

검증된 샘플 — golang github.com/armon/go-radix v1.0.0. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: radix.New initializes an empty radix tree with…

sha256:8f11d87db6312a87b24f5d50b970a7a76533012bd878d51eef33d41b81ff3675

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:golang/github.com/armon/go-radix@v1.0.0
패키지
생성일
2026-08-28T00:40:02Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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

오리진 시더

익명