CodeSampleX

Sample

github.com/jackc/pgproto3/v2 v2.1.1: NewBackend

Verified sample for golang github.com/jackc/pgproto3/v2 v2.1.1: NewBackend. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:8ee07c8bb422494ecd0ed95b75e6faf298a37f86755ba9a2fefe2a677f88f0ff

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify github.com/jackc/pgproto3/v2.NewBackend in pkg:golang/github.com/jackc/pgproto3/v2@v2.1.1
Packages
Symbols
  • github.com/jackc/pgproto3/v2.NewBackend
Created
2026-09-14T23:03:19Z

Contract

  1. pgproto3.NewBackend initializes a backend protocol handler with a ChunkReader and io.Writer
  2. Backend.ReceiveStartupMessage decodes client StartupMessage protocol version and parameters
  3. Backend.Receive decodes incoming client frontend messages including Query
  4. Backend.Send encodes and transmits backend messages including AuthenticationOk, ReadyForQuery, and CommandComplete
  5. Backend.Receive handles client Terminate message to cleanly close protocol session

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

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/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.
csx.json
{"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"}
go.mod
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
)
go.sum
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=
main.go
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())
}
spec.json
{
  "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"
  ]
}
test/contract.go
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.")
}

Origin Seeder

anonymous