LCOV - code coverage report
Current view: top level - src/platform/billing/subscription/composables - useFreeTierQuota.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 84.6 % 13 11
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { createSharedComposable } from '@vueuse/core'
       2              : import { computed, ref, watch } from 'vue'
       3              : 
       4              : import { isCloud } from '@/platform/distribution/types'
       5              : import { remoteConfig } from '@/platform/remoteConfig/remoteConfig'
       6              : import { useApp } from '@/scripts/appInstance'
       7              : import { graphCreditsBadges } from '@/systems/badgeSystem'
       8              : 
       9         2356 : export const useFreeTierQuota = createSharedComposable(function () {
      10         2355 :   const available = ref(0)
      11         2355 :   const maxAvailable = ref(0)
      12         2355 :   watch(
      13              :     () => remoteConfig.value.free_tier_balance?.remaining,
      14              :     (val) => (available.value = val ?? 0),
      15              :     { immediate: true }
      16              :   )
      17         2355 :   watch(
      18              :     () => remoteConfig.value.free_tier_balance?.allowance,
      19              :     (val) => (maxAvailable.value = val ?? 0),
      20              :     { immediate: true }
      21              :   )
      22              : 
      23         2355 :   const quotaEnabled = computed(() => isCloud && maxAvailable.value > 0)
      24         2355 :   const hasInvalidNodes = computed(() => {
      25            0 :     const app = useApp()
      26            0 :     return app.isGraphReady && graphCreditsBadges(app.rootGraph).length > 0
      27              :   })
      28         2355 :   const freeTierExecutionPermitted = computed(
      29              :     () => !hasInvalidNodes.value && quotaEnabled.value && available.value > 0
      30              :   )
      31              : 
      32          150 :   function trackRun() {
      33          150 :     if (available.value > 0) available.value--
      34              :   }
      35              : 
      36         2355 :   return {
      37              :     available,
      38              :     freeTierExecutionPermitted,
      39              :     hasInvalidNodes,
      40              :     maxAvailable,
      41              :     quotaEnabled,
      42              :     trackRun
      43              :   }
      44              : })
        

Generated by: LCOV version 2.0-1