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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
- uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ matrix.ocaml }}
# litany, which make lint runs, is open-opam's.
opam-repositories: |
open-opam: https://github.com/open-opam/opam-repository.git
default: https://opam.ocaml.org
- run: opam install . --deps-only --with-test --with-dev-setup -y
# Use setup-ocaml's switch instead of the Makefile's.
- run: make lint OPAM="opam exec --"
Expand Down
27 changes: 16 additions & 11 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ change updates the page that describes it, not the README.
```sh
make setup # once: the switch hypha-postgres-eio, all dependencies
make test # starts the test Postgres in Podman, runs every test
make lint # formatting, odoc, and the release build
make lint # formatting, odoc, the release build, and Hypha's rules by litany
make fmt # format in place
make docs # the documentation site into _build/docs, as Pages publishes it
make docs-serve # the built site, served on DOCS_PORT, search included
Expand Down Expand Up @@ -73,7 +73,6 @@ Each rule comes with why it exists and the test that catches a break.
release installs, offline, and a page it reads must be the release's.
Test: the docs workflow builds the pages on every pull request and fails
if `agents/` then differs.

- **Every protocol requirement the driver meets has a test case named by
its section** of chapter 54 of the Postgres 18 docs (e.g. `54.2.4 ...`).
Backend messages are read whole, a byte at a time, and at generated
Expand Down Expand Up @@ -113,12 +112,18 @@ Each rule comes with why it exists and the test that catches a break.
`handshake` sources are the application's to cap. Test: `no secret in
the log`, `a bad escape in a password is not quoted`, `a delimiter in a
password is not quoted`.
- **The driver's own failures are values; only the caller's exceptions
pass through.** Failures inside an exchange raise `Fail` internally and
are caught where the exchange began. An exception from a caller's
callback (a row function, a COPY source) and Eio's cancellation propagate
as they came. A failure that leaves the stream out of step (timeout,
broken socket, malformed bytes, a raise from a row function) closes the
connection. A server error does not, since the server marks where its
reply ends. Test: `54.2.3 a server's error keeps the connection`,
`54.2.6 a producer that raises is a CopyFail`.
- **A failure that leaves the stream out of step closes the connection; a
server error does not**, since the server marks where its reply ends. Out
of step is a timeout, a broken socket, malformed bytes or a raise from a
row function. A failure inside an exchange raises `Fail` internally and
is caught where the exchange began; an exception from a caller's callback
(a row function, a COPY source) propagates as it came. Test: `54.2.3 a
server's error keeps the connection`, `54.2.6 a producer that raises is
a CopyFail`.
- **The driver reads the system's clock in one place: to verify a
certificate against `sslrootcert`**, in `tls_config` of
`src/connection.ml`, as `Ca_certs.authenticator` does for the system's
authorities. Why: a certificate is valid at an instant, and `connect` is
given a monotonic clock alone. Symptom: `make lint`'s litany reports
`restricted-dependency` for a clock anywhere else, which that one use is
allowed with its reason beside it.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

## 0.5.4 (2026-12-03)

- A connection that fails while it is being opened keeps the backtrace of
the exception its socket is closed on, where closing could overwrite it.
- Every package installs the documentation for agents, `llms.txt` and every
page, in `$(opam var <package>:doc)`, and every interface it installs
names its page there, or `llms.txt`. The README's *With an agent* says so.

## 0.5.3 (2026-11-22)

- postgres-eio installs its documentation for agents: each page of the
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ help: ## list targets
setup: ## create the switch and install dependencies
@podman compose version >/dev/null 2>&1 || echo "The tests need podman compose."
@opam switch list --short | grep -qx $(SWITCH) || opam switch create $(SWITCH) --empty -y
opam repo add open-opam https://github.com/open-opam/opam-repository.git --switch=$(SWITCH) --rank=1
opam install . --switch=$(SWITCH) --deps-only --with-test --with-dev-setup -y

build: ## build everything
Expand All @@ -25,10 +26,12 @@ build: ## build everything
test: db ## run the tests
POSTGRES_EIO_TEST_PG=$(PG_TEST_URL) $(OPAM) dune test --force

# Release is the profile opam installs with.
lint: ## check formatting, docs and the release build
# Release is the profile opam installs with. litany holds the code to
# Hypha's rules, as the litany file selects them.
lint: ## check formatting, docs, the release build and Hypha's rules
$(OPAM) dune build @all @fmt @doc
$(OPAM) dune build --profile release @all
$(OPAM) litany check

fmt: ## format the code
$(OPAM) dune fmt
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ let () =

## With an agent

postgres-eio installs its documentation at `$(opam var postgres-eio:doc)`:
each page of the site as Markdown, and `llms.txt`, which lists them. Your
agent reads it when told to, in a line in your project's `AGENTS.md`:
Every package of postgres-eio installs its documentation for an agent with
it, at `$(opam var <package>:doc)`: `llms.txt`, and every page in Markdown.
An agent reads it when your project's `AGENTS.md` tells it to:

```md
Before writing code with postgres-eio, read `$(opam var postgres-eio:doc)/llms.txt` and
the pages it lists for the parts you need, and use those parts rather than
writing your own.
Before working with postgres-eio, read `llms.txt` in `$(opam var
<package>:doc)`, for any postgres-eio package the project installs, then the
pages it lists for the parts you need, and use those parts rather than writing
your own.
```

## Contributing
Expand Down
5 changes: 3 additions & 2 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
(:standard -w +a-4-40-41-42-44-45-48-67-70))))

; The documentation for a user's agent, agents/, written from the site's pages
; by `make docs`: installed whole, so $(opam var postgres-eio:doc) holds
; llms.txt and each page.
; by `make docs`: every package installs it whole, so a package installed
; alone, postgres-eio without postgres-eio, still holds llms.txt and each page in
; $(opam var <package>:doc).

(install
(package postgres-eio)
Expand Down
5 changes: 5 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
(and
:with-dev-setup
(= 0.29.0)))
(hypha-litany
(and
:with-dev-setup
(>= 1.3.0)
(< 2.0.0)))
(odoc
(and
:with-dev-setup
Expand Down
223 changes: 223 additions & 0 deletions litany
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
; Hypha's lint set, as litany holds it. Every Hypha repository's litany file
; selects each rule here and keeps each forbid as it is written here; what is
; the repository's own -- a forbid more, a per-path -- is added with its
; reason. Hypha's OCAML.md says what each rule is for.

(litany-config 1)

(lint
(select default)
(extend
unsafe-partial-stdlib
unsafe-obj-magic
untyped-ignore
ignored-result
wildcard-over-owned-variant
open-of-ordinary-module
restricted-dependency))

(rule restricted-dependency
; Refused in every file.
(forbid Stdlib.failwith
(use "a result; a test that raises on purpose declares its own exception"))
(forbid Stdlib.compare
(use "the type's own comparison: Int.compare, String.compare"))
(forbid Stdlib.min
(use "the type's own: Int.min, Float.min"))
(forbid Stdlib.max
(use "the type's own: Int.max, Float.max"))
(forbid Unix.time
(use "the clock the caller gives, read as a Ptime.t"))
(forbid Unix.gettimeofday
(use "the clock the caller gives, read as a Ptime.t"))
(forbid Stdlib.Sys.time
(use "Eio.Time.Mono.now, for time that has passed"))
(forbid Unix.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Unix.alarm
(use "Eio.Time.Timeout.v"))
(forbid Unix.setitimer
(use "Eio.Time.Timeout.v"))
(forbid Unix.getitimer
(use "Eio.Time.Mono.now"))
(forbid Eio_unix.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Eio.Time.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Eio.Time.sleep_until
(use "Eio.Time.Mono.sleep_span, over the span from now to the instant"))
(forbid Eio.Time.with_timeout
(use "Eio.Time.Timeout.v, given an Mtime.Span.t"))
(forbid Eio.Time.with_timeout_exn
(use "Eio.Time.Timeout.v, given an Mtime.Span.t"))
(forbid Eio.Time.Timeout.seconds
(use "Eio.Time.Timeout.v, given an Mtime.Span.t"))
(forbid Eio.Time.Mono.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Uri.query
(use "what the router decoded and validated"))
(forbid Uri.get_query_param
(use "what the router decoded and validated"))
; Refused outside a library's clock module.
(forbid Eio.Time.now
(use "the library's instant.ml, which gives a Ptime.t")
(except **/instant.ml))
(forbid Unix.sleepf
(use "the library's instant.ml, which takes an Mtime.Span.t")
(except **/instant.ml))
; Refused in a library: a program, a test and an example own their process,
; wherever in the tree its bin/, test/, examples/ or bench/ is.
(forbid Stdlib.Sys.getenv
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.getenv_opt
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Unix.getenv
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Unix.environment
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Unix.putenv
(use "an argument: a library sets no global state")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.argv
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.signal
(use "the executable: it owns the process's signals")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.set_signal
(use "the executable: it owns the process's signals")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.chdir
(use "a directory capability the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.command
(use "Eio.Process, on the process manager the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.at_exit
(use "Eio.Switch.on_release, on the switch the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Random.self_init
(use "a Random.State.t, or the secure random source the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Random.init
(use "a Random.State.t, or the secure random source the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Logs.set_reporter
(use "the executable: it configures the log reporter")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Logs.set_level
(use "the executable: it configures the log level")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_string
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_endline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_bytes
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_char
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_int
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_float
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_newline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_string
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_endline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_bytes
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_char
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_int
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_float
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_newline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.stdout
(use "a sink the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.stderr
(use "a sink the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Printf.printf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Printf.eprintf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.printf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.eprintf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.print_string
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.std_formatter
(use "a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.err_formatter
(use "a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Fmt.pr
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Fmt.epr
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Eio_main.run
(use "the env, switch or capability the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Ptime_clock.now
(use "the clock or ~now the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Mtime_clock.now
(use "the clock the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Mtime_clock.elapsed
(use "the clock the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Mtime_clock.counter
(use "the clock the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
; Refused in a Melange library: the console is the page's.
(forbid Js.log
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.log2
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.log3
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.log4
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.logMany
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.Console
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**)))
1 change: 1 addition & 0 deletions postgres-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ depends: [
"merlin" {with-dev-setup & >= "5.6-504"}
"ocaml-lsp-server" {with-dev-setup & >= "1.25.0"}
"ocamlformat" {with-dev-setup & = "0.29.0"}
"hypha-litany" {with-dev-setup & >= "1.3.0" & < "2.0.0"}
"odoc" {with-dev-setup & >= "3.2.1"}
"odoc" {with-doc}
]
Expand Down
5 changes: 4 additions & 1 deletion src/auth.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(** SCRAM-SHA-256 and MD5 sign-in, without IO or randomness: the caller supplies
the nonce. Nothing is logged, and no error contains a password, proof or
message bytes. *)
message bytes.

Its documents, a page for each part:
[$(opam var postgres-eio:doc)/llms.txt]. *)

val md5 : user:string -> password:string -> salt:string -> string
(** The AuthenticationMD5Password response:
Expand Down
5 changes: 4 additions & 1 deletion src/column.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(** A column of a result, as the server describes it before the first row. *)
(** A column of a result, as the server describes it before the first row.

Its documents, a page for each part:
[$(opam var postgres-eio:doc)/llms.txt]. *)

type format =
| Text (** the type's text form, as [psql] prints it *)
Expand Down
Loading