File size: 3,051 Bytes
cad26d4 acd5491 cad26d4 acd5491 cad26d4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | from __future__ import annotations
import os
os.environ["CONTEXTFORGE_ENABLE_MODEL"] = "0"
os.environ["CONTEXTFORGE_SKIP_UI_BUILD"] = "1"
import app
BASE = {
"project_idea": "Build an issue triage agent.",
"target_user": "Engineering teams",
"build_target": "Agent workflow",
"risk_level": "High",
"output_language": "English",
"user_context": "Reports may be incomplete.",
"project_context": "Reduce triage time.",
"technical_context": "Python and structured JSON.",
"constraints": "Do not invent evidence.",
"inputs_files": "Bug reports and logs.",
"output_contract": "Return a prioritized ticket with evidence.",
"failure_modes": "Hallucinated root cause.",
"verification_criteria": "All ticket fields and evidence exist.",
}
def compile_for(topology: str) -> tuple[str, str, str, str, str, str]:
return app.compile_context(
BASE["project_idea"],
BASE["target_user"],
BASE["build_target"],
topology,
BASE["risk_level"],
BASE["output_language"],
app.REASONING_LAYERS,
BASE["user_context"],
BASE["project_context"],
BASE["technical_context"],
BASE["constraints"],
BASE["inputs_files"],
BASE["output_contract"],
BASE["failure_modes"],
BASE["verification_criteria"],
)
def main() -> None:
assert "pending" in app.render_metrics({}).lower()
fast_updates = app.update_mode("Fast Compile")
full_updates = app.update_mode("Full Control")
assert all(update.get("visible") is False for update in fast_updates)
assert all(update.get("visible") is True for update in full_updates)
analysis = app.analyze_intake(BASE)
topology = app.decide_topology(analysis, "Cascade")
vital = app.extract_vital_structure(analysis, topology)
reasoning = app.select_reasoning_architecture(analysis, topology, app.REASONING_LAYERS)
pack = app.generate_prompt_pack(analysis, topology, vital, reasoning, BASE)
qa = app.qa_repair_pass(pack)
final = app.assemble_final_output(analysis, topology, vital, reasoning, qa)
assert qa["pass"]
assert final["prompt_pack"]
expected_counts = {
"Single Prompt": 1,
"Cascade": 4,
"Context Pack": 2,
"Agent Workflow": 4,
}
for topology_name, expected_count in expected_counts.items():
_, _, prompt_text, _, qa_text, runtime = compile_for(topology_name)
assert prompt_text.count("[ROLE]") == expected_count
for tag in app.REQUIRED_PROMPT_TAGS:
assert prompt_text.count(f"[{tag}]") == expected_count
assert "reveal your chain of thought" not in prompt_text.lower()
assert "strategy | upside | risk | cost | selected" in prompt_text
assert "No Chain Of Thought Leakage" in qa_text
assert runtime.count("deterministic_fallback") >= 7
assert "| Stage | Source | Fallback reason | Duration ms |" in runtime
print("ContextForge QA passed.")
if __name__ == "__main__":
main()
|