Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop-tauri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react": "4.7.0",
"esbuild": "^0.25.12",
"jsdom": "25.0.1",
"typescript": "5.6.3",
"vite": "6.4.2",
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-tauri/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 51 additions & 7 deletions rust/src/providers/qwencloud/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,30 @@ impl QwenCloudProvider {
),
)
});
let weekly = snapshot.weekly_used_percent.map(|percent| {
RateWindow::with_details(
percent,
Some(WEEKLY_MINUTES),
snapshot.weekly_resets_at,
quota_detail_percent(percent, snapshot.weekly_total_quota),
)
});

// Prefer the 5-hour window; fall back to the legacy 30-day envelope; if the
// account only exposes the weekly window (e.g. Qwen Cloud individual plans),
// promote it to primary instead of failing the whole fetch.
let has_five_hour_or_legacy = five_hour.is_some() || legacy.is_some();
let primary = five_hour
.or(legacy)
.or_else(|| weekly.clone())
.ok_or_else(|| ProviderError::Parse("Qwen Cloud usage windows missing".into()))?;
let mut usage = UsageSnapshot::new(primary);

if let Some(weekly_percent) = snapshot.weekly_used_percent {
usage = usage.with_secondary(RateWindow::with_details(
weekly_percent,
Some(WEEKLY_MINUTES),
snapshot.weekly_resets_at,
quota_detail_percent(weekly_percent, snapshot.weekly_total_quota),
));
// The weekly window is secondary only when it was not promoted to primary.
if has_five_hour_or_legacy
&& let Some(weekly) = weekly
{
usage = usage.with_secondary(weekly);
}

if let Some(plan) = snapshot.plan_name.filter(|plan| !plan.trim().is_empty()) {
Expand Down Expand Up @@ -1388,4 +1400,36 @@ mod tests {
assert!(!provider.metadata().default_enabled);
assert_eq!(provider.metadata().dashboard_url, Some(DASHBOARD_URL));
}

#[test]
fn weekly_only_shape_promotes_weekly_to_primary() {
// Real-world fixture: the account exposes only the weekly window, so
// there is no per5HourPercentage at all. Previously this failed with
// "Qwen Cloud usage windows missing"; now the weekly window becomes
// the primary window instead.
let payload = serde_json::json!({
"code": "200",
"data": {
"DataV2": {
"data": {
"success": true,
"data": {
"per1WeekPercentage": 0.8439116574633999,
"per1WeekResetTime": 1785234900000_i64
}
},
"success": true,
"httpStatus": 200
}
},
"successResponse": true
});
let usage = QwenCloudProvider::snapshot_to_usage(
QwenCloudProvider::parse(payload.to_string().as_bytes(), None, None).unwrap(),
)
.unwrap();
assert!((usage.primary.used_percent - 84.39116574634).abs() < 1e-9);
assert_eq!(usage.primary.window_minutes, Some(WEEKLY_MINUTES));
assert!(usage.secondary.is_none());
}
}
Loading