Skip to content

Conversation

@creativeprojects
Copy link
Owner

Also try to fix a flaky unit test on my local machine

@coderabbitai
Copy link

coderabbitai bot commented Sep 27, 2025

Walkthrough

Bumps Go toolchain to 1.25 across workflows and go.mod, enables godoclint, adjusts tests in lock package to use context timeouts and global signal handling, modifies a space-writing loop in commands_display.go, adds a new DisplayStatus method for systemd, changes a Windows handler method signature, and updates several comments/docstrings.

Changes

Cohort / File(s) Change summary
CI workflows: Go 1.25 bump
.github/workflows/build.yml, .github/workflows/codeql.yml, .github/workflows/doc.yml, .github/workflows/docker.yml, .github/workflows/release-doc.yml, .github/workflows/release.yml, .github/workflows/snapshot.yml
Update setup-go version from 1.24 to 1.25; no other workflow logic changes.
Go toolchain
go.mod
Update Go version from 1.24.7 to 1.25.1.
Lint configuration
.golangci.yml
Enable godoclint by uncommenting it in linters.enable.
Lock package tests and helper
lock/lock_test.go, lock/test/main.go
Tests use CommandContext with 5s timeout; improved error messages. Global signal handling moved to outer scope; listens for Interrupt, SIGTERM, SIGABRT.
CLI display alignment loop
commands_display.go
Replace index-based loop writing spaces with a range-based loop construct.
Scheduling handlers API
schedule/handler_systemd.go, schedule/handler_windows.go
Add method HandlerSystemd.DisplayStatus(profileName string) error. Rename Windows method from DisplayStatus(string) to DisplayJobStatus(job *Config) error; comment capitalisation updates.
Comments/doc updates only
darwin/calendar_interval.go, schedule/config.go, schtasks/principal.go, schtasks/settings.go, schtasks/taskscheduler.go, shell/arg.go, term/term.go, mask/mask.go
Documentation/comment wording and capitalisation updates; no functional changes.
Flags linter suppression
flags.go
Add //nolint:forcetypeassert on a type assertion; no logic change.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as Caller
  participant HS as HandlerSystemd
  participant SYS as getSystemdStatus
  participant Out as Stdout

  U->>HS: DisplayStatus(profileName)
  HS->>SYS: getSystemdStatus(profileName, root/user scope)
  alt status text returned
    SYS-->>HS: status (non-empty)
    HS->>Out: print "Timers summary" + status
    HS-->>U: nil
  else no status or error
    SYS-->>HS: "" or error
    note right of HS: Returns nil without output when empty/error
    HS-->>U: nil
  end
Loading
sequenceDiagram
  autonumber
  actor T as Test
  participant C as context.WithTimeout(5s)
  participant P as exec.CommandContext
  participant Proc as Child process

  T->>C: create ctx,cancel
  T->>P: start with ctx
  P->>Proc: run
  alt completes before timeout
    Proc-->>T: exit
  else timeout
    C-->>Proc: context deadline -> termination
    Proc-->>T: exit due to ctx
  end
  T->>C: cancel() (defer)
Loading
sequenceDiagram
  autonumber
  actor Main as lock/test/main.go
  participant OS as os/signal
  participant L as Lock
  participant Tm as time.After

  Main->>OS: Notify(sigChan, Interrupt,SIGTERM,SIGABRT)
  Main->>L: Acquire
  L-->>Main: "lock acquired"
  par wait
    Main->>OS: receive from sigChan
  and timeout
    Main->>Tm: time.After(d)
  end
  alt signal received
    Main-->>Main: handle and release
  else timeout fires
    Main-->>Main: release on timeout
  end
  Main->>OS: signal.Stop(sigChan) (defer)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely summarises the primary change of the pull request, which is upgrading the Go version to 1.25, following conventional “chore” phrasing without extraneous detail.
Description Check ✅ Passed The description mentions fixing a flaky unit test, which directly corresponds to the test file modifications in the changeset, so it is appropriately related to the pull request.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch go1.25

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.69%. Comparing base (00f3f2d) to head (3ef0be5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #564   +/-   ##
=======================================
  Coverage   79.69%   79.69%           
=======================================
  Files         137      137           
  Lines       13467    13467           
=======================================
  Hits        10732    10732           
  Misses       2310     2310           
  Partials      425      425           
Flag Coverage Δ
unittests 79.69% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
term/term.go (1)

89-89: Fix incorrect doc comment phrasing.

Docstring still claims the function “returns true”, but the function returns the (width, height) pair. Please align the comment with the actual return values.

-// OsStdoutTerminalSize returns true as os.Stdout is a terminal session
+// OsStdoutTerminalSize returns the current width and height of os.Stdout.
flags.go (1)

61-62: Guard the type assertion to avoid possible panics

cast will usually return the expected concrete type, but if a future caller uses a named type (type CmdOutput string, type Verbosity int, etc.), v.(T) will panic despite a successful conversion. Wrapping the assertion with an ok check keeps the helper robust and removes the need for the lint suppression.

-			if err == nil {
-				defaultValue = v.(T) //nolint:forcetypeassert
+			if err == nil {
+				if converted, ok := v.(T); ok {
+					defaultValue = converted
+				} else {
+					clog.Errorf("cannot assign env variable %s=%q to expected type %T", key, value, defaultValue)
+				}
commands_display.go (1)

401-403: Reduce syscalls: write all spaces in one call

Writing one byte per iteration is inefficient on hot paths. Prebuild the run of spaces and write once.

Apply:

-                for i := 0; i < l.breakLength; i++ {
-                    _, _ = l.writer.Write(l.tokens[0:1]) // fill spaces for alignment
-                }
+                if l.breakLength > 0 {
+                    buf := bytes.Repeat(l.tokens[0:1], l.breakLength)
+                    _, _ = l.writer.Write(buf) // fill spaces for alignment
+                }
schedule/handler_systemd.go (1)

96-121: Silent error swallow and brittle "0 timers" check

Currently any error from getSystemdStatus is silently ignored, making diagnoses hard; and matching "0 timers" is locale‑dependent.

Minimal improvement while keeping UX silent:

-    if err != nil || status == "" || strings.Contains(status, "0 timers") {
-        // fail silently
-        return nil //nolint:nilerr
-    }
+    if err != nil {
+        clog.Debugf("getSystemdStatus(%q) error: %v; output: %q", profileName, err, status)
+        return nil //nolint:nilerr
+    }
+    if status == "" || strings.Contains(status, "0 timers") {
+        return nil
+    }

Optional follow‑up: replace the substring check with a small helper that counts non‑header lines to avoid locale coupling.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00f3f2d and 3ef0be5.

📒 Files selected for processing (23)
  • .github/workflows/build.yml (1 hunks)
  • .github/workflows/codeql.yml (1 hunks)
  • .github/workflows/doc.yml (1 hunks)
  • .github/workflows/docker.yml (1 hunks)
  • .github/workflows/release-doc.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .github/workflows/snapshot.yml (1 hunks)
  • .golangci.yml (1 hunks)
  • commands_display.go (1 hunks)
  • darwin/calendar_interval.go (2 hunks)
  • flags.go (1 hunks)
  • go.mod (1 hunks)
  • lock/lock_test.go (1 hunks)
  • lock/test/main.go (1 hunks)
  • mask/mask.go (1 hunks)
  • schedule/config.go (1 hunks)
  • schedule/handler_systemd.go (2 hunks)
  • schedule/handler_windows.go (2 hunks)
  • schtasks/principal.go (2 hunks)
  • schtasks/settings.go (1 hunks)
  • schtasks/taskscheduler.go (1 hunks)
  • shell/arg.go (2 hunks)
  • term/term.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-02-14T22:53:42.689Z
Learnt from: creativeprojects
PR: creativeprojects/resticprofile#459
File: schtasks/schtasks.go:29-30
Timestamp: 2025-02-14T22:53:42.689Z
Learning: In the `schtasks` package, `tasksPath` is defined as a constant with value `\resticprofile backup\` in `taskscheduler.go`. It's used as a prefix for managing task paths in the Windows Task Scheduler.

Applied to files:

  • schtasks/taskscheduler.go
📚 Learning: 2025-02-04T14:38:07.701Z
Learnt from: creativeprojects
PR: creativeprojects/resticprofile#425
File: schedule/handler_windows.go:97-118
Timestamp: 2025-02-04T14:38:07.701Z
Learning: The shell.SplitArguments function in the resticprofile project returns only []string and does not return any error.

Applied to files:

  • go.mod
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build and test (1.25, ubuntu-latest)
  • GitHub Check: Build and test (1.25, macos-latest)
  • GitHub Check: Build and test (1.25, windows-latest)
🔇 Additional comments (10)
lock/test/main.go (1)

23-27: Broader signal coverage at start-up looks solid

Catching INT/TERM/ABRT at process start and deferring signal.Stop keeps the handler active for the full lifecycle without leaking subscriptions on early exit. Happy with this.

lock/lock_test.go (2)

274-295: Timeout guard shields TestLockIsRemovedAfterInterruptSignal

Wrapping the helper process in a 5 s context and tightening the failure messages should prevent future hangs while keeping the intent clear. Looks good to me.


302-323: Shell-based interrupt test hardening looks good

The context-bound command and explicit assertions mirror the previous test nicely, giving us the same protection against stalled children in the shell variant. No issues spotted.

.github/workflows/codeql.yml (1)

56-57: Go 1.25 specification in CodeQL workflow looks good

Updating the runner to pick up Go ≥1.25 keeps the static analysis aligned with the toolchain bump elsewhere in the repo. Nicely done.

.github/workflows/release-doc.yml (1)

22-23: Documentation release job now matches the Go toolchain upgrade

The setup-go step following the ~1.25 constraint keeps this workflow consistent with the rest of the CI surface.

.github/workflows/release.yml (1)

23-24: Release workflow aligned with Go 1.25

This keeps the release pipeline on the same toolchain level as the rest of the project—looks good.

.golangci.yml (1)

25-25: Enabling godoclint strengthens lint coverage

Nice to see the documentation linter turned on; having it active at the CI level will keep exported symbols properly documented.

schedule/handler_systemd.go (1)

322-325: Doc comment capitalisation LGTM

Comment now starts with the function name; good for godoc.

schedule/handler_windows.go (2)

142-145: Doc comment tidy LGTM

Correct capitalisation for godoc.


107-117: API alignment confirmed
The Handler interface, all platform implementations and call sites (including tests) correctly reference DisplayJobStatus and DisplayStatus.

@creativeprojects creativeprojects merged commit 0a99c85 into master Sep 27, 2025
11 checks passed
@creativeprojects creativeprojects deleted the go1.25 branch September 27, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants