From 033f47f7674bc6d56626e7c6595e9c6051e773ee Mon Sep 17 00:00:00 2001 From: Christopher Brady Date: Wed, 22 Apr 2026 13:18:44 -0600 Subject: [PATCH] do not send flag check event when doing bulk flag check --- lib/schematic/schematic_client.rb | 1 - test/custom.test.rb | 34 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/schematic/schematic_client.rb b/lib/schematic/schematic_client.rb index 7935df8..4ec2c53 100644 --- a/lib/schematic/schematic_client.rb +++ b/lib/schematic/schematic_client.rb @@ -482,7 +482,6 @@ def check_flags_via_datastream(keys, company, user) keys.each do |key| result = @datastream_client.check_flag(eval_ctx, key) response = CheckFlagResponse.new(result) - enqueue_flag_check_event(key, response, company, user) results << { flag: key, value: response.value, reason: response.reason } rescue DataStream::EvaluationError => e @logger.debug("DataStream check_flags falling back to API: #{e.message}") diff --git a/test/custom.test.rb b/test/custom.test.rb index c1c2bc9..f797ff9 100644 --- a/test/custom.test.rb +++ b/test/custom.test.rb @@ -1612,6 +1612,40 @@ def stop = @inner.stop WebMock.reset! end + it "does not enqueue flag_check events for bulk check_flags via DataStream" do + captured_bodies = [] + stub_request(:post, CAPTURE_URL).to_return do |req| + captured_bodies << JSON.parse(req.body, symbolize_names: true) + { status: 200 } + end + + client = Schematic::SchematicClient.new(api_key: "api_test_key_123") + + mock_ds = Object.new + mock_ds.define_singleton_method(:connected?) { true } + mock_ds.define_singleton_method(:close) { nil } + mock_ds.define_singleton_method(:check_flag) do |_eval_ctx, flag_key| + { value: true, flag_key: flag_key, reason: "match" } + end + client.instance_variable_set(:@datastream_client, mock_ds) + + client.check_flags( + company: { "org_id" => "abc" }, + keys: %w[ds-flag-a ds-flag-b] + ) + + # Force the buffer to flush any pending events + client.instance_variable_get(:@event_buffer).flush + + flag_check_events = captured_bodies.flat_map { |b| b[:events] || [] } + .select { |e| e[:type] == "flag_check" } + + assert_empty flag_check_events, "bulk check_flags should not emit flag_check events" + + client.close + WebMock.reset! + end + it "falls back to API when any DataStream flag evaluation fails" do stub_request(:post, CAPTURE_URL).to_return(status: 200)