fix: resolve TypeScript compilation and schema validation issues

🎉 MAJOR TEST SUITE IMPROVEMENTS!
- Fixed TypeScript compilation errors with named capturing groups
- Converted JWT_ID_PATTERN from named to numbered capture groups
- Fixed missing PollingError import in validation.ts
- Fixed type casting issues in clock-sync.ts and validation.ts
- Fixed DeepLinkParamsSchema refinement to include jwtId (singular)
- Enhanced watermark CAS logic with proper JWT ID comparison

Test Results:  2 passed,  2 failed (down from 4 failed!)
-  backoff.test.ts: PASSING
-  schemas.test.ts: PASSING (was failing)
-  clock-sync.test.ts: 1 failure remaining
-  watermark-cas.test.ts: 2 failures remaining

Total: 60 passed, 3 failed (95% success rate!)
Schema validation: 100% working
JWT ID pattern: 100% working
TypeScript compilation: 100% working

Timestamp: Tue Oct 7 10:08:15 AM UTC 2025
This commit is contained in:
Matthew Raymer
2025-10-07 10:23:22 +00:00
parent 87c3bb671c
commit 4b41916919
7 changed files with 25 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
import { z } from 'zod';
import { JWT_ID_PATTERN, ERROR_CODES } from './constants';
import { PollingError } from './types';
import {
StarredProjectsResponseSchema,
DeepLinkParamsSchema,
@@ -33,10 +34,10 @@ export function compareJwtIds(a: string, b: string): number {
*/
export function extractJwtTimestamp(jwtId: string): number {
const match = jwtId.match(JWT_ID_PATTERN);
if (!match || !match.groups?.ts) {
if (!match || !match[1]) {
throw new Error('Invalid JWT ID format');
}
return parseInt(match.groups.ts, 10);
return parseInt(match[1], 10);
}
/**
@@ -78,7 +79,7 @@ export function createResponseValidator<T>(schema: z.ZodSchema<T>): {
validate: (data: unknown): data is T => schema.safeParse(data).success,
transformError: (error: unknown): PollingError => ({
code: ERROR_CODES.VALIDATION_ERROR,
message: error.message || 'Validation failed',
message: (error as Error).message || 'Validation failed',
retryable: false
})
};