Exemplo
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a
Amostra verificada para golang github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a. O contrato rodou em go 1.26 · linux alpine/x64 · docker e…
sha256:61ef0313db0db28758d593c11160e7bd6b3b3bde9d0eaee2541b3930d4f9d62c
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:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-19 |
Caso
HOW- Objetivo
- verify pkg:golang/github.com/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a
- Criado
- 2026-08-19T22:22:57Z
Contrato
- ParseServicefile parses service definitions with multiple sections and key-value settings from io.Reader
- GetService retrieves existing service configuration with exact settings map and returns error for nonexistent service
- ReadServicefile parses service definitions directly from a file path on disk
- ParseServicefile correctly ignores comments and empty lines in service file definitions
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código-fonte
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/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a
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.
{"case":{"caseId":"case:sha256:333ce46758059f0a5d006157f6d70172d85a51f7350ef7f8d6860689a18b28b4","contract":["ParseServicefile parses service definitions with multiple sections and key-value settings from io.Reader","GetService retrieves existing service configuration with exact settings map and returns error for nonexistent service","ReadServicefile parses service definitions directly from a file path on disk","ParseServicefile correctly ignores comments and empty lines in service file definitions"],"goal":"verify pkg:golang/github.com/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a","kind":"HOW","packages":["pkg:golang/github.com/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a"],"schemaVersion":1},"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/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a"],"schemaVersion":1,"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
"fmt"
"io"
"strings"
"github.com/jackc/pgservicefile"
)
// ServiceConfigResolver manages PostgreSQL service file definitions and provides connection parameters.
type ServiceConfigResolver struct {
serviceFile *pgservicefile.Servicefile
}
// NewServiceConfigResolverFromReader parses PostgreSQL service configuration from an io.Reader.
func NewServiceConfigResolverFromReader(r io.Reader) (*ServiceConfigResolver, error) {
sf, err := pgservicefile.ParseServicefile(r)
if err != nil {
return nil, fmt.Errorf("failed to parse service file: %w", err)
}
return &ServiceConfigResolver{serviceFile: sf}, nil
}
// NewServiceConfigResolverFromFile loads and parses a PostgreSQL service configuration file from the filesystem.
func NewServiceConfigResolverFromFile(filePath string) (*ServiceConfigResolver, error) {
sf, err := pgservicefile.ReadServicefile(filePath)
if err != nil {
return nil, fmt.Errorf("failed to read service file: %w", err)
}
return &ServiceConfigResolver{serviceFile: sf}, nil
}
// GetServiceSettings retrieves the key-value settings map for a named service.
func (r *ServiceConfigResolver) GetServiceSettings(name string) (map[string]string, error) {
svc, err := r.serviceFile.GetService(name)
if err != nil {
return nil, fmt.Errorf("service %q not found: %w", name, err)
}
return svc.Settings, nil
}
// BuildConnString builds a standard PostgreSQL connection keyword/value string for a named service.
func (r *ServiceConfigResolver) BuildConnString(name string) (string, error) {
settings, err := r.GetServiceSettings(name)
if err != nil {
return "", err
}
var parts []string
for k, v := range settings {
parts = append(parts, fmt.Sprintf("%s=%s", k, v))
}
return strings.Join(parts, " "), nil
}
func main() {
sampleConfig := `
# Primary database service
[primary_db]
host=db.example.com
port=5432
dbname=production_app
user=app_user
# Analytics replica service
[analytics_db]
host=analytics.example.com
port=5433
dbname=analytics_warehouse
user=readonly_user
`
resolver, err := NewServiceConfigResolverFromReader(strings.NewReader(sampleConfig))
if err != nil {
fmt.Printf("Error initializing resolver: %v\n", err)
return
}
settings, err := resolver.GetServiceSettings("primary_db")
if err != nil {
fmt.Printf("Error retrieving service settings: %v\n", err)
return
}
fmt.Printf("Resolved primary_db host: %s, dbname: %s\n", settings["host"], settings["dbname"])
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/jackc/pgservicefile@v0.0.0-20221227161230-091c0ba34f0a"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/jackc/pgservicefile"
)
func main() {
// Contract 1: ParseServicefile parses service definitions with multiple sections and key-value settings from io.Reader
{
content := `
# PostgreSQL service definitions
[primary_db]
host=db.example.com
port=5432
user=dbuser
dbname=appdb
[replica_db]
host=replica.example.com
port=5433
user=readonly_user
dbname=appdb
`
sf, err := pgservicefile.ParseServicefile(strings.NewReader(content))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ParseServicefile error: %v\n", err)
os.Exit(1)
}
if sf == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected non-nil Servicefile\n")
os.Exit(1)
}
if len(sf.Services) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected 2 services, got %d\n", len(sf.Services))
os.Exit(1)
}
if sf.Services[0].Name != "primary_db" || sf.Services[1].Name != "replica_db" {
fmt.Fprintf(os.Stderr, "FAIL: unexpected service names: %s, %s\n", sf.Services[0].Name, sf.Services[1].Name)
os.Exit(1)
}
}
// Contract 2: GetService retrieves existing service configuration with exact settings map and returns error for nonexistent service
{
content := `
[app_service]
host=localhost
port=5432
dbname=mydb
user=postgres
sslmode=verify-full
`
sf, err := pgservicefile.ParseServicefile(strings.NewReader(content))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ParseServicefile error: %v\n", err)
os.Exit(1)
}
svc, err := sf.GetService("app_service")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: GetService failed for existing service: %v\n", err)
os.Exit(1)
}
if svc.Name != "app_service" {
fmt.Fprintf(os.Stderr, "FAIL: expected service name 'app_service', got %q\n", svc.Name)
os.Exit(1)
}
expectedSettings := map[string]string{
"host": "localhost",
"port": "5432",
"dbname": "mydb",
"user": "postgres",
"sslmode": "verify-full",
}
for k, expectedVal := range expectedSettings {
if actualVal, ok := svc.Settings[k]; !ok || actualVal != expectedVal {
fmt.Fprintf(os.Stderr, "FAIL: setting %q mismatch: got %q, expected %q\n", k, actualVal, expectedVal)
os.Exit(1)
}
}
_, err = sf.GetService("nonexistent_service")
if err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected error when querying nonexistent service, got nil\n")
os.Exit(1)
}
}
// Contract 3: ReadServicefile parses service definitions directly from a file path on disk
{
tmpDir, err := os.MkdirTemp("", "pgservicefile_test_*")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create temp directory: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
filePath := filepath.Join(tmpDir, ".pg_service.conf")
fileContent := `
[metrics_db]
host=metrics.example.com
port=5432
dbname=metrics
user=collector
`
if err := os.WriteFile(filePath, []byte(fileContent), 0600); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to write temp file: %v\n", err)
os.Exit(1)
}
sf, err := pgservicefile.ReadServicefile(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadServicefile error: %v\n", err)
os.Exit(1)
}
svc, err := sf.GetService("metrics_db")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: GetService for metrics_db error: %v\n", err)
os.Exit(1)
}
if svc.Settings["host"] != "metrics.example.com" || svc.Settings["dbname"] != "metrics" {
fmt.Fprintf(os.Stderr, "FAIL: unexpected service settings: %+v\n", svc.Settings)
os.Exit(1)
}
// Nonexistent file should return error
_, err = pgservicefile.ReadServicefile(filepath.Join(tmpDir, "missing.conf"))
if err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected error for missing file, got nil\n")
os.Exit(1)
}
}
// Contract 4: ParseServicefile correctly ignores comments and empty lines in service file definitions
{
contentWithComments := `
# Header comments
# Another comment line
[comment_test]
# Inline parameter comments
host=db.example.com
# Blank lines between keys
port=5432
# Trailing comments
`
sf, err := pgservicefile.ParseServicefile(strings.NewReader(contentWithComments))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ParseServicefile with comments error: %v\n", err)
os.Exit(1)
}
svc, err := sf.GetService("comment_test")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: GetService comment_test error: %v\n", err)
os.Exit(1)
}
if len(svc.Settings) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected 2 settings, got %d: %+v\n", len(svc.Settings), svc.Settings)
os.Exit(1)
}
if svc.Settings["host"] != "db.example.com" || svc.Settings["port"] != "5432" {
fmt.Fprintf(os.Stderr, "FAIL: unexpected settings in comment_test: %+v\n", svc.Settings)
os.Exit(1)
}
}
fmt.Println("PASS: github.com/jackc/pgservicefile contract passed")
}
Seeder de origem
anônimo