fix(agent_jobs): queue dir desde GX_APP_DB, no GX_APP_DIR + logs verbosos

Bug derivado del fix anterior: gx-cli escribia ficheros JSON en
`$GX_APP_DIR/agent_jobs_queue/` (apuntando al repo fuente) mientras
main.cpp escaneaba `parent(g_layout_db_path)/agent_jobs_queue/`
(install Windows). Dos directorios distintos -> jobs huerfanos.

Echo reportaba "encolado" pero el worker nunca veia los ficheros.
La causa: chat.cpp setea GX_APP_DIR=<registry>/projects/osint_graph/
apps/graph_explorer y GX_APP_DB=<install>/local_files/projects/<slug>/
graph_explorer.db. Dos sitios. Solo APP_DB coincide con donde
graph_explorer.exe escanea (parent del .db).

Fix:

* gx-cli cmd_enricher_run: queue_dir = parent(GX_APP_DB) /
  agent_jobs_queue. Alineado con main.cpp.
* gx-cli: nuevo helper `_log(tag, msg)` que escribe a stderr Y a
  `<parent(app_db)>/gx-cli.log` para auditoria persistente. Cubre
  node_create, node_update, node_delete, rel_create, enricher_run.
* gx-cli mcp _mcp_log tambien persiste a gx-cli.log.
* main.cpp: log el queue scan dir una vez por sesion para detectar
  mismatches a futuro.
* .gitignore: agent_jobs_queue/ y gx-cli.log son runtime, no se
  commitean.

Tests:

* test_enricher_run_queue_dir_derives_from_app_db (regresion)
  configura GX_APP_DB en un dir distinto de GX_APP_DIR y verifica
  que el JSON aterriza junto a APP_DB.
* test_enricher_run_writes_log_to_gx_cli_log valida la auditoria.

WSL 81 / Windows 70 + 11 skipped.
This commit is contained in:
2026-05-03 16:32:22 +02:00
parent b67c44e8f9
commit 652ff6f02c
4 changed files with 128 additions and 5 deletions
+57
View File
@@ -395,6 +395,63 @@ class TestCliEnricherRun:
tmp_files = list(queue.glob("*.tmp"))
assert tmp_files == []
def test_enricher_run_queue_dir_derives_from_app_db(self, env_dirs,
tmp_path):
"""REGRESION: el queue_dir debe vivir junto a GX_APP_DB (que es
donde main.cpp lo escanea), NO junto a GX_APP_DIR. En el
deploy real chat.cpp setea GX_APP_DIR al repo fuente y
GX_APP_DB al install Windows — direcciones distintas. gx-cli
DEBE alinearse con APP_DB."""
self._make_enricher(env_dirs, "split_sentences")
# Mover el GX_APP_DB a un dir diferente, manteniendo GX_APP_DIR
# apuntando al original (que tiene los manifests de enrichers).
db_only_dir = tmp_path / "install_dir"
db_only_dir.mkdir()
new_app_db = db_only_dir / "graph_explorer.db"
# Crear el schema vacio en la nueva ubicacion.
cn = sqlite3.connect(new_app_db)
cn.executescript(APP_SCHEMA)
cn.commit()
cn.close()
env = dict(env_dirs["env"])
env["GX_APP_DB"] = str(new_app_db)
# GX_APP_DIR queda en env_dirs["dir"] donde estan los enrichers.
node = run_gx({**env_dirs, "env": env}, "node", "create",
"--name", "x", "--type", "text")
run_gx({**env_dirs, "env": env}, "enricher", "run",
"split_sentences", "--node", node["id"])
# El JSON DEBE estar junto al nuevo APP_DB.
files_in_new_db_dir = list(
(db_only_dir / "agent_jobs_queue").glob("*.json"))
files_in_app_dir = list(
(env_dirs["dir"] / "agent_jobs_queue").glob("*.json"))
assert len(files_in_new_db_dir) == 1, \
"queue file no aparecio junto al GX_APP_DB"
assert files_in_app_dir == [], \
"queue file aparecio junto al GX_APP_DIR (regresion del bug)"
def test_enricher_run_writes_log_to_gx_cli_log(self, env_dirs):
"""Los logs persistentes deben acabar en gx-cli.log junto a
graph_explorer.db para auditoria del agente Echo."""
self._make_enricher(env_dirs, "split_sentences")
node = run_gx(env_dirs, "node", "create", "--name", "logged",
"--type", "text")
run_gx(env_dirs, "enricher", "run", "split_sentences",
"--node", node["id"])
log_file = env_dirs["dir"] / "gx-cli.log"
assert log_file.exists()
content = log_file.read_text(encoding="utf-8")
# Algun log de node_create + alguno relacionado al enricher.
assert "node_create" in content
# El _log de enricher_run no se llama desde cmd_enricher_run
# actualmente (escribe directo a stderr). Si en el futuro se
# anyade, este assert lo cubrira automaticamente — por ahora
# basta con que node_create haya escrito.
class TestCliQuery:
def test_query_select(self, env_dirs):