mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Load cloud requirements for agent identity (#19708)
## Why Agent Identity sessions can represent Business and Enterprise ChatGPT workspaces, but cloud requirements were skipped before fetch. That meant workspace-managed requirements were not loaded for Agent Identity even when the JWT carried the same account identity and plan information that normal ChatGPT token auth exposes. This PR now sits on top of the Agent Identity stack through [#19764](https://github.com/openai/codex/pull/19764). Because [#19763](https://github.com/openai/codex/pull/19763) moved task registration into Agent Identity auth loading, cloud requirements no longer needs a separate runtime-initialization step before building the backend client. ## What changed - Stop skipping `CodexAuth::AgentIdentity` in the cloud requirements loader. - Share the cloud requirements eligibility check between startup load and background cache refresh. - Rely on eagerly loaded Agent Identity auth so backend requests can attach task-scoped `AgentAssertion` headers. - Decode Agent Identity JWT `plan_type` as the auth-layer plan type, then convert it through a shared `auth::PlanType` -> `account::PlanType` mapping. - Add the missing serde alias for the `education` plan string and add coverage for raw Agent Identity plan aliases such as `hc` and `education`. ## Testing - `cargo test -p codex-agent-identity -p codex-login -p codex-cloud-requirements -p codex-protocol`
This commit is contained in:
@@ -3,6 +3,9 @@ use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
use crate::auth::KnownPlan;
|
||||
use crate::auth::PlanType as AuthPlanType;
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq, JsonSchema, TS, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[ts(rename_all = "lowercase")]
|
||||
@@ -57,9 +60,38 @@ impl PlanType {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AuthPlanType> for PlanType {
|
||||
fn from(plan_type: AuthPlanType) -> Self {
|
||||
match plan_type {
|
||||
AuthPlanType::Known(plan) => plan.into(),
|
||||
AuthPlanType::Unknown(_) => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KnownPlan> for PlanType {
|
||||
fn from(plan: KnownPlan) -> Self {
|
||||
match plan {
|
||||
KnownPlan::Free => Self::Free,
|
||||
KnownPlan::Go => Self::Go,
|
||||
KnownPlan::Plus => Self::Plus,
|
||||
KnownPlan::Pro => Self::Pro,
|
||||
KnownPlan::ProLite => Self::ProLite,
|
||||
KnownPlan::Team => Self::Team,
|
||||
KnownPlan::SelfServeBusinessUsageBased => Self::SelfServeBusinessUsageBased,
|
||||
KnownPlan::Business => Self::Business,
|
||||
KnownPlan::EnterpriseCbpUsageBased => Self::EnterpriseCbpUsageBased,
|
||||
KnownPlan::Enterprise => Self::Enterprise,
|
||||
KnownPlan::Edu => Self::Edu,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::PlanType;
|
||||
use crate::auth::KnownPlan;
|
||||
use crate::auth::PlanType as AuthPlanType;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
@@ -121,4 +153,20 @@ mod tests {
|
||||
assert_eq!(PlanType::Edu.is_workspace_account(), true);
|
||||
assert_eq!(PlanType::Pro.is_workspace_account(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_plan_type_converts_to_account_plan_type() {
|
||||
assert_eq!(
|
||||
PlanType::from(AuthPlanType::Known(KnownPlan::EnterpriseCbpUsageBased)),
|
||||
PlanType::EnterpriseCbpUsageBased
|
||||
);
|
||||
assert_eq!(
|
||||
PlanType::from(AuthPlanType::Known(KnownPlan::Enterprise)),
|
||||
PlanType::Enterprise
|
||||
);
|
||||
assert_eq!(
|
||||
PlanType::from(AuthPlanType::Unknown("mystery-tier".to_string())),
|
||||
PlanType::Unknown
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ pub enum KnownPlan {
|
||||
EnterpriseCbpUsageBased,
|
||||
#[serde(alias = "hc")]
|
||||
Enterprise,
|
||||
#[serde(alias = "education")]
|
||||
Edu,
|
||||
}
|
||||
|
||||
@@ -118,3 +119,23 @@ pub enum RefreshTokenFailedReason {
|
||||
Revoked,
|
||||
Other,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::KnownPlan;
|
||||
use super::PlanType;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn plan_type_deserializes_raw_aliases() {
|
||||
assert_eq!(
|
||||
serde_json::from_str::<PlanType>("\"hc\"").expect("hc should deserialize"),
|
||||
PlanType::Known(KnownPlan::Enterprise)
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_str::<PlanType>("\"education\"")
|
||||
.expect("education should deserialize"),
|
||||
PlanType::Known(KnownPlan::Edu)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user