Link in, card, download, send, in private chats and groups. - cmd/core with an embedded download worker - Telegram front end on telego v1.13.0 (Bot API 10.4): link card with thumbnail and format buttons, one live status message, /dl /audio /thumb /info /queue /cancel, group support with requester-only buttons - Database backed queue: paid and free lanes, leases with heartbeats, one automatic retry, cancel, queue position and wait estimate - yt-dlp and ffprobe behind a Runner interface with classified, redacted errors mapped to friendly messages - SQLite via modernc with goose migrations, portable schema - Local file storage behind a Storage interface - go-i18n with an English catalog, no literal text in handlers - Free tier limits enforced before queueing and again on the real file - Bot token and webhook secret are stripped from all log output - Tests: URL parsing, job lifecycle, worker, yt-dlp wrapper, and end to end flows against a fake Bot API server; opt-in test with the real yt-dlp Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
// Package repocheck holds tests that guard repository-wide rules.
|
|
package repocheck
|
|
|
|
import (
|
|
"bufio"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// textExt lists the file types that are checked.
|
|
var textExt = map[string]bool{
|
|
".go": true, ".md": true, ".toml": true, ".sql": true, ".yml": true, ".yaml": true,
|
|
".sh": true, ".example": true, ".service": true, ".ts": true, ".tsx": true,
|
|
".css": true, ".html": true, ".json": true, ".txt": true, "": true,
|
|
}
|
|
|
|
var skipDirs = map[string]bool{
|
|
".git": true, ".tools": true, "node_modules": true, "dist": true, "data": true, "bin": true,
|
|
}
|
|
|
|
func repoRoot(t *testing.T) string {
|
|
t.Helper()
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for {
|
|
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
|
return dir
|
|
}
|
|
parent := filepath.Dir(dir)
|
|
if parent == dir {
|
|
t.Fatal("go.mod not found")
|
|
}
|
|
dir = parent
|
|
}
|
|
}
|
|
|
|
// TestNoEmDashes enforces the project rule that no text uses em dashes:
|
|
// not code comments, not docs, not translations.
|
|
func TestNoEmDashes(t *testing.T) {
|
|
root := repoRoot(t)
|
|
const emDash = "\u2014"
|
|
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.IsDir() {
|
|
if skipDirs[d.Name()] {
|
|
return filepath.SkipDir
|
|
}
|
|
return nil
|
|
}
|
|
if !textExt[filepath.Ext(path)] || d.Name() == "package-lock.json" {
|
|
return nil
|
|
}
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
sc := bufio.NewScanner(f)
|
|
sc.Buffer(make([]byte, 64*1024), 4*1024*1024)
|
|
for n := 1; sc.Scan(); n++ {
|
|
if strings.Contains(sc.Text(), emDash) {
|
|
rel, _ := filepath.Rel(root, path)
|
|
t.Errorf("%s:%d contains an em dash", rel, n)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|