CodeSampleX

Exemplo

modernc.org/ccgo/v4 v4.34.5: lib.NewTask

Amostra verificada para golang modernc.org/ccgo/v4 v4.34.5: lib.NewTask. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:1e90200f87edc647c93c1b8ac196a546b3b4052681fe669eae69585d4c04389d

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-21

Caso

HOW
Objetivo
verify modernc.org/ccgo/v4/lib.NewTask in pkg:golang/modernc.org/ccgo/v4@v4.34.5
Pacotes
Símbolos
  • modernc.org/ccgo/v4/lib.NewTask
Criado
2026-10-21T20:52:14Z

Contrato

  1. NewTask returns a non-nil Task configured with target OS and architecture
  2. NewTask parses command line define and include flags into Task fields
  3. NewTask parses undefine, optimization, and preprocessing flags
  4. NewTask executes C preprocessing on virtual filesystem source and routes output to stdout
  5. NewTask captures errors when preprocessing invalid or missing source files

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 modernc.org/ccgo/v4/lib.NewTask in pkg:golang/modernc.org/ccgo/v4@v4.34.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/modernc.org/ccgo/v4@v4.34.5
Demonstrate these symbols/APIs:
  - modernc.org/ccgo/v4/lib.NewTask

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:9394f6443f2b8d5cb2b10f5081a077b4d5b03a7f07c1e9ad33d4818ad6048944","contract":["NewTask returns a non-nil Task configured with target OS and architecture","NewTask parses command line define and include flags into Task fields","NewTask parses undefine, optimization, and preprocessing flags","NewTask executes C preprocessing on virtual filesystem source and routes output to stdout","NewTask captures errors when preprocessing invalid or missing source files"],"goal":"verify modernc.org/ccgo/v4/lib.NewTask in pkg:golang/modernc.org/ccgo/v4@v4.34.5","kind":"HOW","packages":["pkg:golang/modernc.org/ccgo/v4@v4.34.5"],"schemaVersion":1,"symbols":["modernc.org/ccgo/v4/lib.NewTask"]},"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/modernc.org/ccgo/v4@v4.34.5"],"schemaVersion":1,"subject":"pkg:golang/modernc.org/ccgo/v4@v4.34.5","symbols":["modernc.org/ccgo/v4/lib.NewTask"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require modernc.org/ccgo/v4 v4.34.5

require (
	github.com/dustin/go-humanize v1.0.1 // indirect
	github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
	golang.org/x/mod v0.37.0 // indirect
	golang.org/x/sync v0.21.0 // indirect
	golang.org/x/tools v0.46.0 // indirect
	modernc.org/cc/v4 v4.29.0 // indirect
	modernc.org/gc/v2 v2.6.5 // indirect
	modernc.org/gc/v3 v3.1.4 // indirect
	modernc.org/mathutil v1.7.1 // indirect
	modernc.org/opt v0.2.0 // indirect
	modernc.org/sortutil v1.2.1 // indirect
	modernc.org/strutil v1.2.1 // indirect
	modernc.org/token v1.1.0 // indirect
)
go.sum
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
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/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/tools v0.46.0 h1:7jTurBkPZu4moS/Uy4OQT1M+QBlsj3wejyZwsT8Z7rk=
golang.org/x/tools v0.46.0/go.mod h1:FrD85F8l+NWL+9XWBSyVSHO6Ne4jutsfIFba7AWQ5Ys=
modernc.org/cc/v4 v4.29.0 h1:CXgwL8cvxmyzBQZzbSl/6xFtMCryb6u8IOqDci39cgc=
modernc.org/cc/v4 v4.29.0/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.5 h1:hcwnthv2/LBl+mRLOYwnQA/LuW44Oln1NQlWppNaS1Q=
modernc.org/ccgo/v4 v4.34.5/go.mod h1:aow0HNkO30OSA/2NrtDXkis92ff8ZFiDOmDOPhqhF8U=
modernc.org/ccorpus2 v1.6.0 h1:JODbahvmixwZDoF1kZs/9Rj6aHA2vAPP7HKiNDq//xo=
modernc.org/ccorpus2 v1.6.0/go.mod h1:Wifvo4Q/qS/h1aRoC2TffcHsnxwTikmi1AuLANuucJQ=
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.4 h1:2g65LGVSmFQrXeITAw97x7hCRvZFcyE1uDP+7Vng7JI=
modernc.org/gc/v3 v3.1.4/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/lex v1.1.1 h1:prSCNTLw1R4rn7M/RzwsuMtAuOytfyR3cnyM07P+Pas=
modernc.org/lex v1.1.1/go.mod h1:6r8o8DLJkAnOsQaGi8fMoi+Vt6LTbDaCrkUK729D8xM=
modernc.org/lexer v1.0.4 h1:hU7xVbZsqwPphyzChc7nMSGrsuaD2PDNOmzrzkS5AlE=
modernc.org/lexer v1.0.4/go.mod h1:tOajb8S4sdfOYitzCgXDFmbVJ/LE0v1fNJ7annTw36U=
modernc.org/libc v1.73.4 h1:+ra4Ui8ngyt8HDcO1FTDPWlkAh6yOdaO2yAoh8MddQA=
modernc.org/libc v1.73.4/go.mod h1:DXZ3eO8qMCNn2SnmTNCiC71nJ9Rcq3PsnpU6Vc4rWK8=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/scannertest v1.0.2 h1:JPtfxcVdbRvzmRf2YUvsDibJsQRw8vKA/3jb31y7cy0=
modernc.org/scannertest v1.0.2/go.mod h1:RzTm5RwglF/6shsKoEivo8N91nQIoWtcWI7ns+zPyGA=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
main.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"testing/fstest"

	ccgo "modernc.org/ccgo/v4/lib"
)

func main() {
	mfs := fstest.MapFS{
		"sample.c": &fstest.MapFile{
			Data: []byte("#define BUFFER_CAPACITY 1024\nint default_capacity = BUFFER_CAPACITY;\n"),
		},
	}

	var stdout, stderr bytes.Buffer
	args := []string{"ccgo", "-E", "sample.c"}

	task := ccgo.NewTask("linux", "amd64", args, &stdout, &stderr, mfs)
	if task == nil {
		fmt.Fprintln(os.Stderr, "failed to create task")
		os.Exit(1)
	}

	if err := task.Main(); err != nil {
		fmt.Fprintf(os.Stderr, "preprocessing failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Println("Preprocessing completed successfully:")
	fmt.Print(stdout.String())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify modernc.org/ccgo/v4/lib.NewTask in pkg:golang/modernc.org/ccgo/v4@v4.34.5",
  "kind": "HOW",
  "packages": [
    "pkg:golang/modernc.org/ccgo/v4@v4.34.5"
  ],
  "symbols": [
    "modernc.org/ccgo/v4/lib.NewTask"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"
	"testing/fstest"

	ccgo "modernc.org/ccgo/v4/lib"
)

func main() {
	// Assertion 1: NewTask returns a non-nil Task configured with target OS and architecture
	{
		var stdout, stderr bytes.Buffer
		task := ccgo.NewTask("linux", "amd64", []string{"ccgo"}, &stdout, &stderr, nil)
		if task == nil {
			fmt.Fprintln(os.Stderr, "assertion 1 failed: NewTask returned nil")
			os.Exit(1)
		}
	}

	// Assertion 2: NewTask parses command line define and include flags into Task fields
	{
		mfs := fstest.MapFS{
			"dummy.c": &fstest.MapFile{Data: []byte("int dummy = 1;\n")},
		}
		var stdout, stderr bytes.Buffer
		args := []string{"ccgo", "-D", "CONFIG_FLAG=1", "-I", "include/path", "-E", "dummy.c"}
		task := ccgo.NewTask("linux", "amd64", args, &stdout, &stderr, mfs)
		if task == nil {
			fmt.Fprintln(os.Stderr, "assertion 2 failed: NewTask returned nil")
			os.Exit(1)
		}
		if err := task.Main(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: task.Main error: %v\n", err)
			os.Exit(1)
		}

		foundD := false
		for _, d := range task.D {
			if strings.Contains(d, "CONFIG_FLAG=1") {
				foundD = true
				break
			}
		}
		if !foundD {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: define flag not found in task.D: %v\n", task.D)
			os.Exit(1)
		}

		foundI := false
		for _, i := range task.I {
			if i == "include/path" {
				foundI = true
				break
			}
		}
		if !foundI {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: include flag not found in task.I: %v\n", task.I)
			os.Exit(1)
		}
	}

	// Assertion 3: NewTask parses undefine, optimization, and preprocessing flags
	{
		mfs := fstest.MapFS{
			"dummy.c": &fstest.MapFile{Data: []byte("int dummy = 2;\n")},
		}
		var stdout, stderr bytes.Buffer
		args := []string{"ccgo", "-U", "LEGACY_MODE", "-O2", "-E", "dummy.c"}
		task := ccgo.NewTask("linux", "amd64", args, &stdout, &stderr, mfs)
		if task == nil {
			fmt.Fprintln(os.Stderr, "assertion 3 failed: NewTask returned nil")
			os.Exit(1)
		}
		if err := task.Main(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: task.Main error: %v\n", err)
			os.Exit(1)
		}

		foundU := false
		for _, u := range task.U {
			if strings.Contains(u, "LEGACY_MODE") {
				foundU = true
				break
			}
		}
		if !foundU {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: undefine flag not found in task.U: %v\n", task.U)
			os.Exit(1)
		}
		if task.O != "-O2" {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected optimization flag: %q\n", task.O)
			os.Exit(1)
		}
		if !task.E {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: expected task.E to be true\n")
			os.Exit(1)
		}
	}

	// Assertion 4: NewTask executes C preprocessing on virtual filesystem source and routes output to stdout
	{
		mfs := fstest.MapFS{
			"input.c": &fstest.MapFile{
				Data: []byte("#define BUFFER_LEN 512\nint capacity = BUFFER_LEN;\n"),
			},
		}
		var stdout, stderr bytes.Buffer
		args := []string{"ccgo", "-E", "input.c"}
		task := ccgo.NewTask("linux", "amd64", args, &stdout, &stderr, mfs)
		if task == nil {
			fmt.Fprintln(os.Stderr, "assertion 4 failed: NewTask returned nil")
			os.Exit(1)
		}
		if err := task.Main(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: task.Main error: %v\n", err)
			os.Exit(1)
		}
		if !strings.Contains(stdout.String(), "int capacity = 512;") {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: output missing expanded macro: %q\n", stdout.String())
			os.Exit(1)
		}
	}

	// Assertion 5: NewTask captures errors when preprocessing invalid or missing source files
	{
		mfs := fstest.MapFS{}
		var stdout, stderr bytes.Buffer
		args := []string{"ccgo", "-E", "nonexistent.c"}
		task := ccgo.NewTask("linux", "amd64", args, &stdout, &stderr, mfs)
		if task == nil {
			fmt.Fprintln(os.Stderr, "assertion 5 failed: NewTask returned nil")
			os.Exit(1)
		}
		err := task.Main()
		if err == nil {
			fmt.Fprintln(os.Stderr, "assertion 5 failed: expected error for missing file, got nil")
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

Seeder de origem

anônimo