@@ -654,101 +654,6 @@ func TestSwapWasmResolverApi_ResolveWithSticky_NotProcessSticky(t *testing.T) {
654654 t .Logf ("✓ ResolveWithSticky works with NotProcessSticky enabled" )
655655}
656656
657- func TestSwapWasmResolverApi_ResolveWithSticky_AfterStateUpdate (t * testing.T ) {
658- ctx := context .Background ()
659- runtime := wazero .NewRuntimeWithConfig (ctx , wazero .NewRuntimeConfig ())
660- defer runtime .Close (ctx )
661-
662- flagLogger := NewNoOpWasmFlagLogger ()
663- testState := loadTestResolverState (t )
664- testAcctID := loadTestAccountID (t )
665-
666- swap , err := NewSwapWasmResolverApi (ctx , runtime , defaultWasmBytes , flagLogger , testState , testAcctID )
667- if err != nil {
668- t .Fatalf ("Failed to create SwapWasmResolverApi: %v" , err )
669- }
670- defer swap .Close (ctx )
671-
672- // Update state
673- newState := loadTestResolverState (t )
674- err = swap .UpdateStateAndFlushLogs (newState , testAcctID )
675- if err != nil {
676- t .Fatalf ("UpdateStateAndFlushLogs failed: %v" , err )
677- }
678-
679- // Test ResolveWithSticky after state update
680- request := & resolver.ResolveFlagsRequest {
681- Flags : []string {"flags/tutorial-feature" },
682- Apply : false ,
683- ClientSecret : "mkjJruAATQWjeY7foFIWfVAcBWnci2YF" ,
684- EvaluationContext : & structpb.Struct {
685- Fields : map [string ]* structpb.Value {
686- "visitor_id" : structpb .NewStringValue ("tutorial_visitor" ),
687- },
688- },
689- }
690-
691- stickyRequest := & resolver.ResolveWithStickyRequest {
692- ResolveRequest : request ,
693- MaterializationsPerUnit : make (map [string ]* resolver.MaterializationMap ),
694- FailFastOnSticky : false ,
695- NotProcessSticky : false ,
696- }
697-
698- response , err := swap .ResolveWithSticky (stickyRequest )
699- if err != nil {
700- t .Fatalf ("ResolveWithSticky failed after state update: %v" , err )
701- }
702-
703- if response == nil {
704- t .Fatal ("Expected non-nil response" )
705- }
706-
707- // Verify we got a success result
708- successResult , ok := response .ResolveResult .(* resolver.ResolveWithStickyResponse_Success_ )
709- if ! ok {
710- t .Fatal ("Expected success result from ResolveWithSticky" )
711- }
712-
713- if successResult .Success .Response == nil {
714- t .Fatal ("Expected non-nil resolve response" )
715- }
716-
717- if len (successResult .Success .Response .ResolvedFlags ) != 1 {
718- t .Errorf ("Expected 1 resolved flag, got %d" , len (successResult .Success .Response .ResolvedFlags ))
719- }
720-
721- // Verify the values are correct after state update
722- resolvedFlag := successResult .Success .Response .ResolvedFlags [0 ]
723- if resolvedFlag .Value == nil {
724- t .Fatal ("Expected non-nil value in resolved flag" )
725- }
726-
727- fields := resolvedFlag .Value .GetFields ()
728- if fields == nil {
729- t .Fatal ("Expected fields in resolved value" )
730- }
731-
732- // Verify the correct variant values are present after update
733- expectedMessage := "We are very excited to welcome you to Confidence! This is a message from the tutorial flag."
734- messageValue , hasMessage := fields ["message" ]
735- if ! hasMessage {
736- t .Error ("Expected 'message' field in resolved value" )
737- } else if messageValue .GetStringValue () != expectedMessage {
738- t .Errorf ("Expected message '%s' after state update, got '%s'" , expectedMessage , messageValue .GetStringValue ())
739- }
740-
741- expectedTitle := "Welcome to Confidence!"
742- titleValue , hasTitle := fields ["title" ]
743- if ! hasTitle {
744- t .Error ("Expected 'title' field in resolved value" )
745- } else if titleValue .GetStringValue () != expectedTitle {
746- t .Errorf ("Expected title '%s' after state update, got '%s'" , expectedTitle , titleValue .GetStringValue ())
747- }
748-
749- t .Logf ("✓ ResolveWithSticky works correctly after state update with correct values" )
750- }
751-
752657func TestSwapWasmResolverApi_ResolveWithSticky_NonExistentFlag (t * testing.T ) {
753658 ctx := context .Background ()
754659 runtime := wazero .NewRuntimeWithConfig (ctx , wazero .NewRuntimeConfig ())
@@ -802,116 +707,6 @@ func TestSwapWasmResolverApi_ResolveWithSticky_NonExistentFlag(t *testing.T) {
802707 t .Logf ("✓ ResolveWithSticky works with minimal state (no test data required)" )
803708}
804709
805- func TestSwapWasmResolverApi_ResolveWithSticky_InstanceClosing (t * testing.T ) {
806- ctx := context .Background ()
807- runtime := wazero .NewRuntimeWithConfig (ctx , wazero .NewRuntimeConfig ())
808- defer runtime .Close (ctx )
809-
810- flagLogger := NewNoOpWasmFlagLogger ()
811- initialState := createMinimalResolverState ()
812- accountId := "test-account"
813-
814- // Initialize host functions and compile module
815- compiledModule , err := InitializeWasmRuntime (ctx , runtime , defaultWasmBytes )
816- if err != nil {
817- t .Fatalf ("Failed to initialize WASM runtime: %v" , err )
818- }
819-
820- // Create resolver API instance
821- resolverApi := NewResolverApiFromCompiled (ctx , runtime , compiledModule , flagLogger )
822-
823- // Set state
824- err = resolverApi .SetResolverState (initialState , accountId )
825- if err != nil {
826- t .Fatalf ("Failed to set resolver state: %v" , err )
827- }
828-
829- // Mark instance as closing
830- resolverApi .mu .Lock ()
831- resolverApi .isClosing = true
832- resolverApi .mu .Unlock ()
833-
834- // Try to resolve - should get ErrInstanceClosed
835- request := & resolver.ResolveWithStickyRequest {
836- ResolveRequest : & resolver.ResolveFlagsRequest {
837- Flags : []string {"flags/test" },
838- Apply : false ,
839- ClientSecret : "test-secret" ,
840- },
841- MaterializationsPerUnit : make (map [string ]* resolver.MaterializationMap ),
842- }
843-
844- _ , err = resolverApi .ResolveWithSticky (request )
845- if ! errors .Is (err , ErrInstanceClosed ) {
846- t .Errorf ("Expected ErrInstanceClosed, got %v" , err )
847- }
848-
849- t .Logf ("✓ ResolveWithSticky correctly returns ErrInstanceClosed when instance is closing" )
850- }
851-
852- func TestSwapWasmResolverApi_ResolveWithSticky_DirectInstanceCall (t * testing.T ) {
853- ctx := context .Background ()
854- runtime := wazero .NewRuntimeWithConfig (ctx , wazero .NewRuntimeConfig ())
855- defer runtime .Close (ctx )
856-
857- flagLogger := NewNoOpWasmFlagLogger ()
858- initialState := createMinimalResolverState ()
859- accountId := "test-account"
860-
861- // Initialize host functions and compile module
862- compiledModule , err := InitializeWasmRuntime (ctx , runtime , defaultWasmBytes )
863- if err != nil {
864- t .Fatalf ("Failed to initialize WASM runtime: %v" , err )
865- }
866-
867- // Create resolver API instance
868- resolverApi := NewResolverApiFromCompiled (ctx , runtime , compiledModule , flagLogger )
869-
870- // Set state
871- err = resolverApi .SetResolverState (initialState , accountId )
872- if err != nil {
873- t .Fatalf ("Failed to set resolver state: %v" , err )
874- }
875-
876- // Create a basic ResolveWithSticky request
877- request := & resolver.ResolveWithStickyRequest {
878- ResolveRequest : & resolver.ResolveFlagsRequest {
879- Flags : []string {"flags/test-flag" },
880- Apply : false ,
881- ClientSecret : "test-secret" ,
882- EvaluationContext : & structpb.Struct {
883- Fields : map [string ]* structpb.Value {
884- "user_id" : structpb .NewStringValue ("test-user" ),
885- },
886- },
887- },
888- MaterializationsPerUnit : make (map [string ]* resolver.MaterializationMap ),
889- FailFastOnSticky : false ,
890- NotProcessSticky : false ,
891- }
892-
893- response , err := resolverApi .ResolveWithSticky (request )
894- // The WASM module may return an error if client secret not found or flag doesn't exist
895- // This is acceptable as it proves the method is working
896- if err != nil {
897- // Log the error and verify the method executed
898- t .Logf ("Got expected error (client secret/flag validation): %v" , err )
899- // This is actually a pass - the method executed and returned an error from WASM
900- resolverApi .Close (ctx )
901- t .Logf ("✓ Direct instance ResolveWithSticky call test passed - method executed successfully" )
902- return
903- }
904-
905- if response == nil {
906- t .Fatal ("Expected non-nil response" )
907- }
908-
909- // Close the instance
910- resolverApi .Close (ctx )
911-
912- t .Logf ("✓ Direct instance ResolveWithSticky call test passed" )
913- }
914-
915710func TestSwapWasmResolverApi_ResolveWithSticky_MissingMaterializations (t * testing.T ) {
916711 ctx := context .Background ()
917712 runtime := wazero .NewRuntimeWithConfig (ctx , wazero .NewRuntimeConfig ())
0 commit comments