elastic / elastic/harp

remove skips or crashes when matching multiple packages

Open
#464 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
153
Forks
21
PR merge metrics
No merged PRs in 30d

Description

When a `BundlePatch` matches multiple packages via a selector, `harp` either does not behave as expected or crashes.

## skip

```sh
# 1. Build a 4-package bundle (sorted: aaa < bbb < ccc < zzz)
cat > input.json <<'EOF'
{
"app/aaa": {"k": "v1"},
"app/bbb": {"k": "v2"},
"app/ccc": {"k": "v3"},
"app/zzz": {"k": "v4"}
}
EOF
harp from jsonmap --in input.json > in.bundle

# 2. Patch spec: remove aaa and bbb (adjacent in sorted order)
cat > patch.yaml <<'EOF'
apiVersion: harp.elastic.co/v1
kind: BundlePatch
meta:
name: remove-adjacent
spec:
rules:
- selector:
matchPath:
regex: "^app/(aaa|bbb)$"
package:
remove: true
EOF

# 3. Apply and observe
harp bundle patch --in in.bundle --spec patch.yaml > out.bundle
harp bundle dump --in out.bundle --path-only
```

**Actual behavior behavior**
app/bbb ← silently survived
app/ccc
app/zzz

**Expected behavior**
app/ccc
app/zzz

## crach

```sh
# Using the same 3-package bundle where all packages match:
cat > in3.json <<'EOF'
{"app/one": {"k": "v1"}, "app/three": {"k": "v3"}, "app/two": {"k": "v2"}}
EOF
harp from jsonmap --in in3.json > in3.bundle

cat > remove-all.yaml <<'EOF'
apiVersion: harp.elastic.co/v1
kind: BundlePatch
meta:
name: remove-all
spec:
rules:
- selector:
matchPath:
regex: ".*"
package:
remove: true
EOF

harp bundle patch --in in3.bundle --spec remove-all.yaml > out3.bundle
```

Image

---

Version:
`0.2.12 [main:2025-04-30T22:12:09Z] (Go: go1.23.8 linux/amd64, Flags: defaults, Date: 2025-04-30T22:28:01Z)`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing both cases with the provided `harp from jsonmap`, `harp bundle patch`, and `harp bundle dump` commands and the adjacent-match and match-all YAML specs. Trace bundle patch handling for selectors matching multiple packages; done means every matching package is removed without being skipped, and removing all packages no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.