diff --git a/src/fi/alk/harness/agent_type_check.py b/src/fi/alk/harness/agent_type_check.py index f4393c47a..e6e467d6c 100644 --- a/src/fi/alk/harness/agent_type_check.py +++ b/src/fi/alk/harness/agent_type_check.py @@ -643,13 +643,13 @@ def _tools_in( found |= _markers(raw) imported |= named except Exception as error: - # A skipped file may be the agent's main one, and the reading then finds nothing. The - # type only at WARNING, once a scan: a trace can quote a line of the customer's code, - # and a path can name their business. + # A skipped file may be the agent's main one, and the reading then finds nothing. No + # trace at any level, since a trace can quote a line of the customer's code; the type + # only at WARNING, once a scan, since a path can name their business. skipped += 1 if skipped == 1: logger.warning("agent type scan skipped a file: %s", type(error).__name__) - logger.debug("agent type scan skipped %s", path, exc_info=True) + logger.debug("agent type scan skipped %s: %s", path, type(error).__name__) continue if skipped > 1: logger.warning("agent type scan skipped %d files", skipped) diff --git a/tests/harness/test_agent_type_refusal.py b/tests/harness/test_agent_type_refusal.py index 9a39c36f0..07eff45c3 100644 --- a/tests/harness/test_agent_type_refusal.py +++ b/tests/harness/test_agent_type_refusal.py @@ -618,7 +618,7 @@ def odd(path, *args, **kwargs): assert record.exc_info is None -def test_a_skip_logs_its_type_once_and_its_path_and_trace_at_debug_only( +def test_a_skip_logs_its_type_once_and_its_path_at_debug_only_with_no_trace( tmp_path, monkeypatch, caplog ): _tree(tmp_path, {"a_odd.py": "x = 1\n", "b_odd.py": "x = 1\n", "agent.py": "import playwright\n"}) @@ -641,10 +641,17 @@ def odd(path, *args, **kwargs): "SOURCE-LINE" in record.getMessage() or "odd" in record.getMessage() or record.exc_info for record in loud ) - quiet = [record for record in caplog.records if record.levelno < 20 and record.exc_info] - assert [record.exc_info[0] for record in quiet] == [LookupError, LookupError] - assert "a_odd.py" in quiet[0].getMessage() - assert "b_odd.py" in quiet[1].getMessage() + # No record at any level carries a trace or the error's own text, which can quote the source. + assert not any(record.exc_info or "SOURCE-LINE" in record.getMessage() for record in caplog.records) + assert "SOURCE-LINE" not in caplog.text + quiet = [ + record.getMessage() + for record in caplog.records + if record.levelno < 20 and record.getMessage().startswith("agent type scan skipped ") + ] + assert len(quiet) == 2 + assert "a_odd.py" in quiet[0] and quiet[0].endswith(": LookupError") + assert "b_odd.py" in quiet[1] and quiet[1].endswith(": LookupError") @pytest.mark.skipif(sys.version_info < (3, 12), reason="3.11's tokenizer reads a NUL byte")