Skip to content

refactor(provider): share config persistence helpers - #1538

Merged
skevetter merged 1 commit into
mainfrom
refactor/provider-share-config-persistence
Oct 18, 2026
Merged

skevetter merged 1 commit into
mainfrom
refactor/provider-share-config-persistence

Conversation

@skevetter

@skevetter skevetter commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Share the save, load, and id-guard logic in pkg/provider/dir.go through private helpers. Public signatures and behavior are unchanged.

  • pkg/provider/persist.go: requireID, saveJSON, writeJSONFile, loadJSON[T].
  • pkg/provider/dir.go: the six Get*Dir guards call requireID. The Save and Load functions use the helpers. SaveWorkspaceResult keeps its existence check and does not create the directory.
  • pkg/provider/export.go: the three tar+base64 blocks share archiveDirBase64.
  • pkg/provider/persist_test.go: table-driven tests for the helpers.

Why

Each Save and Load function repeated the same marshal, write, and unmarshal steps. Consolidating them reduces the duplicated code paths that must stay consistent.

Preserved behavior: per-type file modes (0o600 and 0o644), the ... is empty and workspace ... no longer exists error texts, the no-MkdirAll path for workspace results, and the Origin and Context fields set on load.

Validation

  • go build ./...
  • go vet ./pkg/provider/
  • mise run cli:format
  • mise run cli:lint:ci (0 issues)
  • go test ./pkg/provider/... ./pkg/workspace/... ./pkg/options/... (pass)

CodeRabbit CLI

coderabbit review --agent --committed --base-commit 56102eb completed with 0 findings across 4 files.

Auto-merge

Eligible: yes. Behavior-preserving refactor, 4 files, about 205 insertions and 146 deletions. No tests weakened, no restricted paths, and no lint disabled or //nolint added.

Summary by CodeRabbit

  • Bug Fixes
    • Invalid identifiers are now rejected consistently when accessing provider, machine, and workspace directories.
    • Configuration and workspace result files now report read and write errors more consistently, including missing or invalid files.
    • Workspace result saving still requires an existing workspace configuration and does not create a missing workspace directory.

@skevetter skevetter added the auto-refactor Automated refactor PR label Oct 18, 2026
@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 7d14af1
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ad432c1f5ff26b2209485c7

@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 7d14af1
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad432c157ba507320b63025

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ede854a-12d7-4913-8269-34fdeee29993
📥 Commits

Reviewing files that changed from the base of the PR and between 56102eb and 7d14af1.

📒 Files selected for processing: 4
  • pkg/provider/dir.go
  • pkg/provider/export.go
  • pkg/provider/persist.go
  • pkg/provider/persist_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Provider directory validation, JSON persistence, and directory archive creation now use shared helpers. Persistence tests cover identifier checks, JSON operations, file permissions, and error cases.

Changes: Provider helpers

Layer / File(s) Summary
Identifier validation
pkg/provider/persist.go, pkg/provider/dir.go, pkg/provider/persist_test.go
Directory functions use requireID for empty identifier checks. Tests cover valid and empty identifiers.
JSON persistence
pkg/provider/persist.go, pkg/provider/dir.go, pkg/provider/persist_test.go
Config save and load functions use shared JSON helpers. Save modes remain 0600 for provider, Pro instance, and machine configs, and 0644 for workspace configs. Workspace result saving still requires an existing workspace config. Tests cover JSON round trips, permissions, absent parent directories, missing files, and invalid JSON.
Directory archive creation
pkg/provider/export.go
Workspace, machine, and provider exports use archiveDirBase64. The helper applies the existing exclusions, encodes archives as raw base64, and labels compression errors by directory kind.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Refactor

Suggested reviewers: fabiankramm

Merge Risk: ⚪ Minimal · up to 7d14a

This is a behavior-preserving refactor of provider persistence and export helpers, with new tests for the helpers. No concrete merge-blocking risk was found.

Security architecture risk: ⚪ Minimal · up to 7d14a

The refactor preserves existing file permissions, workspace-existence checks, atomic-write behavior, and export filtering. No material security risk was found to be introduced or worsened, and no security findings remain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed paths retain the same filesystem targets and export sources for provider, machine, Pro instance, and workspace state. The helper extraction does not introduce additional callers, credentials, privileges, or cross-service access.

Trust Boundaries and Controls

  • observed — Operation-specific permissions remain explicit at callers: provider, Pro instance, machine, and workspace-result files use 0600; workspace configuration uses 0644. Directory creation retains 0755. The shared helpers do not choose a broader permission policy.

Resilience and Maintainability Implications

  • observed — The unchanged atomic writer retains same-directory temporary files, pre-rename cleanup attempts, permission setting, synchronization, and atomic replacement. Concurrent writers remain last-rename-wins, and directory synchronization may fail after replacement. The workspace existence check is still separate from the write. These are pre-existing failure and concurrency semantics, not new guarantees or regressions introduced by the helpers.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.59% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 main change: consolidating provider configuration persistence logic into shared helpers.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@skevetter
skevetter force-pushed the refactor/provider-share-config-persistence branch from f8d0d80 to 7d14af1 Compare October 18, 2026 02:45
@skevetter
skevetter marked this pull request as ready for review October 18, 2026 03:30
@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit 58162b7 into main Oct 18, 2026
111 checks passed
@skevetter
skevetter deleted the refactor/provider-share-config-persistence branch October 18, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-refactor Automated refactor PR size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant