From 92ff2bc0699d0f5d34f0d27d9d93733db42809db Mon Sep 17 00:00:00 2001 From: Wolf Date: Tue, 29 Sep 2026 14:44:54 +0200 Subject: [PATCH] Remove the MOVED redirects MOVED and _moved answered 301 for twelve paths the settings cog moved off of a few days ago. A browser caches a 301 indefinitely, so a path reused later would be unreachable through no fault of that page, and a one-person app has no outstanding bookmark to protect. Drop the table, the routes, its export from app.web, and the tests that pinned it; the old paths now answer plain 404. Keep the test that every section of the Sources page exists, rewritten without MOVED. Co-Authored-By: Claude Sonnet --- app/static/sources.js | 4 ++-- app/web/__init__.py | 4 ++-- app/web/pages.py | 44 ------------------------------------------- docs/decisions.md | 8 +++++--- tests/test_web.py | 42 +++++++++++++++-------------------------- 5 files changed, 24 insertions(+), 78 deletions(-) diff --git a/app/static/sources.js b/app/static/sources.js index 5f18cf9..ff7411f 100644 --- a/app/static/sources.js +++ b/app/static/sources.js @@ -208,8 +208,8 @@ // Sources shows one section: the one the fragment names or contains, or the // first when there is none or it names none, so `/settings/sources#runs` (a - // rail link, an old path's 301, the Search agents page's "follow it under - // Runs") opens Runs, and so does `#messages`, the log at its end. The rest + // rail link, or the Search agents page's "follow it under Runs") opens + // Runs, and so does `#messages`, the log at its end. The rest // are hidden, not removed, so their scripts still find their roots. It runs // as the script loads rather than on DOMContentLoaded, so the page never // paints all three first. diff --git a/app/web/__init__.py b/app/web/__init__.py index adfb513..47b0055 100644 --- a/app/web/__init__.py +++ b/app/web/__init__.py @@ -7,8 +7,8 @@ from __future__ import annotations from app.web.api import router as api_router from app.web.pages import ( - MOVED, SETTINGS, STATIC_DIR, TABS, router as pages_router, templates, + SETTINGS, STATIC_DIR, TABS, router as pages_router, templates, ) -__all__ = ["MOVED", "SETTINGS", "STATIC_DIR", "TABS", "api_router", "pages_router", +__all__ = ["SETTINGS", "STATIC_DIR", "TABS", "api_router", "pages_router", "templates"] diff --git a/app/web/pages.py b/app/web/pages.py index d8ee355..a103d16 100644 --- a/app/web/pages.py +++ b/app/web/pages.py @@ -23,13 +23,6 @@ contains; the others stay in the page, hidden, so each section's script (the ones they had as pages of their own, each guarding on its own root element) keeps working. -Every path a page has had before (`/agents`, `/companies`, `/sources`, -`/jobs`, `/schedules`, `/messages`, `/account`, and the six sub-tabs the -settings shell started with) answers 301 to its place now, query string -kept, so a bookmark still lands. A merged page's old path lands on its -section's anchor; the old Messages paths land on `#messages`, the log's -block at the end of Runs. - `FUNCTIONS` and `HOSTS` are `plugins.ats`'s, not `app`'s: the nine job functions are the classifier's vocabulary and the hosts are what it parses, and this reaches `plugins/` the same way `app.cli` does, since a plugin is @@ -41,7 +34,6 @@ Jobindex areas and Adzuna countries on the Sources page come from from __future__ import annotations import sys -from collections.abc import Callable from dataclasses import dataclass from pathlib import Path @@ -94,24 +86,6 @@ SECTIONS: dict[str, tuple[tuple[str, str], ...]] = { ), } -#: Where each page that used to be a tab or a sub-tab lives now. The fragment -#: is the section on the merged page, or an element in one (`#messages`, in -#: Runs); a browser keeps it across the 301. -MOVED: dict[str, str] = { - "/agents": "/settings/agents", - "/settings/ranking": "/settings/agents", - "/companies": "/settings/sources#company-boards", - "/settings/companies": "/settings/sources#company-boards", - "/sources": "/settings/sources#job-boards", - "/settings/searches": "/settings/sources#job-boards", - "/jobs": "/settings/sources#runs", - "/schedules": "/settings/sources#runs", - "/settings/pulls": "/settings/sources#runs", - "/messages": "/settings/sources#messages", - "/settings/messages": "/settings/sources#messages", - "/account": "/settings/account", -} - #: `value, label` for each select option. `FUNCTIONS` is already the value a #: role's `function` column holds; only the label is dressed up. FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS] @@ -192,21 +166,3 @@ def sources(request: Request) -> HTMLResponse: @router.get("/settings/account", response_class=HTMLResponse) def account(request: Request) -> HTMLResponse: return page(request, "settings/account.html") - - -def _moved(to: str) -> Callable[[Request], RedirectResponse]: - """A 301 to `to`, carrying the query string, so `/agents?x=1` keeps it. - The query goes before `to`'s fragment, if it has one, or the browser - would read `#runs?x=1` as one fragment.""" - path, _, fragment = to.partition("#") - def redirect(request: Request) -> RedirectResponse: - query = request.url.query - target = f"{path}?{query}" if query else path - return RedirectResponse(f"{target}#{fragment}" if fragment else target, - status_code=301) - return redirect - - -for _old, _new in MOVED.items(): - router.add_api_route(_old, _moved(_new), methods=["GET"], - response_class=RedirectResponse) diff --git a/docs/decisions.md b/docs/decisions.md index af07529..e9f9952 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -126,15 +126,17 @@ What was decided for roledesk and the one reason for each. The longer reasoning ## The phone -**Two tabs and a cog.** `TABS` in `app/web/pages.py` becomes Roles and Applications; the other six pages (Agents, Companies, Sources, Jobs, Schedules, Messages, Account) move behind a settings cog at `/settings/`, because nine tabs wrapped to three rows on a phone and six of them were setup or system pages. The old paths answer 301 to their new place, query string kept, so a bookmark or a `?agent=` link still lands. +**Two tabs and a cog.** `TABS` in `app/web/pages.py` becomes Roles and Applications; the other six pages (Agents, Companies, Sources, Jobs, Schedules, Messages, Account) move behind a settings cog at `/settings/`, because nine tabs wrapped to three rows on a phone and six of them were setup or system pages. -**Settings are three sub-tabs: Search agents, Sources, Account.** Six sub-tabs were three setup pages and three system pages for two things, what the app ranks by and where roles come from, so each is one page now and Account stays its own. The old paths answer 301 to the section they became. +**Settings are three sub-tabs: Search agents, Sources, Account.** Six sub-tabs were three setup pages and three system pages for two things, what the app ranks by and where roles come from, so each is one page now and Account stays its own. + +**The old paths' 301s are gone.** `MOVED` answered 301 for the twelve paths above, kept for the few days between the move and this cut, on the assumption that a bookmark should still land. A browser caches a 301 indefinitely, so a path a future page reused would be unreachable through no fault of that page; a one-person app with no outstanding bookmarks does not need to carry that risk. **Sources is one page, one section per plugin.** Job boards are the `search` plugin's queries, company boards are `ats`'s, and the runs that read both end the page with the message log. A source's section says which plugin it is, and following a company, hiding it and switching its board off are one list. The UI says "job board" for what the API and CLI call a search, since "search agent" already means something else. **Search agents are back in the UI as a list.** One person may run several: their own hunt, and one that monitors roles for someone else, each with its own intent and gates. The list has New and Delete; a delete takes the agent's votes, liked companies and scores with it. -**Settings pages sit beside a rail, and Sources shows one section at a time, chosen by the URL fragment.** The company boards list runs to 50 or 60 companies, so Runs at the end of a stacked page was out of reach and jump links still meant scrolling back up. The rail (`settings/_rail.html`, from `SETTINGS` and `SECTIONS` in `app/web/pages.py`) is sticky beside the content, and a strip under the header below 60rem. The fragment rather than a path per section, because the old paths already 301 to `/settings/sources#runs` and the like, and a hidden section stays in the DOM, so each section's script runs unchanged. +**Settings pages sit beside a rail, and Sources shows one section at a time, chosen by the URL fragment.** The company boards list runs to 50 or 60 companies, so Runs at the end of a stacked page was out of reach and jump links still meant scrolling back up. The rail (`settings/_rail.html`, from `SETTINGS` and `SECTIONS` in `app/web/pages.py`) is sticky beside the content, and a strip under the header below 60rem. The fragment rather than a path per section, because a hidden section stays in the DOM, so each section's script runs unchanged. **Runs is the queue's own elements plus a Problems log.** `` and `` draw what is running and when the pull runs next, the app adds only "Run the pull now", disabled while a pull cascade is live, and the message log is the section's last block rather than a section of its own; `#messages` still lands on it. "Run one stage" went because the cascade is the unit of work: a stage run alone is a partial pull whose result the next stage never sees. `app job ` and `POST /api/jobs` keep the per-stage entry points, which is what "Save and score" uses. diff --git a/tests/test_web.py b/tests/test_web.py index 5d2fb69..9f71ed0 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -17,7 +17,7 @@ from fastapi.testclient import TestClient from app.config import Config, ServerConfig from app.main import create_app from app.storage import Store -from app.web import MOVED, SETTINGS, TABS +from app.web import SETTINGS, TABS from app.web.pages import SECTIONS from auth import AuthConfig from desk.models import Item @@ -575,11 +575,10 @@ def test_every_settings_page_has_the_rail_and_not_the_tab_row(client: TestClient < rail.index('href="/settings/account"') -def test_a_moved_section_is_one_the_sources_page_shows(client: TestClient) -> None: - """Every old path that lands on a fragment of Sources names a section of - `SECTIONS` or an element inside one, and each section is a `
` on the page, which is what sources.js shows one of. The - old Messages paths land on `#messages`, the log at the end of Runs.""" +def test_every_section_of_the_sources_page_exists(client: TestClient) -> None: + """Each entry of `SECTIONS["/settings/sources"]` is a `
` on the page, which is what sources.js shows one of, and + the log at the end of Runs still answers `#messages`.""" anchors = [anchor for anchor, _ in SECTIONS["/settings/sources"]] assert anchors == ["job-boards", "company-boards", "runs"] page = client.get("/settings/sources").text @@ -587,12 +586,7 @@ def test_a_moved_section_is_one_the_sources_page_shows(client: TestClient) -> No for anchor in anchors: assert f'
' in page runs = page[page.index('id="runs"'):] - for to in MOVED.values(): - path, _, anchor = to.partition("#") - if anchor: - assert path == "/settings/sources", to - assert anchor in anchors or f'id="{anchor}"' in runs, to - assert MOVED["/messages"] == MOVED["/settings/messages"] == "/settings/sources#messages" + assert 'id="messages"' in runs def test_settings_is_search_agents(client: TestClient) -> None: @@ -600,21 +594,15 @@ def test_settings_is_search_agents(client: TestClient) -> None: assert res.status_code == 302 and res.headers["location"] == "/settings/agents" -@pytest.mark.parametrize(("old", "new"), sorted(MOVED.items())) -def test_an_old_tab_moves_permanently_and_keeps_its_query( - client: TestClient, old: str, new: str) -> None: - """A merged page's old path lands on its section: the query goes before - the anchor, or the browser would take `#runs?q=` as one fragment.""" - assert {"/agents", "/settings/ranking", "/companies", "/sources", "/jobs", - "/schedules", "/messages", "/settings/searches", "/settings/companies", - "/settings/pulls", "/settings/messages", "/account"} <= set(MOVED) - path, _, anchor = new.partition("#") - res = client.get(old, follow_redirects=False) - assert res.status_code == 301 and res.headers["location"] == new - res = client.get(f"{old}?agent=3&q=a+b", follow_redirects=False) - assert res.status_code == 301 - assert res.headers["location"] == f"{path}?agent=3&q=a+b" + (f"#{anchor}" if anchor else "") - assert client.get(old).status_code == 200 +@pytest.mark.parametrize("old", ["/agents", "/settings/ranking", "/companies", "/sources", + "/jobs", "/schedules", "/messages", "/settings/searches", + "/settings/companies", "/settings/pulls", + "/settings/messages", "/account"]) +def test_an_old_tab_path_is_gone(client: TestClient, old: str) -> None: + """The paths the settings cog moved off of answer 404 now, not a cached + 301: a browser caches a 301 indefinitely, so a path reused later would be + unreachable were the redirect still there.""" + assert client.get(old).status_code == 404 def test_each_page_loads_only_its_own_script(client: TestClient) -> None: