CodeSampleX

示例

github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572: FuncMap, TxtFuncMap, HtmlFuncMap

已验证示例 — golang github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572: FuncMap, TxtFuncMap, HtmlFuncMap. contract 在 go 1.26 · linux alpine/x64 …

sha256:e6ed7a878958870a378a3482cae76d37ad5df574f3c370ed505c9ee8783affe0

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
1
声明的环境 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572
包
符号
  • github.com/go-task/slim-sprig.FuncMap
  • github.com/go-task/slim-sprig.TxtFuncMap
  • github.com/go-task/slim-sprig.HtmlFuncMap
  • github.com/go-task/slim-sprig.GenericFuncMap
  • github.com/go-task/slim-sprig.HermeticTxtFuncMap
  • github.com/go-task/slim-sprig.HermeticHtmlFuncMap
环境
go 1.26.6
创建时间
2026-08-23T17:27:31Z

契约

  1. sprig.FuncMap produces template.FuncMap containing string, math, collection, and serialization helper functions
  2. sprig.TxtFuncMap and sprig.HtmlFuncMap produce helper maps for text/template and html/template
  3. sprig.GenericFuncMap returns map of sprig helper functions without html/template or text/template dependencies
  4. sprig.HermeticTxtFuncMap and sprig.HermeticHtmlFuncMap provide deterministic helper maps excluding environment and clock functions
  5. template execution uses sprig helper functions for string trimming, uppercase conversion, defaults, lists, dicts, and base64 encoding

文件

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

下载源代码构件 (tar.gz)

源代码

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/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572
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:2103b1715034cde2072c2517e2ac980babc8221915c6022621e1643f98ebbba2","contract":["sprig.FuncMap produces template.FuncMap containing string, math, collection, and serialization helper functions","sprig.TxtFuncMap and sprig.HtmlFuncMap produce helper maps for text/template and html/template","sprig.GenericFuncMap returns map of sprig helper functions without html/template or text/template dependencies","sprig.HermeticTxtFuncMap and sprig.HermeticHtmlFuncMap provide deterministic helper maps excluding environment and clock functions","template execution uses sprig helper functions for string trimming, uppercase conversion, defaults, lists, dicts, and base64 encoding"],"goal":"verify pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572","kind":"HOW","packages":["pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572"],"schemaVersion":1,"symbols":["github.com/go-task/slim-sprig.FuncMap","github.com/go-task/slim-sprig.TxtFuncMap","github.com/go-task/slim-sprig.HtmlFuncMap","github.com/go-task/slim-sprig.GenericFuncMap","github.com/go-task/slim-sprig.HermeticTxtFuncMap","github.com/go-task/slim-sprig.HermeticHtmlFuncMap"]},"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/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572","symbols":["github.com/go-task/slim-sprig.FuncMap","github.com/go-task/slim-sprig.TxtFuncMap","github.com/go-task/slim-sprig.HtmlFuncMap","github.com/go-task/slim-sprig.GenericFuncMap","github.com/go-task/slim-sprig.HermeticTxtFuncMap","github.com/go-task/slim-sprig.HermeticHtmlFuncMap"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
go.sum
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/go-task/slim-sprig@v0.0.0-20230315185526-52ccab3ef572"
  ],
  "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 (
	"bytes"
	"fmt"
	htemplate "html/template"
	"os"
	"strings"
	ttemplate "text/template"

	sprig "github.com/go-task/slim-sprig"
)

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

func runTests() error {
	// 1. Test sprig.FuncMap returns template.FuncMap containing core helper functions
	fm := sprig.FuncMap()
	if fm == nil || len(fm) == 0 {
		return fmt.Errorf("sprig.FuncMap() returned empty or nil map")
	}

	requiredKeys := []string{
		"trim", "upper", "lower", "default", "list", "dict",
		"join", "split", "toJson", "fromJson", "add", "mul",
		"coalesce", "hasKey", "keys", "values", "b64enc", "b64dec", "sha256sum",
	}
	for _, key := range requiredKeys {
		if _, ok := fm[key]; !ok {
			return fmt.Errorf("sprig.FuncMap missing required key %q", key)
		}
	}

	// 2. Test sprig.TxtFuncMap and sprig.HtmlFuncMap provide template helper maps
	txtFm := sprig.TxtFuncMap()
	if txtFm == nil || len(txtFm) == 0 {
		return fmt.Errorf("sprig.TxtFuncMap() returned empty or nil map")
	}
	htmlFm := sprig.HtmlFuncMap()
	if htmlFm == nil || len(htmlFm) == 0 {
		return fmt.Errorf("sprig.HtmlFuncMap() returned empty or nil map")
	}

	// 3. Test sprig.GenericFuncMap returns map of sprig helper functions without template dependencies
	gfm := sprig.GenericFuncMap()
	if gfm == nil || len(gfm) == 0 {
		return fmt.Errorf("sprig.GenericFuncMap() returned empty or nil map")
	}
	for _, key := range requiredKeys {
		if _, ok := gfm[key]; !ok {
			return fmt.Errorf("sprig.GenericFuncMap missing required key %q", key)
		}
	}

	// 4. Test sprig.HermeticTxtFuncMap and sprig.HermeticHtmlFuncMap provide deterministic helper maps
	hermeticTxt := sprig.HermeticTxtFuncMap()
	if hermeticTxt == nil || len(hermeticTxt) == 0 {
		return fmt.Errorf("sprig.HermeticTxtFuncMap() returned empty or nil map")
	}
	hermeticHtml := sprig.HermeticHtmlFuncMap()
	if hermeticHtml == nil || len(hermeticHtml) == 0 {
		return fmt.Errorf("sprig.HermeticHtmlFuncMap() returned empty or nil map")
	}
	if _, ok := hermeticTxt["env"]; ok {
		return fmt.Errorf("sprig.HermeticTxtFuncMap should not contain 'env'")
	}
	if _, ok := hermeticTxt["expandenv"]; ok {
		return fmt.Errorf("sprig.HermeticTxtFuncMap should not contain 'expandenv'")
	}

	// 5. Test text/template execution using sprig helper functions
	tmplText := `{{ "  hello world  " | trim | upper }}|{{ "" | default "fallback" }}|{{ list "a" "b" "c" | join "-" }}|{{ add 10 5 }}|{{ mul 4 3 }}|{{ "hello" | b64enc }}|{{ "aGVsbG8=" | b64dec }}|{{ "test" | sha256sum }}`
	tmpl, err := ttemplate.New("test").Funcs(fm).Parse(tmplText)
	if err != nil {
		return fmt.Errorf("text/template parse failed: %w", err)
	}

	var buf bytes.Buffer
	if err := tmpl.Execute(&buf, nil); err != nil {
		return fmt.Errorf("text/template execute failed: %w", err)
	}

	expectedParts := []string{
		"HELLO WORLD",
		"fallback",
		"a-b-c",
		"15",
		"12",
		"aGVsbG8=",
		"hello",
		"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
	}
	gotOutput := buf.String()
	expectedOutput := strings.Join(expectedParts, "|")
	if gotOutput != expectedOutput {
		return fmt.Errorf("template output mismatch:\n got:  %q\n want: %q", gotOutput, expectedOutput)
	}

	// 6. Test dict, keys, hasKey, and JSON serialization in template
	dictTmplText := `{{ $d := dict "name" "sample" "count" 42 }}{{ hasKey $d "name" }}|{{ get $d "count" }}|{{ $d | toJson }}`
	dictTmpl, err := ttemplate.New("dictTest").Funcs(fm).Parse(dictTmplText)
	if err != nil {
		return fmt.Errorf("dict template parse failed: %w", err)
	}

	var dictBuf bytes.Buffer
	if err := dictTmpl.Execute(&dictBuf, nil); err != nil {
		return fmt.Errorf("dict template execute failed: %w", err)
	}

	dictOutput := dictBuf.String()
	if !strings.HasPrefix(dictOutput, "true|42|") {
		return fmt.Errorf("dict template output unexpected: %q", dictOutput)
	}

	// 7. Test html/template execution with HtmlFuncMap
	htmlTmplText := `<b>{{ .Name | upper | html }}</b>`
	htmlTmpl, err := htemplate.New("htmlTest").Funcs(htmlFm).Parse(htmlTmplText)
	if err != nil {
		return fmt.Errorf("html/template parse failed: %w", err)
	}

	var htmlBuf bytes.Buffer
	if err := htmlTmpl.Execute(&htmlBuf, map[string]string{"Name": "<safe & sound>"}); err != nil {
		return fmt.Errorf("html/template execute failed: %w", err)
	}
	expectedHTML := `<b>&lt;SAFE &amp; SOUND&gt;</b>`
	if htmlBuf.String() != expectedHTML {
		return fmt.Errorf("html/template output mismatch: got %q, want %q", htmlBuf.String(), expectedHTML)
	}

	// 8. Test direct generic function execution from GenericFuncMap
	upperFn, ok := gfm["upper"].(func(string) string)
	if !ok {
		return fmt.Errorf("gfm['upper'] is not func(string) string (got %T)", gfm["upper"])
	}
	if got := upperFn("sprig"); got != "SPRIG" {
		return fmt.Errorf("gfm['upper']('sprig') = %q, want 'SPRIG'", got)
	}

	b64encFn, ok := gfm["b64enc"].(func(string) string)
	if !ok {
		return fmt.Errorf("gfm['b64enc'] is not func(string) string (got %T)", gfm["b64enc"])
	}
	if got := b64encFn("data"); got != "ZGF0YQ==" {
		return fmt.Errorf("gfm['b64enc']('data') = %q, want 'ZGF0YQ=='", got)
	}

	return nil
}

原始种子者

匿名