CodeSampleX

Sample

google.golang.org/api v0.273.1: iterator.NewPager

Verified sample for golang google.golang.org/api v0.273.1: iterator.NewPager. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:1e381ae3400eeb36a96a750faf738f801eb8a04c7781ebb97b2fde15e9f3784d

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-10-14

Case

HOW
Goal
verify iterator.NewPager in pkg:golang/google.golang.org/api@v0.273.1
Packages
Symbols
  • iterator.NewPager
Created
2026-10-14T03:02:55Z

Contract

  1. iterator.NewPager(iter, pageSize, pageToken) creates a *Pager whose NextPage(&slice) appends exactly pageSize items and returns the nextPageToken
  2. iterator.NewPager(iter, pageSize, nextPageToken) resumes iteration from nextPageToken and returns an empty token on the final partial page
  3. iterator.NewPager(iter, 0, "") sets a latched error on the iterator's PageInfo so NextPage returns an error for non-positive pageSize

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • 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 iterator.NewPager in pkg:golang/google.golang.org/api@v0.273.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/api@v0.273.1
Demonstrate these symbols/APIs:
  - iterator.NewPager

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:1a9105396c296269bb89c8f4228d59bca88fc8ebd4ebb4ac5a361a889d6f93ee","contract":["iterator.NewPager(iter, pageSize, pageToken) creates a *Pager whose NextPage(\u0026slice) appends exactly pageSize items and returns the nextPageToken","iterator.NewPager(iter, pageSize, nextPageToken) resumes iteration from nextPageToken and returns an empty token on the final partial page","iterator.NewPager(iter, 0, \"\") sets a latched error on the iterator's PageInfo so NextPage returns an error for non-positive pageSize"],"goal":"verify iterator.NewPager in pkg:golang/google.golang.org/api@v0.273.1","kind":"HOW","packages":["pkg:golang/google.golang.org/api@v0.273.1"],"schemaVersion":1,"symbols":["iterator.NewPager"]},"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/google.golang.org/api@v0.273.1"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/api@v0.273.1","symbols":["iterator.NewPager"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require google.golang.org/api v0.273.1
go.sum
google.golang.org/api v0.273.1 h1:L7G/TmpAMz0nKx/ciAVssVmWQiOF6+pOuXeKrWVsquY=
google.golang.org/api v0.273.1/go.mod h1:JbAt7mF+XVmWu6xNP8/+CTiGH30ofmCmk9nM8d8fHew=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify iterator.NewPager in pkg:golang/google.golang.org/api@v0.273.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/api@v0.273.1"
  ],
  "symbols": [
    "iterator.NewPager"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"reflect"

	"google.golang.org/api/iterator"
)

type sliceIterator struct {
	all      []string
	buf      []string
	pageInfo *iterator.PageInfo
}

func newSliceIterator(items []string) *sliceIterator {
	it := &sliceIterator{all: items}
	it.pageInfo, _ = iterator.NewPageInfo(
		it.fetch,
		func() int { return len(it.buf) },
		func() interface{} { b := it.buf; it.buf = nil; return b },
	)
	return it
}

func (it *sliceIterator) PageInfo() *iterator.PageInfo {
	return it.pageInfo
}

func (it *sliceIterator) fetch(pageSize int, pageToken string) (string, error) {
	start := 0
	if pageToken != "" {
		if _, err := fmt.Sscanf(pageToken, "idx-%d", &start); err != nil {
			return "", err
		}
	}
	if start >= len(it.all) {
		return "", nil
	}
	end := start + pageSize
	nextToken := ""
	if end < len(it.all) {
		nextToken = fmt.Sprintf("idx-%d", end)
	} else {
		end = len(it.all)
	}
	it.buf = append(it.buf, it.all[start:end]...)
	return nextToken, nil
}

func main() {
	items := []string{"a", "b", "c", "d", "e"}
	it := newSliceIterator(items)
	pager := iterator.NewPager(it, 2, "")

	var page1 []string
	token1, err := pager.NextPage(&page1)
	if err != nil || token1 != "idx-2" || !reflect.DeepEqual(page1, []string{"a", "b"}) {
		fmt.Fprintf(os.Stderr, "unexpected page1: %v, token: %q, err: %v\n", page1, token1, err)
		os.Exit(1)
	}

	resumedPager := iterator.NewPager(newSliceIterator(items), 2, token1)
	var page2 []string
	token2, err := resumedPager.NextPage(&page2)
	if err != nil || token2 != "idx-4" || !reflect.DeepEqual(page2, []string{"c", "d"}) {
		fmt.Fprintf(os.Stderr, "unexpected page2: %v, token: %q, err: %v\n", page2, token2, err)
		os.Exit(1)
	}

	var page3 []string
	token3, err := resumedPager.NextPage(&page3)
	if err != nil || token3 != "" || !reflect.DeepEqual(page3, []string{"e"}) {
		fmt.Fprintf(os.Stderr, "unexpected page3: %v, token: %q, err: %v\n", page3, token3, err)
		os.Exit(1)
	}

	badPager := iterator.NewPager(newSliceIterator(items), 0, "")
	var badPage []string
	if _, err := badPager.NextPage(&badPage); err == nil {
		fmt.Fprintln(os.Stderr, "expected error for non-positive pageSize")
		os.Exit(1)
	}
}

Origin Seeder

anonymous