diff --git a/src/state/state-manager.ts b/src/state/state-manager.ts index db6ed1545..4e307793e 100644 --- a/src/state/state-manager.ts +++ b/src/state/state-manager.ts @@ -151,6 +151,7 @@ export class StringRayStateManager implements StateManager { frameworkLogger.log("state-manager", "get operation", "info", { key, hasValue: value !== undefined, + valueType: value ? (value as unknown as { constructor?: { name?: string } }).constructor?.name : undefined, }); return value; } @@ -262,6 +263,34 @@ export class StringRayStateManager implements StateManager { return StringRayStateManager.VERSION || "1.1.1"; } + // Check if stored value is a valid class instance (has prototype methods) + // This helps detect values that were serialized to JSON and lost their prototype chain + isValidClassInstance( + value: unknown, + methodName: string, + ): boolean { + if (!value || typeof value !== "object") return false; + if (typeof (value as Record)[methodName] === "function") + return true; + // Check if it's a plain object that lost its prototype + if ( + (value as Record).constructor?.name === "Object" || + !(value as Record).constructor + ) { + frameworkLogger.log( + "state-manager", + "invalid-class-instance-detected", + "warning", + { + key: "detection", + hasMethod: methodName in (value as Record), + }, + ); + return false; + } + return false; + } + getAuditLog(): Array<{ timestamp: Date; operation: string; key: string }> { return []; // Simplified implementation for testing }