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

Copilot AI 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}
if canReuseThreatDetectionEngineConfigForExternalDetector(data, engineID) {
    threatDetectionData.EngineConfig = cloneThreatDetectionEngineConfig(...)
}
threatDetectionData.EngineConfig.Env = mergeThreatDetectionEngineEnv(...)
if threatDetectionData.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>
Copilot AI changed the title [WIP] Refactor threat-detection WorkflowData setup to eliminate duplicates refactor(threat-detection): extract shared external detector WorkflowData setup into helper Jul 17, 2026
Copilot AI requested a review from pelikhan July 17, 2026 06:35
@pelikhan
pelikhan marked this pull request as ready for review July 17, 2026 06:54
Copilot AI review requested due to automatic review settings July 17, 2026 06:54
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

Copilot AI 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
File Description
pkg/workflow/threat_detection_helpers.go Adds shared external-detector setup helper.
pkg/workflow/threat_detection_external.go Replaces duplicated setup logic.
.github/workflows/skillet.lock.yml Updates generated action metadata.
.github/workflows/release.lock.yml Updates generated action metadata.
.github/workflows/hourly-ci-cleaner.lock.yml Updates generated action metadata.
.github/workflows/avenger.lock.yml Updates generated action metadata.
.github/workflows/agentic-auto-upgrade.yml Changes 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

Field Value
Category refactor
Risk medium
Score 38/100 (impact:15, urgency:8, quality:15)
Action batch_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 ·

Copilot AI and 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>

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@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 main Jul 17, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/duplicate-threat-detection-workflowdata-setup branch July 17, 2026 11:18
Sign up for free to 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