You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add description fields and coding guidelines to instruction files (#79)
Add description frontmatter to docs and go instruction files for better agent discoverability.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .github/instructions/go.instructions.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
---
2
2
applyTo: "**/*.go"
3
+
description: "Instructions for working on the azldev Go codebase. IMPORTANT: Always read these instructions when reading or editing Go code in this repository."
3
4
---
4
5
5
6
# Guidelines for Copilot
@@ -44,6 +45,14 @@ applyTo: "**/*.go"
44
45
- Ensure code passes golangci-lint checks
45
46
- Use `github.com/microsoft/azure-linux-dev-tools/internal/utils/fileperms` instead of re-defining file permission constants
46
47
- Use `github.com/microsoft/azure-linux-dev-tools/internal/utils/fileutils` for file operations like `Exists`, `ReadFile`, `WriteFile`, not "github.com/spf13/afero" directly.
48
+
- Avoid directly using os package functions for file operations; use the fileutils package instead.
49
+
50
+
### External Command Execution
51
+
52
+
-**NEVER** use `exec.LookPath` to check for external tools. Use `ctx.CommandInSearchPath("toolname")` or `env.CommandInSearchPath("toolname")` instead — these delegate to the underlying command factory and integrate with `testctx` for stubbing in tests (for example via `testEnv.CmdFactory.RegisterCommandInSearchPath(...)`).
53
+
- Use `exec.CommandContext(ctx, "toolname", args...)` with the binary name (not an absolute path) after the `CommandInSearchPath` check. PATH resolution happens at exec time.
54
+
- Always wrap with `ctx.Command(rawCmd)` or `env.Command(rawCmd)` and use `cmd.RunAndGetOutput(ctx)` or `cmd.Run(ctx)` for consistent event tracking and dry-run support.
55
+
- Capture stderr separately via `rawCmd.Stderr = &stderr` (set BEFORE `ctx.Command()` / `env.Command()`) for use in error messages.
47
56
48
57
### Return values
49
58
@@ -83,6 +92,10 @@ applyTo: "**/*.go"
83
92
}
84
93
```
85
94
95
+
### CmdlineReturns
96
+
97
+
CLI commands should return meaningful structured results. azldev has output formatting helpers to facilitate this (for example, `RunFunc*` wrappers handle formatting, so callers typically should not call `reflectable.FormatValue` directly).
98
+
86
99
## QualityStandards
87
100
88
101
- Make minimal, focused changes to achieve the required functionality
@@ -91,3 +104,11 @@ applyTo: "**/*.go"
91
104
- Organize imports according to Go best practices
92
105
- Linting: Prefer fixing issues over `//nolint` comments. Use targeted `//nolint:<linter>`if absolutely required
New component subcommands (`internal/app/azldev/cmds/component/`) require:
111
+
- **Command wiring test** (`*_test.go`, external `package component_test`): verify `NewXxxCmd()` returns a valid command with correct `Use`, `RunE`, and expected flags/defaults.
112
+
- **No-match test**: call `cmd.ExecuteContext(testEnv.Env)` with a nonexistent component to verify error handling.
113
+
- **Helper unit tests** (`*_test.go`, same-package`package component`): test unexported helper functions (e.g., `findSpecFile`, `cleanupStaleRenders`) using `afero.NewMemMapFs`; where needed, follow the existing `//nolint:testpackage` pattern used in this repo.
114
+
- **Snapshot update**: if the command changes the schema or CLI docs, run `mage scenarioUpdate` to update snapshots.
0 commit comments