Skip to content

Commit d398583

Browse files
committed
update with new agent standards
1 parent 6267cb2 commit d398583

13 files changed

Lines changed: 29 additions & 145 deletions

File tree

‎src/cmd/cmd_suite_test.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ func verifyClusterGroupValues(valuesFile string, expectedClusterGroupValues *typ
124124
}
125125

126126
func createTestDir() string {
127-
dir, err := os.MkdirTemp("", "patternizer-test")
128-
Expect(err).NotTo(HaveOccurred())
129-
return dir
127+
return GinkgoT().TempDir()
130128
}
131129

132130
func runCLI(dir string, args ...string) *gexec.Session {

‎src/cmd/init.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,21 @@ import (
1313

1414
// runInit handles the initialization logic for the init command.
1515
func runInit(withSecrets bool) error {
16-
// Get pattern name and repository root
1716
patternName, repoRoot, err := pattern.GetPatternNameAndRepoRoot()
1817
if err != nil {
1918
return fmt.Errorf("error getting pattern information: %w", err)
2019
}
2120

22-
// Find Helm charts in the repository
2321
chartPaths, err := helm.FindTopLevelCharts(repoRoot)
2422
if err != nil {
2523
return fmt.Errorf("error finding Helm charts: %w", err)
2624
}
2725

28-
// Process values-global.yaml
2926
actualPatternName, clusterGroupName, err := pattern.ProcessGlobalValues(patternName, repoRoot, withSecrets)
3027
if err != nil {
3128
return fmt.Errorf("error processing global values: %w", err)
3229
}
3330

34-
// Process cluster group values using the actual pattern name and cluster group name from the global values
3531
if err := pattern.ProcessClusterGroupValues(actualPatternName, clusterGroupName, repoRoot, chartPaths, withSecrets); err != nil {
3632
return fmt.Errorf("error processing cluster group values: %w", err)
3733
}

‎src/cmd/init_test.go‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ var _ = Describe("patternizer init", func() {
6161
_ = runCLI(tempDir, "init")
6262
})
6363

64-
AfterAll(func() {
65-
os.RemoveAll(tempDir)
66-
})
67-
6864
It("should copy the common pattern scaffold files", func() {
6965
verifyScaffoldFilesCopied(tempDir)
7066
})
@@ -118,10 +114,6 @@ var _ = Describe("patternizer init", func() {
118114
_ = runCLI(tempDir, "init")
119115
})
120116

121-
AfterAll(func() {
122-
os.RemoveAll(tempDir)
123-
})
124-
125117
It("should copy the common pattern scaffold files", func() {
126118
verifyScaffoldFilesCopied(tempDir)
127119
})
@@ -182,10 +174,6 @@ var _ = Describe("patternizer init", func() {
182174
_ = runCLI(tempDir, "init")
183175
})
184176

185-
AfterAll(func() {
186-
os.RemoveAll(tempDir)
187-
})
188-
189177
It("should copy the common pattern scaffold files", func() {
190178
verifyScaffoldFilesCopied(tempDir)
191179
})
@@ -235,10 +223,6 @@ var _ = Describe("patternizer init", func() {
235223
_ = runCLI(tempDir, "init")
236224
})
237225

238-
AfterAll(func() {
239-
os.RemoveAll(tempDir)
240-
})
241-
242226
It("should copy the common pattern scaffold files", func() {
243227
verifyScaffoldFilesCopied(tempDir)
244228
})
@@ -297,10 +281,6 @@ var _ = Describe("patternizer init", func() {
297281
_ = runCLI(tempDir, "init")
298282
})
299283

300-
AfterAll(func() {
301-
os.RemoveAll(tempDir)
302-
})
303-
304284
It("should respect the explicit singleArgoCD override", func() {
305285
globalValuesFile := filepath.Join(tempDir, "values-global.yaml")
306286
expectedGlobalValues := types.ValuesGlobal{
@@ -333,10 +313,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
333313
_ = runCLI(tempDir, "init", "--with-secrets")
334314
})
335315

336-
AfterAll(func() {
337-
os.RemoveAll(tempDir)
338-
})
339-
340316
It("should copy the common pattern scaffold files", func() {
341317
verifyScaffoldFilesCopied(tempDir)
342318
})
@@ -419,10 +395,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
419395
_ = runCLI(tempDir, "init", "--with-secrets")
420396
})
421397

422-
AfterAll(func() {
423-
os.RemoveAll(tempDir)
424-
})
425-
426398
It("should copy the common pattern scaffold files", func() {
427399
verifyScaffoldFilesCopied(tempDir)
428400
})
@@ -515,10 +487,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
515487
_ = runCLI(tempDir, "init", "--with-secrets")
516488
})
517489

518-
AfterAll(func() {
519-
os.RemoveAll(tempDir)
520-
})
521-
522490
It("should copy the common pattern scaffold files", func() {
523491
verifyScaffoldFilesCopied(tempDir)
524492
})
@@ -602,10 +570,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
602570
_ = runCLI(tempDir, "init", "--with-secrets")
603571
})
604572

605-
AfterAll(func() {
606-
os.RemoveAll(tempDir)
607-
})
608-
609573
It("should copy the secrets template file", func() {
610574
verifySecretTemplateCopied(tempDir)
611575
})
@@ -695,10 +659,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
695659
_ = runCLI(tempDir, "init", "--with-secrets")
696660
})
697661

698-
AfterAll(func() {
699-
os.RemoveAll(tempDir)
700-
})
701-
702662
It("should copy the common pattern scaffold files", func() {
703663
verifyScaffoldFilesCopied(tempDir)
704664
})
@@ -789,10 +749,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
789749
_ = runCLI(tempDir, "init", "--with-secrets")
790750
})
791751

792-
AfterAll(func() {
793-
os.RemoveAll(tempDir)
794-
})
795-
796752
It("should not modify the secrets template file", func() {
797753
actual, err := os.ReadFile(filepath.Join(tempDir, "values-secret.yaml.template"))
798754
Expect(err).NotTo(HaveOccurred())

‎src/cmd/root.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ for a validated pattern, including values-global.yaml and values-<clustergroup>.
2929
When --with-secrets is specified, it also copies the secrets template and
3030
configures the pattern.sh script for secrets usage.`,
3131
RunE: func(cmd *cobra.Command, args []string) error {
32-
// Check if "help" is passed as an argument
3332
if len(args) > 0 && args[0] == "help" {
3433
return cmd.Help()
3534
}

‎src/cmd/upgrade.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@ import (
1212

1313
// runUpgrade handles the upgrade logic for the upgrade command.
1414
func runUpgrade(replaceMakefile bool) error {
15-
// Determine repository root
1615
_, repoRoot, err := pattern.GetPatternNameAndRepoRoot()
1716
if err != nil {
1817
return fmt.Errorf("error getting pattern information: %w", err)
1918
}
2019

21-
// Paths
2220
commonDirPath := filepath.Join(repoRoot, "common")
2321
patternShPath := filepath.Join(repoRoot, "pattern.sh")
2422

25-
// Remove common/ directory if it exists
2623
if err := fileutils.RemovePathIfExists(commonDirPath); err != nil {
2724
return fmt.Errorf("error removing common directory: %w", err)
2825
}
2926

30-
// Remove ./pattern.sh if it exists (symlink or file)
3127
if err := fileutils.RemovePathIfExists(patternShPath); err != nil {
3228
return fmt.Errorf("error removing pattern.sh: %w", err)
3329
}

‎src/cmd/upgrade_test.go‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ var _ = Describe("patternizer upgrade", func() {
5151
_ = runCLI(tempDir, "upgrade")
5252
})
5353

54-
AfterAll(func() {
55-
os.RemoveAll(tempDir)
56-
})
57-
5854
It("should copy the common scaffold files (except Makefile)", func() {
5955
verifyPattenShCopied(tempDir)
6056
verifyMakefileCommonCopied(tempDir)
@@ -92,10 +88,6 @@ var _ = Describe("patternizer upgrade", func() {
9288
_ = runCLI(tempDir, "upgrade")
9389
})
9490

95-
AfterAll(func() {
96-
os.RemoveAll(tempDir)
97-
})
98-
9991
It("should not update Makefiles that already include Makefile-common", func() {
10092
f, err := os.ReadFile(filepath.Join(tempDir, "Makefile"))
10193
Expect(err).NotTo(HaveOccurred())
@@ -115,10 +107,6 @@ var _ = Describe("patternizer upgrade --replace-makefile", func() {
115107
_ = runCLI(tempDir, "upgrade", "--replace-makefile")
116108
})
117109

118-
AfterAll(func() {
119-
os.RemoveAll(tempDir)
120-
})
121-
122110
It("should update the common scaffold files (including Makefile)", func() {
123111
verifyScaffoldFilesCopied(tempDir)
124112
})

‎src/internal/embedded/embedded.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package embedded
22

33
import "embed"
44

5+
// Resources holds the embedded resources directory tree (pattern.sh, Makefile, etc.).
6+
//
57
//go:embed resources/*
68
var Resources embed.FS
79

10+
// Skills holds the embedded skills directory tree for IDE integrations.
11+
//
812
//go:embed all:skills
913
var Skills embed.FS

‎src/internal/fileutils/fileutils.go‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func CopyFile(src, dst string) error {
1717
sourceFileStat, err := os.Stat(src)
1818
if err != nil {
19-
return err
19+
return fmt.Errorf("stat source file %s: %w", src, err)
2020
}
2121

2222
if !sourceFileStat.Mode().IsRegular() {
@@ -25,25 +25,24 @@ func CopyFile(src, dst string) error {
2525

2626
sourceFile, err := os.Open(src)
2727
if err != nil {
28-
return err
28+
return fmt.Errorf("open source file %s: %w", src, err)
2929
}
3030
defer sourceFile.Close()
3131

3232
destinationFile, err := os.Create(dst)
3333
if err != nil {
34-
return err
34+
return fmt.Errorf("create destination file %s: %w", dst, err)
3535
}
3636
defer destinationFile.Close()
3737

3838
_, err = io.Copy(destinationFile, sourceFile)
3939
if err != nil {
40-
return err
40+
return fmt.Errorf("copy to %s: %w", dst, err)
4141
}
4242

43-
// Preserve the file permissions from the source file
4443
err = os.Chmod(dst, sourceFileStat.Mode())
4544
if err != nil {
46-
return err
45+
return fmt.Errorf("chmod %s: %w", dst, err)
4746
}
4847

4948
return nil
@@ -69,7 +68,7 @@ func WriteEmbeddedFile(fsys fs.FS, srcPath, dstPath string, mode os.FileMode) er
6968
return fmt.Errorf("reading embedded file %s: %w", srcPath, err)
7069
}
7170
if err := os.WriteFile(dstPath, data, mode); err != nil {
72-
return err
71+
return fmt.Errorf("write file %s: %w", dstPath, err)
7372
}
7473
return os.Chmod(dstPath, mode)
7574
}
@@ -78,11 +77,11 @@ func WriteEmbeddedFile(fsys fs.FS, srcPath, dstPath string, mode os.FileMode) er
7877
func WriteEmbeddedDir(fsys fs.FS, srcDir, dstDir string) error {
7978
return fs.WalkDir(fsys, srcDir, func(path string, d fs.DirEntry, err error) error {
8079
if err != nil {
81-
return err
80+
return fmt.Errorf("walk embedded dir: %w", err)
8281
}
8382
relPath, err := filepath.Rel(srcDir, path)
8483
if err != nil {
85-
return err
84+
return fmt.Errorf("compute relative path for %s: %w", path, err)
8685
}
8786
target := filepath.Join(dstDir, relPath)
8887

@@ -99,19 +98,19 @@ func WriteEmbeddedDir(fsys fs.FS, srcDir, dstDir string) error {
9998
func CopyDir(src, dst string) error {
10099
srcInfo, err := os.Stat(src)
101100
if err != nil {
102-
return err
101+
return fmt.Errorf("stat source dir %s: %w", src, err)
103102
}
104103
if !srcInfo.IsDir() {
105104
return fmt.Errorf("%s is not a directory", src)
106105
}
107106

108107
if err := os.MkdirAll(dst, 0o755); err != nil {
109-
return err
108+
return fmt.Errorf("create destination dir %s: %w", dst, err)
110109
}
111110

112111
entries, err := os.ReadDir(src)
113112
if err != nil {
114-
return err
113+
return fmt.Errorf("read source dir %s: %w", src, err)
115114
}
116115

117116
for _, entry := range entries {
@@ -120,11 +119,11 @@ func CopyDir(src, dst string) error {
120119

121120
if entry.IsDir() {
122121
if err := CopyDir(srcPath, dstPath); err != nil {
123-
return err
122+
return fmt.Errorf("copy subdir %s: %w", entry.Name(), err)
124123
}
125124
} else {
126125
if err := CopyFile(srcPath, dstPath); err != nil {
127-
return err
126+
return fmt.Errorf("copy file %s: %w", entry.Name(), err)
128127
}
129128
}
130129
}
@@ -143,7 +142,7 @@ func RemovePathIfExists(targetPath string) error {
143142
if os.IsNotExist(err) {
144143
return nil
145144
}
146-
return err
145+
return fmt.Errorf("lstat %s: %w", targetPath, err)
147146
}
148147

149148
if info.IsDir() {
@@ -157,7 +156,7 @@ func RemovePathIfExists(targetPath string) error {
157156
func FileContainsIncludeMakefileCommon(makefilePath string) (bool, error) {
158157
data, err := os.ReadFile(makefilePath)
159158
if err != nil {
160-
return false, err
159+
return false, fmt.Errorf("read %s: %w", makefilePath, err)
161160
}
162161
contents := string(data)
163162
// We keep this simple to avoid regex: look for lines with 'include' and 'Makefile-common'
@@ -177,7 +176,7 @@ func FileContainsIncludeMakefileCommon(makefilePath string) (bool, error) {
177176
func PrependLineToFile(filePath, line string) error {
178177
data, err := os.ReadFile(filePath)
179178
if err != nil {
180-
return err
179+
return fmt.Errorf("read %s: %w", filePath, err)
181180
}
182181

183182
mode := os.FileMode(0o644)
@@ -208,7 +207,6 @@ func WriteYAMLWithIndent(data interface{}, filePath string) error {
208207
return fmt.Errorf("failed to encode YAML to %s: %w", filePath, err)
209208
}
210209

211-
// Set file permissions to 0644
212210
if err := os.Chmod(filePath, 0o644); err != nil {
213211
return fmt.Errorf("failed to set permissions on %s: %w", filePath, err)
214212
}

‎src/internal/fileutils/skills.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
var skillTargets = []string{".claude", ".cursor"}
1212

13+
// InstallSkills copies all embedded skill directories into the .claude and .cursor skill directories under the given repository root.
1314
func InstallSkills(repoRoot string) error {
1415
entries, err := fs.ReadDir(embedded.Skills, "skills")
1516
if err != nil {

0 commit comments

Comments
 (0)