22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- import {
6- describeWithEnvironment ,
7- } from '../../testing/EnvironmentHelpers.js' ;
5+ import * as Common from '../../core/common/common.js' ;
86
9- import * as Freestyler from './ai_assistance.js' ;
7+ import * as AiAssistance from './ai_assistance.js' ;
108
11- describeWithEnvironment ( 'Freestyler. AiHistoryStorage', ( ) => {
12- const agent1 : Freestyler . SerializedAgent = {
9+ describe ( ' AiHistoryStorage', ( ) => {
10+ const agent1 : AiAssistance . SerializedAgent = {
1311 id : 'id1' ,
14- type : Freestyler . AgentType . STYLING ,
12+ type : AiAssistance . AgentType . STYLING ,
1513 history : [ ] ,
1614 } ;
17- const agent2 : Freestyler . SerializedAgent = {
15+ const agent2 : AiAssistance . SerializedAgent = {
1816 id : 'id2' ,
19- type : Freestyler . AgentType . FILE ,
17+ type : AiAssistance . AgentType . FILE ,
2018 history : [ ] ,
2119 } ;
22- const agent3 : Freestyler . SerializedAgent = {
20+ const agent3 : AiAssistance . SerializedAgent = {
2321 id : 'id3' ,
24- type : Freestyler . AgentType . NETWORK ,
22+ type : AiAssistance . AgentType . NETWORK ,
2523 history : [ ] ,
2624 } ;
2725
28- afterEach ( ( ) => {
29- Freestyler . AiHistoryStorage . instance ( ) . clearForTest ( ) ;
26+ beforeEach ( ( ) => {
27+ let data : Record < string , string > = { } ;
28+ const dummyStorage = new Common . Settings . SettingsStorage ( { } , {
29+ get ( setting ) {
30+ return Promise . resolve ( data [ setting ] ) ;
31+ } ,
32+ set ( setting , value ) {
33+ data [ setting ] = value ;
34+ } ,
35+ clear ( ) {
36+ data = { } ;
37+ } ,
38+ remove ( setting ) {
39+ delete data [ setting ] ;
40+ } ,
41+ register ( _setting ) { } ,
42+ } ) ;
43+ Common . Settings . Settings . instance ( {
44+ forceNew : true ,
45+ syncedStorage : dummyStorage ,
46+ globalStorage : dummyStorage ,
47+ localStorage : dummyStorage ,
48+ } ) ;
3049 } ) ;
3150
51+ function getStorage ( ) {
52+ return AiAssistance . AiHistoryStorage . instance ( true ) ;
53+ }
54+
3255 it ( 'should create and retrieve history entry' , async ( ) => {
33- const storage = Freestyler . AiHistoryStorage . instance ( ) ;
56+ const storage = getStorage ( ) ;
3457 await storage . upsertHistoryEntry ( agent1 ) ;
3558 assert . deepEqual (
3659 storage . getHistory ( ) ,
3760 [ {
3861 id : 'id1' ,
39- type : 'freestyler' as Freestyler . AgentType ,
62+ type : 'freestyler' as AiAssistance . AgentType ,
4063 history : [ ] ,
4164 } ] ,
4265 ) ;
@@ -46,27 +69,27 @@ describeWithEnvironment('Freestyler.AiHistoryStorage', () => {
4669 [
4770 {
4871 id : 'id1' ,
49- type : 'freestyler' as Freestyler . AgentType ,
72+ type : 'freestyler' as AiAssistance . AgentType ,
5073 history : [ ] ,
5174 } ,
5275 {
5376 id : 'id2' ,
54- type : 'drjones-file' as Freestyler . AgentType ,
77+ type : 'drjones-file' as AiAssistance . AgentType ,
5578 history : [ ] ,
5679 } ,
5780 ] ,
5881 ) ;
5982 } ) ;
6083
6184 it ( 'should update history entries correctly' , async ( ) => {
62- const storage = Freestyler . AiHistoryStorage . instance ( ) ;
85+ const storage = getStorage ( ) ;
6386 await storage . upsertHistoryEntry ( agent1 ) ;
6487 await storage . upsertHistoryEntry ( agent2 ) ;
6588 await storage . upsertHistoryEntry ( {
6689 ...agent1 ,
6790 history : [
6891 {
69- type : Freestyler . ResponseType . USER_QUERY ,
92+ type : AiAssistance . ResponseType . USER_QUERY ,
7093 query : 'text' ,
7194 } ,
7295 ] ,
@@ -76,17 +99,17 @@ describeWithEnvironment('Freestyler.AiHistoryStorage', () => {
7699 [
77100 {
78101 id : 'id1' ,
79- type : 'freestyler' as Freestyler . AgentType ,
102+ type : 'freestyler' as AiAssistance . AgentType ,
80103 history : [
81104 {
82- type : Freestyler . ResponseType . USER_QUERY ,
105+ type : AiAssistance . ResponseType . USER_QUERY ,
83106 query : 'text' ,
84107 } ,
85108 ] ,
86109 } ,
87110 {
88111 id : 'id2' ,
89- type : 'drjones-file' as Freestyler . AgentType ,
112+ type : 'drjones-file' as AiAssistance . AgentType ,
90113 history : [ ] ,
91114 } ,
92115 ] ,
@@ -98,30 +121,30 @@ describeWithEnvironment('Freestyler.AiHistoryStorage', () => {
98121 [
99122 {
100123 id : 'id1' ,
101- type : 'freestyler' as Freestyler . AgentType ,
124+ type : 'freestyler' as AiAssistance . AgentType ,
102125 history : [
103126 {
104- type : Freestyler . ResponseType . USER_QUERY ,
127+ type : AiAssistance . ResponseType . USER_QUERY ,
105128 query : 'text' ,
106129 } ,
107130 ] ,
108131 } ,
109132 {
110133 id : 'id2' ,
111- type : 'drjones-file' as Freestyler . AgentType ,
134+ type : 'drjones-file' as AiAssistance . AgentType ,
112135 history : [ ] ,
113136 } ,
114137 {
115138 id : 'id3' ,
116- type : 'drjones-network-request' as Freestyler . AgentType ,
139+ type : 'drjones-network-request' as AiAssistance . AgentType ,
117140 history : [ ] ,
118141 } ,
119142 ] ,
120143 ) ;
121144 } ) ;
122145
123146 it ( 'should delete a single entry' , async ( ) => {
124- const storage = Freestyler . AiHistoryStorage . instance ( ) ;
147+ const storage = getStorage ( ) ;
125148 await storage . upsertHistoryEntry ( agent1 ) ;
126149 await storage . upsertHistoryEntry ( agent2 ) ;
127150 await storage . upsertHistoryEntry ( agent3 ) ;
@@ -131,22 +154,22 @@ describeWithEnvironment('Freestyler.AiHistoryStorage', () => {
131154 [
132155 {
133156 id : 'id1' ,
134- type : 'freestyler' as Freestyler . AgentType ,
157+ type : 'freestyler' as AiAssistance . AgentType ,
135158 history : [
136159
137160 ] ,
138161 } ,
139162 {
140163 id : 'id3' ,
141- type : 'drjones-network-request' as Freestyler . AgentType ,
164+ type : 'drjones-network-request' as AiAssistance . AgentType ,
142165 history : [ ] ,
143166 } ,
144167 ] ,
145168 ) ;
146169 } ) ;
147170
148171 it ( 'should delete all entries' , async ( ) => {
149- const storage = Freestyler . AiHistoryStorage . instance ( ) ;
172+ const storage = getStorage ( ) ;
150173 await storage . upsertHistoryEntry ( agent1 ) ;
151174 await storage . upsertHistoryEntry ( agent2 ) ;
152175 await storage . upsertHistoryEntry ( agent3 ) ;
0 commit comments