Skip to content

add support for group merging#35

Open
melipass wants to merge 8 commits intotailscale-dev:mainfrom
melipass:main
Open

add support for group merging#35
melipass wants to merge 8 commits intotailscale-dev:mainfrom
melipass:main

Conversation

@melipass
Copy link
Copy Markdown

Previously, when the same group name was defined in multiple child files, each definition was added separately, causing duplicate key errors (#34).

duplicate name "group:group-name" in object (lines X:Y and Z:Y)

This change:

  • Merges group members when the same group name appears in multiple files
  • Deduplicates members during merge
  • Tracks all source files in comments (from/and format)
  • Sorts object members by source so same-source items appear together
  • Dedupes consecutive identical comments to reduce noise

Groups and other ACL sections handled with handleObject() that are defined across multiple files now combine into a single definition. Following the example from #34 :

{
    "groups": {
        // from `companies/company-1/groups.hujson`
        // and `companies/company-2/groups.hujson`
        "group:group-name": [
            "member-1@company.com",
            "member-2@company.com",
            "member-3@company.com",
            "member-4@company.com",
        ]
    }
}

Tested this in my org and works as expected.

Previously, when the same group name was defined in multiple child files,
each definition was added separately, causing duplicate key errors.

This change:
- Merges group members when the same group name appears in multiple files
- Deduplicates members during merge
- Tracks all source files in comments (from/and format)
- Sorts groups by source so same-source groups appear together
- Dedupes consecutive identical comments to reduce noise

Fixes duplicate group names causing parse errors
Previously, when the same group name was defined in multiple child files,
each definition was added separately, causing duplicate key errors.

This change:
- Merges group members when the same group name appears in multiple files
- Deduplicates members during merge
- Tracks all source files in comments (from/and format)
- Sorts groups by source so same-source groups appear together
- Dedupes consecutive identical comments to reduce noise

Fixes duplicate group names causing parse errors
Copy link
Copy Markdown

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 support for merging duplicate object keys (notably groups) across multiple child ACL files to avoid duplicate-key errors and to produce a single combined definition with deduplicated members and consolidated source comments.

Changes:

  • Update handleObject() to merge array-valued members when the same key appears multiple times, deduplicating merged array entries.
  • Add post-merge formatting utilities to sort object members by source comments and dedupe consecutive identical comments.
  • Add tests covering group merging and array deduplication behavior.

Reviewed changes

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

File Description
main.go Implements array-merge + dedup for duplicate object keys; adds comment merge, source-based sorting, and comment dedupe utilities.
main_test.go Adds tests for group merging across files/children and for mergeArraysWithDedup.

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

Comment thread main.go
Comment thread main.go
Comment thread main_test.go
@clstokes clstokes self-assigned this Feb 10, 2026
When merging duplicate keys in nested objects (e.g., autoApprovers.routes),
the existing member may have no `from` comment. Now initializes with
`from parentPath` before appending `and childPath`, and avoids adding
duplicate paths.
When merging arrays with mergeArraysWithDedup, the new array lost any
comments attached to the original array node. Now copies Before, Line,
and End comments from the existing array to the merged result.

Example of preserved comments:

"group:name": [ // This comment is now preserved
    "user@example.com"
] // This comment is now preserved too
Replace ignored errors from jwcc.Parse with explicit error assertions to prevent nil dereferences if input becomes invalid.
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.

3 participants