Skip to content

Commit a476f40

Browse files
hhan2024Codex GPT-6
andcommitted
test(ffe): address dependency coverage and test runner feedback
Use a PHPUnit-compatible exposure log sink and include deferred exposure candidates in the RC lifecycle snapshot. Update the canonical fixtures and exercise dependent-flag results plus exact native telemetry submissions, including rejected paths, prerequisite errors and matcher counts. Environment: Datadog workspace Co-Authored-By: Codex GPT-6 <noreply@localhost>
1 parent bc40e89 commit a476f40

4 files changed

Lines changed: 118 additions & 3 deletions

File tree

‎tests/OpenFeature/dependent_exposures_final_outcome.phpt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ if (PHP_VERSION_ID < 80100) die('skip: fibers require PHP 8.1+');
66
if (!is_file(__DIR__ . '/vendor/autoload.php')) die('skip: OpenFeature test dependencies required');
77
?>
88
--INI--
9-
datadog.trace.log_file={PWD}/dependent_exposures_final_outcome.debug.log
9+
datadog.trace.log_file=./tests/OpenFeature/dependent_exposures_final_outcome.debug.log
10+
error_log=./tests/OpenFeature/dependent_exposures_final_outcome.debug.log
1011
datadog.trace.log_level="debug,ddtrace=trace"
1112
--ENV--
1213
DD_METRICS_OTEL_ENABLED=0
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
--TEST--
2+
FFE shared dependent-flag cases preserve results and native telemetry submissions
3+
--ENV--
4+
DD_TRACE_GENERATE_ROOT_SPAN=0
5+
DD_INSTRUMENTATION_TELEMETRY_ENABLED=0
6+
DD_REMOTE_CONFIG_ENABLED=0
7+
DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=remote_config
8+
DD_METRICS_OTEL_ENABLED=0
9+
--FILE--
10+
<?php
11+
require __DIR__ . '/../../../Common/FeatureFlags/ffe_api_bootstrap.inc';
12+
13+
function applies_to_php(array $item) {
14+
if (isset($item['_include'], $item['_skip'])) throw new RuntimeException('conflicting applicability controls');
15+
foreach (array('_include', '_skip') as $control) {
16+
if (!isset($item[$control])) continue;
17+
$matches = false;
18+
foreach ($item[$control] as $entry) $matches = $matches || $entry['platform'] === 'php';
19+
if (($control === '_include' && !$matches) || ($control === '_skip' && $matches)) return false;
20+
}
21+
return true;
22+
}
23+
24+
function assert_same($actual, $expected, $label) {
25+
if ($actual !== $expected) {
26+
throw new RuntimeException($label . ': got ' . json_encode($actual) . ', expected ' . json_encode($expected));
27+
}
28+
}
29+
30+
function assert_event_matchers(array $events, array $matchers, $noUnmatched, $label) {
31+
// Matchers consume disjoint events in declaration order, including _count.
32+
foreach ($matchers as $matcher) {
33+
if (!applies_to_php($matcher)) continue;
34+
$remaining = $matcher['_count'] ?? 1;
35+
if (!is_int($remaining) || $remaining < 1) throw new RuntimeException('invalid matcher count');
36+
foreach ($events as $index => $event) {
37+
$matches = true;
38+
foreach ($matcher as $key => $expected) {
39+
if ($key === '_count' || $key === '_skip' || $key === '_include') continue;
40+
if (($event[$key] ?? null) !== $expected) $matches = false;
41+
}
42+
if ($matches) {
43+
unset($events[$index]);
44+
if (--$remaining === 0) break;
45+
}
46+
}
47+
assert_same($remaining, 0, $label . ' missing events for ' . json_encode($matcher));
48+
}
49+
if ($noUnmatched) assert_same(array_values($events), array(), $label . ' unmatched events');
50+
}
51+
52+
$evaluations = array();
53+
$exposures = array();
54+
\DDTrace\install_hook('DDTrace\\Internal\\record_ffe_flag_evaluation', function ($hook) use (&$evaluations) {
55+
$args = $hook->args;
56+
$evaluations[] = array('flag' => $args[0], 'variant' => $args[1], 'allocation' => $args[2], 'errorCode' => $args[5]);
57+
});
58+
\DDTrace\install_hook('DDTrace\\Internal\\record_ffe_exposure', function ($hook) use (&$exposures) {
59+
$args = $hook->args;
60+
$exposures[] = array('flag' => $args[0], 'allocation' => $args[3], 'variant' => $args[4]);
61+
});
62+
$evaluator = \DDTrace\FeatureFlags\Internal\NativeEvaluator::create(false, null, function ($batch) {
63+
\DDTrace\FeatureFlags\Internal\NativeEvaluator::submitExposures($batch);
64+
});
65+
$types = array('BOOLEAN' => 'boolean', 'STRING' => 'string', 'INTEGER' => 'integer', 'NUMERIC' => 'float', 'JSON' => 'object');
66+
$caseCount = 0;
67+
$telemetryCount = 0;
68+
// Feature suites are explicit opt-ins. Do not load unrelated suite configurations.
69+
foreach (array('dependent-flags') as $suite) {
70+
$suiteRoot = $root . '/tests/FeatureFlags/ffe-system-test-data/evaluation-suites/' . $suite;
71+
$files = glob($suiteRoot . '/cases/*.json');
72+
if (!$files) throw new RuntimeException('missing canonical suite cases: ' . $suite);
73+
sort($files);
74+
$config = file_get_contents($suiteRoot . '/ufc-config.json');
75+
if ($config === false) throw new RuntimeException('missing canonical suite configuration');
76+
foreach ($files as $file) {
77+
$cases = json_decode(file_get_contents($file), true);
78+
if (!is_array($cases) || !$cases) throw new RuntimeException('empty or invalid canonical case file');
79+
foreach ($cases as $case) {
80+
if (!applies_to_php($case)) continue;
81+
++$caseCount;
82+
// Every case starts with its own configuration snapshot and event window.
83+
assert_same(\DDTrace\Testing\ffe_load_config($config), true, 'load ' . $suite);
84+
$evaluations = $exposures = array();
85+
$details = $evaluator->evaluate($case['flag'], $types[$case['variationType']],
86+
$case['defaultValue'], $case['targetingKey'], $case['attributes']);
87+
$label = $suite . ': ' . $case['description'];
88+
foreach ($case['result'] as $field => $expected) {
89+
switch ($field) {
90+
case 'value': $actual = $details->getValue(); break;
91+
case 'reason': $actual = $details->getReason(); break;
92+
case 'errorCode': $actual = $details->getErrorCode(); break;
93+
default: throw new RuntimeException('unhandled canonical result field ' . $field);
94+
}
95+
assert_same($actual, $expected, $label . ' ' . $field);
96+
}
97+
if (!isset($case['expectations'])) continue;
98+
++$telemetryCount;
99+
$expectations = $case['expectations'];
100+
$noUnmatched = $expectations['noUnmatchedEvents'] ?? false;
101+
if (isset($expectations['exposures'])) {
102+
assert_event_matchers($exposures, $expectations['exposures'], $noUnmatched, $label . ' exposures');
103+
}
104+
if (isset($expectations['evaluationEvents'])) {
105+
assert_event_matchers($evaluations, $expectations['evaluationEvents'], $noUnmatched, $label . ' evaluations');
106+
}
107+
}
108+
}
109+
}
110+
echo 'cases=', $caseCount, "\ntelemetry_cases=", $telemetryCount, "\n";
111+
?>
112+
--EXPECT--
113+
cases=16
114+
telemetry_cases=11

‎tests/ext/ffe/remote_config_lifecycle.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ reset_request_replayer();
9797
before=false
9898
loaded=true
9999
has_config_after_add=true
100-
success={"valueJson":"\"blue\"","variant":"blue","allocationKey":"alloc-string","reason":0,"errorCode":0,"doLog":true,"observeFullEvaluationData":false,"serialId":7,"dependencyEvaluations":[],"providerState":[],"errorMessage":null,"hasConfig":null,"configVersion":null}
100+
success={"valueJson":"\"blue\"","variant":"blue","allocationKey":"alloc-string","reason":0,"errorCode":0,"doLog":true,"observeFullEvaluationData":false,"serialId":7,"dependencyEvaluations":[],"providerState":[],"exposureCandidates":[],"errorMessage":null,"hasConfig":null,"configVersion":null}
101101
removed=true
102102
has_config_after_remove=false
103103
version_increased=true

0 commit comments

Comments
 (0)