sibyl-dev 1.3.0__tar.gz → 1.3.2__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.
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/PKG-INFO +2 -2
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/pyproject.toml +2 -2
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client.py +9 -5
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_transport.py +15 -4
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skill-packs/migration.md +61 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/main.py +2 -0
- sibyl_dev-1.3.2/src/sibyl_cli/migrate.py +381 -0
- sibyl_dev-1.3.2/tests/conftest.py +9 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_auth_login.py +70 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_client_auth_refresh.py +1 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_client_errors.py +1 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/.gitignore +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/README.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/__init__.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/archive.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/auth.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/auth_store.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/capture.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/capture_support.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_admin.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_auth.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_graph.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_memory.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_sources.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/client_work.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/command_support.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/common.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/config_cmd.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/config_store.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/context.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/context_quick.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/crawl.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/crawl_shared.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/hooks/session-start.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skill-packs/contract.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skill-packs/core.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skill-packs/examples.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skill-packs/quick.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skill-packs/workflows.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/data/skills/sibyl/SKILL.md +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/debug.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/dev.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/docker.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/doctor.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/document.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/entity.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/entrypoint.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/epic.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/explore.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/export.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/host.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/id_resolution.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/ingest.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/local.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/logs.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/memory.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/memory_admin.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/memory_display.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/memory_review.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/memory_space.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/memory_views.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/onboarding.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/org.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/pending.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/pending_writes.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/project.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/project_refs.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/recall.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/root_commands.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/session.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/setup.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/skill.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/state.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/synthesis.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/task.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/team.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/update.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/version_drift.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/src/sibyl_cli/view_shared.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/__init__.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_archive.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_auth_store.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_client_contract.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_common.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_config_store.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_context_pack.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_debug.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_docker_runtime.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_docs.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_doctor.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_entity.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_entrypoint.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_epic.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_exit_codes.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_export_memory.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_host_runtime.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_id_resolution.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_ingest.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_init.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_local_surreal.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_logs.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_main_capture.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_main_search.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_onboarding.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_org.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_packaged_data.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_pending_cli.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_pending_visibility.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_pending_writes.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_project.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_resolver_is_single.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_session.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_skill.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_source.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_task.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_task_notes.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_update.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_update_server_axis.py +0 -0
- {sibyl_dev-1.3.0 → sibyl_dev-1.3.2}/tests/test_version_drift.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sibyl-dev
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.2
|
|
4
4
|
Summary: CLI for Sibyl knowledge graph and task workflow
|
|
5
5
|
Project-URL: Homepage, https://github.com/hyperb1iss/sibyl
|
|
6
6
|
Project-URL: Repository, https://github.com/hyperb1iss/sibyl
|
|
@@ -19,7 +19,7 @@ Requires-Dist: httpx>=0.27
|
|
|
19
19
|
Requires-Dist: packaging>=26.0
|
|
20
20
|
Requires-Dist: pyyaml>=6.0
|
|
21
21
|
Requires-Dist: rich>=13.0
|
|
22
|
-
Requires-Dist: sibyl-core==1.3.
|
|
22
|
+
Requires-Dist: sibyl-core==1.3.2
|
|
23
23
|
Requires-Dist: tomli-w>=1.2.0
|
|
24
24
|
Requires-Dist: typer>=0.27.1
|
|
25
25
|
Requires-Dist: websockets>=16.1.1
|
|
@@ -42,7 +42,7 @@ dependencies = [
|
|
|
42
42
|
# WebSocket (logs --follow)
|
|
43
43
|
"websockets>=16.1.1",
|
|
44
44
|
# Shared library
|
|
45
|
-
"sibyl-core==1.3.
|
|
45
|
+
"sibyl-core==1.3.2",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
48
|
# =============================================================================
|
|
@@ -55,7 +55,7 @@ dev = [
|
|
|
55
55
|
"pytest-asyncio",
|
|
56
56
|
"pytest-cov>=7.0.0",
|
|
57
57
|
"ruff",
|
|
58
|
-
"ty>=0.0.
|
|
58
|
+
"ty>=0.0.75",
|
|
59
59
|
]
|
|
60
60
|
|
|
61
61
|
[project.scripts]
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"""Public HTTP client contract for the Sibyl CLI."""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
3
|
import httpx
|
|
6
4
|
|
|
7
5
|
from sibyl_cli.auth_store import normalize_api_url
|
|
@@ -25,6 +23,7 @@ from sibyl_cli.client_transport import (
|
|
|
25
23
|
SibylClientError,
|
|
26
24
|
_auth_credential_scope,
|
|
27
25
|
_auth_replay_scope,
|
|
26
|
+
_environment_auth_token,
|
|
28
27
|
_is_read_like_post,
|
|
29
28
|
_is_refresh_revoked,
|
|
30
29
|
_load_default_auth_token,
|
|
@@ -93,7 +92,7 @@ class SibylClient(
|
|
|
93
92
|
)
|
|
94
93
|
self.timeout = timeout
|
|
95
94
|
self._uses_stored_auth = (
|
|
96
|
-
auth_token is None and
|
|
95
|
+
auth_token is None and _environment_auth_token(self.base_url) is None
|
|
97
96
|
)
|
|
98
97
|
self.auth_token = (
|
|
99
98
|
auth_token
|
|
@@ -140,10 +139,15 @@ def get_client(context_name: str | None = None) -> SibylClient:
|
|
|
140
139
|
global _clients
|
|
141
140
|
|
|
142
141
|
# Resolve the effective context when one isn't explicitly provided.
|
|
143
|
-
if context_name is None
|
|
142
|
+
if context_name is None:
|
|
144
143
|
from sibyl_cli import config_store
|
|
144
|
+
from sibyl_cli.state import get_context_override
|
|
145
145
|
|
|
146
|
-
context_name =
|
|
146
|
+
context_name = (
|
|
147
|
+
get_context_override()
|
|
148
|
+
if _paired_automation_api_url()
|
|
149
|
+
else config_store.resolve_context_name()
|
|
150
|
+
)
|
|
147
151
|
|
|
148
152
|
cache_key = context_name
|
|
149
153
|
|
|
@@ -16,6 +16,7 @@ from sibyl_cli.auth_store import (
|
|
|
16
16
|
credential_scope,
|
|
17
17
|
get_access_token,
|
|
18
18
|
is_access_token_expired,
|
|
19
|
+
normalize_api_url,
|
|
19
20
|
read_server_credentials,
|
|
20
21
|
)
|
|
21
22
|
from sibyl_cli.pending_writes import (
|
|
@@ -128,6 +129,17 @@ def _auth_credential_scope(context_name: str | None = None) -> str | None:
|
|
|
128
129
|
return credential_scope(ctx.name, ctx.org_slug)
|
|
129
130
|
|
|
130
131
|
|
|
132
|
+
def _environment_auth_token(api_base_url: str) -> str | None:
|
|
133
|
+
"""Keep a paired automation credential bound to its selected API URL."""
|
|
134
|
+
token = os.environ.get("SIBYL_AUTH_TOKEN", "").strip()
|
|
135
|
+
if not token:
|
|
136
|
+
return None
|
|
137
|
+
paired_url = _paired_automation_api_url()
|
|
138
|
+
if paired_url and normalize_api_url(paired_url) != normalize_api_url(api_base_url):
|
|
139
|
+
return None
|
|
140
|
+
return token
|
|
141
|
+
|
|
142
|
+
|
|
131
143
|
def _load_default_auth_token(
|
|
132
144
|
api_base_url: str,
|
|
133
145
|
credential_scope_name: str | None = None,
|
|
@@ -135,11 +147,10 @@ def _load_default_auth_token(
|
|
|
135
147
|
"""Load auth token for the given API URL.
|
|
136
148
|
|
|
137
149
|
Priority:
|
|
138
|
-
1. SIBYL_AUTH_TOKEN
|
|
150
|
+
1. SIBYL_AUTH_TOKEN when its paired URL matches (or no URL is provided)
|
|
139
151
|
2. Stored access token for the specific server
|
|
140
152
|
"""
|
|
141
|
-
env_token
|
|
142
|
-
if env_token:
|
|
153
|
+
if env_token := _environment_auth_token(api_base_url):
|
|
143
154
|
return env_token
|
|
144
155
|
|
|
145
156
|
return get_access_token(api_base_url, credential_scope=credential_scope_name)
|
|
@@ -241,7 +252,7 @@ def _load_default_replay_scope(
|
|
|
241
252
|
credential_scope_name: str | None,
|
|
242
253
|
auth_token: str | None,
|
|
243
254
|
) -> str | None:
|
|
244
|
-
if
|
|
255
|
+
if _environment_auth_token(api_base_url):
|
|
245
256
|
return _auth_replay_scope(None, auth_token)
|
|
246
257
|
stored_credentials = read_server_credentials(
|
|
247
258
|
api_base_url,
|
|
@@ -486,3 +486,64 @@ feels right.
|
|
|
486
486
|
- Export command source: `apps/api/src/sibyl/cli/migrate.py` (at commit `290b824b`)
|
|
487
487
|
- Import command source: `apps/api/src/sibyl/cli/migrate.py` (at tag `v0.10.0`, the last version
|
|
488
488
|
with the `legacy-archive` on-ramp; removed in `903a738d`)
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
## Migrating a Personal Instance into a Team Server (to-team replay)
|
|
493
|
+
|
|
494
|
+
Use this when a user wants their local project knowledge in a shared team server (an
|
|
495
|
+
enterprise deployment with SSO) and they are not an operator of that server. This is the
|
|
496
|
+
self-service lane; several teammates can each run it with their own login.
|
|
497
|
+
|
|
498
|
+
**Do not reach for the archive/consolidate lane here.** It is operator-shaped (SSH or
|
|
499
|
+
kubectl to the target, root store access), it migrates whole orgs rather than one
|
|
500
|
+
project, and its exporter fails on live stores that contain record links (RecordID
|
|
501
|
+
serialization, issue #459). The replay lane goes through the target's ordinary
|
|
502
|
+
authenticated API instead: ownership lands on the caller's own server identity by
|
|
503
|
+
construction, and the target re-projects and re-embeds from the verbatim raw records.
|
|
504
|
+
|
|
505
|
+
One-time setup per person:
|
|
506
|
+
|
|
507
|
+
```bash
|
|
508
|
+
sibyl config context create <team> --server https://<team-server> --use
|
|
509
|
+
sibyl auth login --server https://<team-server> # their own SSO login
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
The target project must exist on the team server first (any member with project-create
|
|
513
|
+
rights, once for the whole team):
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
sibyl project create "<Project Name>" --description "..."
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
Then, from the person's normal local context:
|
|
520
|
+
|
|
521
|
+
```bash
|
|
522
|
+
sibyl migrate to-team --target-context <team> --project project_<source-scope-key> --dry-run
|
|
523
|
+
sibyl migrate to-team --target-context <team> --project project_<source-scope-key>
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
What the verb guarantees, and what to check:
|
|
527
|
+
|
|
528
|
+
- Scope: only raw captures with `memory_scope=project` and the given scope key move.
|
|
529
|
+
Private memories stay local. Find the scope key distribution first when unsure:
|
|
530
|
+
the source content store's `raw_captures` table, grouped by `scope_key`.
|
|
531
|
+
- Idempotence: a per-route ledger under `~/.sibyl/migrations` (keyed and
|
|
532
|
+
manifest-pinned to source org + target context + target project) persists after every
|
|
533
|
+
successful post, so interrupts and re-runs never duplicate.
|
|
534
|
+
- Provenance: `provenance.migration` on each replayed record carries the origin org,
|
|
535
|
+
raw id, original `created_at`, capture surface, and any truncated original title.
|
|
536
|
+
- Failures are per-row and reported at the end; empty and oversize bodies are named
|
|
537
|
+
individually rather than aborting the run.
|
|
538
|
+
- Replayed records carry today's `created_at` (the original lives in provenance);
|
|
539
|
+
decay-aware backdating is a known follow-up, not a bug to chase.
|
|
540
|
+
- The target needs a working embedding key before the run, or ingestion will queue
|
|
541
|
+
projection failures.
|
|
542
|
+
- Server/client version skew is enforced by the version contract: the server stamps
|
|
543
|
+
`X-Sibyl-Server-Version` and may publish a `minimum_client_version` floor that fails
|
|
544
|
+
old clients closed, so run the migration with a CLI at least as new as the target
|
|
545
|
+
server's release.
|
|
546
|
+
|
|
547
|
+
Verification after a run: a few `sibyl context "<known topic>"` recalls against the
|
|
548
|
+
team context that the user can grade themselves, plus the run's own migrated/skipped/
|
|
549
|
+
failed counts.
|
|
@@ -64,6 +64,7 @@ from sibyl_cli.memory_display import (
|
|
|
64
64
|
is_raw_memory_reference,
|
|
65
65
|
print_memory_source_inspect,
|
|
66
66
|
)
|
|
67
|
+
from sibyl_cli.migrate import app as migrate_app
|
|
67
68
|
from sibyl_cli.org import app as org_app
|
|
68
69
|
from sibyl_cli.pending import app as pending_writes_app
|
|
69
70
|
from sibyl_cli.pending_writes import pending_write_count, pending_write_status
|
|
@@ -147,6 +148,7 @@ app.add_typer(archive_app, name="archive")
|
|
|
147
148
|
app.add_typer(session_app, name="session")
|
|
148
149
|
app.add_typer(entity_app, name="entity")
|
|
149
150
|
app.add_typer(explore_app, name="explore")
|
|
151
|
+
app.add_typer(migrate_app, name="migrate")
|
|
150
152
|
app.add_typer(export_app, name="export")
|
|
151
153
|
app.add_typer(crawl_app, name="crawl")
|
|
152
154
|
app.add_typer(docs_app, name="docs")
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"""Migrate raw memories from a personal instance into a team server.
|
|
2
|
+
|
|
3
|
+
The replay path: raw memory is law, so migration re-submits the verbatim
|
|
4
|
+
raw captures to the target through the ordinary authenticated API, as the
|
|
5
|
+
caller. Ownership lands on the caller's target identity by construction,
|
|
6
|
+
the target re-projects and re-embeds server-side, and no cluster or
|
|
7
|
+
operator access is involved. The source side reads the local content
|
|
8
|
+
store directly, which every personal-instance owner has by definition.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
import json
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Annotated, Any
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
import typer
|
|
20
|
+
|
|
21
|
+
from sibyl_cli.client import get_client
|
|
22
|
+
from sibyl_cli.common import error, info, run_async, success
|
|
23
|
+
|
|
24
|
+
app = typer.Typer(help="Migrate data between Sibyl instances")
|
|
25
|
+
|
|
26
|
+
_LEDGER_DIR = Path.home() / ".sibyl" / "migrations"
|
|
27
|
+
_PAGE_SIZE = 200
|
|
28
|
+
_MAX_TITLE = 300
|
|
29
|
+
_MAX_CONTENT = 500000
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _ledger_path(route: dict[str, str]) -> Path:
|
|
33
|
+
safe = "--".join(
|
|
34
|
+
route[k] for k in ("source_org", "target_context", "target_project_id")
|
|
35
|
+
).replace("/", "_")
|
|
36
|
+
return _LEDGER_DIR / f"{safe}.json"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _load_ledger(path: Path, route: dict[str, str]) -> dict[str, str]:
|
|
40
|
+
"""Load receipts for exactly this migration route.
|
|
41
|
+
|
|
42
|
+
The manifest inside the file pins source org, target context, and
|
|
43
|
+
target project; a mismatch means the file belongs to a different
|
|
44
|
+
route and must not suppress writes for this one.
|
|
45
|
+
"""
|
|
46
|
+
if not path.exists():
|
|
47
|
+
return {}
|
|
48
|
+
try:
|
|
49
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
50
|
+
except (OSError, json.JSONDecodeError):
|
|
51
|
+
return {}
|
|
52
|
+
if not isinstance(data, dict):
|
|
53
|
+
return {}
|
|
54
|
+
if data.get("route") != route:
|
|
55
|
+
raise RuntimeError(
|
|
56
|
+
f"ledger {path} belongs to a different migration route; "
|
|
57
|
+
"move it aside or pass a different target"
|
|
58
|
+
)
|
|
59
|
+
receipts = data.get("receipts")
|
|
60
|
+
return receipts if isinstance(receipts, dict) else {}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _save_ledger(path: Path, route: dict[str, str], ledger: dict[str, str]) -> None:
|
|
64
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
payload = json.dumps({"route": route, "receipts": ledger}, indent=1, sort_keys=True)
|
|
66
|
+
tmp = path.with_suffix(".tmp")
|
|
67
|
+
tmp.write_text(payload, encoding="utf-8")
|
|
68
|
+
tmp.replace(path)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _source_sql(
|
|
72
|
+
*,
|
|
73
|
+
surreal_url: str,
|
|
74
|
+
username: str,
|
|
75
|
+
password: str,
|
|
76
|
+
statement: str,
|
|
77
|
+
) -> list[Any]:
|
|
78
|
+
"""Run one read-only statement against the local content store."""
|
|
79
|
+
base = surreal_url.replace("ws://", "http://").replace("wss://", "https://")
|
|
80
|
+
base = base.removesuffix("/rpc").rstrip("/")
|
|
81
|
+
response = httpx.post(
|
|
82
|
+
f"{base}/sql",
|
|
83
|
+
content=statement,
|
|
84
|
+
auth=(username, password),
|
|
85
|
+
headers={
|
|
86
|
+
"Accept": "application/json",
|
|
87
|
+
"Content-Type": "text/plain",
|
|
88
|
+
"surreal-ns": "sibyl_content",
|
|
89
|
+
"surreal-db": "content",
|
|
90
|
+
},
|
|
91
|
+
timeout=60.0,
|
|
92
|
+
)
|
|
93
|
+
response.raise_for_status()
|
|
94
|
+
payload = response.json()
|
|
95
|
+
results: list[Any] = []
|
|
96
|
+
for item in payload:
|
|
97
|
+
if item.get("status") != "OK":
|
|
98
|
+
raise RuntimeError(f"source query failed: {item.get('result')}")
|
|
99
|
+
results.append(item.get("result"))
|
|
100
|
+
return results
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _fetch_source_page(
|
|
104
|
+
*,
|
|
105
|
+
surreal_url: str,
|
|
106
|
+
username: str,
|
|
107
|
+
password: str,
|
|
108
|
+
organization_id: str,
|
|
109
|
+
scope_key: str,
|
|
110
|
+
start: int,
|
|
111
|
+
) -> list[dict[str, Any]]:
|
|
112
|
+
statement = (
|
|
113
|
+
"SELECT uuid, title, raw_content, memory_scope, scope_key, tags, "
|
|
114
|
+
"metadata, provenance, source_id, capture_surface, created_at "
|
|
115
|
+
"FROM raw_captures "
|
|
116
|
+
f"WHERE organization_id = '{organization_id}' "
|
|
117
|
+
"AND memory_scope = 'project' "
|
|
118
|
+
f"AND scope_key = '{scope_key}' "
|
|
119
|
+
f"ORDER BY created_at ASC LIMIT {_PAGE_SIZE} START {start};"
|
|
120
|
+
)
|
|
121
|
+
rows = _source_sql(
|
|
122
|
+
surreal_url=surreal_url,
|
|
123
|
+
username=username,
|
|
124
|
+
password=password,
|
|
125
|
+
statement=statement,
|
|
126
|
+
)[0]
|
|
127
|
+
return rows or []
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async def _resolve_target_project(client: Any, wanted: str) -> dict[str, Any] | None:
|
|
131
|
+
if wanted.startswith("project_"):
|
|
132
|
+
# Exact ids resolve directly, so a project beyond the listing
|
|
133
|
+
# window is still reachable.
|
|
134
|
+
try:
|
|
135
|
+
entity = await client.get_entity(wanted)
|
|
136
|
+
except Exception:
|
|
137
|
+
entity = None
|
|
138
|
+
if entity and str(entity.get("id", "")).lower() == wanted.lower():
|
|
139
|
+
return entity
|
|
140
|
+
response = await client.explore(mode="list", types=["project"], limit=200)
|
|
141
|
+
lowered = wanted.lower()
|
|
142
|
+
entities = response.get("entities", [])
|
|
143
|
+
for project in entities:
|
|
144
|
+
if str(project.get("id", "")).lower() == lowered:
|
|
145
|
+
return project
|
|
146
|
+
named = [p for p in entities if str(p.get("name", "")).lower() == lowered]
|
|
147
|
+
if len(named) > 1:
|
|
148
|
+
raise RuntimeError(
|
|
149
|
+
f"target project name '{wanted}' is ambiguous "
|
|
150
|
+
f"({', '.join(str(p.get('id')) for p in named)}); "
|
|
151
|
+
"pass --target-project with the exact id"
|
|
152
|
+
)
|
|
153
|
+
return named[0] if named else None
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@app.command("to-team")
|
|
157
|
+
def to_team(
|
|
158
|
+
target_context: Annotated[
|
|
159
|
+
str,
|
|
160
|
+
typer.Option(
|
|
161
|
+
"--target-context",
|
|
162
|
+
help="Named context for the team server (create with sibyl config "
|
|
163
|
+
"context, then sibyl auth login against it)",
|
|
164
|
+
),
|
|
165
|
+
],
|
|
166
|
+
project: Annotated[
|
|
167
|
+
str,
|
|
168
|
+
typer.Option(
|
|
169
|
+
"--project",
|
|
170
|
+
help="Source project scope key (project_...) to migrate",
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
target_project: Annotated[
|
|
174
|
+
str | None,
|
|
175
|
+
typer.Option(
|
|
176
|
+
"--target-project",
|
|
177
|
+
help="Target project id or name; defaults to the same name lookup",
|
|
178
|
+
),
|
|
179
|
+
] = None,
|
|
180
|
+
source_org: Annotated[
|
|
181
|
+
str | None,
|
|
182
|
+
typer.Option(
|
|
183
|
+
"--source-org",
|
|
184
|
+
help="Source organization UUID (defaults to the only org with rows "
|
|
185
|
+
"for the project scope)",
|
|
186
|
+
),
|
|
187
|
+
] = None,
|
|
188
|
+
source_surreal_url: Annotated[
|
|
189
|
+
str,
|
|
190
|
+
typer.Option("--source-surreal-url", help="Local SurrealDB endpoint"),
|
|
191
|
+
] = "ws://localhost:8000/rpc",
|
|
192
|
+
source_surreal_user: Annotated[
|
|
193
|
+
str,
|
|
194
|
+
typer.Option("--source-surreal-user", help="Local SurrealDB username"),
|
|
195
|
+
] = "root",
|
|
196
|
+
source_surreal_pass: Annotated[
|
|
197
|
+
str,
|
|
198
|
+
typer.Option(
|
|
199
|
+
"--source-surreal-pass",
|
|
200
|
+
envvar="SIBYL_SOURCE_SURREAL_PASS",
|
|
201
|
+
show_default=False,
|
|
202
|
+
help="Local SurrealDB password (prefer the "
|
|
203
|
+
"SIBYL_SOURCE_SURREAL_PASS environment variable; a value on "
|
|
204
|
+
"the command line lands in shell history)",
|
|
205
|
+
),
|
|
206
|
+
] = "root",
|
|
207
|
+
dry_run: Annotated[
|
|
208
|
+
bool,
|
|
209
|
+
typer.Option("--dry-run", help="Count and preview without writing"),
|
|
210
|
+
] = False,
|
|
211
|
+
limit: Annotated[
|
|
212
|
+
int | None,
|
|
213
|
+
typer.Option("--limit", help="Migrate at most N memories"),
|
|
214
|
+
] = None,
|
|
215
|
+
) -> None:
|
|
216
|
+
"""Replay a project's raw memories into a team server as yourself.
|
|
217
|
+
|
|
218
|
+
Reads the verbatim raw captures for one project scope from the local
|
|
219
|
+
content store, then re-submits each to the target through POST
|
|
220
|
+
/memory/raw with provenance recording the original identity and
|
|
221
|
+
timestamps. A ledger under ~/.sibyl/migrations makes re-runs skip
|
|
222
|
+
everything already migrated.
|
|
223
|
+
"""
|
|
224
|
+
|
|
225
|
+
@run_async
|
|
226
|
+
async def _run() -> None:
|
|
227
|
+
if source_org:
|
|
228
|
+
org_id = source_org
|
|
229
|
+
else:
|
|
230
|
+
orgs = _source_sql(
|
|
231
|
+
surreal_url=source_surreal_url,
|
|
232
|
+
username=source_surreal_user,
|
|
233
|
+
password=source_surreal_pass,
|
|
234
|
+
statement=(
|
|
235
|
+
"SELECT organization_id, count() AS n FROM raw_captures "
|
|
236
|
+
"WHERE memory_scope = 'project' AND scope_key = "
|
|
237
|
+
f"'{project}' GROUP BY organization_id;"
|
|
238
|
+
),
|
|
239
|
+
)[0]
|
|
240
|
+
if not orgs:
|
|
241
|
+
error(f"No project-scoped raw memories found for {project}")
|
|
242
|
+
raise typer.Exit(1)
|
|
243
|
+
if len(orgs) > 1:
|
|
244
|
+
error(
|
|
245
|
+
"Multiple source orgs carry this project scope; pass "
|
|
246
|
+
"--source-org to disambiguate: "
|
|
247
|
+
+ ", ".join(str(o["organization_id"]) for o in orgs)
|
|
248
|
+
)
|
|
249
|
+
raise typer.Exit(1)
|
|
250
|
+
org_id = str(orgs[0]["organization_id"])
|
|
251
|
+
|
|
252
|
+
info(f"Source org {org_id}, project scope {project}")
|
|
253
|
+
|
|
254
|
+
target = get_client(target_context)
|
|
255
|
+
wanted = target_project or project
|
|
256
|
+
resolved = await _resolve_target_project(target, wanted)
|
|
257
|
+
if resolved is None and target_project is None:
|
|
258
|
+
# Fall back to the source project's display name via the
|
|
259
|
+
# source API (project entities live in the org graph, which
|
|
260
|
+
# the local API serves; the content store does not).
|
|
261
|
+
source = get_client()
|
|
262
|
+
try:
|
|
263
|
+
source_project = await source.get_entity(project)
|
|
264
|
+
except Exception:
|
|
265
|
+
source_project = None
|
|
266
|
+
source_name = str((source_project or {}).get("name") or "").strip()
|
|
267
|
+
if source_name:
|
|
268
|
+
resolved = await _resolve_target_project(target, source_name)
|
|
269
|
+
if resolved is None:
|
|
270
|
+
error(
|
|
271
|
+
f"Target project '{wanted}' not found on {target_context}. "
|
|
272
|
+
"Create it there first (sibyl project create) or pass "
|
|
273
|
+
"--target-project."
|
|
274
|
+
)
|
|
275
|
+
raise typer.Exit(1)
|
|
276
|
+
target_project_id = str(resolved.get("id"))
|
|
277
|
+
info(f"Target project: {resolved.get('name')} ({target_project_id})")
|
|
278
|
+
|
|
279
|
+
route = {
|
|
280
|
+
"source_org": org_id,
|
|
281
|
+
"target_context": target_context,
|
|
282
|
+
"target_project_id": target_project_id,
|
|
283
|
+
}
|
|
284
|
+
ledger_file = _ledger_path(route)
|
|
285
|
+
ledger = _load_ledger(ledger_file, route)
|
|
286
|
+
|
|
287
|
+
migrated = 0
|
|
288
|
+
skipped = 0
|
|
289
|
+
failed: list[str] = []
|
|
290
|
+
start = 0
|
|
291
|
+
while True:
|
|
292
|
+
rows = _fetch_source_page(
|
|
293
|
+
surreal_url=source_surreal_url,
|
|
294
|
+
username=source_surreal_user,
|
|
295
|
+
password=source_surreal_pass,
|
|
296
|
+
organization_id=org_id,
|
|
297
|
+
scope_key=project,
|
|
298
|
+
start=start,
|
|
299
|
+
)
|
|
300
|
+
if not rows:
|
|
301
|
+
break
|
|
302
|
+
for row in rows:
|
|
303
|
+
original_id = str(row.get("uuid"))
|
|
304
|
+
if original_id in ledger:
|
|
305
|
+
skipped += 1
|
|
306
|
+
continue
|
|
307
|
+
if limit is not None and migrated >= limit:
|
|
308
|
+
break
|
|
309
|
+
if dry_run:
|
|
310
|
+
migrated += 1
|
|
311
|
+
continue
|
|
312
|
+
raw_content = str(row.get("raw_content") or "")
|
|
313
|
+
if not raw_content.strip():
|
|
314
|
+
failed.append(f"{original_id}: empty content, not migrated")
|
|
315
|
+
continue
|
|
316
|
+
if len(raw_content) > _MAX_CONTENT:
|
|
317
|
+
failed.append(
|
|
318
|
+
f"{original_id}: content exceeds the API limit "
|
|
319
|
+
f"({len(raw_content)} > {_MAX_CONTENT}); migrate "
|
|
320
|
+
"this record manually"
|
|
321
|
+
)
|
|
322
|
+
continue
|
|
323
|
+
title = str(row.get("title") or "")
|
|
324
|
+
provenance = dict(row.get("provenance") or {})
|
|
325
|
+
provenance["migration"] = {
|
|
326
|
+
"origin_org": org_id,
|
|
327
|
+
"origin_raw_id": original_id,
|
|
328
|
+
"origin_created_at": str(row.get("created_at")),
|
|
329
|
+
"origin_capture_surface": row.get("capture_surface"),
|
|
330
|
+
"tool": "sibyl migrate to-team",
|
|
331
|
+
}
|
|
332
|
+
if len(title) > _MAX_TITLE:
|
|
333
|
+
provenance["migration"]["origin_title"] = title
|
|
334
|
+
title = title[: _MAX_TITLE - 1] + "…"
|
|
335
|
+
# The retrieval layer prefers metadata.project_id over the
|
|
336
|
+
# scope key (_search_candidates), so a copied source
|
|
337
|
+
# project id would misroute or hide the memory on the
|
|
338
|
+
# target.
|
|
339
|
+
metadata = dict(row.get("metadata") or {})
|
|
340
|
+
if metadata.get("project_id"):
|
|
341
|
+
provenance["migration"]["origin_metadata_project_id"] = str(
|
|
342
|
+
metadata["project_id"]
|
|
343
|
+
)
|
|
344
|
+
metadata["project_id"] = target_project_id
|
|
345
|
+
try:
|
|
346
|
+
response = await target.remember_raw_memory(
|
|
347
|
+
title=title,
|
|
348
|
+
raw_content=raw_content,
|
|
349
|
+
source_id=str(row.get("source_id") or "") or f"migrated:{original_id}",
|
|
350
|
+
memory_scope="project",
|
|
351
|
+
scope_key=target_project_id,
|
|
352
|
+
tags=list(row.get("tags") or []),
|
|
353
|
+
metadata=metadata,
|
|
354
|
+
provenance=provenance,
|
|
355
|
+
capture_surface="migration",
|
|
356
|
+
)
|
|
357
|
+
except Exception as exc:
|
|
358
|
+
failed.append(f"{original_id}: {exc}")
|
|
359
|
+
continue
|
|
360
|
+
ledger[original_id] = str(response.get("id") or response.get("uuid") or "ok")
|
|
361
|
+
_save_ledger(ledger_file, route, ledger)
|
|
362
|
+
migrated += 1
|
|
363
|
+
if migrated % 25 == 0:
|
|
364
|
+
info(f" {migrated} migrated...")
|
|
365
|
+
if limit is not None and migrated >= limit:
|
|
366
|
+
break
|
|
367
|
+
start += _PAGE_SIZE
|
|
368
|
+
await asyncio.sleep(0)
|
|
369
|
+
|
|
370
|
+
if not dry_run:
|
|
371
|
+
_save_ledger(ledger_file, route, ledger)
|
|
372
|
+
|
|
373
|
+
verb = "Would migrate" if dry_run else "Migrated"
|
|
374
|
+
success(f"{verb} {migrated} raw memories ({skipped} already in ledger)")
|
|
375
|
+
if failed:
|
|
376
|
+
error(f"{len(failed)} failures:")
|
|
377
|
+
for line in failed[:10]:
|
|
378
|
+
error(f" {line}")
|
|
379
|
+
raise typer.Exit(1)
|
|
380
|
+
|
|
381
|
+
_run()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Keep CLI tests independent of the invoking shell's server credentials."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.fixture(autouse=True)
|
|
7
|
+
def isolated_cli_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
8
|
+
for variable in ("SIBYL_API_URL", "SIBYL_AUTH_TOKEN", "SIBYL_CONTEXT"):
|
|
9
|
+
monkeypatch.delenv(variable, raising=False)
|
|
@@ -466,6 +466,76 @@ def test_paired_automation_url_and_token_override_the_interactive_context(
|
|
|
466
466
|
clear_client_cache()
|
|
467
467
|
|
|
468
468
|
|
|
469
|
+
@pytest.mark.parametrize("selection", ["context", "base_url", "environment", "flag"])
|
|
470
|
+
@pytest.mark.parametrize("stored", [True, False])
|
|
471
|
+
def test_foreign_automation_credentials_do_not_follow_an_explicit_target(
|
|
472
|
+
tmp_path: Path,
|
|
473
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
474
|
+
selection: str,
|
|
475
|
+
stored: bool,
|
|
476
|
+
) -> None:
|
|
477
|
+
from sibyl_cli import state
|
|
478
|
+
|
|
479
|
+
monkeypatch.setattr(config_store.Path, "home", lambda: tmp_path)
|
|
480
|
+
monkeypatch.setattr(state, "_context_override", None)
|
|
481
|
+
monkeypatch.setattr(state, "_ignore_selection", False)
|
|
482
|
+
monkeypatch.delenv("SIBYL_CONTEXT", raising=False)
|
|
483
|
+
config_store.create_context("prod", "https://sibyl.example.com", org_slug="acme")
|
|
484
|
+
monkeypatch.setenv("SIBYL_API_URL", "http://localhost:3344/api")
|
|
485
|
+
monkeypatch.setenv("SIBYL_AUTH_TOKEN", "automation-token")
|
|
486
|
+
scope = None if selection == "base_url" else "context:prod:org:acme"
|
|
487
|
+
if stored:
|
|
488
|
+
auth_store.set_tokens(
|
|
489
|
+
"https://sibyl.example.com/api",
|
|
490
|
+
"prod-token",
|
|
491
|
+
refresh_token="prod-refresh",
|
|
492
|
+
expires_in=3600,
|
|
493
|
+
credential_scope=scope,
|
|
494
|
+
pending_replay_scope="credential:prod",
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
clear_client_cache()
|
|
498
|
+
try:
|
|
499
|
+
if selection == "context":
|
|
500
|
+
client = SibylClient(context_name="prod")
|
|
501
|
+
elif selection == "base_url":
|
|
502
|
+
client = SibylClient(base_url="https://sibyl.example.com/api")
|
|
503
|
+
else:
|
|
504
|
+
if selection == "environment":
|
|
505
|
+
monkeypatch.setenv("SIBYL_CONTEXT", "prod")
|
|
506
|
+
else:
|
|
507
|
+
monkeypatch.setattr(state, "_context_override", "prod")
|
|
508
|
+
client = get_client()
|
|
509
|
+
assert client.base_url == "https://sibyl.example.com/api"
|
|
510
|
+
assert client._default_headers().get("Authorization") == (
|
|
511
|
+
"Bearer prod-token" if stored else None
|
|
512
|
+
)
|
|
513
|
+
assert client._uses_stored_auth is True
|
|
514
|
+
assert client._replay_scope == ("credential:prod" if stored else None)
|
|
515
|
+
finally:
|
|
516
|
+
clear_client_cache()
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
@pytest.mark.parametrize("paired_url", [None, "https://sibyl.example.com/api/"])
|
|
520
|
+
def test_matching_or_unpaired_environment_token_remains_explicit_auth(
|
|
521
|
+
tmp_path: Path,
|
|
522
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
523
|
+
paired_url: str | None,
|
|
524
|
+
) -> None:
|
|
525
|
+
monkeypatch.setattr(config_store.Path, "home", lambda: tmp_path)
|
|
526
|
+
config_store.create_context("prod", "https://sibyl.example.com", org_slug="acme")
|
|
527
|
+
monkeypatch.setenv("SIBYL_AUTH_TOKEN", "automation-token")
|
|
528
|
+
if paired_url:
|
|
529
|
+
monkeypatch.setenv("SIBYL_API_URL", paired_url)
|
|
530
|
+
else:
|
|
531
|
+
monkeypatch.delenv("SIBYL_API_URL", raising=False)
|
|
532
|
+
|
|
533
|
+
client = SibylClient(context_name="prod")
|
|
534
|
+
|
|
535
|
+
assert client._default_headers()["Authorization"] == "Bearer automation-token"
|
|
536
|
+
assert client._uses_stored_auth is False
|
|
537
|
+
|
|
538
|
+
|
|
469
539
|
def test_auth_commands_follow_the_context_override_like_the_client(
|
|
470
540
|
tmp_path: Path,
|
|
471
541
|
monkeypatch: pytest.MonkeyPatch,
|
|
@@ -163,6 +163,7 @@ async def test_silent_local_relogin_refuses_an_unscoped_organization(
|
|
|
163
163
|
async def test_environment_token_ignores_expired_stored_credential(
|
|
164
164
|
monkeypatch: pytest.MonkeyPatch,
|
|
165
165
|
) -> None:
|
|
166
|
+
monkeypatch.delenv("SIBYL_API_URL", raising=False)
|
|
166
167
|
monkeypatch.setenv("SIBYL_AUTH_TOKEN", "automation-token")
|
|
167
168
|
|
|
168
169
|
def unexpected_stored_expiry_check(*_args: object, **_kwargs: object) -> bool:
|
|
@@ -387,6 +387,7 @@ async def test_environment_token_scope_overrides_active_context_scope(
|
|
|
387
387
|
) -> None:
|
|
388
388
|
monkeypatch.setattr(pending_writes.Path, "home", lambda: tmp_path)
|
|
389
389
|
monkeypatch.setattr(client_transport_module, "AUTO_REPLAY_GRACE_SECONDS", 0.0)
|
|
390
|
+
monkeypatch.delenv("SIBYL_API_URL", raising=False)
|
|
390
391
|
monkeypatch.setenv("SIBYL_AUTH_TOKEN", "automation-token")
|
|
391
392
|
monkeypatch.setattr(
|
|
392
393
|
client_module,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|