Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ jobs:
with:
go-version: '1.26.8'
cache: true
- run: go vet ./...
- if: runner.os == 'Linux'
run: make lint
- if: runner.os != 'Linux'
run: go vet ./...
- name: Verify wildcard and loopback port conflicts
run: go test -v ./internal/deploy -run '^TestProbeNativePortRejectsListeningSockets$'
- run: go test -race ./...
Expand Down Expand Up @@ -134,7 +137,7 @@ jobs:
with:
go-version: '1.26.8'
cache: true
- run: make check cross-build
- run: make cross-build
- uses: actions/upload-artifact@v4
with:
name: lbctl-binaries
Expand Down
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Working on lbctl

- Discover the public contract with `lbctl <command> --help` and `lbctl schema --command '<command>'`.
- During edits, run the affected Go package or named test. For CLI flags, requests, output, or exit codes, use the existing tests under `internal/command` and `internal/integration`. Run `make lint` for formatting and vet checks, then `make check` for the full Go suite with race detection.
- For install, upgrade, rollback, or Core HTTP changes, build the candidate with `make build`. Reuse the relevant script in `scripts/` or run the affected command against the target Core. Check the exit code, structured output, and actual post-operation state. Use isolated test instances for writes and lifecycle changes.
- For endpoint normalization, run `go test ./internal/endpoint -run '^FuzzNormalizeIdempotent$'` to replay seeds. Use `go test ./internal/endpoint -fuzz '^FuzzNormalizeIdempotent$' -fuzztime 10s` to explore new inputs and retain any reproducing inputs.
- When an assertion may miss a specific regression, change one behavior in an isolated copy and run the same test against the original and changed code. Report the command, expected behavior, observed result, and verification still pending.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ COMMIT ?= $(shell git describe --always --dirty)
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS = -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)

.PHONY: build test check cross-build
.PHONY: build lint test check cross-build
build:
$(GO) build -trimpath -ldflags '$(LDFLAGS)' -o bin/lbctl ./cmd/lbctl

test:
$(GO) test -race ./...

check:
test -z "$$(gofmt -l cmd internal)"
lint:
@unformatted=$$(gofmt -l cmd internal) && \
{ test -z "$$unformatted" || { printf 'Run gofmt -w on:\n%s\n' "$$unformatted"; exit 1; }; }
$(GO) vet ./...
$(GO) test -race ./...

check: lint test

cross-build:
GO='$(GO)' VERSION='$(VERSION)' COMMIT='$(COMMIT)' BUILD_DATE='$(BUILD_DATE)' sh scripts/build.sh
20 changes: 15 additions & 5 deletions internal/deploy/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -126,8 +127,10 @@ func nativeFixture(t *testing.T) (string, Record) {
}

func TestNativeUpgradeRestoresVersionAndData(t *testing.T) {
for _, failure := range []string{"", "prepare", "health"} {
for _, failure := range []string{"", "prepare", "health", "canceled"} {
t.Run(failure, func(t *testing.T) {
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
dir, record := nativeFixture(t)
record.Autostart = new(false)
if err := (Store{Dir: dir}).Write(context.Background(), record); err != nil {
Expand All @@ -149,9 +152,9 @@ func TestNativeUpgradeRestoresVersionAndData(t *testing.T) {
}
return nil
},
stop: func(_ context.Context, _ string, record Record) error {
stop: func(ctx context.Context, _ string, record Record) error {
calls = append(calls, "stop:"+record.CoreVersion)
return nil
return ctx.Err()
},
start: func(_ context.Context, _ string, record Record) error {
if record.Autostart == nil || *record.Autostart {
Expand All @@ -163,14 +166,18 @@ func TestNativeUpgradeRestoresVersionAndData(t *testing.T) {
}
return nil
},
health: func(_ context.Context, record Record, _ *http.Client) error {
health: func(ctx context.Context, record Record, _ *http.Client) error {
if failure == "canceled" && record.CoreVersion == "v4.11.8" {
cancel()
return ctx.Err()
}
if failure == "health" && record.CoreVersion == "v4.11.8" {
return fmt.Errorf("healthz 503")
}
return nil
},
}
backup, err := upgradeNative(context.Background(), dir, record, "v4.11.8", io.Discard, nil, operations)
backup, err := upgradeNative(ctx, dir, record, "v4.11.8", io.Discard, nil, operations)
current, readErr := (Store{Dir: dir}).Read()
if readErr != nil {
t.Fatal(readErr)
Expand All @@ -195,6 +202,9 @@ func TestNativeUpgradeRestoresVersionAndData(t *testing.T) {
if failure == "health" && !strings.Contains(err.Error(), "previous version and data restored") {
t.Fatal(err)
}
if failure == "canceled" && !errors.Is(err, context.Canceled) {
t.Fatalf("upgrade error = %v, want context cancellation", err)
}
})
}
}
Expand Down
18 changes: 18 additions & 0 deletions internal/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,21 @@ func TestRejectAmbiguousTargets(t *testing.T) {
})
}
}

func FuzzNormalizeIdempotent(f *testing.F) {
f.Add("http://LOCALHOST:05300/")
f.Add("https://example.com:443/proxy/")
f.Add("http://[::1]:80")
f.Add("https://example.com/%E5%BC%80%E5%8F%91/")
f.Add("https://example.com/a%20b")
f.Fuzz(func(t *testing.T, input string) {
normalized, err := Normalize(input)
if err != nil {
return
}
again, err := Normalize(normalized)
if err != nil || again != normalized {
t.Fatalf("Normalize(%q) = %q, then %q, %v", input, normalized, again, err)
}
})
}
Loading