GeezerVison is showing github.com — dsh harness: DeepSeek hanya lewat dsh, opsi terakhir di setiap rantai… · coderbuzz/orchestrator-kit@3d285e8
This repository was archived by the owner on Nov 2, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: companyos/harness.py +66-10Lines changed: 66 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | Invocation templates come from model-routing/providers/*.harness.yaml; the per-harness builders below only fill in | 9 | 9 | what a template cannot express (tool lists, modes). Adding a harness = descriptor + one builder. | 10 | 10 | """ | | 11 | +import functools | 11 | 12 | import json | | 13 | +import re | 12 | 14 | import shutil | 13 | 15 | import subprocess | 14 | 16 | import tempfile | @@ -139,30 +141,46 @@ def build_claude(hdef, model, req: Request, schema: dict) -> list[str]: | 139 | 141 | {"status": "completed", "summary": "Researched X; two sources agree.", "artifacts": [{"type": "research_report", "title": "X market", "content": "# X\\n...", "evidence": {"sources": ["https://example.com/a", "https://example.com/b"], "findings": ["finding one"], "confidence": 0.7}}]}""" | 140 | 142 |
| 141 | 143 |
| | 144 | +def _mode(caps: set[str]) -> str: | | 145 | + return "yolo" if caps & {"execute_command", "run_tests"} else "edit" if "write_repository" in caps else "plan" | | 146 | + | | 147 | + | | 148 | +def _contract_prompt(req: Request, schema: dict) -> str: | | 149 | + return (f"{req.system_prompt}\n\n---\n\n{req.prompt}\n\nReturn ONLY one JSON object matching this schema:\n" | | 150 | + f"{json.dumps(schema)}\n\n{CONTRACT_GUIDE}") | | 151 | + | | 152 | + | 142 | 153 | def build_zcode(hdef, model, req: Request, schema: dict) -> list[str]: | 143 | 154 | caps = set(req.capabilities) | 144 | | - mode = "yolo" if caps & {"execute_command", "run_tests"} else "edit" if "write_repository" in caps else "plan" | 145 | | - prompt = (f"{req.system_prompt}\n\n---\n\n{req.prompt}\n\nReturn ONLY one JSON object matching this schema:\n" | 146 | | - f"{json.dumps(schema)}\n\n{CONTRACT_GUIDE}") | 147 | | - args = _fill(hdef["invocation"]["non_interactive_args"], {"cwd": req.cwd, "mode": mode}) | | 155 | + prompt = _contract_prompt(req, schema) | | 156 | + args = _fill(hdef["invocation"]["non_interactive_args"], {"cwd": req.cwd, "mode": _mode(caps)}) | 148 | 157 | args = [prompt if a == "{prompt}" else a for a in args] | 149 | 158 | if not caps & {"execute_command", "run_tests"}: | 150 | 159 | args += ["--disallowed-tools", "Bash"] | 151 | 160 | return [hdef["invocation"]["command"], *args] | 152 | 161 |
| 153 | 162 |
| | 163 | +def build_dsh(hdef, model, req: Request, schema: dict) -> list[str]: | | 164 | + caps, inv = set(req.capabilities), hdef["invocation"] | | 165 | + prompt = _contract_prompt(req, schema) | | 166 | + args = _fill(inv["non_interactive_args"], {"cwd": req.cwd, "mode": _mode(caps), "timeout": max(1, req.timeout_seconds - 5)}) | | 167 | + args = [prompt if a == "{prompt}" else a for a in args] | | 168 | + if not caps & {"execute_command", "run_tests"}: | | 169 | + args += ["--disallowed-tools", "bash"] | | 170 | + return [*inv.get("prefix", []), inv["command"], *args] | | 171 | + | | 172 | + | 154 | 173 | def build_agy(hdef, model, req: Request, schema: dict) -> list[str]: | 155 | 174 | """No system-prompt/cwd/tool flags (cwd = subprocess cwd). Always --dangerously-skip-permissions (Board approval 2026-10-12, quote in the | 156 | 175 | descriptor notes): without it agy auto-denies run_command/web/out-of-cwd access and Gemini models then end the turn EMPTY even on | 157 | 176 | text-only tasks (profiling 2026-10-12). The flag auto-approves every tool; --sandbox did not restrict anything on this Linux VM.""" | 158 | | - prompt = (f"{req.system_prompt}\n\n---\n\n{req.prompt}\n\nReturn ONLY one JSON object matching this schema:\n" | 159 | | - f"{json.dumps(schema)}\n\n{CONTRACT_GUIDE}") | | 177 | + prompt = _contract_prompt(req, schema) | 160 | 178 | args = [prompt if a == "{prompt}" else a for a in hdef["invocation"]["non_interactive_args"]] | 161 | 179 | return [hdef["invocation"]["command"], *args, "--dangerously-skip-permissions"] | 162 | 180 |
| 163 | 181 |
| 164 | 182 | RETRYABLE = ("no agent-result JSON", "result violates agent-result contract") # worth one corrective retry on the same route | 165 | | -BUILDERS = {"claude-code": build_claude, "zcode": build_zcode, "agy": build_agy} | | 183 | +BUILDERS = {"claude-code": build_claude, "zcode": build_zcode, "agy": build_agy, "dsh": build_dsh} | 166 | 184 |
| 167 | 185 |
| 168 | 186 | def price_for(hdef: dict, provider: str | None, model: str) -> dict | None: | @@ -213,8 +231,33 @@ def parse_agy_json(stdout: str) -> tuple[str, dict, str]: | 213 | 231 | return text, usage, "" | 214 | 232 |
| 215 | 233 |
| | 234 | +def parse_dsh_json(stdout: str) -> tuple[str, dict, str]: | | 235 | + """dsh `--json` -> (reply text, usage in zh key names, error). prompt_tokens already includes cache hits. | | 236 | + Truncated or non-JSON stdout is an error (not retried on the same route: the transport, not the answer, is broken).""" | | 237 | + i = stdout.find("{") | | 238 | + try: | | 239 | + d, _ = json.JSONDecoder().raw_decode(stdout, i) if i >= 0 else (None, 0) | | 240 | + except ValueError: | | 241 | + d = None | | 242 | + if not isinstance(d, dict) or "status" not in d: | | 243 | + return stdout, {}, "non-JSON output from dsh (truncated or not a result object)" | | 244 | + u = d.get("usage") or {} | | 245 | + usage = {"inputTokens": u.get("prompt_tokens") or 0, "outputTokens": u.get("completion_tokens") or 0, | | 246 | + "cacheReadTokens": u.get("prompt_cache_hit_tokens") or 0, "reasoningTokens": u.get("reasoning_tokens") or 0} | | 247 | + text = d.get("reply") or "" | | 248 | + if d["status"] != "completed": | | 249 | + return text, usage, f"dsh {d['status']}: {str(d.get('failReason'))[:300]}" | | 250 | + return text, usage, "" | | 251 | + | | 252 | + | | 253 | +JSON_PARSERS = {"agy": parse_agy_json, "dsh": parse_dsh_json} # harnesses whose --json output also carries an error status | | 254 | + | | 255 | + | 216 | 256 | def usage_of(harness_id: str, stdout: str) -> dict: | 217 | | - return parse_zcode_json(stdout)[1] if harness_id == "zcode" else parse_agy_json(stdout)[1] if harness_id == "agy" else {} | | 257 | + if harness_id == "zcode": | | 258 | + return parse_zcode_json(stdout)[1] | | 259 | + p = JSON_PARSERS.get(harness_id) | | 260 | + return p(stdout)[1] if p else {} | 218 | 261 |
| 219 | 262 |
| 220 | 263 | def parse(harness_id: str, stdout: str, price: dict | None = None) -> tuple[dict | None, float | None, str]: | @@ -229,8 +272,8 @@ def parse(harness_id: str, stdout: str, price: dict | None = None) -> tuple[dict | 229 | 272 | return None, cost, f"claude error: {d.get('subtype')} {str(d.get('result'))[:300]}" | 230 | 273 | out = d.get("structured_output") or extract_json(d.get("result") or "") | 231 | 274 | return out, cost, "" if out else "no agent-result JSON in claude output" | 232 | | - if harness_id == "agy": | 233 | | - text, usage, err = parse_agy_json(stdout) | | 275 | + if harness_id in JSON_PARSERS: | | 276 | + text, usage, err = JSON_PARSERS[harness_id](stdout) | 234 | 277 | if err: | 235 | 278 | return None, token_cost(price, usage) if usage else None, err | 236 | 279 | else: | @@ -239,11 +282,24 @@ def parse(harness_id: str, stdout: str, price: dict | None = None) -> tuple[dict | 239 | 282 | return out, token_cost(price, usage) if usage else None, "" if out else "no agent-result JSON in output" | 240 | 283 |
| 241 | 284 |
| | 285 | +@functools.cache | | 286 | +def installed_version(command: str) -> str: | | 287 | + """`<command> --version` -> x.y.z ('' when it cannot be read). Cached per process: checked at first use, not on every call.""" | | 288 | + try: | | 289 | + m = re.search(r"\d+\.\d+\.\d+", subprocess.run([command, "--version"], capture_output=True, text=True, timeout=30, stdin=subprocess.DEVNULL).stdout) | | 290 | + except (OSError, subprocess.TimeoutExpired): | | 291 | + return "" | | 292 | + return m.group(0) if m else "" | | 293 | + | | 294 | + | 242 | 295 | def invoke(hdef: dict, model: str, req: Request, schema: dict) -> CallResult: | 243 | 296 | """Real subprocess call. Tests inject a different callable with the same signature.""" | 244 | 297 | builder = BUILDERS.get(hdef["id"]) | 245 | 298 | if builder is None: | 246 | 299 | return CallResult(False, hdef["id"], model, error=f"no adapter builder for harness {hdef['id']}") | | 300 | + pin = hdef.get("pinned_version") | | 301 | + if pin and (v := installed_version(hdef["invocation"]["command"])) != pin: | | 302 | + return CallResult(False, hdef["id"], model, error=f"{hdef['id']} version {v or 'unknown'} does not match the pinned {pin}") | 247 | 303 | argv = builder(hdef, model, req, schema) + selection_args(hdef, model, req) | 248 | 304 | t0 = time.time() | 249 | 305 | with tempfile.TemporaryFile("w+") as out: | |
Collapse file Copy file name to clipboardExpand all lines: model-routing/model-policy.schema.json +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 26 | 26 | }, | 27 | 27 | "candidates": {"type": "array", "minItems": 1, "description": "Ordered preference. The router picks the first routable candidate (harness enabled in config/models).", | 28 | 28 | "items": {"type": "object", "additionalProperties": false, "required": ["harness", "model"], | 29 | | - "properties": {"harness": {"type": "string"}, "model": {"type": "string"}, "provider": {"type": "string"}}}} | | 29 | + "properties": {"harness": {"type": "string"}, "model": {"type": "string"}, "provider": {"type": "string"}, | | 30 | + "effort": {"enum": ["disabled", "low", "medium", "high", "xhigh", "max"], "description": "Effort of this candidate; overrides the selection effort (harnesses that put effort in the model id leave it out)."}}}} | 30 | 31 | } | 31 | 32 | } |
Collapse file Copy file name to clipboardExpand all lines: model-routing/providers/harness.schema.json +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 39 | 39 | ], | 40 | 40 | "description": "documented = CLI flags verified on a real install, adapter not yet written." | 41 | 41 | }, | | 42 | + "pinned_version": { | | 43 | + "type": "string", | | 44 | + "pattern": "^\\d+\\.\\d+\\.\\d+$", | | 45 | + "description": "Exact installed version the adapter was verified against. `<command> --version` is checked before a call; a mismatch is a failed attempt (next route is tried), so an upgrade never reaches production unverified." | | 46 | + }, | 42 | 47 | "verified_with": { | 43 | 48 | "type": "string", | 44 | 49 | "description": "Tool version the invocation was verified against." | | 54 | 59 | "command": { | 55 | 60 | "type": "string" | 56 | 61 | }, | | 62 | + "prefix": { | | 63 | + "type": "array", | | 64 | + "items": {"type": "string"}, | | 65 | + "description": "Words placed before the command (e.g. a secret-injecting wrapper `with-secrets <name> --`); the harness itself is still `command`." | | 66 | + }, | 57 | 67 | "non_interactive_args": { | 58 | 68 | "type": "array", | 59 | 69 | "items": { | 60 | 70 | "type": "string" | 61 | 71 | }, | 62 | | - "description": "Argument template; {prompt}, {model}, {cwd} are filled by the adapter." | | 72 | + "description": "Argument template; {prompt}, {model}, {cwd}, {mode}, {timeout} are filled by the adapter." | 63 | 73 | }, | 64 | 74 | "model_args": { | 65 | 75 | "type": "array", | |
Collapse file Copy file name to clipboardExpand all lines: tests/conftest.py +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,3 +92,21 @@ def auto(self, task, req): | 92 | 92 |
| 93 | 93 | def calls_for(self, **kw): | 94 | 94 | return [c for c in self.calls if all(c.get(k) == v for k, v in kw.items())] | | 95 | + | | 96 | + | | 97 | +@pytest.fixture | | 98 | +def fake_dsh(tmp_path): | | 99 | + """A scripted `dsh` executable: answers --version, records its other argv in argv.json, prints `stdout`, exits with `code`.""" | | 100 | + from companyos.registry import Registry | | 101 | + | | 102 | + def make(stdout="", code=0, version="0.1.6"): | | 103 | + out, argv, script = tmp_path / "out.txt", tmp_path / "argv.json", tmp_path / "dsh" | | 104 | + out.write_text(stdout) | | 105 | + script.write_text("#!/usr/bin/env python3\nimport json, sys\n" | | 106 | + f"if '--version' in sys.argv: print({version!r}); sys.exit(0)\n" | | 107 | + f"open({str(argv)!r}, 'w').write(json.dumps(sys.argv[1:]))\n" | | 108 | + f"sys.stdout.write(open({str(out)!r}).read()); sys.exit({code})\n") | | 109 | + script.chmod(0o755) | | 110 | + h = Registry().harnesses["dsh"] | | 111 | + return {**h, "invocation": {**h["invocation"], "command": str(script), "prefix": []}}, lambda: json.loads(argv.read_text()) | | 112 | + return make |
Collapse file Copy file name to clipboardExpand all lines: tests/tools/test_ai_selection.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,9 +47,9 @@ def test_zh_built_in_models_and_opus_only_decisions(): | 47 | 47 | ["--model", "account:zai-individual-coding-plan/GLM-5.3", "--effort", "high"] | 48 | 48 | assert harness.unsupported(z, "GLM-5.3", glm["provider"], "high") is None | 49 | 49 | assert validate._candidate_checks(REG) == [] | 50 | | - # every policy except strategic ends in a zh built-in model; strategic is Opus only (a decision is blocked, not downgraded) | | 50 | + # policies list zh GLM built-in models (DeepSeek only via dsh, last); strategic is Opus only (a decision is blocked, not downgraded) | 51 | 51 | models = {p: [(c["harness"], c["model"]) for c in m["candidates"]] for p, m in REG.model_policies.items()} | 52 | | - assert models["strategic"] == [("claude-code", "opus"), ("zcode", "claude-opus-5")] | | 52 | + assert models["strategic"] == [("claude-code", "opus")] # Claude plan only; zh has no Anthropic route (Board 2026-10-12) | 53 | 53 | assert ("zcode", "GLM-5.3-Flash") in models["cheap"] and ("zcode", "GLM-5.3") in models["coding"] | 54 | 54 | assert not any(m == "configured" for c in models.values() for _, m in c) | 55 | 55 |
| |
Collapse file Copy file name to clipboard +117Lines changed: 117 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +"""dsh harness: argv, JSON/usage parsing, cost, version pin, failure modes -> next mapped route. No model calls (scripted dsh in conftest).""" | | 2 | +import json | | 3 | + | | 4 | +import pytest | | 5 | + | | 6 | +from companyos import harness | | 7 | +from companyos.registry import Registry | | 8 | + | | 9 | +REG = Registry() | | 10 | +D = REG.harnesses["dsh"] | | 11 | +RESULT = {"status": "completed", "summary": "s"} | | 12 | +AI = {"harness": "dsh", "provider": "deepseek", "model": "deepseek-flash", "effort": "low"} | | 13 | + | | 14 | + | | 15 | +def req(caps=(), timeout=30, cwd="."): | | 16 | + return harness.Request("sys", "task", cwd, list(caps), None, timeout, provider="deepseek", effort="low") | | 17 | + | | 18 | + | | 19 | +def dsh_json(reply=None, status="completed", fail=None, **usage): | | 20 | + u = {"prompt_tokens": 11000, "completion_tokens": 100, "prompt_cache_hit_tokens": 10000, "prompt_cache_miss_tokens": 1000, "reasoning_tokens": 40, **usage} | | 21 | + return json.dumps({"status": status, "reply": json.dumps(RESULT) if reply is None else reply, "toolExecutions": [], "usage": u, "failReason": fail, "sessionId": "s1"}, indent=2) | | 22 | + | | 23 | + | | 24 | +def test_argv_modes_timeout_and_bash_removal(): | | 25 | + a = harness.build_dsh(D, "deepseek-flash", req(cwd="/work"), REG.result_schema) | | 26 | + assert a[:4] == ["with-secrets", "deepseek", "--", "dsh"] and "--json" in a | | 27 | + assert a[a.index("--mode") + 1] == "plan" and a[-2:] == ["--disallowed-tools", "bash"] | | 28 | + assert a[a.index("--timeout") + 1] == "25" and a[a.index("-C") + 1] == "/work" | | 29 | + prompt = a[a.index("-p") + 1] | | 30 | + assert prompt.startswith("sys") and "`actions` is ONLY for actions" in prompt and "Valid example:" in prompt # contract guide, as for zcode | | 31 | + assert "-m" not in a and "-e" not in a # selection args are appended by invoke | | 32 | + assert harness.selection_args(D, "deepseek-flash", req()) == ["-m", "deepseek-flash", "-e", "low"] | | 33 | + y = harness.build_dsh(D, "m", req(["execute_command"]), REG.result_schema) | | 34 | + assert y[y.index("--mode") + 1] == "yolo" and "--disallowed-tools" not in y | | 35 | + e = harness.build_dsh(D, "m", req(["write_repository"]), REG.result_schema) | | 36 | + assert e[e.index("--mode") + 1] == "edit" and e[-2:] == ["--disallowed-tools", "bash"] | | 37 | + | | 38 | + | | 39 | +def test_usage_mapped_to_zcode_fields_and_priced_at_peak_tariff(): | | 40 | + price = harness.price_for(D, "deepseek", "deepseek-flash") | | 41 | + assert price == {"in": 0.30, "cache_hit": 0.006, "out": 1.20} # DeepSeek PEAK list price | | 42 | + out, cost, err = harness.parse("dsh", dsh_json(), price) | | 43 | + assert out == RESULT and err == "" | | 44 | + assert harness.usage_of("dsh", dsh_json()) == {"inputTokens": 11000, "outputTokens": 100, "cacheReadTokens": 10000, "reasoningTokens": 40} | | 45 | + assert cost == round(1000 * 0.30 / 1e6 + 10000 * 0.006 / 1e6 + 100 * 1.20 / 1e6, 6) | | 46 | + | | 47 | + | | 48 | +@pytest.mark.parametrize("stdout,code,expect", [ | | 49 | + (dsh_json(fail="boom", status="failed"), 1, "dsh failed: boom"), | | 50 | + (dsh_json(status="interrupted"), 130, "dsh interrupted"), | | 51 | + (dsh_json(status="waiting_for_user"), 1, "dsh waiting_for_user"), | | 52 | + (dsh_json()[:300], 0, "non-JSON output from dsh"), # truncated pipe (dsh <= 0.1.3) | | 53 | + ("", 130, "exit 130"), | | 54 | + ("", 1, "exit 1"), | | 55 | + (dsh_json(), 1, "exit 1"), # inconsistent: JSON says completed, process says failed | | 56 | +]) | | 57 | +def test_failure_modes_are_failed_attempts_not_crashes(fake_dsh, stdout, code, expect): | | 58 | + h, _ = fake_dsh(stdout, code) | | 59 | + r = harness.invoke(h, "deepseek-flash", req(), REG.result_schema) | | 60 | + assert not r.ok and expect in r.error and not r.error.startswith(harness.RETRYABLE) | | 61 | + | | 62 | + | | 63 | +def test_invoke_end_to_end_with_scripted_dsh(fake_dsh): | | 64 | + h, argv = fake_dsh(dsh_json()) | | 65 | + r = harness.invoke(h, "deepseek-flash", req(), REG.result_schema) | | 66 | + assert r.ok and r.output == RESULT and r.tokens["cacheReadTokens"] == 10000 and not r.cost_estimated and r.cost_usd > 0 | | 67 | + a = argv() | | 68 | + assert a[a.index("-m") + 1] == "deepseek-flash" and a[a.index("-e") + 1] == "low" and "--json" in a | | 69 | + | | 70 | + | | 71 | +def test_output_over_64kib_is_valid_through_the_pipe(fake_dsh): | | 72 | + h, _ = fake_dsh(dsh_json(reply=json.dumps({**RESULT, "summary": "x" * 200_000}))) | | 73 | + r = harness.invoke(h, "deepseek-flash", req(), REG.result_schema) | | 74 | + assert r.ok and len(r.output["summary"]) == 200_000 | | 75 | + | | 76 | + | | 77 | +def test_version_other_than_the_pin_is_a_failed_attempt_without_a_model_call(fake_dsh): | | 78 | + h, argv = fake_dsh(dsh_json(), version="0.1.2") | | 79 | + r = harness.invoke(h, "deepseek-flash", req(), REG.result_schema) | | 80 | + assert not r.ok and "0.1.2" in r.error and "pinned 0.1.6" in r.error | | 81 | + with pytest.raises(FileNotFoundError): | | 82 | + argv() # the scripted dsh never ran a prompt | | 83 | + | | 84 | + | | 85 | +def test_deepseek_is_only_offered_by_dsh_and_mapping_routes_use_it(): | | 86 | + assert "deepseek" not in {p["id"] for p in REG.harnesses["zcode"]["providers"]} | | 87 | + assert not [m for m in REG.harnesses["zcode"]["models"] if m.startswith("deepseek")] | | 88 | + for e in REG.mapping["entries"]: | | 89 | + for ai in [e["ai"], *[f["ai"] for f in e["fallbacks"]]]: | | 90 | + assert ai.get("provider") != "deepseek" or ai["harness"] == "dsh" | | 91 | + | | 92 | + | | 93 | +def test_truncated_dsh_goes_to_the_next_route_without_retry(fake_dsh): | | 94 | + h, _ = fake_dsh(dsh_json()[:200]) | | 95 | + seen = [] | | 96 | + | | 97 | + def fn(hd, m, rq, s): | | 98 | + seen.append(hd["id"]) | | 99 | + return harness.invoke(h, m, rq, s) if hd["id"] == "dsh" else harness.CallResult(True, hd["id"], m, output=RESULT) | | 100 | + res = harness.Router(REG, {}, check_installed=False).call_with_fallback("coding", req(), fn, ai=AI) | | 101 | + assert seen[0] == "dsh" and seen[1] != "dsh" and [a.ok for a in res] == [False, True] # truncation is not retried on the dsh route | | 102 | + | | 103 | + | | 104 | +def test_contract_violation_on_dsh_gets_the_corrective_retry_then_next_route(fake_dsh): | | 105 | + h, _ = fake_dsh(dsh_json(reply=json.dumps({**RESULT, "actions": ["x"]}))) | | 106 | + calls = [] | | 107 | + | | 108 | + def fn(hd, m, rq, s): | | 109 | + calls.append(hd["id"]) | | 110 | + return harness.invoke(h, m, rq, s) if hd["id"] == "dsh" else harness.CallResult(True, hd["id"], m, output=RESULT) | | 111 | + res = harness.Router(REG, {}, check_installed=False).call_with_fallback("coding", req(), fn, ai=AI) | | 112 | + assert calls[:2] == ["dsh", "dsh"] and calls[2] != "dsh" and res[-1].ok | | 113 | + | | 114 | + | | 115 | +def test_descriptor_and_policies_validate(): | | 116 | + for pid in ("coding", "cheap", "research"): | | 117 | + assert any(c["harness"] == "dsh" and c["provider"] == "deepseek" for c in REG.model_policies[pid]["candidates"]) |
Collapse file Copy file name to clipboardExpand all lines: tests/tools/test_zcode_cost.py +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | from companyos.registry import Registry | 6 | 6 |
| 7 | 7 | REG = Registry() | | 8 | +DS = {"in": 0.30, "cache_hit": 0.006, "out": 1.20} # the DeepSeek tariff; the zcode parser is generic, the price is passed in | 8 | 9 | Z = REG.harnesses["zcode"] | 9 | 10 | RESULT = {"status": "completed", "summary": "s"} | 10 | 11 |
| @@ -15,13 +16,13 @@ def zh_json(**usage): | 15 | 16 |
| 16 | 17 | def test_json_flag_in_invocation_and_response_unwrapped(): | 17 | 18 | assert "--json" in Z["invocation"]["non_interactive_args"] | 18 | | - out, cost, err = harness.parse("zcode", zh_json(inputTokens=1000, outputTokens=100), harness.price_for(Z, "deepseek", "deepseek-flash")) | | 19 | + out, cost, err = harness.parse("zcode", zh_json(inputTokens=1000, outputTokens=100), DS) | 19 | 20 | assert out == RESULT and err == "" | 20 | 21 | assert cost == round(1000 * 0.30 / 1e6 + 100 * 1.20 / 1e6, 6) | 21 | 22 |
| 22 | 23 |
| 23 | 24 | def test_cache_read_tokens_priced_at_the_hit_rate(): | 24 | | - p = harness.price_for(Z, "deepseek", "deepseek-flash") | | 25 | + p = DS | 25 | 26 | assert harness.token_cost(p, {"inputTokens": 11000, "cacheReadTokens": 10000, "outputTokens": 0}) == round(1000 * 0.30 / 1e6 + 10000 * 0.006 / 1e6, 6) | 26 | 27 |
| 27 | 28 |
| |
|