Skip to content

fix: Display GDAF scenarios in global project report#21

Merged
ellipse2v merged 2 commits intoellipse2v:mainfrom
zhangtianqi-james:sync/origin
Apr 18, 2026
Merged

fix: Display GDAF scenarios in global project report#21
ellipse2v merged 2 commits intoellipse2v:mainfrom
zhangtianqi-james:sync/origin

Conversation

@zhangtianqi-james
Copy link
Copy Markdown

Problem

GDAF (Goal-Driven Attack Flow) scenarios were generated but not displayed in global_threat_report.html for project mode.

Root Cause

In generate_global_project_report(), a new dummy_model was created but gdaf_scenarios from main_threat_model were not copied to it.

Solution

  1. Moved GDAF execution from export_service.py to report_generator.py (before global report generation)
  2. Added helper methods _resolve_gdaf_context() and _resolve_bom_directory() to ReportGenerator
  3. Copy gdaf_scenarios from main_threat_model to dummy_model in generate_global_project_report()

Files Changed

  • threat_analysis/generation/report_generator.py (+106 lines)
  • threat_analysis/server/export_service.py (-23 lines)

Testing

  • Verified GDAF runs in project mode
  • Verified global_threat_report.html now displays GDAF scenarios

- 在 report_generator.py 中添加 GDAF 运行代码(项目模式)
- 添加辅助方法 _resolve_gdaf_context 和 _resolve_bom_directory
- 在 generate_global_project_report 中复制 gdaf_scenarios 到 dummy_model
- 在 export_service.py 中删除重复的 GDAF 代码(已移到 report_generator)
@zhangtianqi-james zhangtianqi-james changed the title fix: The GDAF project template is displayed in the global report fix: Display GDAF scenarios in global project report Apr 17, 2026
)
logging.info(f"✅ Generated global project report with {len(all_threats_details)} total threats at {output_dir / 'global_threat_report.html'}")

def _resolve_gdaf_context(self, threat_model) -> Optional[str]:
Copy link
Copy Markdown
Owner

@ellipse2v ellipse2v Apr 17, 2026

Choose a reason for hiding this comment

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

Hello, @zhangtianqi-james thank you very much for your help in finding and fixing the bugs

The fix is structurally correct — GDAF now runs before the global report is generated, which resolves the original bug.

One technical debt item worth addressing: _resolve_gdaf_context() and _resolve_bom_directory() are now duplicated across ExportService and ReportGenerator. The commit message
describes a "move" but the originals were not removed from ExportService (they are still called there for single-model exports).

Suggested fix: extract both methods to threat_analysis/utils.py and import from both services:

in threat_analysis/utils.py
def resolve_gdaf_context(threat_model) -> Optional[str]: ...
def resolve_bom_directory(threat_model) -> Optional[str]: ...

Then in both ExportService and ReportGenerator:
from threat_analysis.utils import resolve_gdaf_context, resolve_bom_directory

This keeps a single source of truth and avoids the two copies drifting over time.

Also a minor note: generate_global_project_report() assumes all_models[0] is main_threat_model to copy gdaf_scenarios. This is correct today but fragile — worth adding a comment
documenting the ordering invariant, or passing main_threat_model explicitly as a parameter.

please could you move in utils.py these methods ?

Addresses code duplication identified in PR ellipse2v#21 review.

The _resolve_gdaf_context() and _resolve_bom_directory() methods
were duplicated across ExportService and ReportGenerator. This
change extracts both methods to threat_analysis/utils.py as
standalone functions and updates both services to import from there.

Benefits:
- Single source of truth for path resolution logic
- Easier maintenance - changes apply to both services
- Prevents future drift between duplicate implementations
- Follows DRY principle

The generate_global_project_report() method now includes a comment
documenting the ordering invariant for all_models[0] being the
main threat model, as recommended in the review.

Also updated AIService._load_model_context() docstring to reference
the new location of the resolution logic.

Refs: PR ellipse2v#21
@zhangtianqi-james
Copy link
Copy Markdown
Author

Hi, @ellipse2v thank you very much for the feedback on PR #21.

I've addressed the code duplication issue:

  1. Extracted _resolve_gdaf_context() and _resolve_bom_directory() to threat_analysis/utils.py
  2. Updated both ExportService and ReportGenerator to use the shared utilities
  3. Added a comment in generate_global_project_report() documenting the ordering invariant for all_models[0] as the main threat model

Please review commit "refactor: extract GDAF resolution utilities to avoid duplication" (5b6ad26) and let me know if this looks good.

Copy link
Copy Markdown
Owner

@ellipse2v ellipse2v left a comment

Choose a reason for hiding this comment

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

@ellipse2v ellipse2v merged commit ae2c4c7 into ellipse2v:main Apr 18, 2026
1 check passed
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