Update + signing of the binaries

This commit is contained in:
2025-12-15 00:46:20 +00:00
parent 4aab8af16f
commit 8423b6ada1
23 changed files with 269 additions and 983 deletions
-262
View File
@@ -144,217 +144,6 @@ func TestIsDocumentationFile(t *testing.T) {
}
}
func TestAnalyzePatch(t *testing.T) {
tests := []struct {
name string
patch string
expected PatchStats
}{
{
name: "simple additions",
patch: `@@ -1,3 +1,5 @@
context line
+func main() {
+ x := 5
+}`,
expected: PatchStats{
TotalAdditions: 3,
MeaningfulAdditions: 3,
},
},
{
name: "simple deletions",
patch: `@@ -1,5 +1,3 @@
context line
-func main() {
- x := 5
-}`,
expected: PatchStats{
TotalDeletions: 3,
MeaningfulDeletions: 3,
},
},
{
name: "mixed additions and deletions",
patch: `@@ -1,3 +1,3 @@
-old code
+new code`,
expected: PatchStats{
TotalAdditions: 1,
TotalDeletions: 1,
MeaningfulAdditions: 1,
MeaningfulDeletions: 1,
},
},
{
name: "comment only changes",
patch: `@@ -1,3 +1,5 @@
func main() {
+// This is a comment
+// Another comment
}`,
expected: PatchStats{
TotalAdditions: 2,
CommentAdditions: 2,
},
},
{
name: "whitespace only changes",
patch: `@@ -1,3 +1,5 @@
func main() {
+
+
}`,
expected: PatchStats{
TotalAdditions: 2,
WhitespaceAdditions: 2,
},
},
{
name: "mixed meaningful and non-meaningful",
patch: `@@ -1,5 +1,10 @@
func main() {
+// Add logging
+ x := 5
+
+ // Calculate result
+ result := x * 2
+
}`,
expected: PatchStats{
TotalAdditions: 6,
MeaningfulAdditions: 2, // x := 5 and result := x * 2
CommentAdditions: 2, // two comments
WhitespaceAdditions: 2, // two empty lines
},
},
{
name: "deleted comments",
patch: `@@ -1,5 +1,2 @@
func main() {
-// Old comment
-/* Block comment */
}`,
expected: PatchStats{
TotalDeletions: 2,
CommentDeletions: 2,
},
},
{
name: "python style comments",
patch: `@@ -1,3 +1,6 @@
def main():
+# This is a python comment
+"""This is a docstring"""
+ x = 5`,
expected: PatchStats{
TotalAdditions: 3,
MeaningfulAdditions: 1, // x = 5
CommentAdditions: 2, // # comment and docstring
},
},
{
name: "sql comments",
patch: `@@ -1,2 +1,4 @@
SELECT * FROM users
+-- This is a SQL comment
+WHERE id = 1`,
expected: PatchStats{
TotalAdditions: 2,
MeaningfulAdditions: 1, // WHERE clause
CommentAdditions: 1, // SQL comment
},
},
{
name: "empty patch",
patch: "",
expected: PatchStats{
TotalAdditions: 0,
TotalDeletions: 0,
MeaningfulAdditions: 0,
MeaningfulDeletions: 0,
},
},
{
name: "context only patch",
patch: `@@ -1,3 +1,3 @@
line 1
line 2
line 3`,
expected: PatchStats{
TotalAdditions: 0,
TotalDeletions: 0,
MeaningfulAdditions: 0,
MeaningfulDeletions: 0,
},
},
{
name: "header lines should be ignored",
patch: `--- a/file.go
+++ b/file.go
@@ -1,3 +1,4 @@
context
+new line`,
expected: PatchStats{
TotalAdditions: 1,
MeaningfulAdditions: 1,
},
},
{
name: "c-style block comment continuation",
patch: `@@ -1,2 +1,5 @@
code
+/*
+ * Block comment
+ */`,
expected: PatchStats{
TotalAdditions: 3,
CommentAdditions: 3,
},
},
{
name: "html comments",
patch: `@@ -1,2 +1,4 @@
<div>
+<!-- This is an HTML comment -->
+<p>Content</p>`,
expected: PatchStats{
TotalAdditions: 2,
MeaningfulAdditions: 1, // <p> tag
CommentAdditions: 1, // HTML comment
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := AnalyzePatch(tt.patch)
assert.Equal(t, tt.expected.TotalAdditions, result.TotalAdditions, "TotalAdditions")
assert.Equal(t, tt.expected.TotalDeletions, result.TotalDeletions, "TotalDeletions")
assert.Equal(t, tt.expected.MeaningfulAdditions, result.MeaningfulAdditions, "MeaningfulAdditions")
assert.Equal(t, tt.expected.MeaningfulDeletions, result.MeaningfulDeletions, "MeaningfulDeletions")
assert.Equal(t, tt.expected.CommentAdditions, result.CommentAdditions, "CommentAdditions")
assert.Equal(t, tt.expected.CommentDeletions, result.CommentDeletions, "CommentDeletions")
assert.Equal(t, tt.expected.WhitespaceAdditions, result.WhitespaceAdditions, "WhitespaceAdditions")
assert.Equal(t, tt.expected.WhitespaceDeletions, result.WhitespaceDeletions, "WhitespaceDeletions")
})
}
}
func TestAnalyzePatchSimple(t *testing.T) {
patch := `@@ -1,3 +1,6 @@
func main() {
+// comment
+ x := 5
+
+ y := 10
}`
adds, dels := AnalyzePatchSimple(patch)
assert.Equal(t, 2, adds, "meaningful additions (x := 5 and y := 10)")
assert.Equal(t, 0, dels, "meaningful deletions")
}
func TestIsMeaningfulLine(t *testing.T) {
tests := []struct {
name string
@@ -378,54 +167,3 @@ func TestIsMeaningfulLine(t *testing.T) {
})
}
}
func TestAnalyzePatch_RealWorldExample(t *testing.T) {
// Simulate a real-world Go file change
patch := `diff --git a/main.go b/main.go
index 1234567..abcdefg 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,15 @@ package main
import "fmt"
+// ProcessData handles data processing
+// It takes input and returns processed output
func ProcessData(input string) string {
+ // Validate input
+ if input == "" {
+ return ""
+ }
+
+ // Transform the data
+ result := strings.ToUpper(input)
- return input
+ return result
}`
stats := AnalyzePatch(patch)
// Count what's actually in the patch:
// Additions (lines starting with +, not +++):
// 1. +// ProcessData handles data processing -> comment
// 2. +// It takes input and returns processed output -> comment
// 3. + // Validate input -> comment
// 4. + if input == "" -> meaningful
// 5. + return "" -> meaningful
// 6. + } -> meaningful
// 7. + (empty line) -> whitespace
// 8. + // Transform the data -> comment
// 9. + result := strings.ToUpper(input) -> meaningful
// 10. + return result -> meaningful
// Total: 10 additions, 5 meaningful, 4 comments, 1 whitespace
// Deletions (lines starting with -, not ---):
// 1. - return input -> meaningful
// Total: 1 deletion, 1 meaningful
assert.Equal(t, 10, stats.TotalAdditions, "Total additions")
assert.Equal(t, 1, stats.TotalDeletions, "Total deletions")
assert.Equal(t, 5, stats.MeaningfulAdditions, "Meaningful additions")
assert.Equal(t, 1, stats.MeaningfulDeletions, "Meaningful deletions")
assert.Equal(t, 4, stats.CommentAdditions, "Comment additions")
assert.Equal(t, 1, stats.WhitespaceAdditions, "Whitespace additions")
}