Skip to content

fix(test): make the ciphertext-tamper test deterministic - #302

Merged
telivity-otaip merged 1 commit into
TelivityAI:mainfrom
modernitconsultants:fix/deterministic-tamper-test
Aug 11, 2026
Merged

fix(test): make the ciphertext-tamper test deterministic#302
telivity-otaip merged 1 commit into
TelivityAI:mainfrom
modernitconsultants:fix/deterministic-tamper-test

Conversation

@modernitconsultants

Copy link
Copy Markdown
Contributor

`credential-encryption.spec.ts` › "fails closed when ciphertext is tampered" is probabilistically flaky: it tampers with `blob.ciphertext.replace(/a/g, 'b')`, and whenever the random ciphertext contains no `a`, the replacement is a no-op — the blob arrives untampered, decryption rightly succeeds, and the test fails claiming fail-closed is broken.

Hit tonight in our CI: `1 failed | 1411 passed` on a branch touching none of this code, with the identical tree passing minutes earlier.

Fix: flip the first character to a guaranteed-different one. Same intent, zero probability.

(The auth-tag test above it is already deterministic — `'0'.repeat(...)` can collide with an all-zero tag only with negligible probability, so left alone.)

replace(/a/g,'b') on random hex ciphertext is a no-op whenever it contains no
'a' — the blob arrives untampered and the test fails claiming fail-closed is
broken. Flipping to uppercase 'A' has the same bug (hex 'A'==='a'). Change the
first hex DIGIT ('0'<->'1') instead: distinct nibble values, bytes always
change, verified across all 16 possible first digits.
@modernitconsultants
modernitconsultants force-pushed the fix/deterministic-tamper-test branch from e90a47c to 27b4f07 Compare August 11, 2026 12:10

@telivity-otaip telivity-otaip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice catch on the flaky tamper — replace(/a/g,'b') is a no-op when the hex has no a. Deterministic first-nibble flip is exactly right. Thank you, Charles — merging.

@telivity-otaip
telivity-otaip merged commit 2b4e777 into TelivityAI:main Aug 11, 2026
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