Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conformance/knowledge/filters.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{"expect":{"id":3,"result":{"puzzles":"$array","sources":"$array","seed":20406}}}
{"send":{"jsonrpc":"2.0","id":4,"method":"knowledge/puzzles","params":{"daily":false,"limit":1}}}
{"expect":{"id":4,"result":{"puzzles":"$array","sources":"$array"}}}
{"comment":"Facets list the openings in the same shape as the themes."}
{"comment":"Facets list the openings in the same shape as the themes, an empty list when there are none."}
{"send":{"jsonrpc":"2.0","id":5,"method":"knowledge/puzzleFacets"}}
{"expect":{"id":5,"result":{"bands":"$array","total":"$array","themes":"$array","openings":"$array","sources":"$array"}}}
{"comment":"Refused: an opening that isn't one."}
Expand Down
13 changes: 9 additions & 4 deletions crates/cnp/src/knowledge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,15 @@ pub struct FacetsResult {
/// When a [`Quality`] filter was asked for: the thresholds it used.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub quality: Option<QualityThresholds>,
/// Each opening family that has at least one puzzle, with its counts. Only from a node
/// that offers [`Capabilities::puzzle_filters`].
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub openings: Vec<OpeningCounts>,
/// Each opening family that has at least one puzzle, with its counts. `Some` from a node
/// that offers [`Capabilities::puzzle_filters`], and `None` (the field absent) from one
/// that doesn't.
///
/// Pitfall: an `Option`, not a `Vec` left out when empty, because the spec ties the field
/// to the capability, not to the count: a node with the capability and no puzzles answers
/// `"openings": []`, and a client tells "no openings yet" from "this node counts none".
#[serde(default, skip_serializing_if = "Option::is_none")]
pub openings: Option<Vec<OpeningCounts>>,
}

/// How many puzzles each theme has in each rating band, from complete imports.
Expand Down
21 changes: 18 additions & 3 deletions crates/cnp/tests/knowledge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn an_opening_and_a_daily_filter_are_written_only_when_asked_for() {
fn facets_list_openings_only_when_the_node_has_them() {
let none: knowledge::FacetsResult =
serde_json::from_value(json!({"bands":[],"total":[],"themes":[],"sources":[]})).unwrap();
assert!(none.openings.is_empty());
assert_eq!(none.openings, None);
assert_eq!(
serde_json::to_value(&none).unwrap(),
json!({"bands":[],"total":[],"themes":[],"sources":[]})
Expand All @@ -524,8 +524,23 @@ fn facets_list_openings_only_when_the_node_has_them() {
"openings":[{"opening":"Italian_Game","counts":[4]}]
}))
.unwrap();
assert_eq!(some.openings[0].opening, "Italian_Game");
assert_eq!(some.openings[0].counts, [4]);
let openings = some.openings.expect("openings");
assert_eq!(openings[0].opening, "Italian_Game");
assert_eq!(openings[0].counts, [4]);
}

#[test]
fn facets_of_a_node_with_filters_and_no_puzzles_still_answer_openings() {
// spec/knowledge.md, `knowledge/puzzleFacets`: the field goes with `puzzleFilters`, not
// with the count, and conformance/knowledge/filters.jsonl expects it on an empty library.
let empty = knowledge::FacetsResult {
openings: Some(Vec::new()),
..Default::default()
};
let wire = serde_json::to_value(&empty).unwrap();
assert_eq!(wire["openings"], json!([]));
let back: knowledge::FacetsResult = serde_json::from_value(wire).unwrap();
assert_eq!(back.openings, Some(Vec::new()));
}

#[test]
Expand Down
9 changes: 8 additions & 1 deletion spec/knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ illustrative counts):
- A node that offers `puzzleFilters` also answers with `openings`, in the same shape as
`themes`: `[{"opening": "Italian_Game", "counts": [...]}]`, one count for each band, for
each opening family that has a puzzle (a puzzle with no opening tag is in none, so the counts
don't add up to `total`). Without `puzzleFilters` the field is absent.
don't add up to `total`). The field goes with the capability, not the count: a node with
`puzzleFilters` and no puzzles answers `"openings": []`. Without `puzzleFilters` the field is
absent.
- Counts are of the puzzles of **complete imports** and are the same as asking
`knowledge/puzzles` for that theme, band and quality would reach, which a node can keep as it
imports, not work out at each request. A client doesn't treat a count as current after a new
Expand Down Expand Up @@ -431,6 +433,11 @@ searching puzzles by a position, and Lumbra's OTB games.

## Changes

- **draft 1, 2026-11-16**, clarified: a node that offers `puzzleFilters` answers
`knowledge/puzzleFacets`' `openings` even when it is empty, as the conformance session
already expected; `cnp`'s `FacetsResult::openings` is now an `Option`, so a node built on it
can say so. The wire is unchanged for every client.

- **draft 1, 2026-11-17**, added to the draft: **space** (capability `space`,
`knowledge/usage` and `knowledge/remove`), so a client that downloads puzzles a part at a
time can keep the knowledge within a disk limit the player sets, and remove a whole database
Expand Down
Loading