doover-cli 0.6.8__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.8 → doover_cli-0.6.9}/PKG-INFO +1 -1
  2. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/__init__.py +1 -1
  3. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/apps.py +117 -0
  4. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/apps.py +62 -1
  5. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_apps.py +66 -0
  6. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_utils_apps.py +130 -0
  7. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/CONTRIBUTING.md +0 -0
  8. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/ISSUE_TEMPLATE/bug-report.yaml +0 -0
  9. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  10. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/ISSUE_TEMPLATE/feature-request.yml +0 -0
  11. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  12. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/workflows/lint-test.yml +0 -0
  13. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/workflows/release-brew.yml +0 -0
  14. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/workflows/release-pypi.yml +0 -0
  15. {doover_cli-0.6.8 → doover_cli-0.6.9}/.github/workflows/release.yml +0 -0
  16. {doover_cli-0.6.8 → doover_cli-0.6.9}/.gitignore +0 -0
  17. {doover_cli-0.6.8 → doover_cli-0.6.9}/.pre-commit-config.yaml +0 -0
  18. {doover_cli-0.6.8 → doover_cli-0.6.9}/AGENT.md +0 -0
  19. {doover_cli-0.6.8 → doover_cli-0.6.9}/LICENSE +0 -0
  20. {doover_cli-0.6.8 → doover_cli-0.6.9}/README.md +0 -0
  21. {doover_cli-0.6.8 → doover_cli-0.6.9}/debian/changelog +0 -0
  22. {doover_cli-0.6.8 → doover_cli-0.6.9}/debian/control +0 -0
  23. {doover_cli-0.6.8 → doover_cli-0.6.9}/debian/rules +0 -0
  24. {doover_cli-0.6.8 → doover_cli-0.6.9}/docs/user_stories.md +0 -0
  25. {doover_cli-0.6.8 → doover_cli-0.6.9}/pyproject.toml +0 -0
  26. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/agent.py +0 -0
  27. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/api/__init__.py +0 -0
  28. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/api/auth.py +0 -0
  29. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/api/errors.py +0 -0
  30. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/api/session.py +0 -0
  31. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/app_install.py +0 -0
  32. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/device.py +0 -0
  33. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/device_type.py +0 -0
  34. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/migrate.py +0 -0
  35. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/tunnel.py +0 -0
  36. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/apps/widget_plugin.py +0 -0
  37. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/channel.py +0 -0
  38. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/colours.py +0 -0
  39. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/config_schema.py +0 -0
  40. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/dda_logs.py +0 -0
  41. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/doover_config.py +0 -0
  42. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/grpc.py +0 -0
  43. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/login.py +0 -0
  44. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/notification_schema.py +0 -0
  45. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/registry.py +0 -0
  46. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/renderer/__init__.py +0 -0
  47. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/renderer/_base.py +0 -0
  48. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/renderer/_basic.py +0 -0
  49. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/renderer/_default.py +0 -0
  50. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/renderer/_json.py +0 -0
  51. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/report.py +0 -0
  52. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/simulator.py +0 -0
  53. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/ui_schema.py +0 -0
  54. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/user.py +0 -0
  55. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/__init__.py +0 -0
  56. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/api.py +0 -0
  57. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/context.py +0 -0
  58. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/crud/__init__.py +0 -0
  59. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/crud/commands.py +0 -0
  60. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/crud/lookup.py +0 -0
  61. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/crud/prompting.py +0 -0
  62. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/crud/schema.py +0 -0
  63. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/crud/values.py +0 -0
  64. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/errors.py +0 -0
  65. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/formatters.py +0 -0
  66. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/misc.py +0 -0
  67. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/parsers.py +0 -0
  68. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/prompt.py +0 -0
  69. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/sentry.py +0 -0
  70. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/shell_commands.py +0 -0
  71. {doover_cli-0.6.8 → doover_cli-0.6.9}/src/doover_cli/utils/state.py +0 -0
  72. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/__init__.py +0 -0
  73. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/conftest.py +0 -0
  74. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_agent.py +0 -0
  75. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_app_install.py +0 -0
  76. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_auth_integration.py +0 -0
  77. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_auth_unit.py +0 -0
  78. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_basic.py +0 -0
  79. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_crud_commands.py +0 -0
  80. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_crud_lookup.py +0 -0
  81. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_crud_prompting.py +0 -0
  82. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_crud_schema.py +0 -0
  83. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_crud_values.py +0 -0
  84. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_default_renderer.py +0 -0
  85. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_device.py +0 -0
  86. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_device_cli_integration.py +0 -0
  87. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_device_type.py +0 -0
  88. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_device_type_cli_integration.py +0 -0
  89. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_discover.py +0 -0
  90. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_migrate.py +0 -0
  91. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_prompt.py +0 -0
  92. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_registry.py +0 -0
  93. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_schema_export.py +0 -0
  94. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_sentry.py +0 -0
  95. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_user.py +0 -0
  96. {doover_cli-0.6.8 → doover_cli-0.6.9}/tests/test_widget_plugin.py +0 -0
  97. {doover_cli-0.6.8 → 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.8
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.8"
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(
@@ -43,10 +43,34 @@ RETIRED_FIELDS: dict[str, str | None] = {
43
43
  # app at the wrong function.
44
44
  "lambda_arn": None,
45
45
  "stars": None,
46
+ "long_description_ui": None,
47
+ "long_description_source": None,
46
48
  }
47
49
 
48
50
  # Never included in a publish payload, whatever the config says.
49
- 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
+ )
50
74
 
51
75
 
52
76
  def resolve_ref(data: dict[str, Any], canonical: str) -> Any:
@@ -65,6 +89,39 @@ def resolve_ref(data: dict[str, Any], canonical: str) -> Any:
65
89
  return None
66
90
 
67
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
+
68
125
  def warn_retired_fields(data: dict[str, Any]) -> None:
69
126
  for key in sorted(set(RETIRED_FIELDS) & set(data)):
70
127
  replacement = RETIRED_FIELDS[key]
@@ -123,6 +180,7 @@ class LocalApplication(ControlApplication):
123
180
  config_profiles: list[Any] | None = None,
124
181
  icon_url: str | None = None,
125
182
  banner_url: str | None = None,
183
+ repository_url: str | None = None,
126
184
  key: str | None = None,
127
185
  build_args: str | None = None,
128
186
  widget: str | Path | None = None,
@@ -159,6 +217,7 @@ class LocalApplication(ControlApplication):
159
217
  config_profiles=config_profiles,
160
218
  icon_url=icon_url,
161
219
  banner_url=banner_url,
220
+ repository_url=repository_url,
162
221
  )
163
222
 
164
223
  path = (
@@ -320,6 +379,7 @@ class LocalApplication(ControlApplication):
320
379
  staging_config=data.get("staging_config", {}),
321
380
  icon_url=data.get("icon_url"),
322
381
  banner_url=data.get("banner_url"),
382
+ repository_url=data.get("repository_url"),
323
383
  base_path=app_base,
324
384
  deployment_folder=data.get("deployment_folder"),
325
385
  )
@@ -411,6 +471,7 @@ class LocalApplication(ControlApplication):
411
471
  "notification_schema": self.notification_schema,
412
472
  "icon_url": self.icon_url,
413
473
  "banner_url": self.banner_url,
474
+ "repository_url": self.repository_url,
414
475
  }
415
476
  )
416
477
 
@@ -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
@@ -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