|
1 | 1 | import { beforeEach, afterEach, assert, expect, it, vi } from "vitest"; |
2 | 2 | import { connectSignedTransport } from "./transport"; |
3 | | -import { PublishRejected } from "./outbox"; |
| 3 | +import { createOutbox, PublishRejected } from "./outbox"; |
4 | 4 | import { keypair, signed } from "./testing"; |
5 | 5 |
|
6 | 6 | const filters = [{ kinds: [0], limit: 1 }]; |
@@ -149,3 +149,37 @@ it("explicit quota rejection is retryable; missing response stays unknown with n |
149 | 149 | await vi.advanceTimersByTimeAsync(500); |
150 | 150 | expect(fetcher).toHaveBeenCalledTimes(2); |
151 | 151 | }); |
| 152 | +it.each([ |
| 153 | + [ |
| 154 | + 409, |
| 155 | + "failed", |
| 156 | + "conflict: the relay state changed; reload before writing again", |
| 157 | + ], |
| 158 | + [500, "unknown", "Relay delivery could not be confirmed (500)"], |
| 159 | +])( |
| 160 | + "artifact write answered %s reaches the outbox as %s", |
| 161 | + async (status, delivery, error) => { |
| 162 | + const identity = signer(); |
| 163 | + const transport = await connectSignedTransport( |
| 164 | + identity, |
| 165 | + "https://artifact.test", |
| 166 | + "relay", |
| 167 | + ); |
| 168 | + assert.exists(transport.writer); |
| 169 | + vi.stubGlobal( |
| 170 | + "fetch", |
| 171 | + vi.fn(async () => |
| 172 | + Response.json({ error: "conflict: artifact head changed" }, { status }), |
| 173 | + ), |
| 174 | + ); |
| 175 | + const owner = createOutbox(transport.viewer, transport.writer, { |
| 176 | + load: () => [], |
| 177 | + save() {}, |
| 178 | + }); |
| 179 | + owner.outbox.send({ kind: 45010, content: "", tags: [["h", "c"]] }); |
| 180 | + await vi.waitFor(() => |
| 181 | + expect(owner.outbox.snapshot()[0]).toMatchObject({ delivery, error }), |
| 182 | + ); |
| 183 | + owner.dispose(); |
| 184 | + }, |
| 185 | +); |
0 commit comments