Skip to content

Commit 2eded67

Browse files
Copilotpelikhan
andauthored
Sync permission error hints and add schema validation regression tests
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 189f462 commit 2eded67

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

pkg/parser/schema_errors.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ func findFrontmatterBounds(lines []string) (startIdx int, endIdx int, frontmatte
312312
var knownFieldValidValues = map[string]string{
313313
// Both entries mirror $defs/github_actions_permissions in main_workflow_schema.json.
314314
// Update both when the schema changes.
315-
"/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
316-
"/on/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
315+
"/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-custom-org-roles, organization-custom-repository-roles, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
316+
"/on/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-custom-org-roles, organization-custom-repository-roles, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
317317
}
318318

319319
// knownFieldScopes maps well-known JSON schema paths to a slice of valid scope names.
@@ -325,12 +325,14 @@ var knownFieldScopes = map[string][]string{
325325
"/permissions": {
326326
"actions", "all", "attestations", "checks", "code-quality", "copilot-requests", "contents", "deployments",
327327
"discussions", "id-token", "issues", "metadata", "models",
328+
"organization-custom-org-roles", "organization-custom-repository-roles",
328329
"organization-projects", "packages", "pages", "pull-requests",
329330
"repository-projects", "security-events", "statuses", "vulnerability-alerts",
330331
},
331332
"/on/permissions": {
332333
"actions", "all", "attestations", "checks", "code-quality", "copilot-requests", "contents", "deployments",
333334
"discussions", "id-token", "issues", "metadata", "models",
335+
"organization-custom-org-roles", "organization-custom-repository-roles",
334336
"organization-projects", "packages", "pages", "pull-requests",
335337
"repository-projects", "security-events", "statuses", "vulnerability-alerts",
336338
},

pkg/workflow/permissions_schema_consistency_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"testing"
99

10+
"github.com/github/gh-aw/pkg/parser"
1011
"github.com/stretchr/testify/require"
1112
)
1213

@@ -125,3 +126,35 @@ func TestPermissionsSchemaEnumMatchesConstants(t *testing.T) {
125126
}
126127
}
127128
}
129+
130+
// TestOrganizationCustomRolePermissionsValidateAgainstSchema is a regression test that
131+
// ensures workflow frontmatter using the organization-custom-org-roles and
132+
// organization-custom-repository-roles permission scopes validates cleanly against the
133+
// JSON Schema, and that invalid values for these scopes are still rejected.
134+
func TestOrganizationCustomRolePermissionsValidateAgainstSchema(t *testing.T) {
135+
for _, scope := range []string{"organization-custom-org-roles", "organization-custom-repository-roles"} {
136+
t.Run(scope+"/valid", func(t *testing.T) {
137+
frontmatter := map[string]any{
138+
"on": "workflow_dispatch",
139+
"permissions": map[string]any{
140+
scope: "read",
141+
},
142+
}
143+
if err := parser.ValidateMainWorkflowFrontmatterWithSchemaAndLocation(frontmatter, "workflow.md"); err != nil {
144+
t.Fatalf("expected %q permission scope to validate cleanly, got error: %v", scope, err)
145+
}
146+
})
147+
148+
t.Run(scope+"/invalid-value", func(t *testing.T) {
149+
frontmatter := map[string]any{
150+
"on": "workflow_dispatch",
151+
"permissions": map[string]any{
152+
scope: "not-a-real-value",
153+
},
154+
}
155+
if err := parser.ValidateMainWorkflowFrontmatterWithSchemaAndLocation(frontmatter, "workflow.md"); err == nil {
156+
t.Fatalf("expected invalid value for %q permission scope to be rejected", scope)
157+
}
158+
})
159+
}
160+
}

0 commit comments

Comments
 (0)