Skip to content

Commit b4e3028

Browse files
feat: Implement better dummy fetchers and integrate into BOM generation + update integration to do dummy fetching for json and xml
1 parent d27652e commit b4e3028

File tree

6 files changed

+311
-216
lines changed

6 files changed

+311
-216
lines changed

.github/workflows/integration.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,27 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
fixture: [ repo-10, repo-basic ]
16-
format: [ json, xml ]
17-
hf-mode: [ dummy, online ]
15+
include:
16+
# Dummy mode: only once per format (fixture doesn't matter)
17+
- fixture: repo-basic
18+
format: json
19+
hf-mode: dummy
20+
- fixture: repo-basic
21+
format: xml
22+
hf-mode: dummy
23+
# Online mode: both fixtures, both formats
24+
- fixture: repo-10
25+
format: json
26+
hf-mode: online
27+
- fixture: repo-10
28+
format: xml
29+
hf-mode: online
30+
- fixture: repo-basic
31+
format: json
32+
hf-mode: online
33+
- fixture: repo-basic
34+
format: xml
35+
hf-mode: online
1836
steps:
1937
- name: Checkout code
2038
uses: actions/checkout@v4

cmd/generate.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,12 @@ var generateCmd = &cobra.Command{
110110

111111
var discoveredBOMs []generator.DiscoveredBOM
112112
if mode == "dummy" {
113-
// dummy mode: per discovery: store + build (no network).
114-
// TODO: wire a real dummy method for mode==dummy.
115-
bomBuilder := builder.NewBOMBuilder(builder.DefaultOptions())
116-
discoveredBOMs = make([]generator.DiscoveredBOM, 0, len(discoveries))
117-
118-
for _, d := range discoveries {
119-
modelID := discoveryModelID(d)
120-
121-
ctx := builder.BuildContext{
122-
ModelID: modelID,
123-
Scan: d,
124-
HF: nil,
125-
}
126-
127-
bom, err := bomBuilder.Build(ctx)
128-
if err != nil {
129-
return err
130-
}
131-
discoveredBOMs = append(discoveredBOMs, generator.DiscoveredBOM{
132-
Discovery: d,
133-
BOM: bom,
134-
})
113+
// Dummy mode: do not look at the input (Scanner discoveries)
114+
// Just build one fixed dummy BOM with all fields included.
115+
// Uses dummy_model_api_fetcher.go and dummy_model_readme_fetcher.go
116+
discoveredBOMs, err = generator.BuildDummyBOM()
117+
if err != nil {
118+
return err
135119
}
136120
} else {
137121
// Online mode: per discovery: store + fetch + map + build (inside generator).

internal/.dummy/dummy_fetcher.go

Lines changed: 0 additions & 191 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package fetcher
2+
3+
import (
4+
"context"
5+
)
6+
7+
// DummyModelAPIFetcher returns a fixed ModelAPIResponse for testing/demo purposes
8+
// without making any HTTP requests.
9+
type DummyModelAPIFetcher struct{}
10+
11+
// Fetch returns a comprehensive dummy ModelAPIResponse with all fields populated.
12+
func (f *DummyModelAPIFetcher) Fetch(ctx context.Context, modelID string) (*ModelAPIResponse, error) {
13+
// Create a fixed comprehensive response with all fields populated
14+
gatedBool := false
15+
gated := BoolOrString{Bool: &gatedBool}
16+
17+
return &ModelAPIResponse{
18+
ID: "dummy-org/dummy-model",
19+
ModelID: "dummy-org/dummy-model",
20+
Author: "dummy-org",
21+
PipelineTag: "text-generation",
22+
LibraryName: "transformers",
23+
Tags: []string{
24+
"pytorch",
25+
"gpt2",
26+
"text-generation",
27+
"en",
28+
"license:mit",
29+
"autotrain_compatible",
30+
"endpoints_compatible",
31+
},
32+
License: "mit",
33+
SHA: "1234567890abcdef1234567890abcdef12345678",
34+
Downloads: 1234567,
35+
Likes: 890,
36+
LastMod: "2024-01-15T10:30:00.000Z",
37+
CreatedAt: "2023-06-01T08:00:00.000Z",
38+
Gated: gated,
39+
Private: false,
40+
Inference: "enabled",
41+
UsedStorage: 523456789,
42+
CardData: map[string]any{
43+
"language": "en",
44+
"license": "mit",
45+
"tags": []string{"text-generation", "pytorch"},
46+
},
47+
Config: struct {
48+
ModelType string `json:"model_type"`
49+
Architectures []string `json:"architectures"`
50+
}{
51+
ModelType: "gpt2",
52+
Architectures: []string{"GPT2LMHeadModel"},
53+
},
54+
}, nil
55+
}

0 commit comments

Comments
 (0)