ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
"""Test import bootstrap for the prompt-auto-optimization experiment."""
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
EXPERIMENT_ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(EXPERIMENT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(EXPERIMENT_ROOT))
|
||||
@@ -0,0 +1,21 @@
|
||||
from coding_agent import _apply_one
|
||||
|
||||
|
||||
def test_apply_one_null_old_str():
|
||||
content, err = _apply_one("hello world", None, "x")
|
||||
assert content == "hello world"
|
||||
assert err is not None
|
||||
assert "null" in err
|
||||
|
||||
|
||||
def test_apply_one_null_new_str():
|
||||
content, err = _apply_one("hello world", "hello", None)
|
||||
assert content == "hello world"
|
||||
assert err is not None
|
||||
assert "null" in err
|
||||
|
||||
|
||||
def test_apply_one_normal():
|
||||
content, err = _apply_one("hello world", "hello", "hi")
|
||||
assert err is None
|
||||
assert content == "hi world"
|
||||
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
|
||||
from airline_env import _run_tool
|
||||
|
||||
|
||||
def test_baggage_policy_null_cabin():
|
||||
# 模型显式传 {"cabin": null}:应回退到经济舱默认,而不是 TypeError
|
||||
args = json.loads('{"cabin": null}')
|
||||
result = json.loads(_run_tool("get_baggage_policy", args))
|
||||
assert result["cabin"] == "经济舱"
|
||||
assert result["free_allowance"] == "20kg"
|
||||
|
||||
|
||||
def test_baggage_policy_missing_cabin():
|
||||
result = json.loads(_run_tool("get_baggage_policy", {}))
|
||||
assert result["cabin"] == "经济舱"
|
||||
assert result["free_allowance"] == "20kg"
|
||||
|
||||
|
||||
def test_baggage_policy_business_cabin():
|
||||
result = json.loads(_run_tool("get_baggage_policy", {"cabin": "商务舱"}))
|
||||
assert result["free_allowance"] == "30kg"
|
||||
@@ -0,0 +1,27 @@
|
||||
from coding_agent import _apply_edits_from_args, _apply_one
|
||||
|
||||
|
||||
def test_null_edits_like_empty():
|
||||
working, applied, errors, warnings, edits = _apply_edits_from_args("hello world", {"edits": None})
|
||||
assert working == "hello world"
|
||||
assert applied == 0
|
||||
assert errors == []
|
||||
assert warnings == []
|
||||
assert edits == []
|
||||
|
||||
|
||||
def test_apply_edits_normal():
|
||||
working, applied, errors, warnings, edits = _apply_edits_from_args(
|
||||
"hello world",
|
||||
{"edits": [{"old_str": "hello", "new_str": "hi"}]},
|
||||
)
|
||||
assert working == "hi world"
|
||||
assert applied == 1
|
||||
assert errors == []
|
||||
assert warnings == []
|
||||
assert len(edits) == 1
|
||||
|
||||
|
||||
def test_apply_one_still_rejects_null_strings():
|
||||
content, err = _apply_one("hello", None, "x")
|
||||
assert err is not None
|
||||
@@ -0,0 +1,57 @@
|
||||
import unittest
|
||||
|
||||
from learning_signal import diagnose_failures, format_learning_signal
|
||||
from release_gate import build_candidate_manifest, evaluate_release_gate
|
||||
|
||||
|
||||
def evaluation(holdout=(2, 2), boundary=(0, 2)):
|
||||
return {
|
||||
"holdout": holdout,
|
||||
"boundary": boundary,
|
||||
"results": [
|
||||
{
|
||||
"id": "B1",
|
||||
"group": "boundary",
|
||||
"correct": False,
|
||||
"transferred": True,
|
||||
"should_transfer": False,
|
||||
"handled": None,
|
||||
"note": "不应转接:却转接了",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class LearningAndReleaseTest(unittest.TestCase):
|
||||
def test_diagnosis_comes_from_failed_case(self):
|
||||
report = diagnose_failures(evaluation())
|
||||
self.assertEqual(["B1"], report["source_case_ids"])
|
||||
self.assertEqual("system_prompt.transfer_policy", report["scope"])
|
||||
self.assertEqual("B1", report["dimensions"]["compliant_flexibility"][0]["case_id"])
|
||||
self.assertIn("Source cases: B1", format_learning_signal(report))
|
||||
|
||||
def test_release_requires_improvement_and_no_regression(self):
|
||||
signal = diagnose_failures(evaluation())
|
||||
manifest = build_candidate_manifest({
|
||||
"diff": "+ new rule", "rationale": "narrow transfer",
|
||||
"edits": [{"old_str": "old rule", "new_str": "new rule"}],
|
||||
}, signal)
|
||||
accepted = evaluate_release_gate(evaluation(), evaluation(boundary=(1, 2)), manifest)
|
||||
self.assertTrue(accepted["accepted"])
|
||||
self.assertEqual("release_to_canary", accepted["decision"])
|
||||
|
||||
regressed = evaluate_release_gate(
|
||||
evaluation(holdout=(2, 2)), evaluation(holdout=(1, 2), boundary=(1, 2)), manifest
|
||||
)
|
||||
self.assertFalse(regressed["accepted"])
|
||||
self.assertFalse(regressed["checks"]["holdout_did_not_regress"])
|
||||
|
||||
def test_empty_patch_is_rejected(self):
|
||||
signal = diagnose_failures(evaluation())
|
||||
manifest = build_candidate_manifest({"diff": "", "rationale": "none", "edits": []}, signal)
|
||||
decision = evaluate_release_gate(evaluation(), evaluation(boundary=(1, 2)), manifest)
|
||||
self.assertEqual("reject_candidate", decision["decision"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user