Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .agent/mise-tasks/check/go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run the check's Go step, every gate in every module; gate names as arguments run only those"
# Runs scripts/check/go.sh, one step of the check.
set -euo pipefail
exec scripts/check/go.sh "$@"
5 changes: 5 additions & 0 deletions .agent/mise-tasks/check/lints
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run the check's lints step, lint-context and lint-references at the root"
# Runs scripts/check/lints.sh, one step of the check.
set -euo pipefail
exec scripts/check/lints.sh "$@"
5 changes: 5 additions & 0 deletions .agent/mise-tasks/check/sqlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run the check's sqlint step over the repository's SQL files"
# Runs scripts/check/sqlint.sh, one step of the check.
set -euo pipefail
exec scripts/check/sqlint.sh "$@"
5 changes: 5 additions & 0 deletions .agent/mise-tasks/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run the check's lint gate, golangci-lint with the integration tag, in every module"
# Runs the lint gate of scripts/check/go.sh.
set -euo pipefail
exec scripts/check/go.sh lint
5 changes: 5 additions & 0 deletions .agent/mise-tasks/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run the check's test gate, the unit tier with the race detector, in every module"
# Runs the test gate of scripts/check/go.sh.
set -euo pipefail
exec scripts/check/go.sh test
5 changes: 5 additions & 0 deletions .agent/mise-tasks/vet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run the check's vet gate, go vet with the integration tag, in every module"
# Runs the vet gate of scripts/check/go.sh.
set -euo pipefail
exec scripts/check/go.sh vet
3 changes: 3 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"plansDirectory": "./.claude/plans",
"env": {
"MISE_ENV": "agent"
},
"permissions": {
"allow": [
"Bash(go test:*)",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v7.0.1

- uses: jdx/mise-action@v5.3.0
- uses: jdx/mise-action@v5.4.0

- name: mise run check
run: mise run check
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.claude/plans/
.claude/briefs/
.agent/state/
mise.local.toml
bin/

Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ module only; the `postgres` and `sqlint` sub-modules each keep their own.

## [Unreleased]

### Changed

- Each package's unit tests sit in its `test/` directory as an external test package
(`<pkg>/test/*_test.go`); the root package's are in `test/`. `migrate`'s clock-hook tests stay
beside its `export_test.go`, and the fixtures `migrate`'s two test packages share are in the
internal package `internal/migratetest`. No exported API changes.
- The repository's check runs as step scripts in `scripts/check/` (`go.sh`, `sqlint.sh`,
`lints.sh`), which `mise run check` runs in turn. Vet, fix, and lint take `-tags integration`,
so the integration suites always compile.
- Agent tasks live in the agent area, `.agent/mise-tasks/`, which only the `agent` profile
(`mise.agent.toml`, under `MISE_ENV=agent`) loads: one task per check step, plus `test`, `vet`,
and `lint`, which replace the inline tasks of those names.
- `build` builds the sqlint command into the git-ignored `bin/`. It no longer builds each module;
the check's Go step does.

## [v0.8.0] - 2026-11-24

The migrator manages database extensions: a program declares them by name, and `Up` activates
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,17 @@ The repository is a Go workspace of four modules. Tasks run through
[mise](https://mise.jdx.dev):

```sh
mise run check # build, vet, format, fix, tidy, unit tier, lint, sqlint, lint-context, lint-references; writes nothing
mise run check # build, vet, format, fix, tidy, unit tier, and lint every module (vet, fix, and lint take the integration suites too), then sqlint, lint-context, lint-references; writes nothing
mise run currency # report tools, Go, requirements, actions, images, and Dockerfile source ARGs behind their latest, except a held one; writes nothing
mise run upgrade # move every pin currency reports to its latest, except a held one: tools, then Go and requirements, actions, images, and Dockerfile source ARGs
mise run db:up # build and start the compose PostgreSQL and wait until it is healthy
mise run db:down # stop PostgreSQL, keeping its data
mise run db:reset # stop PostgreSQL and drop its data
mise run integration # run the integration tier of postgres and postgres/pgvector against the running PostgreSQL
mise run acceptance # run db:up and integration, then db:reset whatever the result
mise run build # build the sqlint command into the git-ignored bin/
mise run fmt # format all Go source
mise run tidy # run go mod tidy in every module
```

`compose.yml` runs PostgreSQL on port 5433, beside a service's own on 5432; `POSTGRES_PORT`
Expand Down
1 change: 1 addition & 0 deletions STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ The judgement calls the standards-reviewer applies to sqlate, beyond what `mise
- `architecture/principles/service-tiers.md`: the `Dialect` boundary between the base module and each engine sub-module.
- `architecture/principles/tool-beside-library.md`: the `sqlint` package and its command.
- `architecture/principles/validation-first.md`: authored SQL, `sqlint.Load` and `migrate.New`.
- `architecture/principles/agent-separation.md`: the agent area in `.agent/`, the agent profile in `mise.agent.toml`, and `MISE_ENV=agent` in the Claude settings' `env`.
- `architecture/principles/comments.md`: every comment; a `.sql` file's `--|` header is also its template metadata.
- `architecture/principles/context-architecture.md`: the guide (`README.md` and `docs/`) and each `doc.go`.
31 changes: 17 additions & 14 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,11 @@ func (s *Store) Replace(ctx context.Context, id string, version int64, t NewTeam
`sqltest` is a scripted `database/sql` driver: each response is consumed by the next call in
order, and every call is recorded. Its stub dialect renders `$n` placeholders, so the compiled
text is the one PostgreSQL receives. The test publishes the `app` namespace itself, from an
in-memory file system, so the package's tests depend on nothing outside the package.
in-memory file system, so the package's tests depend on nothing outside the package. The tests
sit in `teams/test/` as the external test package `teams_test`, so they drive only what `teams`
exports.

`teams/patterns_test.go`:
`teams/test/patterns_test.go`:

```go
package teams_test
Expand All @@ -662,7 +664,7 @@ var patterns = fstest.MapFS{
}
```

`teams/database_test.go`:
`teams/test/database_test.go`:

```go
package teams_test
Expand Down Expand Up @@ -725,7 +727,7 @@ mise run test
```

```
ok example.com/teams/teams
ok example.com/teams/teams/test
```

The driver is strict where a real one is: an unscripted call, a wrong argument count, and a
Expand Down Expand Up @@ -1096,17 +1098,18 @@ teams/
├── stores.go
└── teams/
├── database.go
├── database_test.go
├── entities.go
├── patterns_test.go
└── statements/
├── create.sql
├── delete.sql
├── edit.sql
├── find_by_codes.sql
├── seed.sql
├── team_view.sql
└── version.sql
├── statements/
│ ├── create.sql
│ ├── delete.sql
│ ├── edit.sql
│ ├── find_by_codes.sql
│ ├── seed.sql
│ ├── team_view.sql
│ └── version.sql
└── test/
├── database_test.go
└── patterns_test.go
```

From here, the [features](features.md) document covers each mechanism in the detail the program
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
File renamed without changes.
18 changes: 18 additions & 0 deletions internal/migratetest/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Package migratetest holds the fixtures migrate's two test packages share:
// the clock-hook tests beside migrate's export_test.go and the black-box
// tests in migrate/test. It scripts a migrator over the sqltest driver with
// a blocking-lock dialect.
//
// The package exports:
//
// - [ErrDriver], the error a scripted response fails with
// - [Migrations], the two-migration set, one transactional and one not
// - [Locked], [Created], and [Unlocked], the responses to the lock, the
// history table's creation, and the unlock
// - [History], a scripted read of the history table
// - [LockingDialect], a sqltest dialect with a blocking lock and no try-lock
// - [NewMigrator] and [NewMigratorTable], which build a migrator over
// [Migrations] on a scripted pool
// - [AssertOps], which checks the recorded operations and that the script
// was consumed
package migratetest
96 changes: 96 additions & 0 deletions internal/migratetest/migratetest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package migratetest

import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"slices"
"testing"

"github.com/standards-lab/sqlate"
"github.com/standards-lab/sqlate/migrate"
"github.com/standards-lab/sqlate/sqltest"
)

// ErrDriver is the error a scripted response returns where the engine fails.
var ErrDriver = errors.New("engine says no")

// Migrations is the migration set the fixtures run as set "app": version 1
// is transactional, version 2 is not.
var Migrations = []migrate.Migration{
{Version: 1, Name: "a", Up: "CREATE TABLE a (x int)", Down: "DROP TABLE a", Transactional: true},
{Version: 2, Name: "b", Up: "CREATE INDEX CONCURRENTLY ix ON a (x)", Down: "DROP INDEX CONCURRENTLY ix"},
}

// Locked, Created, and Unlocked are the responses to [LockingDialect]'s
// lock, the history table's creation, and [LockingDialect]'s unlock of a
// held lock.
var (
Locked = sqltest.Response{}
Created = sqltest.Response{}
Unlocked = sqltest.Response{Columns: []string{"unlock"}, Rows: [][]driver.Value{{true}}}
)

// History is the response to a read of the history table holding rows, each
// a version, a name, and a dirty flag.
func History(rows ...[]driver.Value) sqltest.Response {
return sqltest.Response{Columns: []string{"version", "name", "dirty"}, Rows: rows}
}

// LockingDialect is sqltest's dialect with a blocking sqlate.Locker and no
// sqlate.TryLocker: Lock runs "SELECT lock($1)" and Unlock reads a boolean
// from "SELECT unlock($1)", failing when it is false.
type LockingDialect struct{ sqltest.Dialect }

// Lock runs "SELECT lock($1)" with the lock's name on conn.
func (LockingDialect) Lock(ctx context.Context, conn *sql.Conn, name string) error {
_, err := conn.ExecContext(ctx, "SELECT lock($1)", name)
return err
}

// Unlock reads "SELECT unlock($1)" with the lock's name on conn and fails
// when the lock was not held.
func (LockingDialect) Unlock(ctx context.Context, conn *sql.Conn, name string) error {
var held bool
if err := conn.QueryRowContext(ctx, "SELECT unlock($1)", name).Scan(&held); err != nil {
return err
}
if !held {
return errors.New("lock not held")
}
return nil
}

// NewMigrator builds a migrator of the one set "app" over [Migrations] on a
// [LockingDialect] pool scripted with responses, at the default history
// table.
func NewMigrator(t *testing.T, opts migrate.Options, responses ...sqltest.Response) (*migrate.Migrator, *sqltest.Recorder) {
t.Helper()
return NewMigratorTable(t, "", opts, responses...)
}

// NewMigratorTable is [NewMigrator] with the set's history table named
// table; an empty table keeps the default.
func NewMigratorTable(t *testing.T, table string, opts migrate.Options, responses ...sqltest.Response) (*migrate.Migrator, *sqltest.Recorder) {
t.Helper()
pool, rec := sqltest.Open(t, responses...)
db := sqlate.Wrap(pool, LockingDialect{})
m, err := migrate.New(db, []migrate.Set{{Name: "app", Table: table, Migrations: Migrations}}, opts)
if err != nil {
t.Fatalf("New: %v", err)
}
return m, rec
}

// AssertOps fails t unless rec recorded exactly the operations want, in
// order, and consumed every scripted response.
func AssertOps(t *testing.T, rec *sqltest.Recorder, want ...sqltest.Op) {
t.Helper()
if got := rec.Ops(); !slices.Equal(got, want) {
t.Errorf("ops = %v\nwant %v", got, want)
}
if rec.Pending() != 0 {
t.Errorf("%d scripted responses unconsumed", rec.Pending())
}
}
Loading