Skip to content

Add tests of enum serialisation#315

Merged
emdash-ie merged 7 commits into
mainfrom
add-thrift-enum-tests
Jul 15, 2026
Merged

Add tests of enum serialisation#315
emdash-ie merged 7 commits into
mainfrom
add-thrift-enum-tests

Conversation

@emdash-ie

Copy link
Copy Markdown
Contributor

What does this change?

We kind of test this already with the ItemResponse test, but it’s worth adding extra ones since we’re specifically worried. I generated the binary values with the thriftToFile helper on thrift v0.15.0 (by downgrading and depending on a local version of fezziwig which was also downgraded), so that we can be confident updating to latest thrift hasn’t changed anything.

This should give us extra confidence for https://github.com/guardian/articles-and-publishing/issues/517

@emdash-ie
emdash-ie requested a review from a team as a code owner July 9, 2026 16:12
@emdash-ie emdash-ie added the maintenance Departmental tracking: maintenance work, not a fix or a feature label Jul 14, 2026
emdash-ie and others added 6 commits July 14, 2026 18:34
We kind of test this already with the ItemResponse test, but it’s worth
adding extra ones since we’re specifically worried. I generated the
binary values with the thriftToFile helper on thrift v0.15.0 (by
downgrading and depending on a local version of fezziwig which was also
downgraded), so that we can be confident updating to latest thrift
hasn’t changed anything.
As pointed out in code review, since the tests only checked that a tag
has decoded, it was possible for a tag to decode successfully but change
tag type, e.g. if two types swapped their IDs. This commit updates the
code to assert on the tag type and make sure they haven’t.

This also exposes the same weakness in the existing tests, in that they
don’t exhaustively check that the binary content deserialises to what
we’d expect it to. I guess we could change that?

Co-authored-by: Grahame Oakland <grahame.oakland@guardian.co.uk>
I want to produce the binary spec files for the enum tests using thrift
0.15.0. To do this, this commit downgrades our thrift dependency back to
0.15.0, and depends on a local version of fezziwig in which I’ve
downgraded thrift back to 0.15.0 as well.
(And also remove the new call I added for tags)

This reverts commit 8f680a9.
@emdash-ie
emdash-ie force-pushed the add-thrift-enum-tests branch from d7759d7 to 7c93489 Compare July 14, 2026 17:45

@groakland groakland 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.

The expected TagType values are currently discarded (_tagType), so this test only verifies that each fixture can be decoded and re-encoded to the same bytes. It does not confirm that the fixture decodes to the intended enum value.

We could pass an assertion to checkRoundTrip for each entry, e.g. asserting that the decoded Tag.type equals the expected TagType? That would ensure the test catches an enum mapping or wire-encoding issue rather than only validating a byte-preserving round trip.

Why this matters:
A round-trip can pass even if decoding maps an enum to the wrong value, because the same incorrect value may be serialized back into the original bytes. Asserting the decoded TagType makes the test validate the actual semantic mapping that this PR is intended to protect.

@groakland groakland 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.

LGTM with the latest changes. Approved

@emdash-ie
emdash-ie merged commit cd42c82 into main Jul 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Departmental tracking: maintenance work, not a fix or a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants