Repository navigation
fix: reconcile release quality checks, diagnostics and docs #2196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce7c635
709b4ce
70e9e76
2623f56
7beede4
ed8b375
4ea46a7
23b1702
fc3686d
aa6edce
a6e30be
85ec7ec
2a5deb4
cf6d0eb
5f02944
2ed752e
6e6c032
a4b467b
83cd988
6928327
9e0fae2
d0896e2
497b181
e0f4b36
6a7602b
cc71c46
57752e2
a6eb8bf
001980f
3bac756
8a74da2
0cbab9d
f6450a8
ed829b2
a18f003
62c479e
2a3e4e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,12 +223,16 @@ fn choose_provider(args: &[String], env: &Environment, saved: Option<&Saved>) -> | |
| /// Builds a request's configuration without reading unrelated credentials during management. | ||
| /// A prompt may use the desktop's API key for its provider and address; model listing uses | ||
| /// only environment API keys, so `--models` never prompts for a saved API key. | ||
| fn configuration(provider: &str, args: &[String], env: &Environment, saved: Option<&Saved>) -> Config { | ||
| fn configuration(provider: &str, args: &[String], env: &Environment, saved: Option<&Saved>) -> Result<Config, String> { | ||
| let mut cfg = (env.config)(provider); | ||
| if cfg.login() | ||
| && let Some(c) = rustgis_assistant::chatgpt::load_any() | ||
| { | ||
| cfg.sign_in(&c); | ||
| if cfg.login() { | ||
| let (credentials, warning) = rustgis_assistant::chatgpt::load_any_report(); | ||
| if let Some(warning) = warning { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behaviour change beyond the refused-store case (question, ~40% confidence). |
||
| return Err(format!("could not read saved ChatGPT sign-ins: {warning}")); | ||
| } | ||
| if let Some(c) = credentials { | ||
| cfg.sign_in(&c); | ||
| } | ||
| } | ||
| if let Some(m) = opt(args, "--model").map(str::to_string).or_else(|| env.model.clone()) { | ||
| cfg.model = m; | ||
|
|
@@ -243,7 +247,7 @@ fn configuration(provider: &str, args: &[String], env: &Environment, saved: Opti | |
| { | ||
| cfg.key = key.expose().to_string(); | ||
| } | ||
| cfg | ||
| Ok(cfg) | ||
| } | ||
|
|
||
| const NEEDS_REQUEST: &str = "ask needs a request, e.g. rustgis-cli ask --sample \"Which countries have the largest GDP?\""; | ||
|
|
@@ -374,7 +378,7 @@ fn ask(s: &mut Session, args: &[String], saved: Option<&Saved>, env: &Environmen | |
| if !models && prompt.is_none() { | ||
| return Err(NEEDS_REQUEST.into()); | ||
| } | ||
| let mut cfg = configuration(&provider, args, env, saved); | ||
| let mut cfg = configuration(&provider, args, env, saved)?; | ||
| // A signed-in account's requests renew its tokens as needed. | ||
| // Without a usable sign-in, say how to sign in before asking for anything. | ||
| if cfg.login() | ||
|
|
@@ -1051,14 +1055,14 @@ mod tests { | |
| fn a_prompt_uses_the_saved_key_but_model_listing_does_not_read_it() { | ||
| let store = anthropic_key(); | ||
| let opted_in = saved(remembered(), &store); | ||
| let list = configuration("anthropic", &args(&["ask", "--models"]), &bare(), Some(&opted_in)); | ||
| let list = configuration("anthropic", &args(&["ask", "--models"]), &bare(), Some(&opted_in)).unwrap(); | ||
| let request = provider::models_request(&list); | ||
| assert!(request.headers.iter().all(|(_, value)| !value.contains("stored-sentinel"))); | ||
| assert!(store.accounts().is_empty()); | ||
| let environment_list = configuration("openai", &args(&["ask", "--models"]), &with_openai_key(), Some(&opted_in)); | ||
| let environment_list = configuration("openai", &args(&["ask", "--models"]), &with_openai_key(), Some(&opted_in)).unwrap(); | ||
| assert_eq!(environment_list.key, "env-key"); | ||
| assert!(store.accounts().is_empty()); | ||
| let prompt = configuration("anthropic", &args(&["ask", "--provider", "anthropic", "hi"]), &bare(), Some(&opted_in)); | ||
| let prompt = configuration("anthropic", &args(&["ask", "--provider", "anthropic", "hi"]), &bare(), Some(&opted_in)).unwrap(); | ||
| assert_eq!(prompt.key, "stored-sentinel"); | ||
| assert_eq!(store.accounts(), ["assistant/anthropic"]); | ||
| } | ||
|
|
@@ -1067,17 +1071,17 @@ mod tests { | |
| fn without_the_opt_in_or_consent_no_key_is_read_and_the_environment_key_wins() { | ||
| let store = anthropic_key(); | ||
| // No --use-saved-secrets: the model list goes out without the saved key. | ||
| let request = provider::models_request(&configuration("anthropic", &args(&["ask", "--models"]), &bare(), None)); | ||
| let request = provider::models_request(&configuration("anthropic", &args(&["ask", "--models"]), &bare(), None).unwrap()); | ||
| assert!(request.headers.iter().all(|(_, value)| !value.contains("stored-sentinel"))); | ||
| // Opted in, but the desktop does not remember keys. | ||
| let off = saved(desktop(&[(provider::REMEMBER_KEY_PREF, "off")]), &store); | ||
| assert_eq!(configuration("anthropic", &args(&["ask", "hi"]), &bare(), Some(&off)).key, ""); | ||
| assert_eq!(configuration("anthropic", &args(&["ask", "hi"]), &bare(), Some(&off)).unwrap().key, ""); | ||
| // A key from the environment is the one used, and nothing is read. | ||
| let opted_in = saved(remembered(), &store); | ||
| assert_eq!(configuration("openai", &args(&["ask", "hi"]), &with_openai_key(), Some(&opted_in)).key, "env-key"); | ||
| assert_eq!(configuration("openai", &args(&["ask", "hi"]), &with_openai_key(), Some(&opted_in)).unwrap().key, "env-key"); | ||
| // The desktop sends its key to its own address only: another one gets no key. | ||
| let elsewhere = args(&["ask", "--base-url", "https://elsewhere.example/v1", "hi"]); | ||
| assert_eq!(configuration("anthropic", &elsewhere, &bare(), Some(&opted_in)).key, ""); | ||
| assert_eq!(configuration("anthropic", &elsewhere, &bare(), Some(&opted_in)).unwrap().key, ""); | ||
| assert!(store.accounts().is_empty()); | ||
| } | ||
|
|
||
|
|
@@ -1103,6 +1107,22 @@ mod tests { | |
| false | ||
| } | ||
|
|
||
| /// A refused store is an actionable CLI error, while no store is a clean signed-out state. | ||
| #[test] | ||
| fn a_refused_chatgpt_store_is_reported_before_a_cli_request() { | ||
| if !in_isolated_settings("tests::a_refused_chatgpt_store_is_reported_before_a_cli_request") { | ||
| return; | ||
| } | ||
| let path = rustgis_assistant::chatgpt::auth_path().unwrap(); | ||
| let text = "{\"version\":3,\"accounts\":[]}"; | ||
| std::fs::write(&path, text).unwrap(); | ||
| let error = configuration("chatgpt", &args(&["ask", "hi"]), &bare(), None).err().unwrap(); | ||
| assert!(error.contains("could not read saved ChatGPT sign-ins") && error.contains("newer RustGIS"), "{error}"); | ||
| assert_eq!(std::fs::read_to_string(&path).unwrap(), text); | ||
| std::fs::remove_file(&path).unwrap(); | ||
| assert!(configuration("chatgpt", &args(&["ask", "hi"]), &bare(), None).unwrap().key.is_empty()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn managing_the_chatgpt_sign_in_never_reads_an_api_key() { | ||
| if !in_isolated_settings("tests::managing_the_chatgpt_sign_in_never_reads_an_api_key") { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.rustgis.mobile; | ||
|
|
||
| /** Ordered phone events, with bounded position retention and bounded work per Rust frame. */ | ||
| final class EventBuffer { | ||
| static final int PER_FRAME = 512; | ||
| private final java.util.ArrayDeque<String> events = new java.util.ArrayDeque<>(); | ||
| private final int mostPositions; | ||
| private int positions; | ||
| private long dropped; | ||
|
|
||
| EventBuffer(int mostPositions) { | ||
| this.mostPositions = mostPositions; | ||
| } | ||
|
|
||
| void add(String event) { | ||
| boolean position = event.startsWith("position\t"); | ||
| if (position && positions >= mostPositions) { | ||
| // Only position fixes may be discarded: picker completions and failures must reach | ||
| // Rust even when several days' positions filled the queue before them. | ||
| java.util.Iterator<String> pending = events.iterator(); | ||
| while (pending.hasNext()) { | ||
| if (pending.next().startsWith("position\t")) { | ||
| pending.remove(); | ||
| positions--; | ||
| dropped++; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| events.add(event.replace('\n', ' ').replace('\r', ' ')); | ||
| if (position) { | ||
| positions++; | ||
| } | ||
| } | ||
|
|
||
| String take() { | ||
| StringBuilder taken = new StringBuilder(); | ||
| int count = 0; | ||
| if (dropped > 0) { | ||
| taken.append("failed\t").append(dropped) | ||
| .append(" positions found while RustGIS was out of sight were dropped: more were waiting than it keeps."); | ||
| dropped = 0; | ||
| count++; | ||
| } | ||
| while (count < PER_FRAME && !events.isEmpty()) { | ||
| String event = events.removeFirst(); | ||
| if (event.startsWith("position\t")) { | ||
| positions--; | ||
| } | ||
| if (count++ > 0) { | ||
| taken.append('\n'); | ||
| } | ||
| taken.append(event); | ||
| } | ||
| return taken.toString(); | ||
| } | ||
|
|
||
| boolean isEmpty() { | ||
| return events.isEmpty() && dropped == 0; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.rustgis.mobile; | ||
|
|
||
| /** Providers successfully registered for the current listener, confined to Android's main thread. */ | ||
| final class LocationProviders { | ||
| private final java.util.HashSet<String> requested = new java.util.HashSet<>(); | ||
|
|
||
| void add(String provider) { | ||
| requested.add(provider); | ||
| } | ||
|
|
||
| void clear() { | ||
| requested.clear(); | ||
| } | ||
|
|
||
| boolean anyEnabled(java.util.function.Predicate<String> enabled) { | ||
| for (String provider : requested) { | ||
| if (enabled.test(provider)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AGENTS.md (medium-low confidence, ~50%): the new CI-timing sentence is a new rule, not a check or test list. The "This file" section says a new rule goes under "Suggested AGENTS.md additions" in the pull request description, and a maintainer decides. Only a check or a test-list line should be edited here directly. The sentence "Label-triggered runs start the tests immediately; label-gated build jobs in
ci.ymlstart from the next push." reads as a rule. Move it to the suggested additions, or say why it is a fact rather than a rule.