Skip to content

fix(resource): improve YAML mapping-error suggestion for nested permissions (#12) - #17

Merged
hk9890 merged 1 commit into
dynatrace-oss:mainfrom
knQzx:fix/issue-12-yaml-suggestion
Jul 13, 2026
Merged

hk9890 merged 1 commit into
dynatrace-oss:mainfrom
knQzx:fix/issue-12-yaml-suggestion

Conversation

@knQzx

@knQzx knQzx commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary

When an agent's frontmatter contains a granular permission block on a single line, like the example from #12

permissions:
  bash: "*": ask
  edit: "*": ask

the YAML parser fails with mapping values are not allowed in this context, the agent is dropped during discovery, and aimgr repo sync removes it from the repo. The auto-generated suggestion in pkg/resource.SuggestFix only mentioned quoting the description field, so users hit a colon-related YAML error and get advice about a field they didn't touch - the failure feels silent

Change

  • rewrite the suggestion in pkg/resource.SuggestFix so it covers both common causes of mapping values are not allowed: an unquoted : inside a scalar value, and a nested mapping written on the same line as its parent key
  • include a corrected permissions: example so the fix is directly applicable

After the change discovery output looks like:

⚠ Discovery Issues for source 'broken-source' (1):

  ✗ agents/broken-agent.md
    Error: agent 'broken-agent' field 'frontmatter' in /...: failed to parse frontmatter YAML: yaml: line 3: mapping values are not allowed in this context
    → Suggestion: YAML mapping error: an unquoted ':' inside a scalar value, or a nested mapping written on the same line as its parent key.
  Fixes:
    - Quote values containing ':' (e.g., description: "My tool: a helper")
    - Put nested mappings on their own indented lines, e.g.:
        permissions:
          bash:
            "*": ask

Test plan

  • updated existing TestSuggestFix case to assert the new wording, plus a new case that asserts the nested-mapping fix is mentioned
  • new integration test TestRunSync_DiscoveryIssueSuggestionMentionsNestedMapping runs the full sync flow against the existing malformed-agent fixture and asserts the suggestion text reaches stdout
  • TestRunSync_TableOutputPrintsDiscoveryIssuesForMalformedResources, TestRunSync_JSONOutputIncludesDiscoveryIssues, TestInstallFromManifest_BootstrapPrintsDiscoveryIssuesForMalformedResources still pass (the install golden-file normalizer only keeps lines containing mapping values are not allowed in this context, so the new suggestion lines don't affect it)
go build ./...
go vet ./...
go test -short ./pkg/resource/ ./cmd/
go test -tags=integration -run "TestRunSync_Discovery|TestInstallFromManifest_BootstrapPrints" ./cmd/

Fixes #12

When an agent's frontmatter contains a granular permission block on a
single line (e.g. `bash: "*": ask`), the YAML parser fails with
"mapping values are not allowed in this context" and aimgr repo sync
silently skips the agent. The auto-generated suggestion only mentioned
quoting the description field, so users had no clue what to fix

Rewrite the suggestion to cover both common causes - an unquoted ':'
inside a scalar value, and a nested mapping written on the same line
as its parent key - and include a corrected `permissions:` example
so the fix is directly applicable

Fixes dynatrace-oss#12
@dynatrace-cla-bot

dynatrace-cla-bot commented Apr 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@knQzx

knQzx commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@hk9890 first PR in this repo - looks like CI needs maintainer approval to run. could you kick it off when you have a moment? no rush. thanks

@hk9890
hk9890 merged commit 1238cdf into dynatrace-oss:main Jul 13, 2026
1 check passed
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.

Agent sync issue with permission block containing more granular permissions

3 participants