Skip to content

fix(variables): add noop mode support#926

Open
klutchell wants to merge 2 commits intogithub:main-enterprisefrom
product-os:balena/noop-vars
Open

fix(variables): add noop mode support#926
klutchell wants to merge 2 commits intogithub:main-enterprisefrom
product-os:balena/noop-vars

Conversation

@klutchell
Copy link
Contributor

@klutchell klutchell commented Feb 2, 2026

Fixes: #925

  • Add noop mode support to Variables plugin add/remove/update methods
  • Return NopCommand instead of making API calls when nop=true
  • Add comprehensive tests for noop mode behavior

Refactor Variables plugin to match the single-item Diffable contract
used by labels, milestones, and other plugins. The previous update()
reimplemented sync() logic internally; now each method handles one item
and lets Diffable.sync() orchestrate iteration.

  • Simplify update() from 90-line array-diffing to single-item PATCH
  • Simplify changed() from JSON.stringify comparison to value check
  • Remove getChanged(), lodash dependency, .then(res=>res) no-ops
  • Match labels.js nop return pattern: Promise.resolve([NopCommand])
  • Fix inconsistent toUpperCase() between add/remove/update
  • Let errors propagate to Diffable.sync() instead of swallowing
  • Normalize find() to strip API metadata fields (created_at, etc.)

Copilot AI review requested due to automatic review settings February 2, 2026 15:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds proper noop (dry-run) behavior to the variables plugin so repository variables are not mutated when nop: true, addressing safe-settings issue #925.

Changes:

  • Added NopCommand-based noop handling to Variables.add(), Variables.remove(), and Variables.update() to avoid mutating API calls in dry-run mode.
  • Expanded unit tests to cover noop behavior for add/remove/update and adjusted test setup to pass nop into the plugin.

Reviewed changes

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

File Description
lib/plugins/variables.js Adds noop checks and returns NopCommand(s) instead of performing POST/PATCH/DELETE when nop is enabled.
test/unit/lib/plugins/variables.test.js Adds unit tests validating noop behavior for variables operations and updates test harness to pass nop.

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

@klutchell klutchell force-pushed the balena/noop-vars branch 2 times, most recently from 0d2cc5e to 723c3be Compare February 2, 2026 17:54
@klutchell klutchell requested a review from Copilot February 2, 2026 17:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


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

@klutchell
Copy link
Contributor Author

@decyjphr this one should be good to go!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comments suppressed due to low confidence (1)

lib/plugins/variables.js:178

  • In noop mode, update() currently returns nopCommands.length === 1 ? nopCommands[0] : nopCommands, which means it can return [] when changed is true but no concrete operations are generated. That bubbles up through Diffable.sync() and can produce non-NopCommand items in the returned results array. Consider returning undefined/null when nopCommands.length === 0 (or ensuring changed is only true when an operation will be emitted).
      if (this.nop) {
        return nopCommands.length === 1 ? nopCommands[0] : nopCommands
      }

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

You can also share your feedback on Copilot code review. Take the survey.

@decyjphr decyjphr closed this Mar 23, 2026
@decyjphr decyjphr reopened this Mar 23, 2026
klutchell and others added 2 commits March 24, 2026 11:45
- Add noop mode support to Variables plugin add/remove/update methods
- Return NopCommand instead of making API calls when nop=true
- Add comprehensive tests for noop mode behavior

Signed-off-by: Kyle Harding <kyle@balena.io>
Refactor Variables plugin to match the single-item Diffable contract
used by labels, milestones, and other plugins. The previous update()
reimplemented sync() logic internally; now each method handles one item
and lets Diffable.sync() orchestrate iteration.

- Simplify update() from 90-line array-diffing to single-item PATCH
- Simplify changed() from JSON.stringify comparison to value check
- Remove getChanged(), lodash dependency, .then(res=>res) no-ops
- Match labels.js nop return pattern: Promise.resolve([NopCommand])
- Fix inconsistent toUpperCase() between add/remove/update
- Let errors propagate to Diffable.sync() instead of swallowing
- Normalize find() to strip API metadata fields (created_at, etc.)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Kyle Harding <kyle@balena.io>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


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

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.

The variables plugin does NOT implement noop support

3 participants