Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Dec 29, 2025

Summary

Replaces scattered isDryRun() checks throughout the codebase with a centralized abstraction layer that automatically intercepts destructive operations using JavaScript Proxies.

Changes

New Module: src/utils/dryRun.ts

  • createDryRunGit() - Proxy wrapper for SimpleGit that blocks mutating operations (push, commit, checkout, merge, etc.)
  • createDryRunOctokit() - Proxy wrapper for Octokit that blocks mutating API calls (create*, update*, delete*, upload*)
  • dryRunFs - Object with file system operations that respect dry-run (writeFile, unlink, mkdir, rename)
  • dryRunExec() / dryRunExecSync() - Generic action wrappers for custom operations
  • logDryRun() - Consistent log formatting

Integration

  • getGitClient() and new createGitClient() return dry-run-aware git clients
  • getGitHubClient() returns dry-run-aware Octokit instance
  • Migrated commands (prepare.ts, publish.ts) and all targets to use wrapped APIs

ESLint Enforcement

Added no-restricted-syntax rules to catch:

  • Direct simpleGit() calls → use createGitClient()
  • Direct new Octokit() → use getGitHubClient()

Testing & Documentation

  • Added comprehensive tests for proxy behavior (19 tests)
  • Documented the pattern in AGENTS.md

Benefits

  • Automatic enforcement via ESLint - hard to forget dry-run checks
  • Consistent [dry-run] Would execute: ... log formatting
  • Reduced boilerplate in commands and targets
  • Self-documenting error messages guide developers to correct APIs

Replaces scattered isDryRun() checks with a centralized abstraction layer
that automatically intercepts destructive operations:

- Add src/utils/dryRun.ts with Proxy wrappers for SimpleGit, Octokit, and fs
- Update getGitClient()/createGitClient() to return dry-run-aware git clients
- Update getGitHubClient() to return dry-run-aware Octokit instance
- Add dryRunFs for file write operations (writeFile, unlink, mkdir, rename)
- Add dryRunExec() helper for custom destructive operations
- Migrate commands and targets to use wrapped APIs
- Add ESLint rules to enforce using dry-run wrapped APIs
- Add comprehensive tests for proxy behavior
- Document the pattern in AGENTS.md
@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2025

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (registry) Auto-create package structure for new packages by BYK in #689

Bug Fixes 🐛

Changelog

  • Deduplicate merged PR entries in preview by BYK in #690
  • Disable author mentions in PR preview comments by BYK in #684

Other

  • (github) Clean up orphaned draft releases on publish failure by BYK in #681
  • (publish) Fail early on dirty git repository by BYK in #683

Build / dependencies / internal 🔧

  • Centralize dry-run logic with Proxy-based abstraction by BYK in #685

🤖 This preview updates automatically when you update the PR.

@BYK BYK changed the title refactor: Centralize dry-run logic with Proxy-based abstraction ref: Centralize dry-run logic with Proxy-based abstraction Dec 29, 2025
- Remove repetitive dry-run proxy comments
- Remove isDryRun() checks from brew.ts, awsLambdaLayer.ts, github.ts
  (use proxied APIs instead)
- Allow clone() through dry-run proxy (safe local operation)
- Remove eslint-disable comments for clone operations
- Update Octokit proxy to return mock status for status-based checks
BYK added 3 commits December 29, 2025 22:11
- Add cloneRepo() helper for cleaner clone+createGitClient pattern
- Rename dryRunFs to safeFs, dryRunExec to safeExec
- Remove remaining isDryRun() checks from github.ts using safeExec
- Remove repetitive dry-run proxy comments from registry.ts and ghPages.ts
- Update AGENTS.md with new naming
- Fix GCS download to return null in dry-run mode (instead of invalid path)
- Use explicit isDryRun() check in createDraftRelease for mock data
- Cache wrapped git instances in proxy to avoid recreation on chaining
- Add copyFile/copyFileSync to safeFs
- Fix import ordering in prepare.ts
- Add tests for chained git operations and proxy caching
@BYK BYK marked this pull request as ready for review December 31, 2025 12:58
…mode

In dry-run mode, git methods like commit() now return proper mock result
objects instead of the proxy itself. This fixes issues where code expects
to access properties like commitResult.commit to get the commit hash.
@BYK BYK enabled auto-merge (squash) December 31, 2025 13:37
@BYK BYK disabled auto-merge December 31, 2025 13:50
Remove pull and push from GIT_MOCK_RESULTS because they are used in
method chains like git.pull().merge().push() in publish.ts. Returning
a mock object instead of the proxy breaks these chains.

Only commit needs a mock result because upm.ts accesses commitResult.commit.
@BYK BYK requested a review from MathurAditya724 December 31, 2025 13:57
Refactor safeFs to use the same Proxy pattern as Git and Octokit
for consistency. This also exports safeFsPromises and safeFsSync
for direct access to the full proxied fs modules.
Return proxy directly instead of Promise.resolve(proxy) to support
method chaining like git.pull().merge().push(). The proxy wraps
SimpleGit which is thenable, so await still works correctly.

Only methods in GIT_MOCK_RESULTS (like commit) return a Promise
with mock data since their return values are actually accessed.
@BYK BYK merged commit d01268a into master Dec 31, 2025
14 checks passed
@BYK BYK deleted the byk/refactor/dry-run-abstraction branch December 31, 2025 14:13
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.

3 participants