CodeSampleX

Sample

github.com/Azure/azure-pipeline-go v0.2.1

Verified sample for golang github.com/Azure/azure-pipeline-go v0.2.1. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:d979573c30eadc1b922bf07e9c08e479a8301faefdd1d359832159c5cf84e07e

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

Case

HOW
Goal
verify pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1
Packages
Created
2026-10-23T19:18:29Z

Contract

  1. pipeline.NewPipeline with MethodFactoryMarker() injects the method-specific Factory passed to Pipeline.Do between outer factories and Options.HTTPSender
  2. pipeline.NewRequest and Request.RewindBody seek the request body back to offset 0 while NewRequestBodyProgress and NewResponseBodyProgress report cumulative bytes transferred
  3. PolicyOptions.Log filters entries via LogOptions.ShouldLog, appends a trailing newline when forwarding to LogOptions.Log, and pipeline.Cause unwraps the root error passed to pipeline.NewError

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 pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1

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:8683fb902e4a66a59854586ba9afd3893ef05aa45a5a12889b7186565945e4a6","contract":["pipeline.NewPipeline with MethodFactoryMarker() injects the method-specific Factory passed to Pipeline.Do between outer factories and Options.HTTPSender","pipeline.NewRequest and Request.RewindBody seek the request body back to offset 0 while NewRequestBodyProgress and NewResponseBodyProgress report cumulative bytes transferred","PolicyOptions.Log filters entries via LogOptions.ShouldLog, appends a trailing newline when forwarding to LogOptions.Log, and pipeline.Cause unwraps the root error passed to pipeline.NewError"],"goal":"verify pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1","kind":"HOW","packages":["pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1"],"schemaVersion":1},"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/Azure/azure-pipeline-go@v0.2.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.0

require github.com/Azure/azure-pipeline-go v0.2.1

require (
	github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	golang.org/x/net v0.61.0 // indirect
	golang.org/x/sys v0.49.0 // indirect
	golang.org/x/text v0.43.0 // indirect
)
go.sum
github.com/Azure/azure-pipeline-go v0.2.1 h1:OLBdZJ3yvOn2MezlWvbrBMTEUQC72zAftRZOMdj5HYo=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149 h1:HfxbT6/JcvIljmERptWhwa8XzP7H3T+Z2N26gTsaDaA=
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/Azure/azure-pipeline-go@v0.2.1"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"context"
	"errors"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"strings"

	"github.com/Azure/azure-pipeline-go/pipeline"
)

func main() {
	var trace []string
	var logged []string

	outerFactory := pipeline.FactoryFunc(func(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.PolicyFunc {
		return func(ctx context.Context, req pipeline.Request) (pipeline.Response, error) {
			trace = append(trace, "outer:req")
			req.Header.Set("X-Outer", "applied")
			po.Log(pipeline.LogInfo, "outer-info")
			po.Log(pipeline.LogDebug, "outer-debug")
			resp, err := next.Do(ctx, req)
			trace = append(trace, "outer:resp")
			return resp, err
		}
	})

	methodFactory := pipeline.FactoryFunc(func(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.PolicyFunc {
		return func(ctx context.Context, req pipeline.Request) (pipeline.Response, error) {
			trace = append(trace, "method:req")
			req.Header.Set("X-Method", "injected")
			resp, err := next.Do(ctx, req)
			trace = append(trace, "method:resp")
			return resp, err
		}
	})

	var receivedBody string
	var rewindBody string
	var receivedHeaders http.Header

	senderFactory := pipeline.FactoryFunc(func(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.PolicyFunc {
		return func(ctx context.Context, req pipeline.Request) (pipeline.Response, error) {
			trace = append(trace, "sender")
			receivedHeaders = req.Header.Clone()
			b1, err := io.ReadAll(req.Body)
			if err != nil {
				return nil, err
			}
			receivedBody = string(b1)

			if err := req.RewindBody(); err != nil {
				return nil, err
			}
			b2, err := io.ReadAll(req.Body)
			if err != nil {
				return nil, err
			}
			rewindBody = string(b2)

			httpResp := &http.Response{
				StatusCode: http.StatusCreated,
				Status:     "201 Created",
				Header:     http.Header{"X-Result": []string{"ok"}},
				Body:       io.NopCloser(strings.NewReader("response-payload")),
				Request:    req.Request,
			}
			return pipeline.NewHTTPResponse(httpResp), nil
		}
	})

	p := pipeline.NewPipeline(
		[]pipeline.Factory{
			outerFactory,
			pipeline.MethodFactoryMarker(),
		},
		pipeline.Options{
			HTTPSender: senderFactory,
			Log: pipeline.LogOptions{
				ShouldLog: func(level pipeline.LogLevel) bool {
					return level <= pipeline.LogInfo
				},
				Log: func(level pipeline.LogLevel, message string) {
					logged = append(logged, fmt.Sprintf("%d:%s", level, message))
				},
			},
		},
	)

	targetURL, err := url.Parse("http://localhost/items")
	if err != nil {
		panic(err)
	}

	var uploadedBytes []int64
	bodyReader := pipeline.NewRequestBodyProgress(strings.NewReader("hello-pipeline"), func(bytesTransferred int64) {
		uploadedBytes = append(uploadedBytes, bytesTransferred)
	})

	req, err := pipeline.NewRequest(http.MethodPost, *targetURL, bodyReader)
	if err != nil {
		panic(err)
	}

	resp, err := p.Do(context.Background(), methodFactory, req)
	if err != nil {
		panic(err)
	}

	expectedTrace := "outer:req,method:req,sender,method:resp,outer:resp"
	if got := strings.Join(trace, ","); got != expectedTrace {
		panic(fmt.Sprintf("unexpected trace: %s", got))
	}

	if receivedHeaders.Get("X-Outer") != "applied" || receivedHeaders.Get("X-Method") != "injected" {
		panic(fmt.Sprintf("unexpected headers: %v", receivedHeaders))
	}

	if receivedBody != "hello-pipeline" || rewindBody != "hello-pipeline" {
		panic(fmt.Sprintf("unexpected body reads: %q / %q", receivedBody, rewindBody))
	}

	if len(uploadedBytes) == 0 || uploadedBytes[len(uploadedBytes)-1] != int64(len("hello-pipeline")) {
		panic(fmt.Sprintf("unexpected progress reports: %v", uploadedBytes))
	}

	if len(logged) != 1 || logged[0] != fmt.Sprintf("%d:outer-info\n", pipeline.LogInfo) {
		panic(fmt.Sprintf("unexpected log entries: %q", logged))
	}

	var downloadedBytes []int64
	respReader := pipeline.NewResponseBodyProgress(resp.Response().Body, func(bytesTransferred int64) {
		downloadedBytes = append(downloadedBytes, bytesTransferred)
	})
	respData, err := io.ReadAll(respReader)
	if err != nil {
		panic(err)
	}
	_ = respReader.Close()

	if resp.Response().StatusCode != http.StatusCreated || string(respData) != "response-payload" {
		panic(fmt.Sprintf("unexpected response: %d %q", resp.Response().StatusCode, string(respData)))
	}
	if len(downloadedBytes) == 0 || downloadedBytes[len(downloadedBytes)-1] != int64(len("response-payload")) {
		panic(fmt.Sprintf("unexpected response progress: %v", downloadedBytes))
	}

	rootErr := errors.New("root-cause")
	wrappedErr := pipeline.NewError(rootErr, "pipeline failure")
	if pipeline.Cause(wrappedErr) != rootErr {
		panic("expected Cause to unwrap rootErr")
	}

	var diagBuf bytes.Buffer
	pipeline.WriteRequestWithResponse(&diagBuf, req.Request, resp.Response(), nil)
	if !strings.Contains(diagBuf.String(), "201 Created") {
		panic(fmt.Sprintf("unexpected WriteRequestWithResponse output: %s", diagBuf.String()))
	}
}

Origin Seeder

anonymous