fix(cli): ag init --force replaces existing admin key instead of crashing (#3351)#3384
Merged
Merged
Conversation
…hing (#3351) - Delete existing 'ag-init-admin' key before creating new one when --force - Auto-overwrite config file when --yes --force (skip interactive prompt) - Set createAdminToken=true when force=true even if existing token found - Regression test: verifies new token differs from old after --force
Contributor
There was a problem hiding this comment.
✅ Approved.
Three-part fix for ag init --force crash:
createAdminToken = !existingToken || force— force always recreates token.if (!yes || !force)guard — skips overwrite prompt when both flags set.- Revoke existing
ag-init-adminkey before creating new one when --force.
Test verifies: first init creates token, second init with --force creates a different token (no crash, no DUPLICATE_KEY_NAME).
CI green. All merge gates pass. Merging.
Minor style note (non-blocking): The closing brace for the new if (!yes || !force) block uses 2-space indent instead of the surrounding 4-space. Functionally correct but inconsistent with file style. Consider a cleanup pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for #3351
Problem
ag init --forcecrashes withDUPLICATE_KEY_NAMEwhen an admin key from a previous init already exists.Root Cause
Two issues:
createKey("ag-init-admin", ...)always uses the same name — no cleanup of the old key--yes --forcestill prompts "Overwrite config?" because the prompter block ran even when force=truecreateAdminTokenwasfalsewhen existing token found, even with--forceFix
--force, delete existingag-init-adminkey before creating new one--yes --forcecreateAdminToken = !existingToken || forceVerification
tsc --noEmit: ✅ Zero errorsnpm run build: ✅ Successvitest run src/__tests__/cli-init.test.ts: ✅ 9/9 passed (including new regression test)Also Fixes
#3355 (same root cause — DUPLICATE_KEY_NAME with --force)