CodeSampleX

Sample

github.com/Microsoft/go-winio v0.6.2: DialPipeContext

Verified sample for golang github.com/Microsoft/go-winio v0.6.2: DialPipeContext. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:7bc5d81daba730baf8cf8f8694d57dbcbb07fcb26a13ae038f6f658d545c15b3

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment windows 11 x64 go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify github.com/Microsoft/go-winio.DialPipeContext in pkg:golang/github.com/Microsoft/go-winio@v0.6.2
Packages
Symbols
  • github.com/Microsoft/go-winio.DialPipeContext
Created
2026-08-18T17:51:10Z

Contract

  1. DialPipeContext connects to an active Windows named pipe within the specified timeout context
  2. DialPipeContext immediately returns an error when the provided context is canceled

Files

  • PROMPT.md
  • client_other.go
  • client_windows.go
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract_other.go
  • test/contract_windows.go

Download the source artifact (tar.gz)

Source

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/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.
client_other.go
//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
}
client_windows.go
//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
}
csx.json
{"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"}
go.mod
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
go.sum
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=
spec.json
{
  "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"
  ]
}
test/contract_other.go
//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")
}
test/contract_windows.go
//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")
}

Origin Seeder

anonymous