Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions apps/web/src/lib/__tests__/pack-build-live.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('pack-build-live', () => {
);
});

it('succeeds after sandbox confirm when health stays degraded but pack is stored', async () => {
it('preserves failed health after sandbox confirms a stored pack', async () => {
const fetchMock = vi
.fn()
.mockResolvedValueOnce({
Expand Down Expand Up @@ -115,6 +115,7 @@ describe('pack-build-live', () => {
ok: false,
reason_code: 'HOSTED_PACK_EXTRACT_FAILED',
},
factory_deliver: { ready: false, reason_code: 'FACTORY_DELIVER_HEALTH_FAILED' },
}),
});
vi.stubGlobal('fetch', fetchMock);
Expand All @@ -126,9 +127,42 @@ describe('pack-build-live', () => {
});

expect(result).toMatchObject({
ok: true,
liveUrl: `https://uvai.io/d/${XYMC_VIDEO_ID}`,
ok: false,
reasonCode: 'HOSTED_PACK_EXTRACT_FAILED',
});
});

it.each([
{
name: 'missing health',
status: 200,
payload: { factory_deliver: { ready: false, reason_code: 'FACTORY_DELIVER_MISSING_HEALTH' } },
},
{
name: 'failed HTTP response with a healthy payload',
status: 503,
payload: { health: { ok: true, status: 200 } },
},
])('does not report ready after a stored-pack retry with $name', async ({ status, payload }) => {
const fetchMock = vi.fn()
.mockResolvedValueOnce(Response.json({
health: { ok: false, reason_code: 'HOSTED_PACK_NOT_FOUND' },
}))
.mockResolvedValueOnce(Response.json({
status: 'success',
data: { videoId: XYMC_VIDEO_ID, sourceHash: XYMC_SOURCE_HASH },
}))
.mockResolvedValueOnce(Response.json(payload, { status }));
vi.stubGlobal('fetch', fetchMock);

const result = await verifyPackBuildLive({
videoId: XYMC_VIDEO_ID,
sourceHash: XYMC_SOURCE_HASH,
origin: 'https://uvai.io',
});

expect(result.ok).toBe(false);
expect(result).not.toHaveProperty('liveUrl');
});

it('scopes pack live receipts to the selected video', () => {
Expand Down
10 changes: 0 additions & 10 deletions apps/web/src/lib/pack-build-live-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,6 @@ export async function verifyPackBuildLive(input: {
if (confirmed.ok) {
hostVideoId = confirmed.videoId;
({ response, payload } = await fetchHealth(hostVideoId));
if (payload.health?.ok !== true) {
const liveUrl = packBuildLiveUrl(origin, hostVideoId);
if (liveUrl) {
return {
ok: true,
liveUrl,
reasonCode: payload.factory_deliver?.reason_code ?? 'FACTORY_DELIVER_READY',
};
}
}
}
}
}
Expand Down
Loading