UpdateMockParams applies filtering parameters and updates the agent's mock manager
(ctx context.Context, params models.MockFilterParams)
| 722 | |
| 723 | // UpdateMockParams applies filtering parameters and updates the agent's mock manager |
| 724 | func (a *Agent) UpdateMockParams(ctx context.Context, params models.MockFilterParams) error { |
| 725 | |
| 726 | a.logger.Debug("UpdateMockParams called", |
| 727 | zap.Time("afterTime", params.AfterTime), |
| 728 | zap.Time("beforeTime", params.BeforeTime), |
| 729 | zap.Bool("useMappingBased", params.UseMappingBased), |
| 730 | zap.Int("mockMappingCount", len(params.MockMapping)), |
| 731 | zap.Bool("strictMockWindow", params.StrictMockWindow)) |
| 732 | |
| 733 | // Strict mock-window is OPT-IN via either the per-call flag |
| 734 | // (params.StrictMockWindow) or the process-wide KEPLOY_STRICT_MOCK_WINDOW |
| 735 | // env override. Surface the EFFECTIVE state so operators searching |
| 736 | // agent logs for "strict mock window enabled" find hits regardless of |
| 737 | // which route they used — previously the log fired only on the per-call |
| 738 | // flag, making env-only opt-ins invisible. |
| 739 | if strictEnabled := pkg.IsStrictMockWindow(params.StrictMockWindow); strictEnabled { |
| 740 | // Fire the activation message at most once per agent process |
| 741 | // (sync.Once). Info (project logging policy disallows Warn for |
| 742 | // expected-default state); the escape-hatch names are embedded |
| 743 | // inline so operators hitting unexpected "missing mock" errors |
| 744 | // after an upgrade can opt out without digging through docs. |
| 745 | // Per-test diagnostics drop to Debug. |
| 746 | a.strictLogOnce.Do(func() { |
| 747 | a.logger.Info( |
| 748 | "strict mock-window containment is ACTIVE for this session — per-test mocks whose request "+ |
| 749 | "timestamp falls outside the outer test window will be dropped rather than promoted "+ |
| 750 | "across tests. If your replays start reporting missing mocks after an upgrade, this "+ |
| 751 | "is likely why. To opt out: set KEPLOY_STRICT_MOCK_WINDOW=0 in the environment, OR "+ |
| 752 | "test.strictMockWindow: false in keploy.yaml.", |
| 753 | zap.Bool("viaPerCallFlag", params.StrictMockWindow), |
| 754 | zap.Bool("viaEnvOverride", !params.StrictMockWindow && strictEnabled), |
| 755 | zap.String("escape_hatch_env", "KEPLOY_STRICT_MOCK_WINDOW=0"), |
| 756 | zap.String("escape_hatch_config", "test.strictMockWindow: false")) |
| 757 | }) |
| 758 | a.logger.Debug("strict mock window active for test", |
| 759 | zap.Time("windowStart", params.AfterTime), |
| 760 | zap.Time("windowEnd", params.BeforeTime)) |
| 761 | } |
| 762 | |
| 763 | // Get stored mocks for the client |
| 764 | storageInterface, exists := a.clientMocks.Load(uint64(0)) |
| 765 | if !exists { |
| 766 | return fmt.Errorf("no mocks stored for client ID") |
| 767 | } |
| 768 | storage := storageInterface.(*ClientMockStorage) |
| 769 | |
| 770 | storage.mu.RLock() |
| 771 | originalFiltered := make([]*models.Mock, len(storage.filtered)) |
| 772 | originalUnfiltered := make([]*models.Mock, len(storage.unfiltered)) |
| 773 | copy(originalFiltered, storage.filtered) |
| 774 | copy(originalUnfiltered, storage.unfiltered) |
| 775 | storage.mu.RUnlock() |
| 776 | |
| 777 | a.logger.Debug("Original mocks before filtering", |
| 778 | zap.Int("originalFiltered", len(originalFiltered)), |
| 779 | zap.Int("originalUnfiltered", len(originalUnfiltered))) |
| 780 | |
| 781 | var filteredMocks, unfilteredMocks []*models.Mock |
nothing calls this directly
no test coverage detected