Пример
golang.org/x/tools v0.6.0: cover.ParseProfilesFromReader
Проверенный пример — golang golang.org/x/tools v0.6.0: cover.ParseProfilesFromReader. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:b7d0303667efdf2aed2d76f41af98f078f27b59f17a781e26487afcc75510d4f
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-16 |
Кейс
HOW- Цель
- verify golang.org/x/tools/cover.ParseProfilesFromReader in pkg:golang/golang.org/x/tools@v0.6.0
- Пакеты
- Символы
-
- golang.org/x/tools/cover.ParseProfilesFromReader
- Создан
- 2026-09-16T10:16:33Z
Контракт
- ParseProfilesFromReader parses coverage profile lines and returns Profile with correct FileName, Mode, and Blocks
- ParseProfilesFromReader parses multiple source files and returns Profiles sorted alphabetically by FileName
- ParseProfilesFromReader merges identical block ranges by summing counts in count mode and bitwise OR in set mode
- ParseProfilesFromReader returns an error when the mode header is missing or malformed
- ParseProfilesFromReader returns an error when block lines have invalid formatting
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Исходный код
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/cover.ParseProfilesFromReader in pkg:golang/golang.org/x/tools@v0.6.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/tools@v0.6.0
Demonstrate these symbols/APIs:
- golang.org/x/tools/cover.ParseProfilesFromReader
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.
{"case":{"caseId":"case:sha256:c0ded8ec8006c4b65d0486b4d268e7045de35b0ef36a7b2595496498e8c98584","contract":["ParseProfilesFromReader parses coverage profile lines and returns Profile with correct FileName, Mode, and Blocks","ParseProfilesFromReader parses multiple source files and returns Profiles sorted alphabetically by FileName","ParseProfilesFromReader merges identical block ranges by summing counts in count mode and bitwise OR in set mode","ParseProfilesFromReader returns an error when the mode header is missing or malformed","ParseProfilesFromReader returns an error when block lines have invalid formatting"],"goal":"verify golang.org/x/tools/cover.ParseProfilesFromReader in pkg:golang/golang.org/x/tools@v0.6.0","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.6.0"],"schemaVersion":1,"symbols":["golang.org/x/tools/cover.ParseProfilesFromReader"]},"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/golang.org/x/tools@v0.6.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.6.0","symbols":["golang.org/x/tools/cover.ParseProfilesFromReader"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require golang.org/x/tools v0.6.0
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/tools/cover"
)
func main() {
sampleProfile := `mode: set
example.com/sample/main.go:10.1,15.20 2 1
example.com/sample/main.go:20.1,25.20 1 0
`
profiles, err := cover.ParseProfilesFromReader(strings.NewReader(sampleProfile))
if err != nil {
fmt.Fprintf(os.Stderr, "ParseProfilesFromReader failed: %v\n", err)
os.Exit(1)
}
for _, p := range profiles {
fmt.Printf("File: %s (Mode: %s), Blocks: %d\n", p.FileName, p.Mode, len(p.Blocks))
}
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/tools/cover.ParseProfilesFromReader in pkg:golang/golang.org/x/tools@v0.6.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/tools@v0.6.0"
],
"symbols": [
"golang.org/x/tools/cover.ParseProfilesFromReader"
]
}
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/tools/cover"
)
func main() {
if err := runTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
func runTests() error {
// 1. ParseProfilesFromReader parses coverage profile lines and returns Profile with correct FileName, Mode, and Blocks
{
data := "mode: set\nexample.com/sample/pkg.go:10.1,15.20 2 1\nexample.com/sample/pkg.go:20.1,25.20 1 0\n"
profiles, err := cover.ParseProfilesFromReader(strings.NewReader(data))
if err != nil {
return fmt.Errorf("assertion 1 failed: %w", err)
}
if len(profiles) != 1 {
return fmt.Errorf("assertion 1: expected 1 profile, got %d", len(profiles))
}
p := profiles[0]
if p.FileName != "example.com/sample/pkg.go" {
return fmt.Errorf("assertion 1: expected FileName example.com/sample/pkg.go, got %s", p.FileName)
}
if p.Mode != "set" {
return fmt.Errorf("assertion 1: expected Mode set, got %s", p.Mode)
}
if len(p.Blocks) != 2 {
return fmt.Errorf("assertion 1: expected 2 blocks, got %d", len(p.Blocks))
}
b0 := p.Blocks[0]
if b0.StartLine != 10 || b0.StartCol != 1 || b0.EndLine != 15 || b0.EndCol != 20 || b0.NumStmt != 2 || b0.Count != 1 {
return fmt.Errorf("assertion 1: unexpected block 0: %+v", b0)
}
b1 := p.Blocks[1]
if b1.StartLine != 20 || b1.StartCol != 1 || b1.EndLine != 25 || b1.EndCol != 20 || b1.NumStmt != 1 || b1.Count != 0 {
return fmt.Errorf("assertion 1: unexpected block 1: %+v", b1)
}
}
// 2. ParseProfilesFromReader parses multiple source files and returns Profiles sorted alphabetically by FileName
{
data := "mode: count\nz.go:1.1,2.1 1 5\na.go:1.1,2.1 1 2\nm.go:1.1,2.1 1 1\n"
profiles, err := cover.ParseProfilesFromReader(strings.NewReader(data))
if err != nil {
return fmt.Errorf("assertion 2 failed: %w", err)
}
if len(profiles) != 3 {
return fmt.Errorf("assertion 2: expected 3 profiles, got %d", len(profiles))
}
if profiles[0].FileName != "a.go" || profiles[1].FileName != "m.go" || profiles[2].FileName != "z.go" {
return fmt.Errorf("assertion 2: expected sorted files [a.go, m.go, z.go], got [%s, %s, %s]",
profiles[0].FileName, profiles[1].FileName, profiles[2].FileName)
}
}
// 3. ParseProfilesFromReader merges identical block ranges by summing counts in count mode and bitwise OR in set mode
{
// Test count mode (summing)
countData := "mode: count\nmain.go:5.1,10.1 2 3\nmain.go:5.1,10.1 2 4\n"
countProfiles, err := cover.ParseProfilesFromReader(strings.NewReader(countData))
if err != nil {
return fmt.Errorf("assertion 3 (count mode) failed: %w", err)
}
if len(countProfiles) != 1 || len(countProfiles[0].Blocks) != 1 {
return fmt.Errorf("assertion 3: expected 1 merged block, got profiles: %d", len(countProfiles))
}
if countProfiles[0].Blocks[0].Count != 7 {
return fmt.Errorf("assertion 3: expected summed count 7, got %d", countProfiles[0].Blocks[0].Count)
}
// Test set mode (bitwise OR)
setData := "mode: set\nmain.go:5.1,10.1 2 1\nmain.go:5.1,10.1 2 1\n"
setProfiles, err := cover.ParseProfilesFromReader(strings.NewReader(setData))
if err != nil {
return fmt.Errorf("assertion 3 (set mode) failed: %w", err)
}
if len(setProfiles) != 1 || len(setProfiles[0].Blocks) != 1 {
return fmt.Errorf("assertion 3: expected 1 merged block, got profiles: %d", len(setProfiles))
}
if setProfiles[0].Blocks[0].Count != 1 {
return fmt.Errorf("assertion 3: expected bitwise OR count 1, got %d", setProfiles[0].Blocks[0].Count)
}
}
// 4. ParseProfilesFromReader returns an error when the mode header is missing or malformed
{
invalidModes := []string{
"bad header without mode\nmain.go:1.1,2.1 1 1\n",
"mode: \nmain.go:1.1,2.1 1 1\n",
"mode\nmain.go:1.1,2.1 1 1\n",
}
for _, inv := range invalidModes {
_, err := cover.ParseProfilesFromReader(strings.NewReader(inv))
if err == nil {
return fmt.Errorf("assertion 4: expected error for malformed mode header %q, got nil", inv)
}
}
}
// 5. ParseProfilesFromReader returns an error when block lines have invalid formatting
{
invalidLines := []string{
"mode: set\nnot-a-valid-coverage-line\n",
"mode: set\nmain.go:1.1,2.1 bad 1\n",
"mode: set\nmain.go:1.1,2.1 1 -5\n",
}
for _, inv := range invalidLines {
_, err := cover.ParseProfilesFromReader(strings.NewReader(inv))
if err == nil {
return fmt.Errorf("assertion 5: expected error for invalid line %q, got nil", inv)
}
}
}
return nil
}
Исходный сидер
аноним