fix(mcp): stage remote ingest by default
Default ticket, multipart, and text-note ingest entry points to staging without launching a job. Propagate WIKI_ARCHIVE_SOURCES from project configuration into the managed service environment.\n\nValidated with the full 206-test suite.
This commit is contained in:
@@ -268,7 +268,6 @@ class McpIngestTests(unittest.TestCase):
|
||||
bundle_id="drawing-package-1",
|
||||
source_type="report_package",
|
||||
label="Customer drawing package",
|
||||
start_job=False,
|
||||
)
|
||||
|
||||
self.assertIn("upload_token", ticket)
|
||||
|
||||
@@ -209,6 +209,53 @@ class RemoteMcpServerTests(unittest.TestCase):
|
||||
self.assertEqual(data["uploads"][0]["sha256"], "sha256:" + hashlib.sha256(payload).hexdigest())
|
||||
self.assertNotIn("path", data["uploads"][0])
|
||||
|
||||
def test_http_upload_endpoint_stages_without_starting_job_by_default(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
manager = IngestManager(
|
||||
vault_path=root / "vault",
|
||||
project_root=root / "project",
|
||||
runtime_root=root / "runtime",
|
||||
)
|
||||
app = mcp_server.create_http_app(
|
||||
FakeApp(),
|
||||
"secret-token",
|
||||
ingest_manager=manager,
|
||||
)
|
||||
body, boundary = multipart_body(
|
||||
{"project": "bjd"},
|
||||
[("files", "drawing.pdf", "application/pdf", b"drawing")],
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
manager,
|
||||
"start_ingest_job",
|
||||
side_effect=AssertionError("default upload staging must not start a job"),
|
||||
) as start_job:
|
||||
messages = run_asgi_http_request(
|
||||
app,
|
||||
method="POST",
|
||||
path="/mcp-ingest/uploads",
|
||||
headers=[
|
||||
(b"authorization", b"Bearer secret-token"),
|
||||
(
|
||||
b"content-type",
|
||||
f"multipart/form-data; boundary={boundary}".encode("ascii"),
|
||||
),
|
||||
],
|
||||
body=body,
|
||||
)
|
||||
|
||||
self.assertEqual(messages[0]["status"], 200)
|
||||
response = b"".join(
|
||||
message.get("body", b"")
|
||||
for message in messages
|
||||
if message["type"] == "http.response.body"
|
||||
)
|
||||
data = json.loads(response.decode("utf-8"))
|
||||
self.assertIsNone(data["job"])
|
||||
start_job.assert_not_called()
|
||||
|
||||
def test_http_upload_endpoint_creates_bundle_from_body_and_attachments(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
@@ -411,7 +458,6 @@ class RemoteMcpServerTests(unittest.TestCase):
|
||||
bundle_id="drawing-package-1",
|
||||
source_type="report_package",
|
||||
label="Customer drawing package",
|
||||
start_job=False,
|
||||
)
|
||||
app = mcp_server.create_http_app(FakeApp(), "secret-token", ingest_manager=manager)
|
||||
payload = b"ticket uploaded drawing"
|
||||
@@ -1419,6 +1465,9 @@ class RemoteMcpServerTests(unittest.TestCase):
|
||||
self.assertEqual(ticket["label"], "Customer drawing package")
|
||||
self.assertFalse(ticket["start_job"])
|
||||
self.assertEqual(instructions["preferred_upload_auth"], "upload_ticket")
|
||||
self.assertFalse(instructions["http_upload"]["start_job_default"])
|
||||
self.assertFalse(instructions["direct_text_tool"]["start_job_default"])
|
||||
self.assertIn("start_job=false", instructions["http_upload"]["curl_example"])
|
||||
self.assertEqual(instructions["http_upload"]["url"], "https://wiki.example.test/mcp-ingest/uploads")
|
||||
self.assertIn("body_text", instructions["http_upload"]["optional_fields"])
|
||||
self.assertIn("bundle_id", instructions["http_upload"]["optional_fields"])
|
||||
@@ -1588,14 +1637,19 @@ class RemoteMcpServerTests(unittest.TestCase):
|
||||
ingest_runtime_root=root / "runtime",
|
||||
ingest_manager=manager,
|
||||
)
|
||||
result = FakeMCP.tools["ingest_text_note"](
|
||||
text="Remote agent thought\n\nNeed to remember this.",
|
||||
title="Customer thought: ACME / risk",
|
||||
project="bjd",
|
||||
doc_type_hint="thought",
|
||||
note="captured from remote agent",
|
||||
start_job=False,
|
||||
)
|
||||
with patch.object(
|
||||
manager,
|
||||
"start_ingest_job",
|
||||
side_effect=AssertionError("default text staging must not start a job"),
|
||||
) as start_job:
|
||||
result = FakeMCP.tools["ingest_text_note"](
|
||||
text="Remote agent thought\n\nNeed to remember this.",
|
||||
title="Customer thought: ACME / risk",
|
||||
project="bjd",
|
||||
doc_type_hint="thought",
|
||||
note="captured from remote agent",
|
||||
)
|
||||
start_job.assert_not_called()
|
||||
payload_path = Path(manager._load_upload(result["uploads"][0]["upload_id"])["path"])
|
||||
payload = payload_path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
public_upload_url="https://uploads.example.test/custom/upload",
|
||||
enable_ingest=True,
|
||||
allow_source_files=False,
|
||||
archive_sources=True,
|
||||
ingest_job_timeout_seconds=111,
|
||||
query_job_timeout_seconds=22,
|
||||
ingest_max_request_bytes=333,
|
||||
@@ -81,6 +82,7 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
self.assertIn("OBSIDIAN_MCP_PUBLIC_BASE_URL=http://192.168.1.10:8765/mcp\n", content)
|
||||
self.assertIn("OBSIDIAN_MCP_INGEST_PUBLIC_UPLOAD_URL=https://uploads.example.test/custom/upload\n", content)
|
||||
self.assertIn("OBSIDIAN_MCP_ALLOW_SOURCE_FILES=0\n", content)
|
||||
self.assertIn("WIKI_ARCHIVE_SOURCES=1\n", content)
|
||||
self.assertIn("OBSIDIAN_MCP_ALLOWED_HOSTS=", content)
|
||||
self.assertIn("192.168.1.10:*", content)
|
||||
self.assertIn("OBSIDIAN_MCP_ALLOWED_ORIGINS=", content)
|
||||
@@ -112,6 +114,7 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
public_upload_url="https://uploads.example.test/saved",
|
||||
enabled_tools=("file-assets", "query"),
|
||||
allow_source_files=False,
|
||||
archive_sources=True,
|
||||
ingest_job_timeout_seconds=444,
|
||||
query_job_timeout_seconds=55,
|
||||
ingest_max_request_bytes=666,
|
||||
@@ -128,6 +131,7 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
self.assertEqual(config.public_upload_url, "https://uploads.example.test/saved")
|
||||
self.assertEqual(config.enabled_tools, ("file-assets", "query"))
|
||||
self.assertFalse(config.allow_source_files)
|
||||
self.assertTrue(config.archive_sources)
|
||||
self.assertEqual(config.ingest_job_timeout_seconds, 444)
|
||||
self.assertEqual(config.query_job_timeout_seconds, 55)
|
||||
self.assertEqual(config.ingest_max_request_bytes, 666)
|
||||
@@ -491,6 +495,11 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
project_root = Path(tmp) / "project"
|
||||
project_root.mkdir()
|
||||
(project_root / ".env").write_text(
|
||||
"OBSIDIAN_VAULT_PATH=/data/bjd-vault\n"
|
||||
"WIKI_ARCHIVE_SOURCES=true\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
config_home = Path(tmp) / "config"
|
||||
manage_mcp_service.write_token_env_file(
|
||||
project_root / ".runtime" / "obsidian-wiki-mcp.env",
|
||||
@@ -519,6 +528,7 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
self.assertIn("Bearer saved-token", output)
|
||||
env_content = (project_root / ".runtime" / "obsidian-wiki-mcp.env").read_text(encoding="utf-8")
|
||||
self.assertIn("OBSIDIAN_MCP_ENABLED_TOOLS=file-assets\n", env_content)
|
||||
self.assertIn("WIKI_ARCHIVE_SOURCES=1\n", env_content)
|
||||
self.assertNotIn("OBSIDIAN_MCP_PUBLIC_BASE_URL=", env_content)
|
||||
self.assertNotIn("OBSIDIAN_MCP_INGEST_PUBLIC_UPLOAD_URL=", env_content)
|
||||
generate_token.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user