fix: bug fixes, test coverage, and CI workflow
Some checks failed
CI / vet (push) Failing after 15s
CI / build (push) Failing after 30s
CI / test (push) Failing after 36s

- Fix Nodes.First() panic on empty slice (return nil)
- Fix ticker leak in archive.go (create once, defer Stop)
- Fix cookie path matching for empty and root paths
- Fix lost query params in google.go (u.Query().Set was discarded)
- Fix type assertion panic in useragents.go
- Fix dropped date parse error in powerball.go
- Remove unreachable dead code in megamillions.go and powerball.go
- Simplify document.go WaitForNetworkIdle, remove unused root field
- Remove debug fmt.Println calls across codebase
- Replace panic(err) with stderr+exit in all cmd/ programs
- Fix duckduckgo cmd: remove useless defer, return error on bad safesearch
- Fix archive cmd: ToConfig returns error instead of panicking
- Add 39+ unit tests across 6 new test files
- Add Gitea Actions CI workflow (build, test, vet in parallel)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-09 11:14:05 -05:00
parent e807dbb2ff
commit e7b7e78796
25 changed files with 868 additions and 117 deletions

View File

@@ -130,10 +130,9 @@ func (c Config) Archive(ctx context.Context, b extractor.Browser, target string)
select {
case <-ctx.Done():
fmt.Println("context already done before entering the loop:", ctx.Err())
slog.Debug("context already done before entering the loop", "err", ctx.Err())
return nil, ctx.Err()
default:
fmt.Println("context not done yet")
// Proceed with the loop
}
// now we are waiting for archive.ph to archive the page and redirect us to the archived page
@@ -141,6 +140,9 @@ func (c Config) Archive(ctx context.Context, b extractor.Browser, target string)
// if the page path starts with /wip/ then we are still waiting
// also periodically refresh the page just in case
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
keepGoing := true
for keepGoing {
select {
@@ -148,14 +150,14 @@ func (c Config) Archive(ctx context.Context, b extractor.Browser, target string)
slog.Info("context done")
keepGoing = false
case <-time.NewTicker(5 * time.Second).C:
case <-ticker.C:
archivedUrl, err := url.Parse(doc.URL())
if err != nil {
continue
}
fmt.Println("checking url:", archivedUrl.String())
slog.Debug("checking url", "url", archivedUrl.String())
// if the url is not the same as the endpoint, or the path does not start with /wip/ or /submit then we are done
if archivedUrl.Hostname() != endpoint.Hostname() || (!strings.HasPrefix(archivedUrl.Path, "/wip/") && !strings.HasPrefix(archivedUrl.Path, "/submit")) {
keepGoing = false

View File

@@ -28,7 +28,7 @@ var Flags = ArchiveFlags{
},
}
func (f ArchiveFlags) ToConfig(_ context.Context, cmd *cli.Command) archive.Config {
func (f ArchiveFlags) ToConfig(_ context.Context, cmd *cli.Command) (archive.Config, error) {
c := archive.DefaultConfig
if e := cmd.String("endpoint"); e != "" {
@@ -38,12 +38,12 @@ func (f ArchiveFlags) ToConfig(_ context.Context, cmd *cli.Command) archive.Conf
if t := cmd.String("timeout"); t != "" {
d, err := time.ParseDuration(t)
if err != nil {
panic(err)
return c, fmt.Errorf("invalid timeout duration: %w", err)
}
c.Timeout = &d
}
return c
return c, nil
}
func main() {
@@ -122,7 +122,8 @@ func main() {
err := cli.Run(context.Background(), os.Args)
if err != nil {
panic(err)
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}