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
12 changes: 6 additions & 6 deletions .atmos.d/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ commands:
flags:
- name: base-ref
type: string
default: origin/main
description: Base branch or commit for PR comparisons
default: ""
description: Base branch or commit for PR comparisons (default is the branch's stackbase, then origin/main)
- name: only
type: string
default: ""
Expand All @@ -31,8 +31,8 @@ commands:
flags:
- name: base-ref
type: string
default: origin/main
description: Base branch or commit for PR comparisons
default: ""
description: Base branch or commit for PR comparisons (default is the branch's stackbase, then origin/main)
- name: only
type: string
default: ""
Expand All @@ -54,8 +54,8 @@ commands:
flags:
- name: base-ref
type: string
default: origin/main
description: Base branch or commit for PR comparisons
default: ""
description: Base branch or commit for PR comparisons (default is the branch's stackbase, then origin/main)
- name: only
type: string
default: ""
Expand Down
12 changes: 6 additions & 6 deletions .atmos.d/format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ commands:
flags:
- name: base-ref
type: string
default: origin/main
description: Base branch or commit for PR comparisons
default: ""
description: Base branch or commit for PR comparisons (default is the branch's stackbase, then origin/main)
- name: only
type: string
default: ""
Expand All @@ -27,8 +27,8 @@ commands:
flags:
- name: base-ref
type: string
default: origin/main
description: Base branch or commit for PR comparisons
default: ""
description: Base branch or commit for PR comparisons (default is the branch's stackbase, then origin/main)
- name: only
type: string
default: ""
Expand All @@ -46,8 +46,8 @@ commands:
flags:
- name: base-ref
type: string
default: origin/main
description: Base branch or commit for PR comparisons
default: ""
description: Base branch or commit for PR comparisons (default is the branch's stackbase, then origin/main)
- name: only
type: string
default: ""
Expand Down
9 changes: 8 additions & 1 deletion cmd/cast/recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,15 @@ func recordingBasePath(plan recordingOutputPlan, atmosConfig *schema.AtmosConfig
return recording.BasePath
}

// recordedCommandArgs returns the command as the user typed it: the program
// name followed by the resolved arguments. The cast header stores this value
// and the docs player types it after the prompt, so omitting the program name
// would render "> --help" instead of "> atmos --help". The arguments are
// copied so the caller's slice is never aliased.
func recordedCommandArgs(args []string) []string {
return append([]string(nil), args...)
command := make([]string, 0, len(args)+1)
command = append(command, cfg.AtmosCommand)
return append(command, args...)
}

// StartHelpRecording starts a cast recording for help output when explicitly
Expand Down
32 changes: 28 additions & 4 deletions cmd/cast/recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestRecordedCommandArgsCopiesResolvedArgs(t *testing.T) {
input := []string{"terraform", "plan", "--stack", "dev"}
got := recordedCommandArgs(input)
want := []string{"terraform", "plan", "--stack", "dev"}
want := []string{"atmos", "terraform", "plan", "--stack", "dev"}
if len(got) != len(want) {
t.Fatalf("got %#v want %#v", got, want)
}
Expand All @@ -28,10 +28,34 @@ func TestRecordedCommandArgsCopiesResolvedArgs(t *testing.T) {
t.Fatalf("got %#v want %#v", got, want)
}
}
got[0] = "changed"
got[1] = "changed"
if input[0] != "terraform" {
t.Fatalf("recordedCommandArgs must copy input, got input %#v", input)
}
input[1] = "mutated"
if got[2] != "plan" {
t.Fatalf("recordedCommandArgs result must not alias input, got %#v", got)
}
}

func TestRecordedCommandArgsIncludesProgramName(t *testing.T) {
tests := []struct {
name string
input []string
want []string
}{
{name: "root help flag", input: []string{"--help"}, want: []string{"atmos", "--help"}},
{name: "subcommand help", input: []string{"ai", "--help"}, want: []string{"atmos", "ai", "--help"}},
{name: "no arguments", input: nil, want: []string{"atmos"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := recordedCommandArgs(tt.input)
if strings.Join(got, "\x00") != strings.Join(tt.want, "\x00") {
t.Fatalf("got %#v want %#v", got, tt.want)
}
})
}
}

func TestStartRecordingSkipsHelpCompletionAndDisabled(t *testing.T) {
Expand Down Expand Up @@ -127,7 +151,7 @@ func TestStartRecordingWithExplicitPath(t *testing.T) {
if err := json.Unmarshal([]byte(headerLine), &header); err != nil {
t.Fatal(err)
}
if header.Command != "terraform plan --stack dev" {
if header.Command != "atmos terraform plan --stack dev" {
t.Fatalf("recorded command = %q", header.Command)
}
if header.Term.Cols != 100 || header.Term.Rows != 30 {
Expand Down Expand Up @@ -178,7 +202,7 @@ func TestStartRecordingWithBareCastFlagUsesGeneratedPath(t *testing.T) {
if err := json.Unmarshal([]byte(headerLine), &header); err != nil {
t.Fatal(err)
}
if header.Command != "terraform plan" {
if header.Command != "atmos terraform plan" {
t.Fatalf("recorded command = %q", header.Command)
}
}
Expand Down
14 changes: 10 additions & 4 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ live progress tree; CI gets static results.
### Checking, formatting, and committing

- `atmos check staged` checks a temporary copy of the index without changing your
files. `check pr` selects committed branch changes relative to `origin/main`
and checks their current working-tree contents; `check all` checks all tracked files.
files. `check pr` selects committed branch changes relative to the comparison base
(`origin/main` unless a stack base is set, as described below) and checks their
current working-tree contents; `check all` checks all tracked files.
- `atmos format staged|pr|all` applies formatting and module cleanup as unstaged
changes. It never stages files and reports operational failures.
- `git commit` runs the full suite against the index. Automatic fixes are returned
Expand All @@ -102,11 +103,16 @@ Formatting exclusions are check-specific and preserve golden snapshots, generate
SVGs, and other existing exclusions. The suite also verifies symlinks, instruction
file sizes, YAML syntax, large files, EditorConfig, module compatibility, and
secrets. The `branch-file-limit` check permits at most 150 files in the branch diff
against the merge base with `origin/main`, including the pending staged changes.
against the merge base with the comparison base (`origin/main` by default), including the
pending staged changes.
Deletions count, renames count once, and unstaged edits are excluded. Initial commits
compare against an empty tree. This is our review-size policy; CodeRabbit's published
file allowance varies by plan. Split larger changes into smaller PRs or a PR stack;
`--base-ref` can select the parent branch when checking a stack.
`--base-ref` can select the parent branch when checking a stack. The commit hook has no
flags, so a stacked branch records its parent once with
`git config branch.<name>.stackbase <parent-branch>`; the hook then measures the file
limit and new-lint findings against that parent. `ATMOS_BRANCH_BASE_REF` overrides it
for a single command.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Go module tidy runs once per affected module, including nested modules.

### Setup and recovery
Expand Down
24 changes: 23 additions & 1 deletion scripts/checks/entry.star
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
# Shared entry point for custom commands and the installed Git hook.
load("suite.star", "run_suite")

# Default comparison base for branch-wide checks such as the 150-file limit.
DEFAULT_BASE = "origin/main"

# Resolve the branch comparison base. A layer in a PR stack compares against its parent
# branch, so an explicit base wins, then ATMOS_BRANCH_BASE_REF, then the per-branch Git
# config key branch.<name>.stackbase, and finally origin/main. An empty base means the
# caller supplied none, so even an explicit origin/main is honored instead of replaced.
def resolve_base(base):
if base:
return base
override = os.getenv("ATMOS_BRANCH_BASE_REF")
if override:
return override
branch = exec.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], output = "capture", check = False)
name = branch.stdout.strip() if branch.exit_code == 0 else ""
if name and name != "HEAD":
configured = exec.run(["git", "config", "--get", "branch." + name + ".stackbase"], output = "capture", check = False)
if configured.exit_code == 0 and configured.stdout.strip():
return configured.stdout.strip()
return DEFAULT_BASE

# Run the shared suite in a Git sandbox with read-only checks or unstaged fixes.
def run(scope, mode, base = "origin/main", only = "", skip = ""):
def run(scope, mode, base = "", only = "", skip = ""):
if mode not in ["check", "format", "commit"]:
fail("Unknown check mode: " + mode)
base = resolve_base(base)
git.sandbox(
scope = scope,
base_ref = base,
Expand Down
Loading
Loading