[PR #207] refactor: reduce cognitive complexity across codebase #208

Open
opened 2026-02-16 09:19:50 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-sandbox/pull/207
Author: @Galois123
Created: 1/12/2026
Status: 🔄 Open

Base: mainHead: refactor/reduce-code-complexity


📝 Commits (9)

  • fa94ad0 refactor: reduce cognitive complexity of releaseLibBinary method
  • 2557bc5 refactor: reduce complexity of output capture runner
  • cb07461 refactor: reuse error format string in output capture
  • 555c1b9 refactor: simplify python releaseLibBinary flow
  • ff00772 refactor: split InstallDependencies into focused helpers
  • 0c20710 refactor: TempDirRunner to reduce complexity
  • cec0684 refactor: reduce cognitive complexity of InitConfig
  • 3bbc877 refactor: deduplicate log file date format string
  • ce822f4 refactor: extract "unsupported language" to constant

📊 Changes

7 files changed (+431 additions, -318 deletions)

View changed files

📝 internal/controller/run.go (+6 -4)
📝 internal/core/runner/nodejs/setup.go (+59 -39)
📝 internal/core/runner/output_capture.go (+102 -82)
📝 internal/core/runner/python/setup.go (+116 -77)
📝 internal/core/runner/temp_dir.go (+40 -33)
📝 internal/static/config.go (+103 -80)
📝 internal/utils/log/core.go (+5 -3)

📄 Description

Summary

Refactor multiple components to reduce cognitive complexity and improve code maintainability by extracting functions, eliminating magic strings, and simplifying control flows.

Changes

This PR contains 9 focused refactor commits:

Constant Extraction

  • internal/controller/run.go - Extract "unsupported language" error message to constant
  • internal/core/runner/output_capture.go - Reuse error format string constant
  • internal/utils/log/core.go - Deduplicate log file date format string

Function Decomposition

  • internal/core/runner/nodejs/setup.go - Split releaseLibBinary into focused helper functions
  • internal/core/runner/python/setup.go - Refactor both releaseLibBinary and InstallDependencies flows
  • internal/core/runner/output_capture.go - Reduce complexity of output capture runner
  • internal/core/runner/temp_dir.go - Extract WithTempDir helper methods
  • internal/static/config.go - Split InitConfig into focused configuration loaders

Files Changed

  • internal/controller/run.go (+6, -4)
  • internal/core/runner/nodejs/setup.go (+59, -39)
  • internal/core/runner/output_capture.go (+105, -85)
  • internal/core/runner/python/setup.go (+116, -77)
  • internal/core/runner/temp_dir.go (+40, -33)
  • internal/static/config.go (+103, -80)
  • internal/utils/log/core.go (+5, -3)

Benefits

  • Improved Readability: Smaller, focused functions are easier to understand
  • Better Maintainability: Each function has a single responsibility
  • Easier Testing: Smaller functions can be tested independently
  • Reduced Cognitive Load: Less nesting and clearer control flow

Testing

All existing tests pass. No functional changes - purely structural improvements.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-sandbox/pull/207 **Author:** [@Galois123](https://github.com/Galois123) **Created:** 1/12/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `refactor/reduce-code-complexity` --- ### 📝 Commits (9) - [`fa94ad0`](https://github.com/langgenius/dify-sandbox/commit/fa94ad0924062de7b0ed64e58a2ee9e3624c1473) refactor: reduce cognitive complexity of releaseLibBinary method - [`2557bc5`](https://github.com/langgenius/dify-sandbox/commit/2557bc5f908b4a6edf4a618cd6105891b8e5c6d0) refactor: reduce complexity of output capture runner - [`cb07461`](https://github.com/langgenius/dify-sandbox/commit/cb07461ddbceb746010cb024242374368f62b65a) refactor: reuse error format string in output capture - [`555c1b9`](https://github.com/langgenius/dify-sandbox/commit/555c1b93b7dc3d9a78db9fa678c25204c1ba3fc7) refactor: simplify python releaseLibBinary flow - [`ff00772`](https://github.com/langgenius/dify-sandbox/commit/ff0077218186a77455411e5e90268709c227a470) refactor: split InstallDependencies into focused helpers - [`0c20710`](https://github.com/langgenius/dify-sandbox/commit/0c20710f9ab3c7443b2b32b8dde4c646cdb05a51) refactor: TempDirRunner to reduce complexity - [`cec0684`](https://github.com/langgenius/dify-sandbox/commit/cec0684e8311b8eca1019f9c2c26184a1aaf34ca) refactor: reduce cognitive complexity of InitConfig - [`3bbc877`](https://github.com/langgenius/dify-sandbox/commit/3bbc877cb7d79bb2c25e63bc788fa13a2a2df320) refactor: deduplicate log file date format string - [`ce822f4`](https://github.com/langgenius/dify-sandbox/commit/ce822f45976682ac5e4f33cf921e37702e4f7981) refactor: extract "unsupported language" to constant ### 📊 Changes **7 files changed** (+431 additions, -318 deletions) <details> <summary>View changed files</summary> 📝 `internal/controller/run.go` (+6 -4) 📝 `internal/core/runner/nodejs/setup.go` (+59 -39) 📝 `internal/core/runner/output_capture.go` (+102 -82) 📝 `internal/core/runner/python/setup.go` (+116 -77) 📝 `internal/core/runner/temp_dir.go` (+40 -33) 📝 `internal/static/config.go` (+103 -80) 📝 `internal/utils/log/core.go` (+5 -3) </details> ### 📄 Description ## Summary Refactor multiple components to reduce cognitive complexity and improve code maintainability by extracting functions, eliminating magic strings, and simplifying control flows. ## Changes This PR contains 9 focused refactor commits: ### Constant Extraction - **internal/controller/run.go** - Extract "unsupported language" error message to constant - **internal/core/runner/output_capture.go** - Reuse error format string constant - **internal/utils/log/core.go** - Deduplicate log file date format string ### Function Decomposition - **internal/core/runner/nodejs/setup.go** - Split `releaseLibBinary` into focused helper functions - **internal/core/runner/python/setup.go** - Refactor both `releaseLibBinary` and `InstallDependencies` flows - **internal/core/runner/output_capture.go** - Reduce complexity of output capture runner - **internal/core/runner/temp_dir.go** - Extract `WithTempDir` helper methods - **internal/static/config.go** - Split `InitConfig` into focused configuration loaders ## Files Changed - `internal/controller/run.go` (+6, -4) - `internal/core/runner/nodejs/setup.go` (+59, -39) - `internal/core/runner/output_capture.go` (+105, -85) - `internal/core/runner/python/setup.go` (+116, -77) - `internal/core/runner/temp_dir.go` (+40, -33) - `internal/static/config.go` (+103, -80) - `internal/utils/log/core.go` (+5, -3) ## Benefits - **Improved Readability**: Smaller, focused functions are easier to understand - **Better Maintainability**: Each function has a single responsibility - **Easier Testing**: Smaller functions can be tested independently - **Reduced Cognitive Load**: Less nesting and clearer control flow ## Testing All existing tests pass. No functional changes - purely structural improvements. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 09:19:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-sandbox#208