WatchConfig.UpsertEntry silently deletes existing contexts when re-upserting a watched file
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
El error está en UpsertEntry en pkg/config/localconfig.go, donde el slice de contextos existente se sobrescribe con la entrada de un solo contexto. Empieza leyendo esa función y el reproductor del issue, y luego añade en pkg/config un test que haga upsert de una entrada con un contexto ya presente y compruebe que todos los contextos anteriores se conservan. Está terminado cuando la lista de contextos fusionada conserva cada contexto sin duplicados y un entry.Context vacío ya no provoca un panic.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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!
- Lenguaje dominante
- Go
- Estrellas
- 59
- Forks
- 74
- Merge medio
- 4 d 5 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microcks/microcks-cli
-
Malformed local configuration is silently accepted and can be overwrittenPosiblemente ocupada @aniket866 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
microcks/microcks-cli#615 ·
Los mantenedores suelen responder en 1 día
-
bug: microcks test get swallows test failure details and operation results in text output modeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
microcks/microcks-cli#608 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
microcks/microcks-cli#606 ·
Los mantenedores suelen responder en 1 día
-
Windows test failures in MockFileSystem.Walk due to path separatorPosiblemente ocupada @dipak0000812 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microcks/microcks-cli#601 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Bug: `testEndpoint` URL Scheme Not ValidatedPosiblemente ocupada @aniket866 la tomó hace 3 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
microcks/microcks-cli#598 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de microcks/microcks-cli
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
riverqueue/river#1576 ·
Los mantenedores suelen responder en 1 día
-
NFS StorageProvider renders a missing nfsSubDir as "<no value>"Posiblemente ocupada @ldming la tomó hoy. Abiertokind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
apecloud/kubeblocks#11067 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
emersion/go-msgauth#87 ·
-
CLI: `describe <ns>.<table>` reports "namespace does not exist" when only the table is missingPosiblemente ocupada @Shruthirdy la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
apache/iceberg-go#2423 ·
Los mantenedores suelen responder en 2 días
-
Add tests for CSV email parsingAbiertogood first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
mafzalkalwardev/mailforge#21 ·