Replace generated config with self-documenting template#134
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughReplaced Viper-based default config creation with an embedded TOML template. Init now attempts to create the config file atomically; if it already exists it loads it, otherwise it writes the embedded Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/config/config.go (1)
16-24: Consider removing or consolidatingsetDefaults()to avoid drift.Both
setDefaults()anddefaultConfigTemplatedefine the same default values (type="aws",tag="latest",port="4566"). If these diverge in the future, users would see different behavior depending on whether the config file exists. Consider either:
- Removing
setDefaults()entirely if the template is always written before loading, or- Generating the template programmatically from the same source of truth.
Currently they're in sync, so this is a low-risk observation for future maintainability.
Also applies to: 47-50
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/config/config.go` around lines 16 - 24, The file currently duplicates container defaults in setDefaults() and defaultConfigTemplate; remove the drift risk by consolidating them: either delete setDefaults() (set/ensure defaultConfigTemplate is written before config load) or extract a single source (e.g., a containersDefault structure/constant) and have both setDefaults() and defaultConfigTemplate be generated from that single symbol so both use the same values; reference setDefaults() and defaultConfigTemplate and update any code that relies on setDefaults() to instead rely on the single source-of-truth or the template-writing sequence.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/config/config.go`:
- Around line 16-24: The file currently duplicates container defaults in
setDefaults() and defaultConfigTemplate; remove the drift risk by consolidating
them: either delete setDefaults() (set/ensure defaultConfigTemplate is written
before config load) or extract a single source (e.g., a containersDefault
structure/constant) and have both setDefaults() and defaultConfigTemplate be
generated from that single symbol so both use the same values; reference
setDefaults() and defaultConfigTemplate and update any code that relies on
setDefaults() to instead rely on the single source-of-truth or the
template-writing sequence.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 563e45c5-bc38-4b98-aff7-0e6b21456469
📒 Files selected for processing (1)
internal/config/config.go
internal/config/config.go
Outdated
| # ENFORCE_IAM = "1" | ||
| # LAMBDA_KEEPALIVE_MS = "300000" | ||
| ` | ||
|
|
There was a problem hiding this comment.
nit can we make this a .toml file embedded via //go:embed? It would allow editing as toml directly with syntax highlighting etc.
internal/config/config.go
Outdated
| type = "aws" # Emulator type. Currently supported: "aws" | ||
| tag = "latest" # Docker image tag, e.g. "latest", "3.8.0", "latest-arm64" | ||
| port = "4566" # Host port the emulator will be accessible on | ||
| # env = [] # Named environment profiles to apply (see [env.*] sections below) |
There was a problem hiding this comment.
suggestion: we can also document volume now, it's been added after we created the issue.
internal/config/config.go
Outdated
| # DEBUG=1 - Enable verbose logging | ||
| # PERSISTENCE=1 - Persist LocalStack state across restarts | ||
| # ENFORCE_IAM=1 - Enable IAM enforcement |
There was a problem hiding this comment.
Updated these based on the data usage of each variable, see relevant discussion for more context.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/config/config.go (1)
42-75: Unify default values to a single source of truth.Lines 48-50 duplicate values already defined in
setDefaults()(Lines 17-22). This can drift and make generated config differ from effective runtime defaults. Please centralize these defaults (shared constants or generated template from one source).Based on learnings: "Configuration file is created automatically on first run with defaults at $HOME/.config/lstk/config.toml or OS default".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/config/config.go` around lines 42 - 75, The defaultConfigTemplate currently duplicates container defaults (type, tag, port) already defined in setDefaults(), which risks drift; modify the code so the template is generated from a single source of truth: either expose the defaults as shared constants (e.g., DefaultContainerType, DefaultContainerTag, DefaultContainerPort) used by both setDefaults() and to build defaultConfigTemplate, or change defaultConfigTemplate into a function that constructs the template string by reading values from setDefaults()/the shared defaults; update references to the const defaultConfigTemplate accordingly so the generated config uses those centralized defaults and remove the hard-coded values from the literal template.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/config/config.go`:
- Around line 98-100: The current Init() code uses os.WriteFile to create the
config (writing defaultConfigTemplate to configPath) which can race and
overwrite another concurrent process; change the creation to use os.OpenFile
with flags os.O_WRONLY|os.O_CREATE|os.O_EXCL and mode 0644 to perform atomic
exclusive creation, write defaultConfigTemplate through that file descriptor,
and if OpenFile returns os.ErrExist then treat it as a benign race by
loading/parsing the existing config (reusing the same load/parse logic) so
Init() is idempotent; reference symbols: Init(), configPath,
defaultConfigTemplate.
---
Nitpick comments:
In `@internal/config/config.go`:
- Around line 42-75: The defaultConfigTemplate currently duplicates container
defaults (type, tag, port) already defined in setDefaults(), which risks drift;
modify the code so the template is generated from a single source of truth:
either expose the defaults as shared constants (e.g., DefaultContainerType,
DefaultContainerTag, DefaultContainerPort) used by both setDefaults() and to
build defaultConfigTemplate, or change defaultConfigTemplate into a function
that constructs the template string by reading values from setDefaults()/the
shared defaults; update references to the const defaultConfigTemplate
accordingly so the generated config uses those centralized defaults and remove
the hard-coded values from the literal template.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: a722a4a5-b977-470e-9a79-a632281498c6
📒 Files selected for processing (1)
internal/config/config.go
|
Thanks for taking a look, @carole-lavillonniere! Tried to address all comments, could you take another look? |
internal/config/default_config.toml
Outdated
| # You can define multiple to run them side by side. | ||
| [[containers]] | ||
| type = "aws" # Emulator type. Currently supported: "aws" | ||
| tag = "latest" # Docker image tag, e.g. "latest", "3.8.0", "latest-arm64" |
There was a problem hiding this comment.
question: Do we restrict image tags to 2026.03 and onwards?
There was a problem hiding this comment.
There is no restriction implemented at the moment but it is a good idea. I still have on my list to look into what versions we want to support DRG-635
There was a problem hiding this comment.
I'd prefer it to be 2026.03 btw 😀 because the official documentation will use that
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/config/config.go (1)
13-14: Consider single-sourcing defaults to avoid drift.Defaults now exist in both
default_config.tomlandsetDefaults()(Line 21 to Line 29). This is easy to desynchronize; consider consolidating to one source of truth.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/config/config.go` around lines 13 - 14, The defaults are duplicated between the embedded variable defaultConfigTemplate and the setDefaults() function; replace the hard-coded defaults in setDefaults() by parsing the embedded defaultConfigTemplate and applying those values as the single source of truth. Update setDefaults() to decode/parse defaultConfigTemplate into the config struct (or an intermediate struct/map) and assign any missing fields from that parsed result, leaving defaultConfigTemplate as the canonical defaults provider and removing literal default values from setDefaults().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/config/config.go`:
- Around line 75-81: The file write/close error handling in the function
creating the default config (where f, defaultConfigTemplate and configPath are
used) can leave a partial file that later makes
firstExistingConfigPath()/loadConfig() succeed on a corrupted file; update the
error paths so that if f.WriteString(...) or f.Close() returns an error you
attempt to remove the incomplete config file at configPath (handle/remove any
remove error but still return the original write/close error wrapped), ensuring
the cleanup occurs before returning the fmt.Errorf in both the writeErr and
closeErr branches.
---
Nitpick comments:
In `@internal/config/config.go`:
- Around line 13-14: The defaults are duplicated between the embedded variable
defaultConfigTemplate and the setDefaults() function; replace the hard-coded
defaults in setDefaults() by parsing the embedded defaultConfigTemplate and
applying those values as the single source of truth. Update setDefaults() to
decode/parse defaultConfigTemplate into the config struct (or an intermediate
struct/map) and assign any missing fields from that parsed result, leaving
defaultConfigTemplate as the canonical defaults provider and removing literal
default values from setDefaults().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 137c907e-6e9d-4724-ae06-833c68ce69b2
📒 Files selected for processing (2)
internal/config/config.gointernal/config/default_config.toml
7c0c0ce to
33a6f8f
Compare
|
Merging with one more commit (33a6f8f) to address @coderabbitai's comment above. Cc @carole-lavillonniere for visibility. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1008
This ensures no partial/corrupt config file is left behind on disk when If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
No description provided.