mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
update cloud requirements parse failure msg (#17396)
<img width="805" height="189" alt="Screenshot 2026-04-10 at 6 17 19 PM" src="https://github.com/user-attachments/assets/3ce22f45-56fb-4011-8005-98a2c1407f30" />
This commit is contained in:
committed by
GitHub
Unverified
parent
8a474a6561
commit
f8bb088617
@@ -51,6 +51,7 @@ const CLOUD_REQUIREMENTS_FETCH_ATTEMPT_METRIC: &str = "codex.cloud_requirements.
|
||||
const CLOUD_REQUIREMENTS_FETCH_FINAL_METRIC: &str = "codex.cloud_requirements.fetch_final";
|
||||
const CLOUD_REQUIREMENTS_LOAD_METRIC: &str = "codex.cloud_requirements.load";
|
||||
const CLOUD_REQUIREMENTS_LOAD_FAILED_MESSAGE: &str = "failed to load your workspace-managed config";
|
||||
const CLOUD_REQUIREMENTS_PARSE_FAILED_MESSAGE: &str = "Your workspace-managed config is invalid and could not be parsed. Please contact your workspace admin.";
|
||||
const CLOUD_REQUIREMENTS_AUTH_RECOVERY_FAILED_MESSAGE: &str = "Your authentication session could not be refreshed automatically. Please log out and sign in again.";
|
||||
const CLOUD_REQUIREMENTS_CACHE_WRITE_HMAC_KEY: &[u8] =
|
||||
b"codex-cloud-requirements-cache-v3-064f8542-75b4-494c-a294-97d3ce597271";
|
||||
@@ -491,7 +492,7 @@ impl CloudRequirementsService {
|
||||
return Err(CloudRequirementsLoadError::new(
|
||||
CloudRequirementsLoadErrorCode::Parse,
|
||||
/*status_code*/ None,
|
||||
CLOUD_REQUIREMENTS_LOAD_FAILED_MESSAGE,
|
||||
format_cloud_requirements_parse_failed_message(contents, &err),
|
||||
));
|
||||
}
|
||||
},
|
||||
@@ -749,6 +750,13 @@ fn parse_cloud_requirements(
|
||||
}
|
||||
}
|
||||
|
||||
fn format_cloud_requirements_parse_failed_message(
|
||||
_contents: &str,
|
||||
err: &toml::de::Error,
|
||||
) -> String {
|
||||
format!("{CLOUD_REQUIREMENTS_PARSE_FAILED_MESSAGE}\n\nDetails:\n{err}")
|
||||
}
|
||||
|
||||
fn emit_fetch_attempt_metric(
|
||||
trigger: &str,
|
||||
attempt: usize,
|
||||
@@ -1617,10 +1625,43 @@ enabled = false
|
||||
CLOUD_REQUIREMENTS_TIMEOUT,
|
||||
);
|
||||
|
||||
assert!(service.fetch().await.is_err());
|
||||
let err = service
|
||||
.fetch()
|
||||
.await
|
||||
.expect_err("parse error should fail closed");
|
||||
let err_text = err.to_string();
|
||||
assert!(err_text.contains(CLOUD_REQUIREMENTS_PARSE_FAILED_MESSAGE));
|
||||
assert!(err_text.contains("Details:"));
|
||||
assert!(err_text.contains("not = ["));
|
||||
assert_eq!(err.code(), CloudRequirementsLoadErrorCode::Parse);
|
||||
assert_eq!(fetcher.request_count.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fetch_cloud_requirements_invalid_enum_value_surfaces_field_name() {
|
||||
let fetcher = Arc::new(SequenceFetcher::new(vec![Ok(Some(
|
||||
"allowed_approval_policies = [\"definitely-not-valid\"]".to_string(),
|
||||
))]));
|
||||
let codex_home = tempdir().expect("tempdir");
|
||||
let service = CloudRequirementsService::new(
|
||||
auth_manager_with_plan("business"),
|
||||
fetcher,
|
||||
codex_home.path().to_path_buf(),
|
||||
CLOUD_REQUIREMENTS_TIMEOUT,
|
||||
);
|
||||
|
||||
let err = service
|
||||
.fetch()
|
||||
.await
|
||||
.expect_err("invalid enum value should fail closed");
|
||||
let err_text = err.to_string();
|
||||
assert!(err_text.contains(CLOUD_REQUIREMENTS_PARSE_FAILED_MESSAGE));
|
||||
assert!(err_text.contains("allowed_approval_policies"));
|
||||
assert!(err_text.contains("definitely-not-valid"));
|
||||
assert!(err_text.contains("unknown variant"));
|
||||
assert_eq!(err.code(), CloudRequirementsLoadErrorCode::Parse);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fetch_cloud_requirements_uses_cache_when_valid() {
|
||||
let codex_home = tempdir().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user