fix(plugin): codexRemove drops header-only bili block with no trailing newline - #187
Merged
Merged
Conversation
…g newline
When the [mcp_servers.bili] table was header-only (no keys) and sat as the
final line with no trailing newline, after.indexOf('\n') was -1, so the
next-table search ran over a slice that still included the header itself and
matched it at index 0. end collapsed to start and the header line survived
the removal.
Compute firstNewline once and treat a missing newline as 'block runs to EOF'
so end = text.length. Adds a regression test covering the header-only,
no-trailing-newline case.
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.
Bug
codexRemove()insrc/plugin-install.tsleaves the[mcp_servers.bili]header line behind when the table is header-only (no keys) and sits as the final line with no trailing newline.Root cause:
When
after.indexOf("\n")is-1(no newline in the block),after.slice(0)still includes the header itself, so the next-table search matches the header at index0.endcollapses tostartand the header line survives the removal.Reproduced: a config ending in
...[mcp_servers.bili](no trailing\n) still containsmcp_servers.biliafterpluginRemove("codex").Fix
Compute
firstNewlineonce and treat a missing newline as "block runs to EOF":Notes
codexInstallalways writescommand/args/envkeys, so a header-only block only arises from manual editing, and it additionally requires a missing trailing newline. Fixing it anyway since the removal path should be total.tests/plugin-agent.test.tscovering the header-only, no-trailing-newline case. Verified the test fails on the old code (header survives) and passes with the fix.