Skip to content

feat: add publish() to PromptClient - #34

Merged
iamDyeus merged 5 commits into
priompt:mainfrom
techkayacodes:feat/publish-prompt
Nov 30, 2026
Merged

iamDyeus merged 5 commits into
priompt:mainfrom
techkayacodes:feat/publish-prompt

Conversation

@techkayacodes

Copy link
Copy Markdown
Contributor

Issue

Fixes #23

What changed

  • Added PromptClient.publish(uri, template, slots=None, message="", branch="") in priompt_sdk/client.py, wired to PromptServiceStub.PublishPrompt with metadata=self._md and returning PublishPromptResponse.
  • Added _derive_slots(template) to extract ASCII {slot} names in first-seen, deduplicated order when slots is None while skipping escaped {{ / }} literal braces (matching validate.Slots in priompt/proto). Explicit slots (including slots=[]) are forwarded as-is.
  • Invalidated cached get(uri) and matching list(prefix) entries (uri.startswith(prefix)) only when branch in ("", "main"), keeping the cache warm for non-main branch publishes.
  • Extended FakeStub and added 11 unit tests in tests/test_client.py covering slot derivation, explicit slots, request/metadata forwarding, and cache invalidation across "", "main", and non-main branches.
  • Documented publish() in README.md.

How I tested it

  • Installed editable with pytest in a Python 3.13.18 .venv (uv pip install -e . pytest) and ran pytest -v tests/test_client.py: 40 passed in 0.46s.

Checklist

  • Assigned to #23 and PR links Fixes #23
  • Unit tests added and passing
  • README.md updated
  • AI assistance disclosure: Used an AI coding assistant to research the codebase, draft the implementation and tests, and verify edge cases; all changes were reviewed before submission.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An in-flight get() or list() can repopulate the cache with stale data after publish() evicts it, requiring coordinated cache invalidation and regression tests for overlapping reads and publishes.

1 open issue
What changed in this PR

Adds PromptClient.publish() so Python callers can publish prompt versions through the public SDK rather than using the private stub, addressing issue #23.

Changes:

  • Forwards publish requests and metadata, deriving slots automatically when omitted.
  • Evicts cached prompt reads and matching list entries after default or main-branch publishes.
  • Adds publish tests and README documentation.
File Description
tests/​test_client.py Extends the fake stub and tests slot derivation, request forwarding, and cache invalidation.
README.md Documents the publish API and adds a usage example.
priompt_sdk/​client.py Implements slot derivation, publish(), and branch-aware cache eviction.

Review effort: Balanced

Comment thread priompt_sdk/client.py
Comment on lines +185 to +189
if self._cache_ttl and branch in ("", "main"):
self._cache.pop(uri, None)
for key in list(self._cache):
if isinstance(key, tuple) and key[0] == "list" and uri.startswith(key[1]):
self._cache.pop(key, None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed! Coordinated cache reads, fills, and invalidations with self._cache_lock and a self._cache_gen generation counter so in-flight get() / list() calls that overlap a publish() (or subscribe() reload) won't repopulate self._cache with stale pre-publish responses, and added deterministic threading.Event-based regression tests for both get() and list() (42/42 passing locally).

@iamDyeus iamDyeus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @techkayacodes, this is great work! publish() meets everything in #23. The slot derivation matches the server's validate.Slots (including escaped {{ }}), and the generation counter that stops an in-flight read from re-caching a stale version is a thoughtful extra. I ran it against a local server and the publish, cache invalidation and list() all behaved as expected.

One small follow-up idea, not blocking: since priompt/priompt#99, publishing to a branch that doesn't exist yet returns NOT_FOUND, so a note in the branch docstring or README saying to create the branch first would help users. Merging now.

@iamDyeus
iamDyeus merged commit b1c97cc into priompt:main Nov 30, 2026
2 checks passed
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.

Add publish() to PromptClient

3 participants