Files
juliusbrussee__caveman/engine/detect_html_test.go
Julius Brussee 82864c8f4c feat: ship Caveman 2.0.0 — engine, proxy, SDKs, unified CLI
Single-commit port of the Caveman 2 tree onto the original repo history
(candidate caveman-2@88878a4 applied over main@3098342). No unrelated-history
merge; original history untouched.

Preserved v1 surfaces:
- skills/caveman/SKILL.md byte-for-byte, plus plugin mirror and caveman.skill zip
- legacy CI (Node 18/20/22 installer + Python 3.11 suites) alongside engine-ci
- cli/install.js compatibility shim forwarding to bin/install.js
- .codex/config.toml ships both hooks and codex_hooks for older Codex (#617)
- README Trendshift + Skills.sh badges and local star-history asset
- v1.10.0-pinned curl installs; benchmarks/tmp-starcharts ignore rules

Fixed for public same-repo release:
- SECURITY.md vulnerability reporting points at this repository
- release-binaries.yml publishes to this repo via job-scoped GITHUB_TOKEN
  (cross-repo PAT removed); binary-release environment still gates signing
- packages/cli/PUBLISHING.md rewritten for packages/ layout and same-repo flow
- profile-contract and provider-catalog lanes skip lane-scope gates on
  initial import so the launch PR can gate on their real validation steps
- ANNOUNCEMENT.md network claim corrected: compression is local; requests
  still go to the provider you configured

Caveman 2 stays opt-in: bin-v1.0.0 binaries and @caveman-ai/cli publish
separately after this lands and soaks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLvb5QniwYjmcawyssQNw9
2026-08-11 16:46:10 +02:00

54 lines
2.0 KiB
Go

package engine_test
import (
"testing"
"github.com/JuliusBrussee/caveman/engine"
)
func TestDetectHTML(t *testing.T) {
e := engine.New(nil, nil)
html := "<!doctype html><html><body><article><p>real article prose with enough text here</p></article></body></html>"
if got := e.Detect([]byte(html)); got != engine.TypeHTML {
t.Errorf("Detect(html) = %q, want %q", got, engine.TypeHTML)
}
}
func TestDetectJSXRoutesToCode(t *testing.T) {
e := engine.New(nil, nil)
// A React component is `<`-dense code; it must route to code, not html, or the
// HTML extractor would shred the source.
jsx := "import React from 'react'\n\n" +
"export function Card({ title, items }) {\n" +
" return (\n" +
" <div className=\"card\">\n" +
" <h2>{title}</h2>\n" +
" <ul>{items.map((it) => (<li key={it.id}>{it.name}</li>))}</ul>\n" +
" </div>\n" +
" )\n}\n"
if got := e.Detect([]byte(jsx)); got == engine.TypeHTML {
t.Errorf("JSX must NOT route to html (would corrupt the source), got %q", got)
}
}
func TestDetectGoWithHTMLStringsNotHTML(t *testing.T) {
e := engine.New(nil, nil)
src := "package render\n\nfunc wrap(s string) string {\n\treturn \"<div><p>\" + s + \"</p></div>\"\n}\n\nfunc tag() string {\n\treturn \"<span>x</span>\"\n}\n"
if got := e.Detect([]byte(src)); got == engine.TypeHTML {
t.Errorf("Go source embedding HTML strings must not route to html, got %q", got)
}
}
func TestDetectLogWithCodeKeywords(t *testing.T) {
e := engine.New(nil, nil)
// A log whose messages contain code keywords (return/class/func) must route to
// the log compressor, not the code one — the precedence guard.
log := "2026-01-01T00:00:00Z [INFO] handler return 200\n" +
"2026-01-01T00:00:01Z [WARN] class loader slow\n" +
"2026-01-01T00:00:02Z [ERROR] func dispatch failed\n" +
"2026-01-01T00:00:03Z [INFO] return to pool\n"
if got := e.Detect([]byte(log)); got != engine.TypeLog {
t.Errorf("Detect(log-with-code-keywords) = %q, want %q", got, engine.TypeLog)
}
}