Skip to content

refactor(threat-detection): extract shared external detector WorkflowData setup into helper - #46142

Merged
pelikhan merged 5 commits into
mainfrom
copilot/duplicate-threat-detection-workflowdata-setup
Jul 17, 2026
Merged

refactor(threat-detection): extract shared external detector WorkflowData setup into helper#46142
pelikhan merged 5 commits into
mainfrom
copilot/duplicate-threat-detection-workflowdata-setup

Conversation

CopilotAI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The synthetic WorkflowData construction for the external-detector path was duplicated verbatim across buildInstallDetectionEngineForExternalDetectorStep and buildExternalDetectorExecutionStep, making env/APITarget propagation logic a divergence risk.

Changes

  • threat_detection_helpers.go — New buildExternalDetectorWorkflowData(data, engineID) helper centralizes the shared setup:

    • Base detection context via buildThreatDetectionWorkflowData
    • Tools = {"bash": ["*"]}
    • Engine config clone/reuse via canReuseThreatDetectionEngineConfigForExternalDetector
    • Env merge via mergeThreatDetectionEngineEnv
    • APITarget inheritance from main engine config
  • threat_detection_external.go — Both buildInstallDetectionEngineForExternalDetectorStep and buildExternalDetectorExecutionStep replace their ~12-line setup blocks with a single call. The execution step layers its step-specific additions (NetworkPermissions, Mounts) on top:

// Before (repeated in both functions):threatDetectionData:=buildThreatDetectionWorkflowData(data, engineID)
threatDetectionData.Tools=map[string]any{"bash": []any{"*"}}
threatDetectionData.EngineConfig=&EngineConfig{ID: engineID}
ifcanReuseThreatDetectionEngineConfigForExternalDetector(data, engineID) {
threatDetectionData.EngineConfig=cloneThreatDetectionEngineConfig(...)
}
threatDetectionData.EngineConfig.Env=mergeThreatDetectionEngineEnv(...)
ifthreatDetectionData.EngineConfig.APITarget==""&&data.EngineConfig!=nil {
threatDetectionData.EngineConfig.APITarget=data.EngineConfig.APITarget
}
// After:threatDetectionData:=buildExternalDetectorWorkflowData(data, engineID)
// execution step only:threatDetectionData.NetworkPermissions=&NetworkPermissions{...}
threatDetectionData.SandboxConfig.Agent.Mounts=appendThreatDetectionRWMount(...)

…icate threat detection setup
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title [WIP] Refactor threat-detection WorkflowData setup to eliminate duplicatesrefactor(threat-detection): extract shared external detector WorkflowData setup into helperJul 17, 2026
CopilotAI requested a review from pelikhanJuly 17, 2026 06:35
@pelikhan
pelikhan marked this pull request as ready for review July 17, 2026 06:54
CopilotAI review requested due to automatic review settings July 17, 2026 06:54
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extracts shared external-detector WorkflowData initialization to prevent configuration divergence.

Changes:

  • Adds a shared helper for tools, engine config, environment, and API target setup.
  • Updates installation and execution paths to use the helper.
  • Includes unrelated generated workflow metadata and scheduling changes.
Show a summary per file
FileDescription
pkg/workflow/threat_detection_helpers.goAdds shared external-detector setup helper.
pkg/workflow/threat_detection_external.goReplaces duplicated setup logic.
.github/workflows/skillet.lock.ymlUpdates generated action metadata.
.github/workflows/release.lock.ymlUpdates generated action metadata.
.github/workflows/hourly-ci-cleaner.lock.ymlUpdates generated action metadata.
.github/workflows/avenger.lock.ymlUpdates generated action metadata.
.github/workflows/agentic-auto-upgrade.ymlChanges the weekly execution schedule.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Medium

on:
schedule:
- cron: "11 4 * * 6"# Weekly (auto-upgrade)
- cron: "21 3 * * 5"# Weekly (auto-upgrade)
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

FieldValue
Categoryrefactor
Riskmedium
Score38/100 (impact:15, urgency:8, quality:15)
Actionbatch_review — batch: go-refactor

Rationale: Behavior-preserving refactor extracting shared WorkflowData helper in threat-detection. CI partially passing. Batch with similar Go refactors.

Generated by 🔧 PR Triage Agent · 166.4 AIC · ⌖ 6.15 AIC · ⊞ 5.6K ·

CopilotAIand others added 2 commits July 17, 2026 07:13
…eat-detection-workflowdata-setup
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

CopilotAI commented Jul 17, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot merge main and recompile

Done in 27dd663. I merged origin/main into this branch and recompiled workflows, which updated the out-of-sync lock files.

@pelikhan
pelikhan merged commit 5374e8b into mainJul 17, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/duplicate-threat-detection-workflowdata-setup branch July 17, 2026 11:18
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.13

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Threat-Detection WorkflowData Setup Across Engine Paths

3 participants

@pelikhan