mikeboone Claude Fable 5.1 commited on
Commit
c0c09a2
·
1 Parent(s): bedf15f

fix(portal): sweep stale bundles — the delete pattern is relative to the upload path

Browse files

deploy_space passed `<subpath>/assets/*` as the delete pattern. huggingface_hub
matches delete patterns against paths RELATIVE to path_in_repo, so a pattern
that already carried the subpath matched nothing: after one update on
test-mcp (2026-10-20) the portal's path held three bundles, the first build's
main bundle still beside the new one. The unit test had asserted the wrong
pattern, so it passed.

`assets/*` now, in both the shared-Space and dedicated-Space cases. A bundle
whose hash is unchanged between builds is both deleted and re-added in the one
commit, and the library keeps the addition.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

demoprep_app/portal/builder.py CHANGED
@@ -1531,10 +1531,15 @@ def deploy_space(dist: Path, owner: str, space: str, subpath: str = "") -> str:
1531
  # (update_portal) would otherwise leave each previous bundle beside the new
1532
  # one, forever. Only the bundles are swept: the source zip and index.html
1533
  # at this path are rewritten by the upload that follows, not deleted first.
1534
- stale = f"{subpath}/assets/*" if subpath else "assets/*"
 
 
 
 
 
1535
  api.upload_folder(folder_path=str(dist), repo_id=repo_id, repo_type="space",
1536
  path_in_repo=subpath or "",
1537
- delete_patterns=[stale],
1538
  commit_message=f"portal build: {subpath or 'root'}")
1539
  host = space_host(owner, space)
1540
  if subpath:
 
1531
  # (update_portal) would otherwise leave each previous bundle beside the new
1532
  # one, forever. Only the bundles are swept: the source zip and index.html
1533
  # at this path are rewritten by the upload that follows, not deleted first.
1534
+ # The pattern is RELATIVE to path_in_repo (huggingface_hub matches delete
1535
+ # patterns against paths under the upload folder, not repo paths). A
1536
+ # subpath-prefixed pattern matched nothing — verified on test-mcp
1537
+ # 2026-10-20, where an updated portal held three bundles instead of two.
1538
+ # A bundle whose hash is unchanged is both deleted and re-added in the one
1539
+ # commit; the library keeps the addition.
1540
  api.upload_folder(folder_path=str(dist), repo_id=repo_id, repo_type="space",
1541
  path_in_repo=subpath or "",
1542
+ delete_patterns=["assets/*"],
1543
  commit_message=f"portal build: {subpath or 'root'}")
1544
  host = space_host(owner, space)
1545
  if subpath:
tests/test_portal_update.py CHANGED
@@ -549,7 +549,12 @@ def test_build_portal_still_maps_through_the_shared_mapping(server):
549
  def test_deploy_space_sweeps_the_previous_bundles_at_that_path(monkeypatch, tmp_path):
550
  """vite names bundles by hash; a rebuild at the same path must replace them,
551
  not pile them up. Only assets/* — the zip beside the site is overwritten by
552
- the upload that follows, never deleted first."""
 
 
 
 
 
553
  import huggingface_hub
554
  from demoprep_app.portal.builder import deploy_space
555
 
@@ -575,7 +580,7 @@ def test_deploy_space_sweeps_the_previous_bundles_at_that_path(monkeypatch, tmp_
575
 
576
  url = deploy_space(dist, "thoughtspot-demoprep", "portals", "spendflo-a0f6cdbe")
577
  assert url == f"https://{HOST}/spendflo-a0f6cdbe/index.html"
578
- assert calls["upload"]["delete_patterns"] == ["spendflo-a0f6cdbe/assets/*"]
579
  assert calls["upload"]["path_in_repo"] == "spendflo-a0f6cdbe"
580
 
581
  deploy_space(dist, "thoughtspot-demoprep", "vantage-portal", "")
 
549
  def test_deploy_space_sweeps_the_previous_bundles_at_that_path(monkeypatch, tmp_path):
550
  """vite names bundles by hash; a rebuild at the same path must replace them,
551
  not pile them up. Only assets/* — the zip beside the site is overwritten by
552
+ the upload that follows, never deleted first.
553
+
554
+ The pattern is relative to path_in_repo: huggingface_hub matches delete
555
+ patterns against paths UNDER the upload folder. The first version of this
556
+ test asserted a subpath-prefixed pattern, which matched nothing on the
557
+ real Space (three bundles after one update, 2026-10-20)."""
558
  import huggingface_hub
559
  from demoprep_app.portal.builder import deploy_space
560
 
 
580
 
581
  url = deploy_space(dist, "thoughtspot-demoprep", "portals", "spendflo-a0f6cdbe")
582
  assert url == f"https://{HOST}/spendflo-a0f6cdbe/index.html"
583
+ assert calls["upload"]["delete_patterns"] == ["assets/*"], "relative to path_in_repo"
584
  assert calls["upload"]["path_in_repo"] == "spendflo-a0f6cdbe"
585
 
586
  deploy_space(dist, "thoughtspot-demoprep", "vantage-portal", "")