-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathcache_memory_integration_test.go
More file actions
176 lines (165 loc) · 5.47 KB
/
Copy pathcache_memory_integration_test.go
File metadata and controls
176 lines (165 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//go:build integration
package workflow
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/github/gh-aw/pkg/stringutil"
"github.com/github/gh-aw/pkg/testutil"
)
func TestCacheMemoryMultipleIntegration(t *testing.T) {
tests := []struct {
name string
frontmatter string
expectedInLock []string
notExpectedInLock []string
}{
{
name: "single cache-memory (backward compatible)",
frontmatter: `---
name: Test Cache Memory Single
on: workflow_dispatch
permissions:
contents: read
issues: read
pull-requests: read
engine: claude
tools:
cache-memory: true
github:
allowed: [get_repository]
---`,
expectedInLock: []string{
"# Cache memory file share configuration from frontmatter processed below",
"- name: Create cache-memory directory",
"- name: Restore cache-memory file share data",
"uses: actions/cache@",
"key: memory-none-nopolicy-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
"path: /tmp/gh-aw/cache-memory",
"cat \"${RUNNER_TEMP}/gh-aw/prompts/cache_memory_prompt.md\"",
"GH_AW_CACHE_DIR: '`/tmp/gh-aw/cache-memory/`'",
"GH_AW_CACHE_DIR: process.env.GH_AW_CACHE_DIR",
},
notExpectedInLock: []string{
// Should NOT upload artifact when detection is disabled
"- name: Upload cache-memory data as artifact",
"cache_memory_prompt_multi.md", // Should not use multi template for default-only cache
"cache-memory/default/",
"cache-memory/session/",
},
},
{
name: "multiple cache-memory with array notation",
frontmatter: `---
name: Test Cache Memory Multiple
on: workflow_dispatch
permissions:
contents: read
issues: read
pull-requests: read
engine: claude
tools:
cache-memory:
- id: default
key: memory-default
- id: session
key: memory-session
github:
allowed: [get_repository]
---`,
expectedInLock: []string{
"# Cache memory file share configuration from frontmatter processed below",
"- name: Create cache-memory directory (default)",
"mkdir -p /tmp/gh-aw/cache-memory",
"- name: Restore cache-memory file share data (default)",
"key: memory-none-nopolicy-memory-default-${{ github.run_id }}",
"path: /tmp/gh-aw/cache-memory",
"- name: Create cache-memory directory (session)",
"mkdir -p /tmp/gh-aw/cache-memory-session",
"- name: Restore cache-memory file share data (session)",
"key: memory-none-nopolicy-memory-session-${{ github.run_id }}",
"path: /tmp/gh-aw/cache-memory-session",
"cache_memory_prompt_multi.md", // Template file reference for multiple caches
"- **default**: `/tmp/gh-aw/cache-memory/`",
"- **session**: `/tmp/gh-aw/cache-memory-session/`",
},
notExpectedInLock: []string{
// Should NOT upload artifacts when detection is disabled
"- name: Upload cache-memory data as artifact (default)",
"- name: Upload cache-memory data as artifact (session)",
"## Cache Folder Available",
},
},
{
name: "multiple cache-memory with custom keys",
frontmatter: `---
name: Test Cache Memory Multiple Custom Keys
on: workflow_dispatch
permissions:
contents: read
issues: read
pull-requests: read
engine: claude
tools:
cache-memory:
- id: data
key: memory-data-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}
- id: logs
key: memory-logs-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}
github:
allowed: [get_repository]
---`,
expectedInLock: []string{
"- name: Create cache-memory directory (data)",
"mkdir -p /tmp/gh-aw/cache-memory-data",
"key: memory-none-nopolicy-data-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
"path: /tmp/gh-aw/cache-memory-data",
"- name: Create cache-memory directory (logs)",
"mkdir -p /tmp/gh-aw/cache-memory-logs",
"key: memory-none-nopolicy-logs-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
"path: /tmp/gh-aw/cache-memory-logs",
"cache_memory_prompt_multi.md", // Template file reference for multiple caches
"- **data**: `/tmp/gh-aw/cache-memory-data/`",
"- **logs**: `/tmp/gh-aw/cache-memory-logs/`",
},
notExpectedInLock: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Create a temporary directory
tmpDir := testutil.TempDir(t, "test-*")
// Write the markdown file
mdPath := filepath.Join(tmpDir, "test-workflow.md")
content := tt.frontmatter + "\n\n# Test Workflow\n\nTest cache-memory configuration.\n"
if err := os.WriteFile(mdPath, []byte(content), 0644); err != nil {
t.Fatalf("Failed to write test markdown file: %v", err)
}
// Compile the workflow
compiler := NewCompiler()
if err := compiler.CompileWorkflow(mdPath); err != nil {
t.Fatalf("Failed to compile workflow: %v", err)
}
// Read the generated lock file
lockPath := stringutil.MarkdownToLockFile(mdPath)
lockContent, err := os.ReadFile(lockPath)
if err != nil {
t.Fatalf("Failed to read lock file: %v", err)
}
lockStr := string(lockContent)
// Check expected strings
for _, expected := range tt.expectedInLock {
if !strings.Contains(lockStr, expected) {
t.Errorf("Expected to find '%s' in lock file but it was missing.\nLock file content:\n%s", expected, lockStr)
}
}
// Check that unexpected strings are NOT present
for _, notExpected := range tt.notExpectedInLock {
if strings.Contains(lockStr, notExpected) {
t.Errorf("Did not expect to find '%s' in lock file but it was present.\nLock file content:\n%s", notExpected, lockStr)
}
}
})
}
}