8000 fix: testsets failing because of noisy fields with skip-app-restart flag by officialasishkumar · Pull Request #3300 · keploy/keploy · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@officialasishkumar
Copy link
Member
@officialasishkumar officialasishkumar commented Nov 21, 2025

Describe the changes that are made

This PR fixes a critical bug where test sets were failing due to mutation of the global noise configuration when the skip-app-restart flag is enabled. The issue occurred because the LeftJoinNoise function was modifying the original globalNoise map, causing noise configurations to accumulate across test sets.

Key Changes:

  • Refactored LeftJoinNoise to perform deep copying of the global noise configuration before merging test-set specific noise
  • Added debug logging in CompareHTTPResp and CompareGRPCResp to track noise configuration application
  • Improved code readability by extracting intermediate variables in comparison functions

Links & References

Closes: #3299

  • NA (if very small change like typo, linting, etc.)

🔗 Related PRs

  • NA

🐞 Related Issues

  • NA

📄 Related Documents

  • NA

What type of PR is this? (check all applicable)

  • 📦 Chore
  • 🍕 Feature
  • 🐞 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🔁 CI
  • ⏩ Revert

Added e2e test pipeline?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added comments for hard-to-understand areas?

  • 👍 yes
  • 🙅 no, because the code is self-explanatory

Added to documentation?

  • 📜 README.md
  • 📓 Wiki
  • 🙅 no documentation needed

Are there any sample code or steps to test the changes?

  • 👍 yes, mentioned below
  • 🙅 no, because it is not needed

Self Review done?

  • ✅ yes
  • ❌ no, because I need help

Any relevant screenshots, recordings or logs?

  • NA

🧠 Semantics for PR Title & Branch Name

Please ensure your PR title and branch name follow the Keploy semantics:

📌 PR Semantics Guide
📌 Branch Semantics Guide

Examples:

  • PR Title: fix: patch MongoDB document update bug
  • Branch Name: feat/#1-login-flow (You may skip mentioning the issue number in the branch name if the change is small and the PR description clearly explains it.)

Additional checklist:

…app-restart flag

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Copilot finished reviewing on behalf of officialasishkumar November 21, 2025 12:32
Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug where test sets were failing due to mutation of the global noise configuration when the skip-app-restart flag is enabled. The issue occurred because the LeftJoinNoise function was modifying the original globalNoise map, causing noise configurations to accumulate across test sets.

Key Changes:

  • Refactored LeftJoinNoise to perform deep copying of the global noise configuration before merging test-set specific noise
  • Added debug logging in CompareHTTPResp and CompareGRPCResp to track noise configuration application
  • Improved code readability by extracting intermediate variables in comparison functions

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/service/replay/utils.go Implements deep copy logic in LeftJoinNoise to prevent mutation of the original global noise configuration
pkg/service/replay/replay.go Refactors noise configuration handling with clearer variable names and adds debug logging for troubleshooting
Comments suppressed due to low confidence (1)

pkg/service/replay/utils.go:69

  • This function has been refactored to fix a critical bug with global noise mutation, but there are no unit tests covering this behavior. Consider adding tests that verify:
  1. The returned noise config doesn't share references with the input globalNoise or tsNoise
  2. Multiple calls with the same globalNoise don't affect each other
  3. The merge behavior works correctly (test-set noise overrides global noise)

This would prevent regression of the bug this PR fixes.

func LeftJoinNoise(globalNoise config.GlobalNoise, tsNoise config.GlobalNoise) config.GlobalNoise {
	// Create a deep copy of globalNoise to avoid mutating the original config
	noise := make(config.GlobalNoise)

	// Deep copy the body map
	if bodyMap, ok := globalNoise["body"]; ok {
		noise["body"] = make(map[string][]string)
		for field, regexArr := range bodyMap {
			// Copy the slice to avoid sharing references
			noise["body"][field] = append([]string{}, regexArr...)
		}
	} else {
		noise["body"] = make(map[string][]string)
	}

	// Deep copy the header map
	if headerMap, ok := globalNoise["header"]; ok {
		noise["header"] = make(map[string][]string)
		for field, regexArr := range headerMap {
			// Copy the slice to avoid sharing references
			noise["header"][field] = append([]string{}, regexArr...)
		}
	} else {
		noise["header"] = make(map[string][]string)
	}

	// Merge test-set specific noise (overwrites global noise for matching fields)
	if tsNoiseBody, ok := tsNoise["body"]; ok {
		for field, regexArr := range tsNoiseBody {
			noise["body"][field] = regexArr
		}
	}

	if tsNoiseHeader, ok := tsNoise["header"]; ok {
		for field, regexArr := range tsNoiseHeader {
			noise["header"][field] = regexArr
		}
	}

	return noise
}

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

Comment on lines 56 to 60
if tsNoiseBody, ok := tsNoise["body"]; ok {
for field, regexArr := range tsNoiseBody {
noise["body"][field] = regexArr
}
}
Copy link
Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The test-set specific noise slices are directly assigned without deep copying. This means the returned noise config still shares slice references with tsNoise, which could lead to the same mutation issues this PR aims to fix.

Consider copying the slices when merging test-set noise:

if tsNoiseBody, ok := tsNoise["body"]; ok {
    for field, regexArr := range tsNoiseBody {
        noise["body"][field] = append([]string{}, regexArr...)
    }
}

The same applies to the header section below (lines 62-66).

Copilot uses AI. Check for mistakes.
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

0