Skip to content

Added clean API for creating anonymous sections - #26

Closed
nikitagricanuk wants to merge 5 commits into
digineo:v2from
nikitagricanuk:v2
Closed

Added clean API for creating anonymous sections#26
nikitagricanuk wants to merge 5 commits into
digineo:v2from
nikitagricanuk:v2

Conversation

@nikitagricanuk

Copy link
Copy Markdown
Contributor

I've noticed that the library lacked clean API for creating anonymous sections in uci. The only way to create such section is to set section name to empty string, but this behaviour isn't documented and hasn't been tested. I've added new AddAnonymousSection function that does this and added some tests for it.

nikitagricanuk and others added 4 commits May 24, 2026 14:14
emitString used `>` instead of `>=`, so a pair of adjacent quotes (`''`
or `""`) produced no token. The parser then expected a value but received
the next `option` keyword, crashing with "expected option value, got
(Option ...)".

Add lexer and parser test cases for empty-string options to pin the
behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@corny
corny force-pushed the v2 branch 7 times, most recently from 2d4bc6d to 4e8670c Compare May 29, 2026 08:39
…elector

Previously, Del() only searched sections by their Name field, which is
empty for anonymous sections. Passing "@type[index]" was silently ignored,
so DelSection() would mark the config tainted and commit a no-op write.

Fix: resolve the selector via getUnnamed() for "@"-prefixed names, then
remove the section by pointer identity rather than by Name string.

Add comprehensive unit tests for all deletion cases:
- named section deletion (regression)
- anonymous section deletion by index
- index shift after removal
- negative index (-1 = last)
- sole anonymous section
- mixed named+anonymous configs
- no-op on out-of-bounds or non-existent names
- full round-trip via the Tree API (GetSections → DelSection → Commit)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.84848% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.89%. Comparing base (60c1481) to head (8cce456).
⚠️ Report is 1 commits behind head on v2.

Files with missing lines Patch % Lines
uci.go 76.19% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v2      #26      +/-   ##
==========================================
+ Coverage   89.02%   89.89%   +0.87%     
==========================================
  Files           7        7              
  Lines         674      831     +157     
==========================================
+ Hits          600      747     +147     
- Misses         65       73       +8     
- Partials        9       11       +2     

☔ View full report in Codecov by Harness.
📢 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.

@corny corny closed this in efdff98 Jun 6, 2026
adonespitogo pushed a commit to flarewifi/go-uci that referenced this pull request Jul 24, 2026
config.Del (backing tree.DelSection) matched a section to remove by its
literal Name field, which is empty for an anonymous section ("config
device" with no name) — never equal to the synthetic "@type[idx]" selector
GetSections/findVlanDeviceSections-style callers pass back for such a
section. DelSection("@device[3]") therefore silently matched nothing, yet
the config was still marked tainted, so a following Commit() reported
success while leaving the section untouched on disk.

Ported from upstream digineo/go-uci commit efdff98
("Added clean API for creating anonymous sections", closes digineo#26),
which fixes this same bug but only on the v2 branch (unreleased, and
carrying an unrelated breaking Tree-interface signature change). This
cherry-picks just the Del fix onto our fork of the older, still
bool-returning API flare-server currently depends on, so it's a drop-in
replacement.

Also renames the module to github.com/flarewifi/go-uci now that this fork
is the org's own dependency going forward.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

2 participants