Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 1 | //! Usage other services meter through the month, charged once it is over: |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 2 | //! security scans, search embeddings, and two billing measures itself each |
| 3 | //! day: private repository storage and git operations. | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 4 | //! |
| 5 | //! Each reports what it cost g1t so far this month (`note_pending`), so the | |
| 6 | //! workspace's limit counts it as it happens. When the month is over, | |
| 7 | //! billing charges it once: at cost plus the margin, on the account's | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 8 | //! terms, after the plan's included usage and the trial credit (see |
| 9 | //! `credits`), dated the month's last second so it falls in that month's | |
| 10 | //! statement and invoice. | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 11 | //! |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 12 | //! The forge is free for every workspace up to the same amounts, on the |
| 13 | //! plan or not; past them, a workspace on the plan pays at cost plus the | |
| 14 | //! margin and is never refused or slowed, and a free workspace is never | |
| 15 | //! charged but is held to them. | |
| 16 | //! | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 17 | //! **Git operations.** Cloudflare Artifacts charges g1t $0.15 per 1,000 |
| 18 | //! operations (clones, fetches, pushes) from 2026-10-14. The repos service | |
| 19 | //! counts those through g1t's git endpoints. Every workspace has | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 20 | //! `GIT_OPERATIONS_INCLUDED` (50,000) a month free; past it, the plan pays |
| 21 | //! at cost plus the margin, and a free workspace is slowed down instead | |
| 22 | //! (the repos service's `GIT_OPERATIONS_FREE_CAP`, the same number). | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 23 | //! |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 24 | //! **Actions cache.** The actions service reports what each workspace's |
| 25 | //! `actions/cache` entries held each day (source `cache`), at what R2 | |
| 26 | //! charges g1t to store them ($0.015 a GB-month). Only the plan is charged | |
| 27 | //! for it, from the first byte; a free workspace is never charged, and its | |
| 28 | //! repositories are held to the cache's quota like everyone's. | |
| 29 | //! | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 30 | //! **Storage.** The git store does not report a repository's size, so the |
| 31 | //! repos service counts the packs pushed through g1t's git endpoints (see | |
| 32 | //! `g1t_contracts::repos::StorageArgs`): a lower bound. Each day billing | |
| 33 | //! records what each workspace's private repositories hold and what is | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 34 | //! free that day (`FREE_PRIVATE_STORAGE_BYTES`, 1 GB, for everyone). Like |
| 35 | //! Cloudflare's own storage billing, a month's GB-months are the days' | |
| 36 | //! amounts past the free one, added up and divided by 30, and only the | |
| 37 | //! plan is charged for them. A free workspace is never charged for | |
| 38 | //! storage: pushes to its private repositories stop once they hold its | |
| 39 | //! free amount. Public repositories are never charged. | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 40 | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 41 | use g1t_contracts::billing::PlanKind; |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 42 | use g1t_contracts::new_id; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 43 | use g1t_contracts::repos::{GitOperationsArgs, StorageArgs, WorkspaceGitOperations, WorkspaceStorage}; |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 44 | use g1t_contracts::time::rfc3339; |
| 45 | use g1t_kit::now_ms; | |
| 46 | use serde::Deserialize; | |
| 47 | use worker::Result; | |
| 48 | ||
| 49 | use crate::credits::{self, Drawn, Eligible}; | |
| 50 | use crate::{Billing, optional}; | |
| 51 | ||
| 52 | /// Sources billing charges itself when the month is over. | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 53 | pub(crate) const CHARGED_HERE: [&str; 5] = ["security", "context", "storage", "git", "cache"]; |
| 54 | ||
| 55 | /// Sources only the plan is charged for: a free workspace's are not kept. | |
| 56 | pub(crate) const PLAN_ONLY: [&str; 1] = ["cache"]; | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 57 | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 58 | /// Sources g1t pays for itself on a free workspace: security scans and |
| 59 | /// search embeddings. No security feature is held back for the plan, and | |
| 60 | /// a free workspace never runs up a bill, so on a workspace without the | |
| 61 | /// plan they are recorded at cost, covered by g1t, and charged nothing | |
| 62 | /// (not even from the trial). On the plan they are charged like any usage. | |
| 63 | pub(crate) const COVERED_FOR_FREE: [&str; 2] = ["security", "context"]; | |
| 64 | ||
| 65 | /// What pays for a month-end source's charge: the plan's included usage | |
| 66 | /// and the trial, and for a covered source on a free workspace, g1t. | |
| 67 | pub(crate) fn month_end_eligible(source: &str, plan: bool) -> Eligible { | |
| 68 | let covered = !plan && COVERED_FOR_FREE.contains(&source); | |
| 69 | Eligible { trial: !covered, repo: None, cover_rest: covered } | |
| 70 | } | |
| 71 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 72 | /// What Artifacts charges g1t, when the price book cannot be read: $0.50 |
| 73 | /// a GB-month of storage, and $0.15 per 1,000 git operations. | |
| 74 | pub(crate) const STORAGE_MICROS_PER_GB_MONTH: i64 = 500_000; | |
| 75 | pub(crate) const GIT_MICROS_PER_THOUSAND: i64 = 150_000; | |
| 76 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 77 | /// When Cloudflare starts charging for Artifacts operations: none before |
| 78 | /// count. | |
| 79 | pub(crate) const GIT_BILLING_STARTS: &str = "2026-10-14T00"; | |
| 80 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 81 | /// What git operations past the free amount cost g1t, at |
| 82 | /// `micros_per_thousand`: nothing up to it. | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 83 | pub(crate) fn git_cost(operations: u64, included: u64, micros_per_thousand: f64) -> i64 { |
| 84 | let past = operations.saturating_sub(included); | |
| 85 | (past as f64 * micros_per_thousand / 1000.0).ceil() as i64 | |
| 86 | } | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 87 | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 88 | /// The first hour of `month` to count git operations from. |
| 89 | pub(crate) fn git_since(month: &str) -> String { | |
| 90 | let start = format!("{month}-01T00"); | |
| 91 | if start.as_str() < GIT_BILLING_STARTS { GIT_BILLING_STARTS.to_owned() } else { start } | |
| 92 | } | |
| 93 | ||
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 94 | /// A gigabyte, as Cloudflare bills storage. |
| 95 | pub(crate) const GB: f64 = 1_000_000_000.0; | |
| 96 | ||
| 97 | /// GB-months from a month's daily measures, each `(private, free)` bytes: | |
| 98 | /// what was past the free amount each day, over 30 days. | |
| 99 | pub(crate) fn storage_gb_months(days: &[(i64, i64)]) -> f64 { | |
| 100 | days.iter().map(|(private, free)| (private - free).max(0) as f64).sum::<f64>() / GB / 30.0 | |
| 101 | } | |
| 102 | ||
| 103 | /// What `gb_months` cost g1t at `micros_per_gb_month`, rounded up. | |
| 104 | pub(crate) fn storage_cost(gb_months: f64, micros_per_gb_month: f64) -> i64 { | |
| 105 | (gb_months * micros_per_gb_month).ceil() as i64 | |
| 106 | } | |
| 107 | ||
| 108 | /// What a source is called on the statement. | |
| 109 | pub(crate) fn title(source: &str) -> &'static str { | |
| 110 | match source { | |
| 111 | "security" => "Security scans", | |
| 112 | "context" => "Search embeddings", | |
| 113 | "storage" => "Private repository storage past the free amount", | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 114 | "git" => "Git operations past the free amount", |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 115 | "cache" => "Actions cache storage", |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 116 | "domains" => "Custom domains", |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 117 | _ => "Metered usage", |
| 118 | } | |
| 119 | } | |
| 120 | ||
| 121 | /// A usage entry to put on the ledger. | |
| 122 | pub(crate) struct UsageLine<'a> { | |
| 123 | pub workspace: &'a str, | |
| 124 | /// What the workspace is charged, after terms and what paid for it. | |
| 125 | pub charged: i64, | |
| 126 | pub description: &'a str, | |
| 127 | pub repo: Option<&'a str>, | |
| 128 | pub task: &'a str, | |
| 129 | pub cost: i64, | |
| 130 | pub reference: &'a str, | |
| 131 | pub created_at: &'a str, | |
| 132 | pub drawn: Drawn, | |
| 133 | } | |
| 134 | ||
| 135 | impl Billing { | |
| 136 | /// Puts a usage entry on the ledger and takes it off the balance, as | |
| 137 | /// one write. | |
| 138 | pub(crate) async fn post_usage(&self, line: UsageLine<'_>) -> Result<()> { | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 139 | // The price versions it was charged at (pricing.rs). |
| 140 | let mut versions = Vec::new(); | |
| 141 | for meter in crate::pricing::meters_of(line.task) { | |
| 142 | versions.extend(self.version_now(meter).await?); | |
| 143 | } | |
| 144 | let price_version = versions.join(","); | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 145 | self.db |
| 146 | .batch(vec![ | |
| 147 | self.db | |
| 148 | .prepare( | |
| 149 | "INSERT INTO ledger | |
| 150 | (id, workspace, kind, amount_micros, description, repo, task, cost_micros, reference, | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 151 | created_at, billed_to, credit_micros, trial_micros, oss_micros, price_version) |
| 152 | VALUES (?, ?, 'usage', ?, ?, ?, ?, ?, ?, ?, 'g1t', ?, ?, ?, ?)", | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 153 | ) |
| 154 | .bind(&[ | |
| 155 | new_id("led", now_ms()).into(), | |
| 156 | line.workspace.into(), | |
| 157 | (-(line.charged as f64)).into(), | |
| 158 | line.description.into(), | |
| 159 | optional(line.repo), | |
| 160 | line.task.into(), | |
| 161 | (line.cost as f64).into(), | |
| 162 | line.reference.into(), | |
| 163 | line.created_at.into(), | |
| 164 | (line.drawn.credit as f64).into(), | |
| 165 | (line.drawn.trial as f64).into(), | |
| 166 | (line.drawn.oss as f64).into(), | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 167 | optional(Some(price_version.as_str()).filter(|v| !v.is_empty())), |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 168 | ])?, |
| 169 | self.db | |
| 170 | .prepare( | |
| 171 | "INSERT INTO accounts (workspace, balance_micros, created_at) VALUES (?1, ?2, ?3) | |
| 172 | ON CONFLICT (workspace) DO UPDATE SET balance_micros = balance_micros + ?2", | |
| 173 | ) | |
| 174 | .bind(&[line.workspace.into(), (-(line.charged as f64)).into(), rfc3339(now_ms()).into()])?, | |
| 175 | ]) | |
| 176 | .await?; | |
| 177 | Ok(()) | |
| 178 | } | |
| 179 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 180 | /// Writes down what a source cost g1t so far in `month`, what it will |
| 181 | /// be charged, and how much of it there was (`detail`, for the Billing | |
| 182 | /// page), replacing the last figure. | |
| 183 | pub(crate) async fn set_pending( | |
| 184 | &self, | |
| 185 | workspace: &str, | |
| 186 | source: &str, | |
| 187 | month: &str, | |
| 188 | cost_micros: i64, | |
| 189 | detail: Option<&str>, | |
| 190 | ) -> Result<()> { | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 191 | // A covered source on a free workspace is never charged, so it does |
| 192 | // not count toward the workspace's limit either. | |
| 193 | let covered = COVERED_FOR_FREE.contains(&source) && !self.has_plan(&workspace.to_lowercase()).await?; | |
| 194 | let charge = if covered { 0 } else { credits::with_margin(cost_micros, self.margin_percent) }; | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 195 | self.db |
| 196 | .prepare( | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 197 | "INSERT INTO pending_usage (workspace, source, month, charge_micros, cost_micros, updated_at, detail) |
| 198 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7) | |
| 199 | ON CONFLICT (workspace, source, month) DO UPDATE SET | |
| 200 | charge_micros = ?4, cost_micros = ?5, updated_at = ?6, detail = COALESCE(?7, detail)", | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 201 | ) |
| 202 | .bind(&[ | |
| 203 | workspace.to_lowercase().into(), | |
| 204 | source.into(), | |
| 205 | month.into(), | |
| 206 | (charge as f64).into(), | |
| 207 | (cost_micros.max(0) as f64).into(), | |
| 208 | rfc3339(now_ms()).into(), | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 209 | optional(detail), |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 210 | ])? |
| 211 | .run() | |
| 212 | .await?; | |
| 213 | Ok(()) | |
| 214 | } | |
| 215 | ||
| 216 | /// Charges every month that is over for the usage billing charges | |
| 217 | /// itself, once each. | |
| 218 | pub(crate) async fn charge_pending(&self) -> Result<()> { | |
| 219 | if self.stripe.is_none() { | |
| 220 | return Ok(()); | |
| 221 | } | |
| 222 | let now = rfc3339(now_ms()); | |
| 223 | let current = credits::month_of(&now); | |
| 224 | #[derive(Deserialize)] | |
| 225 | struct Row { | |
| 226 | workspace: String, | |
| 227 | source: String, | |
| 228 | month: String, | |
| 229 | cost_micros: Option<i64>, | |
| 230 | } | |
| 231 | let marks = CHARGED_HERE.iter().map(|s| format!("'{s}'")).collect::<Vec<_>>().join(", "); | |
| 232 | let due = self | |
| 233 | .db | |
| 234 | .prepare(format!( | |
| 235 | "SELECT workspace, source, month, cost_micros FROM pending_usage | |
| 236 | WHERE month < ? AND charged_at IS NULL AND source IN ({marks}) ORDER BY month LIMIT 50" | |
| 237 | )) | |
| 238 | .bind(&[current.as_str().into()])? | |
| 239 | .all() | |
| 240 | .await? | |
| 241 | .results::<Row>()?; | |
| 242 | for row in due { | |
| 243 | // Claimed first, so two crons never charge it twice. | |
| 244 | let claimed = self | |
| 245 | .db | |
| 246 | .prepare( | |
| 247 | "UPDATE pending_usage SET charged_at = ?1 | |
| 248 | WHERE workspace = ?2 AND source = ?3 AND month = ?4 AND charged_at IS NULL RETURNING workspace", | |
| 249 | ) | |
| 250 | .bind(&[now.as_str().into(), row.workspace.as_str().into(), row.source.as_str().into(), row.month.as_str().into()])? | |
| 251 | .first::<serde_json::Value>(None) | |
| 252 | .await?; | |
| 253 | let cost = row.cost_micros.unwrap_or(0); | |
| 254 | if claimed.is_none() || cost <= 0 { | |
| 255 | continue; | |
| 256 | } | |
| 257 | let base = credits::with_margin(cost, self.margin_percent); | |
| 258 | let (charge, terms_note) = self.charged(&row.workspace, base).await?; | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 259 | let plan = self.has_plan(&row.workspace).await?; |
| 260 | let drawn = self.draw(&row.workspace, charge, &row.month, &month_end_eligible(&row.source, plan)).await?; | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 261 | let detail = if row.source == "storage" { |
| 262 | let gb_months = self.gb_months(&row.workspace, &row.month).await?; | |
| 263 | format!(": {gb_months:.2} GB-months") | |
| 264 | } else { | |
| 265 | String::new() | |
| 266 | }; | |
| 267 | let description = format!("{} in {}{detail}{terms_note}{}", title(&row.source), row.month, drawn.note()); | |
| 268 | let reference = format!("{}/{}/{}", row.source, row.workspace, row.month); | |
| 269 | let created_at = credits::month_end(&row.month); | |
| 270 | self.post_usage(UsageLine { | |
| 271 | workspace: &row.workspace, | |
| 272 | charged: charge - drawn.total(), | |
| 273 | description: &description, | |
| 274 | repo: None, | |
| 275 | task: &row.source, | |
| 276 | cost, | |
| 277 | reference: &reference, | |
| 278 | created_at: &created_at, | |
| 279 | drawn, | |
| 280 | }) | |
| 281 | .await?; | |
| 282 | } | |
| 283 | Ok(()) | |
| 284 | } | |
| 285 | ||
| 286 | /// A workspace's private storage past the free amount in `month`. | |
| 287 | async fn gb_months(&self, workspace: &str, month: &str) -> Result<f64> { | |
| 288 | #[derive(Deserialize)] | |
| 289 | struct Day { | |
| 290 | private_bytes: i64, | |
| 291 | free_bytes: i64, | |
| 292 | } | |
| 293 | let days = self | |
| 294 | .db | |
| 295 | .prepare("SELECT private_bytes, free_bytes FROM storage_days WHERE workspace = ? AND substr(day, 1, 7) = ?") | |
| 296 | .bind(&[workspace.into(), month.into()])? | |
| 297 | .all() | |
| 298 | .await? | |
| 299 | .results::<Day>()?; | |
| 300 | Ok(storage_gb_months(&days.iter().map(|d| (d.private_bytes, d.free_bytes)).collect::<Vec<_>>())) | |
| 301 | } | |
| 302 | ||
| 303 | /// Once a day: what each workspace's private repositories hold, and | |
| 304 | /// what this month's storage past the free amount comes to so far. | |
| 305 | pub(crate) async fn measure_storage(&self) -> Result<()> { | |
| 306 | let Some(repos) = &self.repos else { return Ok(()) }; | |
| 307 | let list: Vec<WorkspaceStorage> = g1t_kit::call(repos, "storage", &StorageArgs {}).await?; | |
| 308 | let now = rfc3339(now_ms()); | |
| 309 | let (day, month) = (&now[..10], credits::month_of(&now)); | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 310 | let price = self.price("private_storage").await?.map_or(STORAGE_MICROS_PER_GB_MONTH as f64, |(cost, _)| cost); |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 311 | for workspace in list { |
| 312 | let slug = workspace.namespace.to_lowercase(); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 313 | let plan = self.has_plan(&slug).await?; |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 314 | // The same free amount for everyone: the plan pays past it. |
| 315 | let free = self.plans.free_storage_bytes; | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 316 | self.db |
| 317 | .prepare( | |
| 318 | "INSERT INTO storage_days (workspace, day, private_bytes, free_bytes) VALUES (?1, ?2, ?3, ?4) | |
| 319 | ON CONFLICT (workspace, day) DO UPDATE SET private_bytes = ?3, free_bytes = ?4", | |
| 320 | ) | |
| 321 | .bind(&[slug.as_str().into(), day.into(), (workspace.private_bytes as f64).into(), (free as f64).into()])? | |
| 322 | .run() | |
| 323 | .await?; | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 324 | // Only the plan pays for storage past its amount. A free |
| 325 | // workspace is never charged: the repos service stops its pushes | |
| 326 | // to private repositories once it is full (see git_ops.rs there). | |
| 327 | let gb_months = if plan { self.gb_months(&slug, &month).await? } else { 0.0 }; | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 328 | if gb_months > 0.0 { |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 329 | let detail = format!("{gb_months:.2} GB-months past the free {}", crate::features::bytes(free)); |
| 330 | self.set_pending(&slug, "storage", &month, storage_cost(gb_months, price), Some(&detail)).await?; | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 331 | } |
| 332 | } | |
| 333 | Ok(()) | |
| 334 | } | |
| 335 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 336 | /// Git operations this month for each workspace, from the repos |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 337 | /// service: what is past the free amount goes to the month's pending |
| 338 | /// usage for workspaces on the plan, which are never slowed or refused | |
| 339 | /// for them. Free workspaces are never charged for them. | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 340 | pub(crate) async fn measure_git(&self) -> Result<()> { |
| 341 | let Some(repos) = &self.repos else { return Ok(()) }; | |
| 342 | let month = credits::month_of(&rfc3339(now_ms())); | |
| 343 | let list: Vec<WorkspaceGitOperations> = | |
| 344 | g1t_kit::call(repos, "git_operations", &GitOperationsArgs { since: Some(git_since(&month)), month: month.clone(), namespace: None }).await?; | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 345 | let price = self.price("git_operations").await?.map_or(GIT_MICROS_PER_THOUSAND as f64, |(cost, _)| cost); |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 346 | for workspace in list { |
| 347 | let slug = workspace.namespace.to_lowercase(); | |
| 348 | if self.plan_kind(&slug).await? == PlanKind::Free { | |
| 349 | continue; | |
| 350 | } | |
| 351 | let cost = git_cost(workspace.operations, self.plans.git_included, price); | |
| 352 | if cost > 0 { | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 353 | let detail = format!( |
| 354 | "{} operations, {} of them free", | |
| 355 | crate::features::thousands(workspace.operations), | |
| 356 | crate::features::thousands(self.plans.git_included) | |
| 357 | ); | |
| 358 | self.set_pending(&slug, "git", &month, cost, Some(&detail)).await?; | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 359 | } |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 360 | } |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 361 | Ok(()) |
| 362 | } | |
| 363 | ||
| 364 | /// The workspace's git operations this month, as last measured. | |
| 365 | pub(crate) async fn git_operations_this_month(&self, workspace: &str) -> Result<u64> { | |
| 366 | let Some(repos) = &self.repos else { return Ok(0) }; | |
| 367 | let month = credits::month_of(&rfc3339(now_ms())); | |
| 368 | let list: Result<Vec<WorkspaceGitOperations>> = | |
| 369 | g1t_kit::call(repos, "git_operations", &GitOperationsArgs { since: Some(format!("{month}-01T00")), month, namespace: Some(workspace.to_lowercase()) }).await; | |
| 370 | Ok(list | |
| 371 | .ok() | |
| 372 | .and_then(|list| list.into_iter().find(|w| w.namespace.eq_ignore_ascii_case(workspace))) | |
| 373 | .map_or(0, |w| w.operations)) | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 374 | } |
| 375 | } | |
| 376 | ||
| 377 | #[cfg(test)] | |
| 378 | mod tests { | |
| 379 | use super::*; | |
| 380 | ||
| 381 | #[test] | |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 382 | fn scans_and_embeddings_on_a_free_workspace_are_covered_by_g1t() { |
| 383 | // No plan: g1t pays, and the trial is left alone. | |
| 384 | let free = month_end_eligible("security", false); | |
| 385 | assert!(free.cover_rest && !free.trial); | |
| 386 | assert!(month_end_eligible("context", false).cover_rest); | |
| 387 | // On the plan: charged like any usage, from its included usage first. | |
| 388 | let plan = month_end_eligible("security", true); | |
| 389 | assert!(!plan.cover_rest && plan.trial); | |
| 390 | // Storage, git and the cache are never kept for a free workspace; | |
| 391 | // were one at the close, it would not be covered either. | |
| 392 | assert!(!month_end_eligible("storage", false).cover_rest); | |
| 393 | assert!(!month_end_eligible("git", false).cover_rest); | |
| 394 | // A covered source is still a source billing charges at the close. | |
| 395 | assert!(COVERED_FOR_FREE.iter().all(|s| CHARGED_HERE.contains(s))); | |
| 396 | } | |
| 397 | ||
| 398 | #[test] | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 399 | fn storage_past_the_free_amount_is_counted_by_the_day() { |
| 400 | // 3 GB private with 1 GB free, every day of a 30-day month: 2 GB-months. | |
| 401 | let month = vec![(3_000_000_000, 1_000_000_000); 30]; | |
| 402 | assert!((storage_gb_months(&month) - 2.0).abs() < 1e-9); | |
| 403 | // Under the free amount: nothing. | |
| 404 | assert_eq!(storage_gb_months(&[(500_000_000, 1_000_000_000); 30]), 0.0); | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 405 | // The plan has the same 1 GB free: 11 GB on it all month is 10 |
| 406 | // GB-months, $5.00 to g1t, $6.00 charged, from its included usage. | |
| 407 | let days = vec![(11_000_000_000, 1_000_000_000); 30]; | |
| 408 | assert!((storage_gb_months(&days) - 10.0).abs() < 1e-9); | |
| 409 | assert_eq!(credits::with_margin(storage_cost(storage_gb_months(&days), STORAGE_MICROS_PER_GB_MONTH as f64), 20), 6_000_000); | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 410 | // Ten days of 4 GB past it: a third of 4 GB-months. |
| 411 | let days = vec![(5_000_000_000, 1_000_000_000); 10]; | |
| 412 | assert!((storage_gb_months(&days) - 4.0 / 3.0).abs() < 1e-9); | |
| 413 | } | |
| 414 | ||
| 415 | #[test] | |
| 416 | fn storage_is_priced_at_cloudflares_rate_plus_the_margin() { | |
| 417 | // $0.50 a GB-month to g1t: 2 GB-months cost $1.00, charged $1.20. | |
| 418 | let cost = storage_cost(2.0, 500_000.0); | |
| 419 | assert_eq!(cost, 1_000_000); | |
| 420 | assert_eq!(credits::with_margin(cost, 20), 1_200_000); | |
| 421 | // A fraction of a millionth rounds up. | |
| 422 | assert_eq!(storage_cost(0.000_000_001, 500_000.0), 1); | |
| 423 | } | |
| 424 | ||
| 425 | #[test] | |
| 426 | fn embeddings_and_scans_are_charged_at_cost_plus_the_margin() { | |
| 427 | // 10 million tokens at $0.067 a million: $0.67, charged $0.804. | |
| 428 | assert_eq!(credits::with_margin(670_000, 20), 804_000); | |
| 429 | assert_eq!(title("context"), "Search embeddings"); | |
| 430 | assert_eq!(title("security"), "Security scans"); | |
| 431 | assert!(CHARGED_HERE.contains(&"storage") && !CHARGED_HERE.contains(&"deployments")); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 432 | assert!(CHARGED_HERE.contains(&"git")); |
| 433 | } | |
| 434 | ||
| 435 | #[test] | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 436 | fn git_operations_are_charged_past_the_free_amount_at_cloudflares_price() { |
| 437 | // $0.15 per 1,000 to g1t; 50,000 a month free for everyone. | |
| 438 | let per_thousand = GIT_MICROS_PER_THOUSAND as f64; | |
| 439 | let free = crate::credits::Config::default().git_included; | |
| 440 | assert_eq!(free, 50_000); | |
| 441 | assert_eq!(git_cost(49_000, free, per_thousand), 0); | |
| 442 | assert_eq!(git_cost(50_000, free, per_thousand), 0); | |
| 443 | // A workspace on the plan pushes on past it, and pays: 70,000 | |
| 444 | // operations are 20,000 past it, $3.00 to g1t, $3.60 charged. | |
| 445 | assert_eq!(git_cost(70_000, free, per_thousand), 3_000_000); | |
| 446 | assert_eq!(credits::with_margin(git_cost(70_000, free, per_thousand), 20), 3_600_000); | |
| 447 | // A million in a month: no cap, $142.50 to g1t. | |
| 448 | assert_eq!(git_cost(1_000_000, free, per_thousand), 142_500_000); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 449 | // One past it: a fraction of a cent, rounded up to a millionth. |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 450 | assert_eq!(git_cost(50_001, free, per_thousand), 150); |
| 451 | assert_eq!(title("git"), "Git operations past the free amount"); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 452 | } |
| 453 | ||
| 454 | #[test] | |
| 455 | fn git_operations_count_from_when_cloudflare_starts_charging() { | |
| 456 | assert_eq!(git_since("2026-10"), "2026-10-14T00"); | |
| 457 | assert_eq!(git_since("2026-11"), "2026-11-01T00"); | |
| 458 | assert_eq!(git_since("2026-09"), "2026-10-14T00"); | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 459 | } |
| 460 | } |