test(mgmt): display_settings_surface stays read-only (gaming-rig now accepted)
The old `..._and_forever_rejected` asserted a 400 for keep_alive=forever; now that it's accepted, that PUT succeeded and WROTE gaming-rig into the process-global prefs, racing other tests. Rewrite read-only: assert the surface (5 presets, effective, enforced axes) and read gaming-rig=forever off the preset list — no write. Acceptance is covered on-glass (.116) + the pure policy tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2788,24 +2788,36 @@ mod tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The display-management endpoints: GET returns the policy surface (presets + effective +
|
/// The display-management GET surface (presets + effective + the enforced-axes list). READ-ONLY
|
||||||
/// the Stage-0 enforced list); PUT rejects `keep_alive: forever` (the `gaming-rig` preset)
|
/// on purpose: `prefs()` is a process-global `OnceLock`, so a PUT here would clobber it and race
|
||||||
/// *before* persisting, so this stays read-only against the global policy store.
|
/// other tests running in the same process. `keep_alive: forever` (gaming-rig) is now accepted
|
||||||
|
/// (not rejected) — that acceptance is covered on-glass (`.116`) + by the pure `policy` tests, and
|
||||||
|
/// the `forever` value is read off the surfaced preset below without writing.
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn display_settings_surface_and_forever_rejected() {
|
async fn display_settings_surface() {
|
||||||
let app = test_app(test_state(), None);
|
let app = test_app(test_state(), None);
|
||||||
|
|
||||||
let (status, body) = send(&app, get_req("/api/v1/display/settings")).await;
|
let (status, body) = send(&app, get_req("/api/v1/display/settings")).await;
|
||||||
assert_eq!(status, StatusCode::OK);
|
assert_eq!(status, StatusCode::OK);
|
||||||
|
let presets = body["presets"].as_array().expect("presets array");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
body["presets"].as_array().map(|a| a.len()),
|
presets.len(),
|
||||||
Some(5),
|
5,
|
||||||
"all five named presets are surfaced for the console picker"
|
"all five named presets are surfaced for the console picker"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
body["effective"]["keep_alive"].is_object(),
|
body["effective"]["keep_alive"].is_object(),
|
||||||
"the effective policy is echoed"
|
"the effective policy is echoed"
|
||||||
);
|
);
|
||||||
|
// gaming-rig surfaces keep_alive: forever (no longer rejected) — read it off the preset list.
|
||||||
|
let gaming = presets
|
||||||
|
.iter()
|
||||||
|
.find(|p| p["id"] == "gaming-rig")
|
||||||
|
.expect("gaming-rig preset surfaced");
|
||||||
|
assert_eq!(
|
||||||
|
gaming["fields"]["keep_alive"]["mode"], "forever",
|
||||||
|
"gaming-rig is keep_alive: forever"
|
||||||
|
);
|
||||||
let enforced: Vec<&str> = body["enforced"]
|
let enforced: Vec<&str> = body["enforced"]
|
||||||
.as_array()
|
.as_array()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -2818,23 +2830,6 @@ mod tests {
|
|||||||
assert!(enforced.contains(&"mode_conflict"));
|
assert!(enforced.contains(&"mode_conflict"));
|
||||||
assert!(enforced.contains(&"identity"));
|
assert!(enforced.contains(&"identity"));
|
||||||
assert!(enforced.contains(&"layout"));
|
assert!(enforced.contains(&"layout"));
|
||||||
|
|
||||||
// `gaming-rig` expands to keep_alive: forever → rejected at Stage 0 (before any write).
|
|
||||||
let put = axum::http::Request::put("/api/v1/display/settings")
|
|
||||||
.header("content-type", "application/json")
|
|
||||||
.body(Body::from(
|
|
||||||
serde_json::json!({ "preset": "gaming-rig" }).to_string(),
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
let (status, body) = send(&app, put).await;
|
|
||||||
assert_eq!(status, StatusCode::BAD_REQUEST);
|
|
||||||
assert!(
|
|
||||||
body["error"]
|
|
||||||
.as_str()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.contains("forever"),
|
|
||||||
"the rejection names the unsupported option"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The display state/release endpoints are wired + auth-gated. On the test host no backend has
|
/// The display state/release endpoints are wired + auth-gated. On the test host no backend has
|
||||||
|
|||||||
Reference in New Issue
Block a user