Route browser, mute and work context through named profiles (#157 step 2b-ii) #310

Merged
stephen merged 15 commits from fj-157-profile-maintenance into main 2026-11-11 04:24:55 +00:00
Owner

Step 2b-ii of #157: browser shortcuts, mute and inbox filtering and the work and status instance display now read the selected named profile instead of the legacy host. Scoped session cookies, logout and maintenance are step 2b-iii; the work sessions stay deferred. #157 stays open.

Inferred clone destinations are routed against the selected account's own instance only, and a clone that points at a different instance than the selected one is refused before any request or mutation is sent. One authority function (lowercase host, port kept only when it is not the scheme default; http 80 and https 443 collapse to the bare host; SSH transport ports are dropped) is shared by remote parsing, preferred-host discovery, routing, cached public destinations and PAT host keys, so explicit --host and inferred entry points agree.

Pinned fj.resolved slugs now infer the destination from the clone too. If the highest-priority remote exists but cannot be parsed (for example a path-mounted URL), the command fails instead of falling back to the default host; a clone with no remote still falls back, an unparseable lower-priority backup remote is ignored, and --host and -R stay the overrides.

Existing hosts.toml entries are not migrated. Stored host keys are matched ignoring ASCII case (two keys that differ only by case are refused as ambiguous), --host resolves through the same match, and a PAT login for a host that already has an entry under another casing updates that entry in place, so a legacy FORGE.EXAMPLE key keeps its credentials and no lowercase twin appears.

Failure paths

  • Failures are not successes: a parse failure on the pinned destination is returned, not turned into the default host. Covered by the profile_consumers matrix (mutations and browser shortcuts for issue, pr and release) with a single bad remote and with a bad upstream over a valid origin; the same matrix fails without the change.
  • Backup remotes: a valid upstream with an unparseable lower-priority remote still resolves (profile_consumers).
  • Stored identities: tests/legacy_host_key.rs writes a mixed-case legacy key and credential, then checks lookup, a repeat login and that exactly one entry remains under the legacy key.
  • Port identity: HTTP 80, HTTPS 443, SSH 2222 and nondefault ports against profile and direct PAT, with and without --host, pinned and unpinned, with exactly 36 authenticated requests on the direct mock and zero on the trap.
  • Concurrency: n/a here. Routing, client construction and browser metadata each load the config separately, so a concurrent account switch can mix snapshots. That predates this PR and is tracked in the follow-up issue.

Review state: the pinned backup-remote fix and the first legacy host key fix were not re-reviewed after the third local self-review round. The later changes (authority-only case folding with exact keys first, stored-key use in named PAT login and proxy setup, and the Fjord session in the legacy host fixture) got one more local round. Its one Medium is a known limit, below.

Known limit: a PAT host configured with a mount path (for example https://forge.example/forgejo) plus a pinned fj.resolved slug and a clone remote under that mount now fails with the discovery error ("cannot infer the instance") instead of using the default host. This is the same refusal rule as for any unparseable remote; --host and -R override it. Mount-aware inference is not part of this PR.

Size: the PR is 1,308 gross added lines, accepted by the lead. Splitting it now would cost more than it saves.

Offline tests only: profile_consumers, auth_profiles, account_override, legacy_host_key, and the config, client::resolve, cli::auth and git unit tests. Live browser behaviour is unchecked.

Step 2b-ii of #157: browser shortcuts, mute and inbox filtering and the work and status instance display now read the selected named profile instead of the legacy host. Scoped session cookies, logout and maintenance are step 2b-iii; the work sessions stay deferred. #157 stays open. Inferred clone destinations are routed against the selected account's own instance only, and a clone that points at a different instance than the selected one is refused before any request or mutation is sent. One authority function (lowercase host, port kept only when it is not the scheme default; http 80 and https 443 collapse to the bare host; SSH transport ports are dropped) is shared by remote parsing, preferred-host discovery, routing, cached public destinations and PAT host keys, so explicit `--host` and inferred entry points agree. Pinned `fj.resolved` slugs now infer the destination from the clone too. If the highest-priority remote exists but cannot be parsed (for example a path-mounted URL), the command fails instead of falling back to the default host; a clone with no remote still falls back, an unparseable lower-priority backup remote is ignored, and `--host` and `-R` stay the overrides. Existing hosts.toml entries are not migrated. Stored host keys are matched ignoring ASCII case (two keys that differ only by case are refused as ambiguous), `--host` resolves through the same match, and a PAT login for a host that already has an entry under another casing updates that entry in place, so a legacy `FORGE.EXAMPLE` key keeps its credentials and no lowercase twin appears. ## Failure paths - Failures are not successes: a parse failure on the pinned destination is returned, not turned into the default host. Covered by the profile_consumers matrix (mutations and browser shortcuts for issue, pr and release) with a single bad remote and with a bad upstream over a valid origin; the same matrix fails without the change. - Backup remotes: a valid upstream with an unparseable lower-priority remote still resolves (profile_consumers). - Stored identities: tests/legacy_host_key.rs writes a mixed-case legacy key and credential, then checks lookup, a repeat login and that exactly one entry remains under the legacy key. - Port identity: HTTP 80, HTTPS 443, SSH 2222 and nondefault ports against profile and direct PAT, with and without `--host`, pinned and unpinned, with exactly 36 authenticated requests on the direct mock and zero on the trap. - Concurrency: n/a here. Routing, client construction and browser metadata each load the config separately, so a concurrent account switch can mix snapshots. That predates this PR and is tracked in the follow-up issue. Review state: the pinned backup-remote fix and the first legacy host key fix were not re-reviewed after the third local self-review round. The later changes (authority-only case folding with exact keys first, stored-key use in named PAT login and proxy setup, and the Fjord session in the legacy host fixture) got one more local round. Its one Medium is a known limit, below. Known limit: a PAT host configured with a mount path (for example `https://forge.example/forgejo`) plus a pinned `fj.resolved` slug and a clone remote under that mount now fails with the discovery error ("cannot infer the instance") instead of using the default host. This is the same refusal rule as for any unparseable remote; `--host` and `-R` override it. Mount-aware inference is not part of this PR. Size: the PR is 1,308 gross added lines, accepted by the lead. Splitting it now would cost more than it saves. Offline tests only: profile_consumers, auth_profiles, account_override, legacy_host_key, and the config, client::resolve, cli::auth and git unit tests. Live browser behaviour is unchecked.
One authority function now serves remote parsing, preferred-host discovery, routing, cached public destinations and PAT host keys. HTTP 80 and HTTPS 443 normalize to the bare lowercase host; other ports stay distinct; SSH transport ports are dropped.
With fj.resolved pinned, a remote that exists but fails to parse (for example a path-mounted URL) no longer falls back to the default host. A clone with no remote still falls back, and --host and -R remain the overrides.
A valid fallback remote no longer takes over when a higher-priority remote is unparseable. --host keeps the lenient lookup.
Only the remote discovery would select must parse; an unparseable lower-priority backup remote is ignored.
Keep legacy mixed-case host keys reachable and update them on login (#157 step 2b-ii)
Some checks failed
ci / check (pull_request) Failing after 3m36s
ci / coverage (pull_request) Has been skipped
ci / live-e2e (pull_request) Has been skipped
b9e6b9a27e
Lookups match stored host keys ignoring ASCII case (ambiguity refused), and a PAT login for a host that already has an entry under another casing updates that entry in place, so no second entry appears.
gerri requested changes 2026-11-11 01:04:17 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head b9e6b9a27e.

  • Medium src/config/metadata.rs:36, src/cli/context.rs:81,127, src/config/muted.rs:121: Invariant: API credentials, browser destinations and mute state must use the same stored host identity (standards 16 and 17). Client resolution now matches host keys case-insensitively, but these consumers retain exact lookups and the supplied spelling. With a supported legacy LOCALHOST:3000 entry containing web_url = "http://localhost:3000", fj --host localhost:3000 issue list -R o/r --web connects using the stored configuration, then constructs the browser URL from an empty default configuration, opening HTTPS instead. Mute, unmute, muted and inbox filtering likewise use a separate lowercase scope, ignoring existing mutes. Named profiles also lose their metadata on this path; unpinned Fjord discovery can incorrectly filter by the platform host. This belongs in this PR because its new case-insensitive client lookup makes these inconsistent paths reachable. Resolve the stored key once and propagate it through discovery, profile lookup, browser metadata and scope hashing. Extend the legacy-key integration test to cover these consumers.

  • Low (edge case) src/cli/context.rs:122: Invariant: routing, credentials and browser metadata must describe one configuration snapshot. The independently loaded snapshots can mix accounts or instances during a concurrent switch. This is the unchanged concurrency deferral acknowledged in the PR body, not a blocking regression. Follow up by passing one resolved snapshot through client and metadata construction.

BLOCKING: 1

Reviewed head b9e6b9a27e at 2026-11-11T01:04:16Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head b9e6b9a27e8cae6508474e3bee20cbed52564fa0. - **Medium** `src/config/metadata.rs:36`, `src/cli/context.rs:81,127`, `src/config/muted.rs:121`: **Invariant: API credentials, browser destinations and mute state must use the same stored host identity** (standards 16 and 17). Client resolution now matches host keys case-insensitively, but these consumers retain exact lookups and the supplied spelling. With a supported legacy `LOCALHOST:3000` entry containing `web_url = "http://localhost:3000"`, `fj --host localhost:3000 issue list -R o/r --web` connects using the stored configuration, then constructs the browser URL from an empty default configuration, opening HTTPS instead. Mute, unmute, muted and inbox filtering likewise use a separate lowercase scope, ignoring existing mutes. Named profiles also lose their metadata on this path; unpinned Fjord discovery can incorrectly filter by the platform host. This belongs in this PR because its new case-insensitive client lookup makes these inconsistent paths reachable. Resolve the stored key once and propagate it through discovery, profile lookup, browser metadata and scope hashing. Extend the legacy-key integration test to cover these consumers. - **Low** (edge case) `src/cli/context.rs:122`: **Invariant: routing, credentials and browser metadata must describe one configuration snapshot.** The independently loaded snapshots can mix accounts or instances during a concurrent switch. This is the unchanged concurrency deferral acknowledged in the PR body, not a blocking regression. Follow up by passing one resolved snapshot through client and metadata construction. BLOCKING: 1 --- Reviewed head b9e6b9a27e8cae6508474e3bee20cbed52564fa0 at 2026-11-11T01:04:16Z by codex exec (read-only sandbox).
Fix clippy lints in the profile test helpers (#157 step 2b-ii)
All checks were successful
ci / check (pull_request) Successful in 23m15s
ci / coverage (pull_request) Successful in 4m2s
ci / live-e2e (pull_request) Successful in 4m10s
bb7c6f4ed8
gerri requested changes 2026-11-11 01:12:09 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head bb7c6f4ed8.

  • Medium: src/config/metadata.rs:35, src/cli/context.rs:83,127, src/config/muted.rs:121. Invariant: API routing, browser destinations and mute persistence must use the same resolved host identity (standards 11 and 17). The client now matches stored keys ignoring case, but these consumers still perform exact lookups or retain the original flag spelling. With the explicitly supported legacy key FORGE.EXAMPLE and a configured web_url, fj --host forge.example issue list -R o/r --web authenticates using the stored entry but builds the browser URL from an empty default configuration, losing its scheme, port or mount path. The same mismatch splits mute/unmute/muted and inbox filtering into different scopes depending on flag casing. For a Fjord gateway, the discovery lookup can also misclassify it as PAT and reject its instance remote. This belongs in this PR because its new case-insensitive client resolution makes these inconsistent paths reachable. Resolve the stored key once and carry it through discovery, metadata lookup, browser construction and mute hashing. Extend the legacy-key integration test beyond api user to cover these consumers.

  • Low: src/cli/context.rs:126, edge case. Invariant: routing, credentials and browser metadata should describe one configuration snapshot (standard 7). The separately loaded snapshots can mix accounts or instances during a concurrent switch. This is the unchanged concurrency deferral already identified in the PR body; it remains follow-up work.

BLOCKING: 1

Reviewed head bb7c6f4ed8 at 2026-11-11T01:12:08Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head bb7c6f4ed8f6c1e6beff6d27e7745e722d7181f1. - **Medium**: `src/config/metadata.rs:35`, `src/cli/context.rs:83,127`, `src/config/muted.rs:121`. **Invariant: API routing, browser destinations and mute persistence must use the same resolved host identity** (standards 11 and 17). The client now matches stored keys ignoring case, but these consumers still perform exact lookups or retain the original flag spelling. With the explicitly supported legacy key `FORGE.EXAMPLE` and a configured `web_url`, `fj --host forge.example issue list -R o/r --web` authenticates using the stored entry but builds the browser URL from an empty default configuration, losing its scheme, port or mount path. The same mismatch splits mute/unmute/muted and inbox filtering into different scopes depending on flag casing. For a Fjord gateway, the discovery lookup can also misclassify it as PAT and reject its instance remote. This belongs in this PR because its new case-insensitive client resolution makes these inconsistent paths reachable. Resolve the stored key once and carry it through discovery, metadata lookup, browser construction and mute hashing. Extend the legacy-key integration test beyond `api user` to cover these consumers. - **Low**: `src/cli/context.rs:126`, **edge case**. **Invariant: routing, credentials and browser metadata should describe one configuration snapshot** (standard 7). The separately loaded snapshots can mix accounts or instances during a concurrent switch. This is the unchanged concurrency deferral already identified in the PR body; it remains follow-up work. BLOCKING: 1 --- Reviewed head bb7c6f4ed8f6c1e6beff6d27e7745e722d7181f1 at 2026-11-11T01:12:08Z by codex exec (read-only sandbox).
Preserve resolved host identity across browser and mute consumers
Some checks failed
ci / check (pull_request) Failing after 4m58s
ci / coverage (pull_request) Has been skipped
ci / live-e2e (pull_request) Has been skipped
42b54abd1e
gerri requested changes 2026-11-11 01:43:11 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head 42b54abd1e.

  • Medium src/cli/auth_login.rs:1083: Invariant: login and credential lookup must preserve one stored host identity. Lowercasing PAT host keys also affects named login in src/cli/invocation_profiles.rs, which still uses exact lookup and never calls existing_key. With a legacy FORGE.EXAMPLE entry, running fj auth login --host FORGE.EXAMPLE --account alice --with-token now creates forge.example alongside it. Subsequent explicit API, browser and mute commands fail because existing_key rejects the pair as ambiguous. This breaks the supported legacy-to-profile migration and is introduced by this PR’s normalization change. Resolve the stored key in named PAT login before config, credential and profile lookup or publication. Extend legacy_host_key to exercise named login.

  • Low src/config/metadata.rs:73: Edge case. Invariant: authority normalization must preserve case-sensitive URL paths. existing_key compares the entire stored key ignoring case, including mount paths supported by PAT login. With forge.example/Team configured, --host forge.example/team silently selects /Team; if both are configured, lookup refuses them as ambiguous. This affects client resolution, browser shortcuts, mute scopes and legacy PAT login. Compare authorities ignoring case while comparing mount paths exactly.

  • Low src/cli/context.rs:118: Edge case. Invariant: routing, credentials and browser destinations must share one selected-profile snapshot. The separate config loads retain the concurrent-switch risk acknowledged in the PR’s “Concurrency” deferral. No new normal-operation evidence makes that accepted follow-up blocking; resolve all three from one snapshot in that follow-up.

BLOCKING: 1

Reviewed head 42b54abd1e at 2026-11-11T01:43:11Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 42b54abd1ecbe377b30c102f2195e887c176815e. - **Medium** `src/cli/auth_login.rs:1083`: **Invariant: login and credential lookup must preserve one stored host identity.** Lowercasing PAT host keys also affects named login in `src/cli/invocation_profiles.rs`, which still uses exact lookup and never calls `existing_key`. With a legacy `FORGE.EXAMPLE` entry, running `fj auth login --host FORGE.EXAMPLE --account alice --with-token` now creates `forge.example` alongside it. Subsequent explicit API, browser and mute commands fail because `existing_key` rejects the pair as ambiguous. This breaks the supported legacy-to-profile migration and is introduced by this PR’s normalization change. Resolve the stored key in named PAT login before config, credential and profile lookup or publication. Extend `legacy_host_key` to exercise named login. - **Low** `src/config/metadata.rs:73`: **Edge case. Invariant: authority normalization must preserve case-sensitive URL paths.** `existing_key` compares the entire stored key ignoring case, including mount paths supported by PAT login. With `forge.example/Team` configured, `--host forge.example/team` silently selects `/Team`; if both are configured, lookup refuses them as ambiguous. This affects client resolution, browser shortcuts, mute scopes and legacy PAT login. Compare authorities ignoring case while comparing mount paths exactly. - **Low** `src/cli/context.rs:118`: **Edge case. Invariant: routing, credentials and browser destinations must share one selected-profile snapshot.** The separate config loads retain the concurrent-switch risk acknowledged in the PR’s “Concurrency” deferral. No new normal-operation evidence makes that accepted follow-up blocking; resolve all three from one snapshot in that follow-up. BLOCKING: 1 --- Reviewed head 42b54abd1ecbe377b30c102f2195e887c176815e at 2026-11-11T01:43:11Z by codex exec (read-only sandbox).
The gateway case switches the legacy key to a Fjord account, which authenticates with the platform-scoped bearer rather than the PAT.
Fold only the authority when matching stored host keys (#157 step 2b-ii)
Some checks failed
ci / check (pull_request) Successful in 18m0s
ci / coverage (pull_request) Has been cancelled
ci / live-e2e (pull_request) Has been cancelled
fb7bdaf755
An exact key wins and mount paths stay case-sensitive. Named PAT login and proxy setup resolve the stored key too, so neither adds a lowercase twin of a legacy entry.
gerri approved these changes 2026-11-11 01:59:49 +00:00
gerri left a comment

Automated Codex review (read-only) of head fb7bdaf755.

  • Low (edge case), src/config/metadata.rs:73: Invariant: ambiguous stored authorities must be refused consistently. The exact-key return bypasses ambiguity detection. With legacy entries forge.example and FORGE.EXAMPLE, lowercase discovery silently selects the first entry, while explicit uppercase selects the second, potentially using different credentials or profiles. route() also bypasses the check at lines 96 and 102. This affects client resolution, browser routing, mute scopes, PAT/profile login and proxy setup. Fix by checking all authority-folded matches before accepting an exact key, preserving case-sensitive mount paths, and removing routing shortcuts that bypass that check. Add coverage where one ambiguous key exactly matches the input.

  • Low (edge case), src/cli/context.rs:119: Invariant: routing, credentials and browser metadata should use one configuration snapshot. The separately loaded snapshots can disagree during a concurrent account or instance switch. This is the unchanged concurrency deferral already documented under the PR’s “Failure paths”; retain it in the referenced follow-up. The eventual fix should carry one resolved selection through routing, client construction and metadata lookup.

BLOCKING: 0

Reviewed head fb7bdaf755 at 2026-11-11T01:59:49Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head fb7bdaf755b1239b5d3938c47a86284563afd1b6. - **Low** (edge case), `src/config/metadata.rs:73`: **Invariant: ambiguous stored authorities must be refused consistently.** The exact-key return bypasses ambiguity detection. With legacy entries `forge.example` and `FORGE.EXAMPLE`, lowercase discovery silently selects the first entry, while explicit uppercase selects the second, potentially using different credentials or profiles. `route()` also bypasses the check at lines 96 and 102. This affects client resolution, browser routing, mute scopes, PAT/profile login and proxy setup. Fix by checking all authority-folded matches before accepting an exact key, preserving case-sensitive mount paths, and removing routing shortcuts that bypass that check. Add coverage where one ambiguous key exactly matches the input. - **Low** (edge case), `src/cli/context.rs:119`: **Invariant: routing, credentials and browser metadata should use one configuration snapshot.** The separately loaded snapshots can disagree during a concurrent account or instance switch. This is the unchanged concurrency deferral already documented under the PR’s “Failure paths”; retain it in the referenced follow-up. The eventual fix should carry one resolved selection through routing, client construction and metadata lookup. BLOCKING: 0 --- Reviewed head fb7bdaf755b1239b5d3938c47a86284563afd1b6 at 2026-11-11T01:59:49Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.