From 2269b3284efcf150c97c8b84068f83b5e094ba5f Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 5 Dec 2026 12:00:31 -0600 Subject: [PATCH 1/2] Docs(fix): Export tagged example launchers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit why: The v0.1.1 guide needs its own shell launcher to start the server used by its examples. what: - Read the selected tag’s example manifest and copy the launcher named by that release. --- scripts/docs/README.md | 4 +++ scripts/docs/api_examples.lua | 33 ++++++++++++++-------- scripts/docs/export.lua | 25 ++++++++++++---- scripts/docs/tests/test_api_examples.lua | 36 ++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 18 deletions(-) diff --git a/scripts/docs/README.md b/scripts/docs/README.md index 9b972aa1..fdeefcdc 100644 --- a/scripts/docs/README.md +++ b/scripts/docs/README.md @@ -26,6 +26,10 @@ Install LuaLS, then export into the default directory: $ luajit scripts/docs/docs.lua export ``` +Use `--source /path/to/checkout` to export another revision. For releases +whose examples start tmux with `examples/api/run.sh`, the export includes +that script alongside the Lua programs. + Check the READMEs: ```console diff --git a/scripts/docs/api_examples.lua b/scripts/docs/api_examples.lua index ed1c09d3..640a2dc0 100644 --- a/scripts/docs/api_examples.lua +++ b/scripts/docs/api_examples.lua @@ -56,17 +56,35 @@ local function non_blank(text) return type(text) == "string" and text:find("%S") ~= nil end +local function check_source_file(path) + require_that(fs.is_file(path) and not fs.is_symlink(path), "example file is missing or linked") + local content = files.read(path) + require_that( + content:find("%S") and content:sub(-1) == "\n" and not content:find("\r", 1, true), + "example files must contain complete UTF-8 text with LF endings" + ) +end + --- Reads the manifest of the complete examples under `root` and checks it against the files. --- `symbols`, when given, is the set a target must belong to. ---@param root string ---@param symbols? table +---@param options? { allow_launcher: boolean } Older releases used a shared tmux launcher. ---@return table manifest -function M.load_examples(root, symbols) +function M.load_examples(root, symbols, options) local manifest = json.read(root .. "/examples/api/manifest.json") check_keys(manifest, { "schema", "setup", "examples" }) require_that(manifest.schema == 1, "unsupported schema") local setup = manifest.setup - check_keys(setup, { "lua", "luv" }) + check_keys( + setup, + { "lua", "luv" }, + options and options.allow_launcher and { "launcher" } or nil + ) + if setup.launcher ~= nil then + require_that(setup.launcher == "examples/api/run.sh", "unexpected launcher path") + check_source_file(root .. "/" .. setup.launcher) + end require_that( type(setup.lua) == "string" and setup.lua:match("^5%.[1-5]%.%d+$"), "Lua version must be pinned" @@ -87,16 +105,7 @@ function M.load_examples(root, symbols) example.file == "examples/api/" .. name .. ".lua", "unexpected example file path" ) - local path = root .. "/" .. example.file - require_that( - fs.is_file(path) and not fs.is_symlink(path), - "example file is missing or linked" - ) - local content = files.read(path) - require_that( - content:find("%S") and content:sub(-1) == "\n" and not content:find("\r", 1, true), - "example files must contain complete UTF-8 text with LF endings" - ) + check_source_file(root .. "/" .. example.file) listed[example.file] = true require_that(non_blank(example.description), "missing task description") require_that( diff --git a/scripts/docs/export.lua b/scripts/docs/export.lua index 5cc4780a..5c65bde9 100644 --- a/scripts/docs/export.lua +++ b/scripts/docs/export.lua @@ -336,6 +336,23 @@ local function annotate(source_lua) end end +--- Collect example source and the manifest that assigns complete programs to API symbols. +---@param source string +---@param symbols table +---@return table[] examples +---@return table? manifest +function M.example_bundle(source, symbols) + local entries = { { "examples", ".lua" } } + local manifest + if fs.is_directory(source .. "/examples/api") then + manifest = api_examples.load_examples(source, symbols, { allow_launcher = true }) + if manifest.setup.launcher then + entries[#entries + 1] = { manifest.setup.launcher, "" } + end + end + return M.content_files(source, entries), manifest +end + ---@param source string The checkout to export. ---@param luals string The language server executable. ---@return table payload @@ -381,13 +398,9 @@ function M.build_payload(source, luals) package = M.rock_metadata(source), declarations = declarations, guides = M.content_files(source, { { "README.md", "" }, { "docs", ".md" } }), - examples = M.content_files(source, { { "examples", ".lua" } }), } - -- Historical sources predate complete examples; an opted-in directory must validate. - if fs.is_directory(source .. "/examples/api") then - payload.api_examples = - api_examples.load_examples(source, api_examples.public_symbols(declarations)) - end + payload.examples, payload.api_examples = + M.example_bundle(source, api_examples.public_symbols(declarations)) M.validate(payload) return payload end diff --git a/scripts/docs/tests/test_api_examples.lua b/scripts/docs/tests/test_api_examples.lua index a8de0004..678d3b5d 100644 --- a/scripts/docs/tests/test_api_examples.lua +++ b/scripts/docs/tests/test_api_examples.lua @@ -1,5 +1,6 @@ local test = require("luaunit") local api = require("docs.api_examples") +local export = require("docs.export") local files = require("support.files") local fs = require("support.fs") local json = require("support.json") @@ -101,6 +102,41 @@ function M.test_complete_programs_cover_their_existing_targets() test.assertEquals(seen, TARGETS) end +local function set_launcher(path) + manifest.setup = { lua = manifest.setup.lua, luv = manifest.setup.luv, launcher = path } + save() +end + +function M.test_an_export_includes_only_the_launcher_its_examples_require() + local name = "examples/api/run.sh" + local content = "#!/bin/sh\nexit 23\n" + files.write(root .. "/" .. name, content) + local function exported_launcher() + local rows, loaded = export.example_bundle(root, TARGETS) + test.assertEquals(assert(loaded).setup, manifest.setup) + for _, row in ipairs(rows) do + if row.path == name then + return row.content + end + end + end + + test.assertNil(exported_launcher()) + set_launcher(name) + test.assertEquals(exported_launcher(), content) + rejects("unexpected or missing manifest fields") +end + +function M.test_a_release_launcher_must_be_the_listed_regular_file() + set_launcher("../run.sh") + test.assertErrorMsgContains("launcher path", export.example_bundle, root, TARGETS) + set_launcher("examples/api/run.sh") + test.assertErrorMsgContains("missing or linked", export.example_bundle, root, TARGETS) + local path = root .. "/" .. manifest.setup.launcher + assert(require("support.uv").fs_symlink("connect.lua", path)) + test.assertErrorMsgContains("missing or linked", export.example_bundle, root, TARGETS) +end + function M.test_receiver_and_collection_identities_match_native_annotations() local declarations = { { From 4959a3644fd26f3909ff8c92b5e9b86064faa099 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 5 Dec 2026 12:00:31 -0600 Subject: [PATCH 2/2] Changelog: Include the tmux launcher with historic why: The v0.1.1 guide needs its own shell launcher to start the server used by its examples. what: - Record the change under Unreleased. --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4b87a57b..fae2b8b2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,9 @@ Notable changes to `libtmux`. - Docs: the README starts with a calculator in a private tmux pane. Run it from standalone Lua or Neovim and read the reply over control mode. +- Docs: The API export includes `examples/api/run.sh` for releases that use + it to start tmux. Readers can run those releases’ examples with the + supplied script. - Runtime: `Runtime:start_server` starts a private tmux server and resolves to an `OwnedServer` with its `server` handle, its `socket_path` and `stop()`. The server lives in a new directory under `root` (the system temporary