Skip to content
Closed
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
10 changes: 7 additions & 3 deletions docs/MP-CAPABILITY-BOUNDARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ dead MP controls offline and no synthesized server state anywhere:
`loadStatus` sits outside enter/refresh, so every failure keeps the last
good figures without touching phase or error state, and the screen
refreshes it on the reference cadence (60s while visible, plus a new turn
and foreground return).
and foreground return). The wide layout of the same read
(`?layout=full`) carries the per-turn campaign income breakdown; because
it runs the reference's enrichment queries, it is read on demand when the
funds details are opened and never polled.
- World reads are public and separate from the character projection:
`GET /api/countries` answers the runtime nation directory,
`GET /api/country/[code]/overview-counts` answers one nation's headline
figures (parties, politicians, elections, bills, regions, GDP, budget
balance, unions, prime rate), `GET /api/country/[code]/states` answers
that nation's regions, `GET /api/country/[code]/parties` and
`GET /api/country/[code]/politicians` answer its parties and
politicians, and `GET /api/elections?country={code}&view=summary` answers
its races, and `GET /api/news` answers the world news feed. The Rust bridge pins the country code to a two-letter key,
politicians, `GET /api/country/[code]/legislature/leaders` answers its
legislature leadership, `GET /api/elections?country={code}&view=summary`
answers its races, and `GET /api/news` answers the world news feed. The Rust bridge pins the country code to a two-letter key,
and the adapter refuses to send anything else. All of these loads sit
outside enter/refresh: a failure keeps the last good view and never
expires the session.
Expand Down
45 changes: 45 additions & 0 deletions docs/NAVIGATION-PARITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -963,3 +963,48 @@ tests: the search fills the recipient, a failed search keeps the draft) and
last-good-matches posture) plus the Rust path/allowlist assertions in
`mp_session::tests::world_reads_resolve_to_pinned_paths`. No
physical-iPhone evidence is claimed; #363/#436 remain open.

## 29. MP campaign income breakdown (#510)

The reference status bar shows the per-turn campaign income lines in the
funds details: base generation, donor bonus, office bonus, union
contribution, state and national tax, and the net per turn. Multiplayer
showed only the balance.

Delivered:

- A new audited read, `GET /api/client-status?layout=full`, answers the
breakdown. The Rust bridge pins the layout (the wide layout runs the
reference's enrichment queries, so it is never polled) and the transport
allowlist accepts only the two pinned layouts for that path.
- Opening the funds details reads the wide payload on demand and renders the
server's own lines: base generation, donor bonus, office bonus, union
contribution, state tax, national tax and net per turn. A figure the
server did not report reads "not reported".
- A failed wide read leaves the details and the session intact.

Focused evidence: `src/ui/MpIncomeBreakdown510.test.tsx` (2 rendered tests:
the breakdown is read on demand and shown, a failed wide read stays
honest), `src/mp/status.test.ts` (the breakdown projection and the
last-good-view posture) and the Rust test
`mp_session::tests::full_status_read_pins_the_full_layout`. No
physical-iPhone evidence is claimed; #363/#436 remain open.

## 30. MP nation leadership (#510)

The reference nation page names the people who run the country. The
multiplayer nation drill-in stopped at the institutions.

Delivered:

- A new audited read, `GET /api/country/[code]/legislature/leaders`,
answers the nation's legislature leadership. The Rust bridge pins the
country code and the path shape.
- The nation card now names the prime minister and the opposition leader
with their party, exactly as the server reports them. A seat the server
does not publish (the speaker, for now) stays absent.

Focused evidence: `src/ui/MpNations510.test.tsx` (the leadership rows ride
the nation drill-in), `src/mp/nations.test.ts` (the projection, the invalid
code refusal, the last-good-holders posture) and the Rust path/allowlist
assertions. No physical-iPhone evidence is claimed; #363/#436 remain open.
148 changes: 141 additions & 7 deletions src-tauri/src/mp_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ pub enum MpFetchOp {
/// influence and favorability the footer shows, and skips the
/// corporation/election/income enrichment the wider layouts run.
ClientStatus,
/// The full status read; GET /api/client-status?layout=full
/// (requireBasicAuth, 401 signed out). Read on demand when the
/// player asks for the per-turn campaign income breakdown, which the
/// minimal layout does not carry. The wider layout runs the
/// reference's enrichment queries, so it is never polled.
ClientStatusFull,
/// Turn/year/processing/countdown; public but fresher via the session.
TurnStatus,
/// Players active within the last hour; public, no session required.
Expand Down Expand Up @@ -183,6 +189,10 @@ pub enum MpFetchOp {
/// The nation's politicians; GET /api/country/[code]/politicians
/// (public, no auth, 400 on an invalid country).
CountryPoliticians,
/// The nation's legislature leadership; GET
/// /api/country/[code]/legislature/leaders (public, no auth, 404 on
/// an invalid country).
CountryLeaders,
/// A nation's election list; GET /api/elections?country={code}&view=
/// summary (public with optional auth, 400 on an invalid country).
/// The country code is a two-letter COUNTRY_CONFIGS key; see
Expand All @@ -205,6 +215,7 @@ impl MpFetchOp {
"savings-accounts" => Some(Self::SavingsAccounts),
"client-nav" => Some(Self::ClientNav),
"client-status" => Some(Self::ClientStatus),
"client-status-full" => Some(Self::ClientStatusFull),
"turn-status" => Some(Self::TurnStatus),
"players-online" => Some(Self::PlayersOnline),
"game-time" => Some(Self::GameTime),
Expand All @@ -222,6 +233,7 @@ impl MpFetchOp {
"country-states" => Some(Self::CountryStates),
"country-parties" => Some(Self::CountryParties),
"country-politicians" => Some(Self::CountryPoliticians),
"country-leaders" => Some(Self::CountryLeaders),
"election-list" => Some(Self::ElectionList),
"news-feed" => Some(Self::NewsFeed),
"character-search" => Some(Self::CharacterSearch),
Expand All @@ -236,6 +248,7 @@ impl MpFetchOp {
Self::SavingsAccounts => "/api/character/savings",
Self::ClientNav => "/api/client-nav",
Self::ClientStatus => "/api/client-status",
Self::ClientStatusFull => "/api/client-status",
Self::TurnStatus => "/api/game/turn/status",
Self::PlayersOnline => "/api/players/online",
Self::GameTime => "/api/game-time",
Expand All @@ -253,6 +266,7 @@ impl MpFetchOp {
Self::CountryStates => "/api/country",
Self::CountryParties => "/api/country",
Self::CountryPoliticians => "/api/country",
Self::CountryLeaders => "/api/country",
Self::ElectionList => "/api/elections",
Self::NewsFeed => "/api/news",
Self::CharacterSearch => "/api/characters/search",
Expand Down Expand Up @@ -612,14 +626,19 @@ fn fetch_path_and_query(
offset: Option<u32>,
) -> Result<String, String> {
match op {
MpFetchOp::ClientStatus => {
MpFetchOp::ClientStatus | MpFetchOp::ClientStatusFull => {
if limit.is_some() || offset.is_some() {
return Err(error::UNSUPPORTED_OP.to_string());
}
// The layout is pinned, never caller-supplied: the minimal
// layout answers the footer scalars without the wide
// enrichment queries.
Ok(format!("{}?layout=minimal", op.path()))
// enrichment queries, and the full layout is read on demand
// for the campaign income breakdown.
let layout = match op {
MpFetchOp::ClientStatus => "minimal",
_ => "full",
};
Ok(format!("{}?layout={}", op.path(), layout))
}
MpFetchOp::NewsFeed => {
let limit = limit.ok_or_else(|| error::BAD_ARG.to_string())?;
Expand Down Expand Up @@ -793,6 +812,30 @@ fn is_country_parties_path(path: &str) -> bool {
is_country_suffix_path(path, "parties")
}

/// Build the exact nation legislature leadership request path from a
/// validated country key.
fn fetch_country_leaders_path(country_code: &str) -> Result<String, String> {
if !is_country_code(country_code) {
return Err(error::BAD_ARG.to_string());
}
Ok(format!(
"{}/{}/legislature/leaders",
MpFetchOp::CountryLeaders.path(),
country_code.to_ascii_uppercase()
))
}

/// True for the pinned nation legislature leadership path shape.
fn is_country_leaders_path(path: &str) -> bool {
let Some(rest) = path.strip_prefix("/api/country/") else {
return false;
};
let Some(code) = rest.strip_suffix("/legislature/leaders") else {
return false;
};
is_country_code(code)
}

/// True for the pinned nation politicians path shape.
fn is_country_politicians_path(path: &str) -> bool {
is_country_suffix_path(path, "politicians")
Expand Down Expand Up @@ -1363,8 +1406,10 @@ fn is_allowlisted_call(method: &str, path_and_query: &str) -> bool {
| ("GET", "/api/players/online")
| ("GET", "/api/admin/maintenance")
| ("GET", "/api/game-time") => query.is_none(),
// The status read only ever runs with the pinned minimal layout.
("GET", "/api/client-status") => matches!(query, Some("layout=minimal")),
// The status read only ever runs with a pinned layout.
("GET", "/api/client-status") => {
matches!(query, Some("layout=minimal") | Some("layout=full"))
}
("GET", "/api/countries") => query.is_none(),
("GET", "/api/characters/search") => match query {
Some(query) => is_character_search_pair(query),
Expand Down Expand Up @@ -1396,7 +1441,8 @@ fn is_allowlisted_call(method: &str, path_and_query: &str) -> bool {
|| is_country_overview_path(path)
|| is_country_states_path(path)
|| is_country_parties_path(path)
|| is_country_politicians_path(path))
|| is_country_politicians_path(path)
|| is_country_leaders_path(path))
}
("POST", "/api/actions/execute") | ("PATCH", "/api/notifications") => query.is_none(),
("PUT", "/api/notifications/preferences") => query.is_none(),
Expand Down Expand Up @@ -2162,6 +2208,44 @@ pub async fn mp_session_fetch(
.ok_or_else(|| error::BAD_ARG.to_string())?;
fetch_country_politicians_path(country)?
}
MpFetchOp::ClientStatusFull => {
if limit.is_some()
|| offset.is_some()
|| detail.election_id.is_some()
|| detail.corporation_id.is_some()
|| detail.union_id.is_some()
|| detail.cabinet_country_code.is_some()
|| detail.cabinet_position_id.is_some()
|| detail.governor_country_code.is_some()
|| detail.governor_state_id.is_some()
|| detail.country_code.is_some()
|| detail.search_query.is_some()
{
return Err(error::UNSUPPORTED_OP.to_string());
}
fetch_path_and_query(op, limit, offset)?
}
MpFetchOp::CountryLeaders => {
if limit.is_some()
|| offset.is_some()
|| detail.election_id.is_some()
|| detail.corporation_id.is_some()
|| detail.union_id.is_some()
|| detail.cabinet_country_code.is_some()
|| detail.cabinet_position_id.is_some()
|| detail.governor_country_code.is_some()
|| detail.governor_state_id.is_some()
|| detail.country_code.is_some()
|| detail.search_query.is_some()
{
return Err(error::UNSUPPORTED_OP.to_string());
}
let country = detail
.country_code
.as_deref()
.ok_or_else(|| error::BAD_ARG.to_string())?;
fetch_country_leaders_path(country)?
}
MpFetchOp::CharacterSearch => {
if limit.is_some()
|| offset.is_some()
Expand Down Expand Up @@ -2310,9 +2394,12 @@ mod tests {
"/api/client-status?layout=minimal"
));
assert!(!is_allowlisted_call("GET", "/api/client-status"));
// The full layout is allowlisted too, but only for the on-demand
// income breakdown read.
assert!(is_allowlisted_call("GET", "/api/client-status?layout=full"));
assert!(!is_allowlisted_call(
"GET",
"/api/client-status?layout=full"
"/api/client-status?layout=wide"
));
assert!(!is_allowlisted_call(
"GET",
Expand All @@ -2324,6 +2411,27 @@ mod tests {
));
}

#[test]
fn full_status_read_pins_the_full_layout() {
assert_eq!(
MpFetchOp::from_id("client-status-full"),
Some(MpFetchOp::ClientStatusFull)
);
assert_eq!(
fetch_path_and_query(MpFetchOp::ClientStatusFull, None, None).unwrap(),
"/api/client-status?layout=full"
);
assert!(!is_allowlisted_call(
"GET",
"/api/client-status?layout=full&x=1"
));
assert!(!is_allowlisted_call(
"POST",
"/api/client-status?layout=full"
));
assert!(fetch_path_and_query(MpFetchOp::ClientStatusFull, Some(5), None).is_err());
}

#[test]
fn world_reads_resolve_to_pinned_paths() {
assert_eq!(MpFetchOp::from_id("countries"), Some(MpFetchOp::Countries));
Expand Down Expand Up @@ -2408,6 +2516,32 @@ mod tests {
));
assert!(fetch_country_politicians_path("").is_err());

assert_eq!(
MpFetchOp::from_id("country-leaders"),
Some(MpFetchOp::CountryLeaders)
);
assert_eq!(
fetch_country_leaders_path("uk").unwrap(),
"/api/country/UK/legislature/leaders"
);
assert!(is_allowlisted_call(
"GET",
"/api/country/UK/legislature/leaders"
));
assert!(!is_allowlisted_call(
"GET",
"/api/country/UKA/legislature/leaders"
));
assert!(!is_allowlisted_call(
"GET",
"/api/country/UK/legislature/leaders?x=1"
));
assert!(!is_allowlisted_call(
"GET",
"/api/country/UK/legislature/leader"
));
assert!(fetch_country_leaders_path("u k").is_err());

assert_eq!(
MpFetchOp::from_id("election-list"),
Some(MpFetchOp::ElectionList)
Expand Down
1 change: 1 addition & 0 deletions src/mp/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe("MpModeSession enter", () => {
nationRegions: null,
nationParties: null,
nationPoliticians: null,
nationLeaders: null,
electionList: null,
newsFeed: null,
characterSearch: null,
Expand Down
Loading
Loading