diff --git a/scripts/sitegen/agents.py b/scripts/sitegen/agents.py index b7ebd66da..38053f7cb 100644 --- a/scripts/sitegen/agents.py +++ b/scripts/sitegen/agents.py @@ -19,12 +19,11 @@ import json from collections.abc import Callable from pathlib import Path -from model.guides import PACKAGE_COMMAND +from model.guides import PACKAGE_COMMAND, install_command +from sitegen.config import SITE_ORIGIN, SITE_URL -SITE = "https://abdess.github.io/retrobios/" -PUBLISHER = "abdess.github.io" -SH = "curl -fsSL https://abdess.github.io/retrobios/i | sh -s --" -PS = "& ([scriptblock]::Create((irm https://abdess.github.io/retrobios/i.ps1)))" +SITE = SITE_URL +PUBLISHER = SITE_ORIGIN.removeprefix("https://") # What a folder put into a command may not hold, as agent-tools.ts refuses # it: PowerShell also ends a single-quoted string on the typographic quotes. REFUSED = "any quote, straight or typographic (' \" ‘ ’ ‚ ‛ “ ” „), a backtick or a control character" @@ -34,6 +33,8 @@ QUOTING = (f"A folder goes in single quotes, attached to its option. One that ho "command and refuses such a folder.") UVX = PACKAGE_COMMAND +# The options the agent steps install with: what the card's games need to start. +GAMES = "--for-games --required-only" # EVENT_SCHEMA of install.py, and the schema generate_event_schema.py writes # from EVENT_KEYS, as the site publishes it. tests/test_site_agents.py holds # both to install.py. @@ -108,9 +109,9 @@ def llms_txt(platforms: list[tuple[str, str]]) -> str: "without. `--yes` alone installs what the card's games need, optional files " "included, and `--all-files` the setup's whole list (gigabytes).", "", - f"1. Preview, nothing written: `{SH} --for-games --required-only --dry-run`", - f"2. Install, no questions: `{SH} --for-games --required-only --yes`", - f"3. On Windows (PowerShell): `{PS} --for-games --required-only --yes`", + f"1. Preview, nothing written: `{install_command('sh', GAMES + ' --dry-run')}`", + f"2. Install, no questions: `{install_command('sh', GAMES + ' --yes')}`", + f"3. On Windows (PowerShell): `{install_command('powershell', GAMES + ' --yes')}`", "", "- Run it on the device itself (its terminal or SSH), or on a computer with the device's " "card plugged in. The installer recognises the handheld systems on the card, among them " @@ -215,8 +216,8 @@ def skill_md() -> str: "", "1. Ask where the games are: on the device itself (with its terminal or SSH), or on " "its card plugged into this computer.", - f"2. Preview, nothing is written: `{SH} --for-games --required-only --dry-run` " - f"(Windows PowerShell: `{PS} --for-games --required-only --dry-run`).", + f"2. Preview, nothing is written: `{install_command('sh', GAMES + ' --dry-run')}` " + f"(Windows PowerShell: `{install_command('powershell', GAMES + ' --dry-run')}`).", "3. Show the user the plan it prints: the setup found, the BIOS folder, the files and " "their size. Ask before going on if the setup or the folder is not the one expected.", "4. Install with the same command, `--yes` in place of `--dry-run`.", diff --git a/scripts/sitegen/indexnow.py b/scripts/sitegen/indexnow.py index 4630c4640..eb7692710 100644 --- a/scripts/sitegen/indexnow.py +++ b/scripts/sitegen/indexnow.py @@ -5,9 +5,9 @@ from __future__ import annotations import json from core import upstream -from sitegen.agents import INDEXNOW_FILE, INDEXNOW_KEY, SITE +from sitegen.agents import INDEXNOW_FILE, INDEXNOW_KEY, PUBLISHER, SITE -HOST = "abdess.github.io" +HOST = PUBLISHER # What one IndexNow request accepts. MAX_URLS = 10_000 USER_AGENT = "retrobios-indexnow" diff --git a/scripts/sitegen/insights.py b/scripts/sitegen/insights.py index 703972eb5..5d84d1dfc 100644 --- a/scripts/sitegen/insights.py +++ b/scripts/sitegen/insights.py @@ -23,12 +23,13 @@ from core import upstream from core.artifacts import write_text_atomic from core.cli import SourceUnreadable from core.github import github_token +from sitegen.config import REPO_SLUG, SITE_URL CONFIG = Path(os.environ.get("RETROBIOS_CONFIG", Path.home() / ".config" / "retrobios")) -SITE_PROPERTY = "https://abdess.github.io/retrobios/" +SITE_PROPERTY = SITE_URL GOATCOUNTER = "https://retrobios.goatcounter.com/api/v0" -REPOSITORY = "Abdess/retrobios" +REPOSITORY = REPO_SLUG SOURCES = ("gsc", "goatcounter", "github") USER_AGENT = "retrobios-site-insights" # GoatCounter builds an export in the background: it is asked for every diff --git a/tests/test_site_agents.py b/tests/test_site_agents.py index 28332f24d..4d8742321 100644 --- a/tests/test_site_agents.py +++ b/tests/test_site_agents.py @@ -30,12 +30,29 @@ class TheGuideLeadsToTheFewestFiles(unittest.TestCase): self.assertIn("\n## Setting up a device for its user\n", self.text) def test_every_command_installs_only_what_the_games_need(self) -> None: - commands = re.findall(r"`((?:curl|&) [^`]+)`", self.text) + commands = re.findall(r"`((?:curl |&\(\[scriptblock)[^`]+)`", self.text) self.assertGreaterEqual(len(commands), 3) for command in commands: with self.subTest(command=command): self.assertIn("--for-games --required-only", command) + def test_the_commands_are_the_ones_the_pages_show(self) -> None: + from model.guides import install_command + + for text in (self.text, siteagents.skill_md()): + for shell in ("sh", "powershell"): + with self.subTest(shell=shell, text=text[:20]): + self.assertIn(install_command(shell, "--for-games --required-only") + " --", + text) + + def test_the_webmcp_tool_writes_the_same_command(self) -> None: + from model.guides import install_command + + tools = TOOLS.read_text(encoding="utf-8") + for shell in ("sh", "powershell"): + with self.subTest(shell=shell): + self.assertIn(f"'{install_command(shell, '-').removesuffix(' -')}'", tools) + def test_each_setup_has_its_page(self) -> None: self.assertIn("(https://abdess.github.io/retrobios/platforms/batocera/)", self.text) @@ -111,7 +128,7 @@ class TheSkillIsAnAgentSkill(unittest.TestCase): self.assertRegex(front["name"], r"^[a-z0-9-]{1,64}$") self.assertLessEqual(len(front["description"]), 1024) self.assertTrue(body.lstrip().startswith("# ")) - for command in re.findall(r"`((?:curl|&) [^`]+)`", body): + for command in re.findall(r"`((?:curl |&\(\[scriptblock)[^`]+)`", body): with self.subTest(command=command): self.assertIn("--for-games --required-only", command) diff --git a/website/src/scripts/agent-tools.ts b/website/src/scripts/agent-tools.ts index 1a156d4a7..c42b12e74 100644 --- a/website/src/scripts/agent-tools.ts +++ b/website/src/scripts/agent-tools.ts @@ -183,7 +183,7 @@ const setupFiles: Tool = { // options wiki/installer.md documents: the fewest files the games on the // card need, unless the user asks for everything. const SH = 'curl -fsSL https://abdess.github.io/retrobios/i | sh -s --'; -const PS = '& ([scriptblock]::Create((irm https://abdess.github.io/retrobios/i.ps1)))'; +const PS = '&([scriptblock]::Create((irm https://abdess.github.io/retrobios/i.ps1)))'; const setupCommand: Tool = { name: 'device_setup_command',