mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-18 16:07:31 +08:00
feat: add session auto-planning and resource-based concurrency scheduling
This commit is contained in:
49
pkg/scheduling/resource_keys_test.go
Normal file
49
pkg/scheduling/resource_keys_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package scheduling
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestExtractResourceKeysDirective(t *testing.T) {
|
||||
keys, cleaned, ok := ExtractResourceKeysDirective("[resource_keys: repo:acme/app,file:pkg/a.go]\nplease check")
|
||||
if !ok {
|
||||
t.Fatalf("expected directive")
|
||||
}
|
||||
if len(keys) != 2 || keys[0] != "repo:acme/app" || keys[1] != "file:pkg/a.go" {
|
||||
t.Fatalf("unexpected keys: %#v", keys)
|
||||
}
|
||||
if cleaned != "please check" {
|
||||
t.Fatalf("unexpected cleaned content: %q", cleaned)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeriveResourceKeysHeuristic(t *testing.T) {
|
||||
keys := DeriveResourceKeys("update pkg/agent/loop.go on main")
|
||||
if len(keys) == 0 {
|
||||
t.Fatalf("expected non-empty keys")
|
||||
}
|
||||
foundFile := false
|
||||
foundBranch := false
|
||||
for _, k := range keys {
|
||||
if k == "file:pkg/agent/loop.go" {
|
||||
foundFile = true
|
||||
}
|
||||
if k == "branch:main" {
|
||||
foundBranch = true
|
||||
}
|
||||
}
|
||||
if !foundFile {
|
||||
t.Fatalf("expected file key in %#v", keys)
|
||||
}
|
||||
if !foundBranch {
|
||||
t.Fatalf("expected branch key in %#v", keys)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseResourceKeyListAddsFilePrefix(t *testing.T) {
|
||||
keys := ParseResourceKeyList("pkg/a.go, repo:acme/app")
|
||||
if len(keys) != 2 {
|
||||
t.Fatalf("unexpected len: %#v", keys)
|
||||
}
|
||||
if keys[0] != "file:pkg/a.go" && keys[1] != "file:pkg/a.go" {
|
||||
t.Fatalf("expected file-prefixed key in %#v", keys)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user