Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,16 @@ func (c *Core) FetchTrackerDryRunPreview(ctx context.Context, req api.Request) (
}
}
}
if !ok {
// The prepared-metadata cache is in-memory, so a restarted GUI session has
// none until the metadata is fetched again. Fetch it here instead of
// refusing the dry run: the preview populates the same cache this reads.
c.logger.Debugf("core: tracker dry-run fetching metadata after cache miss for %s", uniquePaths[0])
if _, err := c.FetchMetadataPreview(ctx, singleReq); err != nil {
return api.TrackerDryRunPreview{}, err
}
meta, ok = c.getDupeCache(uniquePaths[0], signature)
}
} else {
if !ok {
return api.TrackerDryRunPreview{}, fmt.Errorf("core: tracker dry-run requires prepared metadata for %s", uniquePaths[0])
Expand Down
41 changes: 40 additions & 1 deletion internal/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3741,6 +3741,45 @@ func TestRunUploadPreparedDebugDryRunIgnoresCheckBlocksForArtifacts(t *testing.T
}
}

func TestFetchTrackerDryRunPreviewFetchesMetadataOnCacheMiss(t *testing.T) {
t.Parallel()

meta := &stubMeta{}
tracker := &stubTrackers{dryRunEntries: []api.TrackerDryRunEntry{{Tracker: "AITHER", Status: "ready"}}}
core, err := New(api.CoreDependencies{
Config: config.Config{MainSettings: config.MainSettingsConfig{TMDBAPI: "x"}, ScreenshotHandling: config.ScreenshotHandlingConfig{Screens: 1}},
Services: api.ServiceSet{
Filesystem: &stubFS{},
Metadata: meta,
Torrents: &stubTorrent{},
Clients: &stubClient{},
Trackers: tracker,
},
Repository: &stubRepo{},
})
if err != nil {
t.Fatalf("new core: %v", err)
}

preview, err := core.FetchTrackerDryRunPreview(context.Background(), api.Request{
Paths: []string{"/tmp/a"},
Mode: api.ModeGUI,
Trackers: []string{"AITHER"},
})
if err != nil {
t.Fatalf("fetch tracker dry-run preview: %v", err)
}
if preview.SourcePath != "/tmp/a" {
t.Fatalf("expected source path /tmp/a, got %q", preview.SourcePath)
}
if meta.calls != 1 {
t.Fatalf("expected metadata to be prepared once on cache miss, got %d calls", meta.calls)
}
if tracker.dryRunCalls != 1 {
t.Fatalf("expected 1 dry-run build call, got %d", tracker.dryRunCalls)
}
}

func TestFetchTrackerDryRunPreviewNoSeedSkipsClient(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -3968,7 +4007,7 @@ func TestFetchTrackerDryRunPreviewRequiresCachedMetadata(t *testing.T) {

_, err = core.FetchTrackerDryRunPreview(context.Background(), api.Request{
Paths: []string{"/tmp/a"},
Mode: api.ModeGUI,
Mode: api.ModeCLI,
})
assertRequiresPreparedMetadata(t, err, "/tmp/a")
}
Expand Down
Loading