Skip to content

Commit 8293f3d

Browse files
committed
Matlas Prototype
1 parent eb254ac commit 8293f3d

File tree

118 files changed

+13312
-1025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+13312
-1025
lines changed

.DS_Store

-2 KB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
alwaysApply: true
3+
description: Guidance for maintaining CHANGELOG.md and integrating with semantic-release during feature/bugfix development
4+
---
5+
6+
# Changelog maintenance
7+
8+
This project uses Keep a Changelog style and Semantic Versioning. The changelog lives at [CHANGELOG.md](mdc:CHANGELOG.md) and release automation is handled by semantic-release via [semantic-release workflow](mdc:.github/workflows/semantic-release.yml) and [release config](mdc:.releaserc.json).
9+
10+
## What to edit during development
11+
12+
- Only update the `## [Unreleased]` section of [CHANGELOG.md](mdc:CHANGELOG.md)
13+
- Group entries under standard headings (include only those that apply):
14+
- Added
15+
- Changed
16+
- Fixed
17+
- Deprecated
18+
- Removed
19+
- Security
20+
- Use concise, imperative bullet points. Prefer user-facing language over internal implementation details.
21+
- Link related issues/PRs where helpful using `[#123]` with markdown links.
22+
- Do not add version numbers, dates, or modify past release sections.
23+
24+
## When to add entries
25+
26+
- When a change is user-visible (CLI flags/behavior, YAML kinds/fields, output format, docs that change user flows), add a bullet under `Unreleased`.
27+
- If a change is purely internal (refactor, tests, tooling) and has no user impact, skip the changelog.
28+
29+
## Release automation contract
30+
31+
- Do not manually bump versions or author release sections. semantic-release will cut releases and update the changelog based on Conventional Commits.
32+
- Keep `Unreleased` accurate for in-flight work; automation will reconcile at release time. Avoid duplicating the same change across multiple headings.
33+
34+
## Style examples
35+
36+
```markdown
37+
## [Unreleased]
38+
39+
### Added
40+
- New `infra plan --json` output format for CI consumption
41+
42+
### Changed
43+
- Enhanced `version` command to print build metadata (commit, time)
44+
45+
### Fixed
46+
- Corrected `database list` pagination when `--limit` is provided
47+
```
48+
49+
## Cross-feature hygiene
50+
51+
- Align with the feature tracking policy: add a short summary file under `features/` (see [features/TEMPLATE.md](mdc:features/TEMPLATE.md)).
52+
- If the change adds a new user-facing capability, ensure documentation is updated under `docs/` and an example YAML is added under `examples/`, per repository standards.
53+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
alwaysApply: true
3+
description: Conventional Commits guidance to power semantic-release and structured CHANGELOG updates
4+
---
5+
6+
# Conventional Commits
7+
8+
Follow Conventional Commits to enable automated versioning and changelog generation. See config at [release config](mdc:.releaserc.json) and workflow at [semantic-release workflow](mdc:.github/workflows/semantic-release.yml).
9+
10+
## Format
11+
12+
```
13+
<type>(<optional scope>)<!>: <short summary>
14+
15+
<optional body>
16+
17+
<optional footer(s)>
18+
```
19+
20+
## Allowed types (common)
21+
22+
- feat: user-facing feature (triggers minor version)
23+
- fix: bug fix (triggers patch version)
24+
- perf: performance improvement (patch)
25+
- refactor: code refactor without behavior change
26+
- docs: documentation only
27+
- test: tests only
28+
- build: build system or deps
29+
- ci: CI configuration
30+
- chore: maintenance tasks
31+
- revert: revert a previous commit
32+
33+
## Breaking changes
34+
35+
- Append `!` after type or scope, or include a `BREAKING CHANGE:` footer.
36+
- Example: `feat(api)!: drop deprecated v1 endpoints`
37+
- Footer example:
38+
- `BREAKING CHANGE: removed --legacy flag from infra apply`
39+
40+
## Scopes
41+
42+
- Use repository areas for clarity: `infra`, `atlas`, `database`, `cli`, `docs`, `types`, `services`, `apply`, etc.
43+
- Examples: `feat(infra): add --json to plan`, `fix(database): correct list pagination`
44+
45+
## Body and footers
46+
47+
- Body: explain what and why, not how. Wrap at ~72 chars.
48+
- Reference issues/PRs in footers:
49+
- `Refs: #123`
50+
- `Closes: #456`
51+
52+
## Changelog interplay
53+
54+
- Conventional Commits drive release notes. Still update `## [Unreleased]` in [CHANGELOG.md](mdc:CHANGELOG.md) for visibility during development.
55+
- Keep summaries aligned between commit subjects and changelog bullets.
56+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
globs: docs/**/*.md
3+
description: Checklist for authoring Markdown documentation under docs/
4+
---
5+
6+
# Docs Markdown Authoring Checklist
7+
8+
This rule applies to all Markdown files under `docs/`.
9+
10+
- Include valid Jekyll frontmatter at the top (`--- ... ---`) with at least:
11+
- `layout: page` (or `home` where appropriate)
12+
- `title: <Concise Title>`
13+
- `description:` (recommended)
14+
- `permalink:` for top-level navigation pages
15+
16+
- Use relative URLs with Jekyll helpers where possible, e.g. `{{ '/atlas/' | relative_url }}`.
17+
- Keep pages within the site structure and navigation defined in [docs/_config.yml](mdc:docs/_config.yml).
18+
- For code examples, use fenced code blocks with language tags and avoid excessive inline code.
19+
- Images and assets must be placed under `docs/assets/` and referenced with `{{ '/assets/... ' | relative_url }}`.
20+
- Do not add documentation outside the `docs/` directory or bypass the site theme.
21+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
alwaysApply: true
3+
description: Enforce documentation standards (location under docs/ and GitHub Pages theme usage)
4+
---
5+
6+
# Documentation Standards
7+
8+
These rules ensure documentation is consistently authored and published.
9+
10+
- All documentation must reside under the `docs/` directory in the repository root.
11+
- Documentation must use the GitHub Pages Jekyll setup and theme configured in [docs/_config.yml](mdc:docs/_config.yml) (theme `minima`, site served from `baseurl: /matlas-cli`).
12+
13+
## Authoring requirements
14+
15+
- New pages must include Jekyll frontmatter (at least `layout`, `title`, and where applicable `permalink`). Example:
16+
17+
```markdown
18+
---
19+
layout: page
20+
title: My Page
21+
permalink: /my-page/
22+
---
23+
24+
# My Page
25+
26+
Content...
27+
```
28+
29+
- Keep navigation consistent with the site menu. Update the `navigation` list in [docs/_config.yml](mdc:docs/_config.yml) when adding or renaming top-level pages.
30+
- Styles should flow through the existing pipeline: add SCSS to [docs/_sass/main.scss](mdc:docs/_sass/main.scss) (or additional partials) and import via [docs/assets/css/style.scss](mdc:docs/assets/css/style.scss). Do not add standalone CSS outside `docs/assets/`.
31+
- Use fenced code blocks with language tags for examples. Syntax highlighting is provided by the site layout and Highlight.js in [docs/_layouts/default.html](mdc:docs/_layouts/default.html).
32+
33+
## Local preview and validation
34+
35+
- Use the documented workflow in [docs/README.md](mdc:docs/README.md):
36+
37+
```bash
38+
cd docs
39+
bundle install
40+
bundle exec jekyll serve
41+
```
42+
43+
- Ensure the site builds without errors locally and remains compatible with GitHub Pages (respect the theme and plugins defined in [docs/_config.yml](mdc:docs/_config.yml)).
44+
45+
## Do not
46+
47+
- Do not place documentation outside `docs/`.
48+
- Do not change the configured Jekyll theme or `baseurl` without updating site structure, navigation, and deployment expectations.
49+

.cursor/rules/error-handling.mdc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
description: Standardized error handling for concise vs verbose output, real-cause preservation, and consistent formatting across all commands and services
3+
alwaysApply: false
4+
---
5+
### Error Handling Policy
6+
7+
Follow a single, consistent pattern for all errors across the project:
8+
9+
- Use `internal/cli` formatters for all user-facing errors
10+
- Short/non-verbose: `ErrorFormatter.Format(err)` from [`internal/cli/errors.go`](mdc:internal/cli/errors.go)
11+
- Verbose: `EnhancedErrorFormatter.FormatWithAnalysis(err)` from [`internal/cli/enhanced_errors.go`](mdc:internal/cli/enhanced_errors.go)
12+
- Root command wires these already in [`cmd/root.go`](mdc:cmd/root.go). Subcommands must return errors; do not print or handle them locally.
13+
14+
- Always show the real issue
15+
- Preserve and propagate the original cause using Go error wrapping with `%w` and helpers in [`internal/cli/enhanced_errors.go`](mdc:internal/cli/enhanced_errors.go) (`WrapWithOperation`, `WrapWithContext`, `WrapWithStack`).
16+
- Prefer specific sentinel or HTTP-based classification over generic networking guesses. Use Atlas sentinels from [`internal/clients/atlas/errors.go`](mdc:internal/clients/atlas/errors.go) via `errors.Is` or `atlas.IsNotFound`/`atlas.IsUnauthorized`/etc.
17+
- Do not replace the real error with a generic message (e.g., “network error”) when a more specific validation/auth/resource error exists.
18+
19+
- Output contract (must be consistent everywhere)
20+
- Non-verbose (`--verbose` not set): show a single, clear message focused on the actionable cause.
21+
- Shape: `Error: <concise message>` (the enhanced formatter prefixes when needed and extracts the most specific part).
22+
- Verbose (`--verbose` set): include full description with category, root cause, and suggestions when available.
23+
- Shape includes sections such as `Error:`, `Suggestions:`, and `Root Cause:` produced by the enhanced formatter.
24+
- Never display Cobra usage/help text when returning an error. Use `cli.ConfigureCommandErrorHandling(cmd)` and return the error from `RunE`.
25+
26+
- How to return errors in commands and services
27+
- Return, don’t print: return `error` from `RunE`; let root formatting handle output.
28+
- Wrap with context and operation to preserve meaning:
29+
- `return cli.WrapWithOperation(err, "<operation>", <resourceID>)`
30+
- For validation: `return cli.FormatValidationError(field, value, reason)`
31+
- For additional guidance: `return cli.WrapWithSuggestion(err, "<next step>")`
32+
- When calling Atlas SDK, map errors to sentinels in the client and use `errors.Is`/`atlas.Is*` to branch logic instead of string matching.
33+
34+
- Classification precedence (to avoid misleading “network” diagnoses)
35+
- Prefer: Validation/Configuration/AuthZ/AuthN > Resource (exists/not found/conflict) > HTTP status mapping > Network/Timeout fallbacks.
36+
- In verbose mode, always include the original `err.Error()` content so the true cause is visible during debugging.
37+
38+
- Logging and secrecy
39+
- Use the structured logger from [`internal/logging/logger.go`](mdc:internal/logging/logger.go) for debug/diagnostic context. Do not `fmt.Println` raw errors.
40+
- Ensure secrets are masked by relying on the logging package; do not embed credentials in error messages.
41+
42+
### Examples
43+
44+
```go
45+
// Good: preserve cause and context
46+
if err := svc.CreateCluster(ctx, req); err != nil {
47+
return cli.WrapWithOperation(err, "create_cluster", req.Name)
48+
}
49+
50+
// Good: specific validation error
51+
if req.Name == "" {
52+
return cli.FormatValidationError("cluster name", req.Name, "must not be empty")
53+
}
54+
55+
// Good: suggestion to help user fix
56+
return cli.WrapWithSuggestion(err, "Use --timeout 5m or check IP access list")
57+
```
58+
59+
### Acceptance criteria for new/changed code
60+
61+
- Non-verbose execution prints a single concise line without suggestions or stack details.
62+
- Verbose execution prints full enhanced output including `Suggestions:` and/or `Root Cause:` when available.
63+
- Real cause is preserved in verbose output; no generic “network error” replaces a more precise error.
64+
- All commands rely on central formatting; no command prints errors directly.
65+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
alwaysApply: true
3+
description: Ensure every new feature supports both CLI and YAML ApplyDocument, and clearly distinguishes INFRA vs non-INFRA commands.
4+
---
5+
6+
# Feature Interface Consistency (CLI + YAML ApplyDocument)
7+
8+
When introducing any new user-facing feature, always provide both:
9+
10+
- CLI interface with appropriate subcommands and flags
11+
- YAML ApplyDocument support via a dedicated YAML kind (create one if it does not exist)
12+
13+
This policy prevents drift between interfaces and guarantees first-class automation support.
14+
15+
## Command taxonomy: INFRA vs other commands
16+
17+
- INFRA-related functionality belongs under `cmd/infra` (e.g., plan/apply/diff/show/validate flows)
18+
- Keep business logic in the `internal/apply` pipeline and `internal/services/*` layers
19+
- Ensure operations are surfaced in: `apply`, `plan`, `diff`, `show`, `validate`
20+
21+
- Non-INFRA functionality belongs in its domain-specific command group:
22+
- `cmd/atlas/*` for Atlas resources and account/project/cluster/user/network surfaces
23+
- `cmd/database/*` for MongoDB database-level operations
24+
- `cmd/config/*` for CLI configuration and credentials
25+
26+
Both paths must call the same service-layer code in `internal/services/*` to avoid divergence.
27+
28+
## CLI requirements
29+
30+
- Add or extend a subcommand in the correct command group (`cmd/infra`, `cmd/atlas`, `cmd/database`, `cmd/config`)
31+
- Provide flags that are consistent with existing naming and patterns
32+
- Validate inputs and route requests through shared services in `internal/services/*`
33+
- Update command help and autocompletion if applicable
34+
35+
Relevant entry points and patterns:
36+
- `cmd/infra/*.go`
37+
- `cmd/atlas/**/*.go`
38+
- `cmd/database/**/*.go`
39+
- `internal/services/*`
40+
41+
## YAML (ApplyDocument) requirements
42+
43+
- If a unique YAML kind already exists for the object, ensure ApplyDocument supports the new fields/behaviors.
44+
- If no unique YAML kind exists, create one and implement end-to-end support:
45+
- Define or extend types in: [internal/types/apply.go](mdc:internal/types/apply.go), [internal/types/*.go](mdc:internal/types)
46+
- Load and map kinds in: [internal/apply/loader.go](mdc:internal/apply/loader.go)
47+
- Validate schema and semantics in: [internal/apply/validation.go](mdc:internal/apply/validation.go), [internal/validation/schema.go](mdc:internal/validation/schema.go)
48+
- Wire execution to services in: [internal/apply/executor.go](mdc:internal/apply/executor.go), [internal/apply/fetchers.go](mdc:internal/apply/fetchers.go)
49+
- Keep diff/dry-run output coherent in: [internal/apply/diff_formatter.go](mdc:internal/apply/diff_formatter.go), [internal/apply/dryrun_formatter.go](mdc:internal/apply/dryrun_formatter.go)
50+
51+
Both CLI and YAML paths must use the same service-layer implementations in `internal/services/*` (e.g., [internal/services/atlas](mdc:internal/services/atlas), [internal/services/database](mdc:internal/services/database)).
52+
53+
## Documentation and examples
54+
55+
- Add a minimal YAML example to `examples/` and reference it from `docs/`
56+
- Update relevant docs pages under `docs/` to describe the CLI flags and YAML kind usage
57+
58+
## Per-feature tracking
59+
60+
To ensure clarity and traceability, every feature MUST include a concise per-feature summary file:
61+
62+
- Location: `features/`
63+
- Template: `features/TEMPLATE.md`
64+
- Naming: `YYYY-MM-DD-<short-slug>.md` (e.g., `2025-08-13-temporary-users.md`) or `FTR-<id>-<short-slug>.md`
65+
- Minimum content: a top-level title (`Feature: <name>`) and a short "Summary" (2–6 sentences)
66+
- Recommended content: sections mapping changes across CLI, YAML ApplyDocument, service layer, apply pipeline, types, tests, docs, and any breaking/migration notes
67+
68+
## Acceptance checklist (must have)
69+
70+
- CLI subcommand/flags added in the correct command group
71+
- YAML kind exists and is supported by ApplyDocument end-to-end
72+
- Both interfaces call the same `internal/services/*` logic
73+
- Docs updated and example YAML added
74+
- Per-feature tracking file added under `features/` using the template, with a filled Summary and links to relevant code/docs
75+

.cursor/rules/live-tests.mdc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
alwaysApply: false
3+
---
4+
## Live Tests Policy (CLI + YAML)
5+
6+
This repository requires comprehensive, live tests for both CLI and YAML paths. Follow these rules when creating or updating tests:
7+
8+
- **Location**: Place all live tests under `scripts/` (prefer `scripts/test/`), one focused script per surface. Entry point and orchestration live in [`scripts/test.sh`](mdc:scripts/test.sh).
9+
10+
- **Coverage requirements**: Each test script must exercise the maximum breadth of its domain:
11+
- Happy-path for every relevant command and subcommand of the surface
12+
- Flag coverage: required, optional, combinations, mutually exclusive flags, and defaults
13+
- Output variants: at least text and JSON, plus YAML where relevant
14+
- Negative cases: missing/invalid arguments, invalid types, unsupported combinations, permission/auth failures
15+
- Idempotency: repeated runs don’t drift; add dry-run checks where available
16+
17+
- **Dual-path requirement**: For any supported capability, test both interfaces:
18+
- CLI subcommands and flags under `cmd/*`
19+
- YAML ApplyDocument flows handled by `cmd/infra/*` via `validate`, `plan`, `diff`, `show`, `apply`, and `destroy`
20+
21+
- **Runner integration**: All new live tests must be invocable from the main runner:
22+
- Add a dedicated mode/subcommand in [`scripts/test.sh`](mdc:scripts/test.sh)
23+
- Ensure discoverability in help/usage and include the test in appropriate aggregates (e.g., `all`, `comprehensive`)
24+
- Update documentation in [`scripts/README.md`](mdc:scripts/README.md)
25+
26+
- **Script conventions**:
27+
- Use `#!/usr/bin/env bash` and `set -euo pipefail`
28+
- Validate environment (.env support OK) and print clear diagnostics
29+
- Provide `--dry-run`, `--verbose`, and `--timeout` flags when applicable
30+
- Track created resources and guarantee cleanup on EXIT/INT/TERM
31+
- Emit non-zero exit codes on failures; write artifacts to `test-reports/`
32+
33+
- **Naming**:
34+
- Script file: `scripts/test/<domain>.sh`
35+
- Test modes within script: granular selectors for subsets (e.g., `validation`, `errors`, `workflow`)
36+
37+
By policy, tests that do not meet these criteria should be extended to include missing command paths, flag combos, and negative validations before merge.
38+

0 commit comments

Comments
 (0)