|
| 1 | +# Copilot Instructions |
| 2 | + |
| 3 | +## Build, test, and lint |
| 4 | + |
| 5 | +- Use Go 1.25.x (`go.mod` pins `go 1.25.5`; CI uses Go 1.25). |
| 6 | +- Prefer the repo `make` targets for final verification: |
| 7 | + - `make test` - runs `go test --short ./... -race -coverprofile=coverage.txt -covermode=atomic` |
| 8 | + - `make check` - runs `golangci-lint run -c .golangci.yml -v ./...` |
| 9 | + - `make tidy` - runs `go mod tidy` and fails if `go.mod` or `go.sum` changed |
| 10 | + - `make build-errorutil` - builds the `cmd/errorutil` binary |
| 11 | + - `make errorutil` - updates structured error codes and related exports |
| 12 | + - `make errorutil-analyze` - analyzes structured error definitions without rewriting them |
| 13 | +- For a single test during iteration, run Go tests directly at package scope: |
| 14 | + - `go test ./models/registration -run TestGetEntityAcceptsV1Beta2RelationshipSchemaVersion -count=1` |
| 15 | + - general form: `go test ./path/to/package -run TestName -count=1` |
| 16 | + |
| 17 | +## High-level architecture |
| 18 | + |
| 19 | +- This repository is primarily a **shared Go library** for the Meshery ecosystem, not a single application. Most top-level directories are reusable packages; the main executable entrypoints live under `cmd/`, notably `cmd/errorutil` and `cmd/syncmodutil`. |
| 20 | +- The **structured error pipeline** spans several packages: |
| 21 | + - `errors/` defines the shared MeshKit error types and helpers. |
| 22 | + - package-local `error.go` files define concrete errors for each package/component. |
| 23 | + - `logger/` enriches log output with MeshKit error metadata such as code, severity, cause, and remediation. |
| 24 | + - `cmd/errorutil` scans the repository, analyzes those definitions, updates placeholder codes using `helpers/component_info.json`, and writes export/analysis artifacts under `helpers/`. |
| 25 | +- The **MeshModel registration pipeline** is another core slice of the repo: |
| 26 | + - `models/registration/` ingests model packages from directories, YAML/JSON files, nested archives, and OCI artifacts, then assembles a `PackagingUnit`. |
| 27 | + - `models/meshmodel/registry/` persists registrants, models, components, and relationships through GORM-backed registry helpers. |
| 28 | + - Schema definitions themselves come from `github.com/meshery/schemas`; in this repo, focus on how MeshKit loads, normalizes, registers, and persists those entities rather than treating MeshKit as the schema source of truth. |
| 29 | +- Cross-cutting infrastructure packages are intentionally reusable across services: |
| 30 | + - `database/` wraps GORM setup for SQLite and Postgres. |
| 31 | + - `tracing/` provides OpenTelemetry initialization plus HTTP middleware/client transport helpers. |
| 32 | + - `logger/`, `utils/`, `encoding/`, and `converter/` provide shared support code used by Meshery services and tools. |
| 33 | + |
| 34 | +## Key conventions |
| 35 | + |
| 36 | +- Prefer **Makefile targets for final verification**. Use direct `go test ./pkg -run TestName` only for focused iteration. |
| 37 | +- Strictly honor and adhere to the established identifier naming scheme, authoritatively documented in meshery/schemas - https://github.com/meshery/schemas/blob/master/docs/identifier-naming-contributor-guide.md#canonical-naming-directory |
| 38 | +- Structured errors follow strict repository conventions so `errorutil` can understand them: |
| 39 | + - define concrete errors in each package's `error.go` |
| 40 | + - define code symbols matching `^Err[A-Z].+Code$` |
| 41 | + - create errors with `errors.NewV2(...)` when no existing error is a well-suited fit; the `(*errors.Error).NewV2(...)` helper may also be used where applicable) |
| 42 | + - keep static text in the description/cause/remediation arrays as string literals rather than composed constants/concatenations |
| 43 | +- If you add or modify structured errors, run `make errorutil` and usually `make errorutil-analyze`. `errorutil` expects `component_info.json` metadata and emits `errorutil_analyze_*.json` plus `errorutil_errors_export.json` artifacts under `helpers/`. |
| 44 | +- MeshModel registration assumes an imported package/directory contains **exactly one model definition** and then any number of components/relationships associated with it. |
| 45 | +- Registration code is intentionally permissive on input shape: |
| 46 | + - directory import recursively unwraps nested zip/tar/OCI content |
| 47 | + - YAML is normalized to JSON before entity detection/unmarshal |
| 48 | + - registration accepts both legacy and canonical schema-version strings for models/components/relationships where compatibility is required |
| 49 | +- Registration mutates asset references as part of ingestion: model/component SVG fields are written to the filesystem and replaced with file paths before persistence through `RegistryManager`. |
0 commit comments