CodeSampleX

Exemplo

github.com/slackhq/nebula v1.6.1: config.C, config.NewC

Amostra verificada para golang github.com/slackhq/nebula v1.6.1: config.C, config.NewC. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.

sha256:62638350aec30a3db79fcc6117f6af71c72cb7b6719a14d4b81820ad0db15bcf

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

Caso

HOW
Objetivo
verify pkg:golang/github.com/slackhq/nebula@v1.6.1
Pacotes
Símbolos
  • github.com/slackhq/nebula/config.C
  • github.com/slackhq/nebula/config.NewC
Criado
2026-08-27T13:55:13Z

Contrato

  1. NewC initializes a Nebula configuration manager
  2. C.LoadString parses and loads YAML configuration
  3. C.GetString retrieves string values and respects defaults
  4. C.GetInt retrieves integer values and respects defaults
  5. C.GetBool retrieves boolean values and respects defaults
  6. C.IsSet detects presence or absence of configuration keys
  7. C.ReloadConfigString reloads configuration and notifies registered callbacks
  8. C.HasChanged detects modified configuration keys across reloads

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/main.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/slackhq/nebula@v1.6.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/slackhq/nebula@v1.6.1
Demonstrate these symbols/APIs:
  - github.com/slackhq/nebula/config.C
  - github.com/slackhq/nebula/config.NewC

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:306ad7d130c7cbbc437156ff23ffc4da550283a83b338d5ca0ded4f304f2c517","contract":["NewC initializes a Nebula configuration manager","C.LoadString parses and loads YAML configuration","C.GetString retrieves string values and respects defaults","C.GetInt retrieves integer values and respects defaults","C.GetBool retrieves boolean values and respects defaults","C.IsSet detects presence or absence of configuration keys","C.ReloadConfigString reloads configuration and notifies registered callbacks","C.HasChanged detects modified configuration keys across reloads"],"goal":"verify pkg:golang/github.com/slackhq/nebula@v1.6.1","kind":"HOW","packages":["pkg:golang/github.com/slackhq/nebula@v1.6.1"],"schemaVersion":1,"symbols":["github.com/slackhq/nebula/config.C","github.com/slackhq/nebula/config.NewC"]},"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/slackhq/nebula@v1.6.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/slackhq/nebula@v1.6.1","symbols":["github.com/slackhq/nebula/config.C","github.com/slackhq/nebula/config.NewC"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require (
	github.com/sirupsen/logrus v1.8.1
	github.com/slackhq/nebula v1.6.1
)

require (
	github.com/imdario/mergo v0.3.8 // indirect
	golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/slackhq/nebula v1.6.1 h1:/OCTR3abj0Sbf2nGoLUrdDXImrCv0ZVFpVPP5qa0DsM=
github.com/slackhq/nebula v1.6.1/go.mod h1:UmkqnXe4O53QwToSl/gG7sM4BroQwAB7dd4hUaT6MlI=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71 h1:PRD0hj6tTuUnCFD08vkvjkYFbQg/9lV8KIxe1y4/cvU=
golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/slackhq/nebula@v1.6.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/slackhq/nebula@v1.6.1"
  ],
  "symbols": [
    "github.com/slackhq/nebula/config.C",
    "github.com/slackhq/nebula/config.NewC"
  ]
}
test/main.go
package main

import (
	"fmt"
	"io"
	"os"

	"github.com/sirupsen/logrus"
	"github.com/slackhq/nebula/config"
)

func main() {
	// 1. NewC initializes a Nebula configuration manager
	logger := logrus.New()
	logger.SetOutput(io.Discard)
	c := config.NewC(logger)
	if c == nil {
		fmt.Fprintln(os.Stderr, "failed to initialize config.C")
		os.Exit(1)
	}

	// 2. C.LoadString parses and loads YAML configuration
	rawConfig := `
pki:
  ca: /etc/nebula/ca.crt
  cert: /etc/nebula/host.crt
  key: /etc/nebula/host.key
listen:
  host: 0.0.0.0
  port: 4242
punchy:
  punch: true
  respond: false
tun:
  dev: nebula1
`
	if err := c.LoadString(rawConfig); err != nil {
		fmt.Fprintf(os.Stderr, "LoadString failed: %v\n", err)
		os.Exit(1)
	}

	// 3. C.GetString retrieves string values and respects defaults
	if val := c.GetString("pki.ca", ""); val != "/etc/nebula/ca.crt" {
		fmt.Fprintf(os.Stderr, "pki.ca mismatch: expected /etc/nebula/ca.crt, got %q\n", val)
		os.Exit(1)
	}
	if val := c.GetString("missing.key", "default_val"); val != "default_val" {
		fmt.Fprintf(os.Stderr, "default string mismatch: expected default_val, got %q\n", val)
		os.Exit(1)
	}

	// 4. C.GetInt retrieves integer values and respects defaults
	if port := c.GetInt("listen.port", 0); port != 4242 {
		fmt.Fprintf(os.Stderr, "listen.port mismatch: expected 4242, got %d\n", port)
		os.Exit(1)
	}
	if port := c.GetInt("missing.port", 8080); port != 8080 {
		fmt.Fprintf(os.Stderr, "default port mismatch: expected 8080, got %d\n", port)
		os.Exit(1)
	}

	// 5. C.GetBool retrieves boolean values and respects defaults
	if punch := c.GetBool("punchy.punch", false); !punch {
		fmt.Fprintf(os.Stderr, "punchy.punch mismatch: expected true, got %v\n", punch)
		os.Exit(1)
	}
	if respond := c.GetBool("punchy.respond", true); respond {
		fmt.Fprintf(os.Stderr, "punchy.respond mismatch: expected false, got %v\n", respond)
		os.Exit(1)
	}

	// 6. C.IsSet detects presence or absence of configuration keys
	if !c.IsSet("tun.dev") {
		fmt.Fprintf(os.Stderr, "expected tun.dev to be set\n")
		os.Exit(1)
	}
	if c.IsSet("tun.nonexistent") {
		fmt.Fprintf(os.Stderr, "expected tun.nonexistent to not be set\n")
		os.Exit(1)
	}

	// 7. C.ReloadConfigString reloads configuration and notifies registered callbacks
	callbackFired := false
	c.RegisterReloadCallback(func(updatedCfg *config.C) {
		callbackFired = true
	})

	updatedConfig := `
pki:
  ca: /etc/nebula/ca.crt
  cert: /etc/nebula/host.crt
  key: /etc/nebula/host.key
listen:
  host: 0.0.0.0
  port: 9000
punchy:
  punch: true
  respond: true
tun:
  dev: nebula1
`
	if err := c.ReloadConfigString(updatedConfig); err != nil {
		fmt.Fprintf(os.Stderr, "ReloadConfigString failed: %v\n", err)
		os.Exit(1)
	}
	if !callbackFired {
		fmt.Fprintf(os.Stderr, "reload callback did not fire\n")
		os.Exit(1)
	}

	// 8. C.HasChanged detects modified configuration keys across reloads
	if !c.HasChanged("listen.port") {
		fmt.Fprintf(os.Stderr, "expected listen.port HasChanged to be true\n")
		os.Exit(1)
	}
	if c.HasChanged("pki.ca") {
		fmt.Fprintf(os.Stderr, "expected pki.ca HasChanged to be false\n")
		os.Exit(1)
	}
	if newPort := c.GetInt("listen.port", 0); newPort != 9000 {
		fmt.Fprintf(os.Stderr, "updated listen.port mismatch: expected 9000, got %d\n", newPort)
		os.Exit(1)
	}

	fmt.Println("All nebula config contract assertions passed.")
}

Seeder de origem

anônimo