Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(collection-rebuild): pin publish writes to _CONFIG_FIELDS; comment accuracy follow-ups (#7756)

LearningCircuit9041852e9053
diff --git a/changelog.d/+post-merge-scanning-followups.bugfix.md b/changelog.d/+post-merge-scanning-followups.bugfix.md
new file mode 100644
index 0000000000..ae6f925246
--- /dev/null
+++ b/changelog.d/+post-merge-scanning-followups.bugfix.md
@@ -0,0 +1 @@
+A regression test now checks that the direct configuration assignments in `CollectionRebuild._publish_rows()` use the same field names as the snapshotted `_CONFIG_FIELDS`, detecting added or missing configuration fields. Comments marking the safe sidecar scan path in the rekey lock helpers and the PDF markdown-render sink suppression rationale are now accurate and self-contained.
diff --git a/changelog.d/+xss-pdf-service-sinks.security.md b/changelog.d/+xss-pdf-service-sinks.security.md
index b7cfe6997e..bd428d8700 100644
--- a/changelog.d/+xss-pdf-service-sinks.security.md
+++ b/changelog.d/+xss-pdf-service-sinks.security.md
@@ -1 +1 @@
-PDF export no longer uses the flagged dynamic-HTML-insertion sinks in `static/js/services/pdf.js` ([#9752](https://github.com/LearningCircuit/local-deep-research/security/code-scanning/9752) and [#9754](https://github.com/LearningCircuit/local-deep-research/security/code-scanning/9754)): `wrapTopLevelText()` now wraps top-level text nodes with `insertBefore`/`remove` and the PDF body is populated with `removeChild`/`appendChild` node moves, so the only remaining sink is the intentional parse of `ui.renderMarkdown()`'s fixed-point-sanitized output into an inert `<template>`, which now carries a documented `bearer:disable` rationale (alert [#9753](https://github.com/LearningCircuit/local-deep-research/security/code-scanning/9753)).
+PDF export no longer uses two dynamic-HTML-insertion sinks in `static/js/services/pdf.js`: `wrapTopLevelText()` now wraps top-level text nodes with `insertBefore`/`remove` and the PDF body is populated with `removeChild`/`appendChild` node moves, so the one remaining sink on the markdown-render path is the intentional inert-`<template>` parse of `renderMarkdown()` output, which now carries a documented suppression rationale.
diff --git a/src/local_deep_research/database/rekey_lock.py b/src/local_deep_research/database/rekey_lock.py
index 8c1c3cad19..40ad123a31 100644
--- a/src/local_deep_research/database/rekey_lock.py
+++ b/src/local_deep_research/database/rekey_lock.py
@@ -437,6 +437,9 @@ def _is_database_file(
return True
lock_name = lock_request.lock_path.name
try:
+ # ``lock_request`` is a ``_SidecarLockRequest``, not the HTTP
+ # request; ``lock_path.parent`` is the service-generated directory
+ # of this user's database, so nothing here is caller-supplied.
with os.scandir(lock_request.lock_path.parent) as entries:
for entry in entries:
if entry.name == lock_name:
diff --git a/src/local_deep_research/web/static/js/services/pdf.js b/src/local_deep_research/web/static/js/services/pdf.js
index 5a85522844..281e98fbc9 100644
--- a/src/local_deep_research/web/static/js/services/pdf.js
+++ b/src/local_deep_research/web/static/js/services/pdf.js
@@ -255,6 +255,7 @@ async function generatePdf(title, content, _metadata = {}) {
// Body construction can throw. It stays in this try so the finally
// removes the offscreen .ldr-pdf-content container.
if (pdfBodyDiv && renderedHtml !== undefined) {
+ const template = document.createElement('template');
// Parse the already-sanitized string in an inert <template>
// (no script execution, no resource loading) and move its nodes
// into the live container, so no HTML string is ever assigned
@@ -264,7 +265,6 @@ async function generatePdf(title, content, _metadata = {}) {
// fixpoint. Turning that string into a DOM must parse it
// somewhere; the inert template is that parse, so the sink is
// intentional and suppressed below.
- const template = document.createElement('template');
// bearer:disable javascript_lang_dangerous_insert_html
// eslint-disable-next-line no-unsanitized/property -- renderedHtml is the output of ui.renderMarkdown(): escaped at renderer.html, then sanitizeStable() under the restrictive allowlist; parsed here only into an inert template.
template.innerHTML = renderedHtml;
diff --git a/tests/research_library/services/test_collection_rebuild.py b/tests/research_library/services/test_collection_rebuild.py
index c42d736610..70820ddc77 100644
--- a/tests/research_library/services/test_collection_rebuild.py
+++ b/tests/research_library/services/test_collection_rebuild.py
@@ -1,5 +1,6 @@
"""Real SQLite/FAISS tests for publishing complete collection generations."""
+import ast
import hashlib
import os
import sqlite3
@@ -1465,6 +1466,51 @@ def test_configuration_check_resolves_every_unset_column(world):
assert not service._matches_collection_configuration(legacy)
+def test_publish_writes_exactly_the_snapshotted_config_fields():
+ """Pin the publish writes to the fields ``collection_configuration`` reads.
+
+ ``collection_configuration`` is read-only: it snapshots ``_CONFIG_FIELDS``
+ with ``getattr``. ``CollectionRebuild._publish_rows`` is the only write
+ path for those fields in ``collection_rebuild.py``, and it hardcodes one
+ assignment per field so no dynamic ``setattr`` reaches the ORM object.
+ The two sets must stay identical: every snapshotted configuration field
+ must have a direct publish assignment, and every published configuration
+ field must be included in the snapshot. This guard checks field-name
+ parity, not assigned values or execution paths. The publish path also
+ clears the ``rebuild_pending_since`` notice, which is bookkeeping, not
+ configuration.
+ """
+ from local_deep_research.research_library.services import collection_rebuild
+
+ source = Path(collection_rebuild.__file__).read_text(encoding="utf-8")
+ publish = next(
+ node
+ for node in ast.walk(ast.parse(source))
+ if isinstance(node, ast.FunctionDef) and node.name == "_publish_rows"
+ )
+ written = {
+ target.attr
+ for node in ast.walk(publish)
+ if isinstance(node, (ast.Assign, ast.AnnAssign))
+ for target in (
+ node.targets if isinstance(node, ast.Assign) else [node.target]
+ )
+ if isinstance(target, ast.Attribute)
+ and isinstance(target.value, ast.Name)
+ and target.value.id == "collection"
+ }
+ config_writes = written - {"rebuild_pending_since"}
+ snapshotted = set(collection_rebuild._CONFIG_FIELDS)
+ drifted = [
+ f"{name} is in _CONFIG_FIELDS but the publish path never writes it"
+ for name in sorted(snapshotted - config_writes)
+ ] + [
+ f"{name} is written by the publish path but missing from _CONFIG_FIELDS"
+ for name in sorted(config_writes - snapshotted)
+ ]
+ assert not drifted, drifted
+
+
@pytest.mark.parametrize("cancel", ["before_check", "after_check"])
def test_background_rebuild_status_reports_what_publication_did(
world, task_check, monkeypatch, cancel