WatchConfig.UpsertEntry silently deletes existing contexts when re-upserting a watched file
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Lỗi nằm ở UpsertEntry trong pkg/config/localconfig.go, nơi danh sách context hiện có bị ghi đè bởi entry chỉ có một context. Hãy bắt đầu bằng cách đọc hàm đó và đoạn tái hiện lỗi trong issue, sau đó thêm trong pkg/config một test thực hiện upsert một entry khi đã có sẵn một context và kiểm tra rằng tất cả các context trước đó vẫn được giữ lại. Hoàn thành khi danh sách context sau khi gộp giữ được mọi context mà không trùng lặp, và entry.Context rỗng không còn gây panic nữa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When a file is being watched across multiple contexts (e.g. ["dev", "staging"]), re-running microcks import --watch <file> on an existing context—or calling WatchConfig.UpsertEntry with a context already present—silently deletes all other contexts associated with that file from .config/microcks/watch.
In pkg/config/localconfig.go:
func (w *WatchConfig) UpsertEntry(entry WatchEntry) {
for i, e := range w.Entries {
if e.FilePath == entry.FilePath {
contexts := w.Entries[i].Context
if !slices.Contains(contexts, entry.Context[0]) {
entry.Context = append(entry.Context, contexts...)
}
w.Entries[i] = entry
return
}
}
w.Entries = append(w.Entries, entry)
}
If entry.Context[0] is already in contexts, the if !slices.Contains(...) check evaluates to false and does nothing. Because entry.Context only contains the single context from the current invocation, w.Entries[i] = entry replaces the existing context slice with only entry.Context, wiping out all other contexts.
Additionally:
- If
entry.Contextis empty, accessingentry.Context[0]unconditionally panics with runtime error:index out of range [0] with length 0. - If
entry.Contextcontains multiple items, only index0is ever evaluated.
Expected behavior
WatchConfig.UpsertEntry should preserve all existing contexts for a file while adding any new context without duplicates. Re-importing or updating a watched file from one context must not delete other contexts that are monitoring the same file.
Actual behavior
When re-upserting a file with an already existing context, all other contexts previously attached to the entry are discarded, leaving only the single re-upserted context in the watch configuration.
How to Reproduce?
Reproducer
package main
import (
"fmt"
"github.com/microcks/microcks-cli/pkg/config"
)
func main() {
cfg := config.WatchConfig{
Entries: []config.WatchEntry{
{FilePath: "api.yaml", Context: []string{"dev"}},
},
}
// 1. Add "staging" -> Entry has ["staging", "dev"]
cfg.UpsertEntry(config.WatchEntry{FilePath: "api.yaml", Context: []string{"staging"}})
fmt.Printf("After adding staging: %v\n", cfg.Entries[0].Context)
// 2. Re-import / re-upsert from "staging"
cfg.UpsertEntry(config.WatchEntry{FilePath: "api.yaml", Context: []string{"staging"}, MainArtifact: true})
fmt.Printf("After re-upserting staging: %v\n", cfg.Entries[0].Context)
// Output: [staging] --> "dev" context was deleted!
}
Steps to Reproduce via CLI
- Register a file in watch mode across two contexts (
devandstaging). - Run
microcks import --watch <file>again while on thestagingcontext. - Check the watch configuration file:
<file>now only listsstaging, anddevhas been deleted.
Microcks version or git rev
master
Install method (docker-compose, helm chart, operator, docker-desktop extension,...)
No response
Additional information
I would be happy to submit a PR with unit test coverage if the team agrees!
- Ngôn ngữ chính
- Go
- Star
- 59
- Fork
- 74
- Merge trung bình
- 4 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 15
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microcks/microcks-cli
-
Malformed local configuration is silently accepted and can be overwrittenCó thể đã có người làm @aniket866 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microcks/microcks-cli#615 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: microcks test get swallows test failure details and operation results in text output modeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microcks/microcks-cli#608 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microcks/microcks-cli#606 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows test failures in MockFileSystem.Walk due to path separatorCó thể đã có người làm @dipak0000812 đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microcks/microcks-cli#601 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: `testEndpoint` URL Scheme Not ValidatedCó thể đã có người làm @aniket866 đã nhận 1 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microcks/microcks-cli#598 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microcks/microcks-cli
Issue tương tự
-
date_time, url_encode, html_escape, to_unix_time, contains_all and contains_any panic when called without argumentsCó thể đã có người làm @antcybersec đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
projectdiscovery/dsl#372 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blocked-needs-validation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
projectcapsule/capsule#2265 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
JuliusBrussee/caveman#1449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bot-found bug priority: P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
madenvel/KalinkaPlayer#498 ·