WatchConfig.UpsertEntry silently deletes existing contexts when re-upserting a watched file
Maintainer antworten meist innerhalb von 3 Tagen
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 82/100
Rechercherichtung
Der Fehler liegt in UpsertEntry in pkg/config/localconfig.go, wo die vorhandene Context-Liste durch den Einzel-Context-Eintrag überschrieben wird. Lies zuerst diese Funktion und den Reproducer im Issue, und füge dann in pkg/config einen Test hinzu, der einen Eintrag upserted, während bereits ein Context vorhanden ist, und prüft, dass alle bisherigen Contexts erhalten bleiben. Fertig ist es, wenn die zusammengeführte Context-Liste jeden Context ohne Duplikate behält und ein leeres entry.Context nicht mehr zu einem Panic führt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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!
- Vorherrschende Sprache
- Go
- Sterne
- 59
- Forks
- 75
- Ø Merge
- 7 T. 12 Std.
- Gemergte PRs (30 T.)
- 20
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microcks/microcks-cli
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
microcks/microcks-cli#623 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Logging into a locally started instance clears its container reference, causing stop to do nothingOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
microcks/microcks-cli#620 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
bug: microcks test get swallows test failure details and operation results in text output modeEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
microcks/microcks-cli#608 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 3 Tagen
-
KeycloakClient strips realm path when realm URL lacks trailing slashEvtl. vergeben @aryarathoree hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
microcks/microcks-cli#606 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Windows test failures in MockFileSystem.Walk due to path separatorEvtl. vergeben @dipak0000812 hat das vor 7 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
microcks/microcks-cli#601 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in microcks/microcks-cli
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
-
/shutdown/ready can fail to return an HTTP response when readiness takes longer than the server write timeoutEvtl. vergeben @floriankoch hat das heute übernommen. Offentriage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
envoyproxy/gateway#10562 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Adding an LDAP group reports every search failure as "LDAP Group DN is not found"Evtl. vergeben @Daksha1611 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100