@@ -224,13 +224,32 @@ func (m *Manager) BuildLabFrontend(ctx context.Context) error {
224224func (m * Manager ) GenerateXatuCBTProtos (ctx context.Context ) error {
225225 m .log .WithField ("repo" , "xatu-cbt" ).Info ("generating protos" )
226226
227+ // Clean generated proto files before regenerating to avoid stale files
228+ if err := m .CleanXatuCBTProtos (); err != nil {
229+ m .log .WithError (err ).Warn ("failed to clean xatu-cbt protos, continuing anyway" )
230+ }
231+
227232 if err := m .runMake (ctx , m .cfg .Repos .XatuCBT , "proto" ); err != nil {
228233 return fmt .Errorf ("failed to generate xatu-cbt protos: %w" , err )
229234 }
230235
231236 return nil
232237}
233238
239+ // CleanXatuCBTProtos removes generated proto files from xatu-cbt.
240+ func (m * Manager ) CleanXatuCBTProtos () error {
241+ m .log .WithField ("repo" , "xatu-cbt" ).Info ("cleaning generated proto files" )
242+
243+ // xatu-cbt generates protos to pkg/proto/clickhouse/
244+ protoDir := filepath .Join (m .cfg .Repos .XatuCBT , "pkg" , "proto" , "clickhouse" )
245+
246+ if err := os .RemoveAll (protoDir ); err != nil {
247+ return fmt .Errorf ("failed to remove xatu-cbt proto directory: %w" , err )
248+ }
249+
250+ return nil
251+ }
252+
234253// GenerateProtos generates protobuf files for cbt-api.
235254func (m * Manager ) GenerateProtos (ctx context.Context ) error {
236255 // Generate cbt-api protos (only for first network, they're network-agnostic)
@@ -242,6 +261,11 @@ func (m *Manager) GenerateProtos(ctx context.Context) error {
242261 "network" : network .Name ,
243262 }).Info ("generating protos" )
244263
264+ // Clean generated files before regenerating to avoid stale files
265+ if err := m .CleanCBTAPIGenerated (); err != nil {
266+ m .log .WithError (err ).Warn ("failed to clean cbt-api generated files, continuing anyway" )
267+ }
268+
245269 // Use the generated config file
246270 configPath := filepath .Join (".xcli" , "configs" , fmt .Sprintf ("cbt-api-%s.yaml" , network .Name ))
247271
@@ -262,6 +286,40 @@ func (m *Manager) GenerateProtos(ctx context.Context) error {
262286 return nil
263287}
264288
289+ // CleanCBTAPIGenerated removes all generated files from cbt-api.
290+ // This includes proto files, handlers, server implementation, and OpenAPI specs.
291+ func (m * Manager ) CleanCBTAPIGenerated () error {
292+ m .log .WithField ("repo" , "cbt-api" ).Info ("cleaning generated files" )
293+
294+ // Files and directories to remove (matches cbt-api Makefile clean target)
295+ toRemove := []string {
296+ // Proto generated directory
297+ filepath .Join (m .cfg .Repos .CBTAPI , "pkg" , "proto" , "clickhouse" ),
298+ // Generated handler code
299+ filepath .Join (m .cfg .Repos .CBTAPI , "internal" , "handlers" , "generated.go" ),
300+ // Generated server implementation
301+ filepath .Join (m .cfg .Repos .CBTAPI , "internal" , "server" , "implementation.go" ),
302+ // Embedded OpenAPI spec
303+ filepath .Join (m .cfg .Repos .CBTAPI , "internal" , "server" , "openapi.yaml" ),
304+ // Root OpenAPI spec
305+ filepath .Join (m .cfg .Repos .CBTAPI , "openapi.yaml" ),
306+ // Proto descriptors
307+ filepath .Join (m .cfg .Repos .CBTAPI , ".descriptors.pb" ),
308+ // Discovered tables cache
309+ filepath .Join (m .cfg .Repos .CBTAPI , ".tables.txt" ),
310+ // Temp directory
311+ filepath .Join (m .cfg .Repos .CBTAPI , "tmp" ),
312+ }
313+
314+ for _ , path := range toRemove {
315+ if err := os .RemoveAll (path ); err != nil {
316+ m .log .WithError (err ).WithField ("path" , path ).Warn ("failed to remove generated file" )
317+ }
318+ }
319+
320+ return nil
321+ }
322+
265323// binaryExists checks if a binary file exists.
266324func (m * Manager ) binaryExists (path string ) bool {
267325 info , err := os .Stat (path )
0 commit comments