onesearch-cli 1.8.0__tar.gz → 1.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/PKG-INFO +1 -1
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/__init__.py +1 -1
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/api.py +2 -1
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/commands/source.py +5 -15
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/commands/status.py +10 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/pyproject.toml +1 -1
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_reindex_full.py +5 -2
- onesearch_cli-1.9.0/tests/test_status_indexing.py +73 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/.gitignore +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/README.md +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/banner.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/commands/__init__.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/commands/auth.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/commands/config.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/commands/search.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/config.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/context.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/onesearch/main.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_api.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_auth_commands.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_banner.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_config.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_integration_auth.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_json_output.py +0 -0
- {onesearch_cli-1.8.0 → onesearch_cli-1.9.0}/tests/test_main.py +0 -0
|
@@ -211,7 +211,8 @@ class OneSearchAPI:
|
|
|
211
211
|
full: If true, clear metadata and rebuild every file from scratch.
|
|
212
212
|
|
|
213
213
|
Returns:
|
|
214
|
-
|
|
214
|
+
The backend's acknowledgement. The reindex runs in the background,
|
|
215
|
+
so this has no final statistics.
|
|
215
216
|
"""
|
|
216
217
|
suffix = "?full=true" if full else ""
|
|
217
218
|
return self._request("POST", f"/api/sources/{source_id}/reindex{suffix}")
|
|
@@ -215,21 +215,11 @@ def source_reindex(ctx: Context, source_id: str, full: bool):
|
|
|
215
215
|
action = "Full reindexing" if full else "Reindexing"
|
|
216
216
|
out.print(f"[dim]{action} source [cyan]{s['name']}[/cyan]...[/dim]")
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
#
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
out.print(f"\n[green]✓[/green] Reindex completed for [cyan]{s['name']}[/cyan]")
|
|
224
|
-
out.print(f" Files scanned: {stats.get('total_scanned', 0)}")
|
|
225
|
-
out.print(f" New files: {stats.get('new_files', 0)}")
|
|
226
|
-
out.print(f" Modified: {stats.get('modified_files', 0)}")
|
|
227
|
-
out.print(f" Unchanged: {stats.get('unchanged_files', 0)}")
|
|
228
|
-
out.print(f" [green]Successful: {stats.get('successful', 0)}[/green]")
|
|
229
|
-
if stats.get("failed", 0) > 0:
|
|
230
|
-
out.print(f" [yellow]Failed: {stats.get('failed', 0)}[/yellow]")
|
|
231
|
-
if stats.get("skipped", 0) > 0:
|
|
232
|
-
out.print(f" Skipped: {stats.get('skipped', 0)}")
|
|
218
|
+
api.reindex_source(source_id, full=full)
|
|
219
|
+
|
|
220
|
+
# The backend answers 202 once the reindex is queued, so there are no final stats to print.
|
|
221
|
+
out.print(f"\n[green]✓[/green] Reindex started for [cyan]{s['name']}[/cyan]")
|
|
222
|
+
out.print(f" Check progress with [cyan]onesearch status {source_id}[/cyan]")
|
|
233
223
|
except APIError as e:
|
|
234
224
|
err_console.print(f"[red]Error:[/red] {e.message}")
|
|
235
225
|
raise SystemExit(1) from e
|
|
@@ -7,6 +7,7 @@ import json
|
|
|
7
7
|
from datetime import datetime
|
|
8
8
|
|
|
9
9
|
import click
|
|
10
|
+
from rich.markup import escape
|
|
10
11
|
from rich.table import Table
|
|
11
12
|
|
|
12
13
|
from onesearch.api import APIError
|
|
@@ -77,6 +78,15 @@ def status(ctx: Context, source_id: str | None, as_json: bool):
|
|
|
77
78
|
last_indexed = format_timestamp(result.get("last_indexed_at"))
|
|
78
79
|
console.print(f" Last Index: {last_indexed}")
|
|
79
80
|
|
|
81
|
+
if result.get("indexing"):
|
|
82
|
+
console.print(" [cyan]Reindex running now[/cyan]")
|
|
83
|
+
last_error = result.get("last_reindex_error")
|
|
84
|
+
if last_error:
|
|
85
|
+
failed_at = format_timestamp(last_error.get("at"))
|
|
86
|
+
console.print(
|
|
87
|
+
f" [red]Last reindex failed {failed_at}:[/red] {escape(last_error.get('message', ''))}"
|
|
88
|
+
)
|
|
89
|
+
|
|
80
90
|
# Show failed files if any
|
|
81
91
|
failed_files = result.get("failed_files", [])
|
|
82
92
|
if failed_files:
|
|
@@ -12,7 +12,7 @@ def test_api_reindex_source_can_request_full_rebuild():
|
|
|
12
12
|
|
|
13
13
|
def fake_request(method, endpoint, **kwargs):
|
|
14
14
|
calls.append((method, endpoint, kwargs))
|
|
15
|
-
return {"
|
|
15
|
+
return {"status": "running"}
|
|
16
16
|
|
|
17
17
|
api._request = fake_request
|
|
18
18
|
|
|
@@ -30,7 +30,7 @@ def test_source_reindex_full_flag_calls_full_reindex(monkeypatch):
|
|
|
30
30
|
|
|
31
31
|
def reindex_source(self, source_id, full=False):
|
|
32
32
|
calls.append((source_id, full))
|
|
33
|
-
return {"
|
|
33
|
+
return {"message": "Reindex started for source 'docs'", "status": "running", "full": full}
|
|
34
34
|
|
|
35
35
|
monkeypatch.setattr(Context, "get_api", lambda self: FakeAPI())
|
|
36
36
|
|
|
@@ -40,3 +40,6 @@ def test_source_reindex_full_flag_calls_full_reindex(monkeypatch):
|
|
|
40
40
|
assert result.exit_code == 0
|
|
41
41
|
assert calls == [("docs", True)]
|
|
42
42
|
assert "Full reindexing source" in result.output
|
|
43
|
+
assert "Reindex started for" in result.output
|
|
44
|
+
assert "onesearch status docs" in result.output
|
|
45
|
+
assert "Reindex completed" not in result.output
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Copyright (C) 2026 demigodmode
|
|
2
|
+
# SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
"""`onesearch status <id>` has to show a background reindex that is running or failed."""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
from click.testing import CliRunner
|
|
9
|
+
|
|
10
|
+
from onesearch.context import Context
|
|
11
|
+
from onesearch.main import cli
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FakeAPI:
|
|
15
|
+
def __init__(self, detail):
|
|
16
|
+
self.detail = detail
|
|
17
|
+
|
|
18
|
+
def source_status(self, source_id):
|
|
19
|
+
return {
|
|
20
|
+
"source_id": source_id,
|
|
21
|
+
"source_name": "Docs",
|
|
22
|
+
"total_files": 3,
|
|
23
|
+
"successful": 3,
|
|
24
|
+
"failed": 0,
|
|
25
|
+
"skipped": 0,
|
|
26
|
+
"last_indexed_at": None,
|
|
27
|
+
"failed_files": [],
|
|
28
|
+
**self.detail,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _invoke(monkeypatch, detail, args):
|
|
33
|
+
monkeypatch.setattr(Context, "get_api", lambda self: FakeAPI(detail))
|
|
34
|
+
return CliRunner().invoke(cli, ["--url", "http://testserver", "status", "docs", *args], obj=Context())
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_running_reindex_is_shown(monkeypatch):
|
|
38
|
+
result = _invoke(monkeypatch, {"indexing": True, "last_reindex_error": None}, [])
|
|
39
|
+
|
|
40
|
+
assert result.exit_code == 0, result.output
|
|
41
|
+
assert "Reindex running" in result.output
|
|
42
|
+
assert "Last reindex failed" not in result.output
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_last_failed_reindex_is_shown_with_its_reason(monkeypatch):
|
|
46
|
+
detail = {
|
|
47
|
+
"indexing": False,
|
|
48
|
+
"last_reindex_error": {
|
|
49
|
+
"message": "Root path does not exist: /data/gone",
|
|
50
|
+
"at": "2026-12-05T10:15:00+00:00",
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
result = _invoke(monkeypatch, detail, [])
|
|
55
|
+
|
|
56
|
+
assert result.exit_code == 0, result.output
|
|
57
|
+
assert "Last reindex failed" in result.output
|
|
58
|
+
assert "Root path does not exist: /data/gone" in " ".join(result.output.split())
|
|
59
|
+
assert "Reindex running" not in result.output
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_json_output_carries_the_run_state(monkeypatch):
|
|
63
|
+
detail = {
|
|
64
|
+
"indexing": False,
|
|
65
|
+
"last_reindex_error": {"message": "share went away", "at": "2026-12-05T10:15:00+00:00"},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
result = _invoke(monkeypatch, detail, ["--json"])
|
|
69
|
+
|
|
70
|
+
assert result.exit_code == 0, result.output
|
|
71
|
+
data = json.loads(result.output)
|
|
72
|
+
assert data["indexing"] is False
|
|
73
|
+
assert data["last_reindex_error"]["message"] == "share went away"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|