Ejemplo
github.com/Microsoft/go-winio v0.6.2: DialPipeContext
Muestra verificada para golang github.com/Microsoft/go-winio v0.6.2: DialPipeContext. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y pasó.
sha256:7bc5d81daba730baf8cf8f8694d57dbcbb07fcb26a13ae038f6f658d545c15b3
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 2
- Claves de firma que lo compilaron
- 2
Entorno declarado
windows 11 x64 go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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
- verify github.com/Microsoft/go-winio.DialPipeContext in pkg:golang/github.com/Microsoft/go-winio@v0.6.2
- Paquetes
- Símbolos
-
- github.com/Microsoft/go-winio.DialPipeContext
- Creado
- 2026-08-18T17:51:10Z
Contrato
- DialPipeContext connects to an active Windows named pipe within the specified timeout context
- DialPipeContext immediately returns an error when the provided context is canceled
Archivos
- PROMPT.md
- client_other.go
- client_windows.go
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract_other.go
- test/contract_windows.go
Código fuente
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/Microsoft/go-winio.DialPipeContext in pkg:golang/github.com/Microsoft/go-winio@v0.6.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/Microsoft/go-winio@v0.6.2
Demonstrate these symbols/APIs:
- github.com/Microsoft/go-winio.DialPipeContext
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.
//go:build !windows
package winioexample
import (
"context"
"errors"
"net"
)
var ErrWindowsOnly = errors.New("winio named pipes are only supported on Windows")
// DialNamedPipe is a stub for non-Windows platforms.
func DialNamedPipe(ctx context.Context, pipePath string) (net.Conn, error) {
return nil, ErrWindowsOnly
}
// DialAndEcho is a stub for non-Windows platforms.
func DialAndEcho(ctx context.Context, pipePath string, message []byte) ([]byte, error) {
return nil, ErrWindowsOnly
}
//go:build windows
package winioexample
import (
"context"
"fmt"
"io"
"net"
"github.com/Microsoft/go-winio"
)
// DialNamedPipe establishes a connection to a Windows named pipe with context cancellation support.
func DialNamedPipe(ctx context.Context, pipePath string) (net.Conn, error) {
return winio.DialPipeContext(ctx, pipePath)
}
// DialAndEcho connects to a named pipe at pipePath using DialPipeContext,
// writes message to it, and reads back the echoed response.
func DialAndEcho(ctx context.Context, pipePath string, message []byte) ([]byte, error) {
conn, err := winio.DialPipeContext(ctx, pipePath)
if err != nil {
return nil, fmt.Errorf("dial pipe failed: %w", err)
}
defer conn.Close()
if _, err := conn.Write(message); err != nil {
return nil, fmt.Errorf("write to pipe failed: %w", err)
}
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil && err != io.EOF {
return nil, fmt.Errorf("read from pipe failed: %w", err)
}
return buf[:n], nil
}
{"case":{"caseId":"case:sha256:9093f4482e781939df4e9eedfe2a79cdd7a944f18443c84cf4bee2ae80b11e61","contract":["DialPipeContext connects to an active Windows named pipe within the specified timeout context","DialPipeContext immediately returns an error when the provided context is canceled"],"goal":"verify github.com/Microsoft/go-winio.DialPipeContext in pkg:golang/github.com/Microsoft/go-winio@v0.6.2","kind":"HOW","packages":["pkg:golang/github.com/Microsoft/go-winio@v0.6.2"],"schemaVersion":1,"symbols":["github.com/Microsoft/go-winio.DialPipeContext"]},"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/Microsoft/go-winio@v0.6.2"],"schemaVersion":1,"symbols":["github.com/Microsoft/go-winio.DialPipeContext"],"verifierAdapter":"golang@1"}
module example.com/winio-sample
go 1.21
require github.com/Microsoft/go-winio v0.6.2
require golang.org/x/sys v0.10.0 // indirect
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
{
"schemaVersion": 1,
"goal": "verify github.com/Microsoft/go-winio.DialPipeContext in pkg:golang/github.com/Microsoft/go-winio@v0.6.2",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/Microsoft/go-winio@v0.6.2"
],
"symbols": [
"github.com/Microsoft/go-winio.DialPipeContext"
]
}
//go:build !windows
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
cmd := exec.Command("go", "build", "./...")
cmd.Env = append(os.Environ(), "GOOS=windows")
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "GOOS=windows build failed: %v\n%s\n", err, string(out))
os.Exit(1)
}
fmt.Println("PASS: Windows named pipe implementation cross-compiled successfully")
}
//go:build windows
package main
import (
"context"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
"time"
winioexample "example.com/winio-sample"
"github.com/Microsoft/go-winio"
)
func randomPipePath() string {
b := make([]byte, 8)
_, _ = rand.Read(b)
return fmt.Sprintf(`\\.\pipe\csx-test-pipe-%s`, hex.EncodeToString(b))
}
func main() {
pipePath := randomPipePath()
// 1. Start a named pipe listener
l, err := winio.ListenPipe(pipePath, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to listen on pipe: %v\n", err)
os.Exit(1)
}
defer l.Close()
// Server goroutine: echo incoming message
serverErrCh := make(chan error, 1)
go func() {
conn, err := l.Accept()
if err != nil {
serverErrCh <- fmt.Errorf("accept error: %w", err)
return
}
defer conn.Close()
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil && err != io.EOF {
serverErrCh <- fmt.Errorf("server read error: %w", err)
return
}
if _, err := conn.Write(buf[:n]); err != nil {
serverErrCh <- fmt.Errorf("server write error: %w", err)
return
}
serverErrCh <- nil
}()
// 2. Test DialPipeContext connection and round-trip
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
payload := []byte("hello winio named pipe")
resp, err := winioexample.DialAndEcho(ctx, pipePath, payload)
if err != nil {
fmt.Fprintf(os.Stderr, "DialAndEcho failed: %v\n", err)
os.Exit(1)
}
if string(resp) != string(payload) {
fmt.Fprintf(os.Stderr, "expected response %q, got %q\n", string(payload), string(resp))
os.Exit(1)
}
if err := <-serverErrCh; err != nil {
fmt.Fprintf(os.Stderr, "server error: %v\n", err)
os.Exit(1)
}
// 3. Test DialPipeContext cancellation behavior
canceledCtx, cancelImmediate := context.WithCancel(context.Background())
cancelImmediate()
nonExistentPipe := randomPipePath()
_, err = winio.DialPipeContext(canceledCtx, nonExistentPipe)
if err == nil {
fmt.Fprintf(os.Stderr, "expected error when dialing with canceled context, got nil\n")
os.Exit(1)
}
if !errors.Is(err, context.Canceled) && canceledCtx.Err() != context.Canceled {
fmt.Fprintf(os.Stderr, "expected context canceled error, got %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: DialPipeContext verified successfully")
}
Seeder de origen
anónimo