@@ -49,14 +49,20 @@ func TestReload_CSSOnly(t *testing.T) {
4949}
5050
5151func TestReload_ModelOnly (t * testing.T ) {
52- var receivedAction string
52+ var actions [] string
5353 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
5454 var body map [string ]any
5555 json .NewDecoder (r .Body ).Decode (& body )
56- receivedAction = body ["action" ].(string )
56+ action := body ["action" ].(string )
57+ actions = append (actions , action )
5758
5859 w .Header ().Set ("Content-Type" , "application/json" )
59- w .Write ([]byte (`{"result":0,"feedback":{"startup_metrics":{"duration":98}}}` ))
60+ switch action {
61+ case "reload_model" :
62+ w .Write ([]byte (`{"result":0,"feedback":{"startup_metrics":{"duration":98}}}` ))
63+ case "get_ddl_commands" :
64+ w .Write ([]byte (`{"result":0,"feedback":{}}` ))
65+ }
6066 }))
6167 defer server .Close ()
6268
@@ -77,8 +83,8 @@ func TestReload_ModelOnly(t *testing.T) {
7783 t .Fatalf ("Reload: %v" , err )
7884 }
7985
80- if receivedAction != "reload_model" {
81- t .Errorf ("expected reload_model action , got %q " , receivedAction )
86+ if len ( actions ) < 2 || actions [ 0 ] != "reload_model" || actions [ 1 ] != "get_ddl_commands " {
87+ t .Errorf ("expected actions [ reload_model, get_ddl_commands] , got %v " , actions )
8288 }
8389 if ! strings .Contains (stdout .String (), "Model reloaded" ) {
8490 t .Errorf ("expected 'Model reloaded' in output, got: %s" , stdout .String ())
@@ -142,8 +148,15 @@ func TestReload_ParseDuration(t *testing.T) {
142148
143149func TestReload_ModelOnly_WithDuration (t * testing.T ) {
144150 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
151+ var body map [string ]any
152+ json .NewDecoder (r .Body ).Decode (& body )
145153 w .Header ().Set ("Content-Type" , "application/json" )
146- w .Write ([]byte (`{"result":0,"feedback":{"startup_metrics":{"duration":98}}}` ))
154+ switch body ["action" ].(string ) {
155+ case "reload_model" :
156+ w .Write ([]byte (`{"result":0,"feedback":{"startup_metrics":{"duration":98}}}` ))
157+ case "get_ddl_commands" :
158+ w .Write ([]byte (`{"result":0,"feedback":{}}` ))
159+ }
147160 }))
148161 defer server .Close ()
149162
@@ -197,6 +210,49 @@ func TestReload_CSSOnly_Error(t *testing.T) {
197210 }
198211}
199212
213+ func TestReload_ModelOnly_PendingDDL (t * testing.T ) {
214+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
215+ var body map [string ]any
216+ json .NewDecoder (r .Body ).Decode (& body )
217+ w .Header ().Set ("Content-Type" , "application/json" )
218+ switch body ["action" ].(string ) {
219+ case "reload_model" :
220+ w .Write ([]byte (`{"result":0,"feedback":{}}` ))
221+ case "get_ddl_commands" :
222+ w .Write ([]byte (`{"result":0,"feedback":{"ddl_commands":"CREATE TABLE mymodule$customer (id BIGINT NOT NULL);\nALTER TABLE mymodule$order ADD COLUMN status VARCHAR(200);"}}` ))
223+ }
224+ }))
225+ defer server .Close ()
226+
227+ host , port := parseTestServerAddr (t , server .URL )
228+
229+ var stdout bytes.Buffer
230+ opts := ReloadOptions {
231+ SkipBuild : true ,
232+ Host : host ,
233+ Port : port ,
234+ Token : "testpass" ,
235+ Direct : true ,
236+ Stdout : & stdout ,
237+ }
238+
239+ err := Reload (opts )
240+ if err != nil {
241+ t .Fatalf ("Reload: %v" , err )
242+ }
243+
244+ output := stdout .String ()
245+ if ! strings .Contains (output , "WARNING: Database schema changes detected" ) {
246+ t .Errorf ("expected DDL warning in output, got: %s" , output )
247+ }
248+ if ! strings .Contains (output , "CREATE TABLE" ) {
249+ t .Errorf ("expected DDL commands in output, got: %s" , output )
250+ }
251+ if ! strings .Contains (output , "docker up --fresh" ) {
252+ t .Errorf ("expected fix suggestion in output, got: %s" , output )
253+ }
254+ }
255+
200256func TestReload_ModelOnly_ReloadError (t * testing.T ) {
201257 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
202258 w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments