Files
awesome-coding-agents/readme_test.go
T
tiennm99andGitHub 0d5e4b3266 feat: momentum metrics, agents.yml validation, drift detection, hardening (#9)
Review fixes:
- applyMigrations resolves chained renames deterministically (cycle guard)
- GraphQL errors name the failing owner/repo, not the alias
- sanitizeCell escapes backslash + angle brackets (README md/HTML injection)
- timeNow/graphqlURL seams; new httptest fetch tests, site + delta tests
  (coverage 30% -> 65.6%)

Features:
- delta30d computed from history; dashboard gains sortable D30d column
- README shows Top 7-day mover line
- 'go run . -check' validates agents.yml offline (dupes, categories,
  name patterns); wired into CI for contributor PRs
- isArchived + rename drift warnings in daily run; archived badge on
  dashboard (E2E found 3 archived repos: gpt-engineer, void, Roo-Code)
2026-08-09 03:26:01 +07:00

121 lines
2.8 KiB
Go

package main
import (
"testing"
)
func TestSanitizeCell(t *testing.T) {
tests := []struct {
name string
input string
expected string
desc string
}{
{
name: "plain text",
input: "hello world",
expected: "hello world",
desc: "unchanged",
},
{
name: "pipe char",
input: "foo | bar",
expected: "foo \\| bar",
desc: "pipe escaped",
},
{
name: "newline",
input: "line1\nline2",
expected: "line1 line2",
desc: "newline becomes space",
},
{
name: "carriage return",
input: "line1\rline2",
expected: "line1 line2",
desc: "carriage return becomes space",
},
{
name: "pipe and newline",
input: "foo | bar\nbaz",
expected: "foo \\| bar baz",
desc: "both handled correctly",
},
{
name: "empty string",
input: "",
expected: "",
desc: "empty string unchanged",
},
{
name: "multiple pipes",
input: "a | b | c",
expected: "a \\| b \\| c",
desc: "multiple pipes escaped",
},
{
name: "multiple newlines",
input: "line1\n\nline2",
expected: "line1 line2",
desc: "multiple newlines become spaces",
},
{
name: "whitespace trimming",
input: " text ",
expected: "text",
desc: "leading/trailing spaces trimmed",
},
{
name: "complex: whitespace, pipe, newline",
input: " foo | bar\nbaz ",
expected: "foo \\| bar baz",
desc: "all transformations applied",
},
{
name: "only newlines and pipes",
input: "|\n|",
expected: "\\| \\|",
desc: "pipes and newlines only",
},
{
name: "mixed line endings",
input: "line1\nline2\rline3",
expected: "line1 line2 line3",
desc: "both \\n and \\r converted",
},
{
name: "backslash then pipe",
input: `\|`,
expected: `\\\|`,
desc: "backslash escaped first so it can't neutralize the pipe escape (finding: literal backslash + unescaped pipe previously broke the table row)",
},
{
name: "lone backslash",
input: `a\b`,
expected: `a\\b`,
desc: "backslash doubled so Markdown doesn't interpret it as an escape",
},
{
name: "raw html img tag",
input: "<img src=x onerror=alert(1)>",
expected: "&lt;img src=x onerror=alert(1)&gt;",
desc: "angle brackets entity-escaped so raw HTML can't be injected from a third-party description",
},
{
name: "raw html script tag",
input: "<script>alert(1)</script>",
expected: "&lt;script&gt;alert(1)&lt;/script&gt;",
desc: "script tags neutralized via entity escaping",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := sanitizeCell(tt.input)
if result != tt.expected {
t.Errorf("%s: expected %q, got %q", tt.desc, tt.expected, result)
}
})
}
}