Skip to content

Commit 24676b2

Browse files
authored
Qualify default repo-memory branch by workflow ID (#17657)
1 parent 7b23ef8 commit 24676b2

4 files changed

Lines changed: 43 additions & 26 deletions

File tree

‎.github/workflows/daily-code-metrics.lock.yml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/workflow/compiler_orchestrator_workflow.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func (c *Compiler) extractAdditionalConfigurations(
449449
if err != nil {
450450
return err
451451
}
452-
repoMemoryConfig, err := c.extractRepoMemoryConfig(toolsConfig)
452+
repoMemoryConfig, err := c.extractRepoMemoryConfig(toolsConfig, workflowData.WorkflowID)
453453
if err != nil {
454454
return err
455455
}

‎pkg/workflow/repo_memory.go‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ func validateBranchPrefix(prefix string) error {
9696
return nil
9797
}
9898

99-
// extractRepoMemoryConfig extracts repo-memory configuration from tools section
100-
func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemoryConfig, error) {
99+
// extractRepoMemoryConfig extracts repo-memory configuration from tools section.
100+
// workflowID is used to qualify the default branch name (e.g. "memory/{workflowID}").
101+
func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig, workflowID string) (*RepoMemoryConfig, error) {
101102
// Check if repo-memory tool is configured
102103
if toolsConfig == nil || toolsConfig.RepoMemory == nil {
103104
return nil, nil
@@ -110,13 +111,22 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
110111
}
111112
repoMemoryValue := toolsConfig.RepoMemory.Raw
112113

114+
// defaultMemoryBranchID returns workflowID when set, otherwise "default".
115+
// This qualifies the default branch name by workflow, e.g. "memory/repo-assist".
116+
defaultMemoryBranchID := func() string {
117+
if workflowID != "" {
118+
return workflowID
119+
}
120+
return "default"
121+
}
122+
113123
// Handle nil value (simple enable with defaults) - same as true
114124
if repoMemoryValue == nil {
115125
repoMemoryLog.Print("Using default repo-memory configuration (nil value)")
116126
config.Memories = []RepoMemoryEntry{
117127
{
118128
ID: "default",
119-
BranchName: generateDefaultBranchName("default", config.BranchPrefix),
129+
BranchName: generateDefaultBranchName(defaultMemoryBranchID(), config.BranchPrefix),
120130
MaxFileSize: 10240, // 10KB
121131
MaxFileCount: 100,
122132
CreateOrphan: true,
@@ -134,7 +144,7 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
134144
config.Memories = []RepoMemoryEntry{
135145
{
136146
ID: "default",
137-
BranchName: generateDefaultBranchName("default", config.BranchPrefix),
147+
BranchName: generateDefaultBranchName(defaultMemoryBranchID(), config.BranchPrefix),
138148
MaxFileSize: 10240, // 10KB
139149
MaxFileCount: 100,
140150
CreateOrphan: true,
@@ -178,9 +188,11 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
178188
}
179189

180190
// ID is required for array notation
191+
explicitID := false
181192
if id, exists := memoryMap["id"]; exists {
182193
if idStr, ok := id.(string); ok {
183194
entry.ID = idStr
195+
explicitID = true
184196
}
185197
}
186198
// Use "default" if no ID specified
@@ -201,9 +213,14 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
201213
entry.BranchName = branchStr
202214
}
203215
}
204-
// Set default branch name if not specified
216+
// Set default branch name if not specified.
217+
// When no explicit ID was provided (defaulted to "default"), qualify the branch by workflow ID.
205218
if entry.BranchName == "" {
206-
entry.BranchName = generateDefaultBranchName(entry.ID, config.BranchPrefix)
219+
branchID := entry.ID
220+
if !explicitID {
221+
branchID = defaultMemoryBranchID()
222+
}
223+
entry.BranchName = generateDefaultBranchName(branchID, config.BranchPrefix)
207224
}
208225

209226
// Parse file-glob
@@ -311,7 +328,7 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
311328

312329
entry := RepoMemoryEntry{
313330
ID: "default",
314-
BranchName: generateDefaultBranchName("default", config.BranchPrefix),
331+
BranchName: generateDefaultBranchName(defaultMemoryBranchID(), config.BranchPrefix),
315332
MaxFileSize: 10240, // 10KB default
316333
MaxFileCount: 100, // 100 files default
317334
CreateOrphan: true, // create orphan by default

‎pkg/workflow/repo_memory_test.go‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestRepoMemoryConfigDefault(t *testing.T) {
2222
}
2323

2424
compiler := NewCompiler()
25-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
25+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "my-workflow")
2626
if err != nil {
2727
t.Fatalf("Failed to extract repo-memory config: %v", err)
2828
}
@@ -40,8 +40,8 @@ func TestRepoMemoryConfigDefault(t *testing.T) {
4040
t.Errorf("Expected ID 'default', got '%s'", memory.ID)
4141
}
4242

43-
if memory.BranchName != "memory/default" {
44-
t.Errorf("Expected branch name 'memory/default', got '%s'", memory.BranchName)
43+
if memory.BranchName != "memory/my-workflow" {
44+
t.Errorf("Expected branch name 'memory/my-workflow', got '%s'", memory.BranchName)
4545
}
4646

4747
if memory.MaxFileSize != 10240 {
@@ -74,7 +74,7 @@ func TestRepoMemoryConfigObject(t *testing.T) {
7474
}
7575

7676
compiler := NewCompiler()
77-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
77+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
7878
if err != nil {
7979
t.Fatalf("Failed to extract repo-memory config: %v", err)
8080
}
@@ -127,7 +127,7 @@ func TestRepoMemoryConfigArray(t *testing.T) {
127127
}
128128

129129
compiler := NewCompiler()
130-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
130+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
131131
if err != nil {
132132
t.Fatalf("Failed to extract repo-memory config: %v", err)
133133
}
@@ -183,7 +183,7 @@ func TestRepoMemoryConfigDuplicateIDs(t *testing.T) {
183183
}
184184

185185
compiler := NewCompiler()
186-
_, err = compiler.extractRepoMemoryConfig(toolsConfig)
186+
_, err = compiler.extractRepoMemoryConfig(toolsConfig, "")
187187
if err == nil {
188188
t.Fatal("Expected error for duplicate memory IDs, got nil")
189189
}
@@ -395,7 +395,7 @@ func TestRepoMemoryMaxFileSizeValidation(t *testing.T) {
395395
}
396396

397397
compiler := NewCompiler()
398-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
398+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
399399

400400
if tt.wantError {
401401
if err == nil {
@@ -465,7 +465,7 @@ func TestRepoMemoryMaxFileSizeValidationArray(t *testing.T) {
465465
}
466466

467467
compiler := NewCompiler()
468-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
468+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
469469

470470
if tt.wantError {
471471
if err == nil {
@@ -554,7 +554,7 @@ func TestRepoMemoryMaxFileCountValidation(t *testing.T) {
554554
}
555555

556556
compiler := NewCompiler()
557-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
557+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
558558

559559
if tt.wantError {
560560
if err == nil {
@@ -624,7 +624,7 @@ func TestRepoMemoryMaxFileCountValidationArray(t *testing.T) {
624624
}
625625

626626
compiler := NewCompiler()
627-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
627+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
628628

629629
if tt.wantError {
630630
if err == nil {
@@ -778,15 +778,15 @@ func TestBranchPrefixInConfig(t *testing.T) {
778778
require.NoError(t, err, "Failed to parse tools config")
779779

780780
compiler := NewCompiler()
781-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
781+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "my-workflow")
782782
require.NoError(t, err, "Failed to extract repo-memory config")
783783
require.NotNil(t, config, "Expected non-nil config")
784784

785785
assert.Equal(t, "campaigns", config.BranchPrefix, "Expected branch-prefix 'campaigns'")
786786
assert.Len(t, config.Memories, 1, "Expected 1 memory")
787787

788788
memory := config.Memories[0]
789-
assert.Equal(t, "campaigns/default", memory.BranchName, "Expected branch name 'campaigns/default'")
789+
assert.Equal(t, "campaigns/my-workflow", memory.BranchName, "Expected branch name 'campaigns/my-workflow'")
790790
}
791791

792792
// TestBranchPrefixInArrayConfig tests branch-prefix in array configuration
@@ -807,7 +807,7 @@ func TestBranchPrefixInArrayConfig(t *testing.T) {
807807
require.NoError(t, err, "Failed to parse tools config")
808808

809809
compiler := NewCompiler()
810-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
810+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
811811
require.NoError(t, err, "Failed to extract repo-memory config")
812812
require.NotNil(t, config, "Expected non-nil config")
813813

@@ -832,7 +832,7 @@ func TestBranchPrefixWithExplicitBranchName(t *testing.T) {
832832
require.NoError(t, err, "Failed to parse tools config")
833833

834834
compiler := NewCompiler()
835-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
835+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
836836
require.NoError(t, err, "Failed to extract repo-memory config")
837837
require.NotNil(t, config, "Expected non-nil config")
838838

@@ -866,7 +866,7 @@ func TestInvalidBranchPrefixRejectsConfig(t *testing.T) {
866866
require.NoError(t, err, "Failed to parse tools config")
867867

868868
compiler := NewCompiler()
869-
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
869+
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
870870
require.Error(t, err, "Expected error for invalid branch-prefix: %s", tt.prefix)
871871
assert.Nil(t, config, "Expected nil config on error")
872872
})

0 commit comments

Comments
 (0)