mirror of
https://github.com/lemonade-sdk/lemonade.git
synced 2026-11-23 08:49:28 -10:00
* build: stage API docs into resources * feat(server): serve API docs at /docs * test: cover /docs endpoint, fix empty-file truncation bug * feat(server): serve bundled API docs at /docs * feat(server): serve the API reference as an index plus one page per URL Replaces the concatenated response with a JSON index at /v1/docs and one page per URL at /v1/docs/api/lemonade, so pages can be added later without breaking clients. Widens the bundle to all of docs/api. * feat(mcp): expose the bundled API reference as a lemonade_docs tool Lists the reference pages the server ships, or returns one as markdown when `page` is given. Reuses the HTTP endpoint's lookup so the path confinement is shared rather than written twice. * feat(server): optionally bundle the rendered documentation site at /docs/ Adds BUILD_DOCS_SITE, off by default, which builds the existing Zensical site into resources/docs-site and serves it at /docs/. Off by default because zensical installs with pip; the Debian build uses only the archive. * ci(windows): bundle the documentation site in the installer builds Installs zensical and configures with BUILD_DOCS_SITE=ON in both Windows installer jobs, so the shipped MSIs carry the docs site while source builds that cannot install from pip are unaffected. * fix(docs): repair corrupted Windows doc paths Replace backspace and carriage-return characters with literal backslashes. * build: remove Zensical docs site build and packaging wiring Remove BUILD_DOCS_SITE, BuildDocsSite.cmake, WiX docs-site fragments, and CI site bundling steps. * fix(server): stop /docs from showing the UI Return JSON 404 for /docs and point clients to /v1/docs instead, preventing falling back to the SPA UI. * test: verify /docs returns 404 instead of UI * fix(server): drop the leftover docs-site mount
111 lines
3.8 KiB
C++
111 lines
3.8 KiB
C++
#include "lemon/api_docs.h"
|
|
|
|
#include <cstdio>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
namespace {
|
|
|
|
int failures = 0;
|
|
|
|
void check(bool ok, const char* what) {
|
|
std::printf("[%s] %s\n", ok ? "PASS" : "FAIL", what);
|
|
if (!ok) {
|
|
++failures;
|
|
}
|
|
}
|
|
|
|
fs::path make_scratch_dir(const std::string& name) {
|
|
fs::path dir = fs::temp_directory_path() / ("lemon_docs_test_" + name);
|
|
std::error_code ec;
|
|
fs::remove_all(dir, ec);
|
|
fs::create_directories(dir / "api");
|
|
return dir;
|
|
}
|
|
|
|
void write_file(const fs::path& path, const std::string& content) {
|
|
std::ofstream f(path, std::ios::binary);
|
|
f << content;
|
|
}
|
|
|
|
const lemon::ApiDoc* find_doc(const std::vector<lemon::ApiDoc>& docs, const std::string& id) {
|
|
for (const auto& doc : docs) {
|
|
if (doc.id == id) {
|
|
return &doc;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
{
|
|
fs::path dir = make_scratch_dir("index");
|
|
write_file(dir / "api" / "lemonade.md", "# Lemonade API\n\nbody\n");
|
|
write_file(dir / "api" / "openai.md", "# OpenAI Compatible\n");
|
|
write_file(dir / "api" / "untitled.md", "no heading here\n");
|
|
write_file(dir / "api" / "notes.txt", "ignored");
|
|
|
|
auto docs = lemon::list_api_docs(dir.string());
|
|
|
|
check(docs.size() == 3, "only .md files are indexed");
|
|
|
|
const auto* lemonade = find_doc(docs, "api/lemonade");
|
|
check(lemonade != nullptr, "ids are website-relative paths without the extension");
|
|
check(lemonade != nullptr && lemonade->title == "Lemonade API", "title comes from the leading H1");
|
|
check(lemonade != nullptr && lemonade->bytes == fs::file_size(dir / "api" / "lemonade.md"),
|
|
"bytes reports the file size");
|
|
|
|
const auto* untitled = find_doc(docs, "api/untitled");
|
|
check(untitled != nullptr && untitled->title == "api/untitled",
|
|
"title falls back to the id when there is no H1");
|
|
|
|
bool sorted = true;
|
|
for (std::size_t i = 1; i < docs.size(); ++i) {
|
|
if (!(docs[i - 1].id < docs[i].id)) {
|
|
sorted = false;
|
|
}
|
|
}
|
|
check(sorted, "index is sorted by id");
|
|
}
|
|
|
|
{
|
|
fs::path dir = fs::temp_directory_path() / "lemon_docs_test_absent";
|
|
std::error_code ec;
|
|
fs::remove_all(dir, ec);
|
|
check(lemon::list_api_docs(dir.string()).empty(), "missing docs directory yields an empty index");
|
|
}
|
|
|
|
{
|
|
fs::path dir = make_scratch_dir("read");
|
|
write_file(dir / "api" / "lemonade.md", "# Lemonade API\ncontent\n");
|
|
write_file(dir.parent_path() / "lemon_docs_test_read_outside.md", "SECRET");
|
|
|
|
std::string content;
|
|
check(lemon::read_api_doc(dir.string(), "api/lemonade", content) &&
|
|
content.find("content") != std::string::npos,
|
|
"document is readable by id");
|
|
|
|
content.clear();
|
|
check(lemon::read_api_doc(dir.string(), "api/lemonade.md", content) &&
|
|
content.find("content") != std::string::npos,
|
|
"the .md suffix is accepted too");
|
|
|
|
check(!lemon::read_api_doc(dir.string(), "api/missing", content),
|
|
"unknown id is rejected");
|
|
check(!lemon::read_api_doc(dir.string(), "../lemon_docs_test_read_outside", content),
|
|
"traversal outside the docs directory is rejected");
|
|
check(!lemon::read_api_doc(dir.string(), "api/../../lemon_docs_test_read_outside", content),
|
|
"embedded traversal is rejected");
|
|
check(!lemon::read_api_doc(dir.string(), "", content), "empty id is rejected");
|
|
}
|
|
|
|
std::printf("%s\n", failures == 0 ? "All docs endpoint tests passed" : "Docs endpoint tests FAILED");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|