Skip to content

S3UTILS-227: replace util.parseArgs with manual argv parsing#381

Merged
bert-e merged 2 commits intodevelopment/1.17from
bugfix/S3UTILS-227/compat
Apr 1, 2026
Merged

S3UTILS-227: replace util.parseArgs with manual argv parsing#381
bert-e merged 2 commits intodevelopment/1.17from
bugfix/S3UTILS-227/compat

Conversation

@nicolas2bert
Copy link
Copy Markdown
Contributor

@nicolas2bert nicolas2bert commented Mar 31, 2026

Design note:
fix-missing-replication-permissions.js is a standalone script meant to be copied into the vault container of older S3C versions. It does not run inside the s3utils container. It has to be compatible with the Node and npm packages available in the target vault container.

This "copy a self-contained script into an older container" approach is not easy to implement, test, or maintain, and is not a good practice in general.

We accepted this trade-off after discussing with Product and CS to allow fast integration on customer environments.

This tool should not be needed once we update replication permissions for all clients using CRR.

Problem:
fix-missing-replication-permissions.js uses util.parseArgs which requires Node 16.17+. The vault container ships Node 16.13.2 on all S3C versions up to 9.5.0.x, causing "parseArgs is not a function" at runtime.

Fix:
Replace util.parseArgs with manual process.argv parsing. No other dependency changes. There is no risk with other dependencies: vaultclient, aws-sdk v2, and process.argv all work on Node 16.13.2+.

Testing:
Existing functional tests in fixMissingReplicationPermissions.js run the script as a child process through its CLI interface (positionals, --iam-port, --https, --dry-run). Since the CLI contract is unchanged, passing tests confirm the new parsing logic is equivalent.

Problem:
fix-missing-replication-permissions.js uses util.parseArgs which requires
Node 16.17+. The vault container ships Node 16.13.2 on all S3C versions
up to 9.5.0.x, causing "parseArgs is not a function" at runtime.

Fix:
Replace util.parseArgs with manual process.argv parsing. No other
dependency changes. There is no risk with other dependencies: vaultclient,
aws-sdk v2, and process.argv all work on Node 16.13.2+.

Testing:
Existing functional tests in fixMissingReplicationPermissions.js run
the script as a child process through its CLI interface (positionals,
--iam-port, --https, --dry-run). Since the CLI contract is unchanged,
passing tests confirm the new parsing logic is equivalent.
@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 31, 2026

Hello nicolas2bert,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 31, 2026

Incorrect fix version

The Fix Version/s in issue S3UTILS-227 contains:

  • None

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 1.17.6

  • 1.18.0

Please check the Fix Version/s of S3UTILS-227, or the target
branch of this pull request.


for (let i = 0; i < args.length; i++) {
if (args[i] === '--iam-port') {
iamPort = parseInt(args[++i], 10);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If --iam-port is the last argument (no value follows), args[++i] is undefined and parseInt(undefined, 10) silently returns NaN. The original parseArgs would have thrown. Consider guarding against this with a bounds check before incrementing i.

— Claude Code

@claude
Copy link
Copy Markdown

claude bot commented Mar 31, 2026

  • --iam-port without a following value silently produces NaN instead of erroring (line 63). Add a bounds check before args[++i].

    Review by Claude Code

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 31, 2026

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

Add bounds check before consuming the next argument so that
passing --iam-port as the last argument throws instead of
silently setting the port to NaN.
@claude
Copy link
Copy Markdown

claude bot commented Mar 31, 2026

LGTM

Review by Claude Code

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.48%. Comparing base (556e440) to head (ec54481).
⚠️ Report is 2 commits behind head on development/1.17.

Files with missing lines Patch % Lines
...cationAudit/fix-missing-replication-permissions.js 0.00% 15 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           development/1.17     #381      +/-   ##
====================================================
- Coverage             43.57%   43.48%   -0.10%     
====================================================
  Files                    87       87              
  Lines                  6208     6221      +13     
  Branches               1299     1303       +4     
====================================================
  Hits                   2705     2705              
- Misses                 3456     3469      +13     
  Partials                 47       47              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

'dry-run': { type: 'boolean', default: false },
},
});
const args = process.argv.slice(2);
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.

My thoughts but consolidated using claude LLM:
The current implementation works, but the parsing logic is tightly coupled, order-dependent, and will become harder to maintain as flags grow.

A few specific concerns:

  • We’re manually mutating the loop index (i++) to consume values, which makes the control flow harder to reason about and easier to break when adding new flags.
  • Validation is inconsistent, parseInt is used without checking for NaN, which can lead to silent misconfiguration.
  • The if/else chain does not scale; every new flag increases cognitive load and duplication.
    Parsing, validation, and state mutation are all interleaved, making this difficult to test in isolation.

If we want to solve an already solved problem(see last paragraph), I’d recommend moving toward a table-driven approach where each flag maps to a handler. That separates concerns and makes the system extensible without modifying the core loop. At a minimum, a cas-switch-based structure with explicit validation would improve readability and safety.

More broadly, this is reimplementing CLI parsing logic that libraries like minimist or commander already handle robustly (including defaults, type coercion, aliases, and help text). If this script is expected to evolve beyond a couple of flags, introducing a lightweight dependency would reduce long-term complexity and edge cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This ephemeral script (will be deleted o nce we update replication permissions for all clients using CRR cf PR description) is meant to be copied into older vault containers where only a minimal set of dependencies exist.

Using minimist would introduce an additional dependency, and we would need to ensure it behaves consistently across different Vault versions.

for 3 flags, the manual approach is arguably fine. The commit message on HEAD (ec54481) even says "replace util.parseArgs with manual argv parsing" -> so this was a deliberate choice for compatibility.

@nicolas2bert
Copy link
Copy Markdown
Contributor Author

@bert-e approve

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Apr 1, 2026

Integration data created

I have created the integration data for the additional destination branches.

The following branches will NOT be impacted:

  • development/1.13
  • development/1.14
  • development/1.15
  • development/1.16
  • development/1.4
  • development/1.7

You can set option create_pull_requests if you need me to create
integration pull requests in addition to integration branches, with:

@bert-e create_pull_requests

The following options are set: approve

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Apr 1, 2026

I have successfully merged the changeset of this pull request
into targetted development branches:

  • ✔️ development/1.17

  • ✔️ development/1

The following branches have NOT changed:

  • development/1.13
  • development/1.14
  • development/1.15
  • development/1.16
  • development/1.4
  • development/1.7

Please check the status of the associated issue S3UTILS-227.

Goodbye nicolas2bert.

The following options are set: approve

@bert-e bert-e merged commit ec54481 into development/1.17 Apr 1, 2026
11 of 13 checks passed
@bert-e bert-e deleted the bugfix/S3UTILS-227/compat branch April 1, 2026 08:52
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.

4 participants