サンプル
golang.org/x/tools v0.1.1: txtar.Format
検証済みサンプル — golang golang.org/x/tools v0.1.1: txtar.Format. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: txtar.Format serializes an Archive…
sha256:70abba3cb3fb8f23c98aca26f2153bb3b7f14065d96983dcf0e8922bc9fa686f
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 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-10-13 |
ケース
HOW- ゴール
- verify golang.org/x/tools/txtar.Format in pkg:golang/golang.org/x/tools@v0.1.1
- シンボル
-
- golang.org/x/tools/txtar.Format
- 環境
- go 1.26.6
- 作成日
- 2026-10-13T23:44:39Z
コントラクト
- txtar.Format serializes an Archive containing comment and files into txtar format bytes
- txtar.Format delimits files with '-- filename --' marker lines
- txtar.Format output round-trips identically with txtar.Parse
- txtar.Format appends trailing newline to files without trailing newlines
ファイル
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
ソース
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 golang.org/x/tools/txtar.Format in pkg:golang/golang.org/x/tools@v0.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/tools@v0.1.1
Demonstrate these symbols/APIs:
- golang.org/x/tools/txtar.Format
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.
package sample
import (
"bytes"
"strings"
"testing"
"golang.org/x/tools/txtar"
)
func TestContractTxtarFormat(t *testing.T) {
// 1. Verify txtar.Format serializes an Archive containing comment and files into txtar format bytes
archive := &txtar.Archive{
Comment: []byte("This is a sample archive comment.\n"),
Files: []txtar.File{
{
Name: "file1.txt",
Data: []byte("hello world\n"),
},
{
Name: "dir/file2.txt",
Data: []byte("line 1\nline 2\n"),
},
},
}
formatted := txtar.Format(archive)
if len(formatted) == 0 {
t.Fatalf("expected formatted output to be non-empty")
}
str := string(formatted)
if !strings.HasPrefix(str, "This is a sample archive comment.") {
t.Errorf("expected comment at start, got %q", str)
}
// 2. Verify txtar.Format delimits files with '-- filename --' marker lines
if !strings.Contains(str, "-- file1.txt --\nhello world\n") {
t.Errorf("expected file1.txt content with delimiter, got %q", str)
}
if !strings.Contains(str, "-- dir/file2.txt --\nline 1\nline 2\n") {
t.Errorf("expected dir/file2.txt content with delimiter, got %q", str)
}
// 3. Verify txtar.Format output round-trips identically with txtar.Parse
parsed := txtar.Parse(formatted)
if !bytes.Equal(bytes.TrimSpace(parsed.Comment), bytes.TrimSpace(archive.Comment)) {
t.Errorf("roundtrip comment mismatch: got %q, want %q", parsed.Comment, archive.Comment)
}
if len(parsed.Files) != len(archive.Files) {
t.Fatalf("roundtrip files length mismatch: got %d, want %d", len(parsed.Files), len(archive.Files))
}
for i, f := range parsed.Files {
if f.Name != archive.Files[i].Name {
t.Errorf("file %d name mismatch: got %s, want %s", i, f.Name, archive.Files[i].Name)
}
if !bytes.Equal(bytes.TrimSpace(f.Data), bytes.TrimSpace(archive.Files[i].Data)) {
t.Errorf("file %d data mismatch: got %q, want %q", i, f.Data, archive.Files[i].Data)
}
}
// 4. Verify txtar.Format appends trailing newline to files without trailing newlines
noNewlineArchive := &txtar.Archive{
Files: []txtar.File{
{
Name: "test.txt",
Data: []byte("no newline"),
},
},
}
noNewlineFormatted := txtar.Format(noNewlineArchive)
if !strings.HasSuffix(string(noNewlineFormatted), "no newline\n") {
t.Errorf("expected trailing newline appended, got %q", string(noNewlineFormatted))
}
}
{"case":{"caseId":"case:sha256:e40ed68e181e4adf88930c51b57363b8fc49f0d45588e424e430c7be1f74e14b","contract":["txtar.Format serializes an Archive containing comment and files into txtar format bytes","txtar.Format delimits files with '-- filename --' marker lines","txtar.Format output round-trips identically with txtar.Parse","txtar.Format appends trailing newline to files without trailing newlines"],"goal":"verify golang.org/x/tools/txtar.Format in pkg:golang/golang.org/x/tools@v0.1.1","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.1.1"],"schemaVersion":1,"symbols":["golang.org/x/tools/txtar.Format"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","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/golang.org/x/tools@v0.1.1"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.1.1","symbols":["golang.org/x/tools/txtar.Format"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require golang.org/x/tools v0.1.1
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
package sample
import (
"golang.org/x/tools/txtar"
)
// FormatArchive serializes a txtar.Archive into txtar byte format using txtar.Format.
func FormatArchive(comment string, files map[string]string) []byte {
var archiveFiles []txtar.File
for name, data := range files {
archiveFiles = append(archiveFiles, txtar.File{
Name: name,
Data: []byte(data),
})
}
a := &txtar.Archive{
Comment: []byte(comment),
Files: archiveFiles,
}
return txtar.Format(a)
}
// ParseArchive parses txtar formatted bytes into a txtar.Archive using txtar.Parse.
func ParseArchive(data []byte) *txtar.Archive {
return txtar.Parse(data)
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/tools/txtar.Format in pkg:golang/golang.org/x/tools@v0.1.1",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/tools@v0.1.1"
],
"symbols": [
"golang.org/x/tools/txtar.Format"
]
}
オリジンシーダー
匿名