diff --git a/CHANGELOG.md b/CHANGELOG.md index 0971c9a9..d81bb8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,37 @@ Changes are recorded here before a release version is assigned. ### Changed +- Version 0.94.0: a review that cannot reach its pull request says why, and + the review host form shows how to create a token (ADR-0146). Before, a + start with no review host recorded said only that the address was "not a + pull request address of a recorded review host", a private repository the + token cannot see said "the review host answered with status 404", and a + token refused during the file fetch said "the host keeps refusing or + failing requests". + - With no review host recorded, the start says so, that nothing was sent, + and to add the host and a token under **Settings > Reviews > Review + hosts**. An address no recorded host owns says to check it or add its + host. + - A 401 says the token was refused and should be replaced, a 403 that it + lacks a scope or the organization has not approved or authorized it, and + a 404 that the pull request does not exist or the token cannot see its + repository, which is how GitHub, GitLab, and Bitbucket answer a private + repository. Other statuses keep their number. + - `review_host_failing` names its cause: a refused token, a rate limit, or + ten failed requests in a row. `review_fetch_file` tells the model what a + 401, 403, or 404 means in the same way. + - The **Add host** form shows numbered steps for creating a token on the + chosen kind's host under **Kind** and changes them with the kind; each + host's **Set token…** shows its kind's steps. For GitHub they cover the + repository's owner (the operator's own account or the organization) as + resource owner, selected repositories, Pull requests and Contents read, + an organization's approval, and a classic `repo` token for an outside + collaborator. They are plain text, + dated 2026-12-05; the GitHub and Bitbucket Cloud addresses in them were + not confirmed on the documentation pages read. + - No error code changes, no host text reaches a message, and no host was + contacted: the statuses are tested against loopback fixtures. + - The `settings` window is redesigned as six pages of cards (ADR-0136). The sidebar groups **Connections** and **Chat defaults** under **Chat**, each workspace and **All workspaces** under **Workspaces**, and **Toolchains**, diff --git a/Cargo.lock b/Cargo.lock index 736cc175..1ea6ca25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3666,7 +3666,7 @@ dependencies = [ [[package]] name = "omgcode-app" -version = "0.93.0" +version = "0.94.0" dependencies = [ "base64 0.23.1", "directories", @@ -3685,7 +3685,7 @@ dependencies = [ [[package]] name = "omgcode-cli" -version = "0.93.0" +version = "0.94.0" dependencies = [ "clap", "gix", @@ -3699,7 +3699,7 @@ dependencies = [ [[package]] name = "omgcode-core" -version = "0.93.0" +version = "0.94.0" dependencies = [ "base64 0.23.1", "bytes", @@ -3723,7 +3723,7 @@ dependencies = [ [[package]] name = "omgcode-desktop" -version = "0.93.0" +version = "0.94.0" dependencies = [ "omgcode-app", "omgcode-platform", @@ -3737,7 +3737,7 @@ dependencies = [ [[package]] name = "omgcode-platform" -version = "0.93.0" +version = "0.94.0" dependencies = [ "libc", "rustix", diff --git a/Cargo.toml b/Cargo.toml index 883e51c8..825cabb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/omgcode-core", "crates/omgcode-cli", "crates/omgcode-platform", "crates/omgcode-app", "crates/omgcode-desktop"] [workspace.package] -version = "0.93.0" +version = "0.94.0" edition = "2024" rust-version = "1.99.1" license = "Apache-2.0" diff --git a/crates/omgcode-app/src/desktop/reviews/tests.rs b/crates/omgcode-app/src/desktop/reviews/tests.rs index f856ba98..e537b442 100644 --- a/crates/omgcode-app/src/desktop/reviews/tests.rs +++ b/crates/omgcode-app/src/desktop/reviews/tests.rs @@ -1430,7 +1430,13 @@ fn a_start_for_an_address_no_host_recognises_fails_with_a_fixed_text() { assert_eq!(view.state, ReviewOperationState::Failed); let error = view.error.expect("an error"); assert_eq!(error.code, "review_address_unrecognised"); - assert_eq!(error.message, UrlRefusal::Unrecognised.reason()); + // Core's fixed text says nothing was sent and where a host is added (ADR-0146). + assert!( + error.message.contains("nothing was sent") + && error.message.contains("Settings > Reviews > Review hosts"), + "{}", + error.message + ); for text in [&error.code, &error.message] { assert!(!text.contains("example.invalid") && !text.contains("secret-value")); } @@ -1837,7 +1843,12 @@ fn a_failed_start_reports_core_s_fixed_code_and_text_only() { ( StartError::Status(404), "review_host_not_found", - "the review host answered with status 404", + "the review host answered 404: the pull request does not exist, or the token cannot see its repository (a private repository the token has no access to answers 404)", + ), + ( + StartError::Status(502), + "review_host_server_error", + "the review host answered with status 502", ), ( StartError::Malformed, diff --git a/crates/omgcode-core/src/review/error.rs b/crates/omgcode-core/src/review/error.rs index f3d1ad8c..f9fc5099 100644 --- a/crates/omgcode-core/src/review/error.rs +++ b/crates/omgcode-core/src/review/error.rs @@ -1,6 +1,8 @@ //! Why a review step failed. Each reason has a stable code, and none carries //! text from a host, a path, a URL, or the token. +use std::borrow::Cow; + use thiserror::Error; use crate::review_host::ReviewHostError; @@ -11,8 +13,10 @@ pub enum ReviewError { /// The client failed before a status arrived. #[error("the review host request failed: {}", .0.code())] Host(ReviewHostError), - /// The host answered with a status the step cannot use. - #[error("the review host answered with status {0}")] + /// The host answered with a status the step cannot use. A 401, 403, or 404 + /// says what it usually means for a token, because a host answers a + /// private repository that the token cannot see with 404, not 401. + #[error("{}", status_text(*.0))] Status(u16), /// The host kept asking the client to wait, or asked for too long a wait. #[error("the review host rate limit was reached")] @@ -62,3 +66,47 @@ impl From for ReviewError { } } } + +/// What the operator is told about a 401. +pub(crate) const UNAUTHORIZED_TEXT: &str = "the review host refused the token (status 401): it is wrong, expired, or revoked; set a new token for the host in Settings > Reviews > Review hosts"; +/// What the operator is told about a 403. +pub(crate) const FORBIDDEN_TEXT: &str = "the review host refused access (status 403): the token lacks a scope the review needs, or the repository's organization has not approved or authorized it"; +/// What the operator is told about a 404. GitHub, GitLab, and Bitbucket answer +/// a private repository that the token cannot see as if it did not exist. +pub(crate) const NOT_FOUND_TEXT: &str = "the review host answered 404: the pull request does not exist, or the token cannot see its repository (a private repository the token has no access to answers 404)"; + +/// The text of a status. It holds no text from the host. +fn status_text(status: u16) -> Cow<'static, str> { + match status { + 401 => Cow::Borrowed(UNAUTHORIZED_TEXT), + 403 => Cow::Borrowed(FORBIDDEN_TEXT), + 404 => Cow::Borrowed(NOT_FOUND_TEXT), + other => Cow::Owned(format!("the review host answered with status {other}")), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn an_access_status_says_it_is_about_the_token_and_others_give_the_number() { + let unauthorized = ReviewError::Status(401).to_string(); + assert!(unauthorized.contains("status 401"), "{unauthorized}"); + assert!(unauthorized.contains("refused the token"), "{unauthorized}"); + let forbidden = ReviewError::Status(403).to_string(); + assert!(forbidden.contains("status 403"), "{forbidden}"); + assert!(forbidden.contains("lacks a scope"), "{forbidden}"); + let missing = ReviewError::Status(404).to_string(); + assert!(missing.contains("404"), "{missing}"); + assert!(missing.contains("cannot see its repository"), "{missing}"); + assert_eq!( + ReviewError::Status(418).to_string(), + "the review host answered with status 418" + ); + // The codes are unchanged. + assert_eq!(ReviewError::Status(401).code(), "review_host_unauthorized"); + assert_eq!(ReviewError::Status(403).code(), "review_host_forbidden"); + assert_eq!(ReviewError::Status(404).code(), "review_host_not_found"); + } +} diff --git a/crates/omgcode-core/src/review/fetch.rs b/crates/omgcode-core/src/review/fetch.rs index 09b41031..bc245b53 100644 --- a/crates/omgcode-core/src/review/fetch.rs +++ b/crates/omgcode-core/src/review/fetch.rs @@ -193,15 +193,22 @@ pub fn fetch_review( continue; } failures += 1; - if matches!( - record.code.as_deref(), - Some("review_host_unauthorized" | "review_host_rate_limited") - ) || failures >= MAX_CONSECUTIVE_FAILURES - { - return Err(ReviewError::Refused( - "review_host_failing", - "the host keeps refusing or failing requests", - )); + // The code stays `review_host_failing`; the text keeps the cause, + // so a refused token is not reported as a failing host. + let stop = match record.code.as_deref() { + Some("review_host_unauthorized") => Some( + "the review host refused the token while the files were fetched (status 401); set a new token for the host in Settings > Reviews > Review hosts", + ), + Some("review_host_rate_limited") => Some( + "the review host's rate limit stopped the file fetch; start the review again later", + ), + _ if failures >= MAX_CONSECUTIVE_FAILURES => Some( + "ten file requests in a row failed; the host keeps refusing or failing requests", + ), + _ => None, + }; + if let Some(text) = stop { + return Err(ReviewError::Refused("review_host_failing", text)); } } else { failures = 0; diff --git a/crates/omgcode-core/src/review/fetch_tests.rs b/crates/omgcode-core/src/review/fetch_tests.rs index ab8dfc75..1cfb8bae 100644 --- a/crates/omgcode-core/src/review/fetch_tests.rs +++ b/crates/omgcode-core/src/review/fetch_tests.rs @@ -414,6 +414,10 @@ fn an_unauthorised_blob_ends_the_fetch_instead_of_recording_every_file_as_failed ); let error = run.output.as_ref().unwrap_err(); assert_eq!(error.code(), "review_host_failing"); + // The operator is told that the token was refused, not that the host fails. + let text = error.to_string(); + assert!(text.contains("refused the token"), "{text}"); + assert!(text.contains("status 401"), "{text}"); assert!(!run.folder.join("review.json").exists()); } diff --git a/crates/omgcode-core/src/review/start.rs b/crates/omgcode-core/src/review/start.rs index 9a03e034..15e0ec3c 100644 --- a/crates/omgcode-core/src/review/start.rs +++ b/crates/omgcode-core/src/review/start.rs @@ -35,6 +35,11 @@ use crate::session::{ReviewStarted, SessionError, SessionJournal}; use crate::skills::SkillName; use crate::turn::CancelToken; +/// The refusal when no review host is recorded at all: nothing was sent. +pub(crate) const NO_HOST_TEXT: &str = "no review host is recorded, so nothing was sent; add the code host and a token for it in Settings > Reviews > Review hosts, then start the review again"; +/// The refusal when hosts are recorded but none owns the address. +pub(crate) const UNMATCHED_TEXT: &str = "the address is not a pull request address of a recorded review host, so nothing was sent; check the address, or add its host in Settings > Reviews > Review hosts"; + /// How old an unrecorded review folder must be before a start deletes it. const ORPHAN_AGE: Duration = Duration::from_secs(24 * 60 * 60); /// The most entries of the reviews folder one sweep looks at. @@ -152,15 +157,20 @@ fn plan(request: &StartRequest<'_>, make_client: MakeClient<'_>) -> Result "review_address_unrecognised", - super::url::UrlRefusal::Ambiguous => "review_address_ambiguous", - }, - refusal.reason(), - ) - })?; + let parsed = + parse_pull_request_url(request.address, &hosts).map_err(|refusal| match refusal { + // Nothing has been sent, so the text says what to record, not what a + // host answered. + super::url::UrlRefusal::Unrecognised if hosts.is_empty() => { + ReviewError::Refused("review_address_unrecognised", NO_HOST_TEXT) + } + super::url::UrlRefusal::Unrecognised => { + ReviewError::Refused("review_address_unrecognised", UNMATCHED_TEXT) + } + super::url::UrlRefusal::Ambiguous => { + ReviewError::Refused("review_address_ambiguous", refusal.reason()) + } + })?; let status = store .review_hosts() .iter() diff --git a/crates/omgcode-core/src/review/start_tests.rs b/crates/omgcode-core/src/review/start_tests.rs index d30639d5..090bdee9 100644 --- a/crates/omgcode-core/src/review/start_tests.rs +++ b/crates/omgcode-core/src/review/start_tests.rs @@ -351,11 +351,39 @@ fn an_address_no_recorded_host_matches_is_refused() { ] { let error = start(&fixture, address, &CancelToken::new(), |_| Ok(())).expect_err("refused"); assert_eq!(error.code(), "review_address_unrecognised", "{address}"); + let text = error.to_string(); + assert!(text.contains("nothing was sent"), "{text}"); + assert!(text.contains("Review hosts"), "{text}"); } assert!(entries(&root(&fixture)).is_empty()); assert!(fixture.host.targets().is_empty()); } +#[test] +fn with_no_recorded_host_the_refusal_says_to_add_one() { + let fixture = github_fixture(); + let mut store = ControlStore::open(&fixture.data).expect("control store"); + let revision = store.revision(); + // The removal's report is not needed: only the missing record matters here. + let _removal = store + .unbind_review_host("work", revision) + .expect("removal recorded") + .finish(&fixture.credentials); + drop(store); + let error = start( + &fixture, + "https://github.com/o/r/pull/7", + &CancelToken::new(), + |_| Ok(()), + ) + .expect_err("refused"); + assert_eq!(error.code(), "review_address_unrecognised"); + let text = error.to_string(); + assert!(text.starts_with("no review host is recorded"), "{text}"); + assert!(text.contains("add the code host and a token"), "{text}"); + assert!(fixture.host.targets().is_empty(), "nothing was sent"); +} + #[test] fn a_cancel_during_the_fetch_leaves_no_folder_record_or_ledger() { let cancel = CancelToken::new(); diff --git a/crates/omgcode-core/src/review/tools.rs b/crates/omgcode-core/src/review/tools.rs index 72d2e8e9..4308708a 100644 --- a/crates/omgcode-core/src/review/tools.rs +++ b/crates/omgcode-core/src/review/tools.rs @@ -587,6 +587,20 @@ fn refuse_for(error: ReviewError) -> ToolRefusal { "the host's rate limit was reached; try again later", ), ReviewError::Refused(code, text) => refuse(code, text), + // The model is told what an access status means, so it can tell the + // operator that the token, not the file, is the problem. + ReviewError::Status(401) => refuse( + "review_host_unauthorized", + "the host refused the review host's token (status 401); the operator must set a new token for the host", + ), + ReviewError::Status(403) => refuse( + "review_host_forbidden", + "the host refused access to the file (status 403); the token may lack a scope the review needs", + ), + ReviewError::Status(404) => refuse( + "review_host_not_found", + "the host answered 404: the file is not at that commit, or the token cannot see the repository", + ), other => refuse(other.code(), "the host did not return the file"), } } diff --git a/crates/omgcode-core/src/review/tools_tests.rs b/crates/omgcode-core/src/review/tools_tests.rs index 2964a15f..9f7f60d0 100644 --- a/crates/omgcode-core/src/review/tools_tests.rs +++ b/crates/omgcode-core/src/review/tools_tests.rs @@ -524,6 +524,32 @@ fn a_path_over_the_recorded_limit_is_refused_before_the_host_or_the_ledger_is_to assert_eq!(fetch(&mut fixture, &exact), Err("path_not_in_tree")); } +#[test] +fn a_404_tells_the_model_the_token_may_not_see_the_repository() { + let mut fixture = fixture(Vec::new()); + let client = fixture.host.client(ReviewHostKind::GitHub); + let manifest = manifest(); + let cancel = CancelToken::new(); + let ledger = ledger_path(&fixture.root, fixture.id); + let refusal = fetch_on_demand( + OnDemand { + folder: &mut fixture.folder, + manifest: &manifest, + client: &client, + ledger_path: &ledger, + cancel: &cancel, + }, + "big.bin", + ) + .expect_err("the host answers 404"); + assert_eq!(refusal.code, "review_host_not_found"); + assert!( + refusal.text.contains("token cannot see the repository"), + "{}", + refusal.text + ); +} + #[test] fn the_call_and_byte_budgets_stop_fetches_and_failed_calls_count() { let mut fixture = fixture(Vec::new()); diff --git a/crates/omgcode-desktop/ui/src/settings/review_hosts_section.ts b/crates/omgcode-desktop/ui/src/settings/review_hosts_section.ts index 5e3c4d6d..8b450078 100644 --- a/crates/omgcode-desktop/ui/src/settings/review_hosts_section.ts +++ b/crates/omgcode-desktop/ui/src/settings/review_hosts_section.ts @@ -26,8 +26,46 @@ interface KindInfo { credential: string; read: string; post: string; + /** How to create the token on the host, in the order the host's own pages take. */ + steps: ReadonlyArray; } +/** Said under every kind's steps (ADR-0146). */ +export const TOKEN_STEPS_NOTE = + "These steps follow each host’s documentation as read on 2026-12-05; a host can change its pages. OMGCode never opens them for you."; + +const GITHUB_STEPS: ReadonlyArray = [ + "Open github.com/settings/personal-access-tokens/new (Settings > Developer settings > Personal access tokens > Fine-grained tokens > Generate new token).", + "Enter a name and choose an expiration.", + "Resource owner: choose whoever owns the repository: your own account for a personal repository, or the organization for an organization's repository.", + "Repository access: choose Only select repositories, then pick the repositories to review.", + "Repository permissions: Pull requests Read and Contents Read (Pull requests Write to post).", + "Select Generate token and copy it. If the owner is an organization that requires approval, the token reads only public repositories until an organization owner approves it.", + "An outside collaborator on an organization's repository cannot choose that organization: use Tokens (classic) > Generate new token (classic) with the repo scope instead, if the organization allows classic tokens.", + "A private repository the token cannot see answers 404, not 401: check the owner, the repositories, and the approval.", +]; +const GITHUB_ENTERPRISE_STEPS: ReadonlyArray = [ + "Open /settings/personal-access-tokens/new (Settings > Developer settings > Personal access tokens > Fine-grained tokens).", + "Enter a name and an expiration, choose the repository's owner (your own account or its organization) as the resource owner, and Only select repositories.", + "Grant Pull requests Read and Contents Read (Pull requests Write to post), then select Generate token and copy it.", + "A server without fine-grained tokens, or an outside collaborator on an organization's repository: use Tokens (classic) > Generate new token (classic) with the repo scope, if the organization allows it.", + "If the owner is an organization that requires approval, the token works only after an organization owner approves it. A private repository it cannot see answers 404.", +]; +const gitlabSteps = (origin: string): ReadonlyArray => [ + `Open ${origin}/-/user_settings/personal_access_tokens (your avatar > Edit profile > Access > Personal access tokens).`, + "Start a new token (where the page offers a choice, Generate token > Legacy token).", + "Enter a name and an expiration date (at most 365 days unless an administrator changed it).", + "Select the read_api scope (api to post), then select Generate token.", + "Copy the token now: it is shown once. A project or group access token with the same scope also works.", +]; +const azureSteps = (portal: string, scope: string): ReadonlyArray => [ + `Sign in at ${portal}, open User settings (the icon beside your picture) > Personal access tokens.`, + "Select New Token.", + `Enter a name, choose ${scope}, and set an expiration date.`, + "Scopes: Custom defined, then Code: Read (to post, also the pull request threads scope).", + "Select Create and copy the token: it is shown once.", +]; + const GITHUB_CREDENTIAL = "Fine-grained personal access token; a classic repo token where a server does not support fine-grained tokens"; const GITHUB_READ = "Pull requests: read; Contents: read"; @@ -49,6 +87,7 @@ const KINDS: Readonly> = { credential: GITHUB_CREDENTIAL, read: GITHUB_READ, post: GITHUB_POST, + steps: GITHUB_STEPS, }, github_enterprise: { label: "GitHub Enterprise Server", @@ -57,6 +96,7 @@ const KINDS: Readonly> = { credential: GITHUB_CREDENTIAL, read: GITHUB_READ, post: GITHUB_POST, + steps: GITHUB_ENTERPRISE_STEPS, }, gitlab: { label: "GitLab", @@ -65,6 +105,7 @@ const KINDS: Readonly> = { credential: GITLAB_CREDENTIAL, read: "read_api", post: "api", + steps: gitlabSteps("gitlab.com"), }, gitlab_self_managed: { label: "GitLab (self-managed)", @@ -73,6 +114,7 @@ const KINDS: Readonly> = { credential: GITLAB_CREDENTIAL, read: "read_api", post: "api", + steps: gitlabSteps(""), }, azure_devops: { label: "Azure DevOps Services", @@ -81,6 +123,10 @@ const KINDS: Readonly> = { credential: AZURE_CREDENTIAL, read: AZURE_READ, post: AZURE_POST, + steps: azureSteps( + "dev.azure.com/", + "this one organization (not All accessible organizations)", + ), }, azure_devops_server: { label: "Azure DevOps Server", @@ -89,6 +135,10 @@ const KINDS: Readonly> = { credential: AZURE_CREDENTIAL, read: AZURE_READ, post: AZURE_POST, + steps: [ + ...azureSteps("", "the collection"), + "The server's IIS Basic authentication must stay disabled, or the token is refused.", + ], }, bitbucket_cloud: { label: "Bitbucket Cloud", @@ -98,6 +148,13 @@ const KINDS: Readonly> = { "API token with scopes; Atlassian announced that app passwords would be permanently disabled on 2026-06-09", read: "read:pullrequest:bitbucket, read:repository:bitbucket", post: "write:pullrequest:bitbucket (unconfirmed)", + steps: [ + "Open id.atlassian.com/manage-profile/security/api-tokens (Atlassian account > Security > Create and manage API tokens).", + "Select Create API token with scopes, enter a name and an expiry date, then select Next.", + "Choose Bitbucket as the app, then select Next.", + "Select read:pullrequest:bitbucket and read:repository:bitbucket (write:pullrequest:bitbucket to post), then Create token.", + "Copy the token now: it is shown once. An app password is not accepted.", + ], }, bitbucket_data_center: { label: "Bitbucket Data Center", @@ -106,6 +163,13 @@ const KINDS: Readonly> = { credential: "HTTP access token", read: "Repository read", post: "Repository read", + steps: [ + "In Bitbucket, open your profile picture > Manage account > HTTP access tokens.", + "Select Create token and enter a name.", + "Permissions: Repository read. Set an expiry if you want one: it cannot be changed later.", + "Select Create and copy the token: it is shown once.", + "A project or repository administrator can instead create one under Project or Repository settings > HTTP access tokens.", + ], }, }; @@ -171,6 +235,21 @@ function scopesInfo(kind: ReviewHostKind): HTMLElement { ); } +/** The steps that create a token on a kind's host, as plain text: nothing here is a link. */ +function tokenSteps(kind: ReviewHostKind): HTMLElement { + const list = el("ol", {}); + for (const step of kindInfo(kind).steps) { + list.append(el("li", { text: step })); + } + return el( + "div", + { class: "field token-steps" }, + el("p", { text: `How to create a ${kindInfo(kind).label} token` }), + list, + el("p", { class: "muted", text: TOKEN_STEPS_NOTE }), + ); +} + /** The add form, shown after the header button opens it. The token is never kept in view state. */ function addForm({ view, submit, actions, rerender }: SectionContext): HTMLElement { const draft = view.reviewHostDraft; @@ -213,6 +292,7 @@ function addForm({ view, submit, actions, rerender }: SectionContext): HTMLEleme const baseUrlField = labelled("Base URL", "new-review-host-base-url", baseUrl); const organizationField = labelled("Organization", "new-review-host-organization", organization); const scopes = el("div", { class: "field" }); + const steps = el("div", {}); // Shows the fields the chosen kind takes. They are hidden, not rebuilt, so what was typed stays. const arrange = (): void => { const chosen = kind.value as ReviewHostKind; @@ -222,6 +302,7 @@ function addForm({ view, submit, actions, rerender }: SectionContext): HTMLEleme baseUrl.placeholder = info.takes === "base_url" ? info.example : ""; organization.placeholder = info.takes === "organization" ? info.example : ""; replaceChildren(scopes, scopesInfo(chosen)); + replaceChildren(steps, tokenSteps(chosen)); }; const remember = (): void => { view.reviewHostDraft = { @@ -271,6 +352,7 @@ function addForm({ view, submit, actions, rerender }: SectionContext): HTMLEleme "div", { class: "form" }, labelled("Kind", "new-review-host-kind", kind), + steps, labelled("Name", "new-review-host-name", name), baseUrlField, organizationField, @@ -308,6 +390,7 @@ function setTokenDisclosure( class: "muted", text: "Replaces the stored token. It is sent once, then cleared, and is never shown again. It goes only to this host’s REST address.", }), + tokenSteps(host.kind), el("div", { class: "form" }, token.field, el("div", { class: "row-actions" }, save)), ); } diff --git a/crates/omgcode-desktop/ui/tests/settings_review_hosts.test.ts b/crates/omgcode-desktop/ui/tests/settings_review_hosts.test.ts index 9e463759..cd85acd7 100644 --- a/crates/omgcode-desktop/ui/tests/settings_review_hosts.test.ts +++ b/crates/omgcode-desktop/ui/tests/settings_review_hosts.test.ts @@ -7,8 +7,10 @@ import { HOSTILE } from "../src/mock/fixtures"; import { type SettingsApp, startSettings } from "../src/settings/app"; import { ADD_REVIEW_HOST_LABEL, + kindInfo, REVIEW_HOST_KINDS, SCOPES_NOTE, + TOKEN_STEPS_NOTE, UNREADABLE_NOTE, } from "../src/settings/review_hosts_section"; import { @@ -401,6 +403,42 @@ describe("adding a review host", () => { choose(kindSelect(), "bitbucket_data_center"); expect(form()).toContain("HTTP access token"); }); + + it("shows how to create a token on the chosen kind's host, and changes with the kind (ADR-0146)", async () => { + await start(() => overview([])); + openForm(); + const steps = (): HTMLElement => { + const found = root.querySelector("section.block .form .token-steps"); + if (!(found instanceof HTMLElement)) { + throw new Error("No token steps"); + } + return found; + }; + // GitHub is the first kind, so its steps show before any choice. + expect(steps().textContent).toContain("How to create a GitHub token"); + // The owner may be the operator's own account or an organization. + expect(steps().textContent).toContain("your own account for a personal repository"); + expect(steps().textContent).toContain("the organization for an organization's repository"); + expect(steps().textContent).toContain("If the owner is an organization that requires approval"); + // An outside collaborator cannot use a fine-grained token for the organization's repository. + expect(steps().textContent).toContain("An outside collaborator"); + expect(steps().textContent).toContain("Generate new token (classic) with the repo scope"); + expect(steps().textContent).toContain("answers 404, not 401"); + expect(steps().textContent).toContain(TOKEN_STEPS_NOTE); + // Every step is plain text: nothing in the list is a link. + expect(steps().querySelector("a")).toBeNull(); + for (const kind of REVIEW_HOST_KINDS) { + choose(kindSelect(), kind); + expect(steps().querySelectorAll("li").length).toBe(kindInfo(kind).steps.length); + expect(kindInfo(kind).steps.length).toBeGreaterThanOrEqual(4); + expect(steps().textContent).toContain(`How to create a ${kindInfo(kind).label} token`); + } + choose(kindSelect(), "gitlab"); + expect(steps().textContent).toContain("gitlab.com/-/user_settings/personal_access_tokens"); + expect(steps().textContent).toContain("read_api"); + choose(kindSelect(), "azure_devops"); + expect(steps().textContent).toContain("not All accessible organizations"); + }); }); describe("a recorded review host", () => { diff --git a/docs/adr/0146-say-why-a-review-could-not-reach-its-pull-request-and-show-how-to-create-a-token.md b/docs/adr/0146-say-why-a-review-could-not-reach-its-pull-request-and-show-how-to-create-a-token.md new file mode 100644 index 00000000..9249e356 --- /dev/null +++ b/docs/adr/0146-say-why-a-review-could-not-reach-its-pull-request-and-show-how-to-create-a-token.md @@ -0,0 +1,102 @@ +# 0146: Say why a review could not reach its pull request, and show how to create a token + +- Status: Accepted +- Date: 2026-12-05 + +## Context + +The first real use of **New Review** (0.93.0) was a pull request in a private +GitHub repository. No review host was recorded, so the start stopped before +any request with "the address is not a pull request address of a recorded +review host". The operator read that as a failure to reach GitHub and could +not tell that the cause was configuration, not authentication. A chat session +that tried the same address with `web_fetch` got a plain 404, which said more. + +Even with a host recorded, the texts did not help: + +- GitHub, GitLab, and Bitbucket answer a private repository that a token + cannot see with 404, as if it did not exist. Core reported "the review host + answered with status 404", with nothing about the token. +- A 401 on a file during the fetch ended the start with "the host keeps + refusing or failing requests" (`review_host_failing`), which hid that the + token was refused. +- `review_fetch_file` told the model "the host did not return the file" for a + 401, 403, or 404, so the model could not tell the operator that the token was + the problem. +- The **Add host** form named the scopes behind an information button but not + how to create a token. A GitHub fine-grained token for an organization's + repository needs that organization as its resource owner and may need an + owner's approval; until then the token reads public repositories only, and + the review sees a 404. + +## Decision + +1. **Status texts say what an access status usually means.** + `ReviewError::Status` keeps its codes. Its text for 401 says the token was + refused and names **Settings > Reviews > Review hosts**; for 403 that the + token lacks a scope or the organization has not approved or authorized it; + for 404 that the pull request does not exist or the token cannot see its + repository. Other statuses keep "the review host answered with status N". +2. **An unowned address says nothing was sent.** `review_address_unrecognised` + keeps its code. With no host recorded its text says so and tells the + operator to add the host and a token; with hosts recorded it says to check + the address or add its host. `UrlRefusal`'s own reason is unchanged. +3. **`review_host_failing` keeps its cause.** The code is unchanged, and the + text names a refused token (401), a rate limit, or ten failed requests in a + row. +4. **The model gets the same meaning.** `review_fetch_file` answers 401, 403, + and 404 with texts that say the token may be the cause. +5. **The form shows how to create a token.** Each review host kind carries 4 + to 7 numbered steps, shown under the **Kind** select of the add form and + changed with the kind, and in each host's **Set token…**. They are plain text + with no link, dated 2026-12-05, and drawn from the hosts' documentation: + GitHub (fine-grained token, the repository's owner as resource owner, + which is the operator's own account for a personal repository and the + organization otherwise, selected repositories, Pull requests and Contents + read, approval only where an organization requires it, and a classic `repo` + token for an outside collaborator, who cannot choose the organization as a + fine-grained token's owner), GitHub Enterprise Server (the same, or a + classic `repo` token on an older server), GitLab and + self-managed GitLab (`read_api`), Azure DevOps Services (one organization, + Code read) and Server (the collection, IIS Basic authentication off), + Bitbucket Cloud (API token with scopes), and Bitbucket Data Center (HTTP + access token, Repository read). + +No text carries a host's words, the address, a path, or the token, as +ADR-0144 requires. + +The GitHub and Bitbucket Cloud token addresses in the steps were not on the +documentation pages read and are unverified. The GitLab address pattern is +documented. Azure DevOps and Bitbucket Data Center are given by menu path +only. Azure DevOps scope labels on the token page were not confirmed. + +## Alternatives considered + +- **New codes for each case.** A new code for "no host recorded" or for the + cause of `review_host_failing` would let the interface react to it, but it + changes a stable code that tests, the mock, and the contract name. The text + carries the meaning; a code can follow if the dialog grows a button for it. +- **Pass the host's error body through.** It would be the most specific, but + it is host-chosen text in the operator's dialog and the model's context, + which ADR-0144 rules out. +- **Links to each host's token page.** The settings webview opens nothing, + and a link would be the first control there that leaves the application. + The steps name the page as text. +- **A built-in `github.com` host that uses the operator's `gh` sign-in.** It + would remove the setup step, but core would read a credential it did not + store. That is a separate decision. + +## Consequences + +- An operator who has not recorded a host is told what to do, and a 404 on a + private repository points at the token and the organization's approval. +- The texts are longer. The dialog shows them in full. +- The steps go stale when a host changes its pages. Each kind's steps carry + the date they were read, and nothing checks them. +- No host was contacted for this change. The status mapping is tested with + loopback fixtures only. + +## References + +- [Pull request reviews](../reviews.md) +- ADR-0141, ADR-0143, ADR-0144, ADR-0145 diff --git a/docs/adr/index.md b/docs/adr/index.md index 6fdc9d16..47833dbf 100644 --- a/docs/adr/index.md +++ b/docs/adr/index.md @@ -160,3 +160,4 @@ meaningful alternative does not need an ADR. | [0143: Record review hosts with a token each and an HTTPS client for their REST origin](0143-record-review-hosts-with-a-token-each-and-an-https-client-for-their-rest-origin.md) | Accepted | 2026-12-03 | | [0144: Fetch reviews from GitHub into isolated review folders and run review sessions](0144-fetch-reviews-from-github-into-isolated-review-folders-and-run-review-sessions.md) | Accepted | 2026-12-04 | | [0145: Fetch reviews from GitLab, Azure DevOps, and Bitbucket](0145-fetch-reviews-from-gitlab-azure-devops-and-bitbucket.md) | Accepted | 2026-12-04 | +| [0146: Say why a review could not reach its pull request, and show how to create a token](0146-say-why-a-review-could-not-reach-its-pull-request-and-show-how-to-create-a-token.md) | Accepted | 2026-12-05 | diff --git a/docs/desktop-interface.md b/docs/desktop-interface.md index b797fa34..0c7f7fc6 100644 --- a/docs/desktop-interface.md +++ b/docs/desktop-interface.md @@ -2001,7 +2001,9 @@ waits. The window shows: write-only password field for the token. The form does not show a fixed cloud address: the native confirmation names the derived REST origin. The scopes the kind's documentation recommends sit behind an information button, - and say OMGCode cannot check them. **Add host** sends + and say OMGCode cannot check them. Under the kind select, numbered plain-text + steps say how to create a token on that kind's host and change with the + kind; each host's **Set token…** shows them too (ADR-0146). **Add host** sends `settings_add_review_host`. Rust checks every field's shape and length and the token's form before any dialog, so a bad field, a duplicate host, or a token with a space opens none. A native confirmation then names the kind, diff --git a/docs/reviews.md b/docs/reviews.md index a7e5f0d1..dfc08ca8 100644 --- a/docs/reviews.md +++ b/docs/reviews.md @@ -707,7 +707,15 @@ two pages. Increment 2 added the group with **Review skills**, and increment 3 - **Review hosts**: **Add host…** in the page header and one card per host with its name, kind, REST origin, organization, whether its token is readable, the - recommended scopes behind the information button, and **Remove…**. + recommended scopes behind the information button, and **Remove…**. The + add form shows numbered steps for creating a token on the chosen kind's + host under the **Kind** select and changes them with the kind, and each + host's **Set token…** shows its kind's steps (ADR-0146). The steps are + plain text with no link and follow each host's documentation as read on + 2026-12-05. The menu path is from that documentation. The GitLab address + pattern is documented; the GitHub and Bitbucket Cloud addresses were not on + the pages read and are unverified, and Azure DevOps and Bitbucket Data + Center get the menu path only. - **Review skills**: **Import review skill…** in the page header, which opens a native folder dialog and imports with the `review` purpose, disabled. Each skill has the application enablement select, confirmed natively before it @@ -815,7 +823,19 @@ list is authoritative for increment 4a. ADR-0144 records the reasons. a 502 to 504 are retried at most five times. A wait over 60 seconds ends the fetch with `review_host_rate_limited`. Each attempt counts against the 6,000 requests. A 401, a rate limit, or ten failed versions in a row end the fetch - with `review_host_failing`. + with `review_host_failing`, whose text names which of the three it was + ([ADR-0146](adr/0146-say-why-a-review-could-not-reach-its-pull-request-and-show-how-to-create-a-token.md)). +- **Failure text.** The start dialog shows core's text and code. The text + says what an access status usually means, because GitHub, GitLab, and + Bitbucket answer a private repository the token cannot see with 404, not + 401: a 401 says the token was refused and should be replaced, a 403 that the + token lacks a scope or the organization has not approved or authorized it, + and a 404 that the pull request does not exist or the token cannot see its + repository. An address that no recorded host owns says that nothing was + sent and names **Settings > Reviews > Review hosts**, with its own text when + no host is recorded at all. `review_fetch_file` gives the model the same + meaning for 401, 403, and 404. The codes are unchanged, and no text holds + the host's words, the address, or the token (ADR-0146). - **On-demand fetch budget.** `review_fetch_file` is limited to 500 calls and 64 MiB for a review, counted in `reviews-v1/.ledger`. A damaged ledger refuses the call instead of resetting the count. A path over 256 bytes is