Skip to content

Add erp5_log_tail dev tool for live-test/script debugging

Summary

Adds erp5_log_tail, a dev-mode tool that wraps portal_introspections/tailEventLog. Pairs with Products.ERP5Type.Log.log(...) on the write side and replaces the print() / self.fail() pattern that either loses output or aborts the live-test run.

Why

When debugging a live test or a portal_skins Python Script, the existing options are bad:

  • print() output is swallowed by the live-test runner.
  • self.fail("DEBUG: %r" % x) aborts the test at the first probe — only one checkpoint per run, and the test is red.

The Zope event log is the right surface: tests and components can already call from Products.ERP5Type.Log import log, and ERP5 itself logs heavily there (RuleTool, builders, SQLCatalog warnings, deprecation notices). We just needed a read path through MCP.

Token-conscious by default

Follows the path-based I/O pattern introduced in 22c61e06 ("Add path-based I/O for full uploads and large dumps"):

  • Inline response is capped to max_entries (default 50, max 500). Only the most-recent matching entries are kept; if more existed the response sets truncated=true and reports dropped_entry_count so the model knows to narrow grep or spill to disk.

  • save_to_path writes the full filtered content to disk and returns only metadata (entry_count, line_count, saved_to, size_bytes, sha256) plus a short first_entry / last_entry preview (each truncated at 280 chars). max_entries is ignored on the disk side — everything matched goes to the file.

  • grep is documented as the cheapest token-saving knob — a distinctive marker (e.g. log('my_probe', ...)) cuts response size to just the lines you care about.

  • New dev guide erp5_guide(tutorial="tail_event_log") walks through the full emit-and-read loop.

  • The existing run_live_tests guide gains a section pointing here, so anyone debugging a test will land on it.

  • CLAUDE.md tool table gains the entry plus a one-liner in the call-sequence cheat sheet.

Tests

10 new unit tests covering: full tail, grep filter, no-match, max_entries truncation, default 50 cap, save_to_path, save_to_path + max_entries interaction (disk side ignores the cap), oversize-entry preview truncation, missing ERP5_SITE_ROOT, HTTP error path. Full suite: 400 passing.

Live-verified end-to-end

Confirmed against a SlapOS-deployed ERP5 instance:

  1. Wrote a marker via log('my_probe', 'PROBE_MARKER_NEW_TOOL_001') from a portal_skins Python Script.
  2. erp5_log_tail(grep="my_probe") returned the marker line with the token-conscious envelope (entry_count: 2, truncated: false, ~3 lines of content).
  3. erp5_log_tail(save_to_path="/tmp/x.log") wrote 134 entries / 498 lines (29 KB) to disk and returned only metadata + first/last preview — no log body in the response.

Test plan

  • python -m pytest test_erp5_mcp.py — 400 passing
  • Live-verified inline (grep) and save_to_path paths on an ERP5 instance

Merge request reports