CodeSampleX

Пример

github.com/jackc/pgio v1.0.0: AppendInt32

Проверенный пример — golang github.com/jackc/pgio v1.0.0: AppendInt32. Контракт выполнен на go 1.26 · linux alpine/x64 · docker и пройден.

sha256:82d0955505d3c744d863de52d9573ce17ebb27335146afd3c6db42990f2b2e7c

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
1
Заявленная среда go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go go 1

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-26
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-07

Кейс

HOW
Цель
verify github.com/jackc/pgio.AppendInt32 in pkg:golang/github.com/jackc/pgio@v1.0.0
Пакеты
Символы
  • github.com/jackc/pgio.AppendInt32
Окружение
go 1.26.6
Создан
2026-08-26T01:31:06Z

Контракт

  1. pgio.AppendInt32(buf, n) appends the 4-byte big-endian binary encoding of an int32 to the buffer
  2. pgio.AppendInt32 preserves existing slice prefix and increases slice length by 4 bytes
  3. pgio.AppendInt32 correctly encodes positive, negative, zero, MaxInt32, and MinInt32 values

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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/pgio.AppendInt32 in pkg:golang/github.com/jackc/pgio@v1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/jackc/pgio@v1.0.0
Demonstrate these symbols/APIs:
  - github.com/jackc/pgio.AppendInt32
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:39b42d9b8b5f385317021d15c4fecee3c32348148bf810a7d0f0c30cb771fecc","contract":["pgio.AppendInt32(buf, n) appends the 4-byte big-endian binary encoding of an int32 to the buffer","pgio.AppendInt32 preserves existing slice prefix and increases slice length by 4 bytes","pgio.AppendInt32 correctly encodes positive, negative, zero, MaxInt32, and MinInt32 values"],"goal":"verify github.com/jackc/pgio.AppendInt32 in pkg:golang/github.com/jackc/pgio@v1.0.0","kind":"HOW","packages":["pkg:golang/github.com/jackc/pgio@v1.0.0"],"schemaVersion":1,"symbols":["github.com/jackc/pgio.AppendInt32"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","moduleSystem":"go","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/jackc/pgio@v1.0.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/pgio@v1.0.0","symbols":["github.com/jackc/pgio.AppendInt32"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require github.com/jackc/pgio v1.0.0
go.sum
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
main.go
package main

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

	"github.com/jackc/pgio"
)

func main() {
	buf := make([]byte, 0, 16)
	buf = pgio.AppendInt32(buf, 42)
	buf = pgio.AppendInt32(buf, -100)

	var val1, val2 int32
	r := bytes.NewReader(buf)
	_ = binary.Read(r, binary.BigEndian, &val1)
	_ = binary.Read(r, binary.BigEndian, &val2)

	fmt.Printf("encoded: %x, decoded: %d, %d\n", buf, val1, val2)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/jackc/pgio.AppendInt32 in pkg:golang/github.com/jackc/pgio@v1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/jackc/pgio@v1.0.0"
  ],
  "symbols": [
    "github.com/jackc/pgio.AppendInt32"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract_test.go
package test

import (
	"bytes"
	"encoding/binary"
	"math"
	"testing"

	"github.com/jackc/pgio"
)

func TestAppendInt32(t *testing.T) {
	tests := []struct {
		name     string
		input    int32
		expected []byte
	}{
		{
			name:     "zero",
			input:    0,
			expected: []byte{0x00, 0x00, 0x00, 0x00},
		},
		{
			name:     "positive one",
			input:    1,
			expected: []byte{0x00, 0x00, 0x00, 0x01},
		},
		{
			name:     "negative one",
			input:    -1,
			expected: []byte{0xff, 0xff, 0xff, 0xff},
		},
		{
			name:     "arbitrary positive integer",
			input:    0x12345678,
			expected: []byte{0x12, 0x34, 0x56, 0x78},
		},
		{
			name:     "max int32",
			input:    math.MaxInt32,
			expected: []byte{0x7f, 0xff, 0xff, 0xff},
		},
		{
			name:     "min int32",
			input:    math.MinInt32,
			expected: []byte{0x80, 0x00, 0x00, 0x00},
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			buf := make([]byte, 0, 4)
			result := pgio.AppendInt32(buf, tc.input)

			if len(result) != 4 {
				t.Fatalf("expected length 4, got %d", len(result))
			}

			if !bytes.Equal(result, tc.expected) {
				t.Fatalf("expected bytes %x, got %x", tc.expected, result)
			}

			var decoded int32
			if err := binary.Read(bytes.NewReader(result), binary.BigEndian, &decoded); err != nil {
				t.Fatalf("failed to decode int32: %v", err)
			}

			if decoded != tc.input {
				t.Fatalf("decoded value mismatch: expected %d, got %d", tc.input, decoded)
			}
		})
	}
}

func TestAppendInt32_PreservesPrefix(t *testing.T) {
	prefix := []byte{0xAA, 0xBB, 0xCC}
	buf := append([]byte(nil), prefix...)

	result := pgio.AppendInt32(buf, 12345)

	if len(result) != len(prefix)+4 {
		t.Fatalf("expected length %d, got %d", len(prefix)+4, len(result))
	}

	if !bytes.Equal(result[:len(prefix)], prefix) {
		t.Fatalf("prefix was modified: expected %x, got %x", prefix, result[:len(prefix)])
	}

	var decoded int32
	if err := binary.Read(bytes.NewReader(result[len(prefix):]), binary.BigEndian, &decoded); err != nil {
		t.Fatalf("failed to decode int32: %v", err)
	}

	if decoded != 12345 {
		t.Fatalf("decoded value mismatch: expected 12345, got %d", decoded)
	}
}

func TestAppendInt32_MultipleAppends(t *testing.T) {
	var buf []byte
	values := []int32{10, -20, 300, -4000, math.MaxInt32, math.MinInt32}

	for _, v := range values {
		buf = pgio.AppendInt32(buf, v)
	}

	if len(buf) != len(values)*4 {
		t.Fatalf("expected total length %d, got %d", len(values)*4, len(buf))
	}

	r := bytes.NewReader(buf)
	for i, expected := range values {
		var actual int32
		if err := binary.Read(r, binary.BigEndian, &actual); err != nil {
			t.Fatalf("failed reading index %d: %v", i, err)
		}
		if actual != expected {
			t.Fatalf("at index %d: expected %d, got %d", i, expected, actual)
		}
	}
}

Исходный сидер

аноним