Skip to content

refactor: hides more services inside DI#1665

Merged
stalniy merged 1 commit intomainfrom
refactor/services
Jul 11, 2025
Merged

refactor: hides more services inside DI#1665
stalniy merged 1 commit intomainfrom
refactor/services

Conversation

@stalniy
Copy link
Contributor

@stalniy stalniy commented Jul 11, 2025

Why

For better unit testing, lazy creation and central control over axios based http requests

Summary by CodeRabbit

  • Refactor

    • Updated how GitHub, Bitbucket, and GitLab services are accessed throughout the app for improved consistency and maintainability.
    • API URL service is now dynamically provided via a context hook rather than static imports.
    • Internal service instantiation and dependency injection were streamlined for remote deployment and API URL management.
  • Bug Fixes

    • No user-facing bugs were fixed, but internal service management is now more robust.
  • Tests

    • Improved test reliability by switching to per-test-instance mocks for service dependencies, enhancing test isolation and clarity.
  • Chores

    • Removed deprecated and unused API URL service files to clean up the codebase.

@stalniy stalniy requested a review from a team as a code owner July 11, 2025 07:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Warning

Rate limit exceeded

@stalniy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6357c64 and 49aad97.

📒 Files selected for processing (16)
  • apps/deploy-web/src/components/remote-deploy/RemoteRepositoryDeployManager.tsx (5 hunks)
  • apps/deploy-web/src/pages/profile/[username]/index.tsx (1 hunks)
  • apps/deploy-web/src/pages/template/[id]/index.tsx (1 hunks)
  • apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx (10 hunks)
  • apps/deploy-web/src/queries/useBitBucketQuery.ts (9 hunks)
  • apps/deploy-web/src/queries/useGithubQuery.spec.tsx (7 hunks)
  • apps/deploy-web/src/queries/useGithubQuery.ts (7 hunks)
  • apps/deploy-web/src/queries/useGitlabQuery.spec.tsx (10 hunks)
  • apps/deploy-web/src/queries/useGitlabQuery.ts (5 hunks)
  • apps/deploy-web/src/services/api-url/browser-api-url.service.ts (0 hunks)
  • apps/deploy-web/src/services/api-url/server-api-url.service.ts (0 hunks)
  • apps/deploy-web/src/services/app-di-container/app-di-container.ts (2 hunks)
  • apps/deploy-web/src/services/http/http-browser.service.ts (2 hunks)
  • apps/deploy-web/src/services/http/http-server.service.ts (2 hunks)
  • apps/deploy-web/src/services/remote-deploy/github-http.service.ts (7 hunks)
  • apps/deploy-web/src/utils/apiUtils.ts (2 hunks)

Walkthrough

This change refactors the codebase to centralize the instantiation and access of API service classes (GitHub, Bitbucket, GitLab, and API URL services) via a dependency injection context (useServices). It removes deprecated singleton service exports, updates hooks and components to use context-provided services, and adjusts related tests for dependency injection.

Changes

File(s) Change Summary
RemoteRepositoryDeployManager.tsx, useGithubQuery.ts, useBitBucketQuery.ts, useGitlabQuery.ts Refactored to obtain GitHub, Bitbucket, and GitLab service instances from useServices context instead of local instantiation.
useGithubQuery.spec.tsx, useBitBucketQuery.spec.tsx, useGitlabQuery.spec.tsx Updated tests to use per-test injected service mocks via dependency injection, replacing global Jest mocks.
profile/[username]/index.tsx, template/[id]/index.tsx Replaced static API URL config with dynamic retrieval from services.apiUrlService.getBaseApiUrlFor("mainnet").
api-url/browser-api-url.service.ts, api-url/server-api-url.service.ts Deleted deprecated singleton API URL service exports in favor of context-based service retrieval.
http/http-browser.service.ts, http/http-server.service.ts Updated DI containers to provide services via factory functions; added GitHub, Bitbucket, and GitLab service factories.
app-di-container/app-di-container.ts Changed apiUrlService in DI config from instance to factory function; updated interface and container logic.
github-http.service.ts Refactored GitHubService to use a private Axios instance member instead of a module-level variable.
apiUtils.ts Updated to use services.apiUrlService for base API URL instead of deprecated singleton.

Sequence Diagram(s)

sequenceDiagram
    participant Component/Hook
    participant ServicesContext
    participant ServiceInstance

    Component/Hook->>ServicesContext: useServices()
    ServicesContext-->>Component/Hook: { githubService, bitbucketService, gitlabService, apiUrlService }
    Component/Hook->>ServiceInstance: Call service method (e.g., fetchUserProfile)
    ServiceInstance-->>Component/Hook: Response
Loading

Possibly related PRs

Suggested reviewers

  • ygrishajev

Poem

In the warren of code where the services hop,
We gathered them all in one central shop.
No more singletons lost in the thicket,
Now fetched from context, quick as a cricket!
With tests now injected and Axios in tow,
The rabbit approves—let the clean code grow!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 72.02%. Comparing base (a19a7db) to head (49aad97).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../src/services/remote-deploy/github-http.service.ts 14.28% 6 Missing ⚠️
...eploy-web/src/services/http/http-server.service.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1665      +/-   ##
==========================================
- Coverage   72.28%   72.02%   -0.27%     
==========================================
  Files         590      591       +1     
  Lines       13507    13660     +153     
  Branches     2218     2293      +75     
==========================================
+ Hits         9764     9839      +75     
- Misses       3424     3601     +177     
+ Partials      319      220      -99     
Flag Coverage Δ *Carryforward flag
api 80.00% <ø> (ø) Carriedforward from a19a7db
deploy-web 55.92% <87.50%> (-0.22%) ⬇️
notifications 87.90% <ø> (ø) Carriedforward from a19a7db
provider-proxy 84.23% <ø> (ø) Carriedforward from a19a7db

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
apps/deploy-web/src/queries/useBitBucketQuery.ts 100.00% <100.00%> (ø)
apps/deploy-web/src/queries/useGithubQuery.ts 98.43% <100.00%> (+0.16%) ⬆️
apps/deploy-web/src/queries/useGitlabQuery.ts 98.76% <100.00%> (+0.13%) ⬆️
.../src/services/app-di-container/app-di-container.ts 83.78% <ø> (-8.53%) ⬇️
...ploy-web/src/services/http/http-browser.service.ts 88.88% <100.00%> (+7.07%) ⬆️
apps/deploy-web/src/utils/apiUtils.ts 35.05% <100.00%> (ø)
...eploy-web/src/services/http/http-server.service.ts 94.44% <50.00%> (-5.56%) ⬇️
.../src/services/remote-deploy/github-http.service.ts 19.35% <14.28%> (ø)

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
apps/deploy-web/src/queries/useGithubQuery.spec.tsx (1)

11-180: Consider using setup function for better test structure

According to the coding guidelines, test files should use a setup function instead of beforeEach. While the current setupQuery helper works, consider restructuring to use a setup function at the bottom of the root describe block that creates the object under test and returns it.

apps/deploy-web/src/services/remote-deploy/github-http.service.ts (1)

82-84: Consider consistency in axios usage

The fetchAccessToken method still uses the external axios directly instead of the private axiosInstance. While this might be intentional since it calls a different endpoint (/api/github/authenticate), consider whether this should also use the private instance for consistency, or if it needs different configuration.

apps/deploy-web/src/queries/useGitlabQuery.spec.tsx (1)

21-246: Consider adding a setup function for consistency with coding guidelines.

According to the coding guidelines, test files should use a setup function instead of beforeEach. While these tests don't use beforeEach, they also don't follow the prescribed setup function pattern. The current setupQuery approach works well for this specific use case, but consider if a setup function would be more appropriate for consistency.

The setup function should:

  • Be at the bottom of the root describe block
  • Create an object under test and return it
  • Accept a single parameter with inline type definition
  • Not use shared state
  • Not specify return type
apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx (1)

21-281: Consider adding a setup function for consistency with coding guidelines.

According to the coding guidelines, test files should use a setup function instead of beforeEach. While these tests don't use beforeEach, they also don't follow the prescribed setup function pattern. The current setupQuery approach works well for this specific use case, but consider if a setup function would be more appropriate for consistency.

The setup function should:

  • Be at the bottom of the root describe block
  • Create an object under test and return it
  • Accept a single parameter with inline type definition
  • Not use shared state
  • Not specify return type
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 768c503 and 6357c64.

📒 Files selected for processing (16)
  • apps/deploy-web/src/components/remote-deploy/RemoteRepositoryDeployManager.tsx (5 hunks)
  • apps/deploy-web/src/pages/profile/[username]/index.tsx (1 hunks)
  • apps/deploy-web/src/pages/template/[id]/index.tsx (1 hunks)
  • apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx (10 hunks)
  • apps/deploy-web/src/queries/useBitBucketQuery.ts (9 hunks)
  • apps/deploy-web/src/queries/useGithubQuery.spec.tsx (7 hunks)
  • apps/deploy-web/src/queries/useGithubQuery.ts (7 hunks)
  • apps/deploy-web/src/queries/useGitlabQuery.spec.tsx (10 hunks)
  • apps/deploy-web/src/queries/useGitlabQuery.ts (5 hunks)
  • apps/deploy-web/src/services/api-url/browser-api-url.service.ts (0 hunks)
  • apps/deploy-web/src/services/api-url/server-api-url.service.ts (0 hunks)
  • apps/deploy-web/src/services/app-di-container/app-di-container.ts (2 hunks)
  • apps/deploy-web/src/services/http/http-browser.service.ts (1 hunks)
  • apps/deploy-web/src/services/http/http-server.service.ts (2 hunks)
  • apps/deploy-web/src/services/remote-deploy/github-http.service.ts (7 hunks)
  • apps/deploy-web/src/utils/apiUtils.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • apps/deploy-web/src/services/api-url/browser-api-url.service.ts
  • apps/deploy-web/src/services/api-url/server-api-url.service.ts
🧰 Additional context used
📓 Path-based instructions (2)
`apps/{deploy-web,provider-console}/**/*.spec.tsx`: Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files

apps/{deploy-web,provider-console}/**/*.spec.tsx: Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

📄 Source: CodeRabbit Inference Engine (.cursor/rules/query-by-in-tests.mdc)

List of files the instruction was applied to:

  • apps/deploy-web/src/queries/useGithubQuery.spec.tsx
  • apps/deploy-web/src/queries/useGitlabQuery.spec.tsx
  • apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx
`**/*.spec.{ts,tsx}`: Use `setup` function instead of `beforeEach` in test files...

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

📄 Source: CodeRabbit Inference Engine (.cursor/rules/setup-instead-of-before-each.mdc)

List of files the instruction was applied to:

  • apps/deploy-web/src/queries/useGithubQuery.spec.tsx
  • apps/deploy-web/src/queries/useGitlabQuery.spec.tsx
  • apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx
🧠 Learnings (11)
apps/deploy-web/src/pages/profile/[username]/index.tsx (2)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: ygrishajev
PR: akash-network/console#1512
File: apps/deploy-web/src/components/deployments/DeploymentBalanceAlert/DeploymentBalanceAlert.tsx:47-68
Timestamp: 2025-06-19T16:00:05.428Z
Learning: In React Hook Form setups with zod validation, child components using useFormContext() can rely on parent form validation rather than implementing local input validation. Invalid inputs like NaN from parseFloat() are handled by the parent schema validation, eliminating the need for additional local validation in child components.
apps/deploy-web/src/pages/template/[id]/index.tsx (2)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: ygrishajev
PR: akash-network/console#1512
File: apps/deploy-web/src/components/deployments/DeploymentBalanceAlert/DeploymentBalanceAlert.tsx:47-68
Timestamp: 2025-06-19T16:00:05.428Z
Learning: In React Hook Form setups with zod validation, child components using useFormContext() can rely on parent form validation rather than implementing local input validation. Invalid inputs like NaN from parseFloat() are handled by the parent schema validation, eliminating the need for additional local validation in child components.
apps/deploy-web/src/queries/useGitlabQuery.ts (2)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: jzsfkzm
PR: akash-network/console#1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.
apps/deploy-web/src/queries/useBitBucketQuery.ts (2)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: jzsfkzm
PR: akash-network/console#1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.
apps/deploy-web/src/services/remote-deploy/github-http.service.ts (2)
Learnt from: jzsfkzm
PR: akash-network/console#1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
apps/deploy-web/src/utils/apiUtils.ts (1)
Learnt from: jzsfkzm
PR: akash-network/console#1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.
apps/deploy-web/src/queries/useGithubQuery.ts (1)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
apps/deploy-web/src/components/remote-deploy/RemoteRepositoryDeployManager.tsx (1)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
apps/deploy-web/src/queries/useGithubQuery.spec.tsx (8)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function
Learnt from: stalniy
PR: akash-network/console#1436
File: apps/api/src/provider/repositories/provider/provider.repository.ts:79-90
Timestamp: 2025-06-08T03:07:13.871Z
Learning: The getProvidersHostUriByAttributes method in apps/api/src/provider/repositories/provider/provider.repository.ts already has comprehensive test coverage in provider.repository.spec.ts, including tests for complex HAVING clause logic with COUNT(*) FILTER (WHERE ...) syntax, signature conditions (anyOf/allOf), and glob pattern matching.
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block
apps/deploy-web/src/queries/useGitlabQuery.spec.tsx (6)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Learnt from: stalniy
PR: akash-network/console#1436
File: apps/api/src/provider/repositories/provider/provider.repository.ts:79-90
Timestamp: 2025-06-08T03:07:13.871Z
Learning: The getProvidersHostUriByAttributes method in apps/api/src/provider/repositories/provider/provider.repository.ts already has comprehensive test coverage in provider.repository.spec.ts, including tests for complex HAVING clause logic with COUNT(*) FILTER (WHERE ...) syntax, signature conditions (anyOf/allOf), and glob pattern matching.
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block
apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx (5)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function
Learnt from: stalniy
PR: akash-network/console#1436
File: apps/api/src/provider/repositories/provider/provider.repository.ts:79-90
Timestamp: 2025-06-08T03:07:13.871Z
Learning: The getProvidersHostUriByAttributes method in apps/api/src/provider/repositories/provider/provider.repository.ts already has comprehensive test coverage in provider.repository.spec.ts, including tests for complex HAVING clause logic with COUNT(*) FILTER (WHERE ...) syntax, signature conditions (anyOf/allOf), and glob pattern matching.
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
🧬 Code Graph Analysis (7)
apps/deploy-web/src/pages/profile/[username]/index.tsx (1)
apps/deploy-web/src/services/http/http-server.service.ts (1)
  • services (22-31)
apps/deploy-web/src/queries/useGitlabQuery.ts (5)
apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1)
  • useServices (30-32)
apps/deploy-web/src/store/remoteDeployStore.ts (1)
  • tokens (3-13)
apps/deploy-web/src/types/remoteProfile.ts (1)
  • GitLabProfile (33-47)
apps/deploy-web/src/queries/queryKeys.ts (1)
  • QueryKeys (1-84)
apps/deploy-web/src/types/remotedeploy.ts (1)
  • PackageJson (14-18)
apps/deploy-web/src/queries/useBitBucketQuery.ts (1)
apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1)
  • useServices (30-32)
apps/deploy-web/src/services/remote-deploy/github-http.service.ts (3)
apps/deploy-web/src/types/remoteProfile.ts (1)
  • GitHubProfile (2-2)
apps/deploy-web/src/types/remotedeploy.ts (1)
  • GithubRepository (2-2)
apps/deploy-web/src/types/remoteCommits.ts (1)
  • GitCommit (2-2)
apps/deploy-web/src/services/app-di-container/app-di-container.ts (1)
apps/deploy-web/src/utils/apiUtils.ts (1)
  • ApiUrlService (7-126)
apps/deploy-web/src/queries/useGithubQuery.ts (1)
apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1)
  • useServices (30-32)
apps/deploy-web/src/components/remote-deploy/RemoteRepositoryDeployManager.tsx (1)
apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1)
  • useServices (30-32)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (22)
apps/deploy-web/src/pages/template/[id]/index.tsx (1)

37-37: Excellent refactoring to use dynamic service-based API URL retrieval.

This change properly encapsulates API URL logic within the service layer and enables better testability by removing direct dependency on static configuration.

apps/deploy-web/src/utils/apiUtils.ts (2)

3-3: Correct update to use centralized services container.

This change properly replaces the deprecated browserApiUrlService with the new centralized services approach.


124-124: Well-executed migration to service-based API URL retrieval.

The static getter now correctly uses the services container while maintaining the same interface for consumers.

apps/deploy-web/src/pages/profile/[username]/index.tsx (1)

27-27: Consistent refactoring pattern applied correctly.

This change mirrors the template page refactoring, maintaining consistency across server-side rendered pages by using dynamic service-based API URL retrieval.

apps/deploy-web/src/services/http/http-server.service.ts (2)

8-8: Correct import update for DI refactoring.

Replacing the deprecated singleton service import with the class import supports the new factory-based instantiation pattern.


19-19: Excellent implementation of factory-based service instantiation.

This change properly implements dependency injection by using a factory function instead of a static singleton, enabling better testability and lazy initialization.

apps/deploy-web/src/queries/useGithubQuery.ts (2)

5-5: Proper context import for DI pattern.

Adding the useServices import enables context-based service retrieval, supporting the dependency injection refactoring.


12-12: Excellent consistent refactoring across all GitHub hooks.

The consistent pattern of using const { githubService } = useServices() properly implements dependency injection while maintaining the same hook interfaces. This refactoring improves:

  • Testability: Services can now be easily mocked in tests
  • Centralized management: Service configuration is centralized in the DI container
  • Lazy initialization: Services are created only when needed

The hook logic remains unchanged, ensuring no functional regressions while achieving architectural improvements.

Also applies to: 23-23, 33-33, 44-44, 55-55, 81-81, 100-100

apps/deploy-web/src/components/remote-deploy/RemoteRepositoryDeployManager.tsx (2)

10-10: LGTM: Proper dependency injection implementation

The refactoring correctly implements the dependency injection pattern by importing and using the useServices hook to obtain service instances from the React context instead of creating them locally.

Also applies to: 42-42


160-160: LGTM: Consistent service usage pattern

All service method calls correctly use the context-provided instances (bitbucketService, gitlabService, githubService) instead of locally instantiated services. This achieves the PR objectives of centralizing service management and improving testability.

Also applies to: 170-170, 181-181, 183-183

apps/deploy-web/src/queries/useGitlabQuery.ts (1)

6-6: LGTM: Consistent dependency injection pattern across all hooks

Excellent refactoring that consistently applies the dependency injection pattern across all GitLab-related hooks. Each hook properly retrieves the gitlabService instance from the React context using useServices(), maintaining the same functionality while improving testability and service management.

Also applies to: 14-14, 32-32, 48-48, 68-68, 78-78, 88-88, 98-98, 108-108, 133-133

apps/deploy-web/src/queries/useBitBucketQuery.ts (1)

6-6: LGTM: Consistent dependency injection implementation

The refactoring successfully applies the dependency injection pattern consistently across all Bitbucket-related hooks. Each hook properly obtains the bitbucketService instance from the React context, maintaining functional consistency while improving the service architecture.

Also applies to: 15-15, 29-29, 46-46, 66-66, 77-77, 88-88, 99-99, 110-110, 129-129

apps/deploy-web/src/queries/useGithubQuery.spec.tsx (1)

2-2: LGTM: Improved test isolation with per-test mocks

The refactoring successfully removes global mocks in favor of per-test mock instances injected via the services option. This improves test isolation and aligns with the dependency injection pattern. The use of jest-mock-extended provides better type safety for mocks.

Also applies to: 4-4, 15-17, 20-24, 42-44, 46-50, 63-65, 67-71, 85-87, 89-93, 112-114, 116-120, 140-142, 144-148, 163-165, 167-171

apps/deploy-web/src/services/remote-deploy/github-http.service.ts (1)

11-17: LGTM: Proper encapsulation of axios instance

Excellent refactoring that encapsulates the axios instance as a private class member. This improves encapsulation and makes the service more self-contained. All GitHub API calls consistently use the private instance with proper configuration.

Also applies to: 28-28, 37-37, 46-46, 55-55, 64-64, 73-73

apps/deploy-web/src/services/app-di-container/app-di-container.ts (2)

76-76: LGTM! Consistent DI pattern implementation.

The change correctly updates the container to use the factory function directly instead of wrapping it, which aligns with the new DI pattern where apiUrlService is expected to be a factory function in the config.


119-119: LGTM! Interface correctly updated for factory function pattern.

The interface change properly reflects that apiUrlService should now be a factory function returning an ApiUrlService instance, which is consistent with the DI container pattern.

apps/deploy-web/src/queries/useGitlabQuery.spec.tsx (2)

3-3: LGTM! Good use of jest-mock-extended for type-safe mocking.

The import of jest-mock-extended enables better type safety and per-test isolation compared to global mocks.


25-34: LGTM! Excellent per-test mocking strategy.

The use of jest-mock-extended with per-test mock instances provides better test isolation and type safety. The service injection through setupQuery aligns well with the new DI pattern.

apps/deploy-web/src/services/http/http-browser.service.ts (2)

15-15: LGTM! Factory function pattern correctly implemented.

The change from using a singleton import to creating an instance via factory function aligns perfectly with the DI pattern and enables better testability and control.


20-22: LGTM! Remote deployment services properly added to DI container.

The addition of GitHub, Bitbucket, and GitLab services to the container enables centralized service access through the useServices hook, which supports the architectural goal of this refactoring.

apps/deploy-web/src/queries/useBitBucketQuery.spec.tsx (2)

3-3: LGTM! Good use of jest-mock-extended for type-safe mocking.

The import of jest-mock-extended enables better type safety and per-test isolation compared to global mocks.


25-34: LGTM! Excellent per-test mocking strategy.

The use of jest-mock-extended with per-test mock instances provides better test isolation and type safety. The service injection through setupQuery aligns well with the new DI pattern.

baktun14
baktun14 previously approved these changes Jul 11, 2025
@stalniy stalniy force-pushed the refactor/services branch from 6357c64 to 49aad97 Compare July 11, 2025 11:02
@stalniy stalniy merged commit 705bdb6 into main Jul 11, 2025
57 checks passed
@stalniy stalniy deleted the refactor/services branch July 11, 2025 11:10
stalniy added a commit that referenced this pull request Nov 20, 2025
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

Comments