mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
feat(canonical): validate profile name, apply env-var substitution before render
This commit is contained in:
@@ -30,3 +30,43 @@ func TestApplyDryRun(t *testing.T) {
|
||||
|
||||
assert.Contains(t, buf.String(), "dry-run")
|
||||
}
|
||||
|
||||
// TestApplyRefusesIncompleteProfile: apply must error when gateway.url or
|
||||
// gateway.default_model is empty.
|
||||
func TestApplyRefusesIncompleteProfile(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, "config.yaml"), []byte("active_profile: bad\n"), 0o600))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, "profiles"), 0o750))
|
||||
// Profile with empty url and default_model.
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, "profiles", "bad.yaml"),
|
||||
[]byte("name: bad\ngateway:\n url: \"\"\n token: dummy\n default_model: \"\"\nmodels: []\n"), 0o600))
|
||||
|
||||
reg := adapter.NewRegistry()
|
||||
reg.Register(&detectableAdapter{name: "stub", detect: true})
|
||||
|
||||
cmd := NewApply(reg)
|
||||
cmd.SetArgs([]string{"--root", root})
|
||||
err := cmd.Execute()
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "incomplete")
|
||||
}
|
||||
|
||||
// TestApplyAllowIncompleteFlag: --allow-incomplete bypasses the gateway check.
|
||||
func TestApplyAllowIncompleteFlag(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, "config.yaml"), []byte("active_profile: bad\n"), 0o600))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, "profiles"), 0o750))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, "profiles", "bad.yaml"),
|
||||
[]byte("name: bad\ngateway:\n url: \"\"\n token: dummy\n default_model: \"\"\nmodels: []\n"), 0o600))
|
||||
|
||||
reg := adapter.NewRegistry()
|
||||
reg.Register(&detectableAdapter{name: "stub", detect: true})
|
||||
|
||||
var buf bytes.Buffer
|
||||
cmd := NewApply(reg)
|
||||
cmd.SetOut(&buf)
|
||||
// --yes skips first-run prompt; --allow-incomplete skips gateway check.
|
||||
cmd.SetArgs([]string{"--root", root, "--dry-run", "--allow-incomplete", "--yes"})
|
||||
require.NoError(t, cmd.Execute())
|
||||
assert.Contains(t, buf.String(), "dry-run")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user