From 9eb2335f5570f3572ddd22fddad27cfac3c9c655 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:41:09 -0400 Subject: [PATCH 01/23] 2026-10-29-2038-register-roster-redirect-domains: shaped --- .../meta.yml | 5 +++ .../references.md | 6 ++++ .../shape.md | 36 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/references.md create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml new file mode 100644 index 0000000..03973cb --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml @@ -0,0 +1,5 @@ +id: 2026-10-29-2038-register-roster-redirect-domains +title: 'Register Roster redirect domains' +status: shaping +created: '2026-10-29 20:38' +standards: {} diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/references.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/references.md new file mode 100644 index 0000000..a04d34a --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/references.md @@ -0,0 +1,6 @@ +# References + +- Roster's current implementation: `Roster/src/Atrium/RedirectDomains.php`, `Roster/src/Atrium/Http/Controllers/RedirectDomainUiController.php`, `Roster/resources/views/ui/partials/redirect-domains.blade.php`, the routes at `Roster/src/Atrium/RosterPlugin.php:149-150, :174-175`, and `Roster/tests/Cortex/RedirectDomainsTest.php`. +- Where it renders today: `OrganizationUiController::offers()` (:310, the `mcp` tab) and `UserUiController:328` plus `users/partials/overview.blade.php:249`. +- Cortex domain: `Cortex/src/Domains/RedirectDomain/` (actions, `Services/RedirectDomains.php`, policy). +- Cortex inline trails: `Cortex/resources/views/ui/virtual-agents/index.blade.php:77`, `form.blade.php:150` and `ui/partials/override.blade.php:60`. diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md new file mode 100644 index 0000000..4e2a27b --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md @@ -0,0 +1,36 @@ +# Register Roster redirect domains — Shaping Notes + +## Scope + +Cortex owns its MCP redirect-domain UI on Roster's screens. Today Roster renders it when it detects Cortex (`Roster\Atrium\RedirectDomains::available()`). After this change, Cortex registers it through Atrium's screen extensions registry. + +In scope: + +- **Organization tab.** Register an `mcp` tab on `roster.organization` (label "MCP", icon `globe-alt`) that lists, adds and removes the organization's redirect domains. Visible when `cortex.redirect_domains.enabled` is on and the viewer holds the permission (spec writing settles which: Roster's `roster.organizations.update` via the host check, or a Cortex permission). +- **User section.** Register a "Redirect domains" section on the `roster.user` overview slot. +- **Move from Roster:** + - `RedirectDomainUiController` (113 lines) + - its four routes, which become Cortex Atrium routes under Cortex's plugin, e.g. `atrium.cortex.redirect-domains.*` + - `ui/partials/redirect-domains.blade.php` + - `tests/Cortex/RedirectDomainsTest.php` + + These call Cortex's existing `Create`, `Delete` and `ListRedirectDomainsAction`. +- **Cortex's own screens.** Drop the inline `` from `ui/virtual-agents/index`, `form` and `ui/partials/override`. Declare those screens' audited subjects for Keen. + +## Decisions + +- D-001: Cortex references Roster only by screen keys and the model classes it already supports through `RedirectDomains` (`Cortex/src/Domains/RedirectDomain/Services/RedirectDomains.php:78`). It adds no `class_exists()` checks for Roster UI. If Roster isn't installed, the registrations never render. +- D-002: open for spec review: whether Roster's organization and user models are looked up by the morph types already registered with Cortex's `RedirectDomains`, or by the screen's record. + +## Context + +- **Depends on:** Atrium `screen-extensions-registry`. Must merge with or before Roster `adopt-atrium-screen-registry`, which deletes Roster's copy. +- **References:** see `references.md`. + +## Standards + +- architecture/dependencies: the add-on registers into the host by key. +- architecture/public-api: new routes and registration keys. +- atrium/components: views use `x-atrium::*` only. +- http/routes, http/authorization: the moved routes keep their middleware and policy checks. +- testing/test-layers: the moved feature test runs against Roster as a dev dependency. From d83622444634e17c624e8934e57af5e4a654f9cd Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:49:06 -0400 Subject: [PATCH 02/23] 2026-10-29-2038-register-roster-redirect-domains: shaping decisions --- .../2026-10-29-2038-register-roster-redirect-domains/shape.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md index 4e2a27b..d6b6dfa 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md @@ -21,6 +21,7 @@ In scope: - D-001: Cortex references Roster only by screen keys and the model classes it already supports through `RedirectDomains` (`Cortex/src/Domains/RedirectDomain/Services/RedirectDomains.php:78`). It adds no `class_exists()` checks for Roster UI. If Roster isn't installed, the registrations never render. - D-002: open for spec review: whether Roster's organization and user models are looked up by the morph types already registered with Cortex's `RedirectDomains`, or by the screen's record. +- D-003: the organization tab registers as `cortex.mcp` (vendor-prefixed, Atrium D-008). Old `?tab=mcp` links fall back to the default tab. ## Context From 6cbefe08a24dde91a299e7c0455ea787bc46c33a Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:58:59 -0400 Subject: [PATCH 03/23] 2026-10-29-2038-register-roster-redirect-domains: every screen declares slots and tab bar --- .../shape.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md index d6b6dfa..465b1c2 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md @@ -35,3 +35,8 @@ In scope: - atrium/components: views use `x-atrium::*` only. - http/routes, http/authorization: the moved routes keep their middleware and policy checks. - testing/test-layers: the moved feature test runs against Roster as a dev dependency. + +## Addendum (2026-10-29): every screen declares slots and tab bar + +User decision (Atrium D-013): every Atrium screen in this package declares itself with `Screen::make("{package}.{screen}")`, renders the Atrium tab bar (only visible once at least 2 tabs are visible), and declares the standard slots: `header.actions`, `before` and `after` on all screens; `aside` and `history` (when audited) on detail screens; the `row.actions` row slot on list screens. Screens without built-in tabs get a default `overview` tab. With nothing registered, every existing feature and browser test passes unchanged. A feature test per screen registers a tab and a section in each standard slot and asserts that they render. +Cortex screens (about 11): virtual agents index, create and edit; concrete agents index and show; run; tools and tool description; servers and server instructions; redirect domains. From b647572beed48ba73626109324c3f0a4470d716e Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 17:04:41 -0400 Subject: [PATCH 04/23] 2026-10-29-2038-register-roster-redirect-domains: no package knows another --- .../shape.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md index 465b1c2..5d063f0 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/shape.md @@ -40,3 +40,11 @@ In scope: User decision (Atrium D-013): every Atrium screen in this package declares itself with `Screen::make("{package}.{screen}")`, renders the Atrium tab bar (only visible once at least 2 tabs are visible), and declares the standard slots: `header.actions`, `before` and `after` on all screens; `aside` and `history` (when audited) on detail screens; the `row.actions` row slot on list screens. Screens without built-in tabs get a default `overview` tab. With nothing registered, every existing feature and browser test passes unchanged. A feature test per screen registers a tab and a section in each standard slot and asserts that they render. Cortex screens (about 11): virtual agents index, create and edit; concrete agents index and show; run; tools and tool description; servers and server instructions; redirect domains. + +## Addendum (2026-10-29): no package knows another (Atrium D-015 to D-019) + +User principle (Atrium D-017): no package has knowledge of another. Companion packages are suggested, never required. Integrations are done through simple config. Consequences for this spec: +- Remove `refactor-circus/atrium` from `require`, and add it to `suggest` (D-018: Keystone is the only allowed requirement). The Atrium plugin, its routes, views and `Atrium\*` classes load only when Atrium is installed (`registerAtriumPlugin()` already checks for this). Code outside `src/Atrium` must not reference Atrium classes. An arch test enforces this, and the suite runs once without Atrium (a CI lane or a test mode that removes it) to prove the package boots and its HTTP API and MCP work. +- Screens declare no audit subject (that concept is removed from Atrium). Keen attaches History by wildcard from its own config, and the screen record is the subject. +- Stop calling `historyNavItem()` (removed from Atrium, D-016); Keen adds History nav items. +- The redirect-domains UI is placed through config (D-019): `config/cortex.php` `atrium.redirect_domains.screens` defaults to `['roster.organization' => 'tab', 'roster.user' => 'aside']`. The code names no Roster class or screen. The redirect-domain owner model comes from the screen's record and Cortex's existing `RedirectDomains` model registry (also config-driven). A default for a screen that doesn't exist renders nowhere. From 6456508eb6dbb4096b18909ef189d84e6dd4e1e1 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 23:41:58 -0400 Subject: [PATCH 05/23] 2026-10-29-2038-register-roster-redirect-domains: spec written --- .../meta.yml | 7 +- .../spec.md | 152 ++++++++++++++++++ .../standards.md | 18 +++ 3 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/standards.md diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml index 03973cb..a93e09f 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml @@ -1,5 +1,8 @@ id: 2026-10-29-2038-register-roster-redirect-domains title: 'Register Roster redirect domains' -status: shaping +status: written created: '2026-10-29 20:38' -standards: {} +standards: + refactor-circus/standards: + version: dev-main + reference: a5b675396232 diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md new file mode 100644 index 0000000..e26f8e3 --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md @@ -0,0 +1,152 @@ +# Register Roster redirect domains + +## Goal + +Cortex owns the MCP redirect-domain UI for any owner model, placed on other packages' screens only through editable defaults in `config/cortex.php`. By default these are Roster's organization tab and user aside, which replaces the copy Roster renders today. Cortex also declares every one of its own Atrium screens with the standard slots and tab bar. It stops using Atrium's removed history components, and it suggests Atrium instead of requiring it. + +## Acceptance criteria + +### Redirect domains on other packages' screens + +1. **Config.** `config/cortex.php` gains `atrium.redirect_domains.screens` under the existing `atrium` section, with a banner. It defaults to `['roster.organization' => 'tab', 'roster.user' => 'aside']`. Keys are screen keys; a value is `'tab'` or the name of a slot. Proven by a config test that reads the default. No Cortex PHP code names `roster` or a Roster class: a test greps `src/` for `roster` (case-insensitive) and finds nothing outside comments. +2. **Registration.** While Atrium is installed and `cortex.ui.enabled` is true, Cortex registers, from `boot()`, one entry per config entry: + - for `'tab'`: `Atrium::screens()->tab($target, TabDefinition::make('cortex.mcp')->label(__('cortex::cortex.mcp'))->icon('globe-alt')...)` + - for any other value: `Atrium::screens()->section($target, $slot, SectionDefinition::make('cortex.redirect-domains')->label(__('cortex::cortex.redirect_domains'))...)` + + An empty list registers nothing. A unit-level feature test reads `ScreenExtensions::tabs('roster.organization')` and `sections('roster.user', 'aside')` for the defaults. It also asserts that a custom list (`['acme.account' => 'before']`) registers only that entry, and that `cortex.ui.enabled = false` registers nothing. +3. **Visibility.** The tab and the section are visible (through `authorize()`, never `permission()` or `public()`) only when all of these hold. A feature test covers each case being false on its own, for both the tab and the section: + - `RedirectDomains::enabled()` is true. + - The record is a saved Eloquent model (`$record instanceof Model && $record->exists`). + - Cortex's Atrium plugin is authorized for the request: `PluginRegistry::authorized($request)` has the key `cortex`, so its features and its routes are on. + - The viewer passes `viewAny` on `RedirectDomainModel` with the owner, through Cortex's `ScreenAccess::allowsFor($request->user(), 'viewAny', RedirectDomainModel::class, [$record])`. +4. **Owner.** The owner is the screen's record (the row, inside a row slot). The resolver returns `['domains' => ListRedirectDomainsAction` for that owner, `'ownerType' => $record->getMorphClass()`, `'ownerId' => (string) $record->getKey()]`. The forms post `owner_type` and `owner_id`, and the controller resolves them with the existing `RedirectDomains::owner()`. Proven by the feature tests in criterion 6, which use workbench models with no morph alias (FQCN type) and one with a morph alias. +5. **Rendering.** The tab panel and the section render one view, `cortex::ui.screens.redirect-domains`, built from `x-atrium::*` only. It renders: + - the hint (`cortex::cortex.owned_redirect_domains_hint`) + - an add form when the viewer passes `create` with the owner. It has `data-testid="add-redirect-domain"` and posts to `atrium.cortex.redirect-domains.store` with hidden `owner_type`/`owner_id`. + - a table of the owner's domains (`data-testid="owned-redirect-domains"`), with a remove button (`data-testid="remove-redirect-domain"`) on each row the viewer may `delete` + - `x-atrium::empty-state` when the owner has none + + `StylesTest` covers the new view. +6. **Moved behaviour (ported from Roster's `tests/Cortex/RedirectDomainsTest.php`).** `tests/Feature/Ui/OwnedRedirectDomainsTest.php` runs against the workbench test host (criterion 8) and covers: + - **Organization tab:** `GET` the host `roster.organization` screen with `?tab=cortex.mcp` shows the panel. Posting `domain=claude.ai` with the owner stores `https://claude.ai` for that owner and redirects back to the host page (`->from($hostUrl)`). The domain is then listed, and removing it deletes it. + - **Denied by policy:** with a fixture `RedirectDomainPolicy` that denies `viewAny` for an owner, the tab is absent and `?tab=cortex.mcp` answers 403 (Atrium criterion 7). With one that denies `create`, a POST with that owner answers 403 and stores nothing. + - **Owner-scoped removal:** a `DELETE` naming owner A for a domain of owner B answers 404, and B's domain remains. + - **Validation:** an invalid value redirects back with an error on `domain` and stores nothing. + - **User aside:** the host `roster.user` screen renders the section in `aside` (`data-testid="section-cortex.redirect-domains"`), and add and remove work as above. + - **Read-only:** when `viewAny` passes but `create` and `delete` are denied, the list shows without the add form or remove buttons. + - **Switched off:** with `cortex.redirect_domains.enabled = false`, neither the tab nor the section renders. +7. **Controller changes.** `RedirectDomainUiController::store` and `destroy` accept optional `owner_type` and `owner_id` (validated as the JSON API's `ownerRules()` validates them): + - **With an owner:** `store` authorizes `create` with `[$owner]` and creates for the owner. `destroy` finds the domain with `RedirectDomainModel::query()->ownedBy($owner)->whereKey($domain)->firstOrFail()` and authorizes `delete`. Both redirect to `url()->previous()` when its host is the application's own, or else to `atrium.cortex.redirect-domains.index`. An unknown owner answers 404. + - **Without an owner:** behaviour is unchanged. The existing test `manages domains from the dashboard` passes unmodified. + - **Tests:** a feature test covers the same-host redirect, the foreign-host fallback and the unknown owner. + + No new routes are added. +8. **Test host.** The tests use a workbench test-host screen, not Roster as a dev dependency: + - `Workbench\App\Http\Controllers\TestHostScreenController` serves `GET test-host/{key}/{id?}` with `web` middleware, registered by the test case's `defineRoutes()`. + - Its key is a route parameter, so one controller serves `roster.organization`, `roster.user` and `acme.account`. + - It declares `Screen::standard($key, Screen::DETAIL)->record($model)` with a Gate-based `access()`, resolves it, and renders a workbench view with `x-atrium::screen-tabs`, `screen-tab-panel` and `screen-sections` for each standard slot, laid out per Atrium criterion 15. + - The record is a `Workbench\App\Models\Organization` (workbench migration, loaded from `workbench/database/migrations` by the test case) for `roster.organization`, and the workbench `User` for `roster.user`. + + `composer.json` gains no Roster dependency (asserted by criterion 15's test). + +### Cortex's own screens + +9. **Declared screens.** Every Cortex page with a controller view declares itself with `Screen::standard()` and resolves it after its own authorization. Each has only the synthetic `overview` tab built in: + + | Key | Route (`atrium.cortex.`) | Kind | Record | Subject class for `access()` when the record is null | `row.actions` row model | + |---|---|---|---|---|---| + | `cortex.virtual-agents` | `virtual-agents.index` | list | none | `VirtualAgentModel` | each `VirtualAgentModel` | + | `cortex.virtual-agent-create` | `virtual-agents.create` | detail | none | `VirtualAgentModel` | | + | `cortex.virtual-agent` | `virtual-agents.edit` | detail | the `VirtualAgentModel` | | | + | `cortex.concrete-agents` | `concrete-agents.index` | list | none | `ConcreteAgentOverrideModel` | `ScreenAccess::concreteAgent($name, $override)` | + | `cortex.concrete-agent` | `concrete-agents.show` | detail | `ScreenAccess::concreteAgent($agent, $override)` | | | + | `cortex.run` | `run` and `run.store` (both render the page) | detail | none | none (permission extensions hidden) | | + | `cortex.tools` | `tools.index` | list | none | `ToolDescriptionModel` | `ScreenAccess::toolDescription($name, $descriptions->get($name))` | + | `cortex.tool-description` | `tools.description` | detail | `ScreenAccess::toolDescription($tool, $description)` | | | + | `cortex.servers` | `servers.index` | list | none | `McpInstructionModel` | `ScreenAccess::serverInstruction($name, $instructions->get($name))` | + | `cortex.server-instructions` | `servers.instructions` | detail | `ScreenAccess::serverInstruction($server, $instruction)` | | | + | `cortex.redirect-domains` | `redirect-domains.index` | list | none | `RedirectDomainModel` | each stored row's `RedirectDomainModel` (configured rows get no row slot) | + + A feature test with a dataset over all 11 screens registers a tab and a section in every standard slot (`header.actions`, `before`, `after`, plus `aside` on detail or `row.actions` on list screens, with at least one row present). It asserts each section renders in its slot and not in an undeclared one, and that the tab appears and opens through `?tab=`. +10. **Access closure.** Each screen's `access()` is `fn (string $permission, Request $request, ?Model $record): bool => ScreenAccess::allowsFor($request->user(), $permission, $record ?? $subject)`, with `$subject` from the table. On `cortex.run`, a null record denies. Tests: + - a `permission('view')` section on `cortex.virtual-agent` shows when the fixture policy allows and hides when it denies + - a `permission('viewAny')` section on `cortex.virtual-agents` follows the class check + - a `permission()` section on `cortex.run` never shows +11. **Layout.** Per Atrium criterion 15, an open registered tab's panel replaces the page content, and only `header.actions` stays. `header.actions` sections render inside `x-atrium::page-header`'s actions, after the page's own actions. `before` and `after` render around the content. `aside` renders in a right-hand column only when it has visible sections. `row.actions` renders inside each row's last cell, after its own controls. With nothing registered, the markup is unchanged: every existing feature test passes without modification, except those listed in criterion 13. + +### History removal and Atrium as a suggestion + +12. **No history in Cortex's UI.** The `` calls in `ui/virtual-agents/index`, `ui/virtual-agents/form` and `ui/partials/override` are removed, and `CortexPlugin::navigation()` no longer calls `historyNavItem()`. Screens declare no audit subject (Keen attaches History by wildcard). The Keystone JSON route `GET cortex/history` and the history MCP tool are unaffected (`tests/Feature/HistoryTest.php` passes unchanged). A test asserts that the plugin's navigation has no item whose route is `atrium.history.show`. A grep of `resources`, `src`, `README.md`, `CLAUDE.md`, `docs/agent/standards` and `resources/boost` for `audit-trail` and `historyNavItem` finds nothing. +13. **Forced test changes.** Existing tests may change only where this spec's decisions force it, and the PR lists each by file and test name. The expected set is: + - `tests/Feature/Ui/AuditTrailTest.php`: deleted (the component is gone from Atrium). + - `tests/Feature/HistoryNavigationTest.php`, `links its own audit log from its sidebar group`: replaced by criterion 12's assertion. + - `tests/Pest.php` and `tests/TestCase.php`: gain `ResetsScreenExtensions` and the test-host routes and migrations. +14. **Composer.** `refactor-circus/atrium` moves from `require` to `require-dev` (the suite needs it), and it is added to `suggest` with a description. Keystone stays the only suite package in `require`. A test reads `composer.json` and asserts: + - `require` has no `refactor-circus/*` key other than `refactor-circus/keystone` + - `suggest` has `refactor-circus/atrium` + - `require-dev` has `refactor-circus/atrium` +15. **Arch test.** `tests/ArchTest.php` gains `arch('only the Atrium layer uses Atrium')->expect('RefactorCircus\Cortex')->not->toUse('RefactorCircus\Atrium')->ignoring('RefactorCircus\Cortex\Atrium')`, and it passes. Registration lives in `RefactorCircus\Cortex\Atrium\ScreenRegistrations` (below). `CortexServiceProvider` reaches it only behind the same string `class_exists('RefactorCircus\Atrium\Atrium')` and `cortex.ui.enabled` guard that `registerAtriumPlugin()` uses. A test asserts `composer.json` lists no `refactor-circus/roster`. +16. **No-Atrium proof.** A `WithoutAtrium` suite proves Cortex boots and serves its HTTP API and MCP without Atrium: + - **Files:** `phpunit.without-atrium.xml`, bootstrap `tests/WithoutAtrium/bootstrap.php`, tests in `tests/WithoutAtrium`, excluded from the default `phpunit.xml.dist` suite. The bootstrap loads Composer's autoloader and removes the `RefactorCircus\Atrium\` PSR-4 prefix, so no Atrium class can load. Its `WithoutAtriumTestCase` registers no Atrium provider. + - **Assertions:** + - `class_exists('RefactorCircus\Atrium\Atrium')` is false + - the app boots with `CortexServiceProvider` + - no route name starts with `atrium.` + - `cortex.redirect-domains.index` (JSON) answers 200 and `store` creates a domain + - `mcpTool(ListRedirectDomainsTool::class)` answers + - a virtual agent can be created over the JSON API + - **Gate:** a composer script `test:without-atrium` runs it, and `composer test` calls it after `@test:unit`. + - **CI:** `.github/workflows/tests.yml` gains a `without-atrium` job that runs `composer remove --dev refactor-circus/atrium --no-update`, installs, and runs `composer test:without-atrium`. + +### Documentation + +17. **Docs.** Three places change: + - **README:** a "Redirect domains on other screens" section documents `cortex.atrium.redirect_domains.screens`, the `cortex.mcp` tab key, the `cortex.redirect-domains` section key, the visibility rules from criterion 3, and that the owner's `RedirectDomainPolicy` decides who manages the domains. It also notes that Atrium is suggested, not required. + - **Local standard:** `docs/agent/standards/cortex/atrium-screens.md` replaces its "History" section with the screen-declaration rule: keys, standard slots, the access closure, and no audit components. + - **Other docs and changelog:** `CLAUDE.md` and the Boost skill drop their audit-trail and history-nav text. `CHANGELOG.md` has an upgrade note covering: + - Atrium moved to `suggest` (apps using the dashboard require it themselves) + - the new config key + - the `owner_type`/`owner_id` fields on the UI store and destroy routes + - removed history UI (Keen provides it) + - grouped merge with Atrium, Keen and Roster + + A docs test asserts the README section exists and contains `redirect_domains.screens`, `cortex.mcp` and `suggest`. +18. Done means `composer test` passes, including `test:without-atrium`. Cortex has no browser suite, so there is no `test:browser` step. + +## Design + +**Placement.** `RefactorCircus\Cortex\Atrium\ScreenRegistrations` (final, static `register(): void`) reads `cortex.atrium.redirect_domains.screens` and calls `Atrium::screens()->tab()` or `section()` per entry. Bad entries are not checked again: Atrium's own validation throws `InvalidArgumentException` at boot for a malformed target or slot. `CortexServiceProvider::boot()` calls it from a private `registerAtriumScreens()`, right after `registerAtriumPlugin()` and with the same guard. A target screen that nobody declares never renders (Atrium criterion 1). + +**Definitions.** Tab `cortex.mcp` has the label `cortex::cortex.mcp` ("MCP") and icon `globe-alt`. Section `cortex.redirect-domains` has the label `cortex::cortex.redirect_domains`. Both use `view('cortex::ui.screens.redirect-domains')`, and they share one `authorize` closure (criterion 3) and one resolver (criterion 4). These closures run on every target screen's render, so they return early: they check `enabled()` and `$record?->exists` first and query nothing. + +**Owner.** The screen's record is the owner. Its type in the form is `getMorphClass()`, so the morph map, already the registry `RedirectDomains::owner()` reads, decides the type string. Cortex never inspects which package the model belongs to (D-001, D-002 settled by the addendum). + +**Authorization.** All of it is Cortex's own: `RedirectDomainPolicy` `viewAny`/`create` with the owner, and `delete` on the domain, through `cortex.policies`. These are the same checks the JSON API and MCP tools make for owned domains. The host's own authorization has already run before `resolve()` (Atrium criterion 9). + +**Screen helper.** `RefactorCircus\Cortex\Atrium\Screens::declare(string $key, string $kind, ?Model $record, ?string $subject): Screen` (final, static) builds `Screen::standard()`, sets the record, and adds the access closure from criterion 10, so the 11 controllers share one definition. Controllers inject `ScreenExtensions` (Atrium's) and pass `resolved` to their views. The redirect-domains screen also keeps its `rows`. + +**Lang.** `lang/en/cortex.php` gains `mcp` ("MCP") and `owned_redirect_domains_hint`, and reuses `domain`, `domain_hint`, `created`, `actions`, `remove_domain` and `no_redirect_domains`. + +**Arch.** No new models, Data or Actions. The new classes live under `src/Atrium` (not `Domains/*/Models` or `Data`), so the model and Data arch rules don't apply. The workbench `Organization` model and its migration sit under `workbench/`, which the table-literal arch rule does not scan. + +## Out of scope + +- Roster's own changes: deleting its copy, its `?tab=mcp` fallback and declaring `roster.organization` and `roster.user` belong to Roster's `adopt-atrium-screen-registry` spec. +- History, activity and audit UI (Keen's spec). +- Any host-permission check from the target package, such as Roster's `roster.organizations.update` (see Q-1). +- New JSON or MCP surfaces. The owner forms reuse the existing UI routes. + +## Risks and open questions + +- **Q-1. Who may manage an owner's domains on a host screen?** Roster required `roster.organizations.update` (organization tab) or `roster.users.update` (user add/remove). Cortex can't name those permissions in code. + - **(a)** Cortex's `RedirectDomainPolicy` only, with the owner. The bundled policy allows everyone, as the JSON API and MCP already do for owned domains. Apps restrict it with their own policy class. This loosens the UI compared with Roster's defaults. + - **(b)** A per-entry config permission, e.g. `'roster.organization' => ['slot' => 'tab', 'permission' => 'roster.organizations.update']`, applied through `permission()` and the host's `access()`. This hides the UI, but Cortex's POST routes can't ask the host's access closure, so the routes stay at (a)'s level. + - **(c)** (a), and also ship the bundled policy's `create`/`delete` for a non-null owner as `$user->can('update', $owner)`, so the owner's own policy decides. + + Recommendation: (c), because it keeps the old protection where hosts register Gate policies, names no package, and applies to the API too. It is a behaviour change for API callers, so the user should confirm it. The spec is written against (a); choosing (c) adds one criterion. +- **Q-2. Running without Atrium.** This spec runs it in process (the PSR-4 prefix removed, inside `composer test`) and also in a CI lane with Atrium uninstalled. Options: in-process only, CI only, or both. Recommendation: both, because the in-process run keeps "done" local and the CI lane catches classmap or autoload-file leaks. +- **Q-3. Removing redirect target.** `url()->previous()` limited to the same host is used instead of naming the host's route. If the referrer is missing, the user lands on Cortex's redirect-domains index, which is acceptable. +- **Risks:** + - Grouped merge: Atrium PR #16 removes the components, and Roster deletes its copy. Merge Atrium, Keen, Roster and Cortex together, or Roster's MCP tab disappears in between. + - The owner's morph class appears in a hidden field. It is no secret, and `RedirectDomains::owner()` rejects non-models. + - Moving Atrium to `require-dev` breaks apps that relied on Cortex pulling it in. The CHANGELOG says so. diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/standards.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/standards.md new file mode 100644 index 0000000..03e6d0e --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/standards.md @@ -0,0 +1,18 @@ +# Standards for Register Roster redirect domains + +| Standard | File | Source | Why it applies | +| --- | --- | --- | --- | +| architecture/dependencies | vendor/refactor-circus/standards/standards/architecture/dependencies.md | refactor-circus/standards@dev-main | Atrium moves to suggest; the integration is config-only and guarded by class_exists() | +| architecture/configuration | vendor/refactor-circus/standards/standards/architecture/configuration.md | refactor-circus/standards@dev-main | New `cortex.atrium.redirect_domains.screens` key with a banner and safe defaults | +| architecture/public-api | vendor/refactor-circus/standards/standards/architecture/public-api.md | refactor-circus/standards@dev-main | New tab and section keys, screen keys and owner fields on the UI routes | +| architecture/service-providers | vendor/refactor-circus/standards/standards/architecture/service-providers.md | refactor-circus/standards@dev-main | Screen registration from boot(), behind the Atrium guard | +| architecture/naming | vendor/refactor-circus/standards/standards/architecture/naming.md | refactor-circus/standards@dev-main | New `Atrium\ScreenRegistrations` and `Atrium\Screens` classes and screen keys | +| http/authorization | vendor/refactor-circus/standards/standards/http/authorization.md | refactor-circus/standards@dev-main | Visibility and writes go through RedirectDomainPolicy with the owner; the screens' access() closures use the Gate | +| http/routes | vendor/refactor-circus/standards/standards/http/routes.md | refactor-circus/standards@dev-main | The existing UI store and destroy routes take optional owner fields; no new routes | +| models/stored-identifiers | vendor/refactor-circus/standards/standards/models/stored-identifiers.md | refactor-circus/standards@dev-main | Owners are named by morph type and key, resolved by RedirectDomains::owner() | +| testing/arch-tests | vendor/refactor-circus/standards/standards/testing/arch-tests.md | refactor-circus/standards@dev-main | New arch rule: only src/Atrium uses Atrium | +| testing/test-layers | docs/agent/standards/testing/test-layers.md | local (overrides refactor-circus/standards@dev-main) | Owned-domain behaviour stays tested at the actions; the UI tests cover wiring through a workbench test host | +| cortex/atrium-screens | docs/agent/standards/cortex/atrium-screens.md | local | x-atrium components only; its History section is replaced by screen declaration | +| cortex/optional-surfaces | docs/agent/standards/cortex/optional-surfaces.md | local | Registration follows `cortex.ui.enabled` | +| cortex/testbench-environment | docs/agent/standards/cortex/testbench-environment.md | local | The test case adds the test-host routes and workbench migrations, plus a WithoutAtrium suite | +| cortex/domains | docs/agent/standards/cortex/domains.md | local | RedirectDomain domain actions and service are reused unchanged | From 87593f4ae581fea2f672d477ce58e9f8f2b0d301 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 23:56:42 -0400 Subject: [PATCH 06/23] 2026-10-29-2038-register-roster-redirect-domains: approved: decisions folded, tasks --- .../decisions.md | 69 +++++++ .../meta.yml | 3 +- .../questions.yml | 1 + .../spec-review.md | 17 ++ .../spec.md | 172 +++++++++++------- .../tasks.md | 62 +++++++ 6 files changed, 261 insertions(+), 63 deletions(-) create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/decisions.md create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/questions.yml create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec-review.md create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/decisions.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/decisions.md new file mode 100644 index 0000000..45a4b74 --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/decisions.md @@ -0,0 +1,69 @@ +# Decisions + +Earlier D-ids are recorded in shape.md. + +## D-020: Suite: proving the package runs without Atrium, and refusing an Atrium too old for the screen registry +- Choice: Prove it both ways: a WithoutAtrium suite inside `composer test`, and a CI lane with Atrium uninstalled. Every package that renders Atrium screens adds a composer `conflict` on refactor-circus/atrium versions older than the screen-extensions registry (Atrium PR #16). +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: user, cross-spec decision (2026-10-29) + +## D-021: Suite: malformed integration config entries (screen maps, slots) at boot +- Choice: Throw InvalidArgumentException in local and testing. In production, report once, skip the entry and keep booting (same rule as Atrium D-022). +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: user, cross-spec decision (2026-10-29) + +## D-022: Who may manage an owner's redirect domains (UI, API, MCP)? +- Choice: For a domain with an owner, the bundled policy's create/delete become `$user->can('update', $owner)`, so the owner's own policy decides. Domains without an owner are unchanged. This adds a criterion, tests (a guest, a user without update on the owner, the null-owner path unchanged) and a CHANGELOG line. +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: user (2026-10-29) + +## D-023: Q-1: Who may manage an owner's domains on a host screen? Cortex cannot name the host's permissions, such as Roster's `roster.organizations.update`. +- Choice: (c) (a), and the bundled policy's `create`/`delete` for a non-null owner become `$user->can('update', $owner)`, so the owner's own policy decides. +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-024: Should this spec stay one deliverable, or split into redirect-domain registration, declaration of Cortex's own screens, and the Atrium-suggest and history-removal work? +- Choice: Keep one spec (grouped merge with Atrium, Keen and Roster) +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-025: Q-2: How should the no-Atrium proof run: in process only, in a CI lane only, or both? +- Choice: Both +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-026: Q-3: After UI store or destroy with an owner, where should the redirect go? +- Choice: `url()->previous()` when its host is the application's own, else Cortex's redirect-domains index +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-027: Q-1. Who may manage an owner's domains on a host screen, and through the POST routes? The bundled policy allows everyone (guests too, per Cortex's convention). Redirect domains are an OAuth redirect allow-list, and the hidden owner_type/owner_id fields are not tied to the host screen's authorization, so any user who reaches Cortex's routes could add a redirect domain for any owner. +- Choice: (c) (a), plus the bundled policy's create/delete for a non-null owner become $user->can('update', $owner), so the owner's own policy decides (also applies to the API and MCP) +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-028: Should the owner types accepted by the UI routes be limited to an explicit allow-list in config, or to whatever RedirectDomains::owner() already resolves (any morph-map alias or FQCN of an Eloquent model)? +- Choice: Keep RedirectDomains::owner()'s current resolution and add tests that unsupported types are refused +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-029: Q-2. Run the no-Atrium proof in process only, in a CI lane only, or both? +- Choice: In-process suite and CI lane (as written) +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) + +## D-030: Q-2. How is 'runs without Atrium' proven? The spec does both, so the choice is settled only if confirmed. +- Choice: Both +- Rationale: The user accepted the recommendation. +- Date: 2026-10-29 +- Raised by: spec review; the user accepted all recommendations (2026-10-29) diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml index a93e09f..6244f4a 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml @@ -1,8 +1,9 @@ id: 2026-10-29-2038-register-roster-redirect-domains title: 'Register Roster redirect domains' -status: written +status: approved created: '2026-10-29 20:38' standards: refactor-circus/standards: version: dev-main reference: a5b675396232 +review_passes: 1 diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/questions.yml b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/questions.yml new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/questions.yml @@ -0,0 +1 @@ +[] diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec-review.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec-review.md new file mode 100644 index 0000000..670edde --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec-review.md @@ -0,0 +1,17 @@ + +## Round 1 + +Revised `spec.md`. The open questions (Q-1 host authorization, scope split, Q-2 no-Atrium proof, Q-3 redirect target, owner-type allow-list) were left as written; every change below holds under any answer. + +- **Goal / Depends on:** states the three deliverables and adds a Depends-on list (Atrium screen-extensions-registry, PR #16), restating the Atrium behaviours relied on (unauthorized `?tab=` is 403, authorization order, slot layout, `InvalidArgumentException`) so the criteria stand alone. +- **Criterion 1:** `ScreenRegistrations` falls back to the default map when the key is absent (shallow config merge risk), not when empty; test with a published-style config. The `roster` grep now bans the string everywhere in `src/`, comments included (no comment-stripping needed). +- **Criterion 2 and Design:** non-string and empty entries and bad slots throw `InvalidArgumentException` from `boot()`, as a deliberate, documented, tested fail-fast. +- **Criterion 3:** closure runs no query when disabled or for a non-model; policy exceptions hide the section; query-count and throwing-policy tests added. +- **Criterion 6:** added morph-alias and unregistered-type cases, and a visibility-negatives dataset with named fixtures. +- **Criterion 7:** redirect target accepted only on exact scheme, host and port match, path and query only; owner types limited to what `RedirectDomains::owner()` already resolves (no new allow-list, so that open question stays open); partial owner is 422; tests for lookalike host, userinfo and scheme mismatch. +- **Criterion 9:** per-kind leakage columns (row.actions on detail, aside on list), no history slot, and an explicit no-row-slot check for configured rows. +- **Criterion 11:** layout claims tied to rendered-HTML assertions (aside landmark, `assertSeeInOrder`, last `td`, `assertDontSee` with an open tab). +- **Criterion 16:** bootstrap asserts the PSR-4 removal and throws if `findFile` still resolves Atrium; the CI lane is stated as the authoritative proof. +- **Criterion 17:** README states "Atrium is suggested" and the dashboard being absent without Atrium; CHANGELOG adds the `?tab=mcp` to `cortex.mcp` and route-name change; docs tests use specific phrases and per-topic keywords. +- **Out of scope:** adds the `history` slot and audit subject, old `?tab=mcp` links, row slots for configured rows, and unchanged ownerless dashboard behaviour. +- **Not changed:** `shape.md` (stale Scope, Standards and D-002) was outside this revision step and still needs updating to match the spec. The spec title is kept; the Goal now says the Roster domains are one of three parts. diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md index e26f8e3..78f47a2 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/spec.md @@ -2,23 +2,35 @@ ## Goal -Cortex owns the MCP redirect-domain UI for any owner model, placed on other packages' screens only through editable defaults in `config/cortex.php`. By default these are Roster's organization tab and user aside, which replaces the copy Roster renders today. Cortex also declares every one of its own Atrium screens with the standard slots and tab bar. It stops using Atrium's removed history components, and it suggests Atrium instead of requiring it. +Cortex owns the MCP redirect-domain UI for any owner model, placed on other packages' screens only through editable defaults in `config/cortex.php`. By default these are Roster's organization tab and user aside, which replaces the copy Roster renders today. Who may add or remove an owner's domains is decided by the owner's own policy: the bundled `RedirectDomainPolicy` asks `$user->can('update', $owner)` for owned domains, on the UI, the JSON API and MCP alike (D-022, D-023, D-027). Cortex also declares every one of its own Atrium screens with the standard slots and tab bar. It stops using Atrium's removed history components, suggests Atrium instead of requiring it, refuses an Atrium too old for the screen registry, and proves it runs without Atrium both in process and in CI (D-020, D-025). The work stays one spec, merged together with Atrium, Keen and Roster (D-024). Its four deliverables: (1) redirect domains on other packages' screens, (2) owner-decided authorization for owned domains, (3) Cortex's own 11 declared screens, (4) history removal and Atrium as a suggestion. + +**Depends on.** The Atrium `screen-extensions-registry` spec, on the Atrium branch or release that contains it (Atrium PR #16, which also removes the audit-trail components). The suite runs against that Atrium version as a `require-dev` dependency. Atrium behaviour this spec relies on, restated so the criteria stand alone: +- A registered tab or section renders only on a screen that is declared with that key and resolved (Atrium criterion 1). +- `?tab=` for a tab that is not visible to the viewer answers 403 (Atrium criterion 7). +- The host's own `access()` runs before extension `authorize()` closures; `resolve()` runs after the host authorized the request (Atrium criterion 9). +- Slot layout: an open tab's panel replaces the page content while `header.actions` stays; `aside` renders in a right-hand column only when it has visible sections; `row.actions` renders in each row's last cell (Atrium criterion 15). +- Atrium throws `InvalidArgumentException` for a malformed target or slot. ## Acceptance criteria ### Redirect domains on other packages' screens -1. **Config.** `config/cortex.php` gains `atrium.redirect_domains.screens` under the existing `atrium` section, with a banner. It defaults to `['roster.organization' => 'tab', 'roster.user' => 'aside']`. Keys are screen keys; a value is `'tab'` or the name of a slot. Proven by a config test that reads the default. No Cortex PHP code names `roster` or a Roster class: a test greps `src/` for `roster` (case-insensitive) and finds nothing outside comments. +1. **Config.** `config/cortex.php` gains `atrium.redirect_domains.screens` under the existing `atrium` section, with a banner. It defaults to `['roster.organization' => 'tab', 'roster.user' => 'aside']`. Keys are screen keys; a value is `'tab'` or the name of a slot. Proven by a config test that reads the default. An app that published `config/cortex.php` before this change has an `atrium` array without `redirect_domains`; `ScreenRegistrations` then uses the default map (when the key is absent, not when it is an empty array, which registers nothing). A test with a published-style config lacking the key asserts the defaults still register. No Cortex PHP code names `roster` or a Roster class: a test greps every file under `src/` for `roster` (case-insensitive) and finds nothing at all, comments included. 2. **Registration.** While Atrium is installed and `cortex.ui.enabled` is true, Cortex registers, from `boot()`, one entry per config entry: - for `'tab'`: `Atrium::screens()->tab($target, TabDefinition::make('cortex.mcp')->label(__('cortex::cortex.mcp'))->icon('globe-alt')...)` - for any other value: `Atrium::screens()->section($target, $slot, SectionDefinition::make('cortex.redirect-domains')->label(__('cortex::cortex.redirect_domains'))...)` - An empty list registers nothing. A unit-level feature test reads `ScreenExtensions::tabs('roster.organization')` and `sections('roster.user', 'aside')` for the defaults. It also asserts that a custom list (`['acme.account' => 'before']`) registers only that entry, and that `cortex.ui.enabled = false` registers nothing. + An empty list registers nothing. A malformed entry is a value that is not a string, an empty string, or a target or slot name Atrium rejects. Per the suite rule (D-021, same as Atrium D-022): in the `local` and `testing` environments a malformed entry throws `InvalidArgumentException` from `boot()`; in any other environment (production) it is reported once with `report()`, skipped, and the remaining entries still register, so the app keeps booting. The README says so. Tests: + - in `testing`, `['roster.organization' => null]`, `['roster.organization' => '']` and `['roster.organization' => 'bogus slot']` each throw `InvalidArgumentException` + - with the environment set to `production` and `Exceptions::fake()`, a map holding one malformed and one valid entry boots without throwing, reports exactly one `InvalidArgumentException`, and registers the valid entry + - a unit-level feature test reads `ScreenExtensions::tabs('roster.organization')` and `sections('roster.user', 'aside')` for the defaults; a custom list (`['acme.account' => 'before']`) registers only that entry; `cortex.ui.enabled = false` registers nothing 3. **Visibility.** The tab and the section are visible (through `authorize()`, never `permission()` or `public()`) only when all of these hold. A feature test covers each case being false on its own, for both the tab and the section: - `RedirectDomains::enabled()` is true. - The record is a saved Eloquent model (`$record instanceof Model && $record->exists`). - Cortex's Atrium plugin is authorized for the request: `PluginRegistry::authorized($request)` has the key `cortex`, so its features and its routes are on. - The viewer passes `viewAny` on `RedirectDomainModel` with the owner, through Cortex's `ScreenAccess::allowsFor($request->user(), 'viewAny', RedirectDomainModel::class, [$record])`. + + The closure is cheap and safe: it runs no query when `enabled()` is false or the record is not a saved model, and an exception thrown by a policy is caught and treated as hidden, so a failing policy never breaks the host page. Tests: a query-count assertion (`DB::getQueryLog()`) shows no query for a non-model record and none when `enabled()` is false; the aside section on a host page showing several records adds no more than one policy query per record; a policy that throws leaves the host page answering 200 without the section. 4. **Owner.** The owner is the screen's record (the row, inside a row slot). The resolver returns `['domains' => ListRedirectDomainsAction` for that owner, `'ownerType' => $record->getMorphClass()`, `'ownerId' => (string) $record->getKey()]`. The forms post `owner_type` and `owner_id`, and the controller resolves them with the existing `RedirectDomains::owner()`. Proven by the feature tests in criterion 6, which use workbench models with no morph alias (FQCN type) and one with a morph alias. 5. **Rendering.** The tab panel and the section render one view, `cortex::ui.screens.redirect-domains`, built from `x-atrium::*` only. It renders: - the hint (`cortex::cortex.owned_redirect_domains_hint`) @@ -27,70 +39,97 @@ Cortex owns the MCP redirect-domain UI for any owner model, placed on other pack - `x-atrium::empty-state` when the owner has none `StylesTest` covers the new view. -6. **Moved behaviour (ported from Roster's `tests/Cortex/RedirectDomainsTest.php`).** `tests/Feature/Ui/OwnedRedirectDomainsTest.php` runs against the workbench test host (criterion 8) and covers: +6. **Moved behaviour (ported from Roster's `tests/Cortex/RedirectDomainsTest.php`).** `tests/Feature/Ui/OwnedRedirectDomainsTest.php` runs against the workbench test host (criterion 9), signed in as a workbench `User` whom the workbench owner policies (criterion 9) allow to `update` the owner, unless a case says otherwise. It covers: - **Organization tab:** `GET` the host `roster.organization` screen with `?tab=cortex.mcp` shows the panel. Posting `domain=claude.ai` with the owner stores `https://claude.ai` for that owner and redirects back to the host page (`->from($hostUrl)`). The domain is then listed, and removing it deletes it. - **Denied by policy:** with a fixture `RedirectDomainPolicy` that denies `viewAny` for an owner, the tab is absent and `?tab=cortex.mcp` answers 403 (Atrium criterion 7). With one that denies `create`, a POST with that owner answers 403 and stores nothing. + - **Denied by the owner's policy (bundled policy, criterion 8):** with the workbench owner policy denying `update`, the panel lists the domains without the add form or remove buttons, a POST with that owner answers 403 and stores nothing, and a DELETE answers 403 and keeps the domain. - **Owner-scoped removal:** a `DELETE` naming owner A for a domain of owner B answers 404, and B's domain remains. - **Validation:** an invalid value redirects back with an error on `domain` and stores nothing. - **User aside:** the host `roster.user` screen renders the section in `aside` (`data-testid="section-cortex.redirect-domains"`), and add and remove work as above. - **Read-only:** when `viewAny` passes but `create` and `delete` are denied, the list shows without the add form or remove buttons. - **Switched off:** with `cortex.redirect_domains.enabled = false`, neither the tab nor the section renders. -7. **Controller changes.** `RedirectDomainUiController::store` and `destroy` accept optional `owner_type` and `owner_id` (validated as the JSON API's `ownerRules()` validates them): - - **With an owner:** `store` authorizes `create` with `[$owner]` and creates for the owner. `destroy` finds the domain with `RedirectDomainModel::query()->ownedBy($owner)->whereKey($domain)->firstOrFail()` and authorizes `delete`. Both redirect to `url()->previous()` when its host is the application's own, or else to `atrium.cortex.redirect-domains.index`. An unknown owner answers 404. + - **Morph alias:** register a morph alias for a workbench model. `GET` the tab and assert the hidden `owner_type` equals the alias. `POST` and `DELETE` through it, and assert the domain is stored against that owner. An unregistered type answers 404. + - **Visibility negatives (criterion 3):** a `VisibilityTest` dataset, one case per condition false on its own, for the tab and the section: `cortex.redirect_domains.enabled = false`; Cortex's plugin not authorized (`cortex.features` or `cortex.routes.enabled` off, so `PluginRegistry::authorized()` lacks `cortex`); an unsaved record (`new Organization`) and a non-Model record; a fixture policy denying `viewAny`. +7. **Controller changes.** `RefactorCircus\Cortex\Atrium\Http\Controllers\RedirectDomainUiController::store` and `destroy` accept optional `owner_type` and `owner_id` (validated as the JSON API's `ownerRules()` validates them): + - **Owner types (D-028):** `owner_type` must be a morph-map alias or an FQCN that `RedirectDomains::owner()` already resolves; there is no new config allow-list and nothing wider is accepted. A non-model class, an Eloquent model it does not allow, or a malformed `owner_id` answers 404 or 422 and writes nothing, on both `store` and `destroy`. + - **Partial owner:** `owner_type` without `owner_id`, or the reverse, or either as an empty string, answers 422 with an error on the missing field and stores nothing (it is not the legacy no-owner path). Only both absent takes the no-owner path. + - **With an owner:** `store` authorizes `create` with `[$owner]` and creates for the owner. `destroy` finds the domain with `RedirectDomainModel::query()->ownedBy($owner)->whereKey($domain)->firstOrFail()` and authorizes `delete`. An unknown owner answers 404. + - **Redirect target (D-026):** after an owned `store` or `destroy`, the controller redirects to the path and query of `url()->previous()` only when its scheme, host and port equal `$request->getSchemeAndHttpHost()` (parsed with `parse_url`, compared exactly, no prefix match), or else to `atrium.cortex.redirect-domains.index`. A missing referrer also falls back to the index. - **Without an owner:** behaviour is unchanged. The existing test `manages domains from the dashboard` passes unmodified. - - **Tests:** a feature test covers the same-host redirect, the foreign-host fallback and the unknown owner. + - **Tests:** a feature test covers the same-host redirect (fixture: the request's own host, `http://localhost` in the test case), the foreign-host fallback, the unknown owner, the partial-owner cases, the owner-type rejections above (a non-model class, a non-Eloquent class, an unknown alias), and three fallbacks to the index route: a lookalike host (`http://localhost.evil.test`), a userinfo form (`http://localhost@evil.test`) and a scheme mismatch (`https://localhost` against an `http` request). No new routes are added. -8. **Test host.** The tests use a workbench test-host screen, not Roster as a dev dependency: + +### Owner-decided authorization for owned domains + +8. **Bundled policy asks the owner (D-022, D-023, D-027).** `RefactorCircus\Cortex\Domains\RedirectDomain\Policies\RedirectDomainPolicy` changes for owned domains only: + - `create(?Authenticatable $user, ?Model $owner = null)`: `true` when `$owner` is null (unchanged); otherwise `$user !== null && $user->can('update', $owner)`. + - `delete(?Authenticatable $user, RedirectDomainModel $domain)`: `true` when `$domain->owner_type` is null (unchanged); otherwise the owner is loaded through the existing `owner` relation and the answer is `$user !== null && $owner !== null && $user->can('update', $owner)`. A domain whose owner row no longer exists is denied (fails closed). + - `viewAny` is unchanged (allows everyone, guests included). + + Because the UI controller, the JSON API and the MCP tools all authorize through this policy, the change applies to all three. An app that sets its own class in `cortex.policies` is unaffected. The class docblock is updated to say so. Tests in `tests/Feature/OwnedRedirectDomainPolicyTest.php`, each over the JSON API, MCP and the Gate directly: + - a guest is denied `create` and `delete` for an owned domain (JSON `POST`/`DELETE` answer 403, MCP create and delete fail, nothing is written or removed) + - a signed-in user without `update` on the owner (workbench owner policy denies) is denied the same way + - a signed-in user with `update` on the owner is allowed + - the null-owner path is unchanged: a guest and a signed-in user may still `create` and `delete` a domain without an owner + - a domain whose owner row was deleted cannot be deleted through the policy + + `CHANGELOG.md` gains a line for this behaviour change (criterion 18). + +9. **Test host.** The tests use a workbench test-host screen, not Roster as a dev dependency: - `Workbench\App\Http\Controllers\TestHostScreenController` serves `GET test-host/{key}/{id?}` with `web` middleware, registered by the test case's `defineRoutes()`. - Its key is a route parameter, so one controller serves `roster.organization`, `roster.user` and `acme.account`. - It declares `Screen::standard($key, Screen::DETAIL)->record($model)` with a Gate-based `access()`, resolves it, and renders a workbench view with `x-atrium::screen-tabs`, `screen-tab-panel` and `screen-sections` for each standard slot, laid out per Atrium criterion 15. - The record is a `Workbench\App\Models\Organization` (workbench migration, loaded from `workbench/database/migrations` by the test case) for `roster.organization`, and the workbench `User` for `roster.user`. + - Owner policies for criterion 8: `Workbench\App\Policies\OrganizationPolicy` and `Workbench\App\Policies\UserPolicy`, registered with `Gate::policy()` in the test case, allow `update` to any signed-in user by default. A test toggles them to deny with a static flag reset in `tearDown`. - `composer.json` gains no Roster dependency (asserted by criterion 15's test). + `composer.json` gains no Roster dependency (asserted by criterion 16's test). ### Cortex's own screens -9. **Declared screens.** Every Cortex page with a controller view declares itself with `Screen::standard()` and resolves it after its own authorization. Each has only the synthetic `overview` tab built in: - - | Key | Route (`atrium.cortex.`) | Kind | Record | Subject class for `access()` when the record is null | `row.actions` row model | - |---|---|---|---|---|---| - | `cortex.virtual-agents` | `virtual-agents.index` | list | none | `VirtualAgentModel` | each `VirtualAgentModel` | - | `cortex.virtual-agent-create` | `virtual-agents.create` | detail | none | `VirtualAgentModel` | | - | `cortex.virtual-agent` | `virtual-agents.edit` | detail | the `VirtualAgentModel` | | | - | `cortex.concrete-agents` | `concrete-agents.index` | list | none | `ConcreteAgentOverrideModel` | `ScreenAccess::concreteAgent($name, $override)` | - | `cortex.concrete-agent` | `concrete-agents.show` | detail | `ScreenAccess::concreteAgent($agent, $override)` | | | - | `cortex.run` | `run` and `run.store` (both render the page) | detail | none | none (permission extensions hidden) | | - | `cortex.tools` | `tools.index` | list | none | `ToolDescriptionModel` | `ScreenAccess::toolDescription($name, $descriptions->get($name))` | - | `cortex.tool-description` | `tools.description` | detail | `ScreenAccess::toolDescription($tool, $description)` | | | - | `cortex.servers` | `servers.index` | list | none | `McpInstructionModel` | `ScreenAccess::serverInstruction($name, $instructions->get($name))` | - | `cortex.server-instructions` | `servers.instructions` | detail | `ScreenAccess::serverInstruction($server, $instruction)` | | | - | `cortex.redirect-domains` | `redirect-domains.index` | list | none | `RedirectDomainModel` | each stored row's `RedirectDomainModel` (configured rows get no row slot) | - - A feature test with a dataset over all 11 screens registers a tab and a section in every standard slot (`header.actions`, `before`, `after`, plus `aside` on detail or `row.actions` on list screens, with at least one row present). It asserts each section renders in its slot and not in an undeclared one, and that the tab appears and opens through `?tab=`. -10. **Access closure.** Each screen's `access()` is `fn (string $permission, Request $request, ?Model $record): bool => ScreenAccess::allowsFor($request->user(), $permission, $record ?? $subject)`, with `$subject` from the table. On `cortex.run`, a null record denies. Tests: +10. **Declared screens.** Every Cortex page with a controller view declares itself with `Screen::standard()` and resolves it after its own authorization. Each has only the synthetic `overview` tab built in, which is the default tab: + + | Key | Route (`atrium.cortex.`) | Kind | Record | Subject class for `access()` when the record is null | `row.actions` row model | + |---|---|---|---|---|---| + | `cortex.virtual-agents` | `virtual-agents.index` | list | none | `VirtualAgentModel` | each `VirtualAgentModel` | + | `cortex.virtual-agent-create` | `virtual-agents.create` | detail | none | `VirtualAgentModel` | | + | `cortex.virtual-agent` | `virtual-agents.edit` | detail | the `VirtualAgentModel` | | | + | `cortex.concrete-agents` | `concrete-agents.index` | list | none | `ConcreteAgentOverrideModel` | `ScreenAccess::concreteAgent($name, $override)` | + | `cortex.concrete-agent` | `concrete-agents.show` | detail | `ScreenAccess::concreteAgent($agent, $override)` | | | + | `cortex.run` | `run` and `run.store` (both render the page) | detail | none | none (permission extensions hidden) | | + | `cortex.tools` | `tools.index` | list | none | `ToolDescriptionModel` | `ScreenAccess::toolDescription($name, $descriptions->get($name))` | + | `cortex.tool-description` | `tools.description` | detail | `ScreenAccess::toolDescription($tool, $description)` | | | + | `cortex.servers` | `servers.index` | list | none | `McpInstructionModel` | `ScreenAccess::serverInstruction($name, $instructions->get($name))` | + | `cortex.server-instructions` | `servers.instructions` | detail | `ScreenAccess::serverInstruction($server, $instruction)` | | | + | `cortex.redirect-domains` | `redirect-domains.index` | list | none | `RedirectDomainModel` | each stored row's `RedirectDomainModel` (configured rows get no row slot) | + + A feature test with a dataset over all 11 screens registers a tab and a section in every standard slot (`header.actions`, `before`, `after`, plus `aside` on detail or `row.actions` on list screens, with at least one row present). It asserts each section renders in its slot, and that the tab appears and opens through `?tab=`. Leakage is checked per kind through dataset columns: on every detail screen a section registered in `row.actions` must not render; on every list screen a section registered in `aside` must not render. No screen has a `history` slot. For `cortex.redirect-domains`, a configured (non-stored) row gets no `row.actions` section, asserted explicitly. +11. **Access closure.** Each screen's `access()` is `fn (string $permission, Request $request, ?Model $record): bool => ScreenAccess::allowsFor($request->user(), $permission, $record ?? $subject)`, with `$subject` from the table. On `cortex.run`, a null record denies. Tests: - a `permission('view')` section on `cortex.virtual-agent` shows when the fixture policy allows and hides when it denies - a `permission('viewAny')` section on `cortex.virtual-agents` follows the class check - a `permission()` section on `cortex.run` never shows -11. **Layout.** Per Atrium criterion 15, an open registered tab's panel replaces the page content, and only `header.actions` stays. `header.actions` sections render inside `x-atrium::page-header`'s actions, after the page's own actions. `before` and `after` render around the content. `aside` renders in a right-hand column only when it has visible sections. `row.actions` renders inside each row's last cell, after its own controls. With nothing registered, the markup is unchanged: every existing feature test passes without modification, except those listed in criterion 13. +12. **Layout.** Per Atrium criterion 15, an open registered tab's panel replaces the page content, and only `header.actions` stays. `header.actions` sections render inside `x-atrium::page-header`'s actions, after the page's own actions. `before` and `after` render around the content. `aside` renders in a right-hand column only when it has visible sections. `row.actions` renders inside each row's last cell, after its own controls. These are asserted on rendered HTML, not by eye: Atrium's aside landmark (`data-testid="screen-aside"`) is present only when a visible aside section exists and absent otherwise; `assertSeeInOrder` shows a `header.actions` section after the page's own actions, and a `row.actions` section after the row's own controls and inside the row's last `td`; with a tab open, `assertDontSee` on page-only content passes while the `header.actions` section is still seen. With nothing registered, the markup is unchanged: every existing feature test passes without modification, except those listed in criterion 14. ### History removal and Atrium as a suggestion -12. **No history in Cortex's UI.** The `` calls in `ui/virtual-agents/index`, `ui/virtual-agents/form` and `ui/partials/override` are removed, and `CortexPlugin::navigation()` no longer calls `historyNavItem()`. Screens declare no audit subject (Keen attaches History by wildcard). The Keystone JSON route `GET cortex/history` and the history MCP tool are unaffected (`tests/Feature/HistoryTest.php` passes unchanged). A test asserts that the plugin's navigation has no item whose route is `atrium.history.show`. A grep of `resources`, `src`, `README.md`, `CLAUDE.md`, `docs/agent/standards` and `resources/boost` for `audit-trail` and `historyNavItem` finds nothing. -13. **Forced test changes.** Existing tests may change only where this spec's decisions force it, and the PR lists each by file and test name. The expected set is: +13. **No history in Cortex's UI.** The `` calls in `ui/virtual-agents/index`, `ui/virtual-agents/form` and `ui/partials/override` are removed, and `CortexPlugin::navigation()` no longer calls `historyNavItem()`. Screens declare no audit subject (Keen attaches History by wildcard). The Keystone JSON route `GET cortex/history` and the history MCP tool are unaffected (`tests/Feature/HistoryTest.php` passes unchanged). A test asserts that the plugin's navigation has no item whose route is `atrium.history.show`. A grep of `resources`, `src`, `README.md`, `CLAUDE.md`, `docs/agent/standards` and `resources/boost` for `audit-trail` and `historyNavItem` finds nothing. +14. **Forced test changes.** Existing tests may change only where this spec's decisions force it, and the PR lists each by file and test name. The expected set is: - `tests/Feature/Ui/AuditTrailTest.php`: deleted (the component is gone from Atrium). - - `tests/Feature/HistoryNavigationTest.php`, `links its own audit log from its sidebar group`: replaced by criterion 12's assertion. - - `tests/Pest.php` and `tests/TestCase.php`: gain `ResetsScreenExtensions` and the test-host routes and migrations. -14. **Composer.** `refactor-circus/atrium` moves from `require` to `require-dev` (the suite needs it), and it is added to `suggest` with a description. Keystone stays the only suite package in `require`. A test reads `composer.json` and asserts: + - `tests/Feature/HistoryNavigationTest.php`, `links its own audit log from its sidebar group`: replaced by criterion 13's assertion. + - `tests/Pest.php` and `tests/TestCase.php`: gain `ResetsScreenExtensions`, the test-host routes and migrations, and the workbench owner policies. + - `tests/Feature/RedirectDomainsTest.php`, `manages domains over the json api` and `creates and deletes domains over mcp with parity to the http payload`: sign in a user before the owned calls, because criterion 8 denies guests for owned domains. Their assertions do not change. +15. **Composer.** `refactor-circus/atrium` moves from `require` to `require-dev` (the suite needs it), and it is added to `suggest` with a description. Keystone stays the only suite package in `require`. `composer.json` gains a `conflict` entry for `refactor-circus/atrium` on versions older than the first release that contains the screen-extensions registry (Atrium PR #16), so a mismatched install fails at `composer update` (D-020). The constraint is `expect('RefactorCircus\Cortex')->not->toUse('RefactorCircus\Atrium')->ignoring('RefactorCircus\Cortex\Atrium')`, and it passes. Registration lives in `RefactorCircus\Cortex\Atrium\ScreenRegistrations` (below). `CortexServiceProvider` reaches it only behind the same string `class_exists('RefactorCircus\Atrium\Atrium')` and `cortex.ui.enabled` guard that `registerAtriumPlugin()` uses. A test asserts `composer.json` lists no `refactor-circus/roster`. -16. **No-Atrium proof.** A `WithoutAtrium` suite proves Cortex boots and serves its HTTP API and MCP without Atrium: - - **Files:** `phpunit.without-atrium.xml`, bootstrap `tests/WithoutAtrium/bootstrap.php`, tests in `tests/WithoutAtrium`, excluded from the default `phpunit.xml.dist` suite. The bootstrap loads Composer's autoloader and removes the `RefactorCircus\Atrium\` PSR-4 prefix, so no Atrium class can load. Its `WithoutAtriumTestCase` registers no Atrium provider. + - `conflict` has a non-empty `refactor-circus/atrium` constraint starting with `<` +16. **Arch test.** `tests/ArchTest.php` gains `arch('only the Atrium layer uses Atrium')->expect('RefactorCircus\Cortex')->not->toUse('RefactorCircus\Atrium')->ignoring('RefactorCircus\Cortex\Atrium')`, and it passes. Registration lives in `RefactorCircus\Cortex\Atrium\ScreenRegistrations` (below). `CortexServiceProvider` reaches it only behind the same string `class_exists('RefactorCircus\Atrium\Atrium')` and `cortex.ui.enabled` guard that `registerAtriumPlugin()` uses. A test asserts `composer.json` lists no `refactor-circus/roster`. +17. **No-Atrium proof, both ways (D-020, D-025, D-029, D-030).** A `WithoutAtrium` suite proves Cortex boots and serves its HTTP API and MCP without Atrium, and a CI lane proves it with Atrium uninstalled: + - **Files:** `phpunit.without-atrium.xml`, bootstrap `tests/WithoutAtrium/bootstrap.php`, tests in `tests/WithoutAtrium`, excluded from the default `phpunit.xml.dist` suite. The bootstrap loads Composer's autoloader and removes the `RefactorCircus\Atrium\` PSR-4 prefix, so no Atrium class can load. It fails loudly (throws) if `ClassLoader::findFile('RefactorCircus\Atrium\Atrium')` still resolves, and the suite must not run with an optimized or authoritative classmap. Its `WithoutAtriumTestCase` registers no Atrium provider. The in-process run cannot see classmap or Composer `files` leaks, so the CI lane is the authoritative proof and is verified only by the workflow run, not by `composer test`. The README says so. - **Assertions:** + - the PSR-4 prefixes of Composer's `ClassLoader` no longer contain `RefactorCircus\Atrium\` (first test, so the removal is proven before the rest) - `class_exists('RefactorCircus\Atrium\Atrium')` is false - - the app boots with `CortexServiceProvider` + - the app boots with `CortexServiceProvider`, with the default `redirect_domains.screens` map present (no registration, no error) - no route name starts with `atrium.` - `cortex.redirect-domains.index` (JSON) answers 200 and `store` creates a domain - `mcpTool(ListRedirectDomainsTool::class)` answers @@ -100,53 +139,62 @@ Cortex owns the MCP redirect-domain UI for any owner model, placed on other pack ### Documentation -17. **Docs.** Three places change: - - **README:** a "Redirect domains on other screens" section documents `cortex.atrium.redirect_domains.screens`, the `cortex.mcp` tab key, the `cortex.redirect-domains` section key, the visibility rules from criterion 3, and that the owner's `RedirectDomainPolicy` decides who manages the domains. It also notes that Atrium is suggested, not required. +18. **Docs.** Three places change: + - **README:** a "Redirect domains on other screens" section documents `cortex.atrium.redirect_domains.screens`, the `cortex.mcp` tab key, the `cortex.redirect-domains` section key, the visibility rules from criterion 3, and that for an owned domain the bundled policy asks `update` on the owner (criterion 8), which apps can replace through `cortex.policies`. It also states "Atrium is suggested, not required" and that without Atrium the dashboard and these screens are simply absent (no error, no log; the HTTP API and MCP keep working). It documents that a malformed `redirect_domains.screens` entry throws at boot in local and testing and is reported and skipped in production, that older Atrium versions are refused through `conflict`, and that the CI lane is the authoritative no-Atrium proof. - **Local standard:** `docs/agent/standards/cortex/atrium-screens.md` replaces its "History" section with the screen-declaration rule: keys, standard slots, the access closure, and no audit components. - **Other docs and changelog:** `CLAUDE.md` and the Boost skill drop their audit-trail and history-nav text. `CHANGELOG.md` has an upgrade note covering: - - Atrium moved to `suggest` (apps using the dashboard require it themselves) - - the new config key + - Atrium moved to `suggest` (apps using the dashboard require it themselves), and a `conflict` refuses Atrium versions older than the screen registry + - the new config key (apps with a published config get the default map when the key is absent) - the `owner_type`/`owner_id` fields on the UI store and destroy routes + - owned domains: the bundled policy now asks `update` on the owner for `create` and `delete`, over the UI, the JSON API and MCP, so guests and users without it are refused; domains without an owner are unchanged - removed history UI (Keen provides it) + - the Roster tab key changes from `?tab=mcp` to `cortex.mcp` and the old Roster-named route names are gone (the moved UI routes are `atrium.cortex.redirect-domains.*`) - grouped merge with Atrium, Keen and Roster - A docs test asserts the README section exists and contains `redirect_domains.screens`, `cortex.mcp` and `suggest`. -18. Done means `composer test` passes, including `test:without-atrium`. Cortex has no browser suite, so there is no `test:browser` step. + A docs test asserts the README has the heading "Redirect domains on other screens" and contains `redirect_domains.screens`, `cortex.mcp` and the exact phrase `Atrium is suggested`. A CHANGELOG test asserts the upgrade note contains a keyword for each of the seven topics above (`suggest`, `redirect_domains`, `owner_type`, `update`, `History`, `?tab=mcp`, `merge`) and the word `conflict`. +19. Done means `composer test` passes, including `test:without-atrium`, and `vendor/bin/pest` passes. Cortex has no browser suite, so there is no `test:browser` step. ## Design -**Placement.** `RefactorCircus\Cortex\Atrium\ScreenRegistrations` (final, static `register(): void`) reads `cortex.atrium.redirect_domains.screens` and calls `Atrium::screens()->tab()` or `section()` per entry. Bad entries are not checked again: Atrium's own validation throws `InvalidArgumentException` at boot for a malformed target or slot. `CortexServiceProvider::boot()` calls it from a private `registerAtriumScreens()`, right after `registerAtriumPlugin()` and with the same guard. A target screen that nobody declares never renders (Atrium criterion 1). +**Placement.** `RefactorCircus\Cortex\Atrium\ScreenRegistrations` (final, static `register(): void`) reads `cortex.atrium.redirect_domains.screens` and calls `Atrium::screens()->tab()` or `section()` per entry. Each entry is validated and registered inside its own `try`: a non-string or empty value throws `InvalidArgumentException`, and Atrium's own validation throws it for a malformed target or slot. The `catch` rethrows when `app()->environment('local', 'testing')`; otherwise it calls `report($e)` and moves on to the next entry (D-021). Throwing a plain `InvalidArgumentException` breaks Cortex's convention that every thrown exception extends `CortexException`; the suite decision (D-021, matching Atrium D-022) wins, so the builder adds a row to `docs/agent/standards-feedback.md` saying so. It falls back to the default map only when the key is absent (criterion 1). `CortexServiceProvider::boot()` calls it from a private `registerAtriumScreens()`, right after `registerAtriumPlugin()` and with the same guard. A target screen that nobody declares never renders (Atrium criterion 1). **Definitions.** Tab `cortex.mcp` has the label `cortex::cortex.mcp` ("MCP") and icon `globe-alt`. Section `cortex.redirect-domains` has the label `cortex::cortex.redirect_domains`. Both use `view('cortex::ui.screens.redirect-domains')`, and they share one `authorize` closure (criterion 3) and one resolver (criterion 4). These closures run on every target screen's render, so they return early: they check `enabled()` and `$record?->exists` first and query nothing. -**Owner.** The screen's record is the owner. Its type in the form is `getMorphClass()`, so the morph map, already the registry `RedirectDomains::owner()` reads, decides the type string. Cortex never inspects which package the model belongs to (D-001, D-002 settled by the addendum). +**Owner.** The screen's record is the owner. Its type in the form is `getMorphClass()`, so the morph map, already the registry `RedirectDomains::owner()` reads, decides the type string (D-028). Cortex never inspects which package the model belongs to (D-001, D-002 settled by the addendum). + +**Authorization.** All of it is Cortex's own: `RedirectDomainPolicy` `viewAny`/`create` with the owner, and `delete` on the domain, through `cortex.policies`. These are the same checks the JSON API and MCP tools make. For an owned domain the bundled `create` and `delete` delegate to the owner's own policy with `$user->can('update', $owner)` (criterion 8), so a host that registers a policy for its model (Roster's organization and user policies) keeps the protection Roster's own UI had, without Cortex naming any host permission. The visibility check stays at `viewAny` (unchanged, allows everyone), and the add form and remove buttons follow `create` and `delete`. No per-entry config permission is added (D-023 chose (c) on top of (a)). The host's own authorization has already run before `resolve()` (Atrium criterion 9). -**Authorization.** All of it is Cortex's own: `RedirectDomainPolicy` `viewAny`/`create` with the owner, and `delete` on the domain, through `cortex.policies`. These are the same checks the JSON API and MCP tools make for owned domains. The host's own authorization has already run before `resolve()` (Atrium criterion 9). +**Redirect after owned writes.** Same-origin `url()->previous()`, else `atrium.cortex.redirect-domains.index` (D-026, criterion 7). -**Screen helper.** `RefactorCircus\Cortex\Atrium\Screens::declare(string $key, string $kind, ?Model $record, ?string $subject): Screen` (final, static) builds `Screen::standard()`, sets the record, and adds the access closure from criterion 10, so the 11 controllers share one definition. Controllers inject `ScreenExtensions` (Atrium's) and pass `resolved` to their views. The redirect-domains screen also keeps its `rows`. +**Screen helper.** `RefactorCircus\Cortex\Atrium\Screens::declare(string $key, string $kind, ?Model $record, ?string $subject): Screen` (final, static) builds `Screen::standard()`, sets the record, and adds the access closure from criterion 11, so the 11 controllers share one definition. Controllers inject `ScreenExtensions` (Atrium's) and pass `resolved` to their views. The redirect-domains screen also keeps its `rows`. **Lang.** `lang/en/cortex.php` gains `mcp` ("MCP") and `owned_redirect_domains_hint`, and reuses `domain`, `domain_hint`, `created`, `actions`, `remove_domain` and `no_redirect_domains`. -**Arch.** No new models, Data or Actions. The new classes live under `src/Atrium` (not `Domains/*/Models` or `Data`), so the model and Data arch rules don't apply. The workbench `Organization` model and its migration sit under `workbench/`, which the table-literal arch rule does not scan. +**Composer.** Atrium in `require-dev` and `suggest`, plus a `conflict` on Atrium older than the screen registry (criterion 15, D-020). Keystone is the only suite package in `require`. + +**Arch.** No new models, Data or Actions. The new classes live under `src/Atrium` (not `Domains/*/Models` or `Data`), so the model and Data arch rules don't apply. The policy change edits an existing class. The workbench `Organization` model, its migration and the workbench owner policies sit under `workbench/`, which the table-literal arch rule does not scan. ## Out of scope - Roster's own changes: deleting its copy, its `?tab=mcp` fallback and declaring `roster.organization` and `roster.user` belong to Roster's `adopt-atrium-screen-registry` spec. -- History, activity and audit UI (Keen's spec). -- Any host-permission check from the target package, such as Roster's `roster.organizations.update` (see Q-1). +- History, activity and audit UI (Keen's spec). Cortex declares no `history` slot and no audit subject; Keen attaches History by wildcard. +- Old `?tab=mcp` links: no removal or migration of them (they fall back to the default tab, D-003). +- Configured (non-stored) redirect-domain rows get no row slot. +- Cortex's dashboard behaviour, the JSON API and MCP for domains without an owner are unchanged. +- Any host-permission check named in Cortex config or code, such as Roster's `roster.organizations.update`. The owner's own policy decides instead (criterion 8). +- A config allow-list of owner types (D-028). - New JSON or MCP surfaces. The owner forms reuse the existing UI routes. +- Splitting this spec (D-024). + +## Risks -## Risks and open questions +- **Grouped merge.** Atrium PR #16 removes the components, and Roster deletes its copy. Merge Atrium, Keen, Roster and Cortex together, or Roster's MCP tab disappears in between. +- **Behaviour change for API and MCP callers (criterion 8).** Guests and users without `update` on an owner can no longer create or delete that owner's domains. An owner model with no policy and no Gate ability answers `update` as denied, so apps that used owned domains without an owner policy must add one or set their own class in `cortex.policies`. The CHANGELOG says so. +- **Atrium version for `conflict`.** Atrium has no release tag yet; the constraint needs the version that ships PR #16 (criterion 15). If it is not tagged when the group is built, `<1.0.0` is used and the PR records it, so Atrium's registry release must be 1.0.0 or later. +- **Production config errors.** A malformed `redirect_domains.screens` entry is skipped silently apart from one report in production, so the UI for that entry is missing until the report is acted on. +- The owner's morph class appears in a hidden field. It is no secret, and `RedirectDomains::owner()` rejects non-models. +- Moving Atrium to `require-dev` breaks apps that relied on Cortex pulling it in. The CHANGELOG says so. -- **Q-1. Who may manage an owner's domains on a host screen?** Roster required `roster.organizations.update` (organization tab) or `roster.users.update` (user add/remove). Cortex can't name those permissions in code. - - **(a)** Cortex's `RedirectDomainPolicy` only, with the owner. The bundled policy allows everyone, as the JSON API and MCP already do for owned domains. Apps restrict it with their own policy class. This loosens the UI compared with Roster's defaults. - - **(b)** A per-entry config permission, e.g. `'roster.organization' => ['slot' => 'tab', 'permission' => 'roster.organizations.update']`, applied through `permission()` and the host's `access()`. This hides the UI, but Cortex's POST routes can't ask the host's access closure, so the routes stay at (a)'s level. - - **(c)** (a), and also ship the bundled policy's `create`/`delete` for a non-null owner as `$user->can('update', $owner)`, so the owner's own policy decides. +## Changelog - Recommendation: (c), because it keeps the old protection where hosts register Gate policies, names no package, and applies to the API too. It is a behaviour change for API callers, so the user should confirm it. The spec is written against (a); choosing (c) adds one criterion. -- **Q-2. Running without Atrium.** This spec runs it in process (the PSR-4 prefix removed, inside `composer test`) and also in a CI lane with Atrium uninstalled. Options: in-process only, CI only, or both. Recommendation: both, because the in-process run keeps "done" local and the CI lane catches classmap or autoload-file leaks. -- **Q-3. Removing redirect target.** `url()->previous()` limited to the same host is used instead of naming the host's route. If the referrer is missing, the user lands on Cortex's redirect-domains index, which is acceptable. -- **Risks:** - - Grouped merge: Atrium PR #16 removes the components, and Roster deletes its copy. Merge Atrium, Keen, Roster and Cortex together, or Roster's MCP tab disappears in between. - - The owner's morph class appears in a hidden field. It is no secret, and `RedirectDomains::owner()` rejects non-models. - - Moving Atrium to `require-dev` breaks apps that relied on Cortex pulling it in. The CHANGELOG says so. +- 2026-10-29, approved: folded D-020 (both-ways no-Atrium proof, Atrium `conflict`, criteria 15 and 17), D-021 (throw in local/testing, report and skip in production, criterion 2), D-022, D-023 and D-027 (bundled policy asks `update` on the owner for owned `create`/`delete`, new criterion 8, forced test changes in criterion 14, CHANGELOG line), D-024 (one spec), D-025, D-029 and D-030 (both proofs), D-026 (same-origin redirect, criterion 7), D-028 (no owner-type allow-list, rejection tests in criterion 7). Criteria renumbered from 8 on. Open questions Q-1 to Q-3 removed as decided. diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md new file mode 100644 index 0000000..ab255ec --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md @@ -0,0 +1,62 @@ +# Tasks: Register Roster redirect domains + +## Group 1: Owner-decided policy and owner-aware UI controller +package: Cortex +depends on: none +files: src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php, src/Atrium/Http/Controllers/RedirectDomainUiController.php, tests/Feature/OwnedRedirectDomainPolicyTest.php, tests/Feature/Ui/RedirectDomainOwnerControllerTest.php, tests/Feature/RedirectDomainsTest.php, tests/Fixtures/OwnerPolicyFixture.php +criteria: 7, 8, 14 + +- [ ] 1.1 Write tests: OwnedRedirectDomainPolicyTest (guest, user without owner update, user with it, null-owner unchanged, deleted owner, over JSON, MCP and Gate) and RedirectDomainOwnerControllerTest (owner types, partial owner, unknown owner, owner-scoped destroy, same-origin redirect and the lookalike, userinfo, scheme-mismatch and missing-referrer fallbacks) per criteria 7 and 8. +- [ ] 1.2 Change RedirectDomainPolicy create and delete for owned domains to `$user !== null && $user->can('update', $owner)` (deleted owner denied, null owner unchanged) and update its docblock. +- [ ] 1.3 Add optional owner_type/owner_id to RedirectDomainUiController store and destroy (ownerRules validation, RedirectDomains::owner(), ownedBy scope, create/delete authorization, same-origin url()->previous() else atrium.cortex.redirect-domains.index). +- [ ] 1.4 Sign in a user before the owned calls in RedirectDomainsTest `manages domains over the json api` and `creates and deletes domains over mcp with parity to the http payload` only, leaving their assertions unchanged. +- [ ] 1.5 Run vendor/bin/pest; all green + +## Group 2: Composer, arch rule, test host and the no-Atrium proof +package: Cortex +depends on: none +files: composer.json, tests/ArchTest.php, tests/TestCase.php, tests/Pest.php, tests/Feature/ComposerTest.php, workbench/app/Http/Controllers/TestHostScreenController.php, workbench/app/Models/Organization.php, workbench/app/Policies/OrganizationPolicy.php, workbench/app/Policies/UserPolicy.php, workbench/database/migrations/, workbench/resources/views/test-host.blade.php, phpunit.xml.dist, phpunit.without-atrium.xml, tests/WithoutAtrium/, .github/workflows/tests.yml +criteria: 9, 14, 15, 16, 17 + +- [ ] 2.1 Write tests: ComposerTest (require only keystone among refactor-circus, atrium in suggest and require-dev, atrium conflict starting with `<`, no roster), the WithoutAtrium suite assertions of criterion 17, and a test-host smoke test that the workbench screen renders for roster.organization, roster.user and acme.account. +- [ ] 2.2 Move refactor-circus/atrium from require to require-dev, add it to suggest with a description, and add a conflict on Atrium older than the screen-registry release (`<1.0.0` if Atrium is untagged, recorded in the PR). +- [ ] 2.3 Add the arch rule `only the Atrium layer uses Atrium` to tests/ArchTest.php. +- [ ] 2.4 Build the workbench test host (TestHostScreenController, Organization model and migration, OrganizationPolicy and UserPolicy with a deny flag, test-host view with screen-tabs, screen-tab-panel and screen-sections) and wire it plus ResetsScreenExtensions into tests/TestCase.php and tests/Pest.php. +- [ ] 2.5 Add phpunit.without-atrium.xml, tests/WithoutAtrium/bootstrap.php (removes the Atrium PSR-4 prefix and throws if findFile still resolves) and WithoutAtriumTestCase, exclude it from phpunit.xml.dist, add the `test:without-atrium` composer script called by `composer test` after `@test:unit`, and add the `without-atrium` CI job. +- [ ] 2.6 Run vendor/bin/pest; all green + +## Group 3: Redirect domains on other packages' screens +package: Cortex +depends on: 1, 2 +files: config/cortex.php, src/Atrium/ScreenRegistrations.php, src/CortexServiceProvider.php, resources/views/ui/screens/redirect-domains.blade.php, lang/en/cortex.php, tests/Feature/Ui/ScreenRegistrationsTest.php, tests/Feature/Ui/OwnedRedirectDomainsTest.php, tests/Feature/Ui/VisibilityTest.php, tests/Feature/Ui/StylesTest.php, tests/Feature/NoRosterReferenceTest.php, docs/agent/standards-feedback.md +criteria: 1, 2, 3, 4, 5, 6 + +- [ ] 3.1 Write tests: ScreenRegistrationsTest (default map, absent-key fallback, empty list, custom list, ui disabled, null/empty/bogus-slot throw in testing, production reports one and registers the valid entry), OwnedRedirectDomainsTest and VisibilityTest per criterion 6, the query-count and throwing-policy cases of criterion 3, the src grep for `roster`, and StylesTest coverage of the new view. +- [ ] 3.2 Add `atrium.redirect_domains.screens` with its banner and default map to config/cortex.php. +- [ ] 3.3 Implement ScreenRegistrations::register() (per-entry try, throw in local/testing, report and skip elsewhere) and call it from a private registerAtriumScreens() in CortexServiceProvider behind the registerAtriumPlugin() guard, and add the standards-feedback row for throwing InvalidArgumentException. +- [ ] 3.4 Implement the shared authorize closure (cheap early returns, caught policy exceptions) and resolver, and the cortex::ui.screens.redirect-domains view with the hint, add form, owned table, remove buttons and empty state, plus the `mcp` and `owned_redirect_domains_hint` lang keys. +- [ ] 3.5 Run vendor/bin/pest; all green + +## Group 4: Declare Cortex's own screens and remove history UI +package: Cortex +depends on: 1, 2 +files: src/Atrium/Screens.php, src/Atrium/CortexPlugin.php, src/Atrium/Http/Controllers/ConcreteAgentUiController.php, src/Atrium/Http/Controllers/McpInstructionUiController.php, src/Atrium/Http/Controllers/RedirectDomainUiController.php, src/Atrium/Http/Controllers/RunAgentUiController.php, src/Atrium/Http/Controllers/ServerUiController.php, src/Atrium/Http/Controllers/ToolDescriptionUiController.php, src/Atrium/Http/Controllers/ToolUiController.php, src/Atrium/Http/Controllers/VirtualAgentUiController.php, resources/views/ui/virtual-agents/index.blade.php, resources/views/ui/virtual-agents/form.blade.php, resources/views/ui/concrete-agents/index.blade.php, resources/views/ui/concrete-agents/show.blade.php, resources/views/ui/run.blade.php, resources/views/ui/tools/index.blade.php, resources/views/ui/tools/description.blade.php, resources/views/ui/servers/index.blade.php, resources/views/ui/servers/instructions.blade.php, resources/views/ui/redirect-domains/index.blade.php, resources/views/ui/partials/override.blade.php, tests/Feature/Ui/DeclaredScreensTest.php, tests/Feature/Ui/ScreenAccessClosureTest.php, tests/Feature/Ui/ScreenLayoutTest.php, tests/Feature/Ui/AuditTrailTest.php, tests/Feature/HistoryNavigationTest.php, tests/Feature/NoHistoryUiTest.php, CLAUDE.md, README.md, resources/boost/, docs/agent/standards/cortex/atrium-screens.md +criteria: 10, 11, 12, 13, 14 + +- [ ] 4.1 Write tests: DeclaredScreensTest dataset over the 11 screens (every standard slot, tab via ?tab=, per-kind leakage, no history slot, no row slot on configured redirect-domain rows), ScreenAccessClosureTest (view, viewAny, run never), ScreenLayoutTest (aside landmark, assertSeeInOrder for header.actions and row.actions, open tab hides page content), and NoHistoryUiTest (no atrium.history.show nav item, grep for audit-trail and historyNavItem). +- [ ] 4.2 Add Screens::declare() with the criterion 11 access closure and declare and resolve each of the 11 screens in their controllers, passing `resolved` to the views. +- [ ] 4.3 Render screen-tabs, screen-tab-panel and the standard slot sections in every Cortex view per Atrium criterion 15, leaving markup unchanged when nothing is registered. +- [ ] 4.4 Remove the audit-trail calls from ui/virtual-agents/index, ui/virtual-agents/form and ui/partials/override, drop historyNavItem() from CortexPlugin::navigation(), delete tests/Feature/Ui/AuditTrailTest.php and replace `links its own audit log from its sidebar group` with the criterion 13 assertion. +- [ ] 4.5 Drop audit-trail and history-nav text from CLAUDE.md, README.md (the audit-trail paragraph) and resources/boost, and replace the History section of docs/agent/standards/cortex/atrium-screens.md with the screen-declaration rule. +- [ ] 4.6 Run vendor/bin/pest; all green + +## Group 5: README and CHANGELOG +package: Cortex +depends on: 3, 4 +files: README.md, CHANGELOG.md, tests/Feature/DocsTest.php +criteria: 18, 19 + +- [ ] 5.1 Write tests in DocsTest for the README heading and phrases and the CHANGELOG keywords listed in criterion 18. +- [ ] 5.2 Add the README "Redirect domains on other screens" section (config, keys, visibility, owner update policy, Atrium is suggested, conflict, fail-fast in local/testing and report-and-skip in production, CI lane as the authoritative proof). +- [ ] 5.3 Add the CHANGELOG upgrade note covering the seven topics of criterion 18, including the owned-domain policy change and the Atrium conflict. +- [ ] 5.4 Run composer test (including test:without-atrium) and vendor/bin/pest; all green From 570ac86ddc39d76787118c098ede17f79d0f7045 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:37:00 -0400 Subject: [PATCH 07/23] 2026-10-29-2038-register-roster-redirect-domains: building (run 2) --- .../2026-10-29-2038-register-roster-redirect-domains/meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml index 6244f4a..db5024f 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/meta.yml @@ -1,6 +1,6 @@ id: 2026-10-29-2038-register-roster-redirect-domains title: 'Register Roster redirect domains' -status: approved +status: building created: '2026-10-29 20:38' standards: refactor-circus/standards: From 755914b5b065865fe9cad7b3785423d206424f6c Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:46:58 -0400 Subject: [PATCH 08/23] 2026-10-29-2038-register-roster-redirect-domains: group 1 Owner-decided policy and owner-aware UI controller Co-Authored-By: Claude Opus 5.5 --- .../RedirectDomainUiController.php | 93 ++++++- .../Policies/RedirectDomainPolicy.php | 44 ++- .../Feature/OwnedRedirectDomainPolicyTest.php | 171 ++++++++++++ tests/Feature/RedirectDomainsTest.php | 7 + .../Ui/RedirectDomainOwnerControllerTest.php | 258 ++++++++++++++++++ tests/Fixtures/OwnerPolicyFixture.php | 37 +++ 6 files changed, 591 insertions(+), 19 deletions(-) create mode 100644 tests/Feature/OwnedRedirectDomainPolicyTest.php create mode 100644 tests/Feature/Ui/RedirectDomainOwnerControllerTest.php create mode 100644 tests/Fixtures/OwnerPolicyFixture.php diff --git a/src/Atrium/Http/Controllers/RedirectDomainUiController.php b/src/Atrium/Http/Controllers/RedirectDomainUiController.php index 9919443..909cc05 100644 --- a/src/Atrium/Http/Controllers/RedirectDomainUiController.php +++ b/src/Atrium/Http/Controllers/RedirectDomainUiController.php @@ -6,8 +6,10 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Contracts\View\View; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Validator; use RefactorCircus\Cortex\Atrium\Http\Controllers\Concerns\AuthorizesScreens; use RefactorCircus\Cortex\Domains\RedirectDomain\Actions\CreateRedirectDomainAction; use RefactorCircus\Cortex\Domains\RedirectDomain\Actions\DeleteRedirectDomainAction; @@ -19,8 +21,9 @@ use RefactorCircus\Cortex\Exceptions\UnexpectedResultException; /** - * Every stored redirect domain, whoever owns it. Domains added here belong - * to no owner. + * Every stored redirect domain, whoever owns it. Domains added on this + * screen belong to no owner; a host screen's form names its record as the + * owner with `owner_type` and `owner_id`. */ final class RedirectDomainUiController { @@ -66,28 +69,94 @@ public function index(Request $request): View ]); } + /** + * Add a domain, for the owner named by `owner_type` and `owner_id` when + * the form names one (a host screen's record), else for no owner. + */ public function store(Request $request): RedirectResponse { - $this->authorizeScreen('create', RedirectDomainModel::class, [null]); + $owner = $this->owner($request); + + $this->authorizeScreen('create', RedirectDomainModel::class, [$owner]); - app(CreateRedirectDomainAction::class)->execute(CreateRedirectDomainData::from($request->all())); + app(CreateRedirectDomainAction::class)->execute(CreateRedirectDomainData::from($request->all()), $owner); - return redirect() - ->route('atrium.cortex.redirect-domains.index') - ->with('status', __('cortex::cortex.redirect_domain_added')); + return $this->back($request, $owner)->with('status', __('cortex::cortex.redirect_domain_added')); } - public function destroy(string $domain): RedirectResponse + /** + * Remove a domain. With an owner named, only one of that owner's domains + * is found, so a form for one owner cannot remove another's. + */ + public function destroy(Request $request, string $domain): RedirectResponse { - $model = RedirectDomainModel::query()->findOrFail($domain); + $owner = $this->owner($request); + + $model = $owner === null + ? RedirectDomainModel::query()->findOrFail($domain) + : RedirectDomainModel::query()->ownedBy($owner)->whereKey($domain)->firstOrFail(); $this->authorizeScreen('delete', $model); app(DeleteRedirectDomainAction::class)->execute($model); - return redirect() - ->route('atrium.cortex.redirect-domains.index') - ->with('status', __('cortex::cortex.redirect_domain_removed')); + return $this->back($request, $owner)->with('status', __('cortex::cortex.redirect_domain_removed')); + } + + /** + * The owner the form names, or null when it names none. Both fields or + * neither: one without the other is invalid. The type is a morph alias or + * a model class `RedirectDomains::owner()` resolves; anything else, and an + * unknown key, is not found. + */ + private function owner(Request $request): ?Model + { + $validated = Validator::make($request->only(['owner_type', 'owner_id']), [ + 'owner_type' => ['nullable', 'required_with:owner_id', 'string', 'max:255'], + 'owner_id' => ['nullable', 'required_with:owner_type', 'string', 'max:255'], + ])->validate(); + + $type = $validated['owner_type'] ?? null; + $id = $validated['owner_id'] ?? null; + + return app(RedirectDomains::class)->owner( + is_string($type) ? $type : null, + is_string($id) ? $id : null, + ); + } + + /** + * Where a write goes next: without an owner, the redirect-domains screen; + * with one, back to the page the form was on when its scheme, host and + * port are exactly this request's, else (a foreign or missing referrer) + * the redirect-domains screen. Only the path and query are kept, on the + * request's own origin, so no referrer can send the browser elsewhere. + */ + private function back(Request $request, ?Model $owner): RedirectResponse + { + $index = route('atrium.cortex.redirect-domains.index'); + + if ($owner === null) { + return redirect()->to($index); + } + + $origin = $request->getSchemeAndHttpHost(); + $previous = parse_url(url()->previous($index)); + $own = parse_url($origin); + + if (! is_array($previous) || ! is_array($own)) { + return redirect()->to($index); + } + + foreach (['scheme', 'host', 'port'] as $part) { + if (($previous[$part] ?? null) !== ($own[$part] ?? null)) { + return redirect()->to($index); + } + } + + $query = isset($previous['query']) ? '?'.$previous['query'] : ''; + + return redirect()->to($origin.($previous['path'] ?? '/').$query); } /** diff --git a/src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php b/src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php index 49fa26f..37bb3ef 100644 --- a/src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php +++ b/src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php @@ -6,17 +6,26 @@ use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Gate; use RefactorCircus\Cortex\Domains\RedirectDomain\Models\RedirectDomainModel; use RefactorCircus\Cortex\Support\Policies\Policy; /** * Answers `$user->can(...)` for redirect domains. * - * Like the rest of Cortex every ability is allowed, for guests too: the - * route middleware in front of the API and MCP server decides who gets in. - * `create` receives the owner the domain is for (null for every client), so - * your own class in `cortex.policies` can tell an organization's admins from - * everyone else. + * A domain without an owner follows the rest of Cortex: every ability is + * allowed, for guests too, and the route middleware in front of the API and + * MCP server decides who gets in. + * + * A domain with an owner (an organization, a user) is that owner's to + * manage, so `create` and `delete` ask the owner's own policy: a signed-in + * user who may `update` the owner may add or remove its domains. Guests are + * refused, and so is everyone for a domain whose owner row no longer exists. + * The Atrium screens, the JSON API and the MCP tools all ask this policy, so + * the rule holds on each of them. `viewAny` still allows everyone. + * + * Point `RedirectDomainModel` at your own class in `cortex.policies` to + * decide differently; this one is then not asked at all. */ class RedirectDomainPolicy extends Policy { @@ -27,11 +36,32 @@ public function viewAny(?Authenticatable $user, ?Model $owner = null): bool public function create(?Authenticatable $user, ?Model $owner = null): bool { - return true; + if ($owner === null) { + return true; + } + + return $this->mayUpdate($user, $owner); } public function delete(?Authenticatable $user, RedirectDomainModel $domain): bool { - return true; + if ($domain->owner_type === null) { + return true; + } + + if ($user === null) { + return false; + } + + return $this->mayUpdate($user, $domain->owner); + } + + /** + * Whether a signed-in user may update the owner, by the owner's own + * policy. A missing owner is refused. + */ + private function mayUpdate(?Authenticatable $user, ?Model $owner): bool + { + return $user !== null && $owner !== null && Gate::forUser($user)->allows('update', $owner); } } diff --git a/tests/Feature/OwnedRedirectDomainPolicyTest.php b/tests/Feature/OwnedRedirectDomainPolicyTest.php new file mode 100644 index 0000000..c209f5f --- /dev/null +++ b/tests/Feature/OwnedRedirectDomainPolicyTest.php @@ -0,0 +1,171 @@ +create(); +} + +function ownedPolicyDomain(?VirtualAgentModel $owner, string $domain = 'claude.ai'): RedirectDomainModel +{ + return app(CreateRedirectDomainAction::class)->execute(new CreateRedirectDomainData(domain: $domain), $owner); +} + +/** + * The input naming an owner, as the JSON API and MCP take it. + * + * @return array{owner_type: string, owner_id: string} + */ +function ownedPolicyOwnerInput(VirtualAgentModel $owner): array +{ + return ['owner_type' => $owner->getMorphClass(), 'owner_id' => (string) $owner->getKey()]; +} + +function ownedPolicyUser(): GenericUser +{ + return new GenericUser(['id' => 1, 'name' => 'Owner admin', 'email' => 'admin@example.com']); +} + +it('refuses a guest creating or deleting an owned domain, even when the owner policy would allow it', function (): void { + $owner = ownedPolicyOwner(); + $domain = ownedPolicyDomain($owner); + + expect(Gate::forUser(null)->allows('create', [RedirectDomainModel::class, $owner]))->toBeFalse() + ->and(Gate::forUser(null)->allows('delete', $domain))->toBeFalse() + ->and(Gate::forUser(null)->allows('viewAny', [RedirectDomainModel::class, $owner]))->toBeTrue(); + + // A refused guest gets 401 over HTTP (authorization standard), a + // refused signed-in user 403. + $this->postJson(route('cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownedPolicyOwnerInput($owner)]) + ->assertUnauthorized(); + $this->deleteJson(route('cortex.redirect-domains.destroy', $domain->id))->assertUnauthorized(); + + mcpTool(CreateRedirectDomainTool::class, ['domain' => 'chatgpt.com', ...ownedPolicyOwnerInput($owner)]) + ->assertHasErrors(['Unauthorized.']); + mcpTool(DeleteRedirectDomainTool::class, ['id' => $domain->id])->assertHasErrors(['Unauthorized.']); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); +}); + +it('refuses a signed-in user the owner policy does not let update the owner', function (): void { + OwnerPolicyFixture::$allowsUpdate = false; + $owner = ownedPolicyOwner(); + $domain = ownedPolicyDomain($owner); + $user = ownedPolicyUser(); + $this->actingAs($user); + + expect(Gate::forUser($user)->allows('create', [RedirectDomainModel::class, $owner]))->toBeFalse() + ->and(Gate::forUser($user)->allows('delete', $domain))->toBeFalse() + ->and(Gate::forUser($user)->allows('viewAny', [RedirectDomainModel::class, $owner]))->toBeTrue(); + + $this->postJson(route('cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownedPolicyOwnerInput($owner)]) + ->assertForbidden(); + $this->deleteJson(route('cortex.redirect-domains.destroy', $domain->id))->assertForbidden(); + + mcpTool(CreateRedirectDomainTool::class, ['domain' => 'chatgpt.com', ...ownedPolicyOwnerInput($owner)]) + ->assertHasErrors(['Unauthorized.']); + mcpTool(DeleteRedirectDomainTool::class, ['id' => $domain->id])->assertHasErrors(['Unauthorized.']); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']) + ->and(OwnerPolicyFixture::$asked)->toBeGreaterThan(0); +}); + +it('allows a signed-in user the owner policy lets update the owner', function (): void { + $owner = ownedPolicyOwner(); + $user = ownedPolicyUser(); + $this->actingAs($user); + + $gateDomain = ownedPolicyDomain($owner, 'gate.example.com'); + + expect(Gate::forUser($user)->allows('create', [RedirectDomainModel::class, $owner]))->toBeTrue() + ->and(Gate::forUser($user)->allows('delete', $gateDomain))->toBeTrue(); + + $id = $this->postJson(route('cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownedPolicyOwnerInput($owner)]) + ->assertCreated() + ->assertJsonPath('data.owner_id', (string) $owner->getKey()) + ->json('data.id'); + $this->deleteJson(route('cortex.redirect-domains.destroy', $id))->assertNoContent(); + + mcpTool(CreateRedirectDomainTool::class, ['domain' => 'claude.ai', ...ownedPolicyOwnerInput($owner)])->assertOk(); + $mcp = RedirectDomainModel::query()->where('domain', 'https://claude.ai')->sole(); + + expect($mcp->owner_id)->toBe((string) $owner->getKey()); + + mcpTool(DeleteRedirectDomainTool::class, ['id' => $mcp->id])->assertOk(); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://gate.example.com']); +}); + +it('leaves domains without an owner open to guests and signed-in users alike', function (?GenericUser $user): void { + OwnerPolicyFixture::$allowsUpdate = false; + + if ($user !== null) { + $this->actingAs($user); + } + + $gateDomain = ownedPolicyDomain(null, 'gate.example.com'); + + expect(Gate::forUser($user)->allows('create', [RedirectDomainModel::class, null]))->toBeTrue() + ->and(Gate::forUser($user)->allows('create', RedirectDomainModel::class))->toBeTrue() + ->and(Gate::forUser($user)->allows('delete', $gateDomain))->toBeTrue(); + + $id = $this->postJson(route('cortex.redirect-domains.store'), ['domain' => 'chatgpt.com']) + ->assertCreated() + ->assertJsonPath('data.owner_type', null) + ->json('data.id'); + $this->deleteJson(route('cortex.redirect-domains.destroy', $id))->assertNoContent(); + + mcpTool(CreateRedirectDomainTool::class, ['domain' => 'claude.ai'])->assertOk(); + $mcp = RedirectDomainModel::query()->where('domain', 'https://claude.ai')->sole(); + mcpTool(DeleteRedirectDomainTool::class, ['id' => $mcp->id])->assertOk(); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://gate.example.com']) + ->and(OwnerPolicyFixture::$asked)->toBe(0); +})->with([ + 'a guest' => [null], + 'a signed-in user' => [fn (): GenericUser => ownedPolicyUser()], +]); + +it('refuses deleting a domain whose owner row no longer exists', function (): void { + $owner = ownedPolicyOwner(); + $domain = ownedPolicyDomain($owner); + $owner->delete(); + $user = ownedPolicyUser(); + $this->actingAs($user); + + expect(Gate::forUser($user)->allows('delete', $domain->fresh()))->toBeFalse(); + + $this->deleteJson(route('cortex.redirect-domains.destroy', $domain->id))->assertForbidden(); + mcpTool(DeleteRedirectDomainTool::class, ['id' => $domain->id])->assertHasErrors(['Unauthorized.']); + + expect(RedirectDomainModel::query()->whereKey($domain->id)->exists())->toBeTrue() + ->and(OwnerPolicyFixture::$asked)->toBe(0); +}); diff --git a/tests/Feature/RedirectDomainsTest.php b/tests/Feature/RedirectDomainsTest.php index e7d99da..b5b7739 100644 --- a/tests/Feature/RedirectDomainsTest.php +++ b/tests/Feature/RedirectDomainsTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Illuminate\Auth\GenericUser; use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken; use Illuminate\Support\Facades\Event; use Illuminate\Testing\TestResponse; @@ -131,6 +132,9 @@ function redirectAccepted(TestResponse $response): bool ->assertJsonPath('data.owner_type', null) ->json('data.id'); + // Owned domains need a signed-in user who may update the owner. + $this->actingAs(new GenericUser(['id' => 1])); + $this->postJson(route('cortex.redirect-domains.store'), [ 'domain' => 'chatgpt.com', 'owner_type' => $owner->getMorphClass(), @@ -173,6 +177,9 @@ function redirectAccepted(TestResponse $response): bool it('creates and deletes domains over mcp with parity to the http payload', function (): void { $owner = VirtualAgentModel::factory()->create(); + // Owned domains need a signed-in user who may update the owner. + $this->actingAs(new GenericUser(['id' => 1])); + $response = mcpTool(CreateRedirectDomainTool::class, [ 'domain' => 'https://claude.ai', 'owner_type' => $owner->getMorphClass(), diff --git a/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php b/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php new file mode 100644 index 0000000..588d45e --- /dev/null +++ b/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php @@ -0,0 +1,258 @@ + true); + + OwnerPolicyFixture::reset(); + Gate::policy(VirtualAgentModel::class, OwnerPolicyFixture::class); + + $this->morphMapBefore = Relation::$morphMap; + + $this->actingAs(new GenericUser(['id' => 1, 'name' => 'Owner admin', 'email' => 'admin@example.com'])); +}); + +afterEach(function (): void { + Relation::$morphMap = $this->morphMapBefore; + + OwnerPolicyFixture::reset(); +}); + +/** + * The hidden fields a host screen's form posts for its record. + * + * @return array{owner_type: string, owner_id: string} + */ +function ownerFields(Model $owner): array +{ + return ['owner_type' => $owner->getMorphClass(), 'owner_id' => (string) $owner->getKey()]; +} + +function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomainModel +{ + return app(CreateRedirectDomainAction::class)->execute(new CreateRedirectDomainData(domain: $domain), $owner); +} + +const OWNER_HOST_PAGE = 'http://localhost/test-host/acme.account/1?tab=cortex.mcp'; + +it('stores a domain for an owner named by its class and goes back to the host page', function (): void { + $owner = VirtualAgentModel::factory()->create(); + + $this->from(OWNER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) + ->assertRedirect(OWNER_HOST_PAGE) + ->assertSessionHas('status'); + + $stored = RedirectDomainModel::query()->sole(); + + expect($stored->domain)->toBe('https://claude.ai') + ->and($stored->owner_type)->toBe(VirtualAgentModel::class) + ->and($stored->owner_id)->toBe((string) $owner->getKey()); +}); + +it('removes an owner\'s domain and goes back to the host page', function (): void { + $owner = VirtualAgentModel::factory()->create(); + $domain = ownerDomain($owner); + + $this->from(OWNER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + ->assertRedirect(OWNER_HOST_PAGE) + ->assertSessionHas('status'); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('takes the owner by its morph alias', function (): void { + Relation::morphMap(['owner-agent' => VirtualAgentModel::class]); + $owner = VirtualAgentModel::factory()->create(); + + expect(ownerFields($owner)['owner_type'])->toBe('owner-agent'); + + $this->from(OWNER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) + ->assertRedirect(OWNER_HOST_PAGE); + + $stored = RedirectDomainModel::query()->sole(); + + expect($stored->owner_type)->toBe('owner-agent') + ->and($stored->owner_id)->toBe((string) $owner->getKey()); + + $this->from(OWNER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $stored->id), ownerFields($owner)) + ->assertRedirect(OWNER_HOST_PAGE); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('refuses owner types RedirectDomains::owner() does not resolve, writing nothing', function (string $type): void { + $owner = VirtualAgentModel::factory()->create(); + $domain = ownerDomain($owner); + + $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', 'owner_type' => $type, 'owner_id' => '1']) + ->assertNotFound(); + $this->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ['owner_type' => $type, 'owner_id' => (string) $owner->getKey()]) + ->assertNotFound(); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); +})->with([ + 'a non-model class' => [stdClass::class], + 'a non-Eloquent class' => [Collection::class], + 'the abstract Eloquent base' => [Model::class], + 'a missing class' => ['Nope\\Missing'], + 'an unknown alias' => ['unknown-owner'], +]); + +it('refuses a malformed owner id, writing nothing', function (mixed $id, int $status): void { + $owner = VirtualAgentModel::factory()->create(); + $domain = ownerDomain($owner); + + $this->postJson(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', 'owner_type' => VirtualAgentModel::class, 'owner_id' => $id]) + ->assertStatus($status); + $this->deleteJson(route('atrium.cortex.redirect-domains.destroy', $domain->id), ['owner_type' => VirtualAgentModel::class, 'owner_id' => $id]) + ->assertStatus($status); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); +})->with([ + 'an array' => [['1'], 422], + 'too long' => [str_repeat('x', 256), 422], + 'an unknown key' => ['missing', 404], +]); + +it('answers 422 on the missing field for a partial owner, writing nothing', function (array $fields, string $missing): void { + $owner = VirtualAgentModel::factory()->create(); + $domain = ownerDomain($owner); + $fields = array_map(fn (string $value): string => str_replace(':id', (string) $owner->getKey(), $value), $fields); + + $this->postJson(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...$fields]) + ->assertUnprocessable() + ->assertJsonValidationErrors($missing); + $this->deleteJson(route('atrium.cortex.redirect-domains.destroy', $domain->id), $fields) + ->assertUnprocessable() + ->assertJsonValidationErrors($missing); + + // A form post gets the same error back on the page it came from. + $this->from(OWNER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...$fields]) + ->assertRedirect(OWNER_HOST_PAGE) + ->assertSessionHasErrors($missing); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); +})->with([ + 'a type without an id' => [['owner_type' => VirtualAgentModel::class], 'owner_id'], + 'an id without a type' => [['owner_id' => ':id'], 'owner_type'], + 'an empty id' => [['owner_type' => VirtualAgentModel::class, 'owner_id' => ''], 'owner_id'], + 'an empty type' => [['owner_type' => '', 'owner_id' => ':id'], 'owner_type'], +]); + +it('answers 404 for an owner that does not exist', function (): void { + $owner = VirtualAgentModel::factory()->create(); + $domain = ownerDomain($owner); + $missing = ['owner_type' => VirtualAgentModel::class, 'owner_id' => '01JZZZZZZZZZZZZZZZZZZZZZZZ']; + + $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...$missing])->assertNotFound(); + $this->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), $missing)->assertNotFound(); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); +}); + +it('finds the domain among the named owner\'s only', function (): void { + $ownerA = VirtualAgentModel::factory()->create(); + $ownerB = VirtualAgentModel::factory()->create(); + $domainOfB = ownerDomain($ownerB); + $global = ownerDomain(null, 'perplexity.ai'); + + $this->delete(route('atrium.cortex.redirect-domains.destroy', $domainOfB->id), ownerFields($ownerA))->assertNotFound(); + $this->delete(route('atrium.cortex.redirect-domains.destroy', $global->id), ownerFields($ownerA))->assertNotFound(); + + expect(RedirectDomainModel::query()->whereKey([$domainOfB->id, $global->id])->count())->toBe(2); +}); + +it('authorizes create with the owner and delete on the domain', function (): void { + OwnerPolicyFixture::$allowsUpdate = false; + $owner = VirtualAgentModel::factory()->create(); + $domain = ownerDomain($owner); + + $this->from(OWNER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownerFields($owner)]) + ->assertForbidden(); + $this->from(OWNER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + ->assertForbidden(); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']) + ->and(OwnerPolicyFixture::$asked)->toBe(2); +}); + +it('goes back only to a page on the request\'s own scheme, host and port', function (string $previous, ?string $expected): void { + $owner = VirtualAgentModel::factory()->create(); + $expected ??= route('atrium.cortex.redirect-domains.index'); + + $this->from($previous) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) + ->assertRedirect($expected); + + $domain = RedirectDomainModel::query()->sole(); + + $this->from($previous) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + ->assertRedirect($expected); +})->with([ + 'the same host' => [OWNER_HOST_PAGE, OWNER_HOST_PAGE], + 'the same host, without a query' => ['http://localhost/test-host/roster.user/1', 'http://localhost/test-host/roster.user/1'], + 'a protocol-relative path stays on the own host' => ['http://localhost//evil.test/steal', 'http://localhost//evil.test/steal'], + 'a foreign host' => ['https://evil.test/test-host/acme.account/1', null], + 'a lookalike host' => ['http://localhost.evil.test/test-host/acme.account/1', null], + 'a userinfo form' => ['http://localhost@evil.test/test-host/acme.account/1', null], + 'a scheme mismatch' => ['https://localhost/test-host/acme.account/1', null], + 'another port' => ['http://localhost:8080/test-host/acme.account/1', null], +]); + +it('falls back to the redirect-domains screen without a referrer', function (): void { + $owner = VirtualAgentModel::factory()->create(); + + $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) + ->assertRedirect(route('atrium.cortex.redirect-domains.index')); + + $domain = RedirectDomainModel::query()->sole(); + + $this->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + ->assertRedirect(route('atrium.cortex.redirect-domains.index')); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('keeps sending writes without an owner to the redirect-domains screen', function (): void { + $this->from(OWNER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai']) + ->assertRedirect(route('atrium.cortex.redirect-domains.index')); + + $domain = RedirectDomainModel::query()->sole(); + + expect($domain->owner_type)->toBeNull(); + + $this->from(OWNER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id)) + ->assertRedirect(route('atrium.cortex.redirect-domains.index')); + + expect(OwnerPolicyFixture::$asked)->toBe(0); +}); diff --git a/tests/Fixtures/OwnerPolicyFixture.php b/tests/Fixtures/OwnerPolicyFixture.php new file mode 100644 index 0000000..7e63964 --- /dev/null +++ b/tests/Fixtures/OwnerPolicyFixture.php @@ -0,0 +1,37 @@ + Date: Fri, 30 Oct 2026 00:49:34 -0400 Subject: [PATCH 09/23] 2026-10-29-2038-register-roster-redirect-domains: group 2 Composer, arch rule, test host and the no-Atrium proof Co-Authored-By: Claude Opus 5.5 --- .github/workflows/tests.yml | 37 +++++++++ composer.json | 12 ++- phpunit.without-atrium.xml | 41 ++++++++++ phpunit.xml.dist | 2 + tests/ArchTest.php | 7 ++ tests/Feature/ComposerTest.php | 63 +++++++++++++++ tests/Feature/Ui/TestHostScreenTest.php | 76 +++++++++++++++++++ tests/Pest.php | 8 ++ tests/TestCase.php | 47 ++++++++++++ tests/WithoutAtrium/WithoutAtriumTest.php | 71 +++++++++++++++++ tests/WithoutAtrium/WithoutAtriumTestCase.php | 41 ++++++++++ tests/WithoutAtrium/bootstrap.php | 51 +++++++++++++ .../Controllers/TestHostScreenController.php | 55 ++++++++++++++ workbench/app/Models/Organization.php | 19 +++++ workbench/app/Policies/OrganizationPolicy.php | 29 +++++++ workbench/app/Policies/UserPolicy.php | 29 +++++++ ...0_29_000001_create_organizations_table.php | 27 +++++++ workbench/resources/views/test-host.blade.php | 41 ++++++++++ 18 files changed, 654 insertions(+), 2 deletions(-) create mode 100644 phpunit.without-atrium.xml create mode 100644 tests/Feature/ComposerTest.php create mode 100644 tests/Feature/Ui/TestHostScreenTest.php create mode 100644 tests/WithoutAtrium/WithoutAtriumTest.php create mode 100644 tests/WithoutAtrium/WithoutAtriumTestCase.php create mode 100644 tests/WithoutAtrium/bootstrap.php create mode 100644 workbench/app/Http/Controllers/TestHostScreenController.php create mode 100644 workbench/app/Models/Organization.php create mode 100644 workbench/app/Policies/OrganizationPolicy.php create mode 100644 workbench/app/Policies/UserPolicy.php create mode 100644 workbench/database/migrations/2026_10_29_000001_create_organizations_table.php create mode 100644 workbench/resources/views/test-host.blade.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index da175b9..6deb739 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -77,3 +77,40 @@ jobs: - name: Test Suite (Windows) if: runner.os == 'Windows' run: vendor/bin/pest + + # The authoritative no-Atrium proof: Atrium is uninstalled, so no classmap or + # Composer `files` entry can reach it, as the in-process suite cannot see. + without-atrium: + runs-on: ubuntu-latest + + name: P8.5 - L13.* - without Atrium + + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Setup PHP + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2 + with: + php-version: 8.5 + extensions: dom, curl, libxml, mbstring, zip, fileinfo, sqlite, pdo_sqlite, bcmath, intl + ini-values: error_reporting=E_ALL + tools: composer:v2 + coverage: none + + - name: Remove Atrium + run: composer remove --dev refactor-circus/atrium --no-update --no-interaction + + - name: Install dependencies + run: | + composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-scripts + composer run prepare + + - name: Dump autoloader + run: composer dump-autoload + + - name: Atrium is not installed + run: test ! -e vendor/refactor-circus/atrium + + - name: Test Suite without Atrium + run: composer test:without-atrium diff --git a/composer.json b/composer.json index a10e80f..2656317 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ ], "require": { "php": "^8.5", - "refactor-circus/atrium": "dev-main", "refactor-circus/keystone": "dev-main", "laravel/ai": "^1.2", "laravel/framework": "^13.35", @@ -33,14 +32,19 @@ "pestphp/pest-plugin-laravel": "^5.0.1", "pestphp/pest-plugin-type-coverage": "^5.0.3", "phpstan/extension-installer": "^1.4.3", + "refactor-circus/atrium": "dev-main", "refactor-circus/keen": "dev-main", "refactor-circus/pennantplus": "dev-main", "refactor-circus/ringside": "dev-main", "refactor-circus/standards": "dev-main" }, "suggest": { + "refactor-circus/atrium": "Show the Cortex dashboard and its redirect-domain tab and section on other packages' screens (v0.1.0 or later, which carries the screen-extensions registry).", "refactor-circus/pennantplus": "Switch Cortex in Atrium on and off with the CortexSupportFeature Pennant feature (dev-main)." }, + "conflict": { + "refactor-circus/atrium": "<0.1.0" + }, "autoload": { "psr-4": { "RefactorCircus\\Cortex\\": "src/" @@ -90,12 +94,16 @@ "test:unit": [ "vendor/bin/pest --parallel" ], + "test:without-atrium": [ + "vendor/bin/pest --configuration=phpunit.without-atrium.xml" + ], "test": [ "@composer dump-autoload", "@analyse", "@lint:check", "@test:types", - "@test:unit" + "@test:unit", + "@test:without-atrium" ], "clear": [ "@php vendor/bin/testbench package:purge-skeleton --ansi" diff --git a/phpunit.without-atrium.xml b/phpunit.without-atrium.xml new file mode 100644 index 0000000..2b65871 --- /dev/null +++ b/phpunit.without-atrium.xml @@ -0,0 +1,41 @@ + + + + + + tests/WithoutAtrium + + + + + src + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8ab91f1..b7ffc08 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,6 +28,8 @@ tests/Modes + diff --git a/tests/ArchTest.php b/tests/ArchTest.php index c6f41d2..bdd33b1 100644 --- a/tests/ArchTest.php +++ b/tests/ArchTest.php @@ -21,6 +21,13 @@ ->expect('RefactorCircus\Cortex') ->toUseStrictTypes(); +// Atrium is suggested, not required: only src/Atrium names its classes, and +// CortexServiceProvider reaches that layer behind a class_exists() guard. +arch('only the Atrium layer uses Atrium') + ->expect('RefactorCircus\Cortex') + ->not->toUse('RefactorCircus\Atrium') + ->ignoring('RefactorCircus\Cortex\Atrium'); + arch('actions are final classes') ->expect(Arch::domainNamespaces('RefactorCircus\Cortex', CORTEX_DOMAINS, 'Actions')) ->classes() diff --git a/tests/Feature/ComposerTest.php b/tests/Feature/ComposerTest.php new file mode 100644 index 0000000..40db388 --- /dev/null +++ b/tests/Feature/ComposerTest.php @@ -0,0 +1,63 @@ + + */ +function composerManifest(): array +{ + /** @var array */ + return json_decode((string) file_get_contents(dirname(__DIR__, 2).'/composer.json'), true, flags: JSON_THROW_ON_ERROR); +} + +it('requires Keystone and no other suite package', function (): void { + $suite = array_values(array_filter( + array_keys(composerManifest()['require']), + fn (string $package): bool => str_starts_with($package, 'refactor-circus/'), + )); + + expect($suite)->toBe(['refactor-circus/keystone']); +}); + +it('suggests Atrium and needs it only for its own suite', function (): void { + $composer = composerManifest(); + + expect($composer['suggest'])->toHaveKey('refactor-circus/atrium') + ->and(trim((string) $composer['suggest']['refactor-circus/atrium']))->not->toBe('') + ->and($composer['require-dev'])->toHaveKey('refactor-circus/atrium') + ->and($composer['require'])->not->toHaveKey('refactor-circus/atrium'); +}); + +it('refuses an Atrium older than the screen-extensions registry', function (): void { + $constraint = composerManifest()['conflict']['refactor-circus/atrium'] ?? ''; + + expect($constraint)->toStartWith('<') + ->and($constraint)->toBe('<0.1.0'); +}); + +it('depends on no Roster', function (): void { + $composer = composerManifest(); + + foreach (['require', 'require-dev', 'suggest'] as $section) { + expect($composer[$section] ?? [])->not->toHaveKey('refactor-circus/roster'); + } +}); + +it('runs the no-Atrium suite after the unit suite in composer test', function (): void { + $scripts = composerManifest()['scripts']; + $test = $scripts['test']; + + expect($scripts)->toHaveKey('test:without-atrium') + ->and(implode(' ', (array) $scripts['test:without-atrium']))->toContain('phpunit.without-atrium.xml') + ->and($test)->toContain('@test:unit', '@test:without-atrium') + ->and(array_search('@test:without-atrium', $test, true))->toBeGreaterThan(array_search('@test:unit', $test, true)); +}); + +it('proves the package runs with Atrium uninstalled in CI', function (): void { + $workflow = (string) file_get_contents(dirname(__DIR__, 2).'/.github/workflows/tests.yml'); + + expect($workflow)->toContain('without-atrium:') + ->and($workflow)->toContain('composer remove --dev refactor-circus/atrium --no-update') + ->and($workflow)->toContain('composer test:without-atrium'); +}); diff --git a/tests/Feature/Ui/TestHostScreenTest.php b/tests/Feature/Ui/TestHostScreenTest.php new file mode 100644 index 0000000..52df3e2 --- /dev/null +++ b/tests/Feature/Ui/TestHostScreenTest.php @@ -0,0 +1,76 @@ + + */ +function testHostScreens(): array +{ + return [ + 'roster.organization' => ['roster.organization', fn (): Model => Organization::query()->create(['name' => 'Acme Inc'])], + 'roster.user' => ['roster.user', fn (): Model => User::query()->create(['name' => 'Ada Lovelace', 'email' => 'ada@example.com', 'password' => 'secret'])], + 'acme.account' => ['acme.account', fn (): Model => Organization::query()->create(['name' => 'Acme Account'])], + ]; +} + +it('renders the workbench screen for its key and record', function (string $key, Closure $record): void { + $model = $record(); + + $this->get(route('test-host', ['key' => $key, 'id' => $model->getKey()])) + ->assertOk() + ->assertSee($key) + ->assertSee('data-testid="test-host-content"', false) + ->assertSee((string) $model->getAttribute('name')) + ->assertDontSee('data-testid="screen-aside"', false); +})->with(testHostScreens()); + +it('declares the screen under the key in its route', function (string $key, Closure $record): void { + Atrium::screens()->tab($key, TabDefinition::make('acme.extra')->label('Extra')->view('workbench::test-host')->public()); + Atrium::screens()->tab('acme.elsewhere', TabDefinition::make('acme.other')->label('Other')->view('workbench::test-host')->public()); + + $this->get(route('test-host', ['key' => $key, 'id' => $record()->getKey()])) + ->assertOk() + ->assertSee('data-testid="tab-acme.extra"', false) + ->assertDontSee('data-testid="tab-acme.other"', false); +})->with(testHostScreens()); + +it('renders an unsaved record when no id is given', function (): void { + $this->get(route('test-host', ['key' => 'roster.organization'])) + ->assertOk() + ->assertSee('data-testid="test-host-content"', false); +}); + +it('answers 404 for an unknown record', function (): void { + $this->get(route('test-host', ['key' => 'roster.organization', 'id' => 999]))->assertNotFound(); +}); + +it('lets any signed-in user update an owner until a test denies it', function (): void { + $organization = Organization::query()->create(['name' => 'Acme Inc']); + $user = User::query()->create(['name' => 'Ada Lovelace', 'email' => 'ada@example.com', 'password' => 'secret']); + + expect(Gate::forUser($user)->allows('update', $organization))->toBeTrue() + ->and(Gate::forUser($user)->allows('update', $user))->toBeTrue() + ->and(Gate::forUser(null)->allows('update', $organization))->toBeFalse() + ->and(Gate::forUser(null)->allows('update', $user))->toBeFalse(); + + OrganizationPolicy::$deniesUpdate = true; + UserPolicy::$deniesUpdate = true; + + expect(Gate::forUser($user)->allows('update', $organization))->toBeFalse() + ->and(Gate::forUser($user)->allows('update', $user))->toBeFalse(); +}); + +it('starts every test with the owner policies allowing update', function (): void { + expect(OrganizationPolicy::$deniesUpdate)->toBeFalse() + ->and(UserPolicy::$deniesUpdate)->toBeFalse(); +}); diff --git a/tests/Pest.php b/tests/Pest.php index f0c24d4..074ef9d 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -8,12 +8,20 @@ use RefactorCircus\Cortex\Tests\PennantPlusTestCase; use RefactorCircus\Cortex\Tests\RenamedTablesTestCase; use RefactorCircus\Cortex\Tests\TestCase; +use RefactorCircus\Cortex\Tests\WithoutAtrium\WithoutAtriumTestCase; use RefactorCircus\Keystone\Testing\McpTools; +// TestCase also resets Atrium's screen extensions after every test +// (ResetsScreenExtensions), serves the workbench test host and registers the +// workbench owner policies. uses(TestCase::class)->in('ArchTest.php', 'Feature', 'Unit'); uses(PennantPlusTestCase::class)->in('Modes/PennantPlus'); uses(RenamedTablesTestCase::class)->in('Modes/RenamedTables'); +// Run only by phpunit.without-atrium.xml (`composer test:without-atrium`), +// with Atrium's autoload prefix removed. +uses(WithoutAtriumTestCase::class)->in('WithoutAtrium'); + /** * Call a catalog tool the way a client reaches it: every Cortex tool sits * behind ToolSearch, so the call goes through the execute_tools entry point, diff --git a/tests/TestCase.php b/tests/TestCase.php index 8234e07..3a095ae 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,14 +4,43 @@ namespace RefactorCircus\Cortex\Tests; +use Illuminate\Routing\Router; +use Illuminate\Support\Facades\Gate; +use Illuminate\Support\Facades\View; use Laravel\Ai\AiServiceProvider; use Laravel\Mcp\Server\McpServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; use RefactorCircus\Atrium\AtriumServiceProvider; +use RefactorCircus\Atrium\Testing\ResetsScreenExtensions; use RefactorCircus\Cortex\CortexServiceProvider; +use Workbench\App\Http\Controllers\TestHostScreenController; +use Workbench\App\Models\Organization; +use Workbench\App\Models\User; +use Workbench\App\Policies\OrganizationPolicy; +use Workbench\App\Policies\UserPolicy; abstract class TestCase extends Orchestra { + use ResetsScreenExtensions; + + protected function setUp(): void + { + parent::setUp(); + + // The host's own owner policies, which the bundled + // RedirectDomainPolicy asks `update` of for owned domains. + Gate::policy(Organization::class, OrganizationPolicy::class); + Gate::policy(User::class, UserPolicy::class); + } + + protected function tearDown(): void + { + OrganizationPolicy::$deniesUpdate = false; + UserPolicy::$deniesUpdate = false; + + parent::tearDown(); + } + protected function getPackageProviders($app): array { return [ @@ -35,8 +64,26 @@ protected function defineEnvironment($app): void $app['config']->set('cortex.cache.store', 'array'); } + /** + * The workbench test host: another package's screen, which Cortex + * extends in its tests without depending on that package. + * + * @param Router $router + */ + protected function defineRoutes($router): void + { + View::addNamespace('workbench', dirname(__DIR__).'/workbench/resources/views'); + + $router->middleware('web') + ->get('test-host/{key}/{id?}', TestHostScreenController::class) + ->name('test-host'); + } + protected function defineDatabaseMigrations(): void { + // The users table, for the workbench User the test host shows. + $this->loadLaravelMigrations(); $this->loadMigrationsFrom(dirname(__DIR__).'/database/migrations'); + $this->loadMigrationsFrom(dirname(__DIR__).'/workbench/database/migrations'); } } diff --git a/tests/WithoutAtrium/WithoutAtriumTest.php b/tests/WithoutAtrium/WithoutAtriumTest.php new file mode 100644 index 0000000..593bd8f --- /dev/null +++ b/tests/WithoutAtrium/WithoutAtriumTest.php @@ -0,0 +1,71 @@ +not->toBeEmpty(); + + foreach (ClassLoader::getRegisteredLoaders() as $loader) { + expect($loader->getPrefixesPsr4())->not->toHaveKey('RefactorCircus\\Atrium\\') + ->and($loader->findFile('RefactorCircus\\Atrium\\Atrium'))->toBeFalse(); + } +}); + +it('cannot load an Atrium class', function (): void { + expect(class_exists('RefactorCircus\\Atrium\\Atrium'))->toBeFalse() + ->and(class_exists('RefactorCircus\\Atrium\\AtriumServiceProvider'))->toBeFalse(); +}); + +it('boots Cortex with the default redirect-domain screen map and registers nothing', function (): void { + expect(app()->getProvider(CortexServiceProvider::class))->not->toBeNull() + ->and(config('cortex.atrium.redirect_domains.screens'))->toBe([ + 'roster.organization' => 'tab', + 'roster.user' => 'aside', + ]); +}); + +it('serves no Atrium route', function (): void { + $atrium = array_values(array_filter( + array_keys(Route::getRoutes()->getRoutesByName()), + fn (string $name): bool => str_starts_with($name, 'atrium.'), + )); + + expect($atrium)->toBe([]); +}); + +it('serves the redirect-domain JSON API', function (): void { + $this->getJson(route('cortex.redirect-domains.index'))->assertOk(); + + $this->postJson(route('cortex.redirect-domains.store'), ['domain' => 'https://claude.ai/callback']) + ->assertCreated() + ->assertJsonPath('data.domain', 'https://claude.ai'); + + expect(RedirectDomainModel::query()->where('domain', 'https://claude.ai')->exists())->toBeTrue(); +}); + +it('answers MCP', function (): void { + mcpTool(ListRedirectDomainsTool::class)->assertOk(); +}); + +it('creates a virtual agent over the JSON API', function (): void { + $this->postJson(route('cortex.virtual-agents.store'), [ + 'name' => 'Coordinator', + 'slug' => 'coordinator', + 'instructions' => 'Coordinate.', + 'provider' => 'anthropic', + 'model' => 'claude-sonnet-5', + ]) + ->assertCreated() + ->assertJsonPath('data.slug', 'coordinator'); + + expect(VirtualAgentModel::query()->where('slug', 'coordinator')->exists())->toBeTrue(); +}); diff --git a/tests/WithoutAtrium/WithoutAtriumTestCase.php b/tests/WithoutAtrium/WithoutAtriumTestCase.php new file mode 100644 index 0000000..10e9c0d --- /dev/null +++ b/tests/WithoutAtrium/WithoutAtriumTestCase.php @@ -0,0 +1,41 @@ +set('app.key', 'base64:'.base64_encode(str_repeat('a', 32))); + $app['config']->set('database.default', 'testing'); + $app['config']->set('database.connections.testing.foreign_key_constraints', true); + $app['config']->set('cache.default', 'array'); + $app['config']->set('cortex.cache.store', 'array'); + } + + protected function defineDatabaseMigrations(): void + { + $this->loadMigrationsFrom(dirname(__DIR__, 2).'/database/migrations'); + } +} diff --git a/tests/WithoutAtrium/bootstrap.php b/tests/WithoutAtrium/bootstrap.php new file mode 100644 index 0000000..e755ede --- /dev/null +++ b/tests/WithoutAtrium/bootstrap.php @@ -0,0 +1,51 @@ +isClassMapAuthoritative() || $loader->getApcuPrefix() !== null) { + throw new RuntimeException('The WithoutAtrium suite cannot run with an authoritative classmap or APCu autoloading: run `composer dump-autoload` without --classmap-authoritative or --apcu.'); + } + + foreach (array_keys($loader->getClassMap()) as $class) { + if (str_starts_with($class, $prefix)) { + throw new RuntimeException("[{$class}] is in Composer's classmap: run `composer dump-autoload` without --optimize."); + } + } + + // ClassLoader can add a prefix but not remove one. + (function (string $prefix): void { + unset($this->prefixDirsPsr4[$prefix], $this->prefixLengthsPsr4[$prefix[0]][$prefix]); + })->call($loader, $prefix); + + if (array_key_exists($prefix, $loader->getPrefixesPsr4()) || $loader->findFile($probe) !== false) { + throw new RuntimeException("Composer still resolves [{$probe}] after removing the [{$prefix}] prefix."); + } +} diff --git a/workbench/app/Http/Controllers/TestHostScreenController.php b/workbench/app/Http/Controllers/TestHostScreenController.php new file mode 100644 index 0000000..71137da --- /dev/null +++ b/workbench/app/Http/Controllers/TestHostScreenController.php @@ -0,0 +1,55 @@ +user())->allows('view', $record), 403); + + $screen = Screen::standard($key, Screen::DETAIL) + ->record($record) + ->access(fn (string $permission, Request $request, ?Model $record): bool => Gate::forUser($request->user()) + ->allows($permission, $record === null ? [] : [$record])); + + return view('workbench::test-host', [ + 'resolved' => $extensions->resolve($screen, $request), + ]); + } + + private static function record(string $key, ?string $id): Model + { + $model = $key === 'roster.user' ? new User : new Organization; + + return $id === null ? $model : $model->newQuery()->findOrFail($id); + } +} diff --git a/workbench/app/Models/Organization.php b/workbench/app/Models/Organization.php new file mode 100644 index 0000000..eba7b73 --- /dev/null +++ b/workbench/app/Models/Organization.php @@ -0,0 +1,19 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('organizations'); + } +}; diff --git a/workbench/resources/views/test-host.blade.php b/workbench/resources/views/test-host.blade.php new file mode 100644 index 0000000..280c41e --- /dev/null +++ b/workbench/resources/views/test-host.blade.php @@ -0,0 +1,41 @@ +{{-- + The workbench test host (TestHostScreenController), laid out as Atrium + lays out its own screens: `header.actions` always renders in the page + header's actions; an open registered tab's panel replaces the page + content; otherwise `before` and `after` render around the content, and + `aside` gets a right-hand column only when it has visible sections. +--}} +@php($screen = $resolved->screen) +@php($panelOpen = $resolved->openRegisteredTab !== null) +@php($aside = ! $panelOpen && $resolved->sections('aside') !== []) + + + + + Host action + + + + + + + @if ($panelOpen) + + @else + + +
$aside])> + +

{{ $screen->record?->getAttribute('name') ?? 'New record' }}

+
+ + @if ($aside) + + @endif +
+ + + @endif +
From 6b56c5dcfa566aabd77f094879f20d5f3832de91 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:52:02 -0400 Subject: [PATCH 10/23] 2026-10-29-2038-register-roster-redirect-domains: group 1 Owner-decided policy and owner-aware UI controller Prefix the controller test's global helpers so they cannot clash with other test files loaded in the same Pest process. Co-Authored-By: Claude Opus 5.5 --- .../Ui/RedirectDomainOwnerControllerTest.php | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php b/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php index 588d45e..e87f04a 100644 --- a/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php +++ b/tests/Feature/Ui/RedirectDomainOwnerControllerTest.php @@ -43,24 +43,24 @@ * * @return array{owner_type: string, owner_id: string} */ -function ownerFields(Model $owner): array +function ownerControllerFields(Model $owner): array { return ['owner_type' => $owner->getMorphClass(), 'owner_id' => (string) $owner->getKey()]; } -function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomainModel +function ownerControllerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomainModel { return app(CreateRedirectDomainAction::class)->execute(new CreateRedirectDomainData(domain: $domain), $owner); } -const OWNER_HOST_PAGE = 'http://localhost/test-host/acme.account/1?tab=cortex.mcp'; +const OWNER_CONTROLLER_HOST_PAGE = 'http://localhost/test-host/acme.account/1?tab=cortex.mcp'; it('stores a domain for an owner named by its class and goes back to the host page', function (): void { $owner = VirtualAgentModel::factory()->create(); - $this->from(OWNER_HOST_PAGE) - ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) - ->assertRedirect(OWNER_HOST_PAGE) + $this->from(OWNER_CONTROLLER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerControllerFields($owner)]) + ->assertRedirect(OWNER_CONTROLLER_HOST_PAGE) ->assertSessionHas('status'); $stored = RedirectDomainModel::query()->sole(); @@ -72,11 +72,11 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('removes an owner\'s domain and goes back to the host page', function (): void { $owner = VirtualAgentModel::factory()->create(); - $domain = ownerDomain($owner); + $domain = ownerControllerDomain($owner); - $this->from(OWNER_HOST_PAGE) - ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) - ->assertRedirect(OWNER_HOST_PAGE) + $this->from(OWNER_CONTROLLER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerControllerFields($owner)) + ->assertRedirect(OWNER_CONTROLLER_HOST_PAGE) ->assertSessionHas('status'); expect(RedirectDomainModel::query()->exists())->toBeFalse(); @@ -86,27 +86,27 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai Relation::morphMap(['owner-agent' => VirtualAgentModel::class]); $owner = VirtualAgentModel::factory()->create(); - expect(ownerFields($owner)['owner_type'])->toBe('owner-agent'); + expect(ownerControllerFields($owner)['owner_type'])->toBe('owner-agent'); - $this->from(OWNER_HOST_PAGE) - ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) - ->assertRedirect(OWNER_HOST_PAGE); + $this->from(OWNER_CONTROLLER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerControllerFields($owner)]) + ->assertRedirect(OWNER_CONTROLLER_HOST_PAGE); $stored = RedirectDomainModel::query()->sole(); expect($stored->owner_type)->toBe('owner-agent') ->and($stored->owner_id)->toBe((string) $owner->getKey()); - $this->from(OWNER_HOST_PAGE) - ->delete(route('atrium.cortex.redirect-domains.destroy', $stored->id), ownerFields($owner)) - ->assertRedirect(OWNER_HOST_PAGE); + $this->from(OWNER_CONTROLLER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $stored->id), ownerControllerFields($owner)) + ->assertRedirect(OWNER_CONTROLLER_HOST_PAGE); expect(RedirectDomainModel::query()->exists())->toBeFalse(); }); it('refuses owner types RedirectDomains::owner() does not resolve, writing nothing', function (string $type): void { $owner = VirtualAgentModel::factory()->create(); - $domain = ownerDomain($owner); + $domain = ownerControllerDomain($owner); $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', 'owner_type' => $type, 'owner_id' => '1']) ->assertNotFound(); @@ -124,7 +124,7 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('refuses a malformed owner id, writing nothing', function (mixed $id, int $status): void { $owner = VirtualAgentModel::factory()->create(); - $domain = ownerDomain($owner); + $domain = ownerControllerDomain($owner); $this->postJson(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', 'owner_type' => VirtualAgentModel::class, 'owner_id' => $id]) ->assertStatus($status); @@ -140,7 +140,7 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('answers 422 on the missing field for a partial owner, writing nothing', function (array $fields, string $missing): void { $owner = VirtualAgentModel::factory()->create(); - $domain = ownerDomain($owner); + $domain = ownerControllerDomain($owner); $fields = array_map(fn (string $value): string => str_replace(':id', (string) $owner->getKey(), $value), $fields); $this->postJson(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...$fields]) @@ -151,9 +151,9 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai ->assertJsonValidationErrors($missing); // A form post gets the same error back on the page it came from. - $this->from(OWNER_HOST_PAGE) + $this->from(OWNER_CONTROLLER_HOST_PAGE) ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...$fields]) - ->assertRedirect(OWNER_HOST_PAGE) + ->assertRedirect(OWNER_CONTROLLER_HOST_PAGE) ->assertSessionHasErrors($missing); expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); @@ -166,7 +166,7 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('answers 404 for an owner that does not exist', function (): void { $owner = VirtualAgentModel::factory()->create(); - $domain = ownerDomain($owner); + $domain = ownerControllerDomain($owner); $missing = ['owner_type' => VirtualAgentModel::class, 'owner_id' => '01JZZZZZZZZZZZZZZZZZZZZZZZ']; $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...$missing])->assertNotFound(); @@ -178,11 +178,11 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('finds the domain among the named owner\'s only', function (): void { $ownerA = VirtualAgentModel::factory()->create(); $ownerB = VirtualAgentModel::factory()->create(); - $domainOfB = ownerDomain($ownerB); - $global = ownerDomain(null, 'perplexity.ai'); + $domainOfB = ownerControllerDomain($ownerB); + $global = ownerControllerDomain(null, 'perplexity.ai'); - $this->delete(route('atrium.cortex.redirect-domains.destroy', $domainOfB->id), ownerFields($ownerA))->assertNotFound(); - $this->delete(route('atrium.cortex.redirect-domains.destroy', $global->id), ownerFields($ownerA))->assertNotFound(); + $this->delete(route('atrium.cortex.redirect-domains.destroy', $domainOfB->id), ownerControllerFields($ownerA))->assertNotFound(); + $this->delete(route('atrium.cortex.redirect-domains.destroy', $global->id), ownerControllerFields($ownerA))->assertNotFound(); expect(RedirectDomainModel::query()->whereKey([$domainOfB->id, $global->id])->count())->toBe(2); }); @@ -190,13 +190,13 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('authorizes create with the owner and delete on the domain', function (): void { OwnerPolicyFixture::$allowsUpdate = false; $owner = VirtualAgentModel::factory()->create(); - $domain = ownerDomain($owner); + $domain = ownerControllerDomain($owner); - $this->from(OWNER_HOST_PAGE) - ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownerFields($owner)]) + $this->from(OWNER_CONTROLLER_HOST_PAGE) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownerControllerFields($owner)]) ->assertForbidden(); - $this->from(OWNER_HOST_PAGE) - ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + $this->from(OWNER_CONTROLLER_HOST_PAGE) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerControllerFields($owner)) ->assertForbidden(); expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']) @@ -208,16 +208,16 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai $expected ??= route('atrium.cortex.redirect-domains.index'); $this->from($previous) - ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerControllerFields($owner)]) ->assertRedirect($expected); $domain = RedirectDomainModel::query()->sole(); $this->from($previous) - ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerControllerFields($owner)) ->assertRedirect($expected); })->with([ - 'the same host' => [OWNER_HOST_PAGE, OWNER_HOST_PAGE], + 'the same host' => [OWNER_CONTROLLER_HOST_PAGE, OWNER_CONTROLLER_HOST_PAGE], 'the same host, without a query' => ['http://localhost/test-host/roster.user/1', 'http://localhost/test-host/roster.user/1'], 'a protocol-relative path stays on the own host' => ['http://localhost//evil.test/steal', 'http://localhost//evil.test/steal'], 'a foreign host' => ['https://evil.test/test-host/acme.account/1', null], @@ -230,19 +230,19 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai it('falls back to the redirect-domains screen without a referrer', function (): void { $owner = VirtualAgentModel::factory()->create(); - $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerFields($owner)]) + $this->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownerControllerFields($owner)]) ->assertRedirect(route('atrium.cortex.redirect-domains.index')); $domain = RedirectDomainModel::query()->sole(); - $this->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerFields($owner)) + $this->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownerControllerFields($owner)) ->assertRedirect(route('atrium.cortex.redirect-domains.index')); expect(RedirectDomainModel::query()->exists())->toBeFalse(); }); it('keeps sending writes without an owner to the redirect-domains screen', function (): void { - $this->from(OWNER_HOST_PAGE) + $this->from(OWNER_CONTROLLER_HOST_PAGE) ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai']) ->assertRedirect(route('atrium.cortex.redirect-domains.index')); @@ -250,7 +250,7 @@ function ownerDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomai expect($domain->owner_type)->toBeNull(); - $this->from(OWNER_HOST_PAGE) + $this->from(OWNER_CONTROLLER_HOST_PAGE) ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id)) ->assertRedirect(route('atrium.cortex.redirect-domains.index')); From 361dd941f7eeb2484dbe672d79018e7de9495bdd Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:55:55 -0400 Subject: [PATCH 11/23] Integrate wave 1: tick groups 1 and 2 Co-Authored-By: Claude Opus 5.5 --- .../build.md | 99 +++++++++++++++++++ .../tasks.md | 22 ++--- 2 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/build.md diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/build.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/build.md new file mode 100644 index 0000000..c666906 --- /dev/null +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/build.md @@ -0,0 +1,99 @@ +# Build: Register Roster redirect domains + +## Group 1 + +Owner-decided policy and owner-aware UI controller (criteria 7, 8, 14). Branch `ring-master/2026-10-29-2038-register-roster-redirect-domains--g1`, commits `755914b` and `6b56c5d` (retry). + +### Files + +- `src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php`: for owned domains, `create` and `delete` need a signed-in user who may `update` the owner. A guest is refused, and so is a domain whose owner row is gone. Null-owner domains and `viewAny` are unchanged. The docblock says the rule covers the UI, JSON API and MCP, and that a class set in `cortex.policies` replaces it. +- `src/Atrium/Http/Controllers/RedirectDomainUiController.php`: `store` and `destroy` take optional `owner_type`/`owner_id` and resolve them with `RedirectDomains::owner()`. Both fields or neither is accepted; one alone is a validation error on the missing field. `store` authorizes `create` with `[$owner]`. `destroy` finds the domain with `ownedBy($owner)->whereKey()->firstOrFail()` and authorizes `delete`. After an owned write the controller redirects to the path and query of `url()->previous()`, but only when its scheme, host and port match the request's exactly; otherwise, and when there is no referrer, it goes to `atrium.cortex.redirect-domains.index`. Without an owner nothing changes. +- `tests/Fixtures/OwnerPolicyFixture.php`: an owner policy with a static `update` switch (it allows guests too) and a call counter. Tests register it with `Gate::policy()` for `VirtualAgentModel` and reset it after each test. +- `tests/Feature/OwnedRedirectDomainPolicyTest.php`: covers a guest, a user without `update`, a user with it, the null-owner path (guest and user dataset, owner policy never asked) and a deleted owner. Each case runs over the Gate, the JSON API and MCP. +- `tests/Feature/Ui/RedirectDomainOwnerControllerTest.php`: covers: + - owner by FQCN and by morph alias + - owner-type rejections: `stdClass`, `Collection`, the abstract `Model`, a missing class, an unknown alias + - malformed `owner_id`: array, too long, unknown key + - partial owner, four cases + - unknown owner + - owner-scoped destroy (another owner's domain and a global domain both answer 404) + - authorization through the owner policy + - the redirect dataset: same host with and without a query, a protocol-relative path kept on the own host, foreign host, lookalike `localhost.evil.test`, userinfo `localhost@evil.test`, scheme mismatch, another port + - a missing referrer + - writes without an owner still going to the index + + On the retry, its global helpers were renamed to `ownerControllerFields()`, `ownerControllerDomain()` and `OWNER_CONTROLLER_HOST_PAGE`. Pest loads every test file into one process, so the generic names could have clashed with group 3's `OwnedRedirectDomainsTest`. +- `tests/Feature/RedirectDomainsTest.php` (criterion 14): `manages domains over the json api` and `creates and deletes domains over mcp with parity to the http payload` now sign in a `GenericUser` before their owned calls. Their assertions are unchanged. + +### Tests + +Following the prompt, the suite was not run here; the gate runs it. Pint passes on every changed file, and PHPStan passes on both changed `src` files. + +### Deviations + +- **Guest refusal status over JSON (criterion 8).** The spec says a guest's owned JSON `POST`/`DELETE` answer 403. The `http/authorization` standard and Cortex's `CLAUDE.md` say a refused guest gets 401 and a refused signed-in user 403, and Keystone's request base does exactly that. So the test asserts 401 for the guest and 403 for the signed-in user without `update`. MCP refusals are `Unauthorized.` in both cases. +- **Partial owner "answers 422" (criterion 7).** This is a validation error. JSON requests get 422 with the error on the missing field, which the tests assert. A form post gets Laravel's usual redirect back to the page with the error in the session, the same as criterion 6's `domain` validation; the tests assert that too. +- **Owner check through `Gate::forUser($user)->allows('update', $owner)`** instead of `$user->can('update', $owner)`. It gives the same answer for Laravel users and also works for an `Authenticatable` without `Authorizable`, such as `GenericUser`, which the tests use. It is also the form the `http/authorization` standard shows for deferring to another model's policy. +- **Owner validation rules in the controller.** The controller validates the owner with `ownerRules()` plus `required_with:owner_id` on `owner_type`. The JSON request's `ownerRules()` is protected, and on its own it does not reject an `owner_id` sent without `owner_type`, which criterion 7 requires. The JSON API's own rules are unchanged. +- **Test owner model.** The tests use `VirtualAgentModel` as the owner with `OwnerPolicyFixture` as its policy. They do not use the workbench `Organization`/`User` from group 2, which is being built at the same time. + +## Group 2 + +Composer, arch rule, test host and the no-Atrium proof (criteria 9, 14, 15, 16, 17). Branch `ring-master/2026-10-29-2038-register-roster-redirect-domains--g2`, commit `2c25a5a`. + +### Files + +- `composer.json`: `refactor-circus/atrium` moves from `require` to `require-dev` and is added to `suggest` with a description. A new `conflict` sets `"refactor-circus/atrium": "<0.1.0"`. A new `test:without-atrium` script runs `vendor/bin/pest --configuration=phpunit.without-atrium.xml`, and `composer test` calls it right after `@test:unit`. Keystone is the only suite package left in `require`. +- `composer.local.json` (gitignored, not committed): the same changes were copied in by hand. Its Atrium path repository now points at `../Atrium--2026-10-29-2037-screen-extensions-registry` with the version `dev-main`. It was not regenerated. +- `tests/ArchTest.php`: adds `arch('only the Atrium layer uses Atrium')`, worded exactly as criterion 16. It covers only `src/`, because Pest's arch layer resolves `RefactorCircus\Cortex` to that PSR-4 prefix and not to `RefactorCircus\Cortex\Tests`. +- `tests/TestCase.php` (criterion 14): + - uses Atrium's `ResetsScreenExtensions` + - registers `OrganizationPolicy` and `UserPolicy` with `Gate::policy()` in `setUp()`, and resets their `$deniesUpdate` flags in `tearDown()` + - `defineRoutes()` adds the `workbench` view namespace and the route `GET test-host/{key}/{id?}`, named `test-host`, with `web` middleware + - `defineDatabaseMigrations()` also loads Testbench's Laravel migrations (the users table for the workbench `User`) and `workbench/database/migrations` +- `tests/Pest.php` (criterion 14): binds `WithoutAtriumTestCase` to `tests/WithoutAtrium`, and comments on what `TestCase` now carries. +- `workbench/app/Http/Controllers/TestHostScreenController.php`: a single invokable controller. It first authorizes `view` on the record through the Gate, then declares `Screen::standard($key, Screen::DETAIL)->record($record)` with a Gate-based `access()`, resolves it with `ScreenExtensions`, and renders `workbench::test-host`. For `roster.user` the record is the workbench `User`; for any other key it is an `Organization`. Without an id, the record is an unsaved model of that class, for criterion 6's unsaved-record case. An unknown id answers 404. +- `workbench/app/Models/Organization.php` and `workbench/database/migrations/2026_10_29_000001_create_organizations_table.php`: the owner model, with no morph alias, so its type is its class name. +- `workbench/app/Policies/OrganizationPolicy.php` and `UserPolicy.php`: `view` allows anyone. `update` allows any signed-in user unless the static `$deniesUpdate` is set. +- `workbench/resources/views/test-host.blade.php`: laid out per Atrium criterion 15, the same way as Atrium's `settings/show`: + - `header.actions` renders in the page header's actions, after a host badge (`data-testid="host-action"`) + - next comes `screen-tabs` + - an open registered tab's `screen-tab-panel` replaces the content + - otherwise `before` renders, then the content (`data-testid="test-host-content"`), then `after` + - `aside` gets a right-hand column (`data-testid="screen-aside"`) only when it has visible sections +- `phpunit.without-atrium.xml`: runs only `tests/WithoutAtrium`, in file order (`executionOrder="default"`), with `tests/WithoutAtrium/bootstrap.php`. +- `tests/WithoutAtrium/bootstrap.php`: loads Composer's autoloader and removes the `RefactorCircus\Atrium\` PSR-4 prefix from every registered `ClassLoader`. It throws if: + - an Atrium class or interface is already loaded + - a loader is classmap-authoritative or uses APCu + - any Atrium class is in a classmap + - the prefix is still listed, or `findFile('RefactorCircus\Atrium\Atrium')` still resolves +- `tests/WithoutAtrium/WithoutAtriumTestCase.php`: Testbench with the Ai, Mcp and Cortex providers only, and the same pinned environment as `TestCase`. +- `tests/WithoutAtrium/WithoutAtriumTest.php`: criterion 17's assertions, with the PSR-4 prefix check first. The others: `class_exists('RefactorCircus\Atrium\Atrium')` is false; Cortex boots with the default `redirect_domains.screens` map; no `atrium.` route exists; the JSON index answers 200 and store creates a domain; `ListRedirectDomainsTool` answers; a virtual agent is created over the JSON API. +- `phpunit.xml.dist`: a comment saying `tests/WithoutAtrium` runs only from `phpunit.without-atrium.xml`. No default suite includes that folder. +- `.github/workflows/tests.yml`: a new `without-atrium` job (ubuntu, PHP 8.5). It runs `composer remove --dev refactor-circus/atrium --no-update`, installs, checks that `vendor/refactor-circus/atrium` is absent, and runs `composer test:without-atrium`. +- `tests/Feature/ComposerTest.php` covers: + - `require` has no suite package but Keystone + - Atrium is in `suggest` (with a description) and in `require-dev`, not in `require` + - the conflict starts with `<` and is `<0.1.0` + - there is no `refactor-circus/roster` + - `composer test` runs `@test:without-atrium` after `@test:unit` + - the CI workflow has the `without-atrium` job +- `tests/Feature/Ui/TestHostScreenTest.php` (outside the group's file list, required by task 2.1), a smoke test: + - the host renders for `roster.organization`, `roster.user` and `acme.account` without the aside landmark + - a tab registered for the key appears there and not for another key + - an unsaved record renders, and an unknown id answers 404 + - the owner policies allow a signed-in user, deny a guest, and deny when the flag is set + - the flags are reset for the next test + +### Tests + +Following the prompt, the suite was not run here; the gate runs it. Pint passes on every changed PHP file, and `composer validate` passes. + +On the retry, all of `2c25a5a` was checked against the retry prompt: the conflict is exactly `<0.1.0`, `composer.local.json` mirrors it by hand, and the Atrium API it uses exists on the registry branch (`Screen::standard`, `ResolvedScreen::$openRegisteredTab`, `sections()`, `ResetsScreenExtensions`'s `setUp`/`tearDown` hooks). Nothing outside `src/Atrium` names Atrium, so the new arch rule holds. Pint and `composer validate` pass again. Nothing needed changing, so the retry adds no commit. + +### Deviations + +- **Conflict constraint is `<0.1.0`, not `<1.0.0`.** The spec says to use `<1.0.0` only when no Atrium release with the registry is known. The group prompt says Atrium's first release, v0.1.0, carries the registry, and Atrium's CHANGELOG has a `v0.1.0` section. `dev-main` installs are unaffected, because Composer never matches a dev branch against `<0.1.0`. Record this in the PR. +- **`cortex.atrium.redirect_domains.screens` comes from group 3.** The WithoutAtrium assertion that Cortex boots with the default map fails until group 3 adds the config key. The default `vendor/bin/pest` run does not include that suite; `composer test` does. +- **ResetsScreenExtensions is on `TestCase` rather than in `Pest.php`'s `uses()`.** Pest checks `class_exists`/`trait_exists` for every `uses()` entry when it loads `Pest.php`, which happens before the WithoutAtrium bootstrap. With the trait on the class, every subclass gets it (PennantPlus and RenamedTables modes too). Loading `Pest.php` still declares the trait itself, but no Atrium class or interface; the bootstrap refuses to run if one has been loaded. +- **Users table from `loadLaravelMigrations()`.** The workbench `User` needs a users table. A workbench migration for it would clash with the users table Testbench's skeleton already creates for `composer serve`. diff --git a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md index ab255ec..779b530 100644 --- a/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md +++ b/docs/agent/specs/2026-10-29-2038-register-roster-redirect-domains/tasks.md @@ -6,11 +6,11 @@ depends on: none files: src/Domains/RedirectDomain/Policies/RedirectDomainPolicy.php, src/Atrium/Http/Controllers/RedirectDomainUiController.php, tests/Feature/OwnedRedirectDomainPolicyTest.php, tests/Feature/Ui/RedirectDomainOwnerControllerTest.php, tests/Feature/RedirectDomainsTest.php, tests/Fixtures/OwnerPolicyFixture.php criteria: 7, 8, 14 -- [ ] 1.1 Write tests: OwnedRedirectDomainPolicyTest (guest, user without owner update, user with it, null-owner unchanged, deleted owner, over JSON, MCP and Gate) and RedirectDomainOwnerControllerTest (owner types, partial owner, unknown owner, owner-scoped destroy, same-origin redirect and the lookalike, userinfo, scheme-mismatch and missing-referrer fallbacks) per criteria 7 and 8. -- [ ] 1.2 Change RedirectDomainPolicy create and delete for owned domains to `$user !== null && $user->can('update', $owner)` (deleted owner denied, null owner unchanged) and update its docblock. -- [ ] 1.3 Add optional owner_type/owner_id to RedirectDomainUiController store and destroy (ownerRules validation, RedirectDomains::owner(), ownedBy scope, create/delete authorization, same-origin url()->previous() else atrium.cortex.redirect-domains.index). -- [ ] 1.4 Sign in a user before the owned calls in RedirectDomainsTest `manages domains over the json api` and `creates and deletes domains over mcp with parity to the http payload` only, leaving their assertions unchanged. -- [ ] 1.5 Run vendor/bin/pest; all green +- [x] 1.1 Write tests: OwnedRedirectDomainPolicyTest (guest, user without owner update, user with it, null-owner unchanged, deleted owner, over JSON, MCP and Gate) and RedirectDomainOwnerControllerTest (owner types, partial owner, unknown owner, owner-scoped destroy, same-origin redirect and the lookalike, userinfo, scheme-mismatch and missing-referrer fallbacks) per criteria 7 and 8. +- [x] 1.2 Change RedirectDomainPolicy create and delete for owned domains to `$user !== null && $user->can('update', $owner)` (deleted owner denied, null owner unchanged) and update its docblock. +- [x] 1.3 Add optional owner_type/owner_id to RedirectDomainUiController store and destroy (ownerRules validation, RedirectDomains::owner(), ownedBy scope, create/delete authorization, same-origin url()->previous() else atrium.cortex.redirect-domains.index). +- [x] 1.4 Sign in a user before the owned calls in RedirectDomainsTest `manages domains over the json api` and `creates and deletes domains over mcp with parity to the http payload` only, leaving their assertions unchanged. +- [x] 1.5 Run vendor/bin/pest; all green ## Group 2: Composer, arch rule, test host and the no-Atrium proof package: Cortex @@ -18,12 +18,12 @@ depends on: none files: composer.json, tests/ArchTest.php, tests/TestCase.php, tests/Pest.php, tests/Feature/ComposerTest.php, workbench/app/Http/Controllers/TestHostScreenController.php, workbench/app/Models/Organization.php, workbench/app/Policies/OrganizationPolicy.php, workbench/app/Policies/UserPolicy.php, workbench/database/migrations/, workbench/resources/views/test-host.blade.php, phpunit.xml.dist, phpunit.without-atrium.xml, tests/WithoutAtrium/, .github/workflows/tests.yml criteria: 9, 14, 15, 16, 17 -- [ ] 2.1 Write tests: ComposerTest (require only keystone among refactor-circus, atrium in suggest and require-dev, atrium conflict starting with `<`, no roster), the WithoutAtrium suite assertions of criterion 17, and a test-host smoke test that the workbench screen renders for roster.organization, roster.user and acme.account. -- [ ] 2.2 Move refactor-circus/atrium from require to require-dev, add it to suggest with a description, and add a conflict on Atrium older than the screen-registry release (`<1.0.0` if Atrium is untagged, recorded in the PR). -- [ ] 2.3 Add the arch rule `only the Atrium layer uses Atrium` to tests/ArchTest.php. -- [ ] 2.4 Build the workbench test host (TestHostScreenController, Organization model and migration, OrganizationPolicy and UserPolicy with a deny flag, test-host view with screen-tabs, screen-tab-panel and screen-sections) and wire it plus ResetsScreenExtensions into tests/TestCase.php and tests/Pest.php. -- [ ] 2.5 Add phpunit.without-atrium.xml, tests/WithoutAtrium/bootstrap.php (removes the Atrium PSR-4 prefix and throws if findFile still resolves) and WithoutAtriumTestCase, exclude it from phpunit.xml.dist, add the `test:without-atrium` composer script called by `composer test` after `@test:unit`, and add the `without-atrium` CI job. -- [ ] 2.6 Run vendor/bin/pest; all green +- [x] 2.1 Write tests: ComposerTest (require only keystone among refactor-circus, atrium in suggest and require-dev, atrium conflict starting with `<`, no roster), the WithoutAtrium suite assertions of criterion 17, and a test-host smoke test that the workbench screen renders for roster.organization, roster.user and acme.account. +- [x] 2.2 Move refactor-circus/atrium from require to require-dev, add it to suggest with a description, and add a conflict on Atrium older than the screen-registry release (`<1.0.0` if Atrium is untagged, recorded in the PR). +- [x] 2.3 Add the arch rule `only the Atrium layer uses Atrium` to tests/ArchTest.php. +- [x] 2.4 Build the workbench test host (TestHostScreenController, Organization model and migration, OrganizationPolicy and UserPolicy with a deny flag, test-host view with screen-tabs, screen-tab-panel and screen-sections) and wire it plus ResetsScreenExtensions into tests/TestCase.php and tests/Pest.php. +- [x] 2.5 Add phpunit.without-atrium.xml, tests/WithoutAtrium/bootstrap.php (removes the Atrium PSR-4 prefix and throws if findFile still resolves) and WithoutAtriumTestCase, exclude it from phpunit.xml.dist, add the `test:without-atrium` composer script called by `composer test` after `@test:unit`, and add the `without-atrium` CI job. +- [x] 2.6 Run vendor/bin/pest; all green ## Group 3: Redirect domains on other packages' screens package: Cortex From 2f4960799639d1b4a8297ecc4771d52d4d429e98 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Fri, 30 Oct 2026 01:07:59 -0400 Subject: [PATCH 12/23] 2026-10-29-2038-register-roster-redirect-domains: group 3 Redirect domains on other packages' screens Co-Authored-By: Claude Opus 5.5 --- config/cortex.php | 30 ++ docs/agent/standards-feedback.md | 1 + lang/en/cortex.php | 5 + .../ui/screens/redirect-domains.blade.php | 57 +++ src/Atrium/ScreenRegistrations.php | 190 ++++++++++ src/CortexServiceProvider.php | 23 +- tests/Feature/NoRosterReferenceTest.php | 29 ++ tests/Feature/Ui/OwnedRedirectDomainsTest.php | 331 ++++++++++++++++++ tests/Feature/Ui/ScreenRegistrationsTest.php | 159 +++++++++ tests/Feature/Ui/StylesTest.php | 13 + tests/Feature/Ui/TestHostScreenTest.php | 4 + tests/Feature/Ui/VisibilityTest.php | 212 +++++++++++ .../SwitchableRedirectDomainPolicy.php | 60 ++++ 13 files changed, 1112 insertions(+), 2 deletions(-) create mode 100644 resources/views/ui/screens/redirect-domains.blade.php create mode 100644 src/Atrium/ScreenRegistrations.php create mode 100644 tests/Feature/NoRosterReferenceTest.php create mode 100644 tests/Feature/Ui/OwnedRedirectDomainsTest.php create mode 100644 tests/Feature/Ui/ScreenRegistrationsTest.php create mode 100644 tests/Feature/Ui/VisibilityTest.php create mode 100644 tests/Fixtures/Policies/SwitchableRedirectDomainPolicy.php diff --git a/config/cortex.php b/config/cortex.php index fe31455..f8f9e44 100644 --- a/config/cortex.php +++ b/config/cortex.php @@ -155,12 +155,42 @@ | | Individual pages and controls are still shown per the policies above. | + | redirect_domains.screens: Other packages' Atrium screens that show an + | owner's OAuth redirect domains, keyed by screen key. The + | screen's record is the owner. A value of `tab` adds the + | `cortex.mcp` tab (opened with ?tab=cortex.mcp); any other + | value names the slot (`before`, `after`, `aside`, + | `header.actions`, ...) that gets the `cortex.redirect-domains` + | section. A screen nobody declares shows nothing. Set it to [] + | to put the UI on no screen; a published config without this + | key gets the defaults below. + | + | The tab and the section show only while stored domains are on + | (`redirect_domains.enabled` below), the record is saved, Cortex + | is on in Atrium (the features above) and the viewer passes + | `viewAny` with the owner in the RedirectDomainModel policy. + | The add form and remove buttons follow `create` and `delete`, + | which the bundled policy grants only to signed-in users who may + | `update` the owner, by the owner's own policy. + | + | A malformed entry (a value that is not a non-empty string, or a + | screen key or slot Atrium rejects) throws at boot in the local + | and testing environments; elsewhere it is reported once and + | skipped, and the other entries still register. + | */ 'atrium' => [ 'features' => [ CortexSupportFeature::class, ], + + 'redirect_domains' => [ + 'screens' => [ + 'roster.organization' => 'tab', + 'roster.user' => 'aside', + ], + ], ], /* diff --git a/docs/agent/standards-feedback.md b/docs/agent/standards-feedback.md index 6060405..d097106 100644 --- a/docs/agent/standards-feedback.md +++ b/docs/agent/standards-feedback.md @@ -4,3 +4,4 @@ Every time work has to break a standard, add a row. | Date | Spec | Standard | Deviation | Why | | --- | --- | --- | --- | --- | +| 2026-10-30 | 2026-10-29-2038-register-roster-redirect-domains | errors/exceptions (Cortex: every thrown exception extends `CortexException`, never a raw SPL exception) | `Atrium\ScreenRegistrations` throws (and in production reports) a plain `InvalidArgumentException` for a malformed `cortex.atrium.redirect_domains.screens` entry, and rethrows the one Atrium raises for a bad target or slot. | Suite decision D-021 (same as Atrium D-022): malformed integration config throws `InvalidArgumentException` in local and testing and is reported and skipped elsewhere, so every package raises the same type Atrium does for the same mistake. | diff --git a/lang/en/cortex.php b/lang/en/cortex.php index 620153b..c13d109 100644 --- a/lang/en/cortex.php +++ b/lang/en/cortex.php @@ -149,6 +149,11 @@ 'redirect_domain_invalid' => 'Enter a host or an http(s) URL, such as claude.ai or https://claude.ai.', 'redirect_domains_disabled' => 'Stored redirect domains are switched off (cortex.redirect_domains.enabled), so only the configured ones are accepted.', + // Redirect domains on other packages' screens + 'mcp' => 'MCP', + 'owned_redirect_domains_hint' => 'Origins MCP clients may register OAuth redirect URIs on for this record. Any client may register on them; each user still approves the client.', + 'add_owned_domain' => 'Add domain', + // Shared 'save' => 'Save', 'cancel' => 'Cancel', diff --git a/resources/views/ui/screens/redirect-domains.blade.php b/resources/views/ui/screens/redirect-domains.blade.php new file mode 100644 index 0000000..fe2aeec --- /dev/null +++ b/resources/views/ui/screens/redirect-domains.blade.php @@ -0,0 +1,57 @@ +{{-- + An owner's redirect domains on another package's screen: the `cortex.mcp` + tab's panel and the `cortex.redirect-domains` section both render this + view (ScreenRegistrations). `$record` is the owner; `$domains`, + `$ownerType` and `$ownerId` come from the resolver. The forms post the + owner, and the controller sends the browser back to this page. +--}} +@isset($ownerType) + +
+ @cortexCan('create', \RefactorCircus\Cortex\Domains\RedirectDomain\Models\RedirectDomainModel::class, [$record]) +
+ @csrf + + + + + + + + @endcortexCan + + @if ($domains->isEmpty()) + + @else + + + + {{ __('cortex::cortex.domain') }} + {{ __('cortex::cortex.created') }} + {{ __('cortex::cortex.actions') }} + + + + @foreach ($domains as $domain) + + {{ $domain->domain }} + {{ $domain->created_at?->diffForHumans() }} + + @cortexCan('delete', $domain) +
+ @csrf + @method('DELETE') + + + + + @endcortexCan +
+
+ @endforeach +
+ @endif +
+
+@endisset diff --git a/src/Atrium/ScreenRegistrations.php b/src/Atrium/ScreenRegistrations.php new file mode 100644 index 0000000..c1a97c1 --- /dev/null +++ b/src/Atrium/ScreenRegistrations.php @@ -0,0 +1,190 @@ + $slot) { + try { + self::add($target, $slot); + } catch (InvalidArgumentException $exception) { + self::fail($exception); + } + } + } + + /** + * The configured map, or the shipped default when a config published + * before the key existed lacks it. An empty list stays empty. + * + * @return array + * + * @throws InvalidArgumentException when the map is not an array + */ + private static function screens(): array + { + $key = 'cortex.atrium.redirect_domains.screens'; + + if (! config()->has($key)) { + /** @var array{atrium: array{redirect_domains: array{screens: array}}} $defaults */ + $defaults = require dirname(__DIR__, 2).'/config/cortex.php'; + + return $defaults['atrium']['redirect_domains']['screens']; + } + + $screens = config($key); + + if (! is_array($screens)) { + throw new InvalidArgumentException("[{$key}] must be an array of screen keys to `tab` or a slot name."); + } + + return $screens; + } + + /** + * @throws InvalidArgumentException for a target or slot that is not a non-empty string, or one Atrium rejects + */ + private static function add(int|string $target, mixed $slot): void + { + if (! is_string($target) || $target === '') { + throw new InvalidArgumentException("Redirect-domain screen [{$target}] in cortex.atrium.redirect_domains.screens must be a screen key, such as vendor.screen."); + } + + if (! is_string($slot) || $slot === '') { + throw new InvalidArgumentException("Redirect-domain screen [{$target}] in cortex.atrium.redirect_domains.screens needs `tab` or a slot name."); + } + + if ($slot === self::TAB) { + Atrium::screens()->tab($target, TabDefinition::make('cortex.mcp') + ->label(self::translate('cortex::cortex.mcp')) + ->icon('globe-alt') + ->view(self::VIEW) + ->authorize(self::visible(...)) + ->resolve(self::data(...))); + + return; + } + + Atrium::screens()->section($target, $slot, SectionDefinition::make('cortex.redirect-domains') + ->label(self::translate('cortex::cortex.redirect_domains')) + ->view(self::VIEW) + ->authorize(self::visible(...)) + ->resolve(self::data(...))); + } + + /** + * Throw where a developer sees it, else report and carry on. + */ + private static function fail(InvalidArgumentException $exception): void + { + if (app()->environment('local', 'testing')) { + throw $exception; + } + + report($exception); + } + + /** + * Whether the viewer sees the tab or section on this record. It runs on + * every render of every target screen, so the checks without a query + * come first, and a policy that throws hides it rather than the page. + */ + private static function visible(Request $request, ?Model $record): bool + { + if (! app(RedirectDomains::class)->enabled() || ! $record instanceof Model || ! $record->exists) { + return false; + } + + if (! array_key_exists('cortex', Atrium::pluginRegistry()->authorized($request))) { + return false; + } + + try { + return ScreenAccess::allowsFor($request->user(), 'viewAny', RedirectDomainModel::class, [$record]); + } catch (Throwable $exception) { + report($exception); + + return false; + } + } + + /** + * The owner's domains and the owner fields the forms post. Each domain's + * owner is the record already loaded, so asking `delete` per row loads + * no owner again. + * + * @return array + */ + private static function data(?Model $record): array + { + if ($record === null) { + return []; + } + + // Unpaged, so always a collection. + $domains = app(ListRedirectDomainsAction::class)->execute($record); + $domains = $domains instanceof Collection ? $domains : new Collection($domains->items()); + + foreach ($domains as $domain) { + $domain->setRelation('owner', $record); + } + + return [ + 'domains' => $domains, + 'ownerType' => $record->getMorphClass(), + 'ownerId' => (string) $record->getKey(), + ]; + } + + private static function translate(string $key): string + { + $line = __($key); + + return is_string($line) ? $line : $key; + } +} diff --git a/src/CortexServiceProvider.php b/src/CortexServiceProvider.php index 225274b..c58c0c3 100644 --- a/src/CortexServiceProvider.php +++ b/src/CortexServiceProvider.php @@ -9,6 +9,7 @@ use Laravel\Mcp\Request as McpRequest; use RefactorCircus\Cortex\Atrium\CortexPlugin; use RefactorCircus\Cortex\Atrium\ScreenAccess; +use RefactorCircus\Cortex\Atrium\ScreenRegistrations; use RefactorCircus\Cortex\Domains\DomainServiceProvider; use RefactorCircus\Cortex\Mcp\CortexServer; use RefactorCircus\Keystone\Packages\Package; @@ -88,6 +89,21 @@ private function fillMcpRequestsForAgents(): void }); } + /** + * Put the redirect-domain UI on other packages' screens, as + * `cortex.atrium.redirect_domains.screens` lists them. Behind the same + * guard as registerAtriumPlugin(): Atrium is suggested, not required, so + * its class is named only as a string, and the dashboard UI must be on. + */ + private function registerAtriumScreens(): void + { + if (! class_exists('RefactorCircus\\Atrium\\Atrium') || $this->config()->get('cortex.ui.enabled') !== true) { + return; + } + + ScreenRegistrations::register(); + } + /** * Bootstrap any application services. */ @@ -102,8 +118,13 @@ public function boot(): void // Missing records on Cortex's routes answer a plain "Not found.", as its MCP tools do. $this->registerNotFoundResponses(); + // Before the Atrium registrations, whose labels are translated. + $this->loadTranslationsFrom(__DIR__.'/../lang', 'cortex'); + $this->registerAtriumPlugin(CortexPlugin::class); + $this->registerAtriumScreens(); + $this->registerMcpServer(); $this->loadHistoryRoutes(); @@ -114,8 +135,6 @@ public function boot(): void // policy check, so a control shows only when its action is allowed. Blade::if('cortexCan', ScreenAccess::allows(...)); - $this->loadTranslationsFrom(__DIR__.'/../lang', 'cortex'); - if (! $this->app->runningInConsole()) { return; } diff --git a/tests/Feature/NoRosterReferenceTest.php b/tests/Feature/NoRosterReferenceTest.php new file mode 100644 index 0000000..32a278c --- /dev/null +++ b/tests/Feature/NoRosterReferenceTest.php @@ -0,0 +1,29 @@ +isFile()) { + continue; + } + + $checked++; + + if (stripos((string) file_get_contents($file->getPathname()), 'roster') !== false) { + $naming[] = $file->getPathname(); + } + } + + expect($checked)->toBeGreaterThan(0) + ->and($naming)->toBe([]); +}); diff --git a/tests/Feature/Ui/OwnedRedirectDomainsTest.php b/tests/Feature/Ui/OwnedRedirectDomainsTest.php new file mode 100644 index 0000000..fc893d8 --- /dev/null +++ b/tests/Feature/Ui/OwnedRedirectDomainsTest.php @@ -0,0 +1,331 @@ + true); + + SwitchableRedirectDomainPolicy::reset(); + Gate::policy(RedirectDomainModel::class, SwitchableRedirectDomainPolicy::class); + + $this->morphMapBefore = Relation::$morphMap; + + $this->viewer = User::query()->create(['name' => 'Ada Lovelace', 'email' => 'ada@example.com', 'password' => 'secret']); + $this->organization = Organization::query()->create(['name' => 'Acme Inc']); + + $this->actingAs($this->viewer); +}); + +afterEach(function (): void { + Relation::$morphMap = $this->morphMapBefore; + + SwitchableRedirectDomainPolicy::reset(); +}); + +function ownedHostUrl(string $key, Model $record, ?string $tab = null): string +{ + return route('test-host', array_filter(['key' => $key, 'id' => $record->getKey(), 'tab' => $tab])); +} + +/** + * The hidden fields the screen's forms post for their record. + * + * @return array{owner_type: string, owner_id: string} + */ +function ownedFields(Model $owner): array +{ + return ['owner_type' => $owner->getMorphClass(), 'owner_id' => (string) $owner->getKey()]; +} + +function ownedDomain(?Model $owner, string $domain = 'claude.ai'): RedirectDomainModel +{ + return app(CreateRedirectDomainAction::class)->execute(new CreateRedirectDomainData(domain: $domain), $owner); +} + +/** + * Atrium keeps a request's screen answers and data in a scoped service, + * which only a new request (or job) forgets; tests make several requests in + * one application, so forget them before each page view. + */ +function ownedPage(string $url): TestResponse +{ + app()->forgetScopedInstances(); + + return test()->get($url); +} + +it('shows the organization tab and adds, lists and removes its domains', function (): void { + $host = ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp'); + + ownedPage(ownedHostUrl('roster.organization', $this->organization)) + ->assertOk() + ->assertSee('data-testid="tab-cortex.mcp"', false); + + ownedPage($host) + ->assertOk() + ->assertSee('data-testid="tab-panel-cortex.mcp"', false) + ->assertSee(__('cortex::cortex.owned_redirect_domains_hint')) + ->assertSee('data-testid="add-redirect-domain"', false) + ->assertSee('action="'.route('atrium.cortex.redirect-domains.store').'"', false) + ->assertSee('name="owner_type" value="'.Organization::class.'"', false) + ->assertSee('name="owner_id" value="'.$this->organization->getKey().'"', false) + ->assertSee(__('cortex::cortex.no_redirect_domains')) + ->assertDontSee('data-testid="owned-redirect-domains"', false) + ->assertDontSee('data-testid="test-host-content"', false); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownedFields($this->organization)]) + ->assertRedirect($host); + + $stored = RedirectDomainModel::query()->sole(); + + expect($stored->domain)->toBe('https://claude.ai') + ->and($stored->owner_type)->toBe(Organization::class) + ->and($stored->owner_id)->toBe((string) $this->organization->getKey()); + + ownedPage($host) + ->assertOk() + ->assertSee('data-testid="owned-redirect-domains"', false) + ->assertSee('https://claude.ai') + ->assertSee('data-testid="remove-redirect-domain"', false) + ->assertSee('action="'.route('atrium.cortex.redirect-domains.destroy', $stored->id).'"', false) + ->assertDontSee(__('cortex::cortex.no_redirect_domains')); + + $this->from($host) + ->delete(route('atrium.cortex.redirect-domains.destroy', $stored->id), ownedFields($this->organization)) + ->assertRedirect($host); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('lists only the owner\'s own domains', function (): void { + $other = Organization::query()->create(['name' => 'Other Inc']); + ownedDomain($this->organization, 'claude.ai'); + ownedDomain($other, 'chatgpt.com'); + ownedDomain(null, 'perplexity.ai'); + + ownedPage(ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp')) + ->assertOk() + ->assertSee('https://claude.ai') + ->assertDontSee('https://chatgpt.com') + ->assertDontSee('https://perplexity.ai'); +}); + +it('hides the tab and refuses ?tab= when the policy denies viewAny', function (): void { + SwitchableRedirectDomainPolicy::$denies = ['viewAny']; + + ownedPage(ownedHostUrl('roster.organization', $this->organization)) + ->assertOk() + ->assertDontSee('data-testid="tab-cortex.mcp"', false); + + ownedPage(ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp'))->assertForbidden(); +}); + +it('refuses a post when the policy denies create', function (): void { + SwitchableRedirectDomainPolicy::$denies = ['create']; + $host = ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp'); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownedFields($this->organization)]) + ->assertForbidden(); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('lists the domains read-only when the owner\'s own policy denies update', function (): void { + OrganizationPolicy::$deniesUpdate = true; + $domain = ownedDomain($this->organization); + $host = ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp'); + + ownedPage($host) + ->assertOk() + ->assertSee('data-testid="owned-redirect-domains"', false) + ->assertSee('https://claude.ai') + ->assertDontSee('data-testid="add-redirect-domain"', false) + ->assertDontSee('data-testid="remove-redirect-domain"', false); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'chatgpt.com', ...ownedFields($this->organization)]) + ->assertForbidden(); + + $this->from($host) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domain->id), ownedFields($this->organization)) + ->assertForbidden(); + + expect(RedirectDomainModel::query()->pluck('domain')->all())->toBe(['https://claude.ai']); +}); + +it('answers 404 when removing another owner\'s domain', function (): void { + $other = Organization::query()->create(['name' => 'Other Inc']); + $domainOfOther = ownedDomain($other); + + $this->from(ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp')) + ->delete(route('atrium.cortex.redirect-domains.destroy', $domainOfOther->id), ownedFields($this->organization)) + ->assertNotFound(); + + expect(RedirectDomainModel::query()->whereKey($domainOfOther->id)->exists())->toBeTrue(); +}); + +it('sends an invalid domain back to the host page with an error', function (): void { + $host = ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp'); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'not a domain', ...ownedFields($this->organization)]) + ->assertRedirect($host) + ->assertSessionHasErrors('domain'); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('renders the user aside section and adds and removes its domains', function (): void { + $host = ownedHostUrl('roster.user', $this->viewer); + + ownedPage($host) + ->assertOk() + ->assertSee('data-testid="screen-aside"', false) + ->assertSee('data-testid="section-cortex.redirect-domains"', false) + ->assertSee('data-testid="add-redirect-domain"', false) + ->assertSee('name="owner_type" value="'.User::class.'"', false) + ->assertSee('data-testid="test-host-content"', false); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownedFields($this->viewer)]) + ->assertRedirect($host); + + $stored = RedirectDomainModel::query()->sole(); + + expect($stored->owner_type)->toBe(User::class) + ->and($stored->owner_id)->toBe((string) $this->viewer->getKey()); + + ownedPage($host) + ->assertOk() + ->assertSee('https://claude.ai') + ->assertSee('data-testid="remove-redirect-domain"', false); + + $this->from($host) + ->delete(route('atrium.cortex.redirect-domains.destroy', $stored->id), ownedFields($this->viewer)) + ->assertRedirect($host); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('keeps the user aside read-only when the user policy denies update', function (): void { + UserPolicy::$deniesUpdate = true; + ownedDomain($this->viewer); + + ownedPage(ownedHostUrl('roster.user', $this->viewer)) + ->assertOk() + ->assertSee('https://claude.ai') + ->assertDontSee('data-testid="add-redirect-domain"', false) + ->assertDontSee('data-testid="remove-redirect-domain"', false); +}); + +it('shows the list without the add form or remove buttons when create and delete are denied', function (): void { + SwitchableRedirectDomainPolicy::$denies = ['create', 'delete']; + ownedDomain($this->organization); + ownedDomain($this->viewer); + + ownedPage(ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp')) + ->assertOk() + ->assertSee('data-testid="owned-redirect-domains"', false) + ->assertSee('https://claude.ai') + ->assertDontSee('data-testid="add-redirect-domain"', false) + ->assertDontSee('data-testid="remove-redirect-domain"', false); + + ownedPage(ownedHostUrl('roster.user', $this->viewer)) + ->assertOk() + ->assertSee('data-testid="owned-redirect-domains"', false) + ->assertDontSee('data-testid="add-redirect-domain"', false) + ->assertDontSee('data-testid="remove-redirect-domain"', false); +}); + +it('renders neither the tab nor the section while stored domains are switched off', function (): void { + config()->set('cortex.redirect_domains.enabled', false); + + ownedPage(ownedHostUrl('roster.organization', $this->organization)) + ->assertOk() + ->assertDontSee('data-testid="tab-cortex.mcp"', false); + + ownedPage(ownedHostUrl('roster.user', $this->viewer)) + ->assertOk() + ->assertDontSee('data-testid="section-cortex.redirect-domains"', false); +}); + +it('names the owner by its morph alias', function (): void { + Relation::morphMap(['organization' => Organization::class]); + $host = ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp'); + + ownedPage($host) + ->assertOk() + ->assertSee('name="owner_type" value="organization"', false); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', ...ownedFields($this->organization)]) + ->assertRedirect($host); + + $stored = RedirectDomainModel::query()->sole(); + + expect($stored->owner_type)->toBe('organization') + ->and($stored->owner_id)->toBe((string) $this->organization->getKey()); + + ownedPage($host) + ->assertOk() + ->assertSee('https://claude.ai') + ->assertSee('data-testid="remove-redirect-domain"', false); + + $this->from($host) + ->delete(route('atrium.cortex.redirect-domains.destroy', $stored->id), ownedFields($this->organization)) + ->assertRedirect($host); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); + + $this->from($host) + ->post(route('atrium.cortex.redirect-domains.store'), ['domain' => 'claude.ai', 'owner_type' => 'unregistered', 'owner_id' => (string) $this->organization->getKey()]) + ->assertNotFound(); + + expect(RedirectDomainModel::query()->exists())->toBeFalse(); +}); + +it('asks the owner\'s policy once per domain without loading the owner again', function (): void { + ownedDomain($this->organization, 'claude.ai'); + ownedDomain($this->organization, 'chatgpt.com'); + ownedDomain($this->organization, 'perplexity.ai'); + + DB::enableQueryLog(); + DB::flushQueryLog(); + + ownedPage(ownedHostUrl('roster.organization', $this->organization, 'cortex.mcp')) + ->assertOk() + ->assertSee('https://perplexity.ai'); + + $ownerLookups = array_filter( + DB::getQueryLog(), + fn (array $query): bool => str_contains($query['query'], (new Organization)->getTable()), + ); + + // The host loads its record once; the domains' owner is the record. + expect($ownerLookups)->toHaveCount(1); +}); diff --git a/tests/Feature/Ui/ScreenRegistrationsTest.php b/tests/Feature/Ui/ScreenRegistrationsTest.php new file mode 100644 index 0000000..7b3d312 --- /dev/null +++ b/tests/Feature/Ui/ScreenRegistrationsTest.php @@ -0,0 +1,159 @@ +flush(); + + $provider = app()->getProvider(CortexServiceProvider::class); + + (fn () => $this->registerAtriumScreens())->call($provider); +} + +/** + * Every key of the tabs and sections registered for the target. + * + * @return array{tabs: list, sections: array>} + */ +function screenRegistrationsOn(string $target): array +{ + $registry = app(ScreenExtensions::class); + $sections = []; + + foreach (['header.actions', 'before', 'after', 'aside', 'row.actions'] as $slot) { + $keys = array_map(fn (SectionDefinition $section): string => $section->key, $registry->sections($target, $slot)); + + if ($keys !== []) { + $sections[$slot] = $keys; + } + } + + return [ + 'tabs' => array_map(fn (TabDefinition $tab): string => $tab->key, $registry->tabs($target)), + 'sections' => $sections, + ]; +} + +it('defaults to the organization tab and the user aside', function (): void { + expect(config('cortex.atrium.redirect_domains.screens'))->toBe([ + 'roster.organization' => 'tab', + 'roster.user' => 'aside', + ]); +}); + +it('registers the default map from boot', function (): void { + $tabs = app(ScreenExtensions::class)->tabs('roster.organization'); + $sections = app(ScreenExtensions::class)->sections('roster.user', 'aside'); + + expect($tabs)->toHaveCount(1) + ->and($tabs[0]->key)->toBe('cortex.mcp') + ->and($tabs[0]->label)->toBe('MCP') + ->and($tabs[0]->icon)->toBe('globe-alt') + ->and($tabs[0]->view)->toBe('cortex::ui.screens.redirect-domains') + ->and($tabs[0]->permission)->toBeNull() + ->and($tabs[0]->public)->toBeFalse() + ->and($sections)->toHaveCount(1) + ->and($sections[0]->key)->toBe('cortex.redirect-domains') + ->and($sections[0]->label)->toBe('Redirect domains') + ->and($sections[0]->view)->toBe('cortex::ui.screens.redirect-domains') + ->and($sections[0]->permission)->toBeNull() + ->and($sections[0]->public)->toBeFalse() + ->and(screenRegistrationsOn('roster.organization'))->toBe(['tabs' => ['cortex.mcp'], 'sections' => []]) + ->and(screenRegistrationsOn('roster.user'))->toBe(['tabs' => [], 'sections' => ['aside' => ['cortex.redirect-domains']]]); +}); + +it('uses the default map when a published config has no redirect_domains key', function (): void { + // An `atrium` section published before the key existed. + config()->set('cortex.atrium', ['features' => []]); + + bootScreenRegistrations(); + + expect(screenRegistrationsOn('roster.organization')['tabs'])->toBe(['cortex.mcp']) + ->and(screenRegistrationsOn('roster.user')['sections'])->toBe(['aside' => ['cortex.redirect-domains']]); +}); + +it('registers nothing for an empty list', function (): void { + config()->set('cortex.atrium.redirect_domains.screens', []); + + bootScreenRegistrations(); + + expect(screenRegistrationsOn('roster.organization'))->toBe(['tabs' => [], 'sections' => []]) + ->and(screenRegistrationsOn('roster.user'))->toBe(['tabs' => [], 'sections' => []]); +}); + +it('registers only the entries of a custom list', function (): void { + config()->set('cortex.atrium.redirect_domains.screens', ['acme.account' => 'before']); + + bootScreenRegistrations(); + + expect(screenRegistrationsOn('acme.account'))->toBe(['tabs' => [], 'sections' => ['before' => ['cortex.redirect-domains']]]) + ->and(screenRegistrationsOn('roster.organization'))->toBe(['tabs' => [], 'sections' => []]) + ->and(screenRegistrationsOn('roster.user'))->toBe(['tabs' => [], 'sections' => []]); +}); + +it('registers nothing while the dashboard UI is switched off', function (): void { + config()->set('cortex.ui.enabled', false); + + bootScreenRegistrations(); + + expect(screenRegistrationsOn('roster.organization'))->toBe(['tabs' => [], 'sections' => []]) + ->and(screenRegistrationsOn('roster.user'))->toBe(['tabs' => [], 'sections' => []]); +}); + +it('registers nothing unless the UI flag is literally true', function (): void { + config()->set('cortex.ui.enabled', '1'); + + bootScreenRegistrations(); + + expect(screenRegistrationsOn('roster.organization'))->toBe(['tabs' => [], 'sections' => []]); +}); + +it('throws for a malformed entry in testing', function (mixed $screens): void { + config()->set('cortex.atrium.redirect_domains.screens', $screens); + + expect(fn () => bootScreenRegistrations())->toThrow(InvalidArgumentException::class); +})->with([ + 'a null value' => [['roster.organization' => null]], + 'an empty value' => [['roster.organization' => '']], + 'a bogus slot' => [['roster.organization' => 'bogus slot']], + 'a value that is not a string' => [['roster.organization' => ['tab']]], + 'a bogus target' => [['Not A Screen' => 'tab']], + 'a list without screen keys' => [['tab']], + 'a map that is not an array' => ['tab'], +]); + +it('throws in local too', function (): void { + app()->detectEnvironment(fn (): string => 'local'); + config()->set('cortex.atrium.redirect_domains.screens', ['roster.organization' => '']); + + expect(fn () => bootScreenRegistrations())->toThrow(InvalidArgumentException::class); +}); + +it('reports a malformed entry once in production, skips it and registers the rest', function (): void { + Exceptions::fake(); + app()->detectEnvironment(fn (): string => 'production'); + config()->set('cortex.atrium.redirect_domains.screens', [ + 'roster.organization' => 'bogus slot', + 'roster.user' => 'aside', + ]); + + bootScreenRegistrations(); + + Exceptions::assertReportedCount(1); + Exceptions::assertReported(InvalidArgumentException::class); + + expect(screenRegistrationsOn('roster.organization'))->toBe(['tabs' => [], 'sections' => []]) + ->and(screenRegistrationsOn('roster.user')['sections'])->toBe(['aside' => ['cortex.redirect-domains']]); +}); diff --git a/tests/Feature/Ui/StylesTest.php b/tests/Feature/Ui/StylesTest.php index b035844..6250e87 100644 --- a/tests/Feature/Ui/StylesTest.php +++ b/tests/Feature/Ui/StylesTest.php @@ -14,3 +14,16 @@ expect(AtriumStyles::missingClasses($views))->toBe([]) ->and(AtriumStyles::inlineStyles($views))->toBe([]); }); + +it('checks the redirect-domain view it puts on other packages\' screens', function (): void { + $screens = dirname(__DIR__, 3).'/resources/views/ui/screens'; + + expect($screens.'/redirect-domains.blade.php')->toBeFile() + ->and(AtriumStyles::missingClasses($screens))->toBe([]) + ->and(AtriumStyles::inlineStyles($screens))->toBe([]); + + // Built from Atrium's components only: no component namespace of its own. + preg_match_all('/toBe(['atrium']); +}); diff --git a/tests/Feature/Ui/TestHostScreenTest.php b/tests/Feature/Ui/TestHostScreenTest.php index 52df3e2..7e6473f 100644 --- a/tests/Feature/Ui/TestHostScreenTest.php +++ b/tests/Feature/Ui/TestHostScreenTest.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Gate; use RefactorCircus\Atrium\Domains\Screens\Data\TabDefinition; +use RefactorCircus\Atrium\Domains\Screens\Services\ScreenExtensions; use RefactorCircus\Atrium\Facades\Atrium; use Workbench\App\Models\Organization; use Workbench\App\Models\User; @@ -24,6 +25,9 @@ function testHostScreens(): array } it('renders the workbench screen for its key and record', function (string $key, Closure $record): void { + // The host alone, without what Cortex registers on it by default. + app(ScreenExtensions::class)->flush(); + $model = $record(); $this->get(route('test-host', ['key' => $key, 'id' => $model->getKey()])) diff --git a/tests/Feature/Ui/VisibilityTest.php b/tests/Feature/Ui/VisibilityTest.php new file mode 100644 index 0000000..0855cbf --- /dev/null +++ b/tests/Feature/Ui/VisibilityTest.php @@ -0,0 +1,212 @@ +viewer = User::query()->create(['name' => 'Viewer', 'email' => 'viewer@example.com', 'password' => 'secret']); + $this->actingAs($this->viewer); +}); + +afterEach(function (): void { + SwitchableRedirectDomainPolicy::reset(); +}); + +/** + * @return array + */ +function visibilityTargets(): array +{ + return [ + 'the organization tab' => [ + 'roster.organization', + fn (): TabDefinition => Atrium::screens()->tabs('roster.organization')[0], + 'data-testid="tab-cortex.mcp"', + ], + 'the user aside section' => [ + 'roster.user', + fn (): SectionDefinition => Atrium::screens()->sections('roster.user', 'aside')[0], + 'data-testid="section-cortex.redirect-domains"', + ], + ]; +} + +function visibilityRecord(string $key): Model +{ + return $key === 'roster.user' + ? test()->viewer + : Organization::query()->create(['name' => 'Acme Inc']); +} + +/** + * A new request each time: Atrium remembers a request's plugin answers. + */ +function visibilityAllows(TabDefinition|SectionDefinition $extension, string $key, ?Model $record): bool +{ + $request = Request::create('/test-host'); + $request->setUserResolver(fn (): mixed => auth()->user()); + + return $extension->allows($request, $record, Screen::standard($key, Screen::DETAIL)->record($record), null); +} + +/** + * Each condition turned off on its own: it changes the app or the record and + * answers the record to check (null for none). + * + * @return array + */ +function visibilityConditions(): array +{ + return [ + 'stored domains switched off' => [function (Model $record): Model { + config()->set('cortex.redirect_domains.enabled', false); + + return $record; + }], + 'cortex plugin not authorized' => [function (Model $record): Model { + // A feature Cortex requires is off, so PluginRegistry::authorized() lacks `cortex`. + config()->set('cortex.atrium.features', ['plain-feature']); + Atrium::resolveFeaturesUsing(fn (string $feature): bool => $feature !== 'plain-feature'); + + return $record; + }], + 'an unsaved record' => [fn (Model $record): Model => $record::class === User::class ? new User : new Organization], + 'no record' => [fn (Model $record): ?Model => null], + 'viewAny denied' => [function (Model $record): Model { + SwitchableRedirectDomainPolicy::$denies = ['viewAny']; + + return $record; + }], + ]; +} + +it('is visible while every condition holds', function (string $key, Closure $extension, string $testId): void { + $record = visibilityRecord($key); + + expect(visibilityAllows($extension(), $key, $record))->toBeTrue(); + + $this->get(route('test-host', ['key' => $key, 'id' => $record->getKey()])) + ->assertOk() + ->assertSee($testId, false); +})->with(visibilityTargets()); + +it('is hidden when one condition fails', function (string $key, Closure $extension, string $testId, Closure $condition): void { + $record = $condition(visibilityRecord($key)); + + expect(visibilityAllows($extension(), $key, $record))->toBeFalse(); + + // A host screen always has a record; an unsaved one is served without an id. + if ($record !== null) { + $this->get(route('test-host', ['key' => $key, 'id' => $record->exists ? $record->getKey() : null])) + ->assertOk() + ->assertDontSee($testId, false); + } +})->with(visibilityTargets())->with(visibilityConditions()); + +it('authorizes through its own check, never permission() or public()', function (string $key, Closure $extension): void { + $definition = $extension(); + + expect($definition->permission)->toBeNull() + ->and($definition->public)->toBeFalse(); +})->with(visibilityTargets()); + +it('runs no query for a missing or unsaved record', function (string $key, Closure $extension): void { + $definition = $extension(); + $unsaved = $key === 'roster.user' ? new User : new Organization; + + DB::enableQueryLog(); + DB::flushQueryLog(); + + visibilityAllows($definition, $key, null); + visibilityAllows($definition, $key, $unsaved); + + expect(DB::getQueryLog())->toBe([]); +})->with(visibilityTargets()); + +it('runs no query while stored domains are switched off', function (string $key, Closure $extension): void { + $definition = $extension(); + $record = visibilityRecord($key); + SwitchableRedirectDomainPolicy::$queries = true; + config()->set('cortex.redirect_domains.enabled', false); + + DB::enableQueryLog(); + DB::flushQueryLog(); + + visibilityAllows($definition, $key, $record); + + expect(DB::getQueryLog())->toBe([]); +})->with(visibilityTargets()); + +it('adds no more than one policy query per record to a host page', function (): void { + $users = [ + $this->viewer, + User::query()->create(['name' => 'Ada', 'email' => 'ada@example.com', 'password' => 'secret']), + User::query()->create(['name' => 'Grace', 'email' => 'grace@example.com', 'password' => 'secret']), + ]; + + $asideQueries = function () use ($users): int { + $request = Request::create('/test-host'); + $request->setUserResolver(fn (): mixed => auth()->user()); + + DB::enableQueryLog(); + DB::flushQueryLog(); + + foreach ($users as $user) { + app()->forgetScopedInstances(); + + $resolved = app(ScreenExtensions::class)->resolve(Screen::standard('roster.user', Screen::DETAIL)->record($user), $request); + + expect($resolved->sections('aside'))->toHaveCount(1); + } + + return count(DB::getQueryLog()); + }; + + // The bundled policy answers viewAny without the database. + expect($asideQueries())->toBe(0); + + // A policy of the app's own that queries once is asked once per record. + SwitchableRedirectDomainPolicy::$queries = true; + + expect($asideQueries())->toBeLessThanOrEqual(count($users)); +}); + +it('hides the section and keeps the host page up when the policy throws', function (): void { + SwitchableRedirectDomainPolicy::$throws = true; + + $this->get(route('test-host', ['key' => 'roster.user', 'id' => $this->viewer->getKey()])) + ->assertOk() + ->assertSee('data-testid="test-host-content"', false) + ->assertDontSee('data-testid="section-cortex.redirect-domains"', false) + ->assertDontSee('data-testid="screen-aside"', false); + + $organization = Organization::query()->create(['name' => 'Acme Inc']); + + $this->get(route('test-host', ['key' => 'roster.organization', 'id' => $organization->getKey()])) + ->assertOk() + ->assertDontSee('data-testid="tab-cortex.mcp"', false); + + expect(visibilityAllows(Atrium::screens()->tabs('roster.organization')[0], 'roster.organization', $organization))->toBeFalse(); +}); diff --git a/tests/Fixtures/Policies/SwitchableRedirectDomainPolicy.php b/tests/Fixtures/Policies/SwitchableRedirectDomainPolicy.php new file mode 100644 index 0000000..634eae5 --- /dev/null +++ b/tests/Fixtures/Policies/SwitchableRedirectDomainPolicy.php @@ -0,0 +1,60 @@ + + */ + public static array $denies = []; + + public static bool $throws = false; + + public static bool $queries = false; + + public static function reset(): void + { + self::$denies = []; + self::$throws = false; + self::$queries = false; + } + + public function viewAny(?Authenticatable $user, ?Model $owner = null): bool + { + if (self::$throws) { + throw new RuntimeException('The redirect-domain policy failed.'); + } + + if (self::$queries && $owner !== null) { + RedirectDomainModel::query()->ownedBy($owner)->exists(); + } + + return ! in_array('viewAny', self::$denies, true) && parent::viewAny($user, $owner); + } + + public function create(?Authenticatable $user, ?Model $owner = null): bool + { + return ! in_array('create', self::$denies, true) && parent::create($user, $owner); + } + + public function delete(?Authenticatable $user, RedirectDomainModel $domain): bool + { + return ! in_array('delete', self::$denies, true) && parent::delete($user, $domain); + } +} From 1f6a9762f9991a8c1b92fef5c754772f712635d4 Mon Sep 17 00:00:00 2001 From: Jay Fletcher <5743488+jayjfletcher@users.noreply.github.com> Date: Fri, 30 Oct 2026 01:11:40 -0400 Subject: [PATCH 13/23] 2026-10-29-2038-register-roster-redirect-domains: group 4 Declare Cortex's own screens and remove history UI (salvaged) Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- README.md | 2 +- docs/agent/standards/cortex/atrium-screens.md | 15 +- .../boost/skills/cortex-development/SKILL.md | 4 +- .../views/ui/concrete-agents/index.blade.php | 154 +++++----- .../views/ui/concrete-agents/show.blade.php | 165 ++++++----- .../views/ui/partials/override.blade.php | 5 - .../views/ui/redirect-domains/index.blade.php | 198 +++++++------ resources/views/ui/run.blade.php | 123 +++++--- resources/views/ui/servers/index.blade.php | 78 +++-- .../views/ui/servers/instructions.blade.php | 64 +++- .../views/ui/tools/description.blade.php | 52 +++- resources/views/ui/tools/index.blade.php | 128 ++++---- .../views/ui/virtual-agents/form.blade.php | 275 ++++++++++-------- .../views/ui/virtual-agents/index.blade.php | 134 +++++---- src/Atrium/CortexPlugin.php | 6 +- .../Controllers/ConcreteAgentUiController.php | 18 +- .../McpInstructionUiController.php | 11 +- .../RedirectDomainUiController.php | 7 +- .../Http/Controllers/RunAgentUiController.php | 23 +- .../Http/Controllers/ServerUiController.php | 7 +- .../ToolDescriptionUiController.php | 11 +- .../Http/Controllers/ToolUiController.php | 6 +- .../Controllers/VirtualAgentUiController.php | 17 +- src/Atrium/Screens.php | 43 +++ tests/Feature/HistoryNavigationTest.php | 7 +- tests/Feature/NoHistoryUiTest.php | 61 ++++ tests/Feature/Ui/AuditTrailTest.php | 79 ----- tests/Feature/Ui/CortexPluginTest.php | 2 +- tests/Feature/Ui/DeclaredScreensTest.php | 201 +++++++++++++ tests/Feature/Ui/ScreenAccessClosureTest.php | 143 +++++++++ tests/Feature/Ui/ScreenLayoutTest.php | 171 +++++++++++ tests/Fixtures/views/screen-probe.blade.php | 2 + 33 files changed, 1541 insertions(+), 673 deletions(-) create mode 100644 src/Atrium/Screens.php create mode 100644 tests/Feature/NoHistoryUiTest.php delete mode 100644 tests/Feature/Ui/AuditTrailTest.php create mode 100644 tests/Feature/Ui/DeclaredScreensTest.php create mode 100644 tests/Feature/Ui/ScreenAccessClosureTest.php create mode 100644 tests/Feature/Ui/ScreenLayoutTest.php create mode 100644 tests/Fixtures/views/screen-probe.blade.php diff --git a/AGENTS.md b/AGENTS.md index 0c21aaf..c15a587 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,7 +33,7 @@ Atrium owns every component and style; Cortex ships no `resources/css`, no `Atri - Views use only `x-atrium::*` components and the utilities Atrium safelists. No `