// Small helpers shared by the tests that drive LiveTailRetention directly.

export const LIVE_CONTEXT_TYPE = "pi-goal-live-context";

export const msg = (role: string, content: string, timestamp: number): any => ({ role, content, timestamp });
export const contents = (messages: any[]): string[] => messages.map(message => message.content);
export const isLive = (message: any): boolean => message?.customType === LIVE_CONTEXT_TYPE;

/** What a new process starts with: nothing retained in memory. */
export const forgetSharedRetention = (): void => { delete (globalThis as any)[Symbol.for("pi-goal-x.liveRetention")]; };

/** How many messages the two requests share from the start. */
export function sharedPrefix(a: unknown[], b: unknown[]): number {
	let i = 0;
	while (i < a.length && i < b.length && JSON.stringify(a[i]) === JSON.stringify(b[i])) i++;
	return i;
}
