Skip to content

test(persistence): pin the stored cookie and local storage formats - #1713

Open
jaissica12 wants to merge 3 commits into
v3-developmentfrom
test/pin-persistence-formats
Open

jaissica12 wants to merge 3 commits into
v3-developmentfrom
test/pin-persistence-formats

Conversation

@jaissica12

Copy link
Copy Markdown
Contributor

Summary

Data written by earlier releases has to keep decoding the same way. This PR adds fixed expected strings for encodePersistence, decodePersistence and reduceAndEncodePersistence, so any change to the stored format fails a test instead of slipping through a refactor.

  • The fixture includes a comma and double quotes in a plain field: the characters the encoder replaces.
  • No source changes.

Testing

  • 6 new Jest cases; all suites pass.
  • Checked that the tests fail when the encoded format is changed.

🤖 Generated with Claude Code

Add fixed expected strings for encodePersistence, decodePersistence
and reduceAndEncodePersistence. Data written by earlier releases has
to keep decoding the same way, so these literals make any change to
the stored format fail loudly instead of slipping through a refactor.
The fixture includes a comma and double quotes in a plain field, the
characters the encoder replaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jaissica12
jaissica12 requested a review from a team as a code owner October 29, 2026 02:36
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v3-development@413bf5e). Learn more about missing BASE report.

Additional details and impacted files
@@                Coverage Diff                @@
##             v3-development    #1713   +/-   ##
=================================================
  Coverage                  ?   63.67%           
=================================================
  Files                     ?       79           
  Lines                     ?    10419           
  Branches                  ?     2993           
=================================================
  Hits                      ?     6634           
  Misses                    ?     3474           
  Partials                  ?      311           
Flag Coverage Δ
core 54.24% <ø> (?)
rokt-kit 92.58% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment on lines +23 to +51
function fixture(): IPersistenceMinified {
return ({
gs: {
sid: 'session-1',
ie: true,
les: 1700000000000,
ssd: 1700000000000,
dt: 'api-key',
cgid: 'cgid-1',
das: 'das,"1"',
csm: ['mpid1'],
c: null,
ia: {},
},
cu: 'mpid1',
l: true,
mpid1: {
ua: { color: 'blue, green', size: '"large"' },
ui: { '1': 'customer-1', '7': 'test@example.com' },
csd: { '5': 1700000000000 },
con: {
gdpr: {
purpose: {
c: true,
ts: 1700000000000,
d: 'doc',
l: 'loc',
h: 'hw',
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Maintainers can still change how stored session attributes, server settings and integration attributes decode without any of these pinning tests failing. The fixture leaves out gs fields that every save writes (sa, lsa, ss, av) and pins ia and c only as empty or null values that get dropped. So only csm exercises the gs Base64 decode path, and it has its own array check. Fix: add non-empty sa, lsa, ss, ia, av and a string c to fixture() and the expected strings, so every gs field written at src/persistence.ts:344-360 is pinned.

Why this was flagged

src/persistence.ts:344-360 writes gs.sa, gs.lsa, gs.ss, gs.av, gs.c and gs.ia on every save, and store.ts:657 writes lsa as well. The fixture at test/jest/persistence-format.spec.ts:23-51 sets only sid, ie, les, ssd, dt, cgid, das and csm, plus c: null and ia: {}. encodeGlobalSettings deletes those last two (persistence.ts:747-748, 767-768), so neither ends up in ENCODED. decodeGlobalSettings (persistence.ts:822-830) treats csm differently from every other Base64 gs key, so csm cannot stand in for sa, ss, lsa or ia. Suppose a refactor applies the csm Array.isArray deletion to all Base64 gs keys, or changes how the non-Base64 av and c fields are kept. Cookies and local storage written by earlier releases would then lose session attributes or server settings on decode, and all six new tests would still pass. That contradicts the PR's stated aim that any stored-format change fails a test. This is a gap in test coverage only. No shipping code changes.

Verification: nit. This is a coverage gap in a new test, not a production regression. src/persistence.ts:346-360 writes sa, lsa, ss, av, c and ia on every save, but the fixture sets only c: null and ia: {}, which persistence.ts:747-749 and 767-768 delete. Removing sa, ss, lsa or ia from Base64CookieKeys would leave all six new tests passing.

@crisryantan crisryantan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an automated review by Moody (Senior Engineer), requested by Ryan Tan in Chat. Automated review; not an independent human approval.

Risk: low

No blocking issues found. The six tests pin serialization and decoding without changing shipped behavior. The BrowserStack beta failure remains unexplained.

Checked against v3-development at f1003cd; head 115779a.

Checks on this head: 65 passed, 1 failed, 0 pending; failed: BrowserStack Beta Browsers Test

No changes needed. I can't approve this one: test/jest/persistence-format.spec.ts changes 'gdpr', which touches privacy or security, so a person needs to approve it on GitHub.

Checked

  • test/jest/persistence-format.spec.ts:12 | Read the complete addition; checked fixed expectations, fresh fixtures, escaping, empty inputs and both cookie-size cases.
  • src/persistence.ts:808 | Traced encoding and decoding through src/constants.ts:146, src/utils.ts:17 and src/polyfill.ts:7; fixed expectations detect format drift independently of round trips.
  • src/persistence.ts:683 | Checked reduction branches, session membership, user removal and cookie suffix construction against the two new assertions.
  • src/persistence.ts:295 | Followed setLocalStorage, setCookie and savePersistence writes through getLocalStorage, getCookie and storeDataInMemory readers. Their behavior is unchanged.
  • test/jest/persistence.spec.ts:123 | Compared existing malformed-record coverage; also read cookie-decoding and storage-precedence tests and reduction cases in test/src/tests-persistence.ts.
  • test/jest/persistence-format.spec.ts:77 | Checked Store initialization and mocked dependencies. No added production storage access, logging, network requests, DOM sinks, dependencies or page overhead.
  • jest.config.js | Confirmed test discovery and setup. Supplied CI reports 65 passed, one failed and none pending.

Not verified:

  • BrowserStack Beta Browsers Test | Failure logs were not supplied, so its cause and relationship to this change could not be established.

jaissica12 and others added 2 commits October 29, 2026 10:24
The fixture left out session attributes, local session attributes,
server settings and the app version, and set context and integration
attributes only to empty values that encoding drops. Only the cookie
sync map went through the Base64 decode of global settings, and it
has its own array check, so a change to how the other fields are
stored or read back could pass every test.

Give each field a non-empty value and extend the expected strings,
derived from the current encoder, so all of them are pinned. Decoding
now returns the fixture unchanged, so the decoded-fixture helper is
gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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