CodeSampleX

Ejemplo

github.com/google/martian/v3 v3.0.0

Muestra verificada para golang github.com/google/martian/v3 v3.0.0. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:b8e98b483899d68a0d33622ccde394ada2b22c1492d2bae1aad8af2db3b9a75d

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 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Entornos de las ejecuciones de verificación

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

Caso

HOW
Objetivo
verify pkg:golang/github.com/google/martian/v3@v3.0.0
Paquetes
Entorno
go 1.26.6
Creado
2026-10-19T17:40:36Z

Contrato

  1. martian.NewProxy constructs an HTTP proxy that forwards requests and responses
  2. fifo.NewGroup and header.NewModifier compose request and response modifiers in FIFO order
  3. martian.RequestModifierFunc and martian.ResponseModifierFunc intercept and mutate HTTP traffic
  4. martian.NewContext provides per-request context storage with unique ID and key-value access
  5. martian.NewMultiError aggregates multiple errors and reports empty status

Archivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.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 pkg:golang/github.com/google/martian/v3@v3.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/martian/v3@v3.0.0

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:ab740443b3510b0278031a9f8c83beb0a2594845b37baae5644559c4c67938f4","contract":["martian.NewProxy constructs an HTTP proxy that forwards requests and responses","fifo.NewGroup and header.NewModifier compose request and response modifiers in FIFO order","martian.RequestModifierFunc and martian.ResponseModifierFunc intercept and mutate HTTP traffic","martian.NewContext provides per-request context storage with unique ID and key-value access","martian.NewMultiError aggregates multiple errors and reports empty status"],"goal":"verify pkg:golang/github.com/google/martian/v3@v3.0.0","kind":"HOW","packages":["pkg:golang/github.com/google/martian/v3@v3.0.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","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/google/martian/v3@v3.0.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/martian/v3@v3.0.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/google/martian/v3 v3.0.0
go.sum
github.com/google/martian/v3 v3.0.0 h1:pMen7vLs8nvgEYhywH3KDWJIJTeEr2ULsVWHWYHQyBs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
main.go
package main

import (
	"fmt"
	"net/http"

	"github.com/google/martian/v3"
)

func main() {
	martian.Init()
	p := martian.NewProxy()
	defer p.Close()

	p.SetRequestModifier(martian.RequestModifierFunc(func(req *http.Request) error {
		req.Header.Set("X-Martian-Proxy", "active")
		return nil
	}))

	fmt.Println("martian proxy configured")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/google/martian/v3@v3.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/martian/v3@v3.0.0"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"io"
	"net"
	"net/http"
	"net/http/httptest"
	"net/url"
	"os"

	"github.com/google/martian/v3"
	"github.com/google/martian/v3/fifo"
	"github.com/google/martian/v3/header"
)

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

func runContract() error {
	martian.Init()

	origin := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("X-Echo-Static", r.Header.Get("X-Static-Header"))
		w.Header().Set("X-Echo-Dynamic", r.Header.Get("X-Dynamic-Req"))
		w.Header().Set("X-Echo-Ctx", r.Header.Get("X-Ctx-Value"))
		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte("origin-response"))
	}))
	defer origin.Close()

	proxy := martian.NewProxy()
	defer proxy.Close()

	var observedCtxID string
	fg := fifo.NewGroup()
	fg.AddRequestModifier(header.NewModifier("X-Static-Header", "martian-v3"))
	fg.AddRequestModifier(martian.RequestModifierFunc(func(req *http.Request) error {
		req.Header.Set("X-Dynamic-Req", "modified")
		ctx := martian.NewContext(req)
		if ctx != nil {
			observedCtxID = ctx.ID()
			ctx.Set("trace-key", "trace-val")
			if v, ok := ctx.Get("trace-key"); ok {
				if s, ok := v.(string); ok {
					req.Header.Set("X-Ctx-Value", s)
				}
			}
		}
		return nil
	}))
	fg.AddResponseModifier(martian.ResponseModifierFunc(func(res *http.Response) error {
		res.Header.Set("X-Dynamic-Res", "intercepted")
		return nil
	}))

	proxy.SetRequestModifier(fg)
	proxy.SetResponseModifier(fg)

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		return fmt.Errorf("listen failed: %w", err)
	}
	go proxy.Serve(ln)

	proxyURL, err := url.Parse("http://" + ln.Addr().String())
	if err != nil {
		return fmt.Errorf("parse proxy url: %w", err)
	}

	client := &http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyURL(proxyURL),
		},
	}

	resp, err := client.Get(origin.URL)
	if err != nil {
		return fmt.Errorf("client get failed: %w", err)
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("read body: %w", err)
	}
	if string(body) != "origin-response" {
		return fmt.Errorf("unexpected body: %q", string(body))
	}
	if resp.Header.Get("X-Echo-Static") != "martian-v3" {
		return fmt.Errorf("expected X-Echo-Static=martian-v3, got %q", resp.Header.Get("X-Echo-Static"))
	}
	if resp.Header.Get("X-Echo-Dynamic") != "modified" {
		return fmt.Errorf("expected X-Echo-Dynamic=modified, got %q", resp.Header.Get("X-Echo-Dynamic"))
	}
	if resp.Header.Get("X-Echo-Ctx") != "trace-val" || observedCtxID == "" {
		return fmt.Errorf("expected X-Echo-Ctx=trace-val and non-empty context ID, got %q / %q", resp.Header.Get("X-Echo-Ctx"), observedCtxID)
	}
	if resp.Header.Get("X-Dynamic-Res") != "intercepted" {
		return fmt.Errorf("expected X-Dynamic-Res=intercepted, got %q", resp.Header.Get("X-Dynamic-Res"))
	}

	merr := martian.NewMultiError()
	if !merr.Empty() {
		return fmt.Errorf("new MultiError should be empty")
	}
	merr.Add(errors.New("err-one"))
	merr.Add(errors.New("err-two"))
	if merr.Empty() {
		return fmt.Errorf("MultiError should not be empty after Add")
	}
	if len(merr.Errors()) != 2 {
		return fmt.Errorf("expected 2 errors in MultiError, got %d", len(merr.Errors()))
	}
	if merr.Error() != "err-one\nerr-two" {
		return fmt.Errorf("unexpected MultiError string: %q", merr.Error())
	}

	return nil
}

Seeder de origen

anónimo