submitPost: preserve native-image submission receipts before hydration and async completion

未关闭
#290 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
32/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

Start with the public RedditClient reference and the Post implementation in packages/reddit/src/models/Post.ts; trace submitPost through Submit and Info to understand when the receipt is exposed. Then review the media upload documentation for any existing completion contract. Done means the public API defines receipt and pending completion behavior, including created, rejected, unknown, and duplicate-completion outcomes without another Submit.

由索引模型根据 Issue 内容生成。

描述

Summary

Could the public SDK expose the original native-image submission receipt independently of Post hydration, and provide a supported completion handle when media creation is asynchronous?

reddit.submitPost() currently returns Promise<Post>. Two paths can reject without exposing a structured post ID or pending handle to the caller:

  1. Submit returns no ID for an asynchronous image submission; Post.submit throws its asynchronous-creation message.
  2. Submit returns an ID, but the SDK's subsequent Info/hydration request fails before the public promise resolves.

For a scheduled publisher, an unknown outcome must not be retried: the post may already exist. This report does not claim every image post fails, or that either mocked response proves Reddit accepted a particular native submission.

Versions and references

Minimal reproduction: local RPC mocks only

These are direct, supported image-only calls: no application adapter, image/body type suppression, real upload, or live post. Both cases were verified against the pinned SDK using @devvit/test.

import { createDevvitTest } from '@devvit/test/server/vitest';
import { reddit } from '@devvit/web/server';
import { expect, vi } from 'vitest';

const test = createDevvitTest({ subredditName: 'example_dev' });
const options = {
  subredditName: 'example_dev',
  title: 'SDK receipt reproduction',
  kind: 'image' as const,
  imageUrls: ['https://i.redd.it/example.png'] as [string],
  runAs: 'APP' as const,
};

test('asynchronous no-ID response', async ({ mocks }) => {
  const submit = vi.spyOn(mocks.reddit.linksAndComments.plugin, 'Submit')
    .mockResolvedValue({ json: { data: {}, errors: [] } });
  const info = vi.spyOn(mocks.reddit.linksAndComments.plugin, 'Info');

  await expect(reddit.submitPost(options)).rejects.toThrow(
    'is being created asynchronously'
  );
  expect(submit).toHaveBeenCalledTimes(1);
  expect(info).not.toHaveBeenCalled();
});

test('Submit ID is not exposed before failed hydration', async ({ mocks }) => {
  const submit = vi.spyOn(mocks.reddit.linksAndComments.plugin, 'Submit')
    .mockResolvedValue({ json: { data: { id: 'abc123' }, errors: [] } });
  const info = vi.spyOn(mocks.reddit.linksAndComments.plugin, 'Info')
    .mockRejectedValue(new Error('Mock Info unavailable'));

  await expect(reddit.submitPost(options)).rejects.toThrow(
    'Mock Info unavailable'
  );
  expect(submit).toHaveBeenCalledTimes(1);
  expect(info).toHaveBeenCalledTimes(1);
});

Separate native observation

A private scheduled image submission was recorded as uncertain without a returned post ID. Later read-only inspection found a candidate with the expected image and separate body. The original raw SDK exception/Submit response was not retained, so its precise failure branch and causal candidate binding are unknown. The occurrence remains protected; it was not retried or manually marked as an automatic pass.

This observation is separate from the deterministic mocked reproductions above.

Requested supported contract

  • Return the original structured created-post ID before optional Info hydration, so an app can retain it and verify the post separately.
  • If native media is pending without an ID, return a documented token with an authenticated completion operation/event tied to that original submission.
  • Define created/pending/rejected/unknown and duplicate-completion behavior without another Submit.

The current media API returns an asset ID/URL and documents upload, not post completion. We found no current public receipt hook or pending-media completion contract. If a supported approach already exists, guidance would be appreciated; parsing exception strings, matching the newest post, internal plugin imports, or a second Submit are not safe substitutes for this use case.

主要语言
TypeScript
星标
217
派生
89
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

reddit/devvit 的其他 Issue

查看 reddit/devvit 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。