Skip to content

Commit a82153e

Browse files
committed
fix: stabilize job IDs to resolve duplicate job display bugs
1 parent 4ae4610 commit a82153e

9 files changed

Lines changed: 74 additions & 44 deletions

File tree

internal/jobs/git-clone/job.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
type GitCloneJob struct {
17+
id string
1718
URL string
1819
OutputPath string
1920
Depth int
@@ -30,7 +31,12 @@ type gitCloneJobState struct {
3031
}
3132

3233
func New(url, outputPath string, depth int, token, sshKey string) *GitCloneJob {
34+
id := outputPath
35+
if id == "" {
36+
id = url
37+
}
3338
return &GitCloneJob{
39+
id: id,
3440
URL: url,
3541
OutputPath: outputPath,
3642
Depth: depth,
@@ -40,10 +46,7 @@ func New(url, outputPath string, depth int, token, sshKey string) *GitCloneJob {
4046
}
4147

4248
func (j *GitCloneJob) ID() string {
43-
if j.OutputPath != "" {
44-
return j.OutputPath
45-
}
46-
return j.URL
49+
return j.id
4750
}
4851

4952
func (j *GitCloneJob) Type() string { return "git-clone" }

internal/jobs/github-release/ghrelease_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package ghrelease
33
import (
44
"runtime"
55
"testing"
6+
7+
"github.com/tanq16/danzo/utils"
68
)
79

810
func TestParseGitHubURLAcceptsSupportedRepositoryForms(t *testing.T) {
@@ -64,3 +66,15 @@ func TestSelectGitHubLatestAssetIgnoresChecksumsAndMatchesRuntimePlatform(t *tes
6466
t.Fatalf("expected platform asset, got url=%q size=%d", url, size)
6567
}
6668
}
69+
70+
func TestGHReleaseJobIDIsStable(t *testing.T) {
71+
job := New("tanq16/danzo", "", false, utils.HTTPClientConfig{})
72+
initialID := job.ID()
73+
74+
// Simulate what happens in Run() when output path is resolved
75+
job.OutputPath = "danzo_resolved.tar.gz"
76+
77+
if job.ID() != initialID {
78+
t.Fatalf("expected ID to be stable (%q), but got %q", initialID, job.ID())
79+
}
80+
}

internal/jobs/github-release/job.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
type GHReleaseJob struct {
17+
id string
1718
URL string
1819
OutputPath string
1920
Manual bool
@@ -32,7 +33,12 @@ type ghReleaseJobState struct {
3233
}
3334

3435
func New(url, outputPath string, manual bool, httpConfig utils.HTTPClientConfig) *GHReleaseJob {
36+
id := outputPath
37+
if id == "" {
38+
id = url
39+
}
3540
return &GHReleaseJob{
41+
id: id,
3642
URL: url,
3743
OutputPath: outputPath,
3844
Manual: manual,
@@ -41,10 +47,7 @@ func New(url, outputPath string, manual bool, httpConfig utils.HTTPClientConfig)
4147
}
4248

4349
func (j *GHReleaseJob) ID() string {
44-
if j.OutputPath != "" {
45-
return j.OutputPath
46-
}
47-
return j.URL
50+
return j.id
4851
}
4952

5053
func (j *GHReleaseJob) Type() string { return "github-release" }

internal/jobs/google-drive/job.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
type GDriveJob struct {
18+
id string
1819
URL string
1920
OutputPath string
2021
APIKey string
@@ -35,7 +36,12 @@ type gdriveJobState struct {
3536
}
3637

3738
func New(url, outputPath, apiKey, credentialsFile string, httpConfig utils.HTTPClientConfig) *GDriveJob {
39+
id := outputPath
40+
if id == "" {
41+
id = url
42+
}
3843
return &GDriveJob{
44+
id: id,
3945
URL: url,
4046
OutputPath: outputPath,
4147
APIKey: apiKey,
@@ -45,10 +51,7 @@ func New(url, outputPath, apiKey, credentialsFile string, httpConfig utils.HTTPC
4551
}
4652

4753
func (j *GDriveJob) ID() string {
48-
if j.OutputPath != "" {
49-
return j.OutputPath
50-
}
51-
return j.URL
54+
return j.id
5255
}
5356

5457
func (j *GDriveJob) Type() string { return "google-drive" }

internal/jobs/http/job.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type HTTPDownloadJob struct {
4646
}
4747

4848
type HTTPJob struct {
49+
id string
4950
URL string
5051
OutputPath string
5152
Connections int
@@ -62,7 +63,12 @@ type httpJobState struct {
6263
}
6364

6465
func New(url, outputPath string, connections int, httpConfig utils.HTTPClientConfig) *HTTPJob {
66+
id := outputPath
67+
if id == "" {
68+
id = url
69+
}
6570
return &HTTPJob{
71+
id: id,
6672
URL: url,
6773
OutputPath: outputPath,
6874
Connections: connections,
@@ -71,19 +77,7 @@ func New(url, outputPath string, connections int, httpConfig utils.HTTPClientCon
7177
}
7278

7379
func (j *HTTPJob) ID() string {
74-
if j.OutputPath != "" {
75-
return j.OutputPath
76-
}
77-
parsedURL, err := url.Parse(j.URL)
78-
if err != nil {
79-
return j.URL
80-
}
81-
parts := strings.Split(parsedURL.Path, "/")
82-
name := parts[len(parts)-1]
83-
if name == "" {
84-
return j.URL
85-
}
86-
return name
80+
return j.id
8781
}
8882

8983
func (j *HTTPJob) Type() string { return "http" }

internal/jobs/live-stream/job.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
type LiveStreamJob struct {
18+
id string
1819
URL string
1920
OutputPath string
2021
Connections int
@@ -33,7 +34,12 @@ type liveStreamJobState struct {
3334
}
3435

3536
func New(urlStr, outputPath string, connections int, extractor string, httpConfig utils.HTTPClientConfig) *LiveStreamJob {
37+
id := outputPath
38+
if id == "" {
39+
id = urlStr
40+
}
3641
return &LiveStreamJob{
42+
id: id,
3743
URL: urlStr,
3844
OutputPath: outputPath,
3945
Connections: connections,
@@ -43,10 +49,7 @@ func New(urlStr, outputPath string, connections int, extractor string, httpConfi
4349
}
4450

4551
func (j *LiveStreamJob) ID() string {
46-
if j.OutputPath != "" {
47-
return j.OutputPath
48-
}
49-
return j.URL
52+
return j.id
5053
}
5154

5255
func (j *LiveStreamJob) Type() string { return "live-stream" }

internal/jobs/s3/job.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
type S3Job struct {
17+
id string
1718
URL string
1819
OutputPath string
1920
Connections int
@@ -28,7 +29,12 @@ type s3JobState struct {
2829
}
2930

3031
func New(url, outputPath string, connections int, profile string) *S3Job {
32+
id := outputPath
33+
if id == "" {
34+
id = url
35+
}
3136
return &S3Job{
37+
id: id,
3238
URL: url,
3339
OutputPath: outputPath,
3440
Connections: connections,
@@ -37,10 +43,7 @@ func New(url, outputPath string, connections int, profile string) *S3Job {
3743
}
3844

3945
func (j *S3Job) ID() string {
40-
if j.OutputPath != "" {
41-
return j.OutputPath
42-
}
43-
return j.URL
46+
return j.id
4447
}
4548

4649
func (j *S3Job) Type() string { return "s3" }

internal/jobs/torrent/job.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
type TorrentJob struct {
19+
id string
1920
URI string
2021
OutputPath string
2122
Connections int
@@ -32,7 +33,16 @@ type torrentJobState struct {
3233
}
3334

3435
func New(uri, outputPath string, connections int, httpConfig utils.HTTPClientConfig) *TorrentJob {
36+
id := outputPath
37+
if id == "" || id == "." {
38+
if strings.HasPrefix(uri, "magnet:") {
39+
id = "magnet-link"
40+
} else {
41+
id = filepath.Base(uri)
42+
}
43+
}
3544
return &TorrentJob{
45+
id: id,
3646
URI: uri,
3747
OutputPath: outputPath,
3848
Connections: connections,
@@ -41,13 +51,7 @@ func New(uri, outputPath string, connections int, httpConfig utils.HTTPClientCon
4151
}
4252

4353
func (j *TorrentJob) ID() string {
44-
if j.OutputPath != "" && j.OutputPath != "." {
45-
return j.OutputPath
46-
}
47-
if strings.HasPrefix(j.URI, "magnet:") {
48-
return "magnet-link"
49-
}
50-
return filepath.Base(j.URI)
54+
return j.id
5155
}
5256

5357
func (j *TorrentJob) Type() string { return "torrent" }

internal/jobs/ytdlp/job.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,27 @@ type YTDLPProgress struct {
3131
}
3232

3333
type YTDLPJob struct {
34+
id string
3435
URL string
3536
OutputPath string
3637
HTTPConfig utils.HTTPClientConfig
3738
}
3839

3940
func New(url, outputPath string, httpConfig utils.HTTPClientConfig) *YTDLPJob {
41+
id := outputPath
42+
if id == "" {
43+
id = url
44+
}
4045
return &YTDLPJob{
46+
id: id,
4147
URL: url,
4248
OutputPath: outputPath,
4349
HTTPConfig: httpConfig,
4450
}
4551
}
4652

4753
func (j *YTDLPJob) ID() string {
48-
if j.OutputPath != "" {
49-
return j.OutputPath
50-
}
51-
return j.URL
54+
return j.id
5255
}
5356

5457
func (j *YTDLPJob) Type() string { return "ytdlp" }

0 commit comments

Comments
 (0)