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…

sha256:8f11d87db6312a87b24f5d50b970a7a76533012bd878d51eef33d41b81ff3675

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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)
	}
}

オリジンシーダー

匿名