Skip to content

Commit 71b1bc1

Browse files
fix: validate catalog kind overrides (#97)
Co-authored-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> Co-authored-by: Kunal Lanjewar <kunallanjewar@gmail.com>
1 parent 8da72bd commit 71b1bc1

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ it reaches 1.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Reject invalid `lore catalog --kind` overrides before importing entries.
13+
1014
### Documentation
1115

1216
- Document the `Stacked on: #N` PR body convention for non-main-based PRs (CONTRIBUTING.md, PR template).

docs/generated/cli.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,16 +730,22 @@ client's official CLI so you keep full control.
730730
Flags:
731731
--run shell out to each detected client's CLI (prompts per command)
732732
--run --yes shell out without prompting
733+
--update re-register clients whose configured path differs from the
734+
running binary (#61)
735+
--force re-register every detected client unconditionally; implies
736+
--update
733737
--print-config print only the JSON snippet for manual paste (no detection)
734738
--skill (not yet implemented) install Claude Code skill
735739

736740
**Flags**
737741

738742
| flag | type | default | description |
739743
| --- | --- | --- | --- |
744+
| `--force` | bool | `false` | re-register every detected client unconditionally (implies --update) |
740745
| `--print-config` | bool | `false` | print JSON snippet for manual paste (no detection output) |
741746
| `--run` | bool | `false` | shell out to each detected client's CLI (prompts per command) |
742747
| `--skill` | bool | `false` | install Claude Code skill (not yet implemented) |
748+
| `--update` | bool | `false` | re-register clients whose configured path differs from the running binary |
743749
| `--yes` | bool | `false` | skip per-command confirmation prompts (combine with --run) |
744750

745751
## `guild mcp serve`

internal/lore/catalog.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func Catalog(ctx context.Context, db *sql.DB, p *CatalogParams) (*CatalogResult,
6262
if strings.TrimSpace(p.Dir) == "" {
6363
return nil, fmt.Errorf("lore: catalog: dir required")
6464
}
65+
if p.Kind != "" && !isValidKind(p.Kind) {
66+
return nil, fmt.Errorf("%w: %q (valid: idea, research, decision, observation, principle)",
67+
ErrInvalidKind, string(p.Kind))
68+
}
6569

6670
info, err := os.Stat(p.Dir)
6771
if err != nil {

internal/lore/catalog_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package lore
22

33
import (
44
"context"
5+
"errors"
56
"os"
67
"path/filepath"
8+
"strings"
79
"testing"
810
)
911

@@ -146,6 +148,38 @@ func TestCatalog_KindInference(t *testing.T) {
146148
}
147149
}
148150

151+
func TestCatalog_InvalidKindOverride(t *testing.T) {
152+
ctx := context.Background()
153+
db := openTestDB(t, "catalog-bad-kind")
154+
155+
dir := t.TempDir()
156+
if err := os.WriteFile(filepath.Join(dir, "note.md"), []byte("# Note\n\nSome content here."), 0o600); err != nil {
157+
t.Fatalf("write note.md: %v", err)
158+
}
159+
160+
_, err := Catalog(ctx, db, &CatalogParams{
161+
Dir: dir,
162+
ProjectID: "catalog-bad-kind",
163+
Kind: Kind("not-a-real-kind"),
164+
})
165+
if !errors.Is(err, ErrInvalidKind) {
166+
t.Fatalf("Catalog error = %v; want ErrInvalidKind", err)
167+
}
168+
if !strings.Contains(err.Error(), "valid: idea, research, decision, observation, principle") {
169+
t.Fatalf("Catalog error = %q; want valid kind list", err.Error())
170+
}
171+
172+
var count int
173+
if err := db.QueryRowContext(ctx,
174+
`SELECT COUNT(*) FROM entries WHERE project_id = 'catalog-bad-kind'`,
175+
).Scan(&count); err != nil {
176+
t.Fatalf("count entries: %v", err)
177+
}
178+
if count != 0 {
179+
t.Errorf("entries in DB = %d; want 0", count)
180+
}
181+
}
182+
149183
func TestCatalog_SkipsNonMD(t *testing.T) {
150184
ctx := context.Background()
151185
db := openTestDB(t, "catalog-ext")

0 commit comments

Comments
 (0)