CodeSampleX

Пример

github.com/libdns/libdns v1.1.1: RelativeName

Проверенный пример — golang github.com/libdns/libdns v1.1.1: RelativeName. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.

sha256:96d67818f9db591c0bbb1ce67bb081ad44ed77ad41bfe5fe238f010cde3f61a0

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go 1.26 go 1

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-06

Кейс

HOW
Цель
verify github.com/libdns/libdns.RelativeName in pkg:golang/github.com/libdns/libdns@v1.1.1
Пакеты
Символы
  • github.com/libdns/libdns.RelativeName
Окружение
go 1.26.6
Создан
2026-09-06T11:43:53Z

Контракт

  1. RelativeName strips the zone suffix from a fully-qualified domain name to return the relative subdomain
  2. RelativeName returns @ when the domain name matches the zone name
  3. RelativeName ignores trailing dots on both fqdn and zone
  4. RelativeName returns the fqdn without trailing dot when the domain is outside the zone
  5. RelativeName returns stripped fqdn or empty string when zone is empty or input is empty

Файлы

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.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 github.com/libdns/libdns.RelativeName in pkg:golang/github.com/libdns/libdns@v1.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/libdns/libdns@v1.1.1
Demonstrate these symbols/APIs:
  - github.com/libdns/libdns.RelativeName

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:ce670262f34284cb6d8cced9b48bd8f34bf6d7351a1c87bb49c4a08fc7db3840","contract":["RelativeName strips the zone suffix from a fully-qualified domain name to return the relative subdomain","RelativeName returns @ when the domain name matches the zone name","RelativeName ignores trailing dots on both fqdn and zone","RelativeName returns the fqdn without trailing dot when the domain is outside the zone","RelativeName returns stripped fqdn or empty string when zone is empty or input is empty"],"goal":"verify github.com/libdns/libdns.RelativeName in pkg:golang/github.com/libdns/libdns@v1.1.1","kind":"HOW","packages":["pkg:golang/github.com/libdns/libdns@v1.1.1"],"schemaVersion":1,"symbols":["github.com/libdns/libdns.RelativeName"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","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/libdns/libdns@v1.1.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/libdns/libdns@v1.1.1","symbols":["github.com/libdns/libdns.RelativeName"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/libdns/libdns v1.1.1
go.sum
github.com/libdns/libdns v1.1.1 h1:wPrHrXILoSHKWJKGd0EiAVmiJbFShguILTg9leS/P/U=
github.com/libdns/libdns v1.1.1/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
main.go
package main

import (
	"fmt"

	"github.com/libdns/libdns"
)

func main() {
	zone := "example.com."

	// RelativeName strips the zone to return relative record names
	sub := libdns.RelativeName("sub.example.com.", zone)
	fmt.Printf("Relative name for 'sub.example.com.': %s\n", sub)

	// FQDN matching zone returns "@"
	apex := libdns.RelativeName("example.com.", zone)
	fmt.Printf("Apex record name: %s\n", apex)

	// Outside zone returns the name without trailing dot
	other := libdns.RelativeName("api.otherdomain.com.", zone)
	fmt.Printf("Outside zone: %s\n", other)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/libdns/libdns.RelativeName in pkg:golang/github.com/libdns/libdns@v1.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/libdns/libdns@v1.1.1"
  ],
  "symbols": [
    "github.com/libdns/libdns.RelativeName"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/libdns/libdns"
)

func main() {
	// Assertion 1: RelativeName strips the zone suffix from a fully-qualified domain name to return the relative subdomain
	{
		got := libdns.RelativeName("sub.example.com.", "example.com.")
		want := "sub"
		if got != want {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: got %q, want %q\n", got, want)
			os.Exit(1)
		}

		gotMulti := libdns.RelativeName("foo.bar.example.com.", "example.com.")
		wantMulti := "foo.bar"
		if gotMulti != wantMulti {
			fmt.Fprintf(os.Stderr, "assertion 1 failed for multi-label: got %q, want %q\n", gotMulti, wantMulti)
			os.Exit(1)
		}

		gotNested := libdns.RelativeName("foo.bar.example.com", "bar.example.com")
		wantNested := "foo"
		if gotNested != wantNested {
			fmt.Fprintf(os.Stderr, "assertion 1 failed for nested subzone: got %q, want %q\n", gotNested, wantNested)
			os.Exit(1)
		}
	}

	// Assertion 2: RelativeName returns @ when the domain name matches the zone name
	{
		gotWithDots := libdns.RelativeName("example.com.", "example.com.")
		want := "@"
		if gotWithDots != want {
			fmt.Fprintf(os.Stderr, "assertion 2 failed with dots: got %q, want %q\n", gotWithDots, want)
			os.Exit(1)
		}

		gotWithoutDots := libdns.RelativeName("example.com", "example.com")
		if gotWithoutDots != want {
			fmt.Fprintf(os.Stderr, "assertion 2 failed without dots: got %q, want %q\n", gotWithoutDots, want)
			os.Exit(1)
		}

		gotMixed := libdns.RelativeName("example.com.", "example.com")
		if gotMixed != want {
			fmt.Fprintf(os.Stderr, "assertion 2 failed mixed: got %q, want %q\n", gotMixed, want)
			os.Exit(1)
		}
	}

	// Assertion 3: RelativeName ignores trailing dots on both fqdn and zone
	{
		got1 := libdns.RelativeName("sub.example.com", "example.com")
		got2 := libdns.RelativeName("sub.example.com.", "example.com")
		got3 := libdns.RelativeName("sub.example.com", "example.com.")
		got4 := libdns.RelativeName("sub.example.com.", "example.com.")
		want := "sub"
		if got1 != want || got2 != want || got3 != want || got4 != want {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: got [%q, %q, %q, %q], want all %q\n", got1, got2, got3, got4, want)
			os.Exit(1)
		}
	}

	// Assertion 4: RelativeName returns the fqdn without trailing dot when the domain is outside the zone
	{
		gotDiffDomain := libdns.RelativeName("example.com", "example.net")
		wantDiff := "example.com"
		if gotDiffDomain != wantDiff {
			fmt.Fprintf(os.Stderr, "assertion 4 failed for different domain: got %q, want %q\n", gotDiffDomain, wantDiff)
			os.Exit(1)
		}

		gotOther := libdns.RelativeName("sub.other.org.", "example.com.")
		wantOther := "sub.other.org"
		if gotOther != wantOther {
			fmt.Fprintf(os.Stderr, "assertion 4 failed for other fqdn: got %q, want %q\n", gotOther, wantOther)
			os.Exit(1)
		}
	}

	// Assertion 5: RelativeName returns stripped fqdn or empty string when zone is empty or input is empty
	{
		gotBothEmpty := libdns.RelativeName("", "")
		if gotBothEmpty != "" {
			fmt.Fprintf(os.Stderr, "assertion 5 failed for both empty: got %q, want empty\n", gotBothEmpty)
			os.Exit(1)
		}

		gotEmptyFQDN := libdns.RelativeName("", "example.com.")
		if gotEmptyFQDN != "" {
			fmt.Fprintf(os.Stderr, "assertion 5 failed for empty FQDN: got %q, want empty\n", gotEmptyFQDN)
			os.Exit(1)
		}

		gotEmptyZone := libdns.RelativeName("example.com.", "")
		if gotEmptyZone != "example.com" {
			fmt.Fprintf(os.Stderr, "assertion 5 failed for empty zone: got %q, want %q\n", gotEmptyZone, "example.com")
			os.Exit(1)
		}
	}

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

Исходный сидер

аноним