샘플
github.com/jackc/pgproto3/v2 v2.1.1: NewBackend
검증된 샘플 — golang github.com/jackc/pgproto3/v2 v2.1.1: NewBackend. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: pgproto3.NewBackend initializes…
sha256:8ee07c8bb422494ecd0ed95b75e6faf298a37f86755ba9a2fefe2a677f88f0ff
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-14 |
케이스
HOW- 목표
- verify github.com/jackc/pgproto3/v2.NewBackend in pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1
- 심벌
-
- github.com/jackc/pgproto3/v2.NewBackend
- 생성일
- 2026-09-14T23:03:19Z
컨트랙트
- pgproto3.NewBackend initializes a backend protocol handler with a ChunkReader and io.Writer
- Backend.ReceiveStartupMessage decodes client StartupMessage protocol version and parameters
- Backend.Receive decodes incoming client frontend messages including Query
- Backend.Send encodes and transmits backend messages including AuthenticationOk, ReadyForQuery, and CommandComplete
- Backend.Receive handles client Terminate message to cleanly close protocol session
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
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/jackc/pgproto3/v2.NewBackend in pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1
Demonstrate these symbols/APIs:
- github.com/jackc/pgproto3/v2.NewBackend
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:1627b31a7b4e23e4e1062ee462ee30c98f4b9f827e705c66bbd6d87102ed4e2c","contract":["pgproto3.NewBackend initializes a backend protocol handler with a ChunkReader and io.Writer","Backend.ReceiveStartupMessage decodes client StartupMessage protocol version and parameters","Backend.Receive decodes incoming client frontend messages including Query","Backend.Send encodes and transmits backend messages including AuthenticationOk, ReadyForQuery, and CommandComplete","Backend.Receive handles client Terminate message to cleanly close protocol session"],"goal":"verify github.com/jackc/pgproto3/v2.NewBackend in pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1","kind":"HOW","packages":["pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1"],"schemaVersion":1,"symbols":["github.com/jackc/pgproto3/v2.NewBackend"]},"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/pgproto3/v2@v2.1.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1","symbols":["github.com/jackc/pgproto3/v2.NewBackend"],"verifierAdapter":"golang@1"}
module sample-backend
go 1.26.6
require github.com/jackc/pgproto3/v2 v2.1.1
require (
github.com/jackc/chunkreader/v2 v2.0.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
)
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/chunkreader/v2 v2.0.0 h1:DUwgMQuuPnS0rhMXenUtZpqZqrR/30NWY+qQvTpSvEs=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgproto3/v2 v2.1.1 h1:7PQ/4gLoqnl87ZxL7xjO0DR5gYuviDCZxQJsUlFW1eI=
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
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.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
package main
import (
"bytes"
"fmt"
"github.com/jackc/pgproto3/v2"
)
func main() {
clientToServer := &bytes.Buffer{}
serverToClient := &bytes.Buffer{}
backend := pgproto3.NewBackend(pgproto3.NewChunkReader(clientToServer), serverToClient)
query := &pgproto3.Query{String: "SELECT 1;"}
buf := query.Encode(nil)
clientToServer.Write(buf)
msg, err := backend.Receive()
if err != nil {
fmt.Printf("receive error: %v\n", err)
return
}
if q, ok := msg.(*pgproto3.Query); ok {
fmt.Printf("Backend received query: %s\n", q.String)
}
err = backend.Send(&pgproto3.ReadyForQuery{TxStatus: 'I'})
if err != nil {
fmt.Printf("send error: %v\n", err)
return
}
fmt.Printf("Backend sent %d response bytes\n", serverToClient.Len())
}
{
"schemaVersion": 1,
"goal": "verify github.com/jackc/pgproto3/v2.NewBackend in pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1"
],
"symbols": [
"github.com/jackc/pgproto3/v2.NewBackend"
]
}
package main
import (
"bytes"
"fmt"
"os"
"github.com/jackc/pgproto3/v2"
)
func main() {
// 1. pgproto3.NewBackend initializes a backend protocol handler with a ChunkReader and io.Writer
{
clientToServer := &bytes.Buffer{}
serverToClient := &bytes.Buffer{}
cr := pgproto3.NewChunkReader(clientToServer)
backend := pgproto3.NewBackend(cr, serverToClient)
if backend == nil {
fmt.Fprintf(os.Stderr, "Contract 1 failed: NewBackend returned nil\n")
os.Exit(1)
}
}
// 2. Backend.ReceiveStartupMessage decodes client StartupMessage protocol version and parameters
{
clientToServer := &bytes.Buffer{}
serverToClient := &bytes.Buffer{}
backend := pgproto3.NewBackend(pgproto3.NewChunkReader(clientToServer), serverToClient)
sm := &pgproto3.StartupMessage{
ProtocolVersion: pgproto3.ProtocolVersionNumber,
Parameters: map[string]string{
"user": "sampleuser",
"database": "sampledb",
},
}
buf := sm.Encode(nil)
clientToServer.Write(buf)
msg, err := backend.ReceiveStartupMessage()
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 2 failed ReceiveStartupMessage: %v\n", err)
os.Exit(1)
}
decodedSM, ok := msg.(*pgproto3.StartupMessage)
if !ok {
fmt.Fprintf(os.Stderr, "Contract 2 failed: expected StartupMessage, got %#v\n", msg)
os.Exit(1)
}
if decodedSM.ProtocolVersion != pgproto3.ProtocolVersionNumber {
fmt.Fprintf(os.Stderr, "Contract 2 failed: version mismatch\n")
os.Exit(1)
}
if decodedSM.Parameters["user"] != "sampleuser" || decodedSM.Parameters["database"] != "sampledb" {
fmt.Fprintf(os.Stderr, "Contract 2 failed: parameters mismatch\n")
os.Exit(1)
}
}
// 3. Backend.Receive decodes incoming client frontend messages including Query
{
clientToServer := &bytes.Buffer{}
serverToClient := &bytes.Buffer{}
backend := pgproto3.NewBackend(pgproto3.NewChunkReader(clientToServer), serverToClient)
q := &pgproto3.Query{String: "SELECT 42;"}
buf := q.Encode(nil)
clientToServer.Write(buf)
msg, err := backend.Receive()
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 3 failed Receive: %v\n", err)
os.Exit(1)
}
decodedQ, ok := msg.(*pgproto3.Query)
if !ok || decodedQ.String != "SELECT 42;" {
fmt.Fprintf(os.Stderr, "Contract 3 failed: expected Query 'SELECT 42;', got %#v\n", msg)
os.Exit(1)
}
}
// 4. Backend.Send encodes and transmits backend messages including AuthenticationOk, ReadyForQuery, and CommandComplete
{
clientToServer := &bytes.Buffer{}
serverToClient := &bytes.Buffer{}
backend := pgproto3.NewBackend(pgproto3.NewChunkReader(clientToServer), serverToClient)
if err := backend.Send(&pgproto3.AuthenticationOk{}); err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed Send AuthenticationOk: %v\n", err)
os.Exit(1)
}
if err := backend.Send(&pgproto3.CommandComplete{CommandTag: []byte("SELECT 1")}); err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed Send CommandComplete: %v\n", err)
os.Exit(1)
}
if err := backend.Send(&pgproto3.ReadyForQuery{TxStatus: 'I'}); err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed Send ReadyForQuery: %v\n", err)
os.Exit(1)
}
if serverToClient.Len() == 0 {
fmt.Fprintf(os.Stderr, "Contract 4 failed: no output written\n")
os.Exit(1)
}
frontend := pgproto3.NewFrontend(pgproto3.NewChunkReader(serverToClient), &bytes.Buffer{})
msg1, err := frontend.Receive()
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed read AuthenticationOk: %v\n", err)
os.Exit(1)
}
if _, ok := msg1.(*pgproto3.AuthenticationOk); !ok {
fmt.Fprintf(os.Stderr, "Contract 4 failed: expected AuthenticationOk\n")
os.Exit(1)
}
msg2, err := frontend.Receive()
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed read CommandComplete: %v\n", err)
os.Exit(1)
}
if cc, ok := msg2.(*pgproto3.CommandComplete); !ok || string(cc.CommandTag) != "SELECT 1" {
fmt.Fprintf(os.Stderr, "Contract 4 failed: expected CommandComplete 'SELECT 1'\n")
os.Exit(1)
}
msg3, err := frontend.Receive()
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed read ReadyForQuery: %v\n", err)
os.Exit(1)
}
if rfq, ok := msg3.(*pgproto3.ReadyForQuery); !ok || rfq.TxStatus != 'I' {
fmt.Fprintf(os.Stderr, "Contract 4 failed: expected ReadyForQuery 'I'\n")
os.Exit(1)
}
}
// 5. Backend.Receive handles client Terminate message to cleanly close protocol session
{
clientToServer := &bytes.Buffer{}
serverToClient := &bytes.Buffer{}
backend := pgproto3.NewBackend(pgproto3.NewChunkReader(clientToServer), serverToClient)
term := &pgproto3.Terminate{}
buf := term.Encode(nil)
clientToServer.Write(buf)
msg, err := backend.Receive()
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 5 failed Receive Terminate: %v\n", err)
os.Exit(1)
}
if _, ok := msg.(*pgproto3.Terminate); !ok {
fmt.Fprintf(os.Stderr, "Contract 5 failed: expected Terminate, got %#v\n", msg)
os.Exit(1)
}
}
fmt.Println("All contract assertions passed.")
}
오리진 시더
익명