Skip to content

Beautiful Open-Source Form Builder

fix(mcp): align preview links with draft expiry

Julien Nahuma938a61ee090
diff --git a/api/app/Service/Forms/AgentFormDraftService.php b/api/app/Service/Forms/AgentFormDraftService.php
index cda25d0d9..403649b6c 100644
--- a/api/app/Service/Forms/AgentFormDraftService.php
+++ b/api/app/Service/Forms/AgentFormDraftService.php
@@ -16,8 +16,6 @@ class AgentFormDraftService
{
public const EXPIRY_DAYS = 7;
- public const PREVIEW_URL_TTL_MINUTES = 60;
-
public function __construct(
private readonly AgentFormDefinition $formDefinition,
private readonly AgentFormDraftPatcher $patcher,
@@ -218,7 +216,7 @@ class AgentFormDraftService
{
$sourceUrl = URL::temporarySignedRoute(
'agent-drafts.preview',
- now()->addMinutes(self::PREVIEW_URL_TTL_MINUTES),
+ $draft->expires_at,
['draft' => $draft->id],
);
diff --git a/api/tests/Feature/Mcp/AgentDraftEditorTest.php b/api/tests/Feature/Mcp/AgentDraftEditorTest.php
index 8ed2e8db3..8ec5c8613 100644
--- a/api/tests/Feature/Mcp/AgentDraftEditorTest.php
+++ b/api/tests/Feature/Mcp/AgentDraftEditorTest.php
@@ -114,7 +114,7 @@ it('serves preview data only through a valid signed URL without exposing capabil
$this->getJson(route('agent-drafts.preview', $draft))->assertForbidden();
});
-it('keeps each generated browser preview link valid for one hour', function () {
+it('keeps each generated browser preview link valid until the draft expires', function () {
$this->freezeTime();
$draft = app(AgentFormDraftService::class)->create(editorDraftDefinition())['draft'];
$previewUrl = app(AgentFormDraftService::class)->previewUrl($draft);
@@ -122,7 +122,13 @@ it('keeps each generated browser preview link valid for one hour', function () {
parse_str((string) parse_url($previewQuery['source'], PHP_URL_QUERY), $sourceQuery);
expect((int) $sourceQuery['expires'])
- ->toBe(now()->addMinutes(AgentFormDraftService::PREVIEW_URL_TTL_MINUTES)->timestamp);
+ ->toBe($draft->expires_at->timestamp);
+
+ $this->travelTo($draft->expires_at->copy()->subSecond());
+ $this->getJson($previewQuery['source'])->assertOk();
+
+ $this->travelTo($draft->expires_at->copy()->addSecond());
+ $this->getJson($previewQuery['source'])->assertForbidden();
});
it('keeps every guest editor link reusable until the draft expires', function () {
diff --git a/client/pages/agent-drafts/preview.vue b/client/pages/agent-drafts/preview.vue
index a0abc4753..d9b8b6e4b 100644
--- a/client/pages/agent-drafts/preview.vue
+++ b/client/pages/agent-drafts/preview.vue
@@ -123,8 +123,8 @@ onMounted(() => {
workspace: { plan_tier: 'pro', features: [], limits: {} },
}
}).catch(() => {
- errorTitle.value = 'This preview link has expired'
- error.value = 'Your draft is usually still available for seven days. Ask your AI assistant: “Generate a new preview of this form.”'
+ errorTitle.value = 'This draft preview is no longer available'
+ error.value = 'Guest drafts and their previews are available for seven days. Ask your AI assistant to recreate the form if you still need it.'
}).finally(() => {
loading.value = false
})