Files
Media-download-telegram-bot/internal/repocheck/repocheck_test.go
T
MichilisandClaude Fable 5.2 4f11f939a0 Phase 6: Mini App
A Telegram Mini App served by the core under /app/, embedded in the binary.

- API under /app/api/ with initData validated (HMAC, age) on every call
- Pages: Home, Queue, Buy (target, product, invoice), History, Groups,
  group detail (Overview, Settings, Wallet, Usage) and Me
- Every action runs through the same service, billing and scheduler code
  as the chat, so limits, prices and admin checks are decided on the server
- Texts come from the catalog over the API; layout mirrors for RTL
- Front end in web/miniapp (Vite, React, TypeScript); the build is
  committed and guarded by a source hash test; the Docker image rebuilds it
- MINIAPP_ENABLED with an https PUBLIC_URL; entry points from /app, group
  settings and the over-limit offer
- Browser test (make miniapp-e2e) against a core in test mode
- Fix: each download attempt gets its own scratch directory, so a retry
  cannot lose its file to the cleanup of the failed attempt

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 10:27:20 +00:00

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, ".mjs": 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)
}
}