CodeSampleX

Exemplo

github.com/google/uuid v1.6.0: generate DCE Security UUID v2 with uuid.NewDCEPerson and uuid.NewDCEGroup

Amostra verificada para golang github.com/google/uuid v1.6.0: generate DCE Security UUID v2 with uuid.NewDCEPerson and uuid.NewDCEGroup. O contrato rodou em…

sha256:251dffaa3b57e08712a80732c5fc61847a0120da6832e0e25d9300c329f725bb

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
2
Chaves de assinatura que o compilaram
2
Ambiente declarado windows 11 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-19
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-09-07

Caso

HOW
Objetivo
generate DCE Security UUID v2 with uuid.NewDCEPerson and uuid.NewDCEGroup
Pacotes
Símbolos
  • NewDCEGroup
  • NewDCEPerson
Criado
2026-08-18T21:29:11Z

Contrato

  1. uuid.NewDCEPerson returns non-nil UUID v2 without error
  2. uuid.NewDCEPerson returns UUID with Version 2 and RFC4122 variant
  3. uuid.NewDCEPerson returns UUID with Person domain
  4. uuid.NewDCEGroup returns non-nil UUID v2 with Group domain
  5. uuid.NewDCESecurity generates UUID v2 with specified domain and ID
  6. uuid.Parse successfully parses generated UUID v2 string back to original UUID

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/main.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: generate DCE Security UUID v2 with uuid.NewDCEPerson and uuid.NewDCEGroup
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.6.0
Demonstrate these symbols/APIs:
  - NewDCEGroup
  - NewDCEPerson
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:a1a58741a2bbfcf82d9721fd7f8644c52335303c4dcf371ac08d6396bb84459a","contract":["uuid.NewDCEPerson returns non-nil UUID v2 without error","uuid.NewDCEPerson returns UUID with Version 2 and RFC4122 variant","uuid.NewDCEPerson returns UUID with Person domain","uuid.NewDCEGroup returns non-nil UUID v2 with Group domain","uuid.NewDCESecurity generates UUID v2 with specified domain and ID","uuid.Parse successfully parses generated UUID v2 string back to original UUID"],"goal":"generate DCE Security UUID v2 with uuid.NewDCEPerson and uuid.NewDCEGroup","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["NewDCEGroup","NewDCEPerson"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","os":"windows","osVersionBucket":"11","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["NewDCEGroup","NewDCEPerson"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.5

require github.com/google/uuid v1.6.0
go.sum
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=
main.go
package main

import (
	"fmt"

	"github.com/google/uuid"
)

// GeneratePersonUUID creates a DCE Security (version 2) UUID for the current person.
func GeneratePersonUUID() (uuid.UUID, error) {
	return uuid.NewDCEPerson()
}

// GenerateGroupUUID creates a DCE Security (version 2) UUID for the current group.
func GenerateGroupUUID() (uuid.UUID, error) {
	return uuid.NewDCEGroup()
}

// GenerateCustomDCEUUID creates a DCE Security (version 2) UUID with an explicit domain and ID.
func GenerateCustomDCEUUID(domain uuid.Domain, id uint32) (uuid.UUID, error) {
	return uuid.NewDCESecurity(domain, id)
}

func main() {
	personUUID, err := GeneratePersonUUID()
	if err != nil {
		fmt.Printf("Failed to generate person UUID: %v\n", err)
		return
	}
	fmt.Printf("Person UUID: %s\n", personUUID.String())
	fmt.Printf("Version: %d, Domain: %v, Variant: %v\n", personUUID.Version(), personUUID.Domain(), personUUID.Variant())

	groupUUID, err := GenerateGroupUUID()
	if err != nil {
		fmt.Printf("Failed to generate group UUID: %v\n", err)
		return
	}
	fmt.Printf("Group UUID: %s\n", groupUUID.String())
	fmt.Printf("Version: %d, Domain: %v, Variant: %v\n", groupUUID.Version(), groupUUID.Domain(), groupUUID.Variant())

	customUUID, err := GenerateCustomDCEUUID(uuid.Person, 1001)
	if err != nil {
		fmt.Printf("Failed to generate custom DCE UUID: %v\n", err)
		return
	}
	fmt.Printf("Custom DCE UUID: %s (ID: %d)\n", customUUID.String(), customUUID.ID())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "generate DCE Security UUID v2 with uuid.NewDCEPerson and uuid.NewDCEGroup",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "symbols": [
    "NewDCEGroup",
    "NewDCEPerson"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/main.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/uuid"
)

func assertTrue(name string, condition bool) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: expected true, got false\n", name)
		os.Exit(1)
	}
}

func main() {
	// 1. uuid.NewDCEPerson returns non-nil UUID v2 without error
	personUUID, err := uuid.NewDCEPerson()
	assertTrue("uuid.NewDCEPerson returns without error", err == nil)
	assertTrue("uuid.NewDCEPerson returns non-nil UUID", personUUID != uuid.Nil)
	assertTrue("uuid.NewDCEPerson byte length is 16", len(personUUID) == 16)

	// 2. uuid.NewDCEPerson returns UUID with Version 2 and RFC4122 variant
	assertTrue("uuid.NewDCEPerson version is 2", personUUID.Version() == 2)
	assertTrue("uuid.NewDCEPerson variant is RFC4122", personUUID.Variant() == uuid.RFC4122)

	// 3. uuid.NewDCEPerson returns UUID with Person domain
	assertTrue("uuid.NewDCEPerson domain is Person", personUUID.Domain() == uuid.Person)

	// 4. uuid.NewDCEGroup returns non-nil UUID v2 with Group domain
	groupUUID, err := uuid.NewDCEGroup()
	assertTrue("uuid.NewDCEGroup returns without error", err == nil)
	assertTrue("uuid.NewDCEGroup returns non-nil UUID", groupUUID != uuid.Nil)
	assertTrue("uuid.NewDCEGroup version is 2", groupUUID.Version() == 2)
	assertTrue("uuid.NewDCEGroup domain is Group", groupUUID.Domain() == uuid.Group)

	// 5. uuid.NewDCESecurity generates UUID v2 with specified domain and ID
	const customID uint32 = 42001
	customUUID, err := uuid.NewDCESecurity(uuid.Person, customID)
	assertTrue("uuid.NewDCESecurity returns without error", err == nil)
	assertTrue("uuid.NewDCESecurity version is 2", customUUID.Version() == 2)
	assertTrue("uuid.NewDCESecurity domain matches", customUUID.Domain() == uuid.Person)
	assertTrue("uuid.NewDCESecurity ID matches", customUUID.ID() == customID)

	// 6. uuid.Parse successfully parses generated UUID v2 string back to original UUID
	parsedPerson, err := uuid.Parse(personUUID.String())
	assertTrue("uuid.Parse parses person UUID without error", err == nil)
	assertTrue("parsed person UUID equals original", parsedPerson == personUUID)
	assertTrue("parsed person UUID bytes match", bytes.Equal(parsedPerson[:], personUUID[:]))
	assertTrue("parsed person UUID preserves version 2", parsedPerson.Version() == 2)
	assertTrue("parsed person UUID preserves Person domain", parsedPerson.Domain() == uuid.Person)

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

Seeder de origem

anônimo