[duplicate-code] Duplicate Code: Memory allowed-extensions Parsing in cache_config.go and drive_memory_config.go
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
parseCacheMemoryAllowedExtensions(pkg/workflow/cache_config.go)とparseDriveMemoryAllowedExtensions(pkg/workflow/drive_memory_config.go)から始めてください。どちらも重複したループを含んでいます。また、cache_config.go の isValidFileExtension を読んでください。[]string を返す共通のヘルパーを抽出し、両方の呼び出し元でその結果を代入してください。両方の呼び出し元がこれを使用し、エラーメッセージが変わらず、make test-unit で cache_memory と drive_memory のテストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
🔍 Duplicate Code Detected: Memory allowed-extensions Parsing Loop
Analysis of commit 2b5c6d4b8fbf8480ec4c05dbc19fb349aef1f120 (#67506)
Assignee: @copilot
Summary
Two memory-subsystem config parsers — one for cache-memory and one for drive-memory — contain a near-identical loop that reads the allowed-extensions list, validates each entry with isValidFileExtension, and appends it to the entry's AllowedExtensions slice. The bodies differ only by the entry struct type (*CacheMemoryEntry vs *DriveMemoryEntry) and local variable names; the logic, validation, and error message are byte-for-byte identical.
Impact Analysis
- Maintainability: Any change to extension validation (e.g. allowing a new character class, tightening the error message, or supporting a new config shape) must be made in two places, which is easy to miss.
- Bug Risk: The two copies can silently drift — a fix applied to one memory type but not the other produces inconsistent validation behaviour for
cache-memoryvsdrive-memory. - Code Bloat: ~22 lines are duplicated verbatim;
repo-memoryalready uses a different helper (parseRepoMemoryStringList), so the codebase currently has three divergent approaches to the same concept.
Duplication Details
Pattern: allowed-extensions list parse + per-item validation
- Severity: Medium
- Occurrences: 2 (plus a third divergent variant in
repo_memory.go) - Locations:
pkg/workflow/cache_config.go—parseCacheMemoryAllowedExtensions(lines 272–294)pkg/workflow/drive_memory_config.go—parseDriveMemoryAllowedExtensions(lines 148–173)
- Code Sample (
cache_config.go):func parseCacheMemoryAllowedExtensions(cacheMap map[string]any, entry *CacheMemoryEntry) error { allowedExts, exists := cacheMap["allowed-extensions"] if !exists { return nil } extArray, ok := allowedExts.([]any) if !ok { return nil } entry.AllowedExtensions = make([]string, 0, len(extArray)) for _, ext := range extArray { extStr, ok := ext.(string) if !ok { continue } if !isValidFileExtension(extStr) { return fmt.Errorf("invalid allowed-extension %q: must start with '.' followed by alphanumeric characters only (e.g. .json)", extStr) } entry.AllowedExtensions = append(entry.AllowedExtensions, extStr) } return nil } - Code Sample (
drive_memory_config.go, functionally identical):func parseDriveMemoryAllowedExtensions(raw map[string]any, entry *DriveMemoryEntry) error { value, exists := raw["allowed-extensions"] if !exists { return nil } values, ok := value.([]any) if !ok { return nil } entry.AllowedExtensions = make([]string, 0, len(values)) for _, value := range values { extension, ok := value.(string) if !ok { continue } if !isValidFileExtension(extension) { return fmt.Errorf("invalid allowed-extension %q: must start with '.' followed by alphanumeric characters only (e.g. .json)", extension) } entry.AllowedExtensions = append(entry.AllowedExtensions, extension) } return nil }
Refactoring Recommendations
-
Extract a shared helper that returns the parsed slice
- Add e.g.
parseMemoryAllowedExtensions(configMap map[string]any) ([]string, error)(suggested home:pkg/workflow/memory_validation_config.go, alongside the other shared memory helpers, orcache_config.gosinceisValidFileExtensionalready lives there). - Have both callers assign the result:
exts, err := parseMemoryAllowedExtensions(m); entry.AllowedExtensions = exts. - Returning the slice (rather than mutating a typed
*Entry) avoids coupling the helper to either struct type and letsrepo-memoryadopt it too. - Estimated effort: ~1 hour (small, mechanical, well covered by existing
cache_memory_*_test.go/drive_memory_test.go). - Benefits: single source of truth for extension validation and the shared error message; removes drift risk between memory types.
- Add e.g.
-
(Optional) Converge
repo-memory- Evaluate whether
parseRepoMemoryStringListforallowed-extensionscan route through the same helper so all three memory types validate extensions identically.
- Evaluate whether
Implementation Checklist
- Review duplication findings
- Extract shared
parseMemoryAllowedExtensionshelper - Update
cache_config.goanddrive_memory_config.goto call it - (Optional) Converge
repo_memory.goonto the helper - Run
make fmtandmake test-unit - Verify no functionality broken
Analysis Metadata
- Analyzed Files: memory-subsystem source files under
pkg/workflow/(cache/drive/repo/comment/validation) - Detection Method: Serena semantic code analysis + pattern search
- Commit: 2b5c6d4b8fbf8480ec4c05dbc19fb349aef1f120
- Scope note: repository is a single squashed commit, so analysis focused on the commit's stated theme (memory schema contract + safe-output runtime)
Generated by 🔍 Duplicate Code Detector · pi · opus48 · 104.2 AIC · ⌖ 45.4 AIC · ⊞ 1.5K · ◷
- expires on Oct 12, 2026, 1:56 PM UTC-08:00
- 主要言語
- Go
- スター
- 5.4k
- フォーク
- 596
- 平均マージ
- 3時間 37分
- マージ済み PR(30日)
- 833
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/gh-aw のほかの issue
-
automated-analysis code-quality cookie testing
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
wgdonenotdeferred: parenthesized Done() statement escapes non-deferred detection (paren_unwrap_gap)オープンcookie sergo
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
cookie eslint
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
agentic-workflows
難易度 5/5 1週間以上 初心者へのやさしさ 24/100
メンテナーはふだん 1 日以内に返信
-
agentic-workflows
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
prime-radiant-inc/evener#5028 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
[BUG] v4.2.9 PostgreSQL 启动迁移失败:DROP INDEX CURRENT_SCHEMA() 语法错误対応中かも @renovate が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
OpenListTeam/OpenList#3267 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
openpubkey/opkssh#670 ·
メンテナーはふだん 1 日以内に返信