CodeSampleX

示例

google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7: serviceconfig.Service

已验证示例 — golang google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7: serviceconfig.Service. contract 在 go 1.26 · linux debian/x64 …

sha256:e8acf53eecd350d0aed42ea2723a806861d7fdc8478230ab3a508c34bee2c9fd

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

执行证据

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

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

验证运行环境

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

案例

HOW
目标
verify google.golang.org/genproto/googleapis/api/serviceconfig.Service in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7
包
符号
  • google.golang.org/genproto/googleapis/api/serviceconfig.Service
创建时间
2026-09-01T11:32:24Z

契约

  1. serviceconfig.Service can be instantiated with Name, Title, Id, and ProducerProjectId
  2. Service.GetName returns the configured service name
  3. Service.GetTitle returns the configured service title
  4. Service.GetId returns the configured service ID
  5. Service.GetProducerProjectId returns the configured producer project ID
  6. NewService helper creates a configured serviceconfig.Service
  7. GetServiceName, GetServiceTitle, GetServiceId, and GetProducerProjectId return the respective field values
  8. GetServiceName returns empty string on nil service

文件

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • service.go
  • 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 google.golang.org/genproto/googleapis/api/serviceconfig.Service in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/api/serviceconfig.Service

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:c975b0f430bdffcfc2e2e41ca03289c26283265e4216cb3acd857d822ec40008","contract":["serviceconfig.Service can be instantiated with Name, Title, Id, and ProducerProjectId","Service.GetName returns the configured service name","Service.GetTitle returns the configured service title","Service.GetId returns the configured service ID","Service.GetProducerProjectId returns the configured producer project ID","NewService helper creates a configured serviceconfig.Service","GetServiceName, GetServiceTitle, GetServiceId, and GetProducerProjectId return the respective field values","GetServiceName returns empty string on nil service"],"goal":"verify google.golang.org/genproto/googleapis/api/serviceconfig.Service in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/api/serviceconfig.Service"]},"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/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7","symbols":["google.golang.org/genproto/googleapis/api/serviceconfig.Service"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7

require google.golang.org/protobuf v1.34.2 // indirect
go.sum
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
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/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
service.go
package sample

import (
	"google.golang.org/genproto/googleapis/api/serviceconfig"
)

// NewService creates a new serviceconfig.Service instance with provided metadata.
func NewService(name, title, id, producerProjectId string) *serviceconfig.Service {
	return &serviceconfig.Service{
		Name:              name,
		Title:             title,
		Id:                id,
		ProducerProjectId: producerProjectId,
	}
}

// GetServiceName returns the name of the service using GetName().
func GetServiceName(svc *serviceconfig.Service) string {
	if svc == nil {
		return ""
	}
	return svc.GetName()
}

// GetServiceTitle returns the title of the service using GetTitle().
func GetServiceTitle(svc *serviceconfig.Service) string {
	if svc == nil {
		return ""
	}
	return svc.GetTitle()
}

// GetServiceId returns the ID of the service using GetId().
func GetServiceId(svc *serviceconfig.Service) string {
	if svc == nil {
		return ""
	}
	return svc.GetId()
}

// GetProducerProjectId returns the producer project ID of the service using GetProducerProjectId().
func GetProducerProjectId(svc *serviceconfig.Service) string {
	if svc == nil {
		return ""
	}
	return svc.GetProducerProjectId()
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/api/serviceconfig.Service in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20240826202546-f6391c0de4c7"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/api/serviceconfig.Service"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/api/serviceconfig"
	"sample"
)

func main() {
	// Assertion 1: instantiate serviceconfig.Service directly
	svc := &serviceconfig.Service{
		Name:              "endpoints.example.com",
		Title:             "Example API",
		Id:                "2024-08-26r0",
		ProducerProjectId: "example-project-123",
	}

	// Assertion 2: GetName returns the service name
	if got := svc.GetName(); got != "endpoints.example.com" {
		fmt.Fprintf(os.Stderr, "expected GetName() to return %q, got %q\n", "endpoints.example.com", got)
		os.Exit(1)
	}

	// Assertion 3: GetTitle returns the service title
	if got := svc.GetTitle(); got != "Example API" {
		fmt.Fprintf(os.Stderr, "expected GetTitle() to return %q, got %q\n", "Example API", got)
		os.Exit(1)
	}

	// Assertion 4: GetId returns the service ID
	if got := svc.GetId(); got != "2024-08-26r0" {
		fmt.Fprintf(os.Stderr, "expected GetId() to return %q, got %q\n", "2024-08-26r0", got)
		os.Exit(1)
	}

	// Assertion 5: GetProducerProjectId returns the producer project ID
	if got := svc.GetProducerProjectId(); got != "example-project-123" {
		fmt.Fprintf(os.Stderr, "expected GetProducerProjectId() to return %q, got %q\n", "example-project-123", got)
		os.Exit(1)
	}

	// Assertion 6: Helper NewService initializes fields properly
	helperSvc := sample.NewService("endpoints.example.com", "Example API", "2024-08-26r0", "example-project-123")
	if helperSvc == nil {
		fmt.Fprintf(os.Stderr, "expected NewService to return non-nil\n")
		os.Exit(1)
	}

	// Assertion 7: Helper functions extract correct field values
	if got := sample.GetServiceName(helperSvc); got != "endpoints.example.com" {
		fmt.Fprintf(os.Stderr, "expected GetServiceName() to return %q, got %q\n", "endpoints.example.com", got)
		os.Exit(1)
	}
	if got := sample.GetServiceTitle(helperSvc); got != "Example API" {
		fmt.Fprintf(os.Stderr, "expected GetServiceTitle() to return %q, got %q\n", "Example API", got)
		os.Exit(1)
	}
	if got := sample.GetServiceId(helperSvc); got != "2024-08-26r0" {
		fmt.Fprintf(os.Stderr, "expected GetServiceId() to return %q, got %q\n", "2024-08-26r0", got)
		os.Exit(1)
	}
	if got := sample.GetProducerProjectId(helperSvc); got != "example-project-123" {
		fmt.Fprintf(os.Stderr, "expected GetProducerProjectId() to return %q, got %q\n", "example-project-123", got)
		os.Exit(1)
	}

	// Assertion 8: Nil safety in helper functions
	if got := sample.GetServiceName(nil); got != "" {
		fmt.Fprintf(os.Stderr, "expected GetServiceName(nil) to return empty string, got %q\n", got)
		os.Exit(1)
	}

	fmt.Println("All google.golang.org/genproto/googleapis/api/serviceconfig.Service contract assertions passed.")
}

原始种子者

匿名