Replace brittle hardcoded admin path assertions in functional and kernel tests with route-derived URLs
## Problem
Follow-up to:
#3586323+s
Several ai_context tests assert hardcoded admin URL paths instead of
deriving expected paths from Drupal routes. This is the same failure
class as [#3586323]: production code builds links with
`Url::fromRoute()`, but tests break when an upstream module changes a
route path.
The agent edit form assertion was fixed separately in #3586323. This
issue tracks the remaining brittle path assertions, grouped by risk.
### Pattern
Brittle:
```php
$this->assertSession()->linkByHrefExists('/admin/config/ai/agents/debug?agent_id=' . $agent_id);
```
Preferred:
```php
$debug_path = Url::fromRoute('ai_agents_debugger.form', [], [
'query' => ['agent_id' => $agent_id],
])->toString();
$this->assertSession()->linkByHrefExists($debug_path);
```
`AiContextItemViewTest` already follows the preferred pattern with
`$entity->toUrl('canonical')->toString()`.
Production runtime code in `src/` is already route-based. Only tests
(and some docs) need hardening.
### Scope: high-priority test fixes (external routes)
These assert paths owned by other modules and can fail on dependency
updates even when ai_context behavior is correct.
1. **`tests/src/Functional/AiContextAgentSettingsTest.php`**
- `testDebugAndExploreLinkVisibility()` (~30 assertions)
- Hardcoded:
- `/admin/config/ai/agents/debug?agent_id=`
- `/admin/config/ai/agents/explore?agent_id=`
- Derive from:
- `ai_agents_debugger.form`
- `ai_agents_explorer.explorer`
2. **`tests/src/Functional/AiContextAdminSettingsTest.php`**
- Hardcoded: `/admin/modules?filter=ai_context_document_loader`
- Derive from: `system.modules_list` with query `filter`
3. **`tests/src/Kernel/AiContextScopeLanguageTest.php`**
- Hardcoded markup check: `/admin/config/regional/language`
- Derive from: `entity.configurable_language.collection`
4. **`tests/src/Kernel/AiContextScopeTagTest.php`**
- Hardcoded: `/admin/structure/taxonomy/manage/ai_context_tags/overview`
- Derive from: `entity.taxonomy_vocabulary.overview_form`
5. **`modules/ai_context_document_loader/tests/src/Functional/AiContextDocumentLoaderIntegrationFunctionalTest.php`**
- Hardcoded: `/admin/config/media/document-loader`
- Derive from the document_loader settings route (confirm route
name in installed document_loader version)
6. **`tests/src/Unit/AiContextLanguageDetectorTraitTest.php`**
- Hardcoded explore AJAX paths:
- `/admin/config/ai/agents/explore/start`
- `/admin/config/ai/agents/explore` (referer examples)
- Derive from ai_agents_explorer routes where appropriate, or
document that these are intentional fixture paths if the unit test
only cares about language-prefix parsing
### Optional follow-up (same issue or child issues)
**Medium priority — ai_context own admin paths**
Many functional tests hardcode `/admin/config/ai/context/...` paths
that mirror `ai_context.routing.yml` (~200+ `drupalGet()` /
`addressEquals()` uses). These are lower risk (won't break on contrib
updates), but will all fail if ai_context restructures admin URLs.
Consider a shared test helper and incremental conversion.
**Low priority — documentation**
Update docs that still reference outdated admin paths, including agent
URLs changed in ai_agents 1.3.2+ (`/admin/config/ai/tools-automation/agents`):
- `README.md`
- `docs/index.md`
- `docs/developers/configuration.md`
- `docs/features/agent_configuration.md`
- `docs/features/scopes.md`
- `docs/features/multilingual.md`
- `docs/features/scheduling.md`
- `docs/features/importers.md`
- `docs/developers/services.md`
## Proposed approach
- Add a small test helper/trait method, e.g.
`protected function getRoutePath(string $route, array $params = [], array $options = []): string`
- Replace external-route hardcoded assertions first
- Run affected functional/kernel/unit tests after each file
- Keep ai_context-path hardcoding as a separate follow-up if scope is
too large for one MR
### Out of scope
- Production code changes (already route-based)
- `AiContextUsageTrackerTest` fake paths (`/admin/foo`, etc.) — test
fixtures, not route dependencies
- `AiContextScopeSiteSectionTest` path-matching inputs — logic test
data, not href assertions
## Test plan
- [ ] Run updated tests in each changed file
- [ ] Run full `tests/src/Functional/AiContextAgentSettingsTest.php`
- [ ] Run full `tests/src/Functional/AiContextAdminSettingsTest.php`
- [ ] Run affected kernel/unit tests listed above
- [ ] Confirm CI phpunit remains green
## Related
- #3586323 — agent edit form path assertion (fixed separately)
- ai_agents [#3586032](https://www.drupal.org/project/ai_agents/issues/3586032) — upstream route move that exposed this pattern
issue