CodeSampleX

Sample

github.com/google/cel-go v0.24.1: cel.NewEnv, cel.Program, cel.Variable

Verified sample for golang github.com/google/cel-go v0.24.1: cel.NewEnv, cel.Program, cel.Variable. The contract ran on go 1.26 · linux alpine/x64 · docker…

sha256:d0d55506dac6e2f53457d0bfc52909bcca5bcb60afed963d17b3a2a38d257e2c

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

Case

HOW
Goal
verify pkg:golang/github.com/google/cel-go@v0.24.1
Packages
Symbols
  • cel.NewEnv
  • cel.Program
  • cel.Variable
Created
2026-08-23T17:29:05Z

Contract

  1. cel.NewEnv creates environment with declared string and int variables
  2. env.Compile parses and checks boolean expression
  3. env.Program creates executable program
  4. prg.Eval evaluates expression against input variables returning expected boolean result
  5. prg.Eval returns false when condition is not satisfied

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • 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/google/cel-go@v0.24.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/cel-go@v0.24.1
Demonstrate these symbols/APIs:
  - cel.NewEnv
  - cel.Program
  - cel.Variable
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:4fdc37a35e16d81991c2caea90e43929f7990fd164bf7ac37662707dd8592220","contract":["cel.NewEnv creates environment with declared string and int variables","env.Compile parses and checks boolean expression","env.Program creates executable program","prg.Eval evaluates expression against input variables returning expected boolean result","prg.Eval returns false when condition is not satisfied"],"goal":"verify pkg:golang/github.com/google/cel-go@v0.24.1","kind":"HOW","packages":["pkg:golang/github.com/google/cel-go@v0.24.1"],"schemaVersion":1,"symbols":["cel.NewEnv","cel.Program","cel.Variable"]},"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/google/cel-go@v0.24.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/cel-go@v0.24.1","symbols":["cel.NewEnv","cel.Program","cel.Variable"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/google/cel-go v0.24.1

require (
	cel.dev/expr v0.19.1 // indirect
	github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
	github.com/stoewer/go-strcase v1.2.0 // indirect
	golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
	google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
	google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
	google.golang.org/protobuf v1.34.2 // indirect
)
go.sum
cel.dev/expr v0.19.1 h1:NciYrtDRIR0lNCnH1LFJegdjspNx9fI59O7TWcua/W4=
cel.dev/expr v0.19.1/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/cel-go v0.24.1 h1:jsBCtxG8mM5wiUJDSGUqU0K7Mtr3w7Eyv00rw4DiZxI=
github.com/google/cel-go v0.24.1/go.mod h1:Hdf9TqOaTNSFQA1ybQaRqATVoK7m/zcf7IMhGXP5zI8=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw=
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 h1:2035KHhUv+EpyB+hWgJnaWKJOdX1E95w2S8Rr4uWKTs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sample.go
package sample

import (
	"fmt"

	"github.com/google/cel-go/cel"
)

// EvaluateRule creates a CEL environment with string and int variables,
// compiles the given expression, and evaluates it against the provided input.
func EvaluateRule(expression string, name string, age int64) (bool, error) {
	env, err := cel.NewEnv(
		cel.Variable("name", cel.StringType),
		cel.Variable("age", cel.IntType),
	)
	if err != nil {
		return false, fmt.Errorf("failed to create CEL env: %w", err)
	}

	ast, issues := env.Compile(expression)
	if issues != nil && issues.Err() != nil {
		return false, fmt.Errorf("failed to compile CEL expression: %w", issues.Err())
	}

	prg, err := env.Program(ast)
	if err != nil {
		return false, fmt.Errorf("failed to create CEL program: %w", err)
	}

	out, _, err := prg.Eval(map[string]any{
		"name": name,
		"age":  age,
	})
	if err != nil {
		return false, fmt.Errorf("failed to evaluate CEL expression: %w", err)
	}

	val, ok := out.Value().(bool)
	if !ok {
		return false, fmt.Errorf("expression did not evaluate to boolean: %v", out.Value())
	}

	return val, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/google/cel-go@v0.24.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/cel-go@v0.24.1"
  ],
  "symbols": [
    "cel.NewEnv",
    "cel.Program",
    "cel.Variable"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/google/cel-go/cel"
	"sample"
)

func main() {
	// Assertion 1: cel.NewEnv creates environment with declared variables
	env, err := cel.NewEnv(
		cel.Variable("name", cel.StringType),
		cel.Variable("age", cel.IntType),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "cel.NewEnv failed: %v\n", err)
		os.Exit(1)
	}

	// Assertion 2: env.Compile parses and type-checks CEL expressions
	ast, iss := env.Compile(`name.startsWith("Alice") && age >= 18`)
	if iss != nil && iss.Err() != nil {
		fmt.Fprintf(os.Stderr, "env.Compile failed: %v\n", iss.Err())
		os.Exit(1)
	}

	// Assertion 3: env.Program constructs an executable CEL program
	prg, err := env.Program(ast)
	if err != nil {
		fmt.Fprintf(os.Stderr, "env.Program failed: %v\n", err)
		os.Exit(1)
	}

	// Assertion 4: prg.Eval evaluates expression against variable inputs returning boolean result
	out, _, err := prg.Eval(map[string]any{
		"name": "Alice Smith",
		"age":  int64(25),
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "prg.Eval failed: %v\n", err)
		os.Exit(1)
	}
	if val, ok := out.Value().(bool); !ok || !val {
		fmt.Fprintf(os.Stderr, "expected true, got %v\n", out.Value())
		os.Exit(1)
	}

	// Assertion 5: prg.Eval returns false when expression conditions are not satisfied
	outFalse, _, err := prg.Eval(map[string]any{
		"name": "Bob",
		"age":  int64(16),
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "prg.Eval failed: %v\n", err)
		os.Exit(1)
	}
	if val, ok := outFalse.Value().(bool); !ok || val {
		fmt.Fprintf(os.Stderr, "expected false, got %v\n", outFalse.Value())
		os.Exit(1)
	}

	// Helper verification
	res, err := sample.EvaluateRule(`name.startsWith("Alice") && age >= 18`, "Alice Cooper", 30)
	if err != nil {
		fmt.Fprintf(os.Stderr, "sample.EvaluateRule failed: %v\n", err)
		os.Exit(1)
	}
	if !res {
		fmt.Fprintf(os.Stderr, "expected EvaluateRule to return true\n")
		os.Exit(1)
	}

	resFalse, err := sample.EvaluateRule(`name.startsWith("Alice") && age >= 18`, "Alice", 10)
	if err != nil {
		fmt.Fprintf(os.Stderr, "sample.EvaluateRule failed: %v\n", err)
		os.Exit(1)
	}
	if resFalse {
		fmt.Fprintf(os.Stderr, "expected EvaluateRule to return false\n")
		os.Exit(1)
	}

	fmt.Println("All cel-go contract assertions passed.")
}

Origin Seeder

anonymous