CodeSampleX

Sample

github.com/jackc/pgx/v5 v5.10.0: pgtype.Int4OID

Verified sample for golang github.com/jackc/pgx/v5 v5.10.0: pgtype.Int4OID. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:5ef80a9dcc4d442af2b28beb66c67ea93e36f3f697106791769cb8d8b10d05f9

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

Case

HOW
Goal
verify github.com/jackc/pgx/v5/pgtype.Int4OID in pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Packages
Symbols
  • github.com/jackc/pgx/v5/pgtype.Int4OID
Created
2026-08-28T01:23:15Z

Contract

  1. pgtype.Int4OID constant equals 23 representing the PostgreSQL int4 data type OID
  2. pgtype.NewMap registers Int4OID with type name int4 and resolves type definitions by OID and name
  3. pgtype.Map encodes and decodes int32 values using Int4OID under TextFormatCode
  4. pgtype.Map encodes and decodes int32 values into 4-byte big-endian binary using Int4OID under BinaryFormatCode
  5. pgtype.Map scans valid integers and SQL NULL values into pgtype.Int4 structs with Int4OID

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/pgx/v5/pgtype.Int4OID in pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Demonstrate these symbols/APIs:
  - github.com/jackc/pgx/v5/pgtype.Int4OID

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:72491361845de6654f87678c9c054c6c5ea1f6d8235bf742a8b1370bfe4d08de","contract":["pgtype.Int4OID constant equals 23 representing the PostgreSQL int4 data type OID","pgtype.NewMap registers Int4OID with type name int4 and resolves type definitions by OID and name","pgtype.Map encodes and decodes int32 values using Int4OID under TextFormatCode","pgtype.Map encodes and decodes int32 values into 4-byte big-endian binary using Int4OID under BinaryFormatCode","pgtype.Map scans valid integers and SQL NULL values into pgtype.Int4 structs with Int4OID"],"goal":"verify github.com/jackc/pgx/v5/pgtype.Int4OID in pkg:golang/github.com/jackc/pgx/v5@v5.10.0","kind":"HOW","packages":["pkg:golang/github.com/jackc/pgx/v5@v5.10.0"],"schemaVersion":1,"symbols":["github.com/jackc/pgx/v5/pgtype.Int4OID"]},"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/pgx/v5@v5.10.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/pgx/v5@v5.10.0","symbols":["github.com/jackc/pgx/v5/pgtype.Int4OID"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/jackc/pgx/v5 v5.10.0
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/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0=
github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
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/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
main.go
package main

import (
	"fmt"

	"github.com/jackc/pgx/v5/pgtype"
)

func main() {
	m := pgtype.NewMap()

	t, ok := m.TypeForOID(pgtype.Int4OID)
	if !ok {
		panic("type not found for Int4OID")
	}
	fmt.Printf("Int4OID: %d, Type Name: %s\n", pgtype.Int4OID, t.Name)

	encoded, err := m.Encode(pgtype.Int4OID, pgtype.TextFormatCode, int32(42), nil)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Encoded int4: %s\n", string(encoded))

	var val int32
	if err := m.Scan(pgtype.Int4OID, pgtype.TextFormatCode, encoded, &val); err != nil {
		panic(err)
	}
	fmt.Printf("Decoded int4: %d\n", val)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/jackc/pgx/v5/pgtype.Int4OID in pkg:golang/github.com/jackc/pgx/v5@v5.10.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/jackc/pgx/v5@v5.10.0"
  ],
  "symbols": [
    "github.com/jackc/pgx/v5/pgtype.Int4OID"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"os"

	"github.com/jackc/pgx/v5/pgtype"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("Contract tests passed.")
}

func runContractTests() error {
	// 1. Int4OID constant value verification
	if pgtype.Int4OID != 23 {
		return fmt.Errorf("expected Int4OID to be 23, got %d", pgtype.Int4OID)
	}

	// 2. Type lookup in pgtype.Map by OID
	m := pgtype.NewMap()
	t, ok := m.TypeForOID(pgtype.Int4OID)
	if !ok {
		return fmt.Errorf("TypeForOID(Int4OID) failed to find registered type")
	}
	if t.Name != "int4" {
		return fmt.Errorf("expected type name 'int4', got %q", t.Name)
	}
	if t.OID != pgtype.Int4OID {
		return fmt.Errorf("expected type OID %d, got %d", pgtype.Int4OID, t.OID)
	}

	// Type lookup by name
	tByName, ok := m.TypeForName("int4")
	if !ok || tByName.OID != pgtype.Int4OID {
		return fmt.Errorf("TypeForName('int4') mismatch or not found")
	}

	// 3. Text format encoding and decoding with Int4OID
	encodedText, err := m.Encode(pgtype.Int4OID, pgtype.TextFormatCode, int32(12345), nil)
	if err != nil {
		return fmt.Errorf("m.Encode(Int4OID, TextFormatCode) failed: %w", err)
	}
	if string(encodedText) != "12345" {
		return fmt.Errorf("expected encoded text '12345', got %q", string(encodedText))
	}

	var decodedInt32 int32
	err = m.Scan(pgtype.Int4OID, pgtype.TextFormatCode, []byte("12345"), &decodedInt32)
	if err != nil {
		return fmt.Errorf("m.Scan(Int4OID, TextFormatCode) failed: %w", err)
	}
	if decodedInt32 != 12345 {
		return fmt.Errorf("expected decoded value 12345, got %d", decodedInt32)
	}

	// 4. Binary format encoding and decoding with Int4OID
	encodedBin, err := m.Encode(pgtype.Int4OID, pgtype.BinaryFormatCode, int32(67890), nil)
	if err != nil {
		return fmt.Errorf("m.Encode(Int4OID, BinaryFormatCode) failed: %w", err)
	}
	expectedBin := make([]byte, 4)
	binary.BigEndian.PutUint32(expectedBin, uint32(67890))
	if !bytes.Equal(encodedBin, expectedBin) {
		return fmt.Errorf("expected binary %v, got %v", expectedBin, encodedBin)
	}

	var decodedBinInt32 int32
	err = m.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, encodedBin, &decodedBinInt32)
	if err != nil {
		return fmt.Errorf("m.Scan(Int4OID, BinaryFormatCode) failed: %w", err)
	}
	if decodedBinInt32 != 67890 {
		return fmt.Errorf("expected binary decoded value 67890, got %d", decodedBinInt32)
	}

	// 5. pgtype.Int4 struct scanning and NULL handling with Int4OID
	var pgInt pgtype.Int4
	err = m.Scan(pgtype.Int4OID, pgtype.TextFormatCode, []byte("-42"), &pgInt)
	if err != nil {
		return fmt.Errorf("m.Scan into pgtype.Int4 failed: %w", err)
	}
	if !pgInt.Valid || pgInt.Int32 != -42 {
		return fmt.Errorf("expected Valid=true, Int32=-42, got Valid=%v, Int32=%d", pgInt.Valid, pgInt.Int32)
	}

	// NULL scan
	var nullInt pgtype.Int4
	err = m.Scan(pgtype.Int4OID, pgtype.TextFormatCode, nil, &nullInt)
	if err != nil {
		return fmt.Errorf("m.Scan NULL into pgtype.Int4 failed: %w", err)
	}
	if nullInt.Valid {
		return fmt.Errorf("expected Valid=false for NULL scan, got Valid=true")
	}

	return nil
}

Origin Seeder

anonymous