CodeSampleX

Beispiel

golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71: unix.O_CREAT

Verifiziertes Beispiel für golang golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71: unix.O_CREAT. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker…

sha256:5f851d21aacbd0ac56deeb9607ea9e987eb178ee9e1819cefaded7cb7c3ecc5a

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-30
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-30

Fall

HOW
Ziel
verify golang.org/x/sys/unix.O_CREAT in pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71
Pakete
Symbole
  • golang.org/x/sys/unix.O_CREAT
Umgebung
go 1.26.6
Erstellt
2026-08-30T16:01:02Z

Contract

  1. unix.O_CREAT is a non-zero integer flag constant in golang.org/x/sys/unix
  2. unix.Open with unix.O_CREAT|unix.O_RDWR creates a new file descriptor when file does not exist
  3. unix.Write writes data to the file created via unix.O_CREAT
  4. unix.Open with unix.O_CREAT|unix.O_EXCL on an existing file fails with unix.EEXIST

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract_test.go

Quellartefakt herunterladen (tar.gz)

Quelltext

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 golang.org/x/sys/unix.O_CREAT in pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71
Demonstrate these symbols/APIs:
  - golang.org/x/sys/unix.O_CREAT
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:df50520bb04f5b013bb79becfd5deb2f509aef0ff6f7741f6fdf5e268822dcbd","contract":["unix.O_CREAT is a non-zero integer flag constant in golang.org/x/sys/unix","unix.Open with unix.O_CREAT|unix.O_RDWR creates a new file descriptor when file does not exist","unix.Write writes data to the file created via unix.O_CREAT","unix.Open with unix.O_CREAT|unix.O_EXCL on an existing file fails with unix.EEXIST"],"goal":"verify golang.org/x/sys/unix.O_CREAT in pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71"],"schemaVersion":1,"symbols":["golang.org/x/sys/unix.O_CREAT"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","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/sys@v0.0.0-20220406155245-289d7a0edf71"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71","symbols":["golang.org/x/sys/unix.O_CREAT"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71
go.sum
golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71 h1:PRD0hj6tTuUnCFD08vkvjkYFbQg/9lV8KIxe1y4/cvU=
golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
main.go
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"golang.org/x/sys/unix"
)

// CreateFileWithFlags creates a file using unix.O_CREAT with specified flags and mode,
// writes initial data, and returns the path.
func CreateFileWithFlags(dir, filename string, flags int, mode uint32, data []byte) (string, error) {
	fullPath := filepath.Join(dir, filename)
	openFlags := unix.O_CREAT | flags
	fd, err := unix.Open(fullPath, openFlags, mode)
	if err != nil {
		return "", fmt.Errorf("unix.Open failed: %w", err)
	}
	defer unix.Close(fd)

	if len(data) > 0 {
		n, err := unix.Write(fd, data)
		if err != nil {
			return "", fmt.Errorf("unix.Write failed: %w", err)
		}
		if n != len(data) {
			return "", fmt.Errorf("unix.Write partial: %d of %d bytes written", n, len(data))
		}
	}

	return fullPath, nil
}

func main() {
	tmpDir, err := os.MkdirTemp("", "csx-sample-*")
	if err != nil {
		panic(err)
	}
	defer os.RemoveAll(tmpDir)

	path, err := CreateFileWithFlags(tmpDir, "example.txt", unix.O_RDWR|unix.O_TRUNC, 0600, []byte("unix.O_CREAT verification"))
	if err != nil {
		panic(err)
	}
	fmt.Println("Created file successfully:", path)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/sys/unix.O_CREAT in pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.0.0-20220406155245-289d7a0edf71"
  ],
  "symbols": [
    "golang.org/x/sys/unix.O_CREAT"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract_test.go
package test

import (
	"bytes"
	"os"
	"path/filepath"
	"testing"

	"golang.org/x/sys/unix"
)

func TestUnixOCreatCreatesNewFile(t *testing.T) {
	tmpDir := t.TempDir()
	targetPath := filepath.Join(tmpDir, "new_file.txt")

	// Ensure file does not exist initially
	if _, err := os.Stat(targetPath); !os.IsNotExist(err) {
		t.Fatalf("expected file to not exist initially: %v", err)
	}

	// Open with unix.O_CREAT | unix.O_RDWR | unix.O_TRUNC and mode 0600
	fd, err := unix.Open(targetPath, unix.O_CREAT|unix.O_RDWR|unix.O_TRUNC, 0600)
	if err != nil {
		t.Fatalf("unix.Open with unix.O_CREAT failed: %v", err)
	}
	if fd < 0 {
		t.Fatalf("unix.Open returned invalid file descriptor: %d", fd)
	}

	// Write test payload to the newly created file descriptor
	content := []byte("verification payload for unix.O_CREAT")
	n, err := unix.Write(fd, content)
	if err != nil {
		unix.Close(fd)
		t.Fatalf("unix.Write failed: %v", err)
	}
	if n != len(content) {
		unix.Close(fd)
		t.Fatalf("unix.Write wrote %d bytes, expected %d", n, len(content))
	}

	// Close the file descriptor
	if err := unix.Close(fd); err != nil {
		t.Fatalf("unix.Close failed: %v", err)
	}

	// Verify file exists on filesystem and has correct content
	readBack, err := os.ReadFile(targetPath)
	if err != nil {
		t.Fatalf("failed to read back created file: %v", err)
	}
	if !bytes.Equal(readBack, content) {
		t.Fatalf("read back content mismatch: got %q, want %q", readBack, content)
	}
}

func TestUnixOCreatWithOExcl(t *testing.T) {
	tmpDir := t.TempDir()
	targetPath := filepath.Join(tmpDir, "excl_file.txt")

	// Create file first time with unix.O_CREAT | unix.O_EXCL | unix.O_RDWR
	fd1, err := unix.Open(targetPath, unix.O_CREAT|unix.O_EXCL|unix.O_RDWR, 0644)
	if err != nil {
		t.Fatalf("first unix.Open with O_CREAT|O_EXCL failed: %v", err)
	}
	_ = unix.Close(fd1)

	// Opening again with unix.O_CREAT | unix.O_EXCL must return unix.EEXIST
	fd2, err := unix.Open(targetPath, unix.O_CREAT|unix.O_EXCL|unix.O_RDWR, 0644)
	if err == nil {
		unix.Close(fd2)
		t.Fatalf("expected unix.Open with O_CREAT|O_EXCL on existing file to fail, got fd %d", fd2)
	}
	if err != unix.EEXIST {
		t.Fatalf("expected error unix.EEXIST, got %v", err)
	}
}

func TestUnixOCreatConstantValue(t *testing.T) {
	if unix.O_CREAT == 0 {
		t.Fatalf("unix.O_CREAT constant must be non-zero")
	}
}

Ursprungs-Seeder

anonym