Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8b1f499
docs(book): make the seven pages that contradicted main match it
rubentalstra Nov 26, 2026
11d7866
docs(book): explain the access model on one page
rubentalstra Nov 26, 2026
e71bc69
Merge branch 'docs/fix-wrong-book-pages' into docs/book-information-a…
rubentalstra Nov 26, 2026
382f229
docs(book): organise the book in Diataxis form with an audience landi…
rubentalstra Nov 26, 2026
ab32017
docs(book): split Operational policy into four pages
rubentalstra Nov 26, 2026
3511128
docs(book): split the longest pages by task
rubentalstra Nov 26, 2026
c6f4a55
docs(book): state the access-refreshing wait without a number
rubentalstra Nov 26, 2026
db5d67d
Merge branch 'docs/access-model-explanation' into docs/book-informati…
rubentalstra Nov 26, 2026
e69ce01
Merge remote-tracking branch 'origin/main' into docs/book-information…
rubentalstra Nov 26, 2026
a11e218
docs(book): point the storage-sizing self-test at its new page
rubentalstra Nov 26, 2026
b335177
test: read the book examples from the pages they moved to
rubentalstra Nov 26, 2026
ceb9ae5
docs(book): delete the history and stale pointers inside current pages
rubentalstra Nov 26, 2026
0269fb9
docs(book): drop the removed [authz.professional] key and the em-dash…
rubentalstra Nov 26, 2026
2ca7b59
Merge remote-tracking branch 'origin/main' into docs/book-information…
rubentalstra Nov 26, 2026
5adf2cd
Merge remote-tracking branch 'origin/docs/book-information-architectu…
rubentalstra Nov 26, 2026
873133d
docs(book): bring the operator documentation up to date for v6
rubentalstra Nov 26, 2026
68885d1
Merge remote-tracking branch 'origin/main' into docs/book-information…
rubentalstra Nov 26, 2026
0f779b3
Merge remote-tracking branch 'origin/docs/book-information-architectu…
rubentalstra Nov 26, 2026
64b16f6
Merge remote-tracking branch 'origin/docs/delete-stale-book-content' …
rubentalstra Nov 26, 2026
85a04cf
feat(book): a first-integration tutorial whose requests run in CI
rubentalstra Nov 26, 2026
08b5a66
docs(book): generate the command-line reference from the clap definition
rubentalstra Nov 26, 2026
8454996
docs(book): generate the AQL function and refusal code references
rubentalstra Nov 26, 2026
1b315a3
test: keep the SPDX lines the reference tests write out of the REUSE …
rubentalstra Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ crates/*/src/**/generated/** linguist-generated=true
crates/openehr-rm/src/model/data.rs linguist-generated=true
# The shipped ferroehr.toml, generated by tools/config-reference (#5316).
app/ferroehr/assets/ferroehr.default.toml linguist-generated=true
website/book/src/reference/cli.md linguist-generated=true
website/book/src/reference/aql-functions.md linguist-generated=true
website/book/src/reference/refusal-codes.md linguist-generated=true

# ── Linguist: honest language stats ──────────────────────────────────────────
# Generated spec crates: emitted from the vendored BMM by openehr-codegen. The
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ continues from here.

- [Docker Compose](https://ferroehr.eu/docs/latest/installation/compose.html) and a [Helm chart](https://ferroehr.eu/docs/latest/installation/kubernetes.html), with multi-arch images (amd64, arm64)
- [Observability](https://ferroehr.eu/docs/latest/operations.html#observability): Prometheus metrics, OpenTelemetry traces, health probes
- [Backup and point-in-time recovery](https://ferroehr.eu/docs/latest/operations.html#backup-and-point-in-time-recovery) on PostgreSQL
- [Backup and point-in-time recovery](https://ferroehr.eu/docs/latest/database-operations.html#backup-and-point-in-time-recovery) on PostgreSQL
- [Measured conformance](https://ferroehr.eu/docs/latest/conformance.html) and [performance](https://ferroehr.eu/docs/latest/performance.html)
- [Verifiable releases](https://ferroehr.eu/docs/latest/verifying-releases.html): signed, with provenance and a software bill of materials

Expand Down
180 changes: 180 additions & 0 deletions app/ferroehr-rest/tests/it/book_examples_http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-License-Identifier: BUSL-1.1

//! The requests of the book's "Your first integration" tutorial, run in page
//! order against a fresh server, each held to the status its marker names.
//!
//! A request is a fenced `http` block after a `<!-- book-request: NAME ... -->`
//! marker whose attributes are `expect=STATUS`, `body-file=PATH` (relative to
//! the repository root), `capture=VAR:/json/pointer` (with `|object` for the
//! versioned object id before `::`), `json-has=/json/pointer` and
//! `header=NAME:VALUE`. A `{VAR}` in the request is a value an earlier answer
//! captured. The page shows no credentials, so the server runs without
//! authentication.

use std::collections::BTreeMap;
use std::path::PathBuf;

use http::StatusCode;
use serde_json::Value;

use crate::common;

const PAGE: &str = "website/book/src/tutorials/first-integration.md";
const MARKER: &str = "<!-- book-request: ";

/// One request of the page, with what its marker asks of the answer.
#[derive(Debug)]
struct Example {
name: String,
method: String,
path: String,
headers: Vec<(String, String)>,
body: String,
body_file: Option<String>,
expect: u16,
captures: Vec<(String, String)>,
json_has: Vec<String>,
header_has: Vec<(String, String)>,
}

fn repo_file(relative: &str) -> String {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join(relative);
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{} is readable: {e}", path.display()))
}

/// Every marked request of the page, in page order.
fn examples() -> Vec<Example> {
let page = repo_file(PAGE);
let mut found = Vec::new();
for chunk in page.split(MARKER).skip(1) {
let (attributes, rest) = chunk
.split_once(" -->\n")
.expect("a marker closes on its line");
let block = rest
.strip_prefix("```http\n")
.unwrap_or_else(|| panic!("an http block follows the marker {attributes}"));
let block = block.split_once("\n```").expect("the http block closes").0;
let (head, body) = block.split_once("\n\n").unwrap_or((block, ""));
let mut lines = head.lines();
let (method, path) = lines
.next()
.and_then(|line| line.split_once(' '))
.expect("a request line");
let headers = lines
.map(|line| {
let (name, value) = line.split_once(": ").expect("a header line");
(name.to_owned(), value.to_owned())
})
.collect();
let mut words = attributes.split_whitespace();
let name = words.next().expect("a marker names its request").to_owned();
let mut example = Example {
name,
method: method.to_owned(),
path: path.to_owned(),
headers,
body: body.to_owned(),
body_file: None,
expect: 0,
captures: Vec::new(),
json_has: Vec::new(),
header_has: Vec::new(),
};
for word in words {
let (key, value) = word.split_once('=').expect("an attribute is key=value");
match key {
"expect" => example.expect = value.parse().expect("a status code"),
"body-file" => example.body_file = Some(value.to_owned()),
"capture" => {
let (var, pointer) = value.split_once(':').expect("capture=VAR:/pointer");
example.captures.push((var.to_owned(), pointer.to_owned()));
}
"json-has" => example.json_has.push(value.to_owned()),
"header" => {
let (name, wanted) = value.split_once(':').expect("header=NAME:VALUE");
example
.header_has
.push((name.to_owned(), wanted.to_owned()));
}
other => panic!("unknown marker attribute {other}"),
}
}
found.push(example);
}
found
}

/// `text` with each `{VAR}` replaced by its captured value.
fn fill(text: &str, vars: &BTreeMap<String, String>) -> String {
vars.iter().fold(text.to_owned(), |text, (var, value)| {
text.replace(&format!("{{{var}}}"), value)
})
}

#[tokio::test]
async fn the_first_integration_tutorial_runs_as_written() {
let (_pg, app) = common::app(common::api_config(false)).await;
let examples = examples();
assert!(examples.len() >= 8, "the tutorial holds its eight requests");
let mut vars = BTreeMap::new();
for example in examples {
let path = fill(&example.path, &vars);
let mut req = common::req(&example.method, path.as_str());
for (name, value) in &example.headers {
req = req.header(name.as_str(), fill(value, &vars));
}
let body = match &example.body_file {
Some(file) => repo_file(file),
None => fill(&example.body, &vars),
};
let (status, headers, text) = common::send(&app, req.body(body).build()).await;
assert_eq!(
status,
StatusCode::from_u16(example.expect).expect("a status"),
"{} answers {}: {text}",
example.name,
example.expect
);
for (name, wanted) in &example.header_has {
let got = headers
.get(name.as_str())
.and_then(|value| value.to_str().ok())
.unwrap_or_default();
assert!(
got.starts_with(wanted.as_str()),
"{} carries {name}: {wanted}, got {got}",
example.name
);
}
if example.captures.is_empty() && example.json_has.is_empty() {
continue;
}
let json: Value = serde_json::from_str(&text).expect("a JSON answer");
for pointer in &example.json_has {
assert!(
json.pointer(pointer).is_some(),
"{} holds {pointer}: {json}",
example.name
);
}
for (var, pointer) in &example.captures {
let (pointer, object) = match pointer.strip_suffix("|object") {
Some(pointer) => (pointer, true),
None => (pointer.as_str(), false),
};
let value = json
.pointer(pointer)
.and_then(Value::as_str)
.unwrap_or_else(|| panic!("{} holds {pointer}", example.name));
let value = if object {
value.split_once("::").map_or(value, |(id, _)| id)
} else {
value
};
vars.insert(var.clone(), value.to_owned());
}
}
}
2 changes: 2 additions & 0 deletions app/ferroehr-rest/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mod binding_commits_http;
mod binding_issuers_http;
mod binding_purposes_http;
mod binding_refusals_http;
mod book_examples_http;
mod caller_kinds_http;
mod care_writer_review_http;
mod cohort_http;
Expand Down Expand Up @@ -152,6 +153,7 @@ mod query_caseload_http;
mod query_ehr_id_header;
mod query_refusals_http;
mod rbac_e2e;
mod reference_pages;
mod release_before_render;
mod repeated_member_names_http;
mod representation_http;
Expand Down
111 changes: 111 additions & 0 deletions app/ferroehr-rest/tests/it/reference_pages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-License-Identifier: BUSL-1.1

//! The book's reference pages generated from the code: the AQL built-in
//! functions of `openehr-query` and the access refusal codes of the draft
//! access terminology.
//!
//! `the_book_holds_the_current_reference_pages` fails when a committed page
//! differs from what the code renders; `write_the_reference_pages` (ignored,
//! run with `cargo nextest run -p ferroehr-rest --test it --run-ignored only
//! reference_pages`) writes them again.

use std::path::PathBuf;

use openehr_query::ast::{DateTimeFunction, NumericFunction, StringFunction};
use openehr_rm::draft::access_control::terminology::{Refusal, Term as _};

const AQL_FUNCTIONS: &str = "website/book/src/reference/aql-functions.md";
const REFUSAL_CODES: &str = "website/book/src/reference/refusal-codes.md";

fn path(relative: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join(relative)
}

// REUSE-IgnoreStart
fn banner(title: &str, intro: &str) -> String {
[
"<!-- @generated by the ferroehr-rest test reference_pages from the code. DO NOT EDIT. -->\n",
"<!-- SPDX-FileCopyrightText: Cadasto B.V. -->\n",
"<!-- SPDX-License-Identifier: BUSL-1.1 -->\n\n",
"# ",
title,
"\n\n",
intro,
"\n\n",
]
.concat()
}

// REUSE-IgnoreEnd

fn aql_functions() -> String {
let mut out = banner(
"AQL built-in functions",
"**For:** integrators. Every built-in single-row function the AQL parser\n\
accepts, by the group the AQL specification puts it in (QUERY, §Functions).\n\
Names compare without regard to case. How to use them, the aggregates and\n\
FerroEHR's extension functions are on [Querying with AQL](../querying-aql.md).",
);
out.push_str("| Function | Group |\n|---|---|\n");
let rows = StringFunction::ALL
.iter()
.map(|f| (f.as_str(), "string"))
.chain(NumericFunction::ALL.iter().map(|f| (f.as_str(), "numeric")))
.chain(
DateTimeFunction::ALL
.iter()
.map(|f| (f.as_str(), "date and time")),
);
for (name, group) in rows {
out.push_str(&["| `", name, "` | ", group, " |\n"].concat());
}
out
}

fn refusal_codes() -> String {
let mut out = banner(
"Access refusal codes",
"**For:** integrators and operators. Every code the access evaluator refuses\n\
a request under, with the status the caller receives. A `403` names its code\n\
in the problem's `detail`; a `404` answers as if the data did not exist and\n\
names nothing. A `refused-confidentiality` answers `404` instead at a level\n\
the access policy conceals. The access log records the code either way. What each step\n\
decides is on [How FerroEHR decides access](../explanation/access-model.md).",
);
out.push_str("| Code | Answer |\n|---|---|\n");
for refusal in Refusal::ALL {
let answer = if refusal.is_invisible() { "404" } else { "403" };
out.push_str(&["| `", refusal.code(), "` | ", answer, " |\n"].concat());
}
out
}

fn pages() -> [(&'static str, String); 2] {
[
(AQL_FUNCTIONS, aql_functions()),
(REFUSAL_CODES, refusal_codes()),
]
}

#[test]
fn the_book_holds_the_current_reference_pages() {
for (page, rendered) in pages() {
let committed = std::fs::read_to_string(path(page)).expect("the reference page");
assert!(
committed == rendered,
"{page} is out of date: run `cargo nextest run -p ferroehr-rest --test it \
--run-ignored only reference_pages` and commit the page"
);
}
}

#[test]
#[ignore = "writes the book pages; run on purpose after changing the code they render"]
fn write_the_reference_pages() {
for (page, rendered) in pages() {
std::fs::write(path(page), rendered).expect("the reference page is written");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ fn repo_file(relative: &str) -> String {
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{} is readable: {e}", path.display()))
}

/// The TOML block of the book's authentication page that holds `marker`.
/// The TOML block of the book's authorization keys page that holds `marker`.
fn documented_block(marker: &str) -> String {
let page = repo_file("website/book/src/installation/config-auth.md");
let page = repo_file("website/book/src/installation/config-authz.md");
page.split("```toml\n")
.skip(1)
.filter_map(|block| block.split("```").next())
Expand Down
Loading
Loading