CodeSampleX

Exemple

modernc.org/sqlite v1.56.0: NewConnector

Échantillon vérifié pour golang modernc.org/sqlite v1.56.0: NewConnector. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.

sha256:b40f43c3cc915bbb8cdce464c2099fc930837f39326de067f23ff0e735d30d66

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go wsl

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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 debian/x64 · docker ed25519:c1973797be207ac4 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-07

Cas

HOW
Objectif
verify pkg:golang/modernc.org/sqlite@v1.56.0
Paquets
Symboles
  • modernc.org/sqlite.NewConnector
Créé
2026-08-19T10:43:36Z

Contrat

  1. sqlite.NewConnector validates DSN syntax and rejects invalid percent-encoded parameters
  2. sqlite.NewConnector creates a driver.Connector carrying driver capabilities and custom pragmas
  3. Connector.Driver returns the underlying sqlite driver instance
  4. Embedding the returned connector in a custom wrapper intercepts connection creation for sql.OpenDB
  5. Connections opened via sql.OpenDB execute DDL, parameterized queries, and enforce relational constraints
  6. Transactions opened through the connector support atomic commit and rollback semantics

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 pkg:golang/modernc.org/sqlite@v1.56.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/modernc.org/sqlite@v1.56.0
Demonstrate these symbols/APIs:
  - modernc.org/sqlite.NewConnector

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:f975b3f786375370346bb8ec3d4f579ab64e408ed38431b26b2802a04b007f78","contract":["sqlite.NewConnector validates DSN syntax and rejects invalid percent-encoded parameters","sqlite.NewConnector creates a driver.Connector carrying driver capabilities and custom pragmas","Connector.Driver returns the underlying sqlite driver instance","Embedding the returned connector in a custom wrapper intercepts connection creation for sql.OpenDB","Connections opened via sql.OpenDB execute DDL, parameterized queries, and enforce relational constraints","Transactions opened through the connector support atomic commit and rollback semantics"],"goal":"verify pkg:golang/modernc.org/sqlite@v1.56.0","kind":"HOW","packages":["pkg:golang/modernc.org/sqlite@v1.56.0"],"schemaVersion":1,"symbols":["modernc.org/sqlite.NewConnector"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1,"virtualization":"wsl"},"license":"MIT-0","packages":["pkg:golang/modernc.org/sqlite@v1.56.0"],"schemaVersion":1,"symbols":["modernc.org/sqlite.NewConnector"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require modernc.org/sqlite v1.56.0

require (
	github.com/dustin/go-humanize v1.0.1 // indirect
	github.com/google/uuid v1.6.0 // indirect
	github.com/mattn/go-isatty v0.0.24 // indirect
	github.com/ncruces/go-strftime v1.0.0 // indirect
	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
	golang.org/x/sys v0.47.0 // indirect
	modernc.org/libc v1.74.4 // indirect
	modernc.org/mathutil v1.7.1 // indirect
	modernc.org/memory v1.11.0 // indirect
)
go.sum
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3 h1:LMLX+LgTNWpfvCBdFebv6EsYotImrt/Ppc5cXIriCSo=
github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
modernc.org/cc/v4 v4.29.1 h1:MKgdCV3WykTSPqpVrnxdEDS0HEd2FHpKZDzxzU5LyeI=
modernc.org/cc/v4 v4.29.1/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.6 h1:sBgfIwyN0TQ9C5hwIeuqyeAKyMWnbvj2fvpF4L11uzU=
modernc.org/ccgo/v4 v4.34.6/go.mod h1:SZ8YcN9NG7XVsQYdm6jYBvi8PQP1qi+kqB6OhjqI3Fk=
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.4 h1:2g65LGVSmFQrXeITAw97x7hCRvZFcyE1uDP+7Vng7JI=
modernc.org/gc/v3 v3.1.4/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.74.4 h1:fX1Omw4o2/1C2iRkkIsrQTasJQldLhRmuPreXLoWs9k=
modernc.org/libc v1.74.4/go.mod h1:eeQAS9W3sZeKYMFubydxJpII9ybHWshk+7or7bLG9co=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/sqlite v1.56.0 h1:/D8e2RfFqoy/Zc6PuC76U28zFwmI/sYx1Kjm4yEn9e0=
modernc.org/sqlite v1.56.0/go.mod h1:yCJ2cmAaIkHQ25oXWrF8H4O1lIfPYPR26yCEDj2P3pQ=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/modernc.org/sqlite@v1.56.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/modernc.org/sqlite@v1.56.0"
  ],
  "symbols": [
    "modernc.org/sqlite.NewConnector"
  ]
}
test/contract.go
package main

import (
	"context"
	"database/sql"
	"database/sql/driver"
	"fmt"
	"sync/atomic"

	"modernc.org/sqlite"
)

type connectionTracker struct {
	driver.Connector
	openAttempts atomic.Int64
}

func (c *connectionTracker) Connect(ctx context.Context) (driver.Conn, error) {
	c.openAttempts.Add(1)
	return c.Connector.Connect(ctx)
}

func main() {
	// 1. assert sqlite.NewConnector validates DSN syntax and rejects invalid percent-encoded parameters
	if _, err := sqlite.NewConnector("file:test.db?param=%ZZ"); err == nil {
		panic("expected error on invalid DSN percent encoding, got nil")
	}

	// 2. assert sqlite.NewConnector creates a driver.Connector carrying driver capabilities and custom pragmas
	dsn := "file:memdb1?mode=memory&cache=shared&_pragma=foreign_keys(1)"
	baseConnector, err := sqlite.NewConnector(dsn)
	if err != nil {
		panic(fmt.Sprintf("NewConnector failed for %s: %v", dsn, err))
	}

	// 3. assert Connector.Driver returns the underlying sqlite driver instance
	d := baseConnector.Driver()
	if d == nil {
		panic("expected non-nil Driver() from Connector")
	}

	// 4. assert Embedding the returned connector in a custom wrapper intercepts connection creation for sql.OpenDB
	tracker := &connectionTracker{Connector: baseConnector}
	db := sql.OpenDB(tracker)
	defer db.Close()

	if err := db.Ping(); err != nil {
		panic(fmt.Sprintf("db.Ping failed: %v", err))
	}
	if tracker.openAttempts.Load() < 1 {
		panic(fmt.Sprintf("expected at least 1 connection open attempt, got %d", tracker.openAttempts.Load()))
	}

	// Verify foreign_keys pragma was applied through DSN
	var foreignKeys int
	if err := db.QueryRow("PRAGMA foreign_keys").Scan(&foreignKeys); err != nil {
		panic(fmt.Sprintf("PRAGMA foreign_keys query failed: %v", err))
	}
	if foreignKeys != 1 {
		panic(fmt.Sprintf("expected foreign_keys=1, got %d", foreignKeys))
	}

	// 5. assert Connections opened via sql.OpenDB execute DDL, parameterized queries, and enforce relational constraints
	if _, err := db.Exec(`
		CREATE TABLE categories (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
		CREATE TABLE products (id INTEGER PRIMARY KEY, category_id INTEGER REFERENCES categories(id), name TEXT NOT NULL, price REAL);
	`); err != nil {
		panic(fmt.Sprintf("table creation failed: %v", err))
	}

	if _, err := db.Exec("INSERT INTO categories (id, name) VALUES (?, ?)", 1, "Hardware"); err != nil {
		panic(fmt.Sprintf("insert category failed: %v", err))
	}

	if _, err := db.Exec("INSERT INTO products (id, category_id, name, price) VALUES (?, ?, ?, ?)", 100, 1, "Screwdriver", 12.99); err != nil {
		panic(fmt.Sprintf("insert product failed: %v", err))
	}

	var prodName string
	var prodPrice float64
	if err := db.QueryRow("SELECT name, price FROM products WHERE id = ?", 100).Scan(&prodName, &prodPrice); err != nil {
		panic(fmt.Sprintf("query product failed: %v", err))
	}
	if prodName != "Screwdriver" || prodPrice != 12.99 {
		panic(fmt.Sprintf("product mismatch: %s, %f", prodName, prodPrice))
	}

	// Relational constraint check: foreign key violation must fail
	if _, err := db.Exec("INSERT INTO products (id, category_id, name, price) VALUES (?, ?, ?, ?)", 101, 999, "Invalid", 9.99); err == nil {
		panic("expected foreign key violation error, got nil")
	}

	// 6. assert Transactions opened through the connector support atomic commit and rollback semantics
	tx, err := db.Begin()
	if err != nil {
		panic(fmt.Sprintf("Begin tx failed: %v", err))
	}
	if _, err := tx.Exec("INSERT INTO categories (id, name) VALUES (?, ?)", 2, "Electronics"); err != nil {
		panic(fmt.Sprintf("insert in tx failed: %v", err))
	}
	if err := tx.Rollback(); err != nil {
		panic(fmt.Sprintf("rollback failed: %v", err))
	}

	var count int
	if err := db.QueryRow("SELECT COUNT(*) FROM categories WHERE id = 2").Scan(&count); err != nil {
		panic(fmt.Sprintf("count query failed: %v", err))
	}
	if count != 0 {
		panic(fmt.Sprintf("expected rolled-back category count to be 0, got %d", count))
	}

	fmt.Println("Contract passed")
}

Seeder d'origine

anonyme