WatchConfig.UpsertEntry silently deletes existing contexts when re-upserting a watched file
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
该缺陷位于 pkg/config/localconfig.go 中的 UpsertEntry,现有的 context 切片被单个 context 的条目覆盖。请先阅读该函数和 issue 中的复现步骤,然后在 pkg/config 中添加一个测试:在已存在 context 的情况下对条目执行 upsert,并检查之前的所有 context 都被保留。当合并后的 context 列表保留所有 context 且没有重复,并且空的 entry.Context 不再导致 panic 时,即为完成。
由索引模型根据 Issue 内容生成。
描述
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!
- 主要语言
- Go
- 星标
- 59
- 派生
- 74
- 平均合并
- 4 天 5 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microcks/microcks-cli 的其他 Issue
-
Malformed local configuration is silently accepted and can be overwritten可能已有人在做 @aniket866 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
microcks/microcks-cli#615 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
microcks/microcks-cli#608 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
microcks/microcks-cli#606 ·
维护者通常 1 天内回复
-
Windows test failures in MockFileSystem.Walk due to path separator可能已有人在做 @dipak0000812 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
microcks/microcks-cli#601 · 1 条评论 ·
维护者通常 1 天内回复
-
Bug: `testEndpoint` URL Scheme Not Validated可能已有人在做 @aniket866 于 1 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
microcks/microcks-cli#598 · 2 条评论 ·
维护者通常 1 天内回复
查看 microcks/microcks-cli 的全部 Issue
相似的 Issue
-
date_time, url_encode, html_escape, to_unix_time, contains_all and contains_any panic when called without arguments可能已有人在做 @antcybersec 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
projectdiscovery/dsl#372 ·
维护者通常 1 天内回复
-
blocked-needs-validation
难度 2/5 1-3 小时 新手友好度 62/100
projectcapsule/capsule#2265 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
JuliusBrussee/caveman#1449 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
bot-found bug priority: P3
难度 2/5 1-3 小时 新手友好度 72/100
madenvel/KalinkaPlayer#498 ·