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/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: 2 additions & 1 deletion .claude/marathon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ currency = "mise run currency"
[remote]
platform = "github"
publish = "gh pr create"
merge = "gh pr checks --watch && gh pr merge --merge --delete-branch"
checks = "gh pr checks --watch"
merge = "gh pr merge --merge --delete-branch"
ci = '''
sha=$(git rev-parse HEAD)
for _ in $(seq 30); do
Expand Down
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ only; the `postgres` and `postgres/pgvector` sub-modules each keep their own.

## [Unreleased]

### Changed

- **Breaking:** The `go-core` requirement is v0.14.0. Its v0.13.0 changes `EventKind.Raise` to take
an `event.RaiseOptions`, so an importer that calls it changes with this upgrade. The module's
own API is unchanged.
- 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/`. The tests of `admin` and `sweep` that
use an `export_test.go` hook stay beside it, and the fixtures both of a package's test packages
share sit in the internal packages `internal/admintest` and `internal/sweeptest`. No exported API
changes.
- The repository's check runs as step scripts in `scripts/check/` (`go.sh`, `lints.sh`), which
`mise run check` runs in turn.
- Agent tasks live in `.agent/mise-tasks/`, loaded only by the `agent` profile (`mise.agent.toml`,
under `MISE_ENV=agent`): one task per check step, and `test`, `vet`, and `lint`. The inline
`build`, `test`, `vet`, and `lint` tasks are removed; a person's other tasks are unchanged.

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

### Added
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,27 @@ principles:
The repository uses a Go workspace and [mise](https://mise.jdx.dev):

```
mise run check # build, vet, format, fix, tidy, test, and lint every module, then lint-context and 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, discarding its data
mise run check # build, vet, format, fix, tidy, test, and lint every module, then lint-context and 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, discarding its data
mise run integration # run the integration tier against the running stack
mise run acceptance # db:up, integration, then db:down whatever the result; prints the stack's log on failure
mise run fmt # format all Go source
mise run tidy # run go mod tidy in every module
```

`mise run check` runs the step scripts in `scripts/check/`: `go.sh`, the Go gates in each module,
then `lints.sh`. Where `MISE_ENV=agent` is set, as `.claude/settings.json` sets it for the agent,
mise also loads the agent profile, `mise.agent.toml`, which adds the tasks in `.agent/mise-tasks/`:
`check:go` and `check:lints`, one per step, and `test`, `vet`, and `lint`, one gate each.

Each package's tests sit in its `test/` directory as an external test package. In `admin` and
`sweep`, the tests that use an `export_test.go` hook stay beside it, and the fixtures both of the
package's test packages share sit in the internal packages `internal/admintest` and
`internal/sweeptest`.

`compose.yml` runs PostgreSQL with pgvector on port 5438; `POSTGRES_PORT` moves it, and
`GO_DATABASE_DSN` in `mise.toml` follows it. The service builds from
`compose/postgres/Dockerfile`, a copy of sqlate's canonical PostgreSQL image: its `FROM` line is
Expand Down
1 change: 1 addition & 0 deletions STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ The judgement calls the standards-reviewer applies to go-database, beyond what `
- `architecture/principles/service-tiers.md`: `DB.Conn`, `Config.Options`, and the `postgres` provider.
- `architecture/principles/validation-first.md`: `Config.Finalize`, and `admin`'s verbs, which refuse an argument outside their domain before any I/O, and `pgvector.ParseMetric`, which refuses an unknown metric name before any I/O.
- `architecture/principles/context-architecture.md`: the README and each `doc.go`.
- `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.
106 changes: 106 additions & 0 deletions admin/ready_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package admin_test

import (
"context"
"database/sql/driver"
"slices"
"sync"
"sync/atomic"
"testing"

"github.com/standards-lab/go-database/admin"
"github.com/standards-lab/go-database/internal/admintest"
"github.com/standards-lab/sqlate/migrate"
"github.com/standards-lab/sqlate/sqltest"
)

func behindService(t *testing.T) *admin.Service {
t.Helper()
s, _ := admintest.NewService(t, slices.Concat(
admintest.Clean(), []sqltest.Response{admintest.Exists(true), admintest.History([]driver.Value{int64(1), "a", false})},
)...)
if err := s.Start(context.Background()); err != nil {
t.Fatalf("Start: %v", err)
}
if st, err := s.Status(context.Background()); err != nil || st.Ready {
t.Fatalf("Status = %+v, %v", st, err)
}
return s
}

func TestReady_ConcurrentProbesVerifyOnce(t *testing.T) {
s := behindService(t)
var probes atomic.Int32
admin.SetProbe(s, func(context.Context) error {
probes.Add(1)
return migrate.ErrPending
})
var wg sync.WaitGroup
gate := make(chan struct{})
for range 16 {
wg.Go(func() {
<-gate
_ = s.Ready()
})
}
close(gate)
wg.Wait()
if n := probes.Load(); n != 1 {
t.Errorf("probes = %d, want 1", n)
}
}

func TestReady_ProbesNeverOverlap(t *testing.T) {
s := behindService(t)
var probes atomic.Int32
entered, release := make(chan struct{}), make(chan struct{})
admin.SetProbe(s, func(context.Context) error {
if probes.Add(1) == 1 {
entered <- struct{}{}
<-release
}
return nil
})
done := make(chan bool)
go func() { done <- s.Ready() }()
<-entered
admin.ExpireThrottle(s)
if s.Ready() || probes.Load() != 1 {
t.Errorf("a Ready during a probe verified again: probes = %d", probes.Load())
}
close(release)
if !<-done {
t.Error("the probe's clean verify did not set Ready")
}
}

func TestReady_ProbeYieldsToAConcurrentFinding(t *testing.T) {
s, _ := admintest.NewService(t, slices.Concat(
admintest.Clean(),
[]sqltest.Response{admintest.Exists(true), admintest.History([]driver.Value{int64(1), "a", false})},
[]sqltest.Response{admintest.Exists(true), admintest.History([]driver.Value{int64(1), "a", false})},
)...)
ctx := context.Background()
if err := s.Start(ctx); err != nil {
t.Fatalf("Start: %v", err)
}
if _, err := s.Status(ctx); err != nil {
t.Fatalf("Status: %v", err)
}
entered, release := make(chan struct{}), make(chan struct{})
admin.SetProbe(s, func(context.Context) error {
entered <- struct{}{}
<-release
return nil
})
done := make(chan bool)
go func() { done <- s.Ready() }()
<-entered
if st, err := s.Status(ctx); err != nil || st.Ready {
t.Fatalf("Status = %+v, %v", st, err)
}
close(release)
if <-done || s.Ready() {
t.Error("the probe's stale finding overwrote the status found behind")
}
}
13 changes: 7 additions & 6 deletions admin/extensions_test.go → admin/test/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"testing"

"github.com/standards-lab/go-database/admin"
"github.com/standards-lab/go-database/internal/admintest"
"github.com/standards-lab/sqlate/migrate"
"github.com/standards-lab/sqlate/sqltest"
)

type extensionDialect struct{ testDialect }
type extensionDialect struct{ admintest.Dialect }

func (extensionDialect) ExtensionState(param string) string {
return "SELECT installed, default, path FROM extensions WHERE name = " + param
Expand Down Expand Up @@ -45,14 +46,14 @@ var (

func newExtensionService(t *testing.T, declared []migrate.Extension, opts admin.Options, responses ...sqltest.Response) fixture {
t.Helper()
return newMigratorFixture(t, []migrate.Set{{Name: "app", Migrations: set}}, extensionDialect{},
return newMigratorFixture(t, []migrate.Set{{Name: "app", Migrations: admintest.Migrations}}, extensionDialect{},
migrate.Options{Extensions: declared}, opts, responses...)
}

var vector = []migrate.Extension{{Name: "vector"}}

func TestExtensions_StatusListsNoneWhenUndeclared(t *testing.T) {
s, _ := newService(t, current()...)
s, _ := admintest.NewService(t, current()...)
st, err := s.Status(context.Background())
if err != nil {
t.Fatalf("Status: %v", err)
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestExtensions_FaultIsAConflict(t *testing.T) {
}
})
t.Run(name+"/verify", func(t *testing.T) {
f := newExtensionService(t, vector, admin.Options{}, extCurrent, exists(true), applied(), fault.state)
f := newExtensionService(t, vector, admin.Options{}, extCurrent, admintest.Exists(true), admintest.Applied(), fault.state)
ctx := context.Background()
if err := f.service.Verify(ctx); err != nil || !f.service.Ready() {
t.Fatalf("clean Verify = %v, ready %v", err, f.service.Ready())
Expand All @@ -163,7 +164,7 @@ func TestExtensions_FaultIsAConflict(t *testing.T) {
t.Run(name+"/up", func(t *testing.T) {
f := newExtensionService(t, vector, admin.Options{}, slices.Concat(
current(), []sqltest.Response{extCurrent},
[]sqltest.Response{locked, created, applied(), fault.state, unlocked},
[]sqltest.Response{locked, created, admintest.Applied(), fault.state, unlocked},
current(), []sqltest.Response{fault.state},
)...)
ctx := context.Background()
Expand All @@ -184,7 +185,7 @@ func TestExtensions_StartLogsPendingBeforeApplying(t *testing.T) {
f := newExtensionService(t, vector, admin.Options{Logger: slog.New(slog.NewTextHandler(&buf, nil))}, slices.Concat(
[]sqltest.Response{extMissing},
current(), []sqltest.Response{extMissing},
[]sqltest.Response{locked, created, applied(), extMissing, {}, {}, unlocked},
[]sqltest.Response{locked, created, admintest.Applied(), extMissing, {}, {}, unlocked},
[]sqltest.Response{extCurrent}, current(),
)...)
if err := f.service.Start(context.Background()); err != nil {
Expand Down
Loading