Skip to content

Commit be67407

Browse files
roli-lpciclaude
andcommitted
fix(ci): clean main pipeline — ruff, tiktoken-skip, deterministic timeout
Three concerns resolved in one pass: 1. ruff — 46 lint violations (31 auto-fixable F541/F401/UP035, 15 manual: E402 import-reorder in scaffold/_core.py + server.py, F841 unused vars, E702 semicolon-statement splits in tests). 2. tiktoken — tests/scaffold/test_real_tokenizer.py imported tiktoken at module top, hard-failing CI collection. tiktoken is not a declared dev dep (it is a tokenizer-validation utility). Switched to pytest.importorskip so the file runs locally where tiktoken is installed and skips cleanly in CI. 3. timeout race — test_decompose_timeout_returns_degraded_flag and test_decompose_timeout_vector_only_results_returned forced the fallback by setting FIDELIS_DECOMPOSE_TIMEOUT_SECS=0.001, hoping do_recall would take longer than 1ms. Fast CI runners win that race; the fallback never executes; degraded-flag missing; assert fails. Fix: patch fidelis.server.do_recall with a stub that sleeps 1.0s, raise the timeout to 0.1s. 10x margin is race-immune. Verified locally: 481 passed, 1 xpassed, 0 failures (excluding Ollama integration suites which skip cleanly in CI). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7dfe638 commit be67407

15 files changed

Lines changed: 72 additions & 69 deletions

src/fidelis/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _server_error(exc: BaseException) -> None:
3838
print(f"Error: fidelis-server unreachable or unhealthy at {_base_url()}", file=sys.stderr)
3939
print(f" reason: {msg}", file=sys.stderr)
4040
print(" • If you haven't installed the service: `fidelis init`", file=sys.stderr)
41-
print(f" • If the service is installed: `tail ~/.fidelis/server.log`", file=sys.stderr)
41+
print(" • If the service is installed: `tail ~/.fidelis/server.log`", file=sys.stderr)
4242
sys.exit(1)
4343

4444

src/fidelis/init_cmd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,11 @@ def cmd_init(args) -> int:
342342
print(f" log: {Path.home() / '.fidelis' / 'server.log'}")
343343
print()
344344
print("next steps:")
345-
print(f" fidelis health # confirm")
346-
print(f" fidelis watch ~/notes # auto-ingest a directory")
347-
print(f" fidelis mcp install # wire up Claude Code")
345+
print(" fidelis health # confirm")
346+
print(" fidelis watch ~/notes # auto-ingest a directory")
347+
print(" fidelis mcp install # wire up Claude Code")
348348
return 0
349349
else:
350-
print(f"✗ service installed but /health did not respond within 10s")
350+
print("✗ service installed but /health did not respond within 10s")
351351
print(f" check log: {Path.home() / '.fidelis' / 'server.log'}")
352352
return 2

src/fidelis/scaffold/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
from __future__ import annotations
1919

20+
import math as _math
21+
2022
# Version banner — used as scaffold-presence marker for drift measurement.
2123
SCAFFOLD_VERSION = "v0.1.0"
2224
SCAFFOLD_OPEN = f"[FIDELIS-SCAFFOLD-{SCAFFOLD_VERSION}]"
@@ -34,8 +36,6 @@
3436
# Confidence signal — inline meta-information about retrieval quality.
3537
# Helps the LLM calibrate its confidence to actual retrieval quality.
3638

37-
import math as _math
38-
3939

4040
def _sanitize_top_score(top_score: float | None) -> float | None:
4141
"""Sanitize a raw retrieval score to [0, 1] or None.

src/fidelis/server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
import sys
4848
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
4949

50-
logger = logging.getLogger("cogito.server")
51-
5250
from fidelis import __version__
5351
from fidelis.config import load, mem0_config
5452
from fidelis.degrade import queued_count, replay_queue, safe_add
@@ -57,6 +55,8 @@
5755
from fidelis.recall_hybrid import recall_hybrid as do_recall_hybrid
5856
from fidelis.snapshot import _read_snapshot, _snapshot_path
5957

58+
logger = logging.getLogger("cogito.server")
59+
6060

6161
def _boot(cfg: dict) -> object:
6262
"""Import mem0 from wherever it's installed and return a Memory instance."""
@@ -73,7 +73,6 @@ def _boot(cfg: dict) -> object:
7373

7474
def make_handler(memory: object, cfg: dict) -> type:
7575
user_id: str = cfg["user_id"]
76-
query_threshold: float = cfg.get("query_threshold", 250.0)
7776
# FIDELIS_DECOMPOSE_TIMEOUT_SECS: max seconds for /recall sub-query pipeline.
7877
# Default 8s preserves existing behavior in normal cases; kicks in only on slow-call edges.
7978
_decompose_timeout: float = float(os.environ.get("FIDELIS_DECOMPOSE_TIMEOUT_SECS", 8))

tests/scaffold/test_backend_portability.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import json
2525
import subprocess
26-
import time
2726
import urllib.error
2827
import urllib.request
2928
from typing import NamedTuple
@@ -397,7 +396,7 @@ def call(sys_prompt, user_msg):
397396
hedge_rate = results["hedge_compliance_rate"]
398397
answer_rate = results["answer_compliance_rate"]
399398

400-
print(f"\n=== claude-cli ===")
399+
print("\n=== claude-cli ===")
401400
print(f"Hedge compliance : {hedge_rate:.0%} ({sum(r['compliant'] for r in results['hedge_results'])}/{len(results['hedge_results'])})")
402401
print(f"Answer compliance: {answer_rate:.0%} ({sum(r['compliant'] for r in results['answer_results'])}/{len(results['answer_results'])})")
403402
print("\nHedge questions:")

tests/scaffold/test_consumer_surface.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import annotations
99

1010
import json
11-
from pathlib import Path
1211
from unittest.mock import MagicMock, patch
1312

1413
import pytest
@@ -149,10 +148,13 @@ def test_mcp_uninstall_removes_entry(tmp_path):
149148
settings_path = tmp_path / "settings.local.json"
150149
settings_path.write_text(json.dumps({"mcpServers": {}}))
151150

152-
args_install = MagicMock(); args_install.settings = str(settings_path); args_install.force = False
151+
args_install = MagicMock()
152+
args_install.settings = str(settings_path)
153+
args_install.force = False
153154
cmd_mcp_install(args_install)
154155

155-
args_uninstall = MagicMock(); args_uninstall.settings = str(settings_path)
156+
args_uninstall = MagicMock()
157+
args_uninstall.settings = str(settings_path)
156158
rc = cmd_mcp_uninstall(args_uninstall)
157159
assert rc == 0
158160

@@ -163,7 +165,8 @@ def test_mcp_uninstall_removes_entry(tmp_path):
163165
def test_mcp_uninstall_handles_missing_settings(tmp_path):
164166
from fidelis.mcp_cmd import cmd_mcp_uninstall
165167
settings_path = tmp_path / "no-such-file.json"
166-
args = MagicMock(); args.settings = str(settings_path)
168+
args = MagicMock()
169+
args.settings = str(settings_path)
167170
rc = cmd_mcp_uninstall(args)
168171
assert rc == 0 # graceful no-op
169172

tests/scaffold/test_e2e_store_query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import os
1616
import subprocess
1717
import sys
18-
import tempfile
1918
import time
2019
import urllib.error
2120
import urllib.request

tests/scaffold/test_openai_format_compatibility.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def test_scaffold_markers_appear_verbatim(self):
140140
serialized = json.dumps(payload)
141141
# JSON-encode the markers to see what they look like inside the string
142142
# The markers contain only ASCII, so they should appear literally
143-
assert SCAFFOLD_OPEN in serialized, f"SCAFFOLD_OPEN not found in serialized payload"
144-
assert SCAFFOLD_CLOSE in serialized, f"SCAFFOLD_CLOSE not found in serialized payload"
143+
assert SCAFFOLD_OPEN in serialized, "SCAFFOLD_OPEN not found in serialized payload"
144+
assert SCAFFOLD_CLOSE in serialized, "SCAFFOLD_CLOSE not found in serialized payload"
145145

146146
def test_scaffold_content_roundtrips_through_json(self):
147147
"""Scaffold content must survive a JSON round-trip without corruption."""
@@ -322,15 +322,14 @@ def test_answer_compliance(self):
322322
def test_full_classification_summary(self, capsys):
323323
"""Run all 10 questions, print per-question classification for the report."""
324324
print(f"\n{'='*60}")
325-
print(f"gpt-oss:20b — OpenAI wire format smoke test")
325+
print("gpt-oss:20b — OpenAI wire format smoke test")
326326
print(f"{'='*60}")
327327

328328
all_results = []
329329
for q in QUESTIONS:
330330
messages = self._build_messages(q)
331331
response = _call_openai_chat(messages)
332332
classification = _classify_response(response)
333-
expected = "HEDGED" if q.should_hedge else "ANSWERED/OTHER"
334333
correct = (
335334
(q.should_hedge and classification == "HEDGED")
336335
or (not q.should_hedge and classification != "HEDGED")

tests/scaffold/test_real_tokenizer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
from __future__ import annotations
1515

1616
import pytest
17-
import tiktoken
1817

19-
from fidelis.scaffold._core import wrap_system_prompt, _QTYPE_PROC
18+
tiktoken = pytest.importorskip("tiktoken")
19+
20+
from fidelis.scaffold._core import wrap_system_prompt, _QTYPE_PROC # noqa: E402
2021

2122
# --------------------------------------------------------------------------- #
2223
# Fixtures / helpers

tests/scaffold/test_streaming_marker_integrity.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
from __future__ import annotations
2020

2121
import json
22-
from typing import Iterator
2322

2423
import httpx
25-
import pytest
2624

2725
import anthropic
2826

@@ -236,7 +234,7 @@ def test_scaffold_open_marker_present_and_intact_in_wire_body(self):
236234
f"Got: {wire_system[:120]!r}"
237235
)
238236
assert SCAFFOLD_CLOSE in wire_system, (
239-
f"SCAFFOLD_CLOSE marker missing from wire body."
237+
"SCAFFOLD_CLOSE marker missing from wire body."
240238
)
241239

242240
def test_scaffold_open_marker_at_wire_body_start(self):

0 commit comments

Comments
 (0)