Skip to content

Commit c626be7

Browse files
shrijayanclaude
andcommitted
fix: prevent flaky "throws on tampered ciphertext" test
The test replaced base64 char at position 30 with 'X', but if the random nonce already produced 'X' at that position, the string was unchanged and decrypt succeeded (~1.6% flake rate). Now picks a replacement character guaranteed to differ from the original. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9e87daa commit c626be7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/cli/src/__tests__/crypto.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ describe("encrypt / decrypt", () => {
9494

9595
it("throws on tampered ciphertext", () => {
9696
const ciphertext = encrypt("secret", key);
97-
// Flip a character in the middle of the ciphertext
98-
const tampered = ciphertext.slice(0, 30) + "X" + ciphertext.slice(31);
97+
// Flip a character in the middle — ensure it actually changes
98+
const pos = 30;
99+
const replacement = ciphertext[pos] === "X" ? "Y" : "X";
100+
const tampered =
101+
ciphertext.slice(0, pos) + replacement + ciphertext.slice(pos + 1);
99102
expect(() => decrypt(tampered, key)).toThrow();
100103
});
101104
});

0 commit comments

Comments
 (0)