Skip to content

Commit aee2a8e

Browse files
committed
test(browser): address runtime smoke feedback
1 parent 2462f5c commit aee2a8e

4 files changed

Lines changed: 64 additions & 12 deletions

File tree

scripts/test-package-install.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ set -e
55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
# Get the repo root (parent of scripts/)
77
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
8+
BROWSER_PACKAGE_JSON="$REPO_ROOT/packages/browser/package.json"
9+
BROWSER_PACKAGE_JSON_BACKUP="$BROWSER_PACKAGE_JSON.backup"
10+
ROOT_YARN_LOCK="$REPO_ROOT/yarn.lock"
11+
ROOT_YARN_LOCK_BACKUP="$ROOT_YARN_LOCK.backup"
12+
13+
restore_package_files() {
14+
if [[ -f "$BROWSER_PACKAGE_JSON_BACKUP" ]]; then
15+
mv -f "$BROWSER_PACKAGE_JSON_BACKUP" "$BROWSER_PACKAGE_JSON"
16+
fi
17+
if [[ -f "$ROOT_YARN_LOCK_BACKUP" ]]; then
18+
mv -f "$ROOT_YARN_LOCK_BACKUP" "$ROOT_YARN_LOCK"
19+
fi
20+
}
21+
22+
trap restore_package_files EXIT
823

924
echo "Testing @datadog/openfeature-browser package installation..."
1025
echo "Repository root: $REPO_ROOT"
@@ -31,8 +46,8 @@ echo "Installing packed core into browser package..."
3146
cd "$REPO_ROOT/packages/browser"
3247

3348
# Save original package.json and yarn.lock
34-
cp package.json package.json.backup
35-
cp "$REPO_ROOT/yarn.lock" "$REPO_ROOT/yarn.lock.backup"
49+
cp "$BROWSER_PACKAGE_JSON" "$BROWSER_PACKAGE_JSON_BACKUP"
50+
cp "$ROOT_YARN_LOCK" "$ROOT_YARN_LOCK_BACKUP"
3651

3752
# Install the tarball temporarily
3853
yarn add "@datadog/flagging-core@file:$TEST_APP_DIR/core.tgz" --silent
@@ -41,12 +56,10 @@ yarn add "@datadog/flagging-core@file:$TEST_APP_DIR/core.tgz" --silent
4156
echo "Packing @datadog/openfeature-browser..."
4257
yarn pack --filename "$TEST_APP_DIR/browser.tgz" > /dev/null 2>&1
4358

44-
# Restore browser package to original state using git
59+
# Restore browser package to original state
4560
echo "Restoring browser package..."
46-
rm package.json
47-
mv package.json.backup package.json
48-
rm "$REPO_ROOT/yarn.lock"
49-
mv "$REPO_ROOT/yarn.lock.backup" "$REPO_ROOT/yarn.lock"
61+
restore_package_files
62+
trap - EXIT
5063

5164
cd "$REPO_ROOT"
5265

test-app/src/precomputed.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ const configuration = configurationFromString(
2525
rules: { response: 'ignored by the precomputed entrypoint' },
2626
})
2727
)
28-
const roundTrip = JSON.parse(configurationToString(configuration)) as Record<string, unknown>
28+
const serialized = configurationToString(configuration)
29+
const roundTripWire = JSON.parse(serialized) as Record<string, unknown>
30+
const restored = configurationFromString(serialized)
2931
const flag = configuration.precomputed?.response.data.attributes.flags['precomputed-flag']
32+
const restoredFlag = restored.precomputed?.response.data.attributes.flags['precomputed-flag']
3033

3134
assert(flag?.variationValue === true, 'precomputed flag was not parsed')
3235
assert(configuration.rules === undefined, 'precomputed entrypoint parsed rules')
33-
assert(roundTrip.rules === undefined, 'precomputed entrypoint serialized rules')
36+
assert(roundTripWire.rules === undefined, 'precomputed entrypoint serialized rules')
37+
assert(restoredFlag?.variationValue === true, 'precomputed flag did not survive a round trip')
3438

3539
reportSuccess({
3640
entrypoint: 'precomputed',
37-
booleanValue: flag.variationValue,
41+
booleanValue: restoredFlag.variationValue,
3842
rulesExcluded: true,
3943
})

test-app/src/protobuf.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
import { evaluateRulesBasedConfiguration, matchesRule, OperatorType } from '@datadog/flagging-core'
2-
import { configurationFromString, configurationToString } from '@datadog/openfeature-browser'
2+
import { configurationFromString, configurationToString, DatadogProvider } from '@datadog/openfeature-browser'
33
import { assert, reportSuccess } from './smoke'
44

55
const protobufRulesResponse =
66
'EgRwcm9kGigKDGJyb3dzZXItZmxhZxIYEAQaAigBIhAKCmFsbG9jYXRpb24iAiADGigKDGludGVnZXItZmxhZxIYEAIaAhgqIhAKCmFsbG9jYXRpb24iAiADKgJvbg=='
7+
const precomputedResponse = {
8+
data: {
9+
attributes: {
10+
createdAt: '2026-07-06T23:01:56.822Z',
11+
flags: {
12+
'provider-flag': {
13+
allocationKey: 'allocation',
14+
variationKey: 'on',
15+
variationType: 'BOOLEAN',
16+
variationValue: true,
17+
reason: 'STATIC',
18+
doLog: false,
19+
},
20+
},
21+
},
22+
},
23+
}
724
const configuration = configurationFromString(
8-
JSON.stringify({ version: 1, rules: { response: protobufRulesResponse } })
25+
JSON.stringify({
26+
version: 1,
27+
precomputed: { response: JSON.stringify(precomputedResponse) },
28+
rules: { response: protobufRulesResponse },
29+
})
930
)
1031

1132
assert(configuration.rules, 'protobuf rules configuration was not decoded')
@@ -31,6 +52,16 @@ const integerDetails = evaluateRulesBasedConfiguration(
3152
context,
3253
console
3354
)
55+
const provider = new DatadogProvider({
56+
clientToken: 'test-token',
57+
site: 'datadoghq.com',
58+
env: 'test',
59+
enableExposureLogging: false,
60+
enableFlagEvaluationTracking: false,
61+
enableRumFeatureFlagTracking: false,
62+
initialFlagsConfiguration: configuration,
63+
})
64+
const providerDetails = provider.resolveBooleanEvaluation('provider-flag', false, context, console)
3465
const restored = configurationFromString(configurationToString(configuration))
3566
const sha256Matched = matchesRule(
3667
{
@@ -50,6 +81,7 @@ const sha256Matched = matchesRule(
5081

5182
assert(booleanDetails.value === true, 'protobuf boolean evaluation returned the wrong value')
5283
assert(integerDetails.value === 42, 'protobuf int64 evaluation returned the wrong value')
84+
assert(providerDetails.value === true, 'DatadogProvider did not evaluate the decoded configuration')
5385
assert(
5486
restored.rules?.response.$typeName === 'datadog.ffe.flagging.ufc.v1.FlagsConfiguration',
5587
'protobuf rules configuration did not survive a round trip'
@@ -61,5 +93,6 @@ reportSuccess({
6193
protobufTypeName: configuration.rules.response.$typeName,
6294
booleanValue: booleanDetails.value,
6395
integerValue: integerDetails.value,
96+
providerValue: providerDetails.value,
6497
sha256Matched,
6598
})

test-app/tests/smoke.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ test('decodes and evaluates packed protobuf rules in Chromium', async ({ page })
3232
protobufTypeName: 'datadog.ffe.flagging.ufc.v1.FlagsConfiguration',
3333
booleanValue: true,
3434
integerValue: 42,
35+
providerValue: true,
3536
sha256Matched: true,
3637
})
3738
})
@@ -49,6 +50,7 @@ test('decodes protobuf without native text or bigint globals', async ({ page })
4950
expect(result.protobufTypeName).toBe('datadog.ffe.flagging.ufc.v1.FlagsConfiguration')
5051
expect(result.booleanValue).toBe(true)
5152
expect(result.integerValue).toBe(42)
53+
expect(result.providerValue).toBe(true)
5254
})
5355

5456
test('executes the packed precomputed entrypoint in Chromium', async ({ page }) => {

0 commit comments

Comments
 (0)