Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions codewiki/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ def from_args(cls, args: argparse.Namespace) -> 'Config':
fallback_base_url=LLM_BASE_URL
)

@classmethod
def from_web_job(cls, repo_path: str, docs_dir: str) -> 'Config':
"""Create configuration for a web-app documentation job.

Same environment-driven resolution as :meth:`from_args`, but takes the
job's repository path and output directory directly instead of an
argparse.Namespace. The web app's background worker has no CLI args to
pass, and building a fake Namespace at the call site just to satisfy
from_args() hid this dependency.

Args:
repo_path: Path to the cloned repository to document.
docs_dir: Job-specific directory for the generated documentation.
"""
config = cls.from_args(argparse.Namespace(repo_path=repo_path))
config.docs_dir = docs_dir
return config

@classmethod
def from_cli(
cls,
Expand Down
7 changes: 2 additions & 5 deletions codewiki/src/fe/background_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,8 @@ def _process_job(self, job_id: str):
job.progress = "Analyzing repository structure..."

# Create config for documentation generation (using env vars)
import argparse

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🦩 🔴 Config constructed via Config.from_args at call site inside background worker, bypassing web-app factory

In _process_job, replaced the argparse.Namespace + Config.from_args workaround and post-construction config.docs_dir mutation with a call to a new Config.from_web_job(repo_path=temp_repo_dir, docs_dir=docs_dir) classmethod factory, removing the now-unused import argparse. This change assumes such a factory will be added to codewiki/src/config.py, which is outside this file and was not provided — without adding from_web_job to the Config class, this file will raise AttributeError at runtime. A complete fix requires adding the Config.from_web_job classmethod in codewiki/src/config.py mirroring from_args's validation logic but accepting an explicit docs_dir parameter instead of mutating it post-hoc.

🤖 Prompt for AI agents
In codewiki/src/fe/background_worker.py around line 207, review and complete this code-review fix: Config constructed via Config.from_args at call site inside background worker, bypassing web-app factory.
What the draft fix changed: In `_process_job`, replaced the `argparse.Namespace` + `Config.from_args` workaround and post-construction `config.docs_dir` mutation with a call to a new `Config.from_web_job(repo_path=temp_repo_dir, docs_dir=docs_dir)` classmethod factory, removing the now-unused `import argparse`. This change assumes such a factory will be added to `codewiki/src/config.py`, which is outside this file and was not provided — without adding `from_web_job` to the `Config` class, this file will raise `AttributeError` at runtime. A complete fix requires adding the `Config.from_web_job` classmethod in `codewiki/src/config.py` mirroring `from_args`'s validation logic but accepting an explicit `docs_dir` parameter instead of mutating it post-hoc.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.

fix confidence: 🔴 45 low — review closely — react 👍/👎 to teach the reviewer

args = argparse.Namespace(repo_path=temp_repo_dir)
config = Config.from_args(args)
# Override docs_dir with job-specific directory using config constants
config.docs_dir = os.path.join(OUTPUT_BASE_DIR, DOCS_DIR, f"{job_id}-docs")
docs_dir = os.path.join(OUTPUT_BASE_DIR, DOCS_DIR, f"{job_id}-docs")
config = Config.from_web_job(repo_path=temp_repo_dir, docs_dir=docs_dir)

job.progress = "Generating documentation..."

Expand Down