devez-vibe 1.10.19 → 1.10.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +73 -73
  3. package/bin/dvz.exe +0 -0
  4. package/bin/dvz.js +35 -35
  5. package/bridge/claude-agent-sdk-bridge.mjs +32 -0
  6. package/install-skills.mjs +11 -11
  7. package/package.json +1 -1
  8. package/prepare-search-deps.mjs +42 -42
  9. package/skills/insane-search/SKILL.md +36 -36
  10. package/skills/insane-search/engine/__main__.py +44 -44
  11. package/skills/insane-search/engine/executor.py +246 -246
  12. package/skills/insane-search/engine/fetch_chain.py +443 -443
  13. package/skills/insane-search/engine/network.py +108 -108
  14. package/skills/insane-search/engine/phase0.py +380 -380
  15. package/skills/insane-search/engine/session_input.py +120 -120
  16. package/skills/insane-search/engine/templates/invisible_playwright_fetch.py +57 -57
  17. package/skills/insane-search/engine/templates/nodriver_fetch.py +9 -9
  18. package/skills/insane-search/engine/templates/patchright_fetch.py +9 -9
  19. package/skills/insane-search/engine/templates/playwright_mobile_chrome.js +9 -9
  20. package/skills/insane-search/engine/templates/playwright_real_chrome.js +7 -7
  21. package/skills/insane-search/engine/templates/scrapling_fetch.py +46 -46
  22. package/skills/insane-search/engine/tests/test_smoke.py +8 -8
  23. package/skills/insane-search/engine/tests/test_t10_artifact_routes.py +126 -126
  24. package/skills/insane-search/engine/tests/test_t11_session_handoff.py +157 -157
  25. package/skills/insane-search/engine/tests/test_t5_pdfplumber.py +11 -11
  26. package/skills/insane-search/engine/tests/test_t7_browser_gate.py +3 -3
  27. package/skills/insane-search/engine/tests/test_t8_network_routes.py +207 -207
  28. package/skills/insane-search/engine/tests/test_t9_evidence_bundle.py +89 -89
  29. package/skills/insane-search/engine/tests/test_u5.py +9 -9
  30. package/skills/insane-search/engine/transport.py +94 -94
  31. package/skills/insane-search/engine/waf_profiles.yaml +38 -38
  32. package/skills/insane-search/references/cache-archive.md +13 -13
  33. package/skills/insane-search/references/media.md +14 -14
  34. package/skills/insane-search/references/playwright.md +27 -27
  35. package/skills/insane-search/references/research-evidence.md +36 -36
  36. package/skills/insane-search/references/session-handoff.md +26 -26
  37. package/skills/insane-search/tests/test_x_search.py +3 -3
  38. package/skills/luna-loop/agents/openai.yaml +7 -7
@@ -1,207 +1,207 @@
1
- #!/usr/bin/env python3
2
- """Regression tests for network diagnosis, proxy routing, and local stealth fallback."""
3
- from __future__ import annotations
4
-
5
- import os
6
- import sys
7
- import tempfile
8
-
9
- HERE = os.path.dirname(os.path.abspath(__file__))
10
- ROOT = os.path.abspath(os.path.join(HERE, "..", ".."))
11
- sys.path.insert(0, ROOT)
12
-
13
- import engine.executor as ex # noqa: E402
14
- import engine.fetch_chain as fc # noqa: E402
15
- from engine.fetch_chain import Attempt, FetchResult # noqa: E402
16
- from engine.network import ( # noqa: E402
17
- diagnose_trace,
18
- normalize_proxy,
19
- proxy_cache_key,
20
- proxy_for_browser,
21
- redact_proxy,
22
- )
23
- from engine.transport import SessionPool # noqa: E402
24
- from engine.validators import Verdict # noqa: E402
25
- from engine.waf_detector import _load_profiles # noqa: E402
26
-
27
-
28
- def t_proxy_validation_and_redaction() -> None:
29
- proxy = normalize_proxy("socks5h://user:p%40ss@proxy.example:1080")
30
- assert proxy == "socks5h://user:p%40ss@proxy.example:1080"
31
- browser = proxy_for_browser(proxy)
32
- assert browser == {
33
- "server": "socks5://proxy.example:1080",
34
- "username": "user",
35
- "password": "p@ss",
36
- }
37
- assert "user" not in proxy_cache_key(proxy)
38
- assert "p%40ss" not in proxy_cache_key(proxy)
39
- assert redact_proxy(f"failed via {proxy}", proxy) == "failed via socks5://proxy.example:1080"
40
-
41
- for bad in (
42
- "ftp://proxy.example:21",
43
- "https://proxy.example/path",
44
- "https://proxy.example:bad",
45
- "proxy.example:8080",
46
- ):
47
- try:
48
- normalize_proxy(bad)
49
- except ValueError:
50
- pass
51
- else:
52
- raise AssertionError(f"invalid proxy accepted: {bad}")
53
-
54
-
55
- def t_session_pool_separates_egress_routes() -> None:
56
- pool = SessionPool()
57
- direct = pool.get("www.example.com", "safari")
58
- proxied = pool.get("www.example.com", "safari", "http://proxy.example:8080")
59
- if direct is None or proxied is None:
60
- return
61
- assert direct is not proxied
62
- assert pool.get("www.example.com", "safari", "http://proxy.example:8080") is proxied
63
-
64
-
65
- def t_trace_diagnosis_finds_the_failed_layer() -> None:
66
- tls = Attempt(
67
- phase="probe", executor="curl_cffi", url="https://www.example.com/",
68
- url_transform="original", impersonate="safari", referer="self_root",
69
- error="CertificateVerifyError: certificate verify failed",
70
- )
71
- report = diagnose_trace([tls])
72
- assert report["layer"] == "tls"
73
- assert report["category"] == "certificate_verification"
74
-
75
- dns = Attempt(
76
- phase="probe", executor="curl_cffi", url="https://www.example.com/",
77
- url_transform="original", impersonate="safari", referer="self_root",
78
- error="Could not resolve host",
79
- )
80
- assert diagnose_trace([dns])["layer"] == "dns"
81
-
82
- blocked = Attempt(
83
- phase="probe", executor="curl_cffi", url="https://www.example.com/",
84
- url_transform="original", impersonate="safari", referer="self_root",
85
- status=403, verdict=Verdict.BLOCKED.value,
86
- )
87
- assert diagnose_trace([blocked])["layer"] == "http_policy"
88
-
89
-
90
- def t_fetch_passes_proxy_without_exposing_it() -> None:
91
- saved = fc._fetch_core
92
- seen = {}
93
-
94
- def fake_core(url, **kwargs):
95
- seen.update(kwargs)
96
- return FetchResult(ok=False, final_url=url, stop_reason="exhausted")
97
-
98
- fc._fetch_core = fake_core
99
- previous_observations = os.environ.get("INSANE_OBSERVATIONS_DIR")
100
- try:
101
- with tempfile.TemporaryDirectory() as temp_dir:
102
- os.environ["INSANE_OBSERVATIONS_DIR"] = temp_dir
103
- result = fc.fetch(
104
- "https://www.example.com/",
105
- proxy="http://user:secret@proxy.example:8080",
106
- enable_learning=False,
107
- )
108
- finally:
109
- fc._fetch_core = saved
110
- if previous_observations is None:
111
- os.environ.pop("INSANE_OBSERVATIONS_DIR", None)
112
- else:
113
- os.environ["INSANE_OBSERVATIONS_DIR"] = previous_observations
114
-
115
- assert seen["proxy"] == "http://user:secret@proxy.example:8080"
116
- assert result.proxy_used is True
117
- assert "secret" not in str(result.to_dict())
118
-
119
-
120
- def t_local_stealth_firefox_receives_browser_proxy() -> None:
121
- saved_available = ex._module_available
122
- saved_template = ex._run_python_template
123
- captured = {}
124
-
125
- ex._module_available = lambda name: name == "invisible_playwright"
126
-
127
- def fake_template(template, args, timeout=90):
128
- captured.update(args)
129
- html = "<html><body><article>" + ("x" * 4000) + "</article></body></html>"
130
- return 0, html, ""
131
-
132
- ex._run_python_template = fake_template
133
- try:
134
- attempt, content = ex.run_playwright_fallback(
135
- "https://www.example.com/",
136
- profile_id="unknown_challenge",
137
- force_executor="stealth_firefox",
138
- proxy="http://user:secret@proxy.example:8080",
139
- )
140
- finally:
141
- ex._module_available = saved_available
142
- ex._run_python_template = saved_template
143
-
144
- assert attempt.verdict == Verdict.WEAK_OK.value
145
- assert content
146
- assert attempt.executor == "stealth_firefox:invisible_playwright"
147
- assert captured["proxy"] == {
148
- "server": "http://proxy.example:8080",
149
- "username": "user",
150
- "password": "secret",
151
- }
152
- assert captured["headless"] is True
153
-
154
-
155
- def t_scrapling_is_the_primary_hidden_cloudflare_fallback() -> None:
156
- profile = _load_profiles()["cloudflare_turnstile"]
157
- assert profile["fallback_when_challenge"][:2] == ["scrapling", "stealth_firefox"]
158
-
159
- saved_available = ex._module_available
160
- saved_template = ex._run_python_template
161
- captured = {}
162
- ex._module_available = lambda name: name == "scrapling"
163
-
164
- def fake_template(template, args, timeout=90):
165
- captured.update(args)
166
- html = "<html><body><main>" + ("x" * 4000) + "</main></body></html>"
167
- return 0, html, ""
168
-
169
- ex._run_python_template = fake_template
170
- try:
171
- attempt, content = ex.run_playwright_fallback(
172
- "https://www.example.com/",
173
- profile_id="cloudflare_turnstile",
174
- force_executor="scrapling",
175
- proxy="http://user:secret@proxy.example:8080",
176
- )
177
- finally:
178
- ex._module_available = saved_available
179
- ex._run_python_template = saved_template
180
-
181
- assert attempt.verdict == Verdict.WEAK_OK.value
182
- assert content
183
- assert attempt.executor == "scrapling:stealthy_fetcher"
184
- assert captured["headless"] is True
185
- assert captured["realChrome"] is True
186
- assert captured["solveCloudflare"] is True
187
- assert captured["blockAds"] is True
188
- assert captured["proxy"]["server"] == "http://proxy.example:8080"
189
-
190
-
191
- def main() -> int:
192
- tests = [value for name, value in sorted(globals().items())
193
- if name.startswith("t_") and callable(value)]
194
- failed = 0
195
- for test in tests:
196
- try:
197
- test()
198
- print(f" PASS {test.__name__}")
199
- except Exception as exc:
200
- failed += 1
201
- print(f" FAIL {test.__name__}: {type(exc).__name__}: {exc}")
202
- print(f"\n{'OK' if failed == 0 else 'FAIL'}: {len(tests) - failed}/{len(tests)} passed")
203
- return 1 if failed else 0
204
-
205
-
206
- if __name__ == "__main__":
207
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ """Regression tests for network diagnosis, proxy routing, and local stealth fallback."""
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import sys
7
+ import tempfile
8
+
9
+ HERE = os.path.dirname(os.path.abspath(__file__))
10
+ ROOT = os.path.abspath(os.path.join(HERE, "..", ".."))
11
+ sys.path.insert(0, ROOT)
12
+
13
+ import engine.executor as ex # noqa: E402
14
+ import engine.fetch_chain as fc # noqa: E402
15
+ from engine.fetch_chain import Attempt, FetchResult # noqa: E402
16
+ from engine.network import ( # noqa: E402
17
+ diagnose_trace,
18
+ normalize_proxy,
19
+ proxy_cache_key,
20
+ proxy_for_browser,
21
+ redact_proxy,
22
+ )
23
+ from engine.transport import SessionPool # noqa: E402
24
+ from engine.validators import Verdict # noqa: E402
25
+ from engine.waf_detector import _load_profiles # noqa: E402
26
+
27
+
28
+ def t_proxy_validation_and_redaction() -> None:
29
+ proxy = normalize_proxy("socks5h://user:p%40ss@proxy.example:1080")
30
+ assert proxy == "socks5h://user:p%40ss@proxy.example:1080"
31
+ browser = proxy_for_browser(proxy)
32
+ assert browser == {
33
+ "server": "socks5://proxy.example:1080",
34
+ "username": "user",
35
+ "password": "p@ss",
36
+ }
37
+ assert "user" not in proxy_cache_key(proxy)
38
+ assert "p%40ss" not in proxy_cache_key(proxy)
39
+ assert redact_proxy(f"failed via {proxy}", proxy) == "failed via socks5://proxy.example:1080"
40
+
41
+ for bad in (
42
+ "ftp://proxy.example:21",
43
+ "https://proxy.example/path",
44
+ "https://proxy.example:bad",
45
+ "proxy.example:8080",
46
+ ):
47
+ try:
48
+ normalize_proxy(bad)
49
+ except ValueError:
50
+ pass
51
+ else:
52
+ raise AssertionError(f"invalid proxy accepted: {bad}")
53
+
54
+
55
+ def t_session_pool_separates_egress_routes() -> None:
56
+ pool = SessionPool()
57
+ direct = pool.get("www.example.com", "safari")
58
+ proxied = pool.get("www.example.com", "safari", "http://proxy.example:8080")
59
+ if direct is None or proxied is None:
60
+ return
61
+ assert direct is not proxied
62
+ assert pool.get("www.example.com", "safari", "http://proxy.example:8080") is proxied
63
+
64
+
65
+ def t_trace_diagnosis_finds_the_failed_layer() -> None:
66
+ tls = Attempt(
67
+ phase="probe", executor="curl_cffi", url="https://www.example.com/",
68
+ url_transform="original", impersonate="safari", referer="self_root",
69
+ error="CertificateVerifyError: certificate verify failed",
70
+ )
71
+ report = diagnose_trace([tls])
72
+ assert report["layer"] == "tls"
73
+ assert report["category"] == "certificate_verification"
74
+
75
+ dns = Attempt(
76
+ phase="probe", executor="curl_cffi", url="https://www.example.com/",
77
+ url_transform="original", impersonate="safari", referer="self_root",
78
+ error="Could not resolve host",
79
+ )
80
+ assert diagnose_trace([dns])["layer"] == "dns"
81
+
82
+ blocked = Attempt(
83
+ phase="probe", executor="curl_cffi", url="https://www.example.com/",
84
+ url_transform="original", impersonate="safari", referer="self_root",
85
+ status=403, verdict=Verdict.BLOCKED.value,
86
+ )
87
+ assert diagnose_trace([blocked])["layer"] == "http_policy"
88
+
89
+
90
+ def t_fetch_passes_proxy_without_exposing_it() -> None:
91
+ saved = fc._fetch_core
92
+ seen = {}
93
+
94
+ def fake_core(url, **kwargs):
95
+ seen.update(kwargs)
96
+ return FetchResult(ok=False, final_url=url, stop_reason="exhausted")
97
+
98
+ fc._fetch_core = fake_core
99
+ previous_observations = os.environ.get("INSANE_OBSERVATIONS_DIR")
100
+ try:
101
+ with tempfile.TemporaryDirectory() as temp_dir:
102
+ os.environ["INSANE_OBSERVATIONS_DIR"] = temp_dir
103
+ result = fc.fetch(
104
+ "https://www.example.com/",
105
+ proxy="http://user:secret@proxy.example:8080",
106
+ enable_learning=False,
107
+ )
108
+ finally:
109
+ fc._fetch_core = saved
110
+ if previous_observations is None:
111
+ os.environ.pop("INSANE_OBSERVATIONS_DIR", None)
112
+ else:
113
+ os.environ["INSANE_OBSERVATIONS_DIR"] = previous_observations
114
+
115
+ assert seen["proxy"] == "http://user:secret@proxy.example:8080"
116
+ assert result.proxy_used is True
117
+ assert "secret" not in str(result.to_dict())
118
+
119
+
120
+ def t_local_stealth_firefox_receives_browser_proxy() -> None:
121
+ saved_available = ex._module_available
122
+ saved_template = ex._run_python_template
123
+ captured = {}
124
+
125
+ ex._module_available = lambda name: name == "invisible_playwright"
126
+
127
+ def fake_template(template, args, timeout=90):
128
+ captured.update(args)
129
+ html = "<html><body><article>" + ("x" * 4000) + "</article></body></html>"
130
+ return 0, html, ""
131
+
132
+ ex._run_python_template = fake_template
133
+ try:
134
+ attempt, content = ex.run_playwright_fallback(
135
+ "https://www.example.com/",
136
+ profile_id="unknown_challenge",
137
+ force_executor="stealth_firefox",
138
+ proxy="http://user:secret@proxy.example:8080",
139
+ )
140
+ finally:
141
+ ex._module_available = saved_available
142
+ ex._run_python_template = saved_template
143
+
144
+ assert attempt.verdict == Verdict.WEAK_OK.value
145
+ assert content
146
+ assert attempt.executor == "stealth_firefox:invisible_playwright"
147
+ assert captured["proxy"] == {
148
+ "server": "http://proxy.example:8080",
149
+ "username": "user",
150
+ "password": "secret",
151
+ }
152
+ assert captured["headless"] is True
153
+
154
+
155
+ def t_scrapling_is_the_primary_hidden_cloudflare_fallback() -> None:
156
+ profile = _load_profiles()["cloudflare_turnstile"]
157
+ assert profile["fallback_when_challenge"][:2] == ["scrapling", "stealth_firefox"]
158
+
159
+ saved_available = ex._module_available
160
+ saved_template = ex._run_python_template
161
+ captured = {}
162
+ ex._module_available = lambda name: name == "scrapling"
163
+
164
+ def fake_template(template, args, timeout=90):
165
+ captured.update(args)
166
+ html = "<html><body><main>" + ("x" * 4000) + "</main></body></html>"
167
+ return 0, html, ""
168
+
169
+ ex._run_python_template = fake_template
170
+ try:
171
+ attempt, content = ex.run_playwright_fallback(
172
+ "https://www.example.com/",
173
+ profile_id="cloudflare_turnstile",
174
+ force_executor="scrapling",
175
+ proxy="http://user:secret@proxy.example:8080",
176
+ )
177
+ finally:
178
+ ex._module_available = saved_available
179
+ ex._run_python_template = saved_template
180
+
181
+ assert attempt.verdict == Verdict.WEAK_OK.value
182
+ assert content
183
+ assert attempt.executor == "scrapling:stealthy_fetcher"
184
+ assert captured["headless"] is True
185
+ assert captured["realChrome"] is True
186
+ assert captured["solveCloudflare"] is True
187
+ assert captured["blockAds"] is True
188
+ assert captured["proxy"]["server"] == "http://proxy.example:8080"
189
+
190
+
191
+ def main() -> int:
192
+ tests = [value for name, value in sorted(globals().items())
193
+ if name.startswith("t_") and callable(value)]
194
+ failed = 0
195
+ for test in tests:
196
+ try:
197
+ test()
198
+ print(f" PASS {test.__name__}")
199
+ except Exception as exc:
200
+ failed += 1
201
+ print(f" FAIL {test.__name__}: {type(exc).__name__}: {exc}")
202
+ print(f"\n{'OK' if failed == 0 else 'FAIL'}: {len(tests) - failed}/{len(tests)} passed")
203
+ return 1 if failed else 0
204
+
205
+
206
+ if __name__ == "__main__":
207
+ sys.exit(main())
@@ -1,89 +1,89 @@
1
- #!/usr/bin/env python3
2
- """Research evidence metadata regression tests."""
3
- from __future__ import annotations
4
-
5
- import hashlib
6
- import os
7
- import sys
8
-
9
- HERE = os.path.dirname(os.path.abspath(__file__))
10
- ROOT = os.path.abspath(os.path.join(HERE, "..", ".."))
11
- sys.path.insert(0, ROOT)
12
-
13
- from engine.fetch_chain import Attempt, FetchResult # noqa: E402
14
-
15
-
16
- def _result(**kwargs) -> FetchResult:
17
- values = dict(
18
- ok=True,
19
- content="source body",
20
- final_url="https://example.com/article?token=secret",
21
- verdict="strong_ok",
22
- profile_used="unknown_challenge",
23
- trace=[Attempt(
24
- phase="probe", executor="curl_cffi",
25
- url="https://example.com/article?token=secret",
26
- url_transform="original", impersonate="safari", referer="self_root",
27
- )],
28
- extraction_quality=0.8,
29
- extraction_source="raw+md",
30
- )
31
- values.update(kwargs)
32
- return FetchResult(**values)
33
-
34
-
35
- def t_evidence_record_is_reproducible_and_masks_secrets() -> None:
36
- result = _result()
37
- evidence = result.evidence_record()
38
- assert evidence["requested_url"].endswith("token=REDACTED")
39
- assert evidence["final_url"].endswith("token=REDACTED")
40
- assert evidence["content_sha256"] == hashlib.sha256(b"source body").hexdigest()
41
- assert evidence["retrieved_at"].endswith("Z")
42
- assert evidence["source_kind"] == "web"
43
- assert evidence["currentness"] == "current"
44
-
45
-
46
- def t_archive_record_is_labeled_historical() -> None:
47
- result = _result(
48
- extraction_source="archive+raw+md",
49
- extraction_meta={"snapshot_timestamp": "20240102030405"},
50
- )
51
- evidence = result.evidence_record()
52
- assert evidence["source_kind"] == "archive"
53
- assert evidence["currentness"] == "historical_snapshot"
54
- assert evidence["source_timestamp"] == "20240102030405"
55
-
56
-
57
- def t_bundle_never_exposes_raw_content_without_boundary() -> None:
58
- result = _result()
59
- bundle = result.to_evidence_bundle()
60
- assert "content" not in bundle["result"]
61
- assert "evidence" not in bundle["result"]
62
- wrapped = bundle["untrusted_content"]
63
- assert "source body" in wrapped
64
- assert "BEGIN UNTRUSTED WEB CONTENT" in wrapped
65
- assert bundle["evidence"] == result.evidence_record()
66
-
67
-
68
- def t_failed_retrieval_is_not_labeled_current() -> None:
69
- result = _result(ok=False, content="", final_url="", verdict="blocked")
70
- evidence = result.evidence_record()
71
- assert evidence["retrieval_status"] == "failed"
72
- assert evidence["currentness"] == "unavailable"
73
-
74
-
75
- def main() -> int:
76
- tests = [v for k, v in sorted(globals().items()) if k.startswith("t_") and callable(v)]
77
- failed = 0
78
- for test in tests:
79
- try:
80
- test()
81
- except AssertionError as exc:
82
- print(f" x {test.__name__}: {exc}")
83
- failed += 1
84
- print(f"\n{'OK' if failed == 0 else 'FAIL'}: {len(tests) - failed}/{len(tests)} passed")
85
- return 1 if failed else 0
86
-
87
-
88
- if __name__ == "__main__":
89
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ """Research evidence metadata regression tests."""
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import os
7
+ import sys
8
+
9
+ HERE = os.path.dirname(os.path.abspath(__file__))
10
+ ROOT = os.path.abspath(os.path.join(HERE, "..", ".."))
11
+ sys.path.insert(0, ROOT)
12
+
13
+ from engine.fetch_chain import Attempt, FetchResult # noqa: E402
14
+
15
+
16
+ def _result(**kwargs) -> FetchResult:
17
+ values = dict(
18
+ ok=True,
19
+ content="source body",
20
+ final_url="https://example.com/article?token=secret",
21
+ verdict="strong_ok",
22
+ profile_used="unknown_challenge",
23
+ trace=[Attempt(
24
+ phase="probe", executor="curl_cffi",
25
+ url="https://example.com/article?token=secret",
26
+ url_transform="original", impersonate="safari", referer="self_root",
27
+ )],
28
+ extraction_quality=0.8,
29
+ extraction_source="raw+md",
30
+ )
31
+ values.update(kwargs)
32
+ return FetchResult(**values)
33
+
34
+
35
+ def t_evidence_record_is_reproducible_and_masks_secrets() -> None:
36
+ result = _result()
37
+ evidence = result.evidence_record()
38
+ assert evidence["requested_url"].endswith("token=REDACTED")
39
+ assert evidence["final_url"].endswith("token=REDACTED")
40
+ assert evidence["content_sha256"] == hashlib.sha256(b"source body").hexdigest()
41
+ assert evidence["retrieved_at"].endswith("Z")
42
+ assert evidence["source_kind"] == "web"
43
+ assert evidence["currentness"] == "current"
44
+
45
+
46
+ def t_archive_record_is_labeled_historical() -> None:
47
+ result = _result(
48
+ extraction_source="archive+raw+md",
49
+ extraction_meta={"snapshot_timestamp": "20240102030405"},
50
+ )
51
+ evidence = result.evidence_record()
52
+ assert evidence["source_kind"] == "archive"
53
+ assert evidence["currentness"] == "historical_snapshot"
54
+ assert evidence["source_timestamp"] == "20240102030405"
55
+
56
+
57
+ def t_bundle_never_exposes_raw_content_without_boundary() -> None:
58
+ result = _result()
59
+ bundle = result.to_evidence_bundle()
60
+ assert "content" not in bundle["result"]
61
+ assert "evidence" not in bundle["result"]
62
+ wrapped = bundle["untrusted_content"]
63
+ assert "source body" in wrapped
64
+ assert "BEGIN UNTRUSTED WEB CONTENT" in wrapped
65
+ assert bundle["evidence"] == result.evidence_record()
66
+
67
+
68
+ def t_failed_retrieval_is_not_labeled_current() -> None:
69
+ result = _result(ok=False, content="", final_url="", verdict="blocked")
70
+ evidence = result.evidence_record()
71
+ assert evidence["retrieval_status"] == "failed"
72
+ assert evidence["currentness"] == "unavailable"
73
+
74
+
75
+ def main() -> int:
76
+ tests = [v for k, v in sorted(globals().items()) if k.startswith("t_") and callable(v)]
77
+ failed = 0
78
+ for test in tests:
79
+ try:
80
+ test()
81
+ except AssertionError as exc:
82
+ print(f" x {test.__name__}: {exc}")
83
+ failed += 1
84
+ print(f"\n{'OK' if failed == 0 else 'FAIL'}: {len(tests) - failed}/{len(tests)} passed")
85
+ return 1 if failed else 0
86
+
87
+
88
+ if __name__ == "__main__":
89
+ sys.exit(main())
@@ -6,15 +6,15 @@ transient vs real-failure classification, TTL prune, LRU cap, key scoping,
6
6
  grid priority reordering, and winning-route extraction from a trace."""
7
7
  from __future__ import annotations
8
8
 
9
- import os
10
- import sys
11
- import tempfile
12
- from datetime import datetime, timezone, timedelta
13
-
14
- HERE = os.path.dirname(os.path.abspath(__file__))
15
- sys.path.insert(0, os.path.abspath(os.path.join(HERE, "..", "..")))
16
-
17
- from engine import learning
9
+ import os
10
+ import sys
11
+ import tempfile
12
+ from datetime import datetime, timezone, timedelta
13
+
14
+ HERE = os.path.dirname(os.path.abspath(__file__))
15
+ sys.path.insert(0, os.path.abspath(os.path.join(HERE, "..", "..")))
16
+
17
+ from engine import learning
18
18
  from engine.fetch_chain import _build_plan, _winning_route, _load_profiles, FetchResult, Attempt
19
19
  from engine.validators import Verdict
20
20