Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,29 @@ jobs:
# Budgets are unchanged and no test is dropped: each runs in exactly one of the two steps.
- name: Run tests with ThreadSanitizer race detector (-race) & coverage
env:
CPU_BUDGET_TESTS: '^(TestR9H3Adversarial240KBPerformanceBudget|TestR8RedactEmbeddedURLsLinear1MiBUnder15ms|TestR9RedactEmbeddedURLs90DiverseLeakVectorsAndLinear1MiB|TestRound8H8LinearCPUBudgetsUnder40ms)$'
CPU_BUDGET_TESTS: '^(TestR9H3Adversarial240KBPerformanceBudget|TestR8RedactEmbeddedURLsLinear1MiBUnder15ms|TestR9RedactEmbeddedURLs90DiverseLeakVectorsAndLinear1MiB|TestRound8H8LinearCPUBudgetsUnder40ms|TestWave3CommunityNegativeShellsAndPerfBudget|TestWave3CyclingComponentsM7PerfBudget|TestWave3CyclingOEMsAdversarialUnclosedDiv100KLatencyAndCPSCQueryTerm|TestWave3CyclingOEMsM7RegressionsAndPerfBudget|TestWave3DevInfraHTMLAndCWSScan|TestWave3DevM7StreamingAndLatencyFixes|TestWave3EduM7CanvasFalsePositiveAndEdlioLatency|TestWave3FinanceM7SECCompanyFactsStreamingLatency|TestWave3GovM7PreemptionsAndLatency|TestWave3JobsM7ParadoxOliviaLatency|TestWave3ResaleM7RegressionsAndPerfBudget|TestWave3SecurityIntelHTMLExtractorsAndFixtures|TestWave3SocialCreatorFixturesGoldenAndNegativeShells|TestWave3StoreAddonsPreemptionAnd2MBPerfBudget|TestM3MultiPassEntitySanitizeMarkdownAndPerf)$'
run: go test -v -race -count=1 -skip "$CPU_BUDGET_TESTS" -coverprofile=coverage.out ./... && go tool cover -func=coverage.out | tail -n 15

- name: Run CPU-budget tests with -race (no coverage instrumentation)
env:
CPU_BUDGET_TESTS: '^(TestR9H3Adversarial240KBPerformanceBudget|TestR8RedactEmbeddedURLsLinear1MiBUnder15ms|TestR9RedactEmbeddedURLs90DiverseLeakVectorsAndLinear1MiB|TestRound8H8LinearCPUBudgetsUnder40ms)$'
CPU_BUDGET_TESTS: '^(TestR9H3Adversarial240KBPerformanceBudget|TestR8RedactEmbeddedURLsLinear1MiBUnder15ms|TestR9RedactEmbeddedURLs90DiverseLeakVectorsAndLinear1MiB|TestRound8H8LinearCPUBudgetsUnder40ms|TestWave3CommunityNegativeShellsAndPerfBudget|TestWave3CyclingComponentsM7PerfBudget|TestWave3CyclingOEMsAdversarialUnclosedDiv100KLatencyAndCPSCQueryTerm|TestWave3CyclingOEMsM7RegressionsAndPerfBudget|TestWave3DevInfraHTMLAndCWSScan|TestWave3DevM7StreamingAndLatencyFixes|TestWave3EduM7CanvasFalsePositiveAndEdlioLatency|TestWave3FinanceM7SECCompanyFactsStreamingLatency|TestWave3GovM7PreemptionsAndLatency|TestWave3JobsM7ParadoxOliviaLatency|TestWave3ResaleM7RegressionsAndPerfBudget|TestWave3SecurityIntelHTMLExtractorsAndFixtures|TestWave3SocialCreatorFixturesGoldenAndNegativeShells|TestWave3StoreAddonsPreemptionAnd2MBPerfBudget|TestM3MultiPassEntitySanitizeMarkdownAndPerf)$'
run: |
go test -v -race -count=1 -run "$CPU_BUDGET_TESTS" ./internal/mcpfed ./internal/politeness ./internal/extract | tee cpu-budget.log
test "$(grep -c '^--- PASS: ' cpu-budget.log)" -eq 4
test "$(grep -c '^--- PASS: ' cpu-budget.log)" -eq 19

- name: Run native Go fuzzing smoke suite
run: |
go test -fuzz=FuzzRobotsParseAndMatch -fuzztime=2s ./internal/politeness
go test -fuzz=FuzzParseRetryAfter -fuzztime=2s ./internal/politeness
go test -fuzz=FuzzIsPublicIP -fuzztime=2s ./internal/politeness
go test -fuzz=FuzzClassify -fuzztime=2s ./internal/classify
go test -fuzz=FuzzExtractHTML -fuzztime=2s ./internal/extract
go test -fuzz=FuzzParseLlmsTxt -fuzztime=2s ./internal/extract
go test -fuzz=FuzzExtractPDFPureGo -fuzztime=2s ./internal/extract
go test -fuzz=FuzzDeclarativeFormat -fuzztime=2s ./internal/extract
go test -fuzz=FuzzBotAuthVerifyRequest -fuzztime=2s ./internal/botauth
go test -fuzz=FuzzValidateCustomHeaders -fuzztime=2s ./internal/crawl
go test -fuzz=FuzzPublicHTTPS -fuzztime=2s ./internal/crawl
go test -run '^FuzzRobotsParseAndMatch$' -fuzz=FuzzRobotsParseAndMatch -fuzztime=2s ./internal/politeness
go test -run '^FuzzParseRetryAfter$' -fuzz=FuzzParseRetryAfter -fuzztime=2s ./internal/politeness
go test -run '^FuzzIsPublicIP$' -fuzz=FuzzIsPublicIP -fuzztime=2s ./internal/politeness
go test -run '^FuzzClassify$' -fuzz=FuzzClassify -fuzztime=2s ./internal/classify
go test -run '^FuzzExtractHTML$' -fuzz=FuzzExtractHTML -fuzztime=2s ./internal/extract
go test -run '^FuzzParseLlmsTxt$' -fuzz=FuzzParseLlmsTxt -fuzztime=2s ./internal/extract
go test -run '^FuzzExtractPDFPureGo$' -fuzz=FuzzExtractPDFPureGo -fuzztime=2s ./internal/extract
go test -run '^FuzzDeclarativeFormat$' -fuzz=FuzzDeclarativeFormat -fuzztime=2s ./internal/extract
go test -run '^FuzzBotAuthVerifyRequest$' -fuzz=FuzzBotAuthVerifyRequest -fuzztime=2s ./internal/botauth
go test -run '^FuzzValidateCustomHeaders$' -fuzz=FuzzValidateCustomHeaders -fuzztime=2s ./internal/crawl
go test -run '^FuzzPublicHTTPS$' -fuzz=FuzzPublicHTTPS -fuzztime=2s ./internal/crawl

- name: Run allocation microbenchmarks & WASI WebAssembly build check
run: |
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ test: vet
go test -v -race -cover ./...

fuzz:
go test -fuzz=FuzzRobotsParseAndMatch -fuzztime=3s ./internal/politeness
go test -fuzz=FuzzParseRetryAfter -fuzztime=3s ./internal/politeness
go test -fuzz=FuzzIsPublicIP -fuzztime=3s ./internal/politeness
go test -fuzz=FuzzClassify -fuzztime=3s ./internal/classify
go test -fuzz=FuzzExtractHTML -fuzztime=3s ./internal/extract
go test -fuzz=FuzzParseLlmsTxt -fuzztime=3s ./internal/extract
go test -run '^FuzzRobotsParseAndMatch$$' -fuzz=FuzzRobotsParseAndMatch -fuzztime=3s ./internal/politeness
go test -run '^FuzzParseRetryAfter$$' -fuzz=FuzzParseRetryAfter -fuzztime=3s ./internal/politeness
go test -run '^FuzzIsPublicIP$$' -fuzz=FuzzIsPublicIP -fuzztime=3s ./internal/politeness
go test -run '^FuzzClassify$$' -fuzz=FuzzClassify -fuzztime=3s ./internal/classify
go test -run '^FuzzExtractHTML$$' -fuzz=FuzzExtractHTML -fuzztime=3s ./internal/extract
go test -run '^FuzzParseLlmsTxt$$' -fuzz=FuzzParseLlmsTxt -fuzztime=3s ./internal/extract

bench:
go test -bench=. -benchmem ./...
Expand Down
23 changes: 23 additions & 0 deletions cmd/edgefetch-wasm/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ func TestWasmReactorExportsRoundTrip(t *testing.T) {
if strLen == 0 || strings.Contains(string(wasmOutBuf[:strLen]), "<script") || !strings.HasPrefix(string(wasmOutBuf[:strLen]), "Hi") {
t.Fatalf("unexpected efCallRawStr output: %q", string(wasmOutBuf[:strLen]))
}

// post_extract_html via efCallRaw with htmlByteLen meta-pair split
paradoxHTML := `<!doctype html><html><head><title>Account Manager II | FedEx Careers</title><script type="application/ld+json">{"@context":"https://schema.org","@type":"JobPosting","title":"Account Manager II","hiringOrganization":{"@type":"Organization","name":"FedEx"},"jobLocation":{"@type":"Place","address":{"@type":"PostalAddress","addressLocality":"Memphis","addressRegion":"TN","addressCountry":"US"}},"description":"Manage enterprise shipping accounts across regional territories."}</script><script>window.oliviaChatConfig = {"clientId":"fedex"};</script></head><body><h1>Account Manager II</h1></body></html>`
curMD := "# Account Manager II"
postMeta := `{"op":"post_extract_html","meta":{"baseUrl":"https://careers.fedex.com/account-manager-ii/job/P25-397759-1","htmlByteLen":` + strconv.Itoa(len(paradoxHTML)) + `}}`
_ = efInPtr(uint32(len(postMeta) + len(paradoxHTML) + len(curMD)))
copy(wasmInBuf, postMeta)
copy(wasmInBuf[len(postMeta):], paradoxHTML)
copy(wasmInBuf[len(postMeta)+len(paradoxHTML):], curMD)
postLen := efCallRaw(uint32(len(postMeta)), uint32(len(postMeta)+len(paradoxHTML)+len(curMD)))
if postLen == 0 || !strings.Contains(string(wasmOutBuf[:postLen]), `"ok":true`) || !strings.Contains(string(wasmOutBuf[:postLen]), `"extractorId":"paradox-olivia"`) {
t.Fatalf("unexpected post_extract_html efCallRaw output: %q", string(wasmOutBuf[:postLen]))
}
// Non-matching page via post_extract_html raw meta-pair returns ok:false
emptyHTML := `<!doctype html><html><head><title>Blank</title></head><body><p>Nothing special here.</p></body></html>`
negMeta := `{"op":"post_extract_html","meta":{"baseUrl":"https://example.org/plain","htmlByteLen":` + strconv.Itoa(len(emptyHTML)) + `}}`
_ = efInPtr(uint32(len(negMeta) + len(emptyHTML)))
copy(wasmInBuf, negMeta)
copy(wasmInBuf[len(negMeta):], emptyHTML)
negLen := efCallRaw(uint32(len(negMeta)), uint32(len(negMeta)+len(emptyHTML)))
if negLen == 0 || !strings.Contains(string(wasmOutBuf[:negLen]), `"ok":false`) {
t.Fatalf("expected post_extract_html ok:false for non-matching page, got: %q", string(wasmOutBuf[:negLen]))
}
}

func TestWasmManifestFormatTwinPageKeyOptIn(t *testing.T) {
Expand Down
114 changes: 82 additions & 32 deletions cmd/edgefetch-wasm/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,22 +1170,24 @@ func dispatchWasmRPC(rawReq []byte) (any, error) {
return map[string]any{"matched": false}, nil
}
out := map[string]any{
"matched": true,
"id": m.ID,
"adapterId": m.AdapterID,
"fetchUrl": m.FetchURL,
"kind": string(m.Kind),
"accept": m.Accept,
"rawAccept": m.RawAccept(),
"maxBytes": m.EffectiveMaxBytes(),
"commerceMode": m.CommerceMode(),
"requiresPageKeyOptIn": m.RequiresPageKeyOptIn,
"authMode": m.AuthMode,
"userAgentProfile": m.UserAgentProfile,
"minIntervalMs": m.MinIntervalMs,
"maxCacheTtlMs": m.MaxCacheTtlMs,
"maxConcurrent": m.MaxConcurrent,
"strictRobots": m.StrictRobots,
"matched": true,
"id": m.ID,
"adapterId": m.AdapterID,
"fetchUrl": m.FetchURL,
"kind": string(m.Kind),
"accept": m.Accept,
"rawAccept": m.RawAccept(),
"maxBytes": m.EffectiveMaxBytes(),
"commerceMode": m.CommerceMode(),
"requiresPageKeyOptIn": m.RequiresPageKeyOptIn,
"authMode": m.AuthMode,
"userAgentProfile": m.UserAgentProfile,
"minIntervalMs": m.MinIntervalMs,
"maxCacheTtlMs": m.MaxCacheTtlMs,
"maxConcurrent": m.MaxConcurrent,
"strictRobots": m.StrictRobots,
"allowCrossOriginRedirects": m.AllowCrossOriginRedirects(),
"allowTruncatedStream": m.AllowTruncatedStream(),
}
if m.FallbackFetchURL != "" {
out["fallbackFetchUrl"] = m.FallbackFetchURL
Expand Down Expand Up @@ -1341,22 +1343,24 @@ func dispatchWasmRPC(rawReq []byte) (any, error) {
return map[string]any{"matched": false}, nil
}
out := map[string]any{
"matched": true,
"id": m.ID,
"adapterId": m.AdapterID,
"fetchUrl": m.FetchURL,
"kind": string(m.Kind),
"accept": m.Accept,
"rawAccept": m.RawAccept(),
"maxBytes": m.EffectiveMaxBytes(),
"commerceMode": m.CommerceMode(),
"requiresPageKeyOptIn": m.RequiresPageKeyOptIn,
"authMode": m.AuthMode,
"userAgentProfile": m.UserAgentProfile,
"minIntervalMs": m.MinIntervalMs,
"maxCacheTtlMs": m.MaxCacheTtlMs,
"maxConcurrent": m.MaxConcurrent,
"strictRobots": m.StrictRobots,
"matched": true,
"id": m.ID,
"adapterId": m.AdapterID,
"fetchUrl": m.FetchURL,
"kind": string(m.Kind),
"accept": m.Accept,
"rawAccept": m.RawAccept(),
"maxBytes": m.EffectiveMaxBytes(),
"commerceMode": m.CommerceMode(),
"requiresPageKeyOptIn": m.RequiresPageKeyOptIn,
"authMode": m.AuthMode,
"userAgentProfile": m.UserAgentProfile,
"minIntervalMs": m.MinIntervalMs,
"maxCacheTtlMs": m.MaxCacheTtlMs,
"maxConcurrent": m.MaxConcurrent,
"strictRobots": m.StrictRobots,
"allowCrossOriginRedirects": m.AllowCrossOriginRedirects(),
"allowTruncatedStream": m.AllowTruncatedStream(),
}
if m.FallbackFetchURL != "" {
out["fallbackFetchUrl"] = m.FallbackFetchURL
Expand Down Expand Up @@ -2054,6 +2058,52 @@ func dispatchWasmRPC(rawReq []byte) (any, error) {
}
return map[string]any{"url": extract.ScrubTwinURLSecrets(p.URL)}, nil

case "check_unbounded_twin_guard":
var p struct {
URL string `json:"url"`
}
if err := json.Unmarshal(env.Payload, &p); err != nil {
return nil, err
}
blocked, msg := extract.CheckUnboundedTwinEndpointGuard(p.URL)
if !blocked {
return map[string]any{"blocked": false}, nil
}
return map[string]any{"blocked": true, "message": msg}, nil

case "nostr_prepare_nip01":
var p struct {
URL string `json:"url"`
SelfHost string `json:"selfHost"`
SubID string `json:"subId"`
MaxEvents int `json:"maxEvents"`
}
if err := json.Unmarshal(env.Payload, &p); err != nil {
return nil, err
}
return extract.PrepareNostrNIP01(p.URL, p.SelfHost, p.SubID, p.MaxEvents), nil

case "nostr_format_nip01":
var p struct {
OrigURL string `json:"origUrl"`
RelayURL string `json:"relayUrl"`
SubID string `json:"subId"`
NIP11Raw string `json:"nip11Raw"`
Frames []string `json:"frames"`
MaxEvents int `json:"maxEvents"`
}
if err := json.Unmarshal(env.Payload, &p); err != nil {
return nil, err
}
if p.Frames != nil && len(p.NIP11Raw) == 0 && p.RelayURL == "" {
return map[string]any{"events": extract.ParseNostrNIP01Frames(p.SubID, p.Frames, p.MaxEvents)}, nil
}
doc, ok := extract.FormatNostrNIP01Frames(p.OrigURL, p.RelayURL, p.SubID, p.NIP11Raw, p.Frames, p.MaxEvents)
if !ok || doc == nil {
return map[string]any{"ok": false}, nil
}
return map[string]any{"ok": true, "doc": doc}, nil

case "refine_blocked_map":
var p classify.RefineBlockedMapInput
if err := json.Unmarshal(env.Payload, &p); err != nil {
Expand Down
Loading