CodeSampleX

Exemplo

github.com/subosito/gotenv v1.6.0: Parse

Amostra verificada para golang github.com/subosito/gotenv v1.6.0: Parse. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:a738bc24f221ab47c9991a0bb57610a43629f2731c65143f39d7f42fdbcd1d4c

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 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

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-09-20

Caso

HOW
Objetivo
verify github.com/subosito/gotenv.Parse in pkg:golang/github.com/subosito/gotenv@v1.6.0
Pacotes
Símbolos
  • github.com/subosito/gotenv.Parse
Ambiente
go 1.26.6
Criado
2026-09-20T11:09:29Z

Contrato

  1. gotenv.Parse parses key-value pairs separated by equal signs or colons from an io.Reader
  2. gotenv.Parse ignores empty lines and comment lines starting with hash characters
  3. gotenv.Parse preserves literal content in single-quoted values without variable expansion
  4. gotenv.Parse expands environment variables and previously defined keys within unquoted and double-quoted values
  5. gotenv.Parse strips optional export keywords preceding variable definitions
  6. gotenv.Parse parses multiline values enclosed in double quotes across multiple lines

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.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 github.com/subosito/gotenv.Parse in pkg:golang/github.com/subosito/gotenv@v1.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/subosito/gotenv@v1.6.0
Demonstrate these symbols/APIs:
  - github.com/subosito/gotenv.Parse

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:b9338bf1891c01055bf23c522de4ef0c587499de3de0bad82b4d5d67f5124cba","contract":["gotenv.Parse parses key-value pairs separated by equal signs or colons from an io.Reader","gotenv.Parse ignores empty lines and comment lines starting with hash characters","gotenv.Parse preserves literal content in single-quoted values without variable expansion","gotenv.Parse expands environment variables and previously defined keys within unquoted and double-quoted values","gotenv.Parse strips optional export keywords preceding variable definitions","gotenv.Parse parses multiline values enclosed in double quotes across multiple lines"],"goal":"verify github.com/subosito/gotenv.Parse in pkg:golang/github.com/subosito/gotenv@v1.6.0","kind":"HOW","packages":["pkg:golang/github.com/subosito/gotenv@v1.6.0"],"schemaVersion":1,"symbols":["github.com/subosito/gotenv.Parse"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/subosito/gotenv@v1.6.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/subosito/gotenv@v1.6.0","symbols":["github.com/subosito/gotenv.Parse"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/subosito/gotenv v1.6.0

require golang.org/x/text v0.12.0 // indirect
go.sum
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
main.go
package main

import (
	"fmt"
	"strings"

	"github.com/subosito/gotenv"
)

func main() {
	envData := `
# Sample configuration
APP_NAME=MyApp
APP_PORT=8080
export APP_ENV=production
`
	env := gotenv.Parse(strings.NewReader(envData))

	fmt.Printf("APP_NAME: %s\n", env["APP_NAME"])
	fmt.Printf("APP_PORT: %s\n", env["APP_PORT"])
	fmt.Printf("APP_ENV: %s\n", env["APP_ENV"])
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/subosito/gotenv.Parse in pkg:golang/github.com/subosito/gotenv@v1.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/subosito/gotenv@v1.6.0"
  ],
  "symbols": [
    "github.com/subosito/gotenv.Parse"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"reflect"
	"strings"

	"github.com/subosito/gotenv"
)

func main() {
	// Assertion 1: gotenv.Parse parses key-value pairs separated by equal signs or colons from an io.Reader
	{
		raw := "A=alpha\nB: beta\nC = charlie"
		env := gotenv.Parse(strings.NewReader(raw))
		expected := gotenv.Env{"A": "alpha", "B": "beta", "C": "charlie"}
		if !reflect.DeepEqual(env, expected) {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected %v, got %v\n", expected, env)
			os.Exit(1)
		}
	}

	// Assertion 2: gotenv.Parse ignores empty lines and comment lines starting with hash characters
	{
		raw := "# Header comment\n\nKEY=val\n# Footer comment"
		env := gotenv.Parse(strings.NewReader(raw))
		expected := gotenv.Env{"KEY": "val"}
		if !reflect.DeepEqual(env, expected) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected %v, got %v\n", expected, env)
			os.Exit(1)
		}
	}

	// Assertion 3: gotenv.Parse preserves literal content in single-quoted values without variable expansion
	{
		raw := "LITERAL='raw $FOO string'"
		env := gotenv.Parse(strings.NewReader(raw))
		expected := gotenv.Env{"LITERAL": "raw $FOO string"}
		if !reflect.DeepEqual(env, expected) {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %v, got %v\n", expected, env)
			os.Exit(1)
		}
	}

	// Assertion 4: gotenv.Parse expands environment variables and previously defined keys within unquoted and double-quoted values
	{
		os.Setenv("EXTERNAL_NAME", "service")
		raw := "PREFIX=prod\nFULL_NAME=\"$PREFIX-$EXTERNAL_NAME\""
		env := gotenv.Parse(strings.NewReader(raw))
		expected := gotenv.Env{"PREFIX": "prod", "FULL_NAME": "prod-service"}
		if !reflect.DeepEqual(env, expected) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: expected %v, got %v\n", expected, env)
			os.Exit(1)
		}
	}

	// Assertion 5: gotenv.Parse strips optional export keywords preceding variable definitions
	{
		raw := "export APP_ENV=production\nexport SERVICE_NAME=\"auth service\""
		env := gotenv.Parse(strings.NewReader(raw))
		expected := gotenv.Env{"APP_ENV": "production", "SERVICE_NAME": "auth service"}
		if !reflect.DeepEqual(env, expected) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: expected %v, got %v\n", expected, env)
			os.Exit(1)
		}
	}

	// Assertion 6: gotenv.Parse parses multiline values enclosed in double quotes across multiple lines
	{
		raw := "CERT=\"line1\nline2\nline3\""
		env := gotenv.Parse(strings.NewReader(raw))
		expected := gotenv.Env{"CERT": "line1\nline2\nline3"}
		if !reflect.DeepEqual(env, expected) {
			fmt.Fprintf(os.Stderr, "assertion 6 failed: expected %v, got %v\n", expected, env)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all gotenv.Parse contract assertions passed")
}

Seeder de origem

anônimo