CodeSampleX

Ejemplo

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

Muestra verificada para golang github.com/jackc/pgx/v5 v5.10.0: pgtype.Int8OID. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y pasó.

sha256:7c5f3e7cb504d727e81008567438bd32355e71151c60847dcd24169235ced87d

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify github.com/jackc/pgx/v5/pgtype.Int8OID in pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Paquetes
Símbolos
  • github.com/jackc/pgx/v5/pgtype.Int8OID
Creado
2026-08-28T01:25:53Z

Contrato

  1. pgtype.Int8OID matches PostgreSQL int8 OID constant 20 and resolves to type int8 in pgtype.Map
  2. pgtype.Map encodes and scans int64 values in PostgreSQL text format using pgtype.Int8OID
  3. pgtype.Map encodes and scans int64 values in PostgreSQL 8-byte big-endian binary wire format using pgtype.Int8OID
  4. pgtype.Map scans PostgreSQL NULL data into pgtype.Int8 with Valid false using pgtype.Int8OID
  5. pgtype.Map returns an error when scanning malformed or out-of-range text data with pgtype.Int8OID

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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.Int8OID 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.Int8OID
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.
csx.json
{"case":{"caseId":"case:sha256:b8c58f0b78b8f2a3b4a29561e656860c8f234ed84b5ec45ca6c21c6c01c9e2be","contract":["pgtype.Int8OID matches PostgreSQL int8 OID constant 20 and resolves to type int8 in pgtype.Map","pgtype.Map encodes and scans int64 values in PostgreSQL text format using pgtype.Int8OID","pgtype.Map encodes and scans int64 values in PostgreSQL 8-byte big-endian binary wire format using pgtype.Int8OID","pgtype.Map scans PostgreSQL NULL data into pgtype.Int8 with Valid false using pgtype.Int8OID","pgtype.Map returns an error when scanning malformed or out-of-range text data with pgtype.Int8OID"],"goal":"verify github.com/jackc/pgx/v5/pgtype.Int8OID 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.Int8OID"]},"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.Int8OID"],"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"
)

// EncodeInt8 encodes an int64 value into PostgreSQL text or binary representations using Int8OID.
func EncodeInt8(m *pgtype.Map, value int64, format int16) ([]byte, error) {
	return m.Encode(pgtype.Int8OID, format, value, nil)
}

// DecodeInt8 decodes PostgreSQL encoded bytes into an int64 value using Int8OID.
func DecodeInt8(m *pgtype.Map, data []byte, format int16) (int64, error) {
	var val int64
	err := m.Scan(pgtype.Int8OID, format, data, &val)
	if err != nil {
		return 0, err
	}
	return val, nil
}

func main() {
	typeMap := pgtype.NewMap()
	val := int64(9223372036854775807)

	textEncoded, err := EncodeInt8(typeMap, val, pgtype.TextFormatCode)
	if err != nil {
		fmt.Printf("Error encoding int8 to text: %v\n", err)
		return
	}
	fmt.Printf("Encoded int8 text: %s\n", string(textEncoded))

	binEncoded, err := EncodeInt8(typeMap, val, pgtype.BinaryFormatCode)
	if err != nil {
		fmt.Printf("Error encoding int8 to binary: %v\n", err)
		return
	}
	fmt.Printf("Encoded int8 binary bytes: %x\n", binEncoded)

	decodedVal, err := DecodeInt8(typeMap, binEncoded, pgtype.BinaryFormatCode)
	if err != nil {
		fmt.Printf("Error decoding int8 from binary: %v\n", err)
		return
	}
	fmt.Printf("Decoded int8 binary: %d\n", decodedVal)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/jackc/pgx/v5/pgtype.Int8OID 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.Int8OID"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/main.go
package main

import (
	"bytes"
	"fmt"
	"os"

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

func assertTrue(name string, condition bool) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: expected true, got false\n", name)
		os.Exit(1)
	}
}

func assertEqualInt64(name string, actual, expected int64) {
	if actual != expected {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: got %d, expected %d\n", name, actual, expected)
		os.Exit(1)
	}
}

func assertEqualUint32(name string, actual, expected uint32) {
	if actual != expected {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: got %d, expected %d\n", name, actual, expected)
		os.Exit(1)
	}
}

func assertEqualString(name, actual, expected string) {
	if actual != expected {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: got %q, expected %q\n", name, actual, expected)
		os.Exit(1)
	}
}

func assertBytesEqual(name string, actual, expected []byte) {
	if !bytes.Equal(actual, expected) {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: got %x, expected %x\n", name, actual, expected)
		os.Exit(1)
	}
}

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

	// Contract: pgtype.Int8OID matches PostgreSQL int8 OID constant 20 and resolves to type int8 in pgtype.Map
	assertEqualUint32("pgtype.Int8OID value", pgtype.Int8OID, 20)
	typ, ok := typeMap.TypeForOID(pgtype.Int8OID)
	assertTrue("TypeForOID(pgtype.Int8OID) found", ok)
	assertEqualString("TypeForOID name", typ.Name, "int8")
	assertEqualUint32("TypeForOID OID", typ.OID, pgtype.Int8OID)

	typByName, okByName := typeMap.TypeForName("int8")
	assertTrue("TypeForName(\"int8\") found", okByName)
	assertEqualUint32("TypeForName OID", typByName.OID, pgtype.Int8OID)

	// Contract: pgtype.Map encodes and scans int64 values in PostgreSQL text format using pgtype.Int8OID
	encodedText, err := typeMap.Encode(pgtype.Int8OID, pgtype.TextFormatCode, int64(9223372036854775807), nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error encoding text int8: %v\n", err)
		os.Exit(1)
	}
	assertEqualString("encoded text int8 max", string(encodedText), "9223372036854775807")

	var scannedTextVal int64
	err = typeMap.Scan(pgtype.Int8OID, pgtype.TextFormatCode, []byte("-9223372036854775808"), &scannedTextVal)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error scanning text int8: %v\n", err)
		os.Exit(1)
	}
	assertEqualInt64("scanned text int8 min", scannedTextVal, -9223372036854775808)

	// Contract: pgtype.Map encodes and scans int64 values in PostgreSQL 8-byte big-endian binary wire format using pgtype.Int8OID
	testVal := int64(0x0102030405060708)
	expectedBin := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
	encodedBin, err := typeMap.Encode(pgtype.Int8OID, pgtype.BinaryFormatCode, testVal, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error encoding binary int8: %v\n", err)
		os.Exit(1)
	}
	assertBytesEqual("encoded binary int8", encodedBin, expectedBin)

	var scannedBinVal int64
	err = typeMap.Scan(pgtype.Int8OID, pgtype.BinaryFormatCode, encodedBin, &scannedBinVal)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error scanning binary int8: %v\n", err)
		os.Exit(1)
	}
	assertEqualInt64("scanned binary int8", scannedBinVal, testVal)

	// Contract: pgtype.Map scans PostgreSQL NULL data into pgtype.Int8 with Valid false using pgtype.Int8OID
	var nullVal pgtype.Int8
	err = typeMap.Scan(pgtype.Int8OID, pgtype.TextFormatCode, nil, &nullVal)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error scanning nil into pgtype.Int8: %v\n", err)
		os.Exit(1)
	}
	assertTrue("scanned nil has Valid false", !nullVal.Valid)

	// Contract: pgtype.Map returns an error when scanning malformed or out-of-range text data with pgtype.Int8OID
	var badVal int64
	errBad := typeMap.Scan(pgtype.Int8OID, pgtype.TextFormatCode, []byte("not-an-int8"), &badVal)
	if errBad == nil {
		fmt.Fprintf(os.Stderr, "Expected error scanning malformed text, got nil\n")
		os.Exit(1)
	}
	assertTrue("error is non-nil for invalid text", errBad != nil)

	errOverflow := typeMap.Scan(pgtype.Int8OID, pgtype.TextFormatCode, []byte("9223372036854775808"), &badVal)
	if errOverflow == nil {
		fmt.Fprintf(os.Stderr, "Expected error scanning overflow value, got nil\n")
		os.Exit(1)
	}
	assertTrue("error is non-nil for overflow", errOverflow != nil)

	fmt.Println("All pgtype.Int8OID contract assertions passed.")
}

Seeder de origen

anónimo