MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestBuild

Function TestBuild

internal/aiagentconfig/builder_test.go:34–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestBuild(t *testing.T) {
35 rootDir := t.TempDir()
36
37 // Create test files
38 file1Content := []byte("# Project Rules\nAlways use Go.")
39 file2Content := []byte(`{"allow": ["read"]}`)
40
41 require.NoError(t, os.WriteFile(filepath.Join(rootDir, "CLAUDE.md"), file1Content, 0o600))
42 require.NoError(t, os.MkdirAll(filepath.Join(rootDir, ".claude"), 0o755))
43 require.NoError(t, os.WriteFile(filepath.Join(rootDir, ".claude", "settings.json"), file2Content, 0o600))
44
45 gitCtx := &GitContext{
46 Repository: "https://github.com/org/repo",
47 CommitSHA: "abc123",
48 }
49
50 data, err := Build(rootDir, []DiscoveredFile{
51 {Path: "CLAUDE.md", Kind: ConfigFileKindInstruction},
52 {Path: ".claude/settings.json", Kind: ConfigFileKindConfiguration},
53 }, "claude", gitCtx)
54 require.NoError(t, err)
55
56 assert.Equal(t, "claude", data.Agent.Name)
57 assert.NotEmpty(t, data.ConfigHash)
58
59 // Verify git context
60 require.NotNil(t, data.GitContext)
61 assert.Equal(t, "https://github.com/org/repo", data.GitContext.Repository)
62 assert.Equal(t, "abc123", data.GitContext.CommitSHA)
63
64 // Verify config files
65 require.Len(t, data.ConfigFiles, 2)
66
67 cf1 := data.ConfigFiles[0]
68 assert.Equal(t, "CLAUDE.md", cf1.Path)
69 assert.Equal(t, ConfigFileKindInstruction, cf1.Kind)
70 assert.Equal(t, int64(len(file1Content)), cf1.Size)
71 hash1 := sha256.Sum256(file1Content)
72 assert.Equal(t, hex.EncodeToString(hash1[:]), cf1.SHA256)
73 assert.Equal(t, base64.StdEncoding.EncodeToString(file1Content), cf1.Content)
74
75 cf2 := data.ConfigFiles[1]
76 assert.Equal(t, ".claude/settings.json", cf2.Path)
77 assert.Equal(t, ConfigFileKindConfiguration, cf2.Kind)
78 hash2 := sha256.Sum256(file2Content)
79 assert.Equal(t, hex.EncodeToString(hash2[:]), cf2.SHA256)
80
81 // Verify config hash is deterministic (includes path:hash for rename detection)
82 hashes := []string{
83 fmt.Sprintf("CLAUDE.md:%s", hex.EncodeToString(hash1[:])),
84 fmt.Sprintf(".claude/settings.json:%s", hex.EncodeToString(hash2[:])),
85 }
86 sort.Strings(hashes)
87 combined := sha256.Sum256([]byte(strings.Join(hashes, "")))
88 assert.Equal(t, hex.EncodeToString(combined[:]), data.ConfigHash)
89}
90
91func TestBuildWithCursorAgent(t *testing.T) {

Callers

nothing calls this directly

Calls 2

BuildFunction · 0.85
StringsMethod · 0.80

Tested by

no test coverage detected