Test assertions were out of sync with the coreerr.E() error format
introduced in 9a24df3 — updated 8 assertions from "prefix 404" to
"prefix: HTTP 404". Added round-trip tests for UpdateRecord,
EnsureRecord, ClearACMEChallenge, CreateLoadBalancer, DeleteLoadBalancer,
CreateSnapshot, GetLoadBalancer, ListLoadBalancers, GetServer, and unit
tests for HostsByRole/AppServers. Coverage: 62.5% → 80.9%. Updated
CLAUDE.md to reflect go-log/go-io dependencies and coding standards.
Co-Authored-By: Virgil <virgil@lethean.io>
2.7 KiB
2.7 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
core/go-infra provides infrastructure provider API clients (Hetzner Cloud, Hetzner Robot, CloudNS) and a YAML-based infrastructure configuration parser. Dependencies: go-log (error handling), go-io (file I/O), yaml.v3, and testify (tests).
Build & Test
go test ./... # run all tests
go test -race ./... # run all tests with race detector
go test -run TestFoo ./... # run a single test by name
No build step needed for the library. The cmd/ packages are CLI commands registered via forge.lthn.ai/core/cli and are built as part of the parent core CLI tool, not standalone binaries.
Architecture
Single infra package (root directory) with four source files:
client.go—APIClientwith retry, exponential backoff + jitter, rate-limit (429+Retry-After) handling. Functional options pattern (WithHTTPClient,WithRetry,WithAuth,WithPrefix). Two execution paths:Do(JSON decode) andDoRaw(raw bytes).hetzner.go—HCloudClient(Bearer token auth, Hetzner Cloud API: servers, load balancers, snapshots) andHRobotClient(Basic auth, Hetzner Robot API: dedicated servers). Both embedAPIClientvia delegation.cloudns.go—CloudNSClient(query-param auth, CloudNS DNS API). UsesDoRawbecause CloudNS returns non-standard JSON (e.g.{}for empty lists). IncludesEnsureRecord(idempotent upsert) and ACME DNS-01 challenge helpers.config.go—Configstruct parsed frominfra.yamlviaLoad()orDiscover()(walks parent dirs). Defines the full infrastructure topology: hosts, load balancers, DNS, SSL, database, cache, containers, S3, CDN, CI/CD, monitoring, backups.
CLI Commands (cmd/)
These are subcommands for the parent core CLI, registered via cli.RegisterCommands() in init():
cmd/prod— Production infrastructure management (status,setup,dns,lb,ssh). Readsinfra.yaml.cmd/monitor— Security finding aggregator. Pulls from GitHub code scanning, Dependabot, and secret scanning APIs viaghCLI.
Coding Standards
- UK English in comments and strings
- Error handling: Use
coreerr.E()fromgo-log, neverfmt.Errorforerrors.New - File I/O: Use
coreio.Local.Read()fromgo-io, neveros.ReadFile - Tests use
testify(assert+require) - Test naming:
TestType_Method_Good,TestType_Method_Bad,TestType_Method_Uglysuffixes (Good = happy path, Bad = expected errors, Ugly = edge cases) - Tests use
httptest.NewServerfor HTTP mocking — no mock libraries - License: EUPL-1.2