@@ -41,7 +41,7 @@ func TestParse_NoModelWeights(t *testing.T) {
4141 t .Fatal ("Expected error when parsing bundle without model weights, got nil" )
4242 }
4343
44- expectedErrMsg := "no supported model weights found (neither GGUF nor safetensors )"
44+ expectedErrMsg := "no supported model weights found (neither GGUF, safetensors, nor DDUF )"
4545 if ! strings .Contains (err .Error (), expectedErrMsg ) {
4646 t .Errorf ("Expected error message to contain %q, got: %v" , expectedErrMsg , err )
4747 }
@@ -93,6 +93,63 @@ func TestParse_WithGGUF(t *testing.T) {
9393 }
9494}
9595
96+ func TestParse_WithNestedGGUF (t * testing.T ) {
97+ // Create a temporary directory for the test bundle.
98+ tempDir := t .TempDir ()
99+
100+ // Create model subdirectory.
101+ modelDir := filepath .Join (tempDir , ModelSubdir )
102+ if err := os .MkdirAll (modelDir , 0755 ); err != nil {
103+ t .Fatalf ("Failed to create model directory: %v" , err )
104+ }
105+
106+ // Create nested directory structure.
107+ weightsDir := filepath .Join (modelDir , "nested" , "weights" )
108+ if err := os .MkdirAll (weightsDir , 0755 ); err != nil {
109+ t .Fatalf ("Failed to create nested weights directory: %v" , err )
110+ }
111+
112+ // Create a GGUF file in the nested directory.
113+ nestedGGUFPath := filepath .Join (weightsDir , "model.gguf" )
114+ if err := os .WriteFile (nestedGGUFPath , []byte ("dummy nested gguf" ), 0644 ); err != nil {
115+ t .Fatalf ("Failed to create nested GGUF file: %v" , err )
116+ }
117+
118+ // Create a valid config.json at bundle root.
119+ cfg := types.Config {
120+ Format : types .FormatGGUF ,
121+ }
122+ configPath := filepath .Join (tempDir , "config.json" )
123+ f , err := os .Create (configPath )
124+ if err != nil {
125+ t .Fatalf ("Failed to create config.json: %v" , err )
126+ }
127+ if err := json .NewEncoder (f ).Encode (cfg ); err != nil {
128+ f .Close ()
129+ t .Fatalf ("Failed to encode config: %v" , err )
130+ }
131+ f .Close ()
132+
133+ // Parse the bundle and ensure GGUF discovery falls back to recursion.
134+ bundle , err := Parse (tempDir )
135+ if err != nil {
136+ t .Fatalf ("Expected successful parse with nested GGUF, got: %v" , err )
137+ }
138+
139+ expectedPath := filepath .Join ("nested" , "weights" , "model.gguf" )
140+ if bundle .ggufFile != expectedPath {
141+ t .Errorf ("Expected ggufFile to be %q, got: %s" , expectedPath , bundle .ggufFile )
142+ }
143+
144+ fullPath := bundle .GGUFPath ()
145+ if fullPath == "" {
146+ t .Error ("Expected GGUFPath() to return a non-empty path" )
147+ }
148+ if ! strings .HasSuffix (fullPath , expectedPath ) {
149+ t .Errorf ("Expected GGUFPath() to end with %q, got: %s" , expectedPath , fullPath )
150+ }
151+ }
152+
96153func TestParse_WithSafetensors (t * testing.T ) {
97154 // Create a temporary directory for the test bundle
98155 tempDir := t .TempDir ()
@@ -139,6 +196,56 @@ func TestParse_WithSafetensors(t *testing.T) {
139196 }
140197}
141198
199+ func TestParse_WithDDUF (t * testing.T ) {
200+ // Create a temporary directory for the test bundle.
201+ tempDir := t .TempDir ()
202+
203+ // Create model subdirectory.
204+ modelDir := filepath .Join (tempDir , ModelSubdir )
205+ if err := os .MkdirAll (modelDir , 0755 ); err != nil {
206+ t .Fatalf ("Failed to create model directory: %v" , err )
207+ }
208+
209+ // Create a dummy DDUF file.
210+ ddufPath := filepath .Join (modelDir , "model.dduf" )
211+ if err := os .WriteFile (ddufPath , []byte ("dummy dduf content" ), 0644 ); err != nil {
212+ t .Fatalf ("Failed to create DDUF file: %v" , err )
213+ }
214+
215+ // Create a valid config.json at bundle root.
216+ cfg := types.Config {
217+ Format : types .FormatDDUF ,
218+ }
219+ configPath := filepath .Join (tempDir , "config.json" )
220+ f , err := os .Create (configPath )
221+ if err != nil {
222+ t .Fatalf ("Failed to create config.json: %v" , err )
223+ }
224+ if err := json .NewEncoder (f ).Encode (cfg ); err != nil {
225+ f .Close ()
226+ t .Fatalf ("Failed to encode config: %v" , err )
227+ }
228+ f .Close ()
229+
230+ // Parse the bundle and ensure DDUF-only bundles are accepted.
231+ bundle , err := Parse (tempDir )
232+ if err != nil {
233+ t .Fatalf ("Expected successful parse with DDUF file, got: %v" , err )
234+ }
235+
236+ if bundle .ddufFile != "model.dduf" {
237+ t .Errorf ("Expected ddufFile to be %q, got: %s" , "model.dduf" , bundle .ddufFile )
238+ }
239+
240+ fullPath := bundle .DDUFPath ()
241+ if fullPath == "" {
242+ t .Error ("Expected DDUFPath() to return a non-empty path" )
243+ }
244+ if ! strings .HasSuffix (fullPath , "model.dduf" ) {
245+ t .Errorf ("Expected DDUFPath() to end with %q, got: %s" , "model.dduf" , fullPath )
246+ }
247+ }
248+
142249func TestParse_WithNestedSafetensors (t * testing.T ) {
143250 // Create a temporary directory for the test bundle
144251 tempDir := t .TempDir ()
@@ -198,6 +305,63 @@ func TestParse_WithNestedSafetensors(t *testing.T) {
198305 }
199306}
200307
308+ func TestParse_WithNestedDDUF (t * testing.T ) {
309+ // Create a temporary directory for the test bundle.
310+ tempDir := t .TempDir ()
311+
312+ // Create model subdirectory.
313+ modelDir := filepath .Join (tempDir , ModelSubdir )
314+ if err := os .MkdirAll (modelDir , 0755 ); err != nil {
315+ t .Fatalf ("Failed to create model directory: %v" , err )
316+ }
317+
318+ // Create nested directory structure.
319+ diffusersDir := filepath .Join (modelDir , "sanitized" , "diffusers" )
320+ if err := os .MkdirAll (diffusersDir , 0755 ); err != nil {
321+ t .Fatalf ("Failed to create nested diffusers directory: %v" , err )
322+ }
323+
324+ // Create a DDUF file in the nested directory.
325+ nestedDDUFPath := filepath .Join (diffusersDir , "model.dduf" )
326+ if err := os .WriteFile (nestedDDUFPath , []byte ("dummy nested dduf" ), 0644 ); err != nil {
327+ t .Fatalf ("Failed to create nested DDUF file: %v" , err )
328+ }
329+
330+ // Create a valid config.json at bundle root.
331+ cfg := types.Config {
332+ Format : types .FormatDDUF ,
333+ }
334+ configPath := filepath .Join (tempDir , "config.json" )
335+ f , err := os .Create (configPath )
336+ if err != nil {
337+ t .Fatalf ("Failed to create config.json: %v" , err )
338+ }
339+ if err := json .NewEncoder (f ).Encode (cfg ); err != nil {
340+ f .Close ()
341+ t .Fatalf ("Failed to encode config: %v" , err )
342+ }
343+ f .Close ()
344+
345+ // Parse the bundle and ensure DDUF discovery falls back to recursion.
346+ bundle , err := Parse (tempDir )
347+ if err != nil {
348+ t .Fatalf ("Expected successful parse with nested DDUF, got: %v" , err )
349+ }
350+
351+ expectedPath := filepath .Join ("sanitized" , "diffusers" , "model.dduf" )
352+ if bundle .ddufFile != expectedPath {
353+ t .Errorf ("Expected ddufFile to be %q, got: %s" , expectedPath , bundle .ddufFile )
354+ }
355+
356+ fullPath := bundle .DDUFPath ()
357+ if fullPath == "" {
358+ t .Error ("Expected DDUFPath() to return a non-empty path" )
359+ }
360+ if ! strings .HasSuffix (fullPath , expectedPath ) {
361+ t .Errorf ("Expected DDUFPath() to end with %q, got: %s" , expectedPath , fullPath )
362+ }
363+ }
364+
201365func TestParse_WithBothFormats (t * testing.T ) {
202366 // Create a temporary directory for the test bundle
203367 tempDir := t .TempDir ()
0 commit comments