Skip to content

lanternd: support explicit staging environment for desktop services - #577

Open
atavism wants to merge 7 commits into
mainfrom
atavism/issue-3723
Open

lanternd: support explicit staging environment for desktop services#577
atavism wants to merge 7 commits into
mainfrom
atavism/issue-3723

Conversation

@atavism

@atavism atavism commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Add validated prod|staging environment selection to lanternd run and install, persist it in the Windows service command, and expose the active environment. This lets installed Lantern payment tests reliably use staging services.

Summary by CodeRabbit

  • New Features

    • Added support for selecting production or staging environments when running or installing the daemon.
    • Persisted the selected environment across service restarts on macOS, Linux, and Windows.
    • Staging mode now uses staging authentication and service endpoints.
  • Bug Fixes

    • Added validation for unsupported environment values.
    • Improved recovery and handling of configured service arguments.
  • Tests

    • Added coverage for environment selection, defaults, validation, persistence, and platform-specific service configuration.

Copilot AI review requested due to automatic review settings July 24, 2026 16:19
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 74a25f0c-cd35-4dec-bbc4-9e202ea414de

📥 Commits

Reviewing files that changed from the base of the PR and between 036591e and 4a83abc.

📒 Files selected for processing (2)
  • cmd/lanternd/lanternd.go
  • cmd/lanternd/lanternd_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/lanternd/lanternd_test.go
  • cmd/lanternd/lanternd.go

📝 Walkthrough

Walkthrough

The daemon now supports validated prod and staging environments. The selected environment persists in service arguments, flows through platform service managers, and controls backend authentication and endpoint configuration.

Changes

Daemon environment selection

Layer / File(s) Summary
Environment configuration and persistence
cmd/lanternd/lanternd.go, cmd/lanternd/lanternd_test.go
Commands validate environment values, apply production defaults, serialize service arguments, and restore persisted configuration.
Platform service environment wiring
cmd/lanternd/lanternd_darwin.go, cmd/lanternd/lanternd_linux.go, cmd/lanternd/lanternd_windows.go
launchd, systemd, and Windows service definitions pass the selected environment to the daemon. Windows execution parses persisted arguments and derives child-process arguments from the parsed configuration.
Environment-specific daemon backend
cmd/lanternd/lanternd.go, cmd/lanternd/lanternd_test.go
Daemon startup selects staging or production authentication and pro-server endpoints, passes the environment to the backend, and logs the selected URLs. Tests cover staging configuration and preservation of a development environment for production options.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RunCommand
  participant serviceConfig
  participant ServiceManager
  participant runDaemon
  participant Backend
  RunCommand->>serviceConfig: Read paths, log level, and environment
  serviceConfig->>ServiceManager: Persist daemon arguments
  ServiceManager->>runDaemon: Start with selected environment
  runDaemon->>Backend: Initialize with environment-specific endpoints and authentication
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: explicit staging environment support for desktop services.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch atavism/issue-3723

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an explicit prod|staging environment selection to lanternd so desktop installs (systemd/launchd/Windows service) can reliably run against staging backend services, and persists that selection in the service command line.

Changes:

  • Add --environment flag (validated) to lanternd run and lanternd install, and propagate it into daemon startup options.
  • Persist the selected environment in system service definitions across Windows/systemd/launchd.
  • Add tests covering argument parsing, persistence, and staging endpoint selection.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/lanternd/lanternd.go Adds environment parsing/validation, service arg persistence helpers, and threads environment into backend options/logging.
cmd/lanternd/lanternd_windows.go Persists --environment into the Windows service configuration and parses it back from the service ImagePath.
cmd/lanternd/lanternd_test.go Adds tests for environment flag validation, service arg round-tripping, and staging endpoint selection.
cmd/lanternd/lanternd_linux.go Extends the systemd unit template and install path to include --environment.
cmd/lanternd/lanternd_darwin.go Extends the launchd plist template and install path to include --environment.
Comments suppressed due to low confidence (2)

cmd/lanternd/lanternd.go:61

  • The new doc comment above parseDaemonEnvironment restates what the function already makes clear from its name and implementation. To match AGENTS.md comment guidance, consider removing it unless there's a surprising invariant or rationale to document.
// parseDaemonEnvironment keeps lanternd from silently accepting an unknown environment.
func parseDaemonEnvironment(value string) (daemonEnvironment, error) {

cmd/lanternd/lanternd.go:413

  • The doc comment above daemonBackendURLs restates the function name/signature rather than capturing a non-obvious contract. Consider removing it to keep comment noise low (per AGENTS.md).
// daemonBackendURLs returns the endpoints that the backend will use for the selected environment.
func daemonBackendURLs(environment daemonEnvironment) (authURL, proServerURL string) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/lanternd/lanternd.go Outdated
Comment on lines +400 to +410
// daemonBackendOptions passes the selected daemon environment through to the backend.
func daemonBackendOptions(dataPath, logPath, logLevel string, environment daemonEnvironment) backend.Options {
return backend.Options{
DataDir: dataPath,
LogDir: logPath,
LogLevel: logLevel,
})
EnvOverrides: map[string]string{
commonenv.ENV.String(): string(environment),
},
}
}
Comment thread cmd/lanternd/lanternd.go Outdated
Comment on lines +50 to +51
// UnmarshalText validates the environment while go-arg parses the command line.
func (e *daemonEnvironment) UnmarshalText(text []byte) error {
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