diff --git a/AGENTS.md b/AGENTS.md index 0cb8d97..529573c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,7 +11,7 @@ documentation site, [docs/](docs/src/content/docs/index.mdx). ```sh make setup # once: the switch spindle, every dependency make test # starts the test Postgres in Podman, runs every suite -make lint # formatting, odoc, the release build, and the opam files +make lint # formatting, odoc, the release build, Hypha's rules by litany, and the opam files make fmt # format in place make docs # the documentation site into _build/docs, as Pages publishes it; docs-serve serves it make release VERSION=1.2.3 # once CHANGES.md names it: tag and release with open-opam @@ -129,10 +129,20 @@ out you broke it, as it is true today. Cite one by its bold phrase. since Logs drops every line until it is; `Spindle.Log`'s default sink writes its lines to stderr; and `spindle-cli`, a command line, prints its answer and its errors and - exits with its status. Symptom: `rg -n -w - 'exit|stderr|print_string|print_endline|prerr_endline|Printf\.printf' - -g '*.ml' http core client postgres sqlite cli` finds one in a place this - list does not name. + exits with its status. Symptom: `make lint`'s litany reports + `restricted-dependency` or `suspicious-exit-in-library`, which each of + these places is allowed with its reason beside it, and `cli/` by a + `per-path` in the `litany` file. +- **Spindle owns the process in these places alone, beside those above.** + `Spindle.serve` handles SIGTERM and SIGINT, to stop as its `.mli` says; + `Spindle.Log.setup`, which an executable calls, sets the `Logs` reporter + and level, its reporter reads the system's clock, since it runs on + whichever thread logged and outside any event loop, and its writer + writes the lines still waiting as the process ends. Why: Spindle is the + framework a program's `main` hands the process to, and a library under + it does none of this. Symptom: `make lint`'s litany reports + `restricted-dependency` for a signal, `Logs`, a clock or `at_exit` + anywhere but `core/server.ml` and `core/log.ml`. - **Spindle reads and writes HTTP itself, names no driver, and its client installs and links no framework.** No library links another HTTP implementation or names one; `spindle-postgres` and `spindle-sqlite` diff --git a/CHANGES.md b/CHANGES.md index 99dbb5d..ace2bc5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,13 @@ # Changes +## 0.15.2 (2026-12-03) + +- `Spindle_client` keeps the backtrace of an exception it closes a + connection on, where closing could overwrite it. +- Every package installs the documentation for agents, `llms.txt` and every + page, in `$(opam var :doc)`, and every interface it installs + names its page there, or `llms.txt`. The README's *With an agent* says so. + ## 0.15.1 (2026-11-22) - spindle installs its documentation for agents: each page of the site as diff --git a/Makefile b/Makefile index 164e4b6..4d9fc95 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,12 @@ test/oidc/node_modules: test/oidc/package.json test/oidc/bun.lock # unless told it is an error, and installing from source prints each one. # The client's packages are built alone, as opam installs them for a # program that wants no framework. -lint: ## check formatting, docs, the release build and the opam files +# litany holds the code to Hypha's rules, as the litany file selects them. +lint: ## check formatting, docs, the release build, Hypha's rules and the opam files $(OPAM) dune build @all @fmt @doc $(OPAM) dune build --profile release @all $(OPAM) dune build -p spindle-http,spindle-client,spindle-mcp-client @install + $(OPAM) litany check opam lint -W @1..99 *.opam fmt: ## format the code diff --git a/README.md b/README.md index 7f7225b..7719edf 100644 --- a/README.md +++ b/README.md @@ -89,15 +89,14 @@ with the bounds from your types, and every error it may answer. ## With an agent -spindle installs its documentation at `$(opam var spindle:doc)`: each page -of the site as Markdown, the tutorial and guides among them, 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 spindle installs its documentation for an agent with it, at +`$(opam var :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 spindle, read `$(opam var spindle: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 spindle, read `llms.txt` in `$(opam var :doc)`, +for any spindle package the project installs, then the pages it lists for the +parts you need, and use those parts rather than writing your own. ``` ## Contributing diff --git a/cli/spindle_cli.mli b/cli/spindle_cli.mli index 7d7ff59..5b74797 100644 --- a/cli/spindle_cli.mli +++ b/cli/spindle_cli.mli @@ -1,5 +1,7 @@ (** An application's command line: its API, described from the routes. + Its documents, a page for each part: [$(opam var spindle-cli:doc)/llms.txt]. + OCaml cannot load an application into a generic command, so each application calls {!run} from an executable of its own: diff --git a/client/spindle_client.ml b/client/spindle_client.ml index 8270c4b..bf64227 100644 --- a/client/spindle_client.ml +++ b/client/spindle_client.ml @@ -714,8 +714,9 @@ let exchange ~sw t ~headers ~body meth target ~reused = close_connection c; attempt ~fresh:true | exception ex -> + let bt = Printexc.get_raw_backtrace () in close_connection c; - raise ex + Printexc.raise_with_backtrace ex bt in attempt ~fresh:false @@ -879,8 +880,9 @@ let open_answer ~sw t ~headers ~body meth target = close_connection c; attempt ~fresh:true | exception ex -> + let bt = Printexc.get_raw_backtrace () in close_connection c; - raise ex + Printexc.raise_with_backtrace ex bt in attempt ~fresh:false @@ -1093,11 +1095,14 @@ let refusal_body t c (head : Head.Response.t) = | Error _ -> "" | Ok framing -> ( let reader = Framing.reader framing c.reader ~max_trailer:max_head in - match Framing.read reader ~max:t.max_body ~reserve:(fun _ -> true) with + (match Framing.read reader ~max:t.max_body ~reserve:(fun _ -> true) with | Ok body -> body | Error _ -> "" | exception (Eio.Cancel.Cancelled _ as ex) -> raise ex | exception _ -> "") + [@litany.allow + "suspicious-catch-all-handler: the refusal stands whatever ended its \ + body, and cancellation is raised again above"]) (* A socket's own writer rather than [Buf_write.with_flow], which waits for everything written to go: to a server that stopped reading, a wait with @@ -1181,8 +1186,9 @@ let open_websocket t ?timeout ?(headers = []) ?keep_alive ?max_message protocol (fun () -> Ok (`Refused (head, refusal_body t c head))) | head -> Ok (`Switching (c, head)) | exception ex -> + let bt = Printexc.get_raw_backtrace () in close_connection c; - raise ex) + Printexc.raise_with_backtrace ex bt) with | Ok opened -> Ok opened | Error `Timeout -> Error (match timed_out deadline with #error as e -> e) @@ -1438,7 +1444,8 @@ module Otlp = struct if List.length spans = batch_size then send_waiting client q ~url ~headers ~service - let run ?ratio ?(headers = []) ~clock ~endpoint ~service client f = + let run (type a) ?ratio ?(headers = []) ~clock ~endpoint ~service client + (f : Trace.exporter -> a) : a = let url = (if String.ends_with ~suffix:"/" endpoint then String.sub endpoint 0 (String.length endpoint - 1) @@ -1477,7 +1484,7 @@ module Otlp = struct else None); false); (fun () -> - ignore (Eio.Promise.await answer); + ignore (Eio.Promise.await answer : a); true); ] in diff --git a/client/spindle_client.mli b/client/spindle_client.mli index f39ef9c..9be3ed7 100644 --- a/client/spindle_client.mli +++ b/client/spindle_client.mli @@ -1,5 +1,11 @@ (** Calling another server. + Its documents, a page for each part: + [$(opam var spindle-client:doc)/llms.txt]. + + Its page, with its examples: + [$(opam var spindle-client:doc)/pages/guide/client.md]. + The request is written, and the response read, by [spindle_http] -- the reader and writer the server is built on, so the framework has one account of where a message ends. A 1xx before the answer is read and dropped, a diff --git a/core/access.mli b/core/access.mli index f5522d8..65e06da 100644 --- a/core/access.mli +++ b/core/access.mli @@ -1,5 +1,8 @@ (** Who may do what: a policy decides, a dependency enforces. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/access.md]. + A policy is a function of the caller, an action and the object it is done to, written in OCaml beside the routes it guards. A route reaches a guarded object only through {!can}, which loads it, asks the policy, and hands the diff --git a/core/alarm.mli b/core/alarm.mli index 66950c5..ba0ec3d 100644 --- a/core/alarm.mli +++ b/core/alarm.mli @@ -1,5 +1,7 @@ (** Wake-ups, one per key: "look at this again after so long". + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + Setting a key again supersedes what was set before: the earlier wake-up's fiber is cancelled, not left asleep, and a key is forgotten once it has fired or been cancelled -- so a table of alarms holds only what is still to diff --git a/core/app.mli b/core/app.mli index 07cee2a..c10b253 100644 --- a/core/app.mli +++ b/core/app.mli @@ -1,6 +1,8 @@ (** An application: routes, what answers everything they do not match, and what applies to all of it. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + A request is matched by method and path. A path some route claims under another method is [405] with [Allow], which names [OPTIONS] too: a plain [OPTIONS] of such a path, where no route declares one, is [204] with that diff --git a/core/background.mli b/core/background.mli index 73beea1..861fd4b 100644 --- a/core/background.mli +++ b/core/background.mli @@ -1,5 +1,8 @@ (** Work nobody is waiting for. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/background.md]. + A daemon, so a process shutting down is not held open by one. A failure is {b logged}, never raised: a fiber's exception fails the switch it was forked on, and when that switch is the server's, one bug in a background job would diff --git a/core/bearer.mli b/core/bearer.mli index fbb3491..ec4806f 100644 --- a/core/bearer.mli +++ b/core/bearer.mli @@ -4,6 +4,8 @@ challenge RFC 6750 §3 names, and described by the metadata document RFC 9728 has a client find the issuer from. + Its page, with its examples: [$(opam var spindle:doc)/pages/guide/oauth.md]. + {[ let auth = Spindle.Bearer.make ~issuer:"https://id.example.com" diff --git a/core/body.mli b/core/body.mli index 29bf0d0..379a217 100644 --- a/core/body.mli +++ b/core/body.mli @@ -1,6 +1,8 @@ (** A request body read as it arrives: what {!Spindle.body_stream} hands a route, for a body too large to hold -- an upload. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ let rec save file body = let* part = Spindle.Body.read body in diff --git a/core/body_repr.mli b/core/body_repr.mli index 36bf1e1..fb6985e 100644 --- a/core/body_repr.mli +++ b/core/body_repr.mli @@ -1,6 +1,8 @@ (** A request's body while a route runs: read whole once and kept for every dependency that asks, or handed to the one that streams it. What {!Body} is, - underneath. *) + underneath. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type error = Request_repr.body_error diff --git a/core/broadcast.mli b/core/broadcast.mli index 7ed9059..ed23579 100644 --- a/core/broadcast.mli +++ b/core/broadcast.mli @@ -1,5 +1,7 @@ (** One event, rendered once, sent to everybody listening to a topic. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + There is no broker. A broker exists to carry an event from one process to a socket held by another, and in one process three hundred listeners are three hundred fibers parked on a read, which is the thing Eio is good at. What the diff --git a/core/cache.mli b/core/cache.mli index b0e876d..e695409 100644 --- a/core/cache.mli +++ b/core/cache.mli @@ -1,6 +1,8 @@ (** How long a browser may keep what the routes answer, apart from what they serve: a policy of the application's, given among its middleware. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ Spindle.serve env ~middleware:[ Spindle.Cache.forever ~under:Spindle.Path.[ s "assets" ] ] diff --git a/core/compress.mli b/core/compress.mli index f4ea5cb..1cb0b29 100644 --- a/core/compress.mli +++ b/core/compress.mli @@ -3,6 +3,9 @@ process pays and the proxy in front often compresses already, and a route's own in place of it where the route gives one ({!Route.maker}'s [compress]). + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/compression.md]. + {[ Spindle.serve env ~compress:Spindle.Compress.default routes ]} diff --git a/core/compress_repr.mli b/core/compress_repr.mli index 9155a47..a86e862 100644 --- a/core/compress_repr.mli +++ b/core/compress_repr.mli @@ -1,5 +1,7 @@ (** What {!Compress} is, underneath: shared with the server, which decides - whether an answer is compressed. *) + whether an answer is compressed. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type policy = { min_bytes : int; (** an answer shorter than this is sent as it is *) diff --git a/core/conditional.mli b/core/conditional.mli index b8dccb1..4207954 100644 --- a/core/conditional.mli +++ b/core/conditional.mli @@ -1,5 +1,7 @@ (** A [GET] of a representation: RFC 9110 §13.2.2's preconditions in their - order, then §14's range: one account for every file the framework serves. *) + order, then §14's range: one account for every file the framework serves. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type validators = { tag : Spindle_http.Etag.t; diff --git a/core/cookie.mli b/core/cookie.mli index 9c74b4f..f920a79 100644 --- a/core/cookie.mli +++ b/core/cookie.mli @@ -1,5 +1,8 @@ (** Cookies: the ones a response sets, and reading the ones a request carries. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/cookies.md]. + A cookie is declared once, by its name and the description its value is read and written by, and used both ways: diff --git a/core/cookie_repr.ml b/core/cookie_repr.ml index e670843..533d9a2 100644 --- a/core/cookie_repr.ml +++ b/core/cookie_repr.ml @@ -144,7 +144,7 @@ let decode s = let make ?path ?max_age_s ?http_only ?same_site n v = let max_age = match (max_age_s, n.age) with - | Some a, Some b -> Some (min a b) + | Some a, Some b -> Some (Int.min a b) | Some a, None | None, Some a -> Some a | None, None -> None in diff --git a/core/cookie_repr.mli b/core/cookie_repr.mli index 8b936b1..63b3712 100644 --- a/core/cookie_repr.mli +++ b/core/cookie_repr.mli @@ -1,6 +1,8 @@ (** A cookie as the framework holds it: writing [Set-Cookie], reading [Cookie], encoding a value. What {!Cookie} is, underneath; each value {!Cookie} - exports is documented there. *) + exports is documented there. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type same_site = Strict | Lax diff --git a/core/cors.mli b/core/cors.mli index 1c7eee6..71f83e2 100644 --- a/core/cors.mli +++ b/core/cors.mli @@ -3,6 +3,9 @@ given, and a route's own in place of it where the route gives one ({!Route.maker}'s [cors]). A route the policy it has allows is covered. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/cookies.md]. + {[ let app_site = Spindle.Cors.origins ~credentials:true [ "https://app.example.com" ] diff --git a/core/cors_repr.mli b/core/cors_repr.mli index 544857f..963eaa2 100644 --- a/core/cors_repr.mli +++ b/core/cors_repr.mli @@ -1,6 +1,8 @@ (** A CORS policy as the server applies it: what {!Cors.origins} or {!Cors.any} makes, and the fields of the Fetch standard's answers it owes a cross-origin - request. *) + request. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type origins = Origins of string list | Any diff --git a/core/deadline.ml b/core/deadline.ml index 64f2f2d..f1f0b56 100644 --- a/core/deadline.ml +++ b/core/deadline.ml @@ -52,7 +52,7 @@ let remaining t = if t.due_at = never then None else let left = t.due_at - now t.clock in - Some (Mtime.Span.of_uint64_ns (Int64.of_int (max 0 left))) + Some (Mtime.Span.of_uint64_ns (Int64.of_int (Int.max 0 left))) let passed t = t.passed diff --git a/core/deadline.mli b/core/deadline.mli index 2b142d1..0a8eb83 100644 --- a/core/deadline.mli +++ b/core/deadline.mli @@ -3,6 +3,8 @@ that domain's connections once a tick -- a deadline and its sweep are on the same domain, always. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + Every read of the connection, and every flush of an answer to it, runs against it, and moving it is a write to a field, not a timer: arming it for a head, a body or an answer, and the bytes that go moving it on, cost diff --git a/core/dep.mli b/core/dep.mli index 96ac0da..a68d7f1 100644 --- a/core/dep.mli +++ b/core/dep.mli @@ -1,5 +1,8 @@ (** Dependencies: what a handler needs, computed from the request. + Its page, with its examples: + [$(opam var spindle:doc)/pages/tutorial/dependencies.md]. + A ['a t] is a value -- a body of some shape, a query parameter, a signed-in person -- that is worked out when a request arrives, or a refusal that answers the request instead. A handler lists what it needs with OCaml's own diff --git a/core/dep_repr.mli b/core/dep_repr.mli index 8519ed0..66139da 100644 --- a/core/dep_repr.mli +++ b/core/dep_repr.mli @@ -1,6 +1,8 @@ (** A dependency as the framework runs it: what it reads, how it refuses, its two stages, and the identity its answer is shared by. What {!Dep} is, - underneath; the types {!Dep} names are documented there. *) + underneath; the types {!Dep} names are documented there. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type body = | Raw : { content_types : string list } -> body diff --git a/core/described.mli b/core/described.mli index 154857c..31e1c64 100644 --- a/core/described.mli +++ b/core/described.mli @@ -1,6 +1,8 @@ (** An application's routes as the two printers read them: every description walked, the answers first and then the bodies, so a component a response and - a request share takes the response's name. *) + a request share takes the response's name. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type returns = | Value of { diff --git a/core/event.mli b/core/event.mli index 5e864a8..fcb9256 100644 --- a/core/event.mli +++ b/core/event.mli @@ -1,6 +1,8 @@ (** Server-Sent Events, declared: what a stream may send, by name and description, and each event made from its declaration. + Its page, with its examples: [$(opam var spindle:doc)/pages/guide/sse.md]. + {[ type room diff --git a/core/file_types.mli b/core/file_types.mli index ee93c5b..bd3570a 100644 --- a/core/file_types.mli +++ b/core/file_types.mli @@ -1,5 +1,7 @@ (** A file's media type by its name, and the precompressed siblings a build - writes beside it, shared by {!Static} and {!Files}. *) + writes beside it, shared by {!Static} and {!Files}. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) val content_type : types:(string * string) list -> string -> string (** The type of a file by its extension, compared without case, [types] before diff --git a/core/files.ml b/core/files.ml index 387085e..b15abd8 100644 --- a/core/files.ml +++ b/core/files.ml @@ -107,13 +107,13 @@ let send_file root f ~first ~count send = && Option.equal Ptime.equal (Ptime.of_float_s st.mtime) f.modified in let send_range file = - let buf = Cstruct.create (max 1 (min read_bytes count)) in + let buf = Cstruct.create (Int.max 1 (Int.min read_bytes count)) in let rec go at left = if left = 0 then Ok () else let n = Eio.File.pread file ~file_offset:(Optint.Int63.of_int at) - [ Cstruct.sub buf 0 (min left (Cstruct.length buf)) ] + [ Cstruct.sub buf 0 (Int.min left (Cstruct.length buf)) ] in match send (Cstruct.to_string ~len:n buf) with | Ok () -> go (at + n) (left - n) diff --git a/core/files.mli b/core/files.mli index e5b2ba7..ab3800c 100644 --- a/core/files.mli +++ b/core/files.mli @@ -1,6 +1,8 @@ (** A directory served from disk as it is when a request arrives: uploads, generated reports, anything that changes while the server runs. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ Spindle.serve env (routes @ [ Spindle.Files.directory ~at:Path.(s "uploads") "var/uploads" ]) diff --git a/core/form.mli b/core/form.mli index 285685e..072a5e5 100644 --- a/core/form.mli +++ b/core/form.mli @@ -1,5 +1,7 @@ (** A form's fields, typed: [Spindle.Form.required "email" Wiretype.string]. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + A field is an input as a query parameter is, read by its wiretype description, and a problem with one is {!Refusal.invalid} at [form.], reported with every other problem of the request at once. The body is read diff --git a/core/gzip.mli b/core/gzip.mli index 767cd53..f88a965 100644 --- a/core/gzip.mli +++ b/core/gzip.mli @@ -1,5 +1,7 @@ (** gzip (RFC 1952) written a piece at a time: deflate from [decompress] and the - CRC-32 its trailer carries. *) + CRC-32 its trailer carries. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type t (** One stream being written. *) diff --git a/core/handler_clock.mli b/core/handler_clock.mli index 85fdcc4..2860fbd 100644 --- a/core/handler_clock.mli +++ b/core/handler_clock.mli @@ -1,7 +1,9 @@ (** How long a route's handler has run, its waits on its client's body left out: what [handler_timeout] bounds ({!Server.Limits}, {!Route.Limits}), since [body_timeout] and [min_body_rate] already bound those waits. One a request, - kept by whatever hands the route its body. *) + kept by whatever hands the route its body. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type t diff --git a/core/header.mli b/core/header.mli index 153a39a..458ac79 100644 --- a/core/header.mli +++ b/core/header.mli @@ -1,5 +1,7 @@ (** Request headers, typed: [Spindle.Header.optional "x-page" Wiretype.int]. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + As {!Query}, at [header.]: a value is read by its wiretype description, as [Wiretype.of_text] reads one; a name is matched without regard to case, and a value is read trimmed. diff --git a/core/health.mli b/core/health.mli index 23df97c..ae84450 100644 --- a/core/health.mli +++ b/core/health.mli @@ -4,6 +4,9 @@ own, and a check reads what it asks about as a route does, so they are made with the rest before any of it exists: + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/health.md]. + {[ let routes = app_routes @ Spindle.Health.routes [ Spindle_postgres.Pool.check db ] diff --git a/core/input.mli b/core/input.mli index e318146..b6ac10b 100644 --- a/core/input.mli +++ b/core/input.mli @@ -2,7 +2,9 @@ parameter, told apart only by where its text comes from, each read by its wiretype description as [Wiretype.of_text] reads one. {!Query}, {!Header}, the cookie inputs and {!Spindle.param} are built on this, and nothing - outside the library reaches it. *) + outside the library reaches it. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type source diff --git a/core/key.mli b/core/key.mli index 5f77d00..72c7cb4 100644 --- a/core/key.mli +++ b/core/key.mli @@ -1,5 +1,7 @@ (** The keys a signed or an encrypted cookie is made with ({!Spindle.Cookie}). + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ let () = match Sys.getenv_opt "COOKIE_SECRET" with diff --git a/core/key_repr.mli b/core/key_repr.mli index e82e50e..c0d6eaa 100644 --- a/core/key_repr.mli +++ b/core/key_repr.mli @@ -1,6 +1,7 @@ (** A key as the framework holds it: {!Key}'s, and the two more a signed and an encrypted cookie are made with, which nothing outside the framework can use. -*) + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type t type ring diff --git a/core/limits_repr.mli b/core/limits_repr.mli index 74c7b90..fffd2f6 100644 --- a/core/limits_repr.mli +++ b/core/limits_repr.mli @@ -1,6 +1,8 @@ (** What {!Server.Limits} and {!Route.Limits} are, underneath: the connection loop reads both, a route's in place of the server's where it gave one, and - {!Test} applies them as the loop does. *) + {!Test} applies them as the loop does. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type server = { max_body : int; diff --git a/core/log.ml b/core/log.ml index 3552ebb..42570ed 100644 --- a/core/log.ml +++ b/core/log.ml @@ -16,7 +16,13 @@ let level_name = function (* The reporter is set before any event loop, and runs on whichever thread logged, so it reads the system's clock itself rather than an Eio one. *) let now_with_ms ?tz_offset_s () = - let now = Ptime_clock.now () in + let now = + (Ptime_clock.now + [@litany.allow + "restricted-dependency: the reporter runs on whichever thread logged, \ + before and outside any event loop, so it has no Eio clock to be given"]) + () + in let date, ((hh, mm, ss), _) = Ptime.to_date_time ?tz_offset_s now in let _, ps = Ptime.Span.to_d_ps (Ptime.frac_s now) in (date, (hh, mm, ss), Int64.to_int (Int64.div ps 1_000_000_000L)) @@ -226,10 +232,19 @@ let write_pass () = update_registered (List.filter (fun other -> other != d)) end; Mutex.unlock d.lock; - Buffer.output_buffer Stdlib.stderr lines; + Buffer.output_buffer + (Stdlib.stderr + [@litany.allow + "restricted-dependency: the default sink writes its lines to stderr, \ + as Spindle.Log's .mli says"]) + lines; Buffer.clear lines) (Atomic.get registered); - flush Stdlib.stderr + flush + (Stdlib.stderr + [@litany.allow + "restricted-dependency: the default sink writes its lines to stderr, as \ + Spindle.Log's .mli says"]) (* A domain wakes the writer only with the first line of a pass, so a lone line is written at once, and the lines logged while the writer writes or @@ -251,7 +266,11 @@ let writer_started = Atomic.make false let start_writer () = if Atomic.compare_and_set writer_started false true then begin ignore (Domain.spawn writer : unit Domain.t); - at_exit (fun () -> Mutex.protect pass_lock write_pass) + (at_exit + [@litany.allow + "restricted-dependency: the lines still waiting are written as the \ + process ends, whichever switch has gone"]) (fun () -> + Mutex.protect pass_lock write_pass) end (* ------------------------------------------------------------------ *) @@ -355,8 +374,16 @@ let setup ?format ?(level = Some Logs.Info) ?(sources = []) ?out () = Printexc.record_backtrace true; (* Not Logs' own reporter mutex, which would be held while every line is formatted. *) - Logs.set_reporter (reporter ~format ~sink); - Logs.set_level level; + (Logs.set_reporter + [@litany.allow + "restricted-dependency: Spindle.Log.setup is what an executable calls to \ + configure its log"]) + (reporter ~format ~sink); + (Logs.set_level + [@litany.allow + "restricted-dependency: Spindle.Log.setup is what an executable calls to \ + configure its log"]) + level; List.iter (fun src -> let name = Logs.Src.name src in diff --git a/core/log.mli b/core/log.mli index eeea486..328671f 100644 --- a/core/log.mli +++ b/core/log.mli @@ -1,6 +1,9 @@ (** Logging: one line per event, on stderr, through {{:https://erratique.ch/software/logs}logs}. + Its page, with its examples: + [$(opam var spindle:doc)/pages/tutorial/logging.md]. + Every library that logs through [logs] lands here too, so a line from TLS arrives beside a line from the application in the same shape. A line inside a request carries that request's id; a fiber the request forks inherits it, diff --git a/core/melange.mli b/core/melange.mli index d994da8..ae442a5 100644 --- a/core/melange.mli +++ b/core/melange.mli @@ -3,6 +3,8 @@ route that calls it, so a browser written in OCaml calls the server with the server's own types and never with a path or a shape typed by hand. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + It is printed from the same walk as {!Openapi.document} and {!Zod.schemas}, so the three cannot disagree. The module is wiretype's for every component -- [Wiretype.Schema.Melange.module_], each a type and the functions that diff --git a/core/metrics.mli b/core/metrics.mli index 7e5480a..db0b92b 100644 --- a/core/metrics.mli +++ b/core/metrics.mli @@ -2,6 +2,9 @@ histograms, each with a fixed list of label names, registered on a registry the application makes and passes where it serves -- + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/metrics.md]. + {[ let metrics = Spindle.Metrics.create () diff --git a/core/middleware.mli b/core/middleware.mli index c7c0995..2cf6593 100644 --- a/core/middleware.mli +++ b/core/middleware.mli @@ -1,5 +1,8 @@ (** What applies to every route: a function from a handler to a handler. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/middleware.md]. + {[ let count_requests handler request = Atomic.incr count; diff --git a/core/multipart.mli b/core/multipart.mli index faca306..6a814b4 100644 --- a/core/multipart.mli +++ b/core/multipart.mli @@ -1,6 +1,8 @@ (** A body read a part at a time, as it arrives: what {!Spindle.multipart} hands a route, for an upload too large to hold. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ let rec each parts = let* part = Spindle.Multipart.next parts in diff --git a/core/openapi.mli b/core/openapi.mli index 2631857..5b865f3 100644 --- a/core/openapi.mli +++ b/core/openapi.mli @@ -1,6 +1,9 @@ (** An application's routes as an OpenAPI 3.2 document, and a page to read it by ({!val-routes} serves both). + Its page, with its examples: + [$(opam var spindle:doc)/pages/tutorial/openapi.md]. + Everything is read from {!Spindle.App.routes} and the routes' descriptions: requests from the decoding direction, answers from the encoding one, each description with a [kind] a component named by it. A route's codes are its diff --git a/core/out.mli b/core/out.mli index 5702224..cf262cd 100644 --- a/core/out.mli +++ b/core/out.mli @@ -1,5 +1,7 @@ (** JSON as the generator writes it: in the order it was built, two spaces to a - level, so a committed document changes only where the application did. *) + level, so a committed document changes only where the application did. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type t = | Null diff --git a/core/outgoing.mli b/core/outgoing.mli index 150c0f7..65b4474 100644 --- a/core/outgoing.mli +++ b/core/outgoing.mli @@ -1,6 +1,8 @@ (** What a handler adds to its answer as dependencies: the cookies and headers it sets, for {!Spindle.set_cookie}, {!Spindle.add_header} and whatever else - in the framework sets one, so each is set the one way. *) + in the framework sets one, so each is set the one way. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) val set_cookie : (Cookie.t -> unit) Dep.t val add_header : (string * string -> unit) Dep.t diff --git a/core/parameter.mli b/core/parameter.mli index 4d24b05..b8d756b 100644 --- a/core/parameter.mli +++ b/core/parameter.mli @@ -1,7 +1,9 @@ (** A text input's description -- a path segment's, a query parameter's, a header's, a cookie's, a form's field's -- as the router, the readers and the document see it: what [Wiretype.Schema.walk] says of it, and its kind's - name. Nothing outside the library reaches it. *) + name. Nothing outside the library reaches it. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) val schema : 'a Wiretype.t -> Wiretype.Schema.t (** What a request's input is, walked as a body read from a request is. *) diff --git a/core/path.mli b/core/path.mli index 892cf8d..75e2e6e 100644 --- a/core/path.mli +++ b/core/path.mli @@ -1,6 +1,8 @@ (** Paths: which URLs a route answers, and the names and types of their parameters. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ let user_id = Path.int "user_id" let posts = Path.(s "users" / user_id / s "posts") diff --git a/core/path_repr.mli b/core/path_repr.mli index 180a051..9a4c1c9 100644 --- a/core/path_repr.mli +++ b/core/path_repr.mli @@ -1,5 +1,7 @@ (** A path as the framework reads it: its segments and each parameter's - description. What {!Path} is, underneath, and what the router matches. *) + description. What {!Path} is, underneath, and what the router matches. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type unparsed = | Invalid diff --git a/core/query.mli b/core/query.mli index 8f22474..c261635 100644 --- a/core/query.mli +++ b/core/query.mli @@ -1,5 +1,7 @@ (** Query parameters, typed: [Spindle.Query.optional "page" Wiretype.int]. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + Each is a dependency that says what it reads, by name and by its wiretype description, which reads its text as [Wiretype.of_text] does. A value its description does not read -- outside its bounds or not -- is diff --git a/core/rate.mli b/core/rate.mli index b8d1b45..93681f0 100644 --- a/core/rate.mli +++ b/core/rate.mli @@ -1,6 +1,9 @@ (** How often a key may call a route: a limit, and the dependency that holds a request to it. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/rate-limits.md]. + {[ let sign_ins = Spindle.Rate.create ~limit:10 ~per:Mtime.Span.s () diff --git a/core/refusal.ml b/core/refusal.ml index a338092..bb21e50 100644 --- a/core/refusal.ml +++ b/core/refusal.ml @@ -147,12 +147,12 @@ let raised ex bt = let rate_limited ~retry_after_s = make Code.rate_limited - ~headers:[ ("retry-after", string_of_int (max 1 retry_after_s)) ] + ~headers:[ ("retry-after", string_of_int (Int.max 1 retry_after_s)) ] "That was asked too often. Please try again in a moment." let busy ?(retry_after_s = 1) ?detail () = make ?detail Code.busy - ~headers:[ ("retry-after", string_of_int (max 1 retry_after_s)) ] + ~headers:[ ("retry-after", string_of_int (Int.max 1 retry_after_s)) ] "The server is busy. Please try again in a moment." (* Nothing says a second try is faster, so no Retry-After. *) diff --git a/core/refusal.mli b/core/refusal.mli index eb4573d..c0d5039 100644 --- a/core/refusal.mli +++ b/core/refusal.mli @@ -1,5 +1,7 @@ (** A request answered with "no": a code, a sentence and a detail. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + The client is sent the code and the sentence as [{"error": code, "message": sentence}]. The code is what a client branches on and the sentence is what a person reads, so it is a sentence -- a diff --git a/core/request.mli b/core/request.mli index 2fc2e2b..8a12a95 100644 --- a/core/request.mli +++ b/core/request.mli @@ -1,5 +1,7 @@ (** What arrived: a method, a target, headers and a peer. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + A handler rarely reads this directly -- it asks for what it needs through {!Dep} -- but a dependency of the application's own is written against it. The body is not here: it is read only once the dependencies that do not need diff --git a/core/request_repr.ml b/core/request_repr.ml index aeef212..944b3a9 100644 --- a/core/request_repr.ml +++ b/core/request_repr.ml @@ -99,7 +99,9 @@ let client_gone t = fst t.client_gone (* A resolver may be told twice: by the stream that saw the client go, then by the exchange as it ends. *) -let mark_client_gone t = ignore (Eio.Promise.try_resolve (snd t.client_gone) ()) +let mark_client_gone t = + ignore (Eio.Promise.try_resolve (snd t.client_gone) () : bool) + let meth t = t.meth let version t = t.version let target t = t.target diff --git a/core/request_repr.mli b/core/request_repr.mli index 60a0bb0..b4cb8f1 100644 --- a/core/request_repr.mli +++ b/core/request_repr.mli @@ -1,6 +1,8 @@ (** A request as the framework holds it: what {!Request} is, underneath, and the one thing only the framework does to one, setting the route it matched. Each - value {!Request} exports is documented there. *) + value {!Request} exports is documented there. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) (** How reading a body failed: what {!Body.error} is. *) type body_error = Too_large | Unreadable of string | Over_budget diff --git a/core/response.mli b/core/response.mli index 526ff50..ac8e206 100644 --- a/core/response.mli +++ b/core/response.mli @@ -1,5 +1,7 @@ (** What a handler answers. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + How an answer is framed, and whether its connection lasts, is the server's to say: [Content-Length], [Transfer-Encoding], [Connection], [Keep-Alive], [Upgrade], [TE] and [Trailer] are written by the server and by nothing else, diff --git a/core/returns.mli b/core/returns.mli index 0ee34ec..1d84495 100644 --- a/core/returns.mli +++ b/core/returns.mli @@ -4,6 +4,8 @@ cannot return anything else, and it is known without running the route -- which is how the API's document is written. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + {[ Spindle.get Path.(s "users" / user_id) (Returns.json user_json) (let+ id = Spindle.param user_id in find_user id) diff --git a/core/returns_repr.mli b/core/returns_repr.mli index aa84c73..744d063 100644 --- a/core/returns_repr.mli +++ b/core/returns_repr.mli @@ -1,6 +1,8 @@ (** What a route returns: its model, what it describes, and how its result becomes a response. What {!Returns} is, underneath: a model is made only by - {!Returns}. *) + {!Returns}. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) (** A model, typed by what the route's handler answers. *) type 'r t = diff --git a/core/route.mli b/core/route.mli index 83410d6..0e3ed25 100644 --- a/core/route.mli +++ b/core/route.mli @@ -2,6 +2,9 @@ value, so an endpoint is declared in one place, in the order a request line has it. + Its page, with its examples: + [$(opam var spindle:doc)/pages/tutorial/routes.md]. + {[ let order_id = Path.int "order_id" diff --git a/core/route_repr.mli b/core/route_repr.mli index 197e561..3c0cb28 100644 --- a/core/route_repr.mli +++ b/core/route_repr.mli @@ -1,6 +1,8 @@ (** A route: what it says of itself, its segments, and how it answers. Made only here, through {!Spindle.get} and its siblings; answered only by {!App}. What - {!Route} is, underneath. *) + {!Route} is, underneath. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) type param = { name : string; diff --git a/core/scalar.mli b/core/scalar.mli index 13b5954..08581c6 100644 --- a/core/scalar.mli +++ b/core/scalar.mli @@ -1,3 +1,5 @@ -(** Scalar's standalone script, as the file under [scalar/] holds it. *) +(** Scalar's standalone script, as the file under [scalar/] holds it. + + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *) val js : string diff --git a/core/server.ml b/core/server.ml index a83c46d..51f0b64 100644 --- a/core/server.ml +++ b/core/server.ml @@ -573,22 +573,30 @@ let write_stream ?gzip ~clock ~limits ~deadline ~framing req out | Counted _ -> true (* Ends with the connection, so nothing may follow. *) | Raw -> ( - try - Eio.Buf_write.string out.buf (gzip_trailer ()); - flush ~limits ~deadline out; - false - with + (try + Eio.Buf_write.string out.buf (gzip_trailer ()); + flush ~limits ~deadline out; + false + with | (Eio.Cancel.Cancelled _ | Stalled) as ex -> raise ex | _ -> false) + [@litany.allow + "suspicious-catch-all-handler: a trailer that cannot be \ + written ends the connection whatever stopped it, and \ + cancellation and a stall are raised again above"]) | Chunked -> ( - try - Write.chunk out.buf (gzip_trailer ()); - Write.last_chunk out.buf; - flush ~limits ~deadline out; - true - with + (try + Write.chunk out.buf (gzip_trailer ()); + Write.last_chunk out.buf; + flush ~limits ~deadline out; + true + with | (Eio.Cancel.Cancelled _ | Stalled) as ex -> raise ex - | _ -> false))) + | _ -> false) + [@litany.allow + "suspicious-catch-all-handler: a trailer that cannot be \ + written ends the connection whatever stopped it, and \ + cancellation and a stall are raised again above"]))) | exception (Eio.Cancel.Cancelled _ as ex) -> log_end "connection closed"; raise ex @@ -674,7 +682,7 @@ let request_body ~limits ~state ~deadline ~framing ~reader ~req ic out progress if progress.cleared_to_send || too_large then Ok () else ( Write.continue out.buf; - match flush ~limits ~deadline out with + (match flush ~limits ~deadline out with | () -> progress.cleared_to_send <- true; Ok () @@ -684,6 +692,9 @@ let request_body ~limits ~state ~deadline ~framing ~reader ~req ic out progress | exception _ -> Request_repr.mark_client_gone req; Error (Body.Unreadable "the client has gone")) + [@litany.allow + "suspicious-catch-all-handler: a write that fails for any reason is a \ + client that has gone, and cancellation is raised again above"]) in let failed = function | `Too_large -> Error Body.Too_large @@ -1093,7 +1104,7 @@ let serve_connection ~clock ~read_clock ~limits ~trace ~instruments ~state let ic = Eio.Buf_read.of_flow (Deadline.reading deadline flow) - ~initial_size:(min io_buffer_bytes limits.max_header_bytes) + ~initial_size:(Int.min io_buffer_bytes limits.max_header_bytes) ~max_size:limits.max_header_bytes in (* Which side ends the connection: when it is the server, the client may @@ -1500,14 +1511,24 @@ let stop_on_signals ~sw () = Eio.Condition.broadcast signal in List.iter - (fun s -> Sys.set_signal s (Sys.Signal_handle on_signal)) + (fun s -> + (Sys.set_signal + [@litany.allow + "restricted-dependency: Spindle.serve is the program's server: it \ + stops on SIGTERM and SIGINT, as its .mli says"]) + s (Sys.Signal_handle on_signal)) [ Sys.sigterm; Sys.sigint ]; Eio.Fiber.fork_daemon ~sw (fun () -> Eio.Condition.loop_no_mutex signal (fun () -> if Atomic.get signalled then Some () else None); (* A second signal stops at once: Ctrl-C twice means now. *) List.iter - (fun s -> Sys.set_signal s Sys.Signal_default) + (fun s -> + (Sys.set_signal + [@litany.allow + "restricted-dependency: a second signal stops at once, so the \ + handlers Spindle.serve set are its to remove"]) + s Sys.Signal_default) [ Sys.sigterm; Sys.sigint ]; Eio.Promise.resolve stop (); `Stop_daemon); diff --git a/core/server.mli b/core/server.mli index 60139c0..a15ac3b 100644 --- a/core/server.mli +++ b/core/server.mli @@ -1,5 +1,8 @@ (** Serving an {!App}: the connection loop. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/serving.md]. + The loop is Spindle's own, and so is every byte it reads and writes. Every decision about a connection is made here: where a head and a body end, whether a connection carries another request, and how long anything may diff --git a/core/session.mli b/core/session.mli index f3c4941..730b38d 100644 --- a/core/session.mli +++ b/core/session.mli @@ -1,6 +1,9 @@ (** Sessions kept on the server: a visit's data in a store, and a cookie that holds only its id. + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/cookies.md]. + {[ let session = Spindle.Session.create diff --git a/core/spindle.ml b/core/spindle.ml index c01b96d..0dc473d 100644 --- a/core/spindle.ml +++ b/core/spindle.ml @@ -236,9 +236,18 @@ let serve ?(port = 8080) ?host ?domains ?resources ?middleware ?refuses or written to stderr where the program set no log up, since Logs drops every line until a reporter is set. *) let stop_because why = - if Logs.reporter () == Logs.nop_reporter then prerr_endline why + if Logs.reporter () == Logs.nop_reporter then + (prerr_endline + [@litany.allow + "restricted-dependency: Logs drops every line until a reporter is set, \ + so the reason a server stops is written to stderr"]) + why else L.err (fun f -> f "%s" why); - exit 1 + (exit + [@litany.allow + "suspicious-exit-in-library: a server that cannot start is stopped where \ + an orchestrator sees it, as Spindle.serve's .mli says"]) + 1 in let instance = match @@ -264,7 +273,11 @@ let serve ?(port = 8080) ?host ?domains ?resources ?middleware ?refuses else Printf.sprintf "%s:%d" host port in Option.value ready ~default:(fun where -> - Printf.printf "Listening on http://%s (%s)\n%!" authority where) + (Printf.printf + [@litany.allow + "restricted-dependency: Spindle.serve prints the address it listens \ + on unless given ?ready, as its .mli says"]) + "Listening on http://%s (%s)\n%!" authority where) in match Server.run ~sw ~net:(Eio.Stdenv.net env) diff --git a/core/spindle.mli b/core/spindle.mli index 606d293..786b411 100644 --- a/core/spindle.mli +++ b/core/spindle.mli @@ -1,5 +1,7 @@ (** Spindle: a web framework on Eio. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + An application is a list of {!Route}s. A route is one value -- a method, a {!Path}, what it {!Returns} and a handler -- and a handler asks for everything it needs as {!Dep}endencies, a path parameter as much as the diff --git a/core/static.mli b/core/static.mli index 1e9089e..237daa3 100644 --- a/core/static.mli +++ b/core/static.mli @@ -1,5 +1,8 @@ (** A directory of files -- a built site, its assets -- served by the process. + Its page, with its examples: + [$(opam var spindle:doc)/pages/tutorial/static-files.md]. + {[ Spindle.serve env (routes @ [ Spindle.Static.directory "dist" ]) ]} diff --git a/core/test.ml b/core/test.ml index 9c7256f..d590b48 100644 --- a/core/test.ml +++ b/core/test.ml @@ -200,12 +200,12 @@ let call ?(now = Ptime.epoch) ?(peer = "127.0.0.1") ?proxied ?proxy_header Buffer.contents b (* What the wire would carry: no byte past the length it said. *) | Wire.Counted (n, stream) -> - let b = Buffer.create (min n part_bytes) in + let b = Buffer.create (Int.min n part_bytes) in ignore (stream.produce (fun s -> let room = n - Buffer.length b in Buffer.add_string b - (String.sub s 0 (min room (String.length s))); + (String.sub s 0 (Int.min room (String.length s))); if String.length s > room then Error Response.Gone else Ok ()) : (unit, Response.gone) result); Buffer.contents b); @@ -394,7 +394,12 @@ let events ?(now = Ptime.epoch) ?(headers = []) ?(meth = `GET) ?body app target { status = Status.of_int (Status.to_int wire.status); headers = wire.headers; - body = (match wire.body with Wire.Bytes s -> s | _ -> ""); + body = + (match wire.body with + | Wire.Bytes s -> s + | Wire.Nothing | Wire.Chunks _ | Wire.Counted _ | Wire.Until_close _ + | Wire.Connection _ -> + ""); } type websocket_error = Refused of response | Ended of Websocket.error @@ -467,7 +472,12 @@ let websocket ?(now = Ptime.epoch) ?(headers = []) app protocol target f = { status = Status.of_int (Status.to_int wire.status); headers = wire.headers; - body = (match wire.body with Wire.Bytes s -> s | _ -> ""); + body = + (match wire.body with + | Wire.Bytes s -> s + | Wire.Nothing | Wire.Chunks _ | Wire.Counted _ + | Wire.Until_close _ | Wire.Connection _ -> + ""); }) let header r name = diff --git a/core/test.mli b/core/test.mli index bcec26a..be8e4a8 100644 --- a/core/test.mli +++ b/core/test.mli @@ -1,5 +1,8 @@ (** Calling an application in-process: no socket, no port, and a clock the test - sets. *) + sets. + + Its page, with its examples: + [$(opam var spindle:doc)/pages/guide/testing.md]. *) type response = { status : Spindle_http.Status.t; diff --git a/core/wire.mli b/core/wire.mli index a2e052e..1a84e16 100644 --- a/core/wire.mli +++ b/core/wire.mli @@ -1,6 +1,8 @@ (** A response as it goes out for one request: the status, every header, and what follows them. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + One function decides it, and both the server and {!Test.call} use it, so a test sees the head the wire gets. The two differ only in [Connection], which belongs to the connection and not to the response, and which the server diff --git a/core/zod.mli b/core/zod.mli index 35827e9..0846df7 100644 --- a/core/zod.mli +++ b/core/zod.mli @@ -2,6 +2,8 @@ schemas, for a client to parse what the server sends with the same shapes the server describes. + Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. + It is printed from the same walk as {!Openapi.document}, so the two cannot disagree. Each component is [export const Schema] with its type [z.infer]red beside it, each after those it refers to, the refusal among diff --git a/dune b/dune index 7916c8c..b089ffc 100644 --- a/dune +++ b/dune @@ -14,11 +14,54 @@ (: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`: the spindle package installs it whole, so -; $(opam var spindle:doc) holds llms.txt and each page. +; by `make docs`: every package installs it whole, so a package installed +; alone, spindle-http without spindle, still holds llms.txt and each page in +; $(opam var :doc). (install (package spindle) (section doc) (source_trees (agents as .))) + +(install + (package spindle-cli) + (section doc) + (source_trees + (agents as .))) + +(install + (package spindle-client) + (section doc) + (source_trees + (agents as .))) + +(install + (package spindle-http) + (section doc) + (source_trees + (agents as .))) + +(install + (package spindle-mcp) + (section doc) + (source_trees + (agents as .))) + +(install + (package spindle-mcp-client) + (section doc) + (source_trees + (agents as .))) + +(install + (package spindle-postgres) + (section doc) + (source_trees + (agents as .))) + +(install + (package spindle-sqlite) + (section doc) + (source_trees + (agents as .))) diff --git a/dune-project b/dune-project index b3c2a56..4ed3ec1 100644 --- a/dune-project +++ b/dune-project @@ -187,6 +187,11 @@ (and :with-dev-setup (= 0.29.0))) + (hypha-litany + (and + :with-dev-setup + (>= 1.3.0) + (< 2.0.0))) ; The renderers the page examples are written with: a page is a string ; to Spindle, so none of them is a dependency of the framework. (htmlit diff --git a/http/accept.mli b/http/accept.mli index 72be28a..b648bdb 100644 --- a/http/accept.mli +++ b/http/accept.mli @@ -1,6 +1,9 @@ (** Content negotiation, as RFC 9110 §12 writes it: what a request accepts, each with its weight, and choosing among what a route can answer. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ match Accept.parse_media "text/csv;q=0.9, application/json" with | Ok ranges -> Accept.choose_media ranges [ csv; json ] (* Some json *) diff --git a/http/auth.ml b/http/auth.ml index 7ee41f3..778cfb9 100644 --- a/http/auth.ml +++ b/http/auth.ml @@ -49,7 +49,8 @@ let credentials = (* Each element of a challenge list begins a challenge or adds a parameter to the one before it: a token followed by "=" is a parameter. *) -type element = Starts of t | Continues of (string * string) +type parameter = string * string +type element = Starts of t | Continues of parameter let element = A.( diff --git a/http/auth.mli b/http/auth.mli index fe10161..8f54703 100644 --- a/http/auth.mli +++ b/http/auth.mli @@ -2,6 +2,9 @@ in [Authorization] or [Proxy-Authorization], and the challenges a [401] or a [407] names in [WWW-Authenticate] or [Proxy-Authenticate]. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Auth.credentials "Bearer mF_9.B5f-4.1JqM" = Ok { scheme = "bearer"; value = Token68 "mF_9.B5f-4.1JqM" } diff --git a/http/base64url.mli b/http/base64url.mli index 6a239ca..9db3352 100644 --- a/http/base64url.mli +++ b/http/base64url.mli @@ -1,5 +1,8 @@ (** Base64url without padding, as JOSE writes every part of a key and a - signature (RFC 7515 §2). *) + signature (RFC 7515 §2). + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) val decode : string -> string option (** The octets, where the text is base64url in its one canonical form: no diff --git a/http/cache_control.mli b/http/cache_control.mli index a4da550..c9b913d 100644 --- a/http/cache_control.mli +++ b/http/cache_control.mli @@ -1,6 +1,9 @@ (** [Cache-Control], as RFC 9111 §5.2 writes it: directives, each with an argument or none. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Cache_control.parse {|max-age=60, private="Set-Cookie"|} = Ok [ ("max-age", Some "60"); ("private", Some "Set-Cookie") ] diff --git a/http/calendar.mli b/http/calendar.mli index 83c6ec3..2fef681 100644 --- a/http/calendar.mli +++ b/http/calendar.mli @@ -1,4 +1,7 @@ -(** The names an HTTP-date gives a day of the week and a month. *) +(** The names an HTTP-date gives a day of the week and a month. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) val weekdays : string array (** Three-letter names, Sunday first, as [Ptime.weekday_num] numbers them. *) diff --git a/http/connection.mli b/http/connection.mli index c31b3cb..508542e 100644 --- a/http/connection.mli +++ b/http/connection.mli @@ -1,5 +1,8 @@ (** A connection once a protocol spoken after HTTP has it: a server's after it - answered [101 Switching Protocols], a client's after its handshake. *) + answered [101 Switching Protocols], a client's after its handshake. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) type t = { reader : Eio.Buf_read.t; diff --git a/http/context.mli b/http/context.mli index 5abb9a8..cfd5784 100644 --- a/http/context.mli +++ b/http/context.mli @@ -1,5 +1,8 @@ (** The request a fiber runs for: its id, its place in a trace, and the span it - records, if any -- what {!Log} and {!Trace} are both built on. *) + records, if any -- what {!Log} and {!Trace} are both built on. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) type value = [ `String of string | `Int of int | `Float of float | `Bool of bool ] diff --git a/http/date.mli b/http/date.mli index e60bbdf..31af3f0 100644 --- a/http/date.mli +++ b/http/date.mli @@ -2,6 +2,9 @@ IMF-fixdate a sender writes ({!to_string}), and the two obsolete forms a recipient must still accept. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ (* each [Some] of the instant 1994-11-06T08:49:37Z *) let imf = Date.parse ~now "Sun, 06 Nov 1994 08:49:37 GMT" diff --git a/http/etag.mli b/http/etag.mli index 5e1d700..8c3f289 100644 --- a/http/etag.mli +++ b/http/etag.mli @@ -1,6 +1,9 @@ (** Entity tags, as RFC 9110 §8.8.3 writes them, and the two ways §8.8.3.2 compares them. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Etag.parse {|W/"xyzzy"|} = Ok { weak = true; opaque = "xyzzy" } Etag.condition {|"a", W/"b"|} = Ok (Tags [ ...; ... ]) diff --git a/http/event_stream.mli b/http/event_stream.mli index dbef38b..3cce24f 100644 --- a/http/event_stream.mli +++ b/http/event_stream.mli @@ -3,6 +3,9 @@ one module, so both ends of a stream have one account of where an event ends. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Event_stream.event ~name:"state" ~id:"7" {|{"n":1}|} = Ok "event: state\nid: 7\ndata: {\"n\":1}\n\n" diff --git a/http/field.mli b/http/field.mli index 64c6c64..7179303 100644 --- a/http/field.mli +++ b/http/field.mli @@ -1,6 +1,9 @@ (** The field grammar every message shares: RFC 9110's tokens, a field line split and checked, a list field's elements, and a field found by name. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + Both readers and the writer use this module and no grammar of their own, so what one of them refuses the others cannot let through. *) diff --git a/http/forwarded.mli b/http/forwarded.mli index 6c70d25..4c71b0f 100644 --- a/http/forwarded.mli +++ b/http/forwarded.mli @@ -2,6 +2,9 @@ what it saw -- who asked it, on which of its interfaces, for which host, over which protocol. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Forwarded.parse {|for=192.0.2.60;proto=https, for="[2001:db8::1]:47011"|} ]} diff --git a/http/frame.ml b/http/frame.ml index 2536d5d..39b9361 100644 --- a/http/frame.ml +++ b/http/frame.ml @@ -70,7 +70,7 @@ let read_payload r h ~on_piece buf = let rec go at = if at < h.length then ( R.ensure r 1; - let n = min (h.length - at) (R.buffered_bytes r) in + let n = Int.min (h.length - at) (R.buffered_bytes r) in let piece = R.take n r in Buffer.add_string buf (match h.mask with None -> piece | Some m -> apply_mask m ~at piece); @@ -96,7 +96,7 @@ let write w ?mask ~fin opcode payload ~flush = W.BE.uint64 w (Int64.of_int length)); Option.iter (W.string w) mask; let rec go at = - let n = min write_piece_bytes (length - at) in + let n = Int.min write_piece_bytes (length - at) in let s = String.sub payload at n in W.string w (match mask with None -> s | Some m -> apply_mask m ~at s); match flush () with diff --git a/http/frame.mli b/http/frame.mli index 0733abc..64e7278 100644 --- a/http/frame.mli +++ b/http/frame.mli @@ -1,6 +1,9 @@ (** A WebSocket's frames, as RFC 6455 §5 spells them: read from a buffer and written to one, and nothing about what a conversation of them means. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + A payload is read in pieces, however large it is, so the reader's buffer never has to hold a whole frame: a server's is the connection's own, sized for a request head. *) diff --git a/http/framing.ml b/http/framing.ml index 647be7c..3d65ff4 100644 --- a/http/framing.ml +++ b/http/framing.ml @@ -144,7 +144,7 @@ let read_crlf_line r = let take_buffered r n = read_or_break r (fun ic -> Eio.Buf_read.ensure ic 1; - Eio.Buf_read.take (min n (Eio.Buf_read.buffered_bytes ic)) ic) + Eio.Buf_read.take (Int.min n (Eio.Buf_read.buffered_bytes ic)) ic) let is_hex = function | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' -> true @@ -213,7 +213,7 @@ let rec next r n = r.state <- Done; None) else - let s = take_buffered r (min n left) in + let s = take_buffered r (Int.min n left) in r.consumed <- r.consumed + String.length s; Some s | Chunked, Size_line -> ( @@ -244,7 +244,7 @@ let rec next r n = r.consumed <- r.consumed + String.length s; Some s | Chunked, In_chunk left -> - let s = take_buffered r (min n left) in + let s = take_buffered r (Int.min n left) in let left = left - String.length s in r.consumed <- r.consumed + String.length s; if left = 0 then ( diff --git a/http/framing.mli b/http/framing.mli index e8b57ab..992eaa7 100644 --- a/http/framing.mli +++ b/http/framing.mli @@ -1,6 +1,9 @@ (** Where a body ends: decided from its message's head, then read off the connection a piece at a time. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + Whatever this cannot delimit exactly is refused rather than guessed at, because a body that ends in the wrong place leaves its remainder on the connection, to be read as the next request -- which, behind a proxy that diff --git a/http/grammar.mli b/http/grammar.mli index 05f4f52..ac9a0cb 100644 --- a/http/grammar.mli +++ b/http/grammar.mli @@ -1,6 +1,9 @@ (** RFC 9110 §5.6's pieces, which field values are built from, as parsers: one token, one quoted string and one list of parameters, so every structure that - holds them reads them the same way. *) + holds them reads them the same way. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) val is_tchar : char -> bool val ows : unit Angstrom.t diff --git a/http/head.ml b/http/head.ml index 76fc57d..5b654ae 100644 --- a/http/head.ml +++ b/http/head.ml @@ -283,7 +283,7 @@ module Request = struct [ '/'; '?'; '#' ] with | [] -> String.length rest - | ends -> List.fold_left min (String.length rest) ends + | ends -> List.fold_left Int.min (String.length rest) ends in let authority = String.sub rest 0 stop in if String.contains authority '@' then diff --git a/http/head.mli b/http/head.mli index 80a9a40..899e56e 100644 --- a/http/head.mli +++ b/http/head.mli @@ -1,6 +1,9 @@ (** A message's head, read off a connection: its start line and its fields, and nothing a parser could read two ways. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + A head RFC 9112 forbids is refused rather than repaired, because two readers that repair it differently -- this one and a proxy in front of it -- disagree about where one message ends and the next begins. The one repair diff --git a/http/instant.mli b/http/instant.mli index d47eef8..85034eb 100644 --- a/http/instant.mli +++ b/http/instant.mli @@ -1,6 +1,9 @@ (** Instants, as a [Ptime.t], and the waits between them, as an [Mtime.Span.t]: what a clock is read into, the one place a wait until an instant is worked - out, and a sleep for code no Eio loop runs. *) + out, and a sleep for code no Eio loop runs. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) val of_clock : _ Eio.Time.clock -> Ptime.t (** The clock's time now. A clock reads a time within the years 0000 to 9999, diff --git a/http/jwk.mli b/http/jwk.mli index 72d569e..e26c879 100644 --- a/http/jwk.mli +++ b/http/jwk.mli @@ -3,6 +3,9 @@ requires of RS256; EC on P-256 (RFC 7518 §6.2); and OKP on Ed25519 (RFC 8037 §2). A private member a key carries is not read. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ match Jwk.set_of_string body with | Ok keys -> Jws.verify jws ~keys diff --git a/http/jws.mli b/http/jws.mli index c5853ed..6d730ad 100644 --- a/http/jws.mli +++ b/http/jws.mli @@ -3,6 +3,9 @@ ES256 or EdDSA. No other algorithm is checked: ["none"] signs nothing, and an HMAC's key is a secret both ends hold, which a public key set never is. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ let* jws = Jws.of_string token in let* payload = Jws.verify jws ~keys in diff --git a/http/local.mli b/http/local.mli index 8bf8693..d35d468 100644 --- a/http/local.mli +++ b/http/local.mli @@ -1,5 +1,8 @@ (** What belongs to the domain a fiber runs on. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + Eio forks a fiber only onto a switch of the domain it is on: a switch made at startup cannot take a fiber forked from a request on another domain. So every domain Spindle runs has a switch of its own, which lasts as long as diff --git a/http/log.mli b/http/log.mli index 4cd6341..3d975d9 100644 --- a/http/log.mli +++ b/http/log.mli @@ -1,6 +1,9 @@ (** What a line is made of, on either end of a call: the framework's source, a line's structured fields, and the request a fiber runs for. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + The reporter that writes a line is [Spindle.Log]'s; this is what a server and a client both write lines with, so that a call made while a request is answered logs under that request. *) diff --git a/http/media_type.mli b/http/media_type.mli index 066a0ce..276be08 100644 --- a/http/media_type.mli +++ b/http/media_type.mli @@ -1,6 +1,9 @@ (** A media type, as [Content-Type] holds one (RFC 9110 §8.3.1): a type, a subtype and parameters. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Media_type.parse {|application/json; charset="utf-8"|} = Ok diff --git a/http/meth.mli b/http/meth.mli index 6986d82..b6e4009 100644 --- a/http/meth.mli +++ b/http/meth.mli @@ -1,6 +1,9 @@ (** Request methods: every one RFC 9110 §9 defines, and [PATCH] (RFC 5789); [`Other m] is any other, spelled as it came. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {b The set is closed at 1.0.} A method registered later stays [`Other m] for every 1.x release, so a match on this type keeps its meaning across them. *) diff --git a/http/multipart.ml b/http/multipart.ml index cf4b955..bf6edef 100644 --- a/http/multipart.ml +++ b/http/multipart.ml @@ -170,7 +170,7 @@ let skip_preamble t = Ok () | None -> t.position <- - max t.position + Int.max t.position (Buffer.length t.buffer - String.length t.delimiter + 1); let* got = pull_more t in if got then search () else malformed "the body has no boundary" @@ -252,7 +252,7 @@ let read_part_head t = if available t > t.max_head then Error Head_too_large else let searched = - max 0 (available t - (String.length blank_line - 1)) + Int.max 0 (available t - (String.length blank_line - 1)) in let* got = pull_more t in if got then search ~searched diff --git a/http/multipart.mli b/http/multipart.mli index a6b7810..1013bb4 100644 --- a/http/multipart.mli +++ b/http/multipart.mli @@ -2,6 +2,9 @@ what a browser posts from a form with a file in it, read a part at a time as it arrives. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ let parts = Multipart.create ~boundary ~max_head:8192 pull in match Multipart.next parts with diff --git a/http/private.mli b/http/private.mli index 4b3480a..3cbda5b 100644 --- a/http/private.mli +++ b/http/private.mli @@ -2,7 +2,10 @@ connection, where a body ends, a message written, and a WebSocket run over a connection. They are reached here because both ends are built on them, and are not covered by the library's version -- any may change in any release. - An application names none of them. *) + An application names none of them. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) module Head = Head module Framing = Framing diff --git a/http/range.ml b/http/range.ml index 8531312..fe2a6c1 100644 --- a/http/range.ml +++ b/http/range.ml @@ -41,8 +41,10 @@ let parse = G.parse ~what:"a Range value" specifier let satisfy ~length = function | From first when first < length -> Some (first, length - 1) - | Span (first, last) when first < length -> Some (first, min last (length - 1)) - | Suffix n when n > 0 && length > 0 -> Some (max 0 (length - n), length - 1) + | Span (first, last) when first < length -> + Some (first, Int.min last (length - 1)) + | Suffix n when n > 0 && length > 0 -> + Some (Int.max 0 (length - n), length - 1) | From _ | Span _ | Suffix _ -> None let content_range ~first ~last ~length = diff --git a/http/range.mli b/http/range.mli index 3157f56..da0123f 100644 --- a/http/range.mli +++ b/http/range.mli @@ -1,6 +1,9 @@ (** Byte ranges, as RFC 9110 §14 writes them: a request's [Range], and the [Content-Range] of an answer to one. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Range.parse "bytes=0-499, -500" = Ok (Bytes [ Span (0, 499); Suffix 500 ]) Range.satisfy ~length:1000 (Suffix 500) = Some (500, 999) diff --git a/http/spindle_http.mli b/http/spindle_http.mli index b683220..00d0ba5 100644 --- a/http/spindle_http.mli +++ b/http/spindle_http.mli @@ -1,7 +1,10 @@ (** HTTP as both ends speak it: what a server and a client share, and what an application names -- statuses, methods, fields and the values they carry, the messages spoken after HTTP, and what a line is logged with. Each - module's [.mli] is its reference. *) + module's [.mli] is its reference. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) (** {1 Messages} *) diff --git a/http/status.mli b/http/status.mli index 113ef73..9c85f95 100644 --- a/http/status.mli +++ b/http/status.mli @@ -1,5 +1,8 @@ (** The statuses a handler may answer with. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + Every status RFC 9110 §15 defines is a constructor, and so are those of RFC 6585, 7725, 8297 and 8470 -- [`Precondition_required], [`Too_many_requests], [`Request_header_fields_too_large], [`Network_authentication_required], diff --git a/http/structured.mli b/http/structured.mli index bd31573..6981966 100644 --- a/http/structured.mli +++ b/http/structured.mli @@ -1,6 +1,9 @@ (** Structured Fields, as RFC 9651 defines them for the fields built on it: an item, a list or a dictionary, each value with parameters. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Structured.dictionary "a=1, b;q=5, c=(x \"y\")" = Ok diff --git a/http/trace.mli b/http/trace.mli index 48400da..7d08de6 100644 --- a/http/trace.mli +++ b/http/trace.mli @@ -2,6 +2,9 @@ the W3C trace {!Log} already carries, so a server, the calls it makes and the statements it runs are one trace. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + Nothing is recorded unless an {!type-exporter} is given where the request begins, and the trace is kept: a trace begun here at the exporter's ratio, one joined from a caller as the caller's [traceparent] says. Everything else diff --git a/http/urlencoded.mli b/http/urlencoded.mli index 9e2e88e..f290b9a 100644 --- a/http/urlencoded.mli +++ b/http/urlencoded.mli @@ -1,6 +1,9 @@ (** [application/x-www-form-urlencoded], as the WHATWG URL standard reads and writes it: what a browser posts from a form with no file in it. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ Urlencoded.parse "name=Kim+Lee&tag=a&tag=b%26c" = [ ("name", "Kim Lee"); ("tag", "a"); ("tag", "b&c") ] diff --git a/http/version.mli b/http/version.mli index a84a616..46d43c7 100644 --- a/http/version.mli +++ b/http/version.mli @@ -1,4 +1,7 @@ (** The HTTP/1 versions a message is spoken in: what a request says it speaks - ([Spindle.Request.version]), and what a test asks to be called with. *) + ([Spindle.Request.version]), and what a test asks to be called with. + + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. *) type t = Http_1_0 | Http_1_1 diff --git a/http/websocket.ml b/http/websocket.ml index 627595e..a19a624 100644 --- a/http/websocket.ml +++ b/http/websocket.ml @@ -377,7 +377,9 @@ let read_frames t ~side ~max_message ~heard reader = fail t Protocol_error "a new message before the last one ended" | None -> - let b = Buffer.create (min h.length first_buffer_bytes) in + let b = + Buffer.create (Int.min h.length first_buffer_bytes) + in Frame.read_payload reader h ~on_piece:heard b; if h.fin then deliver h.opcode b else next (Some (h.opcode, b))) @@ -427,7 +429,8 @@ let read_frames t ~side ~max_message ~heard reader = | Frame.Text -> hand_over t (Message (Text_data s)); next None - | _ -> + | Frame.Binary | Frame.Continuation | Frame.Close | Frame.Ping | Frame.Pong + -> hand_over t (Message (Binary_data s)); next None in diff --git a/http/websocket.mli b/http/websocket.mli index df16aa8..edd3fe0 100644 --- a/http/websocket.mli +++ b/http/websocket.mli @@ -1,6 +1,9 @@ (** WebSockets, served and called, in one model: a protocol says what each side sends, and each end holds a socket typed from its own side. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + {[ type said = { text : string } [@@deriving wiretype] diff --git a/http/write.mli b/http/write.mli index be60a4a..f5d228a 100644 --- a/http/write.mli +++ b/http/write.mli @@ -2,6 +2,9 @@ an [Eio.Buf_write.t]. Nothing here flushes; when the bytes leave is the caller's to decide. + Its documents, a page for each part: + [$(opam var spindle-http:doc)/llms.txt]. + A head is checked whole before any of it is written, so a refused one leaves nothing on the connection. *) diff --git a/litany b/litany new file mode 100644 index 0000000..3459a3b --- /dev/null +++ b/litany @@ -0,0 +1,230 @@ +; 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/**))) + +; Spindle's own. + +(per-path + (paths cli/**) + (ignore restricted-dependency suspicious-exit-in-library) + (reason "spindle-cli is a command line: it prints its answer and its errors and exits with its status")) diff --git a/mcp-client/protocol/spindle_mcp_protocol.mli b/mcp-client/protocol/spindle_mcp_protocol.mli index 7a04bc3..74e8df1 100644 --- a/mcp-client/protocol/spindle_mcp_protocol.mli +++ b/mcp-client/protocol/spindle_mcp_protocol.mli @@ -1,6 +1,9 @@ (** The Model Context Protocol's messages, as both ends read and write them: JSON-RPC 2.0 as MCP 2026-07-28 uses it, and the protocol's version. It does - no I/O, so the server and the client read one message one way. *) + no I/O, so the server and the client read one message one way. + + Its documents, a page for each part: + [$(opam var spindle-mcp-client:doc)/llms.txt]. *) val version : string (** ["2026-07-28"]: the one version spoken, by both ends. *) diff --git a/mcp-client/spindle_mcp_client.mli b/mcp-client/spindle_mcp_client.mli index 0d5a370..10cf374 100644 --- a/mcp-client/spindle_mcp_client.mli +++ b/mcp-client/spindle_mcp_client.mli @@ -2,6 +2,9 @@ the Model Context Protocol, 2026-07-28, on {!Spindle_client} alone: a program that only calls another server installs and links no framework. + Its documents, a page for each part: + [$(opam var spindle-mcp-client:doc)/llms.txt]. + {[ let weather = Spindle_mcp_client.create client ~url:"https://weather.example.com/mcp" diff --git a/mcp/spindle_mcp.mli b/mcp/spindle_mcp.mli index 5b8f865..ca59c34 100644 --- a/mcp/spindle_mcp.mli +++ b/mcp/spindle_mcp.mli @@ -2,6 +2,11 @@ and watches resources through, added to the application's own, as {!Spindle.Health.routes} are. + Its documents, a page for each part: [$(opam var spindle-mcp:doc)/llms.txt]. + + Its page, with its examples: + [$(opam var spindle-mcp:doc)/pages/guide/mcp.md]. + {[ let forecast = Spindle_mcp.tool "get_forecast" ~scope:"weather:read" query_json diff --git a/postgres/bounds.mli b/postgres/bounds.mli index 53a5625..c332f6a 100644 --- a/postgres/bounds.mli +++ b/postgres/bounds.mli @@ -1,5 +1,8 @@ (** The framework's bounds on a connection: what {!Spindle_postgres.connect} and - {!Pool.create} both ask for. *) + {!Pool.create} both ask for. + + Its documents, a page for each part: + [$(opam var spindle-postgres:doc)/llms.txt]. *) val apply : ?statement_timeout:Mtime.Span.t -> diff --git a/postgres/pool.ml b/postgres/pool.ml index 8322d21..a7e11b3 100644 --- a/postgres/pool.ml +++ b/postgres/pool.ml @@ -107,4 +107,8 @@ let run ?size ?wait ?statement_timeout ?idle_in_transaction_timeout ?parameters Printexc.raise_with_backtrace ex bt) | Error m -> L.err (fun f -> f "the pool could not be opened: %s" m); - exit 1 + (exit + [@litany.allow + "suspicious-exit-in-library: a server whose pool cannot open is \ + stopped where an orchestrator sees it, as Pool.run's .mli says"]) + 1 diff --git a/postgres/pool.mli b/postgres/pool.mli index 0e16f3f..068f77f 100644 --- a/postgres/pool.mli +++ b/postgres/pool.mli @@ -1,6 +1,9 @@ (** Connections, made up front and borrowed one at a time: the Postgres backend's pool ([Rowtype_postgres.Pool]), each connection bounded as - {!Spindle_postgres.connect} bounds one, and a transaction on a borrow. *) + {!Spindle_postgres.connect} bounds one, and a transaction on a borrow. + + Its documents, a page for each part: + [$(opam var spindle-postgres:doc)/llms.txt]. *) type t diff --git a/postgres/session.mli b/postgres/session.mli index 616b02d..be43e25 100644 --- a/postgres/session.mli +++ b/postgres/session.mli @@ -1,6 +1,9 @@ (** Sessions in a table of the application's database, for a server of more than one process ({!Spindle.Session}). + Its documents, a page for each part: + [$(opam var spindle-postgres:doc)/llms.txt]. + {[ let session = Spindle.Session.create diff --git a/postgres/source.mli b/postgres/source.mli index 8075796..598d53d 100644 --- a/postgres/source.mli +++ b/postgres/source.mli @@ -1,4 +1,7 @@ (** The library's one log source, [spindle-postgres]: a pool that could not be - opened, and one with no connection free within its wait. *) + opened, and one with no connection free within its wait. + + Its documents, a page for each part: + [$(opam var spindle-postgres:doc)/llms.txt]. *) val src : Logs.src diff --git a/postgres/spindle_postgres.mli b/postgres/spindle_postgres.mli index 75c4d77..d84b9e6 100644 --- a/postgres/spindle_postgres.mli +++ b/postgres/spindle_postgres.mli @@ -2,6 +2,12 @@ bounded as a server bounds them, a pool and the probe that asks it, and the refusal a database failure answers. + Its documents, a page for each part: + [$(opam var spindle-postgres:doc)/llms.txt]. + + Its page, with its examples: + [$(opam var spindle-postgres:doc)/pages/guide/databases.md]. + A transaction is the backend's ([Rowtype_postgres.Transaction]), and migrating is [rowtype-migrate]'s, a step of its own before the server starts. *) diff --git a/postgres/traced.mli b/postgres/traced.mli index 6e31368..cb7f0b1 100644 --- a/postgres/traced.mli +++ b/postgres/traced.mli @@ -1,4 +1,7 @@ -(** What watches the statements of every connection the library makes. *) +(** What watches the statements of every connection the library makes. + + Its documents, a page for each part: + [$(opam var spindle-postgres:doc)/llms.txt]. *) val observer : Rowtype_postgres.observer (** Each statement a {!Spindle.Trace.Client} span of the trace the fiber is in, diff --git a/spindle.opam b/spindle.opam index 8b4d6e2..6ca7831 100644 --- a/spindle.opam +++ b/spindle.opam @@ -37,6 +37,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"} "htmlit" {with-dev-setup & >= "0.2.0"} "tyxml" {with-dev-setup & >= "5.0.0"} "tyxml-ppx" {with-dev-setup & >= "5.0.0"} diff --git a/sqlite/pool.ml b/sqlite/pool.ml index a192b95..7a01c53 100644 --- a/sqlite/pool.ml +++ b/sqlite/pool.ml @@ -98,4 +98,8 @@ let run ?size ?wait ?timeout env file f = | Error e -> L.err (fun f -> f "the pool could not be opened: %s" (Rowtype.error_to_string e)); - exit 1 + (exit + [@litany.allow + "suspicious-exit-in-library: a server whose pool cannot open is \ + stopped where an orchestrator sees it, as Pool.run's .mli says"]) + 1 diff --git a/sqlite/pool.mli b/sqlite/pool.mli index 6caa810..5de745a 100644 --- a/sqlite/pool.mli +++ b/sqlite/pool.mli @@ -1,6 +1,9 @@ (** Connections to one SQLite file, made up front and borrowed one at a time: the SQLite backend's pool ([Rowtype_sqlite.Pool]), the file in WAL mode, and - a transaction on a borrow. *) + a transaction on a borrow. + + Its documents, a page for each part: + [$(opam var spindle-sqlite:doc)/llms.txt]. *) type t diff --git a/sqlite/session.mli b/sqlite/session.mli index 908758d..f1a8ae1 100644 --- a/sqlite/session.mli +++ b/sqlite/session.mli @@ -1,5 +1,8 @@ (** Sessions in a table of the application's database ({!Spindle.Session}). + Its documents, a page for each part: + [$(opam var spindle-sqlite:doc)/llms.txt]. + {[ let session = Spindle.Session.create diff --git a/sqlite/source.mli b/sqlite/source.mli index 9a7a1e0..7fcabb8 100644 --- a/sqlite/source.mli +++ b/sqlite/source.mli @@ -1,4 +1,7 @@ (** The library's one log source, [spindle-sqlite]: a pool that could not be - opened, and one with no connection free within its wait. *) + opened, and one with no connection free within its wait. + + Its documents, a page for each part: + [$(opam var spindle-sqlite:doc)/llms.txt]. *) val src : Logs.src diff --git a/sqlite/spindle_sqlite.mli b/sqlite/spindle_sqlite.mli index 902f38d..559a299 100644 --- a/sqlite/spindle_sqlite.mli +++ b/sqlite/spindle_sqlite.mli @@ -2,6 +2,12 @@ connections to one file, in WAL mode so a read never waits on a write, the probe that asks it, and the refusal a database failure answers. + Its documents, a page for each part: + [$(opam var spindle-sqlite:doc)/llms.txt]. + + Its page, with its examples: + [$(opam var spindle-sqlite:doc)/pages/guide/databases.md]. + A transaction is the backend's ([Rowtype_sqlite.Transaction]), and migrating is [rowtype-migrate]'s, a step of its own before the server starts: [rowtype-migrate up --url sqlite:app.db]. *) diff --git a/sqlite/traced.mli b/sqlite/traced.mli index 2acb4db..73fbd10 100644 --- a/sqlite/traced.mli +++ b/sqlite/traced.mli @@ -1,4 +1,7 @@ -(** What watches the statements of every connection the library makes. *) +(** What watches the statements of every connection the library makes. + + Its documents, a page for each part: + [$(opam var spindle-sqlite:doc)/llms.txt]. *) val observer : Rowtype_sqlite.observer (** Each statement a {!Spindle.Trace.Client} span of the trace the fiber is in, diff --git a/test/in_memory.ml b/test/in_memory.ml index 880666d..6b3ddc4 100644 --- a/test/in_memory.ml +++ b/test/in_memory.ml @@ -40,7 +40,7 @@ module Pipe = struct let rec read t buf = let have = Buffer.length t.pending in if have > 0 then begin - let n = min have (Cstruct.length buf) in + let n = Int.min have (Cstruct.length buf) in Cstruct.blit_from_string (Buffer.sub t.pending 0 n) 0 buf 0 n; let rest = Buffer.sub t.pending n (have - n) in Buffer.clear t.pending; @@ -60,7 +60,7 @@ module Pipe = struct else let room = capacity - Buffer.length t.pending in if room > 0 then begin - let n = min room (Cstruct.lenv bufs) in + let n = Int.min room (Cstruct.lenv bufs) in Buffer.add_string t.pending (Cstruct.to_string ~len:n (Cstruct.concat bufs)); Eio.Condition.broadcast t.changed; diff --git a/test/stub_server.ml b/test/stub_server.ml index bc4ab0b..a986841 100644 --- a/test/stub_server.ml +++ b/test/stub_server.ml @@ -76,7 +76,11 @@ let listen ~sw ~net = { meth = head.meth; path = Uri.path uri; - query = Uri.query uri; + query = + Uri.query uri + [@litany.allow + "restricted-dependency: the stub is a server of \ + its own, with no router to decode a query"]; headers = head.headers; body; }); diff --git a/test/test_access.ml b/test/test_access.ml index 15022ba..d327088 100644 --- a/test/test_access.ml +++ b/test/test_access.ml @@ -170,7 +170,10 @@ let test_a_shared_note_is_read_by_anyone_signed_in () = check_status "not its owner" `OK (call ~user:1 `GET "/notes/2") let test_a_denial_writes_one_line () = - let lines = captured (fun () -> ignore (call ~user:2 `DELETE "/notes/1")) in + let lines = + captured (fun () -> + ignore (call ~user:2 `DELETE "/notes/1" : Spindle.Test.response)) + in match denials lines with | [ l ] -> let says what expected = @@ -185,7 +188,10 @@ let test_a_denial_writes_one_line () = | other -> Alcotest.failf "%d denial lines" (List.length other) let test_an_allow_writes_no_line () = - let lines = captured (fun () -> ignore (call ~user:1 `DELETE "/notes/1")) in + let lines = + captured (fun () -> + ignore (call ~user:1 `DELETE "/notes/1" : Spindle.Test.response)) + in Alcotest.(check int) "no denial line" 0 (List.length (denials lines)) let test_a_denial_may_be_a_refusal_of_the_routes_own () = diff --git a/test/test_http_rfc.ml b/test/test_http_rfc.ml index 8f11cd1..e9d1a71 100644 --- a/test/test_http_rfc.ml +++ b/test/test_http_rfc.ml @@ -42,7 +42,7 @@ module Pieces = struct match t.left with | [] -> raise t.ends | p :: rest -> - let n = min (String.length p) (Cstruct.length buf) in + let n = Int.min (String.length p) (Cstruct.length buf) in Cstruct.blit_from_string p 0 buf 0 n; t.left <- (if n = String.length p then rest @@ -2290,7 +2290,8 @@ let plain_server () = Buffer.clear pending; Buffer.add_string pending (String.sub text i (String.length text - i)); - ignore (Unix.write_substring fd reply 0 (String.length reply)); + ignore + (Unix.write_substring fd reply 0 (String.length reply) : int); each () | None -> () in @@ -2381,7 +2382,8 @@ let test_bytes_on_a_kept_connection_are_not_the_next_answer () = in Alcotest.(check string) "the first call, on connection 0" "0" (body ()); let stray = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nstale" in - ignore (Unix.write_substring (connection 0) stray 0 (String.length stray)); + ignore + (Unix.write_substring (connection 0) stray 0 (String.length stray) : int); Alcotest.(check string) "the next, on a new one" "1" (body ()) (* RFC 9112 §9.5: a kept connection the server has closed is not lent, so diff --git a/test/test_spindle.ml b/test/test_spindle.ml index 75b1331..d5df995 100644 --- a/test/test_spindle.ml +++ b/test/test_spindle.ml @@ -500,7 +500,8 @@ let test_middleware_runs_in_the_order_listed () = ignore (Spindle.Test.call (Spindle.Test.app ~middleware:[ marked "a"; marked "b" ] [ seen ]) - `GET "/seen"); + `GET "/seen" + : Spindle.Test.response); Alcotest.(check (list string)) "outermost first" [ "a in"; "b in"; "handler"; "b out"; "a out" ] @@ -574,7 +575,7 @@ let test_middleware_can_ask_the_route () = in let told_for meth path = told := []; - ignore (Spindle.Test.call a meth path); + ignore (Spindle.Test.call a meth path : Spindle.Test.response); match !told with [ what ] -> what | _ -> "told more than once" in check_string "a route" "/hello/{name}" (told_for `GET "/hello/kim"); @@ -781,7 +782,7 @@ let test_a_dependency_runs_once_per_request () = let r = Spindle.Test.call app `GET "/shared" in check_string "every use is given the one answer" "1 10 1" r.body; check_int "and it ran once" 1 !ran; - ignore (Spindle.Test.call app `GET "/shared"); + ignore (Spindle.Test.call app `GET "/shared" : Spindle.Test.response); check_int "once per request" 2 !ran let test_uncached_runs_at_every_use () = @@ -803,7 +804,7 @@ let test_uncached_runs_at_every_use () = Printf.sprintf "%d %d %d" a b c); ] in - ignore (Spindle.Test.call app `GET "/shared"); + ignore (Spindle.Test.call app `GET "/shared" : Spindle.Test.response); check_int "worked out at every use" 2 !late; check_int "and what it is made of shared" 1 !ran @@ -876,7 +877,7 @@ let test_a_bind_shares_what_it_names () = (Spindle.Test.call app `GET "/shared").body; check_int "the named value ran once" 1 !ran; check_int "and a made one once, where it was made" 1 !made; - ignore (Spindle.Test.call app `GET "/shared"); + ignore (Spindle.Test.call app `GET "/shared" : Spindle.Test.response); check_int "made again for the next request" 2 !made let test_query_header_cookie_and_clock () = @@ -1864,12 +1865,14 @@ let test_expired_sessions_are_swept () = (string_session ~idle:Mtime.Span.s ~absolute:Mtime.Span.s r) in for _ = 1 to 501 do - ignore (Spindle.Test.call app `POST "/put/kim") + ignore (Spindle.Test.call app `POST "/put/kim" : Spindle.Test.response) done; Alcotest.(check (list int)) "the first request swept, and found nothing ended" [ 0 ] !(r.swept); let later () = - ignore (Spindle.Test.call ~now:(Instants.of_ms 60_000) app `GET "/me") + ignore + (Spindle.Test.call ~now:(Instants.of_ms 60_000) app `GET "/me" + : Spindle.Test.response) in later (); Alcotest.(check (list int)) @@ -2641,8 +2644,8 @@ let test_a_compression_that_cannot_be_is_refused () = refused "level" (fun () -> Spindle.Compress.make ~level:0 ()); refused "level" (fun () -> Spindle.Compress.make ~level:10 ()); refused "min_bytes" (fun () -> Spindle.Compress.make ~min_bytes:(-1) ()); - ignore (Spindle.Compress.make ~level:1 ~min_bytes:0 ()); - ignore (Spindle.Compress.make ~level:9 ()) + ignore (Spindle.Compress.make ~level:1 ~min_bytes:0 () : Spindle.Compress.t); + ignore (Spindle.Compress.make ~level:9 () : Spindle.Compress.t) let test_an_answer_is_compressed_where_it_may_be () = let a = @@ -2776,8 +2779,11 @@ let test_a_limit_that_cannot_be_is_refused () = refused "per" (fun () -> Spindle.Rate.create ~limit:1_000 ~per:(Mtime.Span.of_uint64_ns 999L) ()); ignore - (Spindle.Rate.create ~limit:1_000 ~per:(Mtime.Span.of_uint64_ns 1_000L) ()); - ignore (Spindle.Rate.create ~limit:1 ~per:Mtime.Span.ms ~burst:1 ()) + (Spindle.Rate.create ~limit:1_000 ~per:(Mtime.Span.of_uint64_ns 1_000L) () + : Spindle.Rate.t); + ignore + (Spindle.Rate.create ~limit:1 ~per:Mtime.Span.ms ~burst:1 () + : Spindle.Rate.t) let test_a_burst_is_its_own_figure () = let mono_clock = Eio_mock.Clock.Mono.make () in @@ -3304,7 +3310,7 @@ let test_levels_are_read_from_a_spec () = (* At debug, TLS tracing writes the records themselves -- every header of every call inside them. Turning everything up must not turn that on. *) let test_the_wire_is_not_raised_by_the_everything_level () = - ignore (captured ~level:(Some Logs.Debug) ignore); + ignore (captured ~level:(Some Logs.Debug) ignore : string list); List.iter (fun src -> if String.equal (Logs.Src.name src) "tls.tracing" then @@ -3314,7 +3320,9 @@ let test_the_wire_is_not_raised_by_the_everything_level () = | Some Logs.Warning -> true | _ -> false)) (Logs.Src.list ()); - ignore (captured ~sources:[ ("tls.tracing", Some Logs.Debug) ] ignore); + ignore + (captured ~sources:[ ("tls.tracing", Some Logs.Debug) ] ignore + : string list); List.iter (fun src -> if String.equal (Logs.Src.name src) "tls.tracing" then @@ -4147,13 +4155,21 @@ let test_a_metric_that_cannot_be_exposed_is_refused () = | exception Invalid_argument _ -> ()) [ ( "a name that is no name", - fun () -> ignore (Spindle.Metrics.gauge m "9 lives") ); - ("a name twice", fun () -> ignore (Spindle.Metrics.gauge m "hits")); + fun () -> + ignore (Spindle.Metrics.gauge m "9 lives" : Spindle.Metrics.gauge) ); + ( "a name twice", + fun () -> + ignore (Spindle.Metrics.gauge m "hits" : Spindle.Metrics.gauge) ); ( "a histogram's own label", - fun () -> ignore (Spindle.Metrics.gauge m ~labels:[ "le" ] "g") ); + fun () -> + ignore + (Spindle.Metrics.gauge m ~labels:[ "le" ] "g" + : Spindle.Metrics.gauge) ); ( "buckets that fall", - fun () -> ignore (Spindle.Metrics.histogram m ~buckets:[ 1.; 0.5 ] "h") - ); + fun () -> + ignore + (Spindle.Metrics.histogram m ~buckets:[ 1.; 0.5 ] "h" + : Spindle.Metrics.histogram) ); ]; Spindle.Metrics.sampled m ~labels:[ "pool" ] "pools" (fun () -> [ ([ "a" ], 1.) ]); @@ -4289,7 +4305,7 @@ let test_metrics_are_guarded_as_a_route_is () = | Some _ | None -> Error (Spindle.Refusal.make forbidden "Not you.")) in let m = Spindle.Metrics.create () in - ignore (Spindle.Metrics.gauge m "up"); + ignore (Spindle.Metrics.gauge m "up" : Spindle.Metrics.gauge); let app = Spindle.Test.app (Spindle.Metrics.routes ~guard m) in check_status "refused without" 403 (Spindle.Test.call app `GET "/metrics").status; @@ -6956,10 +6972,13 @@ let test_blocking_carries_the_request_and_refuses_an_effect () = "the request's id, on the thread" (Some "r1") (Spindle.Log.with_request_id "r1" (fun () -> Spindle.blocking Spindle.Log.request_id)); - match Spindle.blocking (fun () -> Eio.Fiber.yield ()) with + (match Spindle.blocking (fun () -> Eio.Fiber.yield ()) with | () -> Alcotest.fail "an effect on a systhread did something" | exception (Eio.Cancel.Cancelled _ as ex) -> raise ex - | exception _ -> () + | exception _ -> ()) + [@litany.allow + "suspicious-catch-all-handler: any exception is the refusal the test asks \ + for, and cancellation is raised again above"] let test_a_pretty_line_reads () = let lines = ref [] in @@ -7100,7 +7119,8 @@ let test_routes_that_could_both_answer_are_refused () = Spindle.delete Spindle.Path.(s "users" / user_id) Spindle.Returns.response (says "gone"); - ]) + ] + : Spindle.App.instance) let order_id = Spindle.Path.int "order_id" @@ -9947,7 +9967,11 @@ let test_a_probe_is_logged_at_debug () = ~domains:1 ~clock:mono_clock (Spindle.Test.app (hello :: quiet :: Spindle.Health.routes [])) in - let call path = ignore (call_on ~net ~clock:mono_clock ~port `GET path) in + let call path = + ignore + (call_on ~net ~clock:mono_clock ~port `GET path + : string Spindle_client.response) + in let logged sub = List.exists (contains ~sub) !lines in at Logs.Info; call "/livez"; diff --git a/test/test_spindle_postgres.ml b/test/test_spindle_postgres.ml index 38462cd..773ada5 100644 --- a/test/test_spindle_postgres.ml +++ b/test/test_spindle_postgres.ml @@ -293,7 +293,8 @@ let test_a_pool_takes_the_drivers_options () = (ok (Pg.run db (S.find_opt ~params:S.unit ~row:S.int "select 1") - ())); + ()) + : int option); Pg.run db (S.find_opt ~params:S.unit ~row:S.int "select count(*)::integer from pg_prepared_statements") @@ -408,7 +409,7 @@ let store_of pool ?table () = Ok "kept"); ] in - ignore (Spindle.Test.call app `GET "/"); + ignore (Spindle.Test.call app `GET "/" : Spindle.Test.response); match !kept with Some store -> store | None -> Alcotest.fail "no store" (* The pool as /readyz asks it: ready at rest, and ready while every @@ -1007,7 +1008,8 @@ let test_sessions_read_the_pool_as_a_resource () = Spindle.Test.browser (Spindle.Test.app ~resources:[ Spindle.Dep.resource db pool ] routes) in - ignore (Spindle.Test.Browser.call b `POST "/sign-in"); + ignore + (Spindle.Test.Browser.call b `POST "/sign-in" : Spindle.Test.response); Alcotest.(check string) "found in the table" "kim" (Spindle.Test.Browser.call b `GET "/me").body; Spindle_postgres.Pool.close pool) diff --git a/test/test_spindle_sqlite.ml b/test/test_spindle_sqlite.ml index 1bfb03d..0e3c78c 100644 --- a/test/test_spindle_sqlite.ml +++ b/test/test_spindle_sqlite.ml @@ -323,7 +323,7 @@ let store_of pool ?table () = Ok "kept"); ] in - ignore (Spindle.Test.call app `GET "/"); + ignore (Spindle.Test.call app `GET "/" : Spindle.Test.response); match !kept with Some store -> store | None -> Alcotest.fail "no store" let entry ?(seen = 2.) expires = @@ -432,7 +432,7 @@ let test_sessions_read_the_pool_as_a_resource () = Spindle.Test.browser (Spindle.Test.app ~resources:[ Spindle.Dep.resource db pool ] routes) in - ignore (Spindle.Test.Browser.call b `POST "/sign-in"); + ignore (Spindle.Test.Browser.call b `POST "/sign-in" : Spindle.Test.response); Alcotest.(check string) "found in the table" "kim" (Spindle.Test.Browser.call b `GET "/me").body diff --git a/test/test_websocket.ml b/test/test_websocket.ml index 63d874c..c67d299 100644 --- a/test/test_websocket.ml +++ b/test/test_websocket.ml @@ -720,7 +720,7 @@ let test_a_peer_reading_slowly_is_sent_the_whole_message () = Eio.Time.Mono.sleep_span clock Mtime.Span.(500 * ms); match Eio.Buf_read.take - (min 1024 (String.length payload - Buffer.length taken)) + (Int.min 1024 (String.length payload - Buffer.length taken)) r with | piece -> diff --git a/test/test_websocket_rfc.ml b/test/test_websocket_rfc.ml index 4e91aa5..9bfb0cf 100644 --- a/test/test_websocket_rfc.ml +++ b/test/test_websocket_rfc.ml @@ -27,7 +27,7 @@ module Pieces = struct match t.left with | [] -> raise End_of_file | p :: rest -> - let n = min (String.length p) (Cstruct.length buf) in + let n = Int.min (String.length p) (Cstruct.length buf) in Cstruct.blit_from_string p 0 buf 0 n; t.left <- (if n = String.length p then rest @@ -548,7 +548,7 @@ module Stalling = struct Eio.Promise.await t.go_on; t.left <- max_int); let s = Cstruct.to_string (Cstruct.concat bufs) in - let n = min t.left (String.length s) in + let n = Int.min t.left (String.length s) in Buffer.add_string t.taken (String.sub s 0 n); t.left <- t.left - n; n @@ -875,7 +875,7 @@ module Script = struct t.left <- Some []; Eio.Fiber.await_cancel () | p :: rest -> - let n = min (String.length p) (Cstruct.length buf) in + let n = Int.min (String.length p) (Cstruct.length buf) in Cstruct.blit_from_string p 0 buf 0 n; t.left <- Some @@ -1048,7 +1048,7 @@ let check_client_handshake r delivery = module G = QCheck.Gen -let gen_cuts n = G.(list_size (int_bound 8) (int_bound (max 1 n))) +let gen_cuts n = G.(list_size (int_bound 8) (int_bound (Int.max 1 n))) let test_every_row_holds_at_any_cut () = let rows = Array.of_list server_rows in diff --git a/test/test_wire.ml b/test/test_wire.ml index f51a50d..d94fc48 100644 --- a/test/test_wire.ml +++ b/test/test_wire.ml @@ -227,7 +227,9 @@ let counted = Ok (Spindle.Response.stream ~length:5 (fun send -> let ( let* ) = Result.bind in - let* () = send (String.sub sent 0 (min 2 (String.length sent))) in + let* () = + send (String.sub sent 0 (Int.min 2 (String.length sent))) + in if String.length sent > 2 then send (String.sub sent 2 (String.length sent - 2)) else Ok ()))) @@ -522,8 +524,9 @@ let test_a_client_gone_before_its_continue_is_a_value () = Eio.Promise.resolve saw "an error"; Error e | exception ex -> + let bt = Printexc.get_raw_backtrace () in Eio.Promise.resolve saw (Printexc.to_string ex); - raise ex) + Printexc.raise_with_backtrace ex bt) in In_memory.run @@ fun env -> Eio.Switch.run @@ fun sw ->