doover-cli 0.6.7__tar.gz → 0.6.9__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.
Files changed (97) hide show
  1. {doover_cli-0.6.7 → doover_cli-0.6.9}/PKG-INFO +1 -1
  2. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/__init__.py +1 -1
  3. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/apps.py +117 -0
  4. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/config_schema.py +5 -0
  5. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/notification_schema.py +2 -2
  6. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/apps.py +127 -11
  7. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_apps.py +66 -0
  8. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_schema_export.py +117 -2
  9. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_utils_apps.py +130 -0
  10. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/CONTRIBUTING.md +0 -0
  11. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/ISSUE_TEMPLATE/bug-report.yaml +0 -0
  12. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  13. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/ISSUE_TEMPLATE/feature-request.yml +0 -0
  14. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  15. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/workflows/lint-test.yml +0 -0
  16. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/workflows/release-brew.yml +0 -0
  17. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/workflows/release-pypi.yml +0 -0
  18. {doover_cli-0.6.7 → doover_cli-0.6.9}/.github/workflows/release.yml +0 -0
  19. {doover_cli-0.6.7 → doover_cli-0.6.9}/.gitignore +0 -0
  20. {doover_cli-0.6.7 → doover_cli-0.6.9}/.pre-commit-config.yaml +0 -0
  21. {doover_cli-0.6.7 → doover_cli-0.6.9}/AGENT.md +0 -0
  22. {doover_cli-0.6.7 → doover_cli-0.6.9}/LICENSE +0 -0
  23. {doover_cli-0.6.7 → doover_cli-0.6.9}/README.md +0 -0
  24. {doover_cli-0.6.7 → doover_cli-0.6.9}/debian/changelog +0 -0
  25. {doover_cli-0.6.7 → doover_cli-0.6.9}/debian/control +0 -0
  26. {doover_cli-0.6.7 → doover_cli-0.6.9}/debian/rules +0 -0
  27. {doover_cli-0.6.7 → doover_cli-0.6.9}/docs/user_stories.md +0 -0
  28. {doover_cli-0.6.7 → doover_cli-0.6.9}/pyproject.toml +0 -0
  29. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/agent.py +0 -0
  30. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/api/__init__.py +0 -0
  31. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/api/auth.py +0 -0
  32. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/api/errors.py +0 -0
  33. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/api/session.py +0 -0
  34. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/app_install.py +0 -0
  35. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/device.py +0 -0
  36. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/device_type.py +0 -0
  37. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/migrate.py +0 -0
  38. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/tunnel.py +0 -0
  39. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/apps/widget_plugin.py +0 -0
  40. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/channel.py +0 -0
  41. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/colours.py +0 -0
  42. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/dda_logs.py +0 -0
  43. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/doover_config.py +0 -0
  44. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/grpc.py +0 -0
  45. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/login.py +0 -0
  46. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/registry.py +0 -0
  47. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/renderer/__init__.py +0 -0
  48. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/renderer/_base.py +0 -0
  49. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/renderer/_basic.py +0 -0
  50. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/renderer/_default.py +0 -0
  51. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/renderer/_json.py +0 -0
  52. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/report.py +0 -0
  53. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/simulator.py +0 -0
  54. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/ui_schema.py +0 -0
  55. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/user.py +0 -0
  56. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/__init__.py +0 -0
  57. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/api.py +0 -0
  58. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/context.py +0 -0
  59. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/crud/__init__.py +0 -0
  60. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/crud/commands.py +0 -0
  61. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/crud/lookup.py +0 -0
  62. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/crud/prompting.py +0 -0
  63. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/crud/schema.py +0 -0
  64. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/crud/values.py +0 -0
  65. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/errors.py +0 -0
  66. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/formatters.py +0 -0
  67. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/misc.py +0 -0
  68. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/parsers.py +0 -0
  69. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/prompt.py +0 -0
  70. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/sentry.py +0 -0
  71. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/shell_commands.py +0 -0
  72. {doover_cli-0.6.7 → doover_cli-0.6.9}/src/doover_cli/utils/state.py +0 -0
  73. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/__init__.py +0 -0
  74. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/conftest.py +0 -0
  75. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_agent.py +0 -0
  76. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_app_install.py +0 -0
  77. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_auth_integration.py +0 -0
  78. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_auth_unit.py +0 -0
  79. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_basic.py +0 -0
  80. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_crud_commands.py +0 -0
  81. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_crud_lookup.py +0 -0
  82. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_crud_prompting.py +0 -0
  83. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_crud_schema.py +0 -0
  84. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_crud_values.py +0 -0
  85. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_default_renderer.py +0 -0
  86. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_device.py +0 -0
  87. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_device_cli_integration.py +0 -0
  88. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_device_type.py +0 -0
  89. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_device_type_cli_integration.py +0 -0
  90. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_discover.py +0 -0
  91. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_migrate.py +0 -0
  92. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_prompt.py +0 -0
  93. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_registry.py +0 -0
  94. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_sentry.py +0 -0
  95. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_user.py +0 -0
  96. {doover_cli-0.6.7 → doover_cli-0.6.9}/tests/test_widget_plugin.py +0 -0
  97. {doover_cli-0.6.7 → doover_cli-0.6.9}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: doover-cli
3
- Version: 0.6.7
3
+ Version: 0.6.9
4
4
  Summary: CLI for Doover
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.11
@@ -1,7 +1,7 @@
1
1
  from doover_cli.renderer import Renderer
2
2
  from typing import Annotated, Optional
3
3
 
4
- __version__ = "0.6.7"
4
+ __version__ = "0.6.9"
5
5
 
6
6
  import click
7
7
  import typer
@@ -33,6 +33,7 @@ from ..registry import is_doover_registry, login_for_push, publish_github_output
33
33
  from ..utils.apps import (
34
34
  PACKAGE_APP_TYPES,
35
35
  discover_apps,
36
+ filter_create_only,
36
37
  get_app_directory,
37
38
  call_with_uv,
38
39
  get_docker_path,
@@ -128,6 +129,67 @@ def _detect_git_commit(root_fp: Path) -> str:
128
129
  return result.stdout.strip() if result.returncode == 0 else ""
129
130
 
130
131
 
132
+ def _normalise_remote_url(remote: str) -> str | None:
133
+ """A git remote as a browsable https URL, or None if it isn't one.
134
+
135
+ Remotes here are SSH by convention, which is not a URL anyone can open, and
136
+ the field is rendered as a link.
137
+ """
138
+ remote = remote.strip()
139
+ if not remote:
140
+ return None
141
+
142
+ # scp-style: git@host:org/repo.git
143
+ if "://" not in remote and ":" in remote and not remote.startswith("/"):
144
+ userhost, _, path = remote.partition(":")
145
+ host = userhost.rpartition("@")[2]
146
+ if not host or not path:
147
+ return None
148
+ remote = f"https://{host}/{path}"
149
+ elif remote.startswith(("ssh://", "git://")):
150
+ remote = "https://" + remote.split("://", 1)[1]
151
+ elif not remote.startswith(("http://", "https://")):
152
+ # A local path or a protocol nothing can browse.
153
+ return None
154
+
155
+ scheme, _, rest = remote.partition("://")
156
+ # Strip credentials -- a token embedded in a CI checkout's remote must not
157
+ # be published.
158
+ rest = rest.rpartition("@")[2]
159
+ remote = f"{scheme}://{rest}"
160
+
161
+ if remote.endswith(".git"):
162
+ remote = remote[: -len(".git")]
163
+ remote = remote.rstrip("/")
164
+ return remote or None
165
+
166
+
167
+ def _detect_repository_url(root_fp: Path) -> str | None:
168
+ """Best-effort repository URL for the app dir, from CI or `origin`."""
169
+ server = os.environ.get("GITHUB_SERVER_URL")
170
+ repository = os.environ.get("GITHUB_REPOSITORY")
171
+ if server and repository:
172
+ return f"{server.rstrip('/')}/{repository}"
173
+
174
+ project_url = os.environ.get("CI_PROJECT_URL")
175
+ if project_url:
176
+ return project_url.rstrip("/")
177
+
178
+ try:
179
+ result = subprocess.run(
180
+ ["git", "remote", "get-url", "origin"],
181
+ cwd=root_fp,
182
+ capture_output=True,
183
+ text=True,
184
+ check=False,
185
+ )
186
+ except OSError:
187
+ return None
188
+ if result.returncode != 0:
189
+ return None
190
+ return _normalise_remote_url(result.stdout)
191
+
192
+
131
193
  def _is_multi_platform(build_args: str) -> bool:
132
194
  """Whether `build_args` asks for more than one platform.
133
195
 
@@ -456,6 +518,47 @@ def _resolve_application_id(client, app_config, *, staging: bool) -> int | None:
456
518
  return None
457
519
 
458
520
 
521
+ def _fetch_existing_application(client, app_config, *, staging: bool):
522
+ """The app as the cloud currently holds it, or None if it doesn't exist yet.
523
+
524
+ Publishing is a patch, and some fields are only seeded on create -- see
525
+ CREATE_ONLY_FIELDS -- so the payload can't be decided without knowing what is
526
+ already there.
527
+ """
528
+ app_id = _get_persisted_application_id(app_config, staging=staging)
529
+ if app_id is not None:
530
+ try:
531
+ return client.applications.retrieve(str(app_id))
532
+ except Exception:
533
+ # A pinned id that doesn't resolve is the publish's problem, not
534
+ # ours; it fails with a clearer error a few lines later.
535
+ return None
536
+
537
+ try:
538
+ page = client.applications.list(
539
+ name=app_config.name,
540
+ archived=False,
541
+ page=1,
542
+ per_page=100,
543
+ )
544
+ except Exception:
545
+ return None
546
+
547
+ matches = [
548
+ item for item in page.results if getattr(item, "name", None) == app_config.name
549
+ ]
550
+ return matches[0] if len(matches) == 1 else None
551
+
552
+
553
+ def _report_create_only_skips(skipped: dict) -> None:
554
+ for field, (cloud_value, config_value) in sorted(skipped.items()):
555
+ rich.print(
556
+ f"[yellow]{field}: keeping {cloud_value!r} from the cloud "
557
+ f"(doover_config.json says {config_value!r}). This field is only "
558
+ f"seeded on create -- change it in the admin portal.[/yellow]"
559
+ )
560
+
561
+
459
562
  def _image_package_uri(app_config) -> str | None:
460
563
  """The ECR image a processor deploys from, or None if it ships a package.zip.
461
564
 
@@ -1295,6 +1398,13 @@ def publish(
1295
1398
  include_deployment_data=True,
1296
1399
  )
1297
1400
 
1401
+ # Seeded from the checkout when doover_config.json doesn't name one. It is
1402
+ # create-only, so a detected value never overwrites what the cloud holds.
1403
+ if "repository_url" not in payload:
1404
+ detected_repository = _detect_repository_url(root_fp)
1405
+ if detected_repository:
1406
+ payload["repository_url"] = detected_repository
1407
+
1298
1408
  client, renderer = get_state()
1299
1409
 
1300
1410
  # The publish endpoints are organisation-scoped: without the
@@ -1322,6 +1432,13 @@ def publish(
1322
1432
  f"Updating application on doover site ({_control_base_url() or 'unknown base URL'})...\n"
1323
1433
  )
1324
1434
 
1435
+ with renderer.loading("Reading current application..."):
1436
+ existing = _fetch_existing_application(
1437
+ client, app_config, staging=resolved_staging
1438
+ )
1439
+ payload, skipped = filter_create_only(payload, existing)
1440
+ _report_create_only_skips(skipped)
1441
+
1325
1442
  try:
1326
1443
  with renderer.loading("Publishing application..."):
1327
1444
  application_id = _get_persisted_application_id(
@@ -14,6 +14,7 @@ from .utils.apps import (
14
14
  get_app_config,
15
15
  preserve_file,
16
16
  run_schema_export,
17
+ RUST_EXPORT_COMMAND,
17
18
  )
18
19
 
19
20
  app = typer.Typer(no_args_is_help=True)
@@ -65,6 +66,10 @@ def export(
65
66
  "export-config",
66
67
  app_name=app_config.name,
67
68
  cwd=app_fp,
69
+ # The one exporter that drives a Rust binary: its `export` writes
70
+ # every schema the app has, so the UI and notification exporters
71
+ # have nothing left to run.
72
+ rust_default=RUST_EXPORT_COMMAND,
68
73
  )
69
74
  else:
70
75
  config = get_app_config(app_fp, app_name=app_name)
@@ -46,16 +46,16 @@ def export(
46
46
  print("App requested no notification export. Skipping...")
47
47
  return
48
48
 
49
+ print("Exporting notification schema...")
49
50
  run_schema_export(
50
51
  root_fp,
51
52
  app_config.export_notification_command,
52
53
  "export-notifications",
54
+ optional=True,
53
55
  app_name=app_config.name,
54
56
  cwd=app_fp,
55
57
  )
56
58
 
57
- print("Exporting notification schema...")
58
-
59
59
  if validate_ is True:
60
60
  print("Validating notification schema...")
61
61
  ctx.invoke(validate, ctx, app_fp=app_fp, export_=False)
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import json
3
3
  import sys
4
+ import tomllib
4
5
  import base64
5
6
  import shutil
6
7
  import contextlib
@@ -42,10 +43,34 @@ RETIRED_FIELDS: dict[str, str | None] = {
42
43
  # app at the wrong function.
43
44
  "lambda_arn": None,
44
45
  "stars": None,
46
+ "long_description_ui": None,
47
+ "long_description_source": None,
45
48
  }
46
49
 
47
50
  # Never included in a publish payload, whatever the config says.
48
- NEVER_SENT = frozenset({"lambda_arn", "stars"})
51
+ NEVER_SENT = frozenset(
52
+ {
53
+ "lambda_arn",
54
+ "stars",
55
+ "long_description_ui",
56
+ "long_description_source",
57
+ }
58
+ )
59
+
60
+ # Seeded from doover_config.json when the app is created, or when the cloud has
61
+ # no value yet. After that the cloud wins and publishing leaves them alone, so
62
+ # an edit made in the admin portal survives the next deploy.
63
+ CREATE_ONLY_FIELDS = frozenset(
64
+ {
65
+ "display_name",
66
+ "description",
67
+ "visibility",
68
+ "allow_many",
69
+ "icon_url",
70
+ "banner_url",
71
+ "repository_url",
72
+ }
73
+ )
49
74
 
50
75
 
51
76
  def resolve_ref(data: dict[str, Any], canonical: str) -> Any:
@@ -64,6 +89,39 @@ def resolve_ref(data: dict[str, Any], canonical: str) -> Any:
64
89
  return None
65
90
 
66
91
 
92
+ def _has_cloud_value(value: Any) -> bool:
93
+ if value is None:
94
+ return False
95
+ if isinstance(value, str):
96
+ return bool(value.strip())
97
+ return True
98
+
99
+
100
+ def filter_create_only(
101
+ payload: dict[str, Any], existing: Any | None
102
+ ) -> tuple[dict[str, Any], dict[str, tuple[Any, Any]]]:
103
+ """Drop CREATE_ONLY_FIELDS the cloud already has a value for.
104
+
105
+ Returns the payload to send and the fields that were held back, as
106
+ `{field: (cloud_value, config_value)}`.
107
+ """
108
+ if existing is None:
109
+ return payload, {}
110
+
111
+ kept = dict(payload)
112
+ skipped: dict[str, tuple[Any, Any]] = {}
113
+ for field in CREATE_ONLY_FIELDS:
114
+ if field not in kept:
115
+ continue
116
+ cloud_value = getattr(existing, field, None)
117
+ if not _has_cloud_value(cloud_value):
118
+ continue
119
+ config_value = kept.pop(field)
120
+ if cloud_value != config_value:
121
+ skipped[field] = (cloud_value, config_value)
122
+ return kept, skipped
123
+
124
+
67
125
  def warn_retired_fields(data: dict[str, Any]) -> None:
68
126
  for key in sorted(set(RETIRED_FIELDS) & set(data)):
69
127
  replacement = RETIRED_FIELDS[key]
@@ -122,6 +180,7 @@ class LocalApplication(ControlApplication):
122
180
  config_profiles: list[Any] | None = None,
123
181
  icon_url: str | None = None,
124
182
  banner_url: str | None = None,
183
+ repository_url: str | None = None,
125
184
  key: str | None = None,
126
185
  build_args: str | None = None,
127
186
  widget: str | Path | None = None,
@@ -158,6 +217,7 @@ class LocalApplication(ControlApplication):
158
217
  config_profiles=config_profiles,
159
218
  icon_url=icon_url,
160
219
  banner_url=banner_url,
220
+ repository_url=repository_url,
161
221
  )
162
222
 
163
223
  path = (
@@ -319,6 +379,7 @@ class LocalApplication(ControlApplication):
319
379
  staging_config=data.get("staging_config", {}),
320
380
  icon_url=data.get("icon_url"),
321
381
  banner_url=data.get("banner_url"),
382
+ repository_url=data.get("repository_url"),
322
383
  base_path=app_base,
323
384
  deployment_folder=data.get("deployment_folder"),
324
385
  )
@@ -410,6 +471,7 @@ class LocalApplication(ControlApplication):
410
471
  "notification_schema": self.notification_schema,
411
472
  "icon_url": self.icon_url,
412
473
  "banner_url": self.banner_url,
474
+ "repository_url": self.repository_url,
413
475
  }
414
476
  )
415
477
 
@@ -624,40 +686,94 @@ def detect_language(app_dir: Path) -> str | None:
624
686
 
625
687
 
626
688
  # What a Rust app runs to regenerate its schemas. The framework gives every
627
- # application binary an `export [path] [--app-name NAME]` subcommand that writes
628
- # the config schema and, when the app has one, the UI schema -- one command for
629
- # both, with the same read-merge-write over doover_config.json that pydoover's
630
- # exporters do. Driven through cargo so it works from a plain checkout with
631
- # nothing built yet, which is the state CI is always in.
689
+ # application binary a single `export [path] [--app-name NAME]` subcommand that
690
+ # writes the config schema and, when the app has one, the UI schema -- with the
691
+ # same read-merge-write over doover_config.json that pydoover's exporters do.
692
+ # Driven through cargo so it works from a plain checkout with nothing built yet,
693
+ # which is the state CI is always in.
694
+ #
695
+ # One command for every schema, which is why only the config exporter passes it
696
+ # as its `rust_default`: see run_schema_export.
632
697
  RUST_EXPORT_COMMAND = "cargo run --quiet -- export doover_config.json"
633
698
 
634
699
 
700
+ def python_declares_script(app_dir: Path, script: str) -> bool | None:
701
+ """Whether `app_dir`'s pyproject.toml declares the `script` console script.
702
+
703
+ None when there is nothing to go on -- no pyproject.toml, or one this can't
704
+ read -- so a caller can fall back to running the script and finding out.
705
+ """
706
+ pyproject = app_dir / "pyproject.toml"
707
+ if not pyproject.exists():
708
+ return None
709
+ try:
710
+ data = tomllib.loads(pyproject.read_text())
711
+ except (tomllib.TOMLDecodeError, OSError):
712
+ return None
713
+
714
+ scripts = data.get("project", {}).get("scripts")
715
+ if not isinstance(scripts, dict):
716
+ # A pyproject with no scripts table declares no exporters at all, which
717
+ # is an answer rather than a gap.
718
+ return False
719
+ return script in scripts
720
+
721
+
635
722
  def run_schema_export(
636
723
  app_dir: Path,
637
724
  command: str | None,
638
725
  python_default: str,
639
726
  app_name: str | None = None,
640
727
  cwd: Path | None = None,
728
+ rust_default: str | None = None,
729
+ optional: bool = False,
641
730
  ) -> None:
642
731
  """Regenerate an app's schemas by running its own exporter.
643
732
 
644
- Python apps run a console script under uv, as they always have. Rust apps
645
- run their binary's built-in `export` subcommand, so the schema in
646
- doover_config.json comes from the source in both languages rather than from
647
- whatever was committed.
733
+ Python apps run a console script under uv, as they always have: one script
734
+ per schema, each with its own default.
735
+
736
+ Rust apps have no such split. The framework gives a binary one `export`
737
+ subcommand that writes every schema it has, so exactly one exporter drives
738
+ it -- the config one, which passes `rust_default`. The others do nothing for
739
+ a Rust app unless it names a command explicitly, because there is nothing
740
+ left for them to write and no second subcommand to call.
741
+
742
+ That asymmetry is not cosmetic. Inventing `cargo run -- export` as the
743
+ default for *any* schema kind means a repo whose binary is not a doover-rs
744
+ application runs it anyway: doover-device-agent's binary rejects `export`
745
+ and fails the publish, and doover-device-runtime's supervisor accepts any
746
+ argv, so it started supervising and hung a CI job for 75 minutes. Both had
747
+ already opted out of every exporter that existed when they were written; the
748
+ next one to be added found them again.
648
749
 
649
750
  `command` is the app's own `export_*_command`, honoured verbatim when set --
650
751
  an app whose binary is not what `cargo run` picks by default (a workspace
651
752
  with several) says so there rather than being unbuildable by CI.
652
753
  """
653
754
  if detect_language(app_dir) == "rs":
654
- cmd = command or RUST_EXPORT_COMMAND
755
+ cmd = command or rust_default
756
+ if cmd is None:
757
+ print(
758
+ "Rust app: its `export` subcommand writes every schema it has, "
759
+ "and the config export already ran it. Skipping..."
760
+ )
761
+ return
655
762
  # The binary otherwise falls back to APP_KEY or its own file name, which
656
763
  # is not the application name in a repo whose binary is spelled with
657
764
  # hyphens and whose app is spelled with underscores.
658
765
  if app_name and "--app-name" not in cmd:
659
766
  cmd = f"{cmd} --app-name {app_name}"
660
767
  run(cmd, cwd=app_dir)
768
+ elif (
769
+ optional
770
+ and command is None
771
+ and (python_declares_script(app_dir, python_default) is False)
772
+ ):
773
+ print(
774
+ f"App declares no `{python_default}` script, so it has no schema of "
775
+ "this kind. Skipping..."
776
+ )
661
777
  else:
662
778
  call_with_uv(command or python_default, in_shell=True, cwd=cwd)
663
779
 
@@ -1,4 +1,5 @@
1
1
  import re
2
+ import subprocess
2
3
  from contextlib import nullcontext
3
4
  from types import SimpleNamespace
4
5
 
@@ -1562,3 +1563,68 @@ def test_publish_processor_package_uses_package_zip(tmp_path):
1562
1563
  assert response == {"id": 303}
1563
1564
  assert captured["application_id"] == "303"
1564
1565
  assert captured["body"] == {"file": package_fp}
1566
+
1567
+
1568
+ @pytest.mark.parametrize(
1569
+ "remote,expected",
1570
+ [
1571
+ (
1572
+ "git@github.com:spaneng/analog-level-sensor.git",
1573
+ "https://github.com/spaneng/analog-level-sensor",
1574
+ ),
1575
+ (
1576
+ "ssh://git@github.com/spaneng/analog-level-sensor.git",
1577
+ "https://github.com/spaneng/analog-level-sensor",
1578
+ ),
1579
+ (
1580
+ "https://github.com/spaneng/analog-level-sensor.git\n",
1581
+ "https://github.com/spaneng/analog-level-sensor",
1582
+ ),
1583
+ # A CI checkout's remote can carry a token; publishing it would leak it.
1584
+ (
1585
+ "https://x-access-token:secret@github.com/spaneng/app.git",
1586
+ "https://github.com/spaneng/app",
1587
+ ),
1588
+ ("/srv/git/local-repo.git", None),
1589
+ ("", None),
1590
+ ],
1591
+ )
1592
+ def test_normalise_remote_url(remote, expected):
1593
+ assert apps_app._normalise_remote_url(remote) == expected
1594
+
1595
+
1596
+ def test_detect_repository_url_prefers_github_actions_env(monkeypatch, tmp_path):
1597
+ monkeypatch.setenv("GITHUB_SERVER_URL", "https://github.com")
1598
+ monkeypatch.setenv("GITHUB_REPOSITORY", "spaneng/analog-level-sensor")
1599
+
1600
+ assert (
1601
+ apps_app._detect_repository_url(tmp_path)
1602
+ == "https://github.com/spaneng/analog-level-sensor"
1603
+ )
1604
+
1605
+
1606
+ def test_detect_repository_url_falls_back_to_the_origin_remote(monkeypatch, tmp_path):
1607
+ monkeypatch.delenv("GITHUB_SERVER_URL", raising=False)
1608
+ monkeypatch.delenv("GITHUB_REPOSITORY", raising=False)
1609
+ monkeypatch.delenv("CI_PROJECT_URL", raising=False)
1610
+ subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
1611
+ subprocess.run(
1612
+ ["git", "remote", "add", "origin", "git@github.com:spaneng/tracker.git"],
1613
+ cwd=tmp_path,
1614
+ check=True,
1615
+ )
1616
+
1617
+ assert (
1618
+ apps_app._detect_repository_url(tmp_path)
1619
+ == "https://github.com/spaneng/tracker"
1620
+ )
1621
+
1622
+
1623
+ def test_detect_repository_url_is_none_outside_a_repo(monkeypatch, tmp_path):
1624
+ monkeypatch.delenv("GITHUB_SERVER_URL", raising=False)
1625
+ monkeypatch.delenv("GITHUB_REPOSITORY", raising=False)
1626
+ monkeypatch.delenv("CI_PROJECT_URL", raising=False)
1627
+ # An empty HOME keeps a parent repo's origin (this checkout's) out of it.
1628
+ monkeypatch.setenv("GIT_CEILING_DIRECTORIES", str(tmp_path.parent))
1629
+
1630
+ assert apps_app._detect_repository_url(tmp_path) is None
@@ -60,7 +60,13 @@ class TestRunSchemaExport:
60
60
  def test_rust_app_runs_its_export_subcommand(self, tmp_path, calls):
61
61
  (tmp_path / "Cargo.toml").touch()
62
62
 
63
- apps_utils.run_schema_export(tmp_path, None, "export-config", app_name="foo")
63
+ apps_utils.run_schema_export(
64
+ tmp_path,
65
+ None,
66
+ "export-config",
67
+ app_name="foo",
68
+ rust_default=apps_utils.RUST_EXPORT_COMMAND,
69
+ )
64
70
 
65
71
  assert calls["uv"] == []
66
72
  cmd, cwd = calls["run"][0]
@@ -71,10 +77,44 @@ class TestRunSchemaExport:
71
77
  def test_rust_app_without_an_app_name_leaves_the_flag_off(self, tmp_path, calls):
72
78
  (tmp_path / "Cargo.toml").touch()
73
79
 
74
- apps_utils.run_schema_export(tmp_path, None, "export-config")
80
+ apps_utils.run_schema_export(
81
+ tmp_path, None, "export-config", rust_default=apps_utils.RUST_EXPORT_COMMAND
82
+ )
75
83
 
76
84
  assert "--app-name" not in calls["run"][0][0]
77
85
 
86
+ def test_a_rust_app_runs_nothing_for_a_second_schema_kind(self, tmp_path, calls):
87
+ """The UI and notification exporters, which pass no rust_default.
88
+
89
+ A doover-rs binary has one `export` that writes every schema it has, so
90
+ the config exporter already ran it. Inventing the same command again is
91
+ what hung doover-device-runtime for 75 minutes: its binary is a
92
+ supervisor that accepts any argv, so `export` started it supervising.
93
+ """
94
+ (tmp_path / "Cargo.toml").touch()
95
+
96
+ apps_utils.run_schema_export(tmp_path, None, "export-ui", app_name="foo")
97
+
98
+ assert calls["run"] == []
99
+ assert calls["uv"] == []
100
+
101
+ def test_a_rust_app_still_honours_an_explicit_command(self, tmp_path, calls):
102
+ """An app that really does have a second exporter says so."""
103
+ (tmp_path / "Cargo.toml").touch()
104
+
105
+ apps_utils.run_schema_export(
106
+ tmp_path, "cargo run --bin exporter -- ui", "export-ui", app_name="foo"
107
+ )
108
+
109
+ assert calls["run"][0][0].startswith("cargo run --bin exporter -- ui")
110
+
111
+ def test_a_python_app_is_unaffected_by_the_rust_default(self, tmp_path, calls):
112
+ (tmp_path / "pyproject.toml").touch()
113
+
114
+ apps_utils.run_schema_export(tmp_path, None, "export-ui", app_name="foo")
115
+
116
+ assert calls["uv"][0][0] == ("export-ui",)
117
+
78
118
  def test_a_configured_rust_command_wins(self, tmp_path, calls):
79
119
  """A workspace with several binaries names the one to run itself."""
80
120
  (tmp_path / "Cargo.toml").touch()
@@ -104,6 +144,81 @@ class TestRunSchemaExport:
104
144
  assert calls["run"][0][0].endswith("explicit")
105
145
 
106
146
 
147
+ class TestOptionalSchema:
148
+ """`optional=True` -- the notification schema, which most apps don't have.
149
+
150
+ An app declares its exporters in its own `[project.scripts]`, so the absence
151
+ of one there is the app saying it has no notifications. Running it anyway
152
+ meant `uv run export-notifications` failed on nearly every Python app: a red
153
+ error and a reported handled exception for the ordinary case.
154
+ """
155
+
156
+ def _pyproject(self, tmp_path, body):
157
+ (tmp_path / "pyproject.toml").write_text(body)
158
+ return tmp_path
159
+
160
+ def test_skipped_when_the_script_is_not_declared(self, tmp_path, calls):
161
+ self._pyproject(
162
+ tmp_path,
163
+ '[project.scripts]\nexport-config = "app.app_config:export"\n',
164
+ )
165
+
166
+ apps_utils.run_schema_export(
167
+ tmp_path, None, "export-notifications", app_name="foo", optional=True
168
+ )
169
+
170
+ assert calls["uv"] == []
171
+ assert calls["run"] == []
172
+
173
+ def test_run_when_the_script_is_declared(self, tmp_path, calls):
174
+ self._pyproject(
175
+ tmp_path,
176
+ "[project.scripts]\n"
177
+ 'export-notifications = "app.app_notifications:export"\n',
178
+ )
179
+
180
+ apps_utils.run_schema_export(
181
+ tmp_path, None, "export-notifications", app_name="foo", optional=True
182
+ )
183
+
184
+ assert calls["uv"][0][0] == ("export-notifications",)
185
+
186
+ def test_an_explicit_command_is_never_probed(self, tmp_path, calls):
187
+ """An app naming its own exporter has said it has one, whatever the
188
+ scripts table looks like -- a second app in the repo exports through a
189
+ differently-named script."""
190
+ self._pyproject(tmp_path, '[project]\nname = "app"\n')
191
+
192
+ apps_utils.run_schema_export(
193
+ tmp_path,
194
+ "export-notifications-processor",
195
+ "export-notifications",
196
+ app_name="foo",
197
+ optional=True,
198
+ )
199
+
200
+ assert calls["uv"][0][0] == ("export-notifications-processor",)
201
+
202
+ def test_an_unreadable_pyproject_still_runs_the_export(self, tmp_path, calls):
203
+ """No answer is not the same as `no`: run it and let it fail loudly."""
204
+ self._pyproject(tmp_path, "this is not valid toml [[[")
205
+
206
+ apps_utils.run_schema_export(
207
+ tmp_path, None, "export-notifications", app_name="foo", optional=True
208
+ )
209
+
210
+ assert calls["uv"][0][0] == ("export-notifications",)
211
+
212
+ def test_a_required_schema_is_run_regardless(self, tmp_path, calls):
213
+ """Config and UI are not optional: every app of their type has one, so a
214
+ missing script there is a real failure worth surfacing."""
215
+ self._pyproject(tmp_path, '[project]\nname = "app"\n')
216
+
217
+ apps_utils.run_schema_export(tmp_path, None, "export-config", app_name="foo")
218
+
219
+ assert calls["uv"][0][0] == ("export-config",)
220
+
221
+
107
222
  class TestNoExport:
108
223
  """`export_config_command: NO_EXPORT` -- an app that holds no config of its
109
224
  own. Publishing one used to require giving it an exporter that wrote
@@ -313,6 +313,136 @@ def test_retired_fields_are_never_published(tmp_path):
313
313
  assert field not in payload, field
314
314
 
315
315
 
316
+ class _Existing:
317
+ def __init__(self, **fields):
318
+ for key, value in fields.items():
319
+ setattr(self, key, value)
320
+
321
+
322
+ def test_portal_owned_long_description_fields_are_never_published(tmp_path):
323
+ app_config = LocalApplication.from_config(
324
+ {
325
+ "name": "tracker-app",
326
+ "long_description_ui": "written in the portal",
327
+ "long_description_source": "ui",
328
+ },
329
+ tmp_path,
330
+ )
331
+
332
+ payload = app_config.to_request_payload()
333
+
334
+ assert "long_description_ui" not in payload
335
+ assert "long_description_source" not in payload
336
+
337
+
338
+ def test_create_only_fields_are_sent_when_the_app_does_not_exist(tmp_path):
339
+ app_config = LocalApplication.from_config(
340
+ {
341
+ "name": "tracker-app",
342
+ "display_name": "Tracker App",
343
+ "visibility": "PUB",
344
+ },
345
+ tmp_path,
346
+ )
347
+
348
+ payload, skipped = apps_utils.filter_create_only(
349
+ app_config.to_request_payload(), None
350
+ )
351
+
352
+ assert payload["display_name"] == "Tracker App"
353
+ assert payload["visibility"] == "PUB"
354
+ assert skipped == {}
355
+
356
+
357
+ def test_create_only_fields_are_sent_when_the_cloud_has_no_value(tmp_path):
358
+ app_config = LocalApplication.from_config(
359
+ {
360
+ "name": "tracker-app",
361
+ "display_name": "Tracker App",
362
+ "icon_url": "https://example.com/icon.png",
363
+ },
364
+ tmp_path,
365
+ )
366
+
367
+ payload, skipped = apps_utils.filter_create_only(
368
+ app_config.to_request_payload(),
369
+ _Existing(display_name=" ", icon_url=None),
370
+ )
371
+
372
+ assert payload["display_name"] == "Tracker App"
373
+ assert payload["icon_url"] == "https://example.com/icon.png"
374
+ assert skipped == {}
375
+
376
+
377
+ def test_create_only_fields_do_not_overwrite_the_cloud(tmp_path):
378
+ """A portal edit has to survive the next deploy — that's the whole point."""
379
+ app_config = LocalApplication.from_config(
380
+ {
381
+ "name": "tracker-app",
382
+ "display_name": "Tracker App",
383
+ "description": "A tracker app",
384
+ "visibility": "PUB",
385
+ "allow_many": True,
386
+ "image_name": "registry.doover.com/apps/tracker:main",
387
+ },
388
+ tmp_path,
389
+ )
390
+
391
+ payload, skipped = apps_utils.filter_create_only(
392
+ app_config.to_request_payload(),
393
+ _Existing(
394
+ display_name="Renamed In Portal",
395
+ description="A tracker app",
396
+ visibility="PRI",
397
+ allow_many=False,
398
+ ),
399
+ )
400
+
401
+ for field in ("display_name", "description", "visibility", "allow_many"):
402
+ assert field not in payload, field
403
+ # Only a value that actually differs is worth telling the user about.
404
+ assert set(skipped) == {"display_name", "visibility", "allow_many"}
405
+ assert skipped["display_name"] == ("Renamed In Portal", "Tracker App")
406
+ # Everything outside the create-only set still publishes.
407
+ assert payload["image_name"] == "registry.doover.com/apps/tracker:main"
408
+
409
+
410
+ def test_repository_url_is_declarable_and_create_only(tmp_path):
411
+ app_config = LocalApplication.from_config(
412
+ {
413
+ "name": "tracker-app",
414
+ "repository_url": "https://github.com/spaneng/tracker",
415
+ },
416
+ tmp_path,
417
+ )
418
+
419
+ payload = app_config.to_request_payload()
420
+ assert payload["repository_url"] == "https://github.com/spaneng/tracker"
421
+
422
+ kept, skipped = apps_utils.filter_create_only(
423
+ payload, _Existing(repository_url="https://github.com/spaneng/moved")
424
+ )
425
+ assert "repository_url" not in kept
426
+ assert set(skipped) == {"repository_url"}
427
+
428
+
429
+ def test_long_description_still_publishes_over_the_cloud(tmp_path):
430
+ """Only the presentation fields are create-only; the README is code-owned."""
431
+ readme = tmp_path / "README.md"
432
+ readme.write_text("# Tracker\n\nFrom the repo.")
433
+ app_config = LocalApplication.from_config(
434
+ {"name": "tracker-app", "long_description": "README.md"},
435
+ tmp_path,
436
+ )
437
+
438
+ payload, _ = apps_utils.filter_create_only(
439
+ app_config.to_request_payload(),
440
+ _Existing(long_description="something older"),
441
+ )
442
+
443
+ assert payload["long_description"] == "# Tracker\n\nFrom the repo."
444
+
445
+
316
446
  @pytest.mark.parametrize(
317
447
  "build_args,expected",
318
448
  [
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