Skip to content

refactor(neuralwatt): replace current_period_start/end with kwh_reset_date#1794

Merged
looplj merged 2 commits into
looplj:unstablefrom
djdembeck:feat/replace-period-dates-kwh-reset
Jun 7, 2026
Merged

refactor(neuralwatt): replace current_period_start/end with kwh_reset_date#1794
looplj merged 2 commits into
looplj:unstablefrom
djdembeck:feat/replace-period-dates-kwh-reset

Conversation

@djdembeck

Copy link
Copy Markdown
Contributor

Summary

Replaced current_period_start and current_period_end fields with kwh_reset_date in the NeuralWatt quota checker to better align with NeuralWatt's API subscription model and simplify quota reset date tracking.

Spirit/Intent

Use a single kwh_reset_date field instead of period start/end dates for clearer quota reset tracking specific to NeuralWatt's kWh-based billing model.

Key Changes

  • neuralwatt_checker.go: Replaced CurrentPeriodStart and CurrentPeriodEnd with KwhResetDate in NeuralWattSubscription struct; updated parseResponse() to parse kwh_reset_date field
  • neuralwatt_checker_test.go: Updated all test fixtures to use kwh_reset_date instead of current_period_start/current_period_end
  • quotas.ts: Updated TypeScript type definitions to reflect the backend field changes

Risks

  • Breaking change for any frontend code relying on current_period_start or current_period_end - must ensure all consumers are updated to use kwh_reset_date
  • Test coverage maintained but assumes API response format matches new structure

djdembeck added 2 commits June 6, 2026 15:18
Replace CurrentPeriodStart/End with KwhResetDate for accurate
NeuralWatt quota reset date tracking.

- Remove CurrentPeriodStart and CurrentPeriodEnd from NeuralWattBalance struct
- Add KwhResetDate field for explicit quota reset tracking
- Update parseResponse to read kwh_reset_date from API response
- Update convertNeuralWattSubscriptionToMap to include kwh_reset_date
- Update frontend quota types with new subscription fields
- Update all test cases to use kwh_reset_date instead of period dates
- Add new test function for kwh_reset_date handling
- Add kwh_reset_date field and NextResetAt assertions to WarningState
  and ZeroRemainingWithoutOverage tests, matching ExhaustedState pattern
- Fix R3 inconsistency: all subscription tests now exercise reset-date
  parsing, restoring coverage that existed before the field rename
@djdembeck djdembeck force-pushed the feat/replace-period-dates-kwh-reset branch from 79540c5 to aa7289d Compare June 6, 2026 22:49
@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Replaces current_period_start/current_period_end with a single kwh_reset_date field across the NeuralWatt quota checker, better matching the provider's billing model. All three layers — Go struct, map serialization, and TypeScript type — are updated consistently.

  • neuralwatt_checker.go: NeuralWattSubscription drops both period fields and gains KwhResetDate; parseResponse and convertNeuralWattSubscriptionToMap updated accordingly.
  • neuralwatt_checker_test.go: All fixtures migrated to kwh_reset_date; NextResetAt assertions added to warning/exhausted/zero-remaining tests; a dedicated TestNeuralWatt_CheckQuota_KwhResetDate test added for the available state.
  • quotas.ts: kwh_reset_date?: string | null added to ProviderNeuralWattQuotaData; a grep confirms no other frontend code referenced the removed fields.

Confidence Score: 4/5

Safe to merge — the field rename is complete across Go struct, serialization, and TypeScript types, with no remaining references to the old fields in NeuralWatt code.

The change is narrow and well-contained. A grep confirms current_period_start/current_period_end survive only in the unrelated nanogpt_checker.go. Test coverage for the new field is solid, including the new dedicated test. Only a stray double blank line was found.

No files require special attention; the double blank line in neuralwatt_checker.go is cosmetic.

Important Files Changed

Filename Overview
internal/server/biz/provider_quota/neuralwatt_checker.go Swaps CurrentPeriodStart/End for KwhResetDate in the struct and map builder; logic is correct. Minor: double blank line left in convertNeuralWattSubscriptionToMap after the removed blocks.
internal/server/biz/provider_quota/neuralwatt_checker_test.go All fixtures updated to kwh_reset_date; new assertions added for NextResetAt in warning/exhausted/zero-remaining tests; dedicated TestNeuralWatt_CheckQuota_KwhResetDate added for the available state.
frontend/src/features/system/data/quotas.ts Adds kwh_reset_date to ProviderNeuralWattQuotaData subscription type; no other frontend code references the removed or new fields.

Sequence Diagram

sequenceDiagram
    participant FE as Frontend (quotas.ts)
    participant API as GraphQL API
    participant QC as NeuralWattQuotaChecker
    participant NW as NeuralWatt API

    FE->>API: ProviderQuotaStatuses query
    API->>QC: CheckQuota(ctx, channel)
    QC->>NW: GET /v1/quota (Bearer token)
    NW-->>QC: "{ subscription: { kwh_reset_date, kwh_remaining, ... } }"
    QC->>QC: parseResponse() - time.Parse(RFC3339, kwh_reset_date) to nextResetAt
    QC->>QC: convertNeuralWattSubscriptionToMap() - includes kwh_reset_date
    QC-->>API: "QuotaData { status, NextResetAt, RawData }"
    API-->>FE: "providerQuotaStatus { nextResetAt, quotaData.subscription.kwh_reset_date }"
Loading

Comments Outside Diff (1)

  1. internal/server/biz/provider_quota/neuralwatt_checker.go, line 207-212 (link)

    P2 A stray double blank line was left behind after the current_period_start/current_period_end blocks were removed, creating inconsistent spacing compared with every other field guard in the function.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix: add kwh_reset_date to remaining Neu..." | Re-trigger Greptile

@looplj looplj merged commit 98c7855 into looplj:unstable Jun 7, 2026
4 checks passed
junjiangao pushed a commit to junjiangao/axonhub that referenced this pull request Jun 9, 2026
…_date (looplj#1794)

* fix: replace current_period_start/end with kwh_reset_date

Replace CurrentPeriodStart/End with KwhResetDate for accurate
NeuralWatt quota reset date tracking.

- Remove CurrentPeriodStart and CurrentPeriodEnd from NeuralWattBalance struct
- Add KwhResetDate field for explicit quota reset tracking
- Update parseResponse to read kwh_reset_date from API response
- Update convertNeuralWattSubscriptionToMap to include kwh_reset_date
- Update frontend quota types with new subscription fields
- Update all test cases to use kwh_reset_date instead of period dates
- Add new test function for kwh_reset_date handling

* fix: add kwh_reset_date to remaining NeuralWatt test fixtures

- Add kwh_reset_date field and NextResetAt assertions to WarningState
  and ZeroRemainingWithoutOverage tests, matching ExhaustedState pattern
- Fix R3 inconsistency: all subscription tests now exercise reset-date
  parsing, restoring coverage that existed before the field rename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants