Skip to content

perf(cli): resolve a teamspace for drive reads from the org and memberships only - #209

Merged
owbone merged 3 commits into
mainfrom
danidapena/cp-lean-teamspace-lookup
Oct 22, 2026
Merged

owbone merged 3 commits into
mainfrom
danidapena/cp-lean-teamspace-lookup

Conversation

@Danidapena

@Danidapena Danidapena commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Resolve the teamspace for lightning cp downloads, ls and walk from its org and the user's memberships alone, so drive reads no longer call GET /v1/projects/{id}.

Summary

  • resolve_lit_url builds a full Teamspace just to learn its ID. That fetches memberships and the project twice per command, and needs GET /v1/projects/{id}.
  • New resolve_teamspace_ref / resolve_lit_url_ref resolve lit://<org>/<teamspace>/... from GET /v1/orgs/?name=<org> and GET /v1/memberships?filterByUserId=True, one call each, and return only the teamspace's ID and name.
  • Teamspaces are always owned by an organization, so there is no user-owner fallback: an unknown org, or a teamspace the user isn't a member of, is a ValueError.
  • lit:/// paths take the current teamspace's name and org from the same sources Teamspace uses (LIGHTNING_TEAMSPACE / LIGHTNING_ORG, then ~/.lightning/config.yaml), then make the same two requests. With no current teamspace configured they raise a ValueError pointing at the long form.
  • Filesystem.copy downloads, listdir and walk use it. Uploads keep the full Teamspace, since they may need its cloud account.
  • New API-layer helpers: OrgApi.find_org_id (None on 404) and TeamspaceApi.find_teamspace_id, which matches on name or display name and raises on ambiguity like get_teamspace.

Why

During the platform relaunch only a small allow-list of /v1/ paths is reachable. With this change a download needs GET /v1/orgs/, GET /v1/memberships and the drive's trees/blobs routes, and no longer GET /v1/projects/{id}.

Testing

  • New tests/core/filesystem/test_filesystem_teamspace_lookup.py, 10 tests: the org/memberships path makes no project or full-resolution call; display-name match; lit:/// from env, from config, and with nothing configured; unknown org and non-member teamspace errors; a non-404 org error is raised; ambiguous names; a file download end to end.
  • Existing copy/listdir/walk read tests now mock resolve_teamspace_ref instead of resolve_teamspace.
  • Full suite: 2716 passed, 8 skipped. Ruff and the other pre-commit hooks pass; the mypy hook needs uv, which wasn't installed, and running mypy directly on the changed files reported only missing third-party stubs.
  • Traced against a local control plane: a download, from both lit://<org>/<teamspace>/ and lit:///, now makes orgs → memberships → trees, with no /v1/projects/{id}. Not verified live: a real file download through the blob route.

🤖 Generated with Claude Code

— Claude Opus 5.5, on direct instruction; reviewed before posting

…rships only

lightning cp, ls and walk built a full Teamspace to learn its ID, fetching
memberships and the project twice. Reads now resolve an org-owned teamspace
from GET /v1/orgs and GET /v1/memberships alone, so they no longer need
GET /v1/projects/{id}. User-owned teamspaces and lit:/// paths still go
through the full lookup; uploads keep it for cloud-account resolution.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Danidapena and others added 2 commits October 21, 2026 17:06
Teamspaces are always owned by an organization, so drop the fallback to the
full lookup for a named teamspace: an unknown org or a teamspace the user is
not a member of is now an error. lit:/// paths still resolve the current
teamspace. Tests for the read paths mock resolve_teamspace_ref.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…amspace

lit:/// read the current teamspace's name and org from the environment or
config, then built a full Teamspace. Resolve those names the same way and use
the org-and-memberships lookup, so a relative path makes the same two
requests as lit://<org>/<teamspace>/. With no current teamspace configured it
is now a ValueError pointing at the long form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owbone
owbone merged commit 9dcd6e1 into main Oct 22, 2026
24 checks passed
@owbone
owbone deleted the danidapena/cp-lean-teamspace-lookup branch October 22, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants