mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-02 07:47:58 +00:00
feat(web-app-dashboard): move the tile switch to services.dashboard.display
The dashboard read `display` from the role's meta/info.yml, which no inventory can override, so a host could not hide a tile. docker_cards now skips a card when `services.dashboard.display` in the merged applications is false, and absent still means shown; a non-bool value fails loudly. roles_with_service drops the same role from the dashboard tile-reachability targets so the Playwright spec does not wait for a hidden tile, and the inventory validator accepts `services.dashboard.display` for every role that declares `services.dashboard`, since no role default carries it. `display` leaves the meta/info.yml allowlist, web-app-jellyfin drops its redundant `display: true`, and base.md and layout.md document the new switch. Real lookups with web-app-gitea set to display false render the Dashboard and Jellyfin cards and only jellyfin as a tile target, and all three without the override; the nine tests for the new behaviour fail against the old code. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
abee135c53
commit
3ef937a9d8
12 files changed
+269
-36
No files matched your search
@@ -359,6 +359,100 @@ logo:
|
||||
with self.assertRaisesRegex(AnsibleError, "nope"):
|
||||
self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
def _add_role(self, role_name, application_id, info_yaml):
|
||||
role_dir = Path(self.test_roles_dir) / role_name
|
||||
(role_dir / "meta").mkdir(parents=True)
|
||||
(role_dir / "vars").mkdir(parents=True)
|
||||
(role_dir / ROLE_FILE_VARS_MAIN).write_text(
|
||||
f"application_id: {application_id}\n", encoding="utf-8"
|
||||
)
|
||||
(role_dir / "README.md").write_text(f"# {role_name}\n", encoding="utf-8")
|
||||
(role_dir / ROLE_FILE_META_MAIN).write_text(
|
||||
'galaxy_info:\n description: "Second role."\n', encoding="utf-8"
|
||||
)
|
||||
(role_dir / ROLE_FILE_META_INFO).write_text(info_yaml, encoding="utf-8")
|
||||
|
||||
def _two_role_variables(self):
|
||||
self._add_role("web-app-other", "other", "logo:\n class: fa-solid fa-cube\n")
|
||||
fake_variables = self._base_fake_variables()
|
||||
fake_variables["domains"]["other"] = "other.example.com"
|
||||
fake_variables["applications"]["other"] = {
|
||||
"services": {"dashboard": {"enabled": True}}
|
||||
}
|
||||
fake_variables["group_names"] = ["portfolio", "other"]
|
||||
return fake_variables
|
||||
|
||||
def test_display_false_skips_the_card(self):
|
||||
fake_variables = self._base_fake_variables()
|
||||
fake_variables["applications"]["portfolio"]["services"]["dashboard"][
|
||||
"display"
|
||||
] = False
|
||||
|
||||
result = self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
self.assertEqual(result, [[]])
|
||||
|
||||
def test_absent_display_shows_the_card(self):
|
||||
fake_variables = self._base_fake_variables()
|
||||
self.assertNotIn(
|
||||
"display",
|
||||
fake_variables["applications"]["portfolio"]["services"]["dashboard"],
|
||||
)
|
||||
|
||||
result = self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
|
||||
|
||||
def test_display_true_shows_the_card(self):
|
||||
fake_variables = self._base_fake_variables()
|
||||
fake_variables["applications"]["portfolio"]["services"]["dashboard"][
|
||||
"display"
|
||||
] = True
|
||||
|
||||
result = self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
|
||||
|
||||
def test_display_false_hides_only_its_own_card(self):
|
||||
fake_variables = self._two_role_variables()
|
||||
fake_variables["applications"]["other"]["services"]["dashboard"]["display"] = (
|
||||
False
|
||||
)
|
||||
|
||||
result = self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
|
||||
|
||||
def test_both_cards_render_without_display(self):
|
||||
fake_variables = self._two_role_variables()
|
||||
|
||||
result = self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
self.assertEqual(
|
||||
[c["title"] for c in result[0]],
|
||||
["Portfolio Application", "web-app-other"],
|
||||
)
|
||||
|
||||
def test_info_display_false_no_longer_hides_the_card(self):
|
||||
meta_info_path = Path(self.role_dir) / ROLE_FILE_META_INFO
|
||||
meta_info_path.write_text(
|
||||
"logo:\n class: fa-solid fa-briefcase\ndisplay: false\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = self._run_lookup(LookupModule(), self._base_fake_variables())
|
||||
|
||||
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
|
||||
|
||||
def test_non_bool_display_fails_loudly(self):
|
||||
fake_variables = self._base_fake_variables()
|
||||
fake_variables["applications"]["portfolio"]["services"]["dashboard"][
|
||||
"display"
|
||||
] = "false"
|
||||
|
||||
with self.assertRaisesRegex(AnsibleError, "portfolio"):
|
||||
self._run_lookup(LookupModule(), fake_variables)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -613,6 +613,37 @@ class RolesWithServiceLookupTests(unittest.TestCase):
|
||||
("matrix.example.com", "https://web-app-chat.example.com"),
|
||||
)
|
||||
|
||||
def test_dashboard_display_false_drops_the_tile_target(self):
|
||||
applications = {
|
||||
"web-app-hidden": {
|
||||
"services": {
|
||||
"dashboard": {"enabled": True, "shared": True, "display": False}
|
||||
},
|
||||
"domains": {"canonical": ["hidden.example.com"]},
|
||||
},
|
||||
"web-app-shown": {
|
||||
"services": {"dashboard": {"enabled": True, "shared": True}},
|
||||
"domains": {"canonical": ["shown.example.com"]},
|
||||
},
|
||||
}
|
||||
result = self._run(["dashboard"], applications)[0]
|
||||
self.assertEqual([r["id"] for r in result], ["web-app-shown"])
|
||||
|
||||
def test_dashboard_display_true_keeps_the_tile_target(self):
|
||||
applications = self._card_target_role("dashboard", display=True)
|
||||
result = self._run(["dashboard"], applications)[0]
|
||||
self.assertEqual([r["id"] for r in result], ["web-app-chat"])
|
||||
|
||||
def test_dashboard_non_bool_display_fails_loudly(self):
|
||||
applications = self._card_target_role("dashboard", display="false")
|
||||
with self.assertRaisesRegex(AnsibleError, "web-app-chat"):
|
||||
self._run(["dashboard"], applications)
|
||||
|
||||
def test_other_services_ignore_a_display_key(self):
|
||||
applications = self._card_target_role("prometheus", display=False)
|
||||
result = self._run(["prometheus"], applications)[0]
|
||||
self.assertEqual([r["id"] for r in result], ["web-app-chat"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user