Skip to content

feat(core): add cache-busting version param to apps-sdk widget output…#531

Open
slackerzz wants to merge 2 commits intoalpic-ai:mainfrom
slackerzz:template_uri_versioning
Open

feat(core): add cache-busting version param to apps-sdk widget output…#531
slackerzz wants to merge 2 commits intoalpic-ai:mainfrom
slackerzz:template_uri_versioning

Conversation

@slackerzz
Copy link
Copy Markdown
Contributor

@slackerzz slackerzz commented Mar 5, 2026

this will close #530

as suggest by @qchuchu I added a cache-busting parameter to the outputTemplate uri

Greptile Summary

This PR adds a ?v=${Date.now()} cache-busting query parameter to the apps-sdk widget URI in registerWidget, so that each server startup produces a new openai/outputTemplate value, preventing stale widget content from being served to clients that cache the URI.

Changes:

  • server.ts: The widgetConfig.uri for the apps-sdk host now appends ?v=${Date.now()} at widget-registration time. Because the same URI value is assigned to both the MCP resource registration and the openai/outputTemplate tool metadata, the two stay in sync.
  • widget.test.ts: The existing outputTemplate assertion is updated to expect the versioned URI. A vi.spyOn(Date, "now").mockReturnValue(now) is introduced to make the timestamp deterministic in the test.

Issue found:

  • The vi.spyOn(Date, "now") mock in the new test is not restored by the existing afterEach(() => vi.clearAllMocks()). clearAllMocks resets call history only — it does not restore the original Date.now implementation. Any tests added after this one in the same describe block will receive the frozen timestamp instead of the real current time. The afterEach should be updated to call vi.restoreAllMocks() as well.

Confidence Score: 4/5

  • Safe to merge after fixing the test spy cleanup; the production code change itself is correct.
  • The core change in server.ts is minimal and correct — a single-line addition of a timestamp query parameter that is consistently applied to both the resource URI and the tool metadata. The only real concern is in the test: the vi.spyOn(Date, "now") mock is not restored by vi.clearAllMocks(), which could silently break future tests. This is a logic-level test infrastructure issue, not a production bug, hence a score of 4 rather than 5.
  • packages/core/src/test/widget.test.ts — the Date.now spy introduced in the new test needs proper teardown via vi.restoreAllMocks().

Last reviewed commit: d81ccb7

Greptile also left 1 inline comment on this PR.

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@slackerzz slackerzz force-pushed the template_uri_versioning branch from d81ccb7 to bb55dd9 Compare March 6, 2026 08:13
@qchuchu
Copy link
Copy Markdown
Contributor

qchuchu commented Mar 6, 2026

Thanks for the PR @slackerzz ! I'm going to do small tests to verify that it doesn't break any behavior. We have a small chat this morning with @fredericbarthelet - I'll update you ASAP !

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.

Allow versioning of widget Resource URIs

2 participants