Files
awesome-coding-agents/readme_test.go
T
tiennm99 62cbdd7a4a fix: harden GitHub fetcher and history I/O, add canonical keying
GitHub fetcher (github.go):
- add 30s HTTP client timeout (was http.DefaultClient with no bound)
- chunk GraphQL alias requests at 50 repos to stay clear of abuse detection
- abort the run on any partial GraphQL error or missing repo rather than
  silently shrinking the README and poisoning the next delta
- retry transient failures (network, 5xx, 429) with 2s/4s/8s backoff

History layer (history.go):
- key snapshots by canonical owner/repo from agents.yml instead of the
  rename-resolved NameWithOwner returned by the API; carry a lazy
  migration map so existing aaif-goose/goose entries fold into block/goose
  on next read with no manual data edit
- tighten the 7d delta window to (cutoff-3d, cutoff] so a missed cron week
  no longer mislabels a 90d-old comparison as Delta7d
- replace the snapshots[:0] aliased filter loop with slices.DeleteFunc
- log malformed JSONL lines to stderr with line numbers instead of
  silently skipping them
- write history.jsonl atomically via tmp file + rename so a crash
  mid-write can no longer truncate accumulated history

Plus collapse a few redundant fmt.Errorf wraps, drop a named Config type
that was used once, inline the single-call sortByStars helper with a
deterministic tiebreaker on canonical key, and use filepath.Base instead
of hand-rolling a basename.

Includes unit tests covering the 7d window edges, canonical-key
migration, atomic write path, malformed-line tolerance, YAML validation,
and markdown cell escaping.
2026-05-14 15:49:05 +07:00

97 lines
2.0 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",
},
}
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)
}
})
}
}