CodeSampleX

サンプル

github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be

検証済みサンプル — golang github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:b6c11fc27616551962ab2d24eb4bc3e9a8c513646635f85cd7f2f542d435ad6a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
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-08-28

ケース

HOW
ゴール
verify pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be
パッケージ
作成日
2026-08-28T00:37:13Z

コントラクト

  1. shlex.Split parses command-line strings into argument slices using POSIX quoting and escaping rules
  2. shlex.Split preserves escaped characters and spaces when using backslashes
  3. shlex.Split returns ErrNoClosing when a quoted argument is not terminated
  4. shlex.Split returns ErrNoEscaped when an escape backslash appears at the end of input
  5. shlex.NewLexer and NewLexerString tokenize input streams and strings into words

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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 pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be
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:8693ca1837008ddd06aefc78e1773bfb6e66881b1f6285162add152d182140d5","contract":["shlex.Split parses command-line strings into argument slices using POSIX quoting and escaping rules","shlex.Split preserves escaped characters and spaces when using backslashes","shlex.Split returns ErrNoClosing when a quoted argument is not terminated","shlex.Split returns ErrNoEscaped when an escape backslash appears at the end of input","shlex.NewLexer and NewLexerString tokenize input streams and strings into words"],"goal":"verify pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be","kind":"HOW","packages":["pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be"],"schemaVersion":1},"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/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be"],"schemaVersion":1,"subject":"pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22.0

require github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
go.sum
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
main.go
package main

import (
	"fmt"
	"os"

	"github.com/anmitsu/go-shlex"
)

// SplitCommand splits a shell command line string into separate arguments using POSIX rules.
func SplitCommand(cmdLine string) ([]string, error) {
	return shlex.Split(cmdLine, true)
}

// TokenizeWords tokenizes a string using Lexer with custom settings.
func TokenizeWords(input string) ([]string, error) {
	lexer := shlex.NewLexerString(input, true, false)
	return lexer.Split()
}

func main() {
	cmd := `echo "hello world" 'single quoted' flag\ with\ space`
	args, err := SplitCommand(cmd)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to split command: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Split %d arguments:\n", len(args))
	for i, arg := range args {
		fmt.Printf("  [%d] %s\n", i, arg)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"os"
	"reflect"
	"strings"

	"github.com/anmitsu/go-shlex"
)

func main() {
	// Assertion 1: shlex.Split parses command-line strings into argument slices using POSIX quoting and escaping rules
	{
		input := `grep -rn "search term" 'another argument' standalone`
		got, err := shlex.Split(input, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: shlex.Split unexpected error: %v\n", err)
			os.Exit(1)
		}
		expected := []string{"grep", "-rn", "search term", "another argument", "standalone"}
		if !reflect.DeepEqual(got, expected) {
			fmt.Fprintf(os.Stderr, "FAIL: shlex.Split result mismatch: got %v, want %v\n", got, expected)
			os.Exit(1)
		}
	}

	// Assertion 2: shlex.Split preserves escaped characters and spaces when using backslashes
	{
		input := `printf "escaped \"quotes\"" unquoted\ space`
		got, err := shlex.Split(input, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: shlex.Split with escapes failed: %v\n", err)
			os.Exit(1)
		}
		expected := []string{"printf", `escaped "quotes"`, "unquoted space"}
		if !reflect.DeepEqual(got, expected) {
			fmt.Fprintf(os.Stderr, "FAIL: shlex.Split escape mismatch: got %v, want %v\n", got, expected)
			os.Exit(1)
		}
	}

	// Assertion 3: shlex.Split returns ErrNoClosing when a quoted argument is not terminated
	{
		input := `echo "unclosed string`
		_, err := shlex.Split(input, true)
		if err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error for unclosed quote, got nil\n")
			os.Exit(1)
		}
		if !errors.Is(err, shlex.ErrNoClosing) && err != shlex.ErrNoClosing {
			fmt.Fprintf(os.Stderr, "FAIL: expected ErrNoClosing, got %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 4: shlex.Split returns ErrNoEscaped when an escape backslash appears at the end of input
	{
		input := `echo trailing escape \`
		_, err := shlex.Split(input, true)
		if err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error for trailing escape, got nil\n")
			os.Exit(1)
		}
		if !errors.Is(err, shlex.ErrNoEscaped) && err != shlex.ErrNoEscaped {
			fmt.Fprintf(os.Stderr, "FAIL: expected ErrNoEscaped, got %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 5: shlex.NewLexer and NewLexerString tokenize input streams and strings into words
	{
		reader := strings.NewReader("word1 'quoted word2' word3")
		lexer := shlex.NewLexer(reader, true, false)
		got, err := lexer.Split()
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: NewLexer Split failed: %v\n", err)
			os.Exit(1)
		}
		expected := []string{"word1", "quoted word2", "word3"}
		if !reflect.DeepEqual(got, expected) {
			fmt.Fprintf(os.Stderr, "FAIL: NewLexer Split mismatch: got %v, want %v\n", got, expected)
			os.Exit(1)
		}

		strLexer := shlex.NewLexerString("alpha beta gamma", true, false)
		gotStr, err := strLexer.Split()
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: NewLexerString Split failed: %v\n", err)
			os.Exit(1)
		}
		expectedStr := []string{"alpha", "beta", "gamma"}
		if !reflect.DeepEqual(gotStr, expectedStr) {
			fmt.Fprintf(os.Stderr, "FAIL: NewLexerString Split mismatch: got %v, want %v\n", gotStr, expectedStr)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: pkg:golang/github.com/anmitsu/go-shlex@v0.0.0-20200514113438-38f4b401e2be contract passed")
}

オリジンシーダー

匿名