Conversation
…nd table-driven patterns Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…est.go Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve test quality for threat detection file access
Refactor threat detection tests: testify assertions, table-driven patterns, helper functions
Feb 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors pkg/workflow/threat_detection_file_access_test.go to improve test readability and coverage around threat-detection step generation by adopting testify assertions, table-driven subtests, and shared helpers.
Changes:
- Migrates manual error/string checks to
require.*(setup) andassert.*(validation). - Refactors multiple string assertions into table-driven subtests with clearer intent.
- Adds helper constructors plus new coverage for step-generation helpers (
buildDownloadArtifactStep,buildEchoAgentOutputsStep,buildThreatDetectionAnalysisStep).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+201
to
+205
| { | ||
| name: "downloads agent-output", | ||
| substring: "agent-output", | ||
| message: "should download agent-output artifact", | ||
| }, |
There was a problem hiding this comment.
In the download-artifact step test, agent-output is hard-coded even though the production code uses constants.AgentOutputArtifactName. Using the constant here will keep the test aligned if the artifact name ever changes and avoids duplicating magic strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves test quality in
threat_detection_file_access_test.goby migrating to testify assertions, table-driven patterns, and adding coverage for previously untested step generation functions.Changes
Testify migration: Replace manual error checks with
require.*for setup (file I/O, config creation) andassert.*for validations (string containment, output verification)Table-driven refactoring: Convert string validation tests into table-driven subtests with descriptive names and assertion messages
Helper functions: Add
createTestCompiler(t)andcreateTestWorkflowData(t, threatConfig)to reduce test boilerplate and improve maintainabilityNew test coverage: Add comprehensive tests for step generation functions:
buildDownloadArtifactStep- validates artifact names and download pathsbuildEchoAgentOutputsStep- validates output echoing with custom job namesbuildThreatDetectionAnalysisStep- validates environment variable configurationImproved naming: Rename tests to behavior-focused patterns (e.g.,
TestThreatDetectionSteps_UseFilePathReferences)Example
Before:
After:
Note:
parseThreatDetectionConfigandbuildThreatDetectionJobare already comprehensively tested inthreat_detection_test.goand not duplicated here.Original prompt
This section details on the original issue you should resolve
<issue_title>[testify-expert] Improve Test Quality: pkg/workflow/threat_detection_file_access_test.go</issue_title>
<issue_description>### Overview
The test file
pkg/workflow/threat_detection_file_access_test.gohas been selected for quality improvement by the Testify Uber Super Expert. This issue provides specific, actionable recommendations to enhance test quality, coverage, and maintainability using testify best practices.Current State
pkg/workflow/threat_detection_file_access_test.gopkg/workflow/threat_detection.go*Compiler)Test Quality Analysis
Strengths ✅
TestThreatDetectionUsesFilePathNotInline,TestThreatDetectionHasBashReadTools)TestThreatDetectionTemplateUsesFilePathcorrectly tests actual template file contentAreas for Improvement 🎯
1. Testify Assertions
Current Issues:
t.Error()andt.Errorf()instead of testify assertionst.Fatalf()for file read errors instead ofrequire.NoError()t.Error()for string content checksRecommended Changes:
Why this matters: Testify provides clearer error messages, better test output, and is the standard used throughout this codebase (see
scratchpad/testing.md). Usingrequire.*for setup failures stops the test immediately, whileassert.*continues checking other conditions.2. Table-Driven Tests
Current Issues:
TestThreatDetectionUsesFilePathNotInlinechecks multiple string conditions that could be table-drivenTestThreatDetectionTemplateUsesFilePathhas multiple similar string checksRecommended Changes: