From 7d72053b7db720e41c46ad18e99829716546f419 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 22 Feb 2026 09:20:55 +0100 Subject: [PATCH] chore: fix flaky agent token test by not splitting on underscore (#8048) Base64url encoding uses '_' as a valid character, so splitting the JWT token on '_' would intermittently break the JWT parsing when the encoded payload or signature contained underscores. Strip the known prefix instead. Co-authored-by: Claude Opus 4.6 --- integration_tests/test/agent_workers.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/integration_tests/test/agent_workers.py b/integration_tests/test/agent_workers.py index 4b0c616433..9ced69b5c5 100644 --- a/integration_tests/test/agent_workers.py +++ b/integration_tests/test/agent_workers.py @@ -166,15 +166,14 @@ class TestAgentWorkers(unittest.TestCase): print(f"Agent token tests for token: {token}") self.assertIsNotNone(token) - # JWT tokens have the format: jwt_agent__ - self.assertTrue(token.startswith("jwt_agent_"), "Token should start with jwt_agent_") + # JWT tokens have the format: jwt_agent_ + prefix = "jwt_agent_" + self.assertTrue(token.startswith(prefix), "Token should start with jwt_agent_") - # Test that it's a valid JWT format (should contain 2 dots in the JWT part) - parts = token.split('_') - self.assertGreaterEqual(len(parts), 3, "Token should have at least 3 parts separated by underscores") - - # The actual JWT is after the second underscore - jwt_part = parts[2] + # Extract the JWT by stripping the known prefix (don't split on '_' + # because base64url encoding uses '_' as a valid character) + jwt_part = token[len(prefix):] + self.assertGreater(len(jwt_part), 0, "JWT part should not be empty") self.assertEqual(jwt_part.count('.'), 2, "JWT should contain exactly 2 dots") # Check that the token contains three base64-encoded parts