Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

22 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { isFailed, orElse, part } from "./partial.ts";
5
6test("a part that throws is kept as failed, by what it is; one that answers is its answer", async () => {
7 const quiet = console.warn;
8 console.warn = () => {};
9 try {
10 const failed = await part(Promise.reject(new Error("work failed with status 503")), "Reviewers");
11 assert.deepEqual(failed, { failed: true, what: "Reviewers" });
12 assert.equal(isFailed(failed), true);
13 assert.equal(orElse(failed, []).length, 0);
14 } finally {
15 console.warn = quiet;
16 }
17 // A refusal is an answer, not a failure.
18 const refused = await part(Promise.resolve({ ok: false, code: "not_found" }), "Reviewers");
19 assert.equal(isFailed(refused), false);
20 assert.deepEqual(await part(null, "Nothing asked"), null);
21 assert.equal(isFailed({ failed: true }), false);
22});