Add scope enum validation to cache-memory parser#19406
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enforces the existing cache-memory.scope enum at parse time so invalid scope values are rejected instead of silently behaving like the default "workflow" scope.
Changes:
- Add explicit scope validation in
parseCacheMemoryEntry()(only"workflow"and"repo"are accepted). - Add unit tests covering valid scopes (object/array forms), invalid scopes, and defaulting to
"workflow"when omitted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pkg/workflow/cache.go |
Validates cache-memory.scope against the allowed enum and returns a descriptive error on invalid values. |
pkg/workflow/cache_scope_validation_test.go |
Adds tests for scope validation across object/array tool syntaxes and for default scope behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Validate scope value | ||
| if !slices.Contains([]string{"workflow", "repo"}, entry.Scope) { | ||
| return entry, fmt.Errorf("invalid cache-memory scope %q: must be one of [workflow, repo]", entry.Scope) | ||
| } |
There was a problem hiding this comment.
The list of valid scopes is duplicated (once in the slices.Contains call and again in the error string). This can drift if a new scope is added. Define a validScopes slice once (optionally at package scope) and use it both for validation and for formatting the error message (e.g., %v), so there’s a single source of truth.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply comments |
… formatting Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
parseCacheMemoryEntry()inpkg/workflow/cache.gousingslices.Containspkg/workflow/cache_scope_validation_test.gousing testify assertionsvalidCacheMemoryScopesat package scope as single source of truth for validation and error messagesmake fmt lint buildpasses with 0 issuesOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.