@vercel/board 0.45.1 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{access-3udXjJAg.mjs → access-C06pIr0M.mjs} +2 -2
- package/dist/access.d.mts +2 -2
- package/dist/access.mjs +5 -5
- package/dist/{actors-DasGZnfb.mjs → actors-Dkyg-oo0.mjs} +3 -3
- package/dist/{auth-aiOVE82-.mjs → auth-B9-wXQ-x.mjs} +29 -9
- package/dist/{auth-BG_whr9_.d.mts → auth-li3lKwJG.d.mts} +1 -1
- package/dist/{backend-D6yTo8Un.d.mts → backend-i_esjwUS.d.mts} +144 -5
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/{chat-provider-V2jnjVLq.d.mts → chat-provider-BWBGZOZY.d.mts} +4 -2
- package/dist/{chat-provider-BvNqOQFL.mjs → chat-provider-CD7jskh7.mjs} +7 -4
- package/dist/cli-commands.d.mts +1 -1
- package/dist/cli-commands.mjs +1 -1
- package/dist/cli-embedded.d.mts +2 -2
- package/dist/cli-embedded.mjs +3 -2
- package/dist/cli.mjs +46 -15
- package/dist/{commands-DewS14_P.d.mts → commands-CJsOA-hf.d.mts} +60 -0
- package/dist/{commands-CqdnjUkm.mjs → commands-Dk6_cHLS.mjs} +325 -0
- package/dist/{conformance-BInS4_6b.mjs → conformance-CDP8y2Zm.mjs} +1063 -6
- package/dist/conformance.d.mts +6 -5
- package/dist/conformance.mjs +1 -1
- package/dist/{engine-XVBt02Bl.mjs → engine-j2VeNuKG.mjs} +51 -50
- package/dist/{errors-ZazTZh-s.mjs → errors-QhkdzI-o.mjs} +176 -9
- package/dist/{events-D17RndlV.mjs → events-MOcxGpOQ.mjs} +2 -2
- package/dist/{exports-DCxecX15.mjs → exports-CEqS-IPP.mjs} +1417 -84
- package/dist/exports-CF9rKCXd.d.mts +44 -0
- package/dist/{external-DfhN7lKK.mjs → external-BuVTXT1R.mjs} +7 -3
- package/dist/{index-Djmr4GzQ.d.mts → index-ttfx1TZ6.d.mts} +2 -2
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +5 -5
- package/dist/index.node.d.mts +7 -6
- package/dist/index.node.mjs +5 -4
- package/dist/inspect/app.js +215 -115
- package/dist/inspect/engine.js +5 -5
- package/dist/inspect-8YAhl_h3.mjs +2 -0
- package/dist/{inspect-CHsgnf_5.mjs → inspect-vOSrW_g6.mjs} +322 -50
- package/dist/{local-DE9vmanM.mjs → local-0ajWOVhN.mjs} +1673 -98
- package/dist/{main-CF1Me3jg.mjs → main-B8Zkd4Pm.mjs} +1282 -58
- package/dist/{memory-DyEL0fvN.mjs → memory-CMm-Fk_A.mjs} +2 -2
- package/dist/{mentions-DfZGp3B-.mjs → mentions-CnWt9Z5b.mjs} +34 -1
- package/dist/{middleware-BHHKHA9q.mjs → middleware-CT6vMNUc.mjs} +2 -2
- package/dist/{provider-BC9mPYVh.d.mts → provider-Bc3xI90K.d.mts} +199 -6
- package/dist/{routes-CkUetTO2.mjs → routes-ABXf3CKq.mjs} +261 -8
- package/dist/{routes-zm4TXKCC.d.mts → routes-CjA6Mp4D.d.mts} +610 -6
- package/dist/{schemas-BhZaystC.mjs → schemas-7VFdomFB.mjs} +34 -1
- package/dist/serve-BepKXDH3.mjs +285 -0
- package/dist/{server-Bmz0zqYM.mjs → server-4rQL3xuH.mjs} +41 -22
- package/dist/{serving-BLVRrJ7P.mjs → serving-BNdiReQT.mjs} +1 -1
- package/dist/{sql-CyVcjw8x.mjs → sql-IEbO5vXs.mjs} +174 -9
- package/dist/{sqlite-Con-8duk.mjs → sqlite-CVG8XKHm.mjs} +2 -2
- package/dist/{sqlite-db-BdzxtUOV.mjs → sqlite-db-BJjPQYx4.mjs} +1 -1
- package/dist/sync-chat-sdk.d.mts +16 -2
- package/dist/sync-chat-sdk.mjs +2 -2
- package/dist/sync-github.d.mts +16 -2
- package/dist/sync-github.mjs +3 -3
- package/dist/sync-linear.d.mts +17 -3
- package/dist/sync-linear.mjs +2 -2
- package/dist/sync-slack.d.mts +17 -3
- package/dist/sync-slack.mjs +107 -15
- package/dist/sync.d.mts +2 -2
- package/dist/sync.mjs +2 -2
- package/dist/{origin-BbwhnKrg.mjs → task-batch-BZXm6kOE.mjs} +83 -8
- package/dist/{tokens-BErYXuHZ.mjs → tokens-BCp4EWTQ.mjs} +2 -2
- package/docs/01-board/01-mounting.md +8 -5
- package/docs/01-board/03-identity.md +43 -23
- package/docs/01-board/04-messages.md +3 -2
- package/docs/01-board/06-watchers.md +3 -3
- package/docs/01-board/07-schedules.md +2 -2
- package/docs/01-board/08-middleware.md +7 -0
- package/docs/01-board/09-access.md +6 -4
- package/docs/01-board/10-local.md +4 -1
- package/docs/01-board/11-tasks.md +348 -0
- package/docs/02-sync/01-overview.md +4 -5
- package/docs/02-sync/02-functions.md +2 -2
- package/docs/02-sync/03-slack.md +8 -5
- package/docs/02-sync/06-providers.md +8 -0
- package/docs/03-guides/02-inspector.md +83 -10
- package/docs/03-guides/06-sandboxed-agents.md +7 -5
- package/docs/03-guides/07-build-a-ui.md +210 -0
- package/docs/03-guides/08-tailnet.md +123 -0
- package/docs/04-reference/01-cli.md +272 -23
- package/docs/04-reference/02-board.md +287 -7
- package/docs/04-reference/03-http.md +208 -13
- package/docs/04-reference/05-conformance.md +10 -7
- package/package.json +1 -1
- package/dist/exports-Gspe1eEq.d.mts +0 -4
- package/dist/inspect-C8U3A4jQ.mjs +0 -2
- package/dist/serve-CEMvl0EH.mjs +0 -181
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./routes-
|
|
1
|
+
import { f as BoardError } from "./errors-QhkdzI-o.mjs";
|
|
2
|
+
import "./routes-ABXf3CKq.mjs";
|
|
3
3
|
import { c as canonical, t as block } from "./blocks-CVoBC7ur.mjs";
|
|
4
|
-
import { a as canText, c as compileAccess } from "./access-
|
|
4
|
+
import { a as canText, c as compileAccess } from "./access-C06pIr0M.mjs";
|
|
5
5
|
//#region src/conformance/index.ts
|
|
6
6
|
var Mismatch = class extends Error {};
|
|
7
7
|
const show = (value) => JSON.stringify(value) ?? String(value);
|
|
@@ -32,6 +32,7 @@ async function refused(attempt, status, what) {
|
|
|
32
32
|
}
|
|
33
33
|
const NO_CAN = "this run can't call the board with an x-board-can header";
|
|
34
34
|
const NO_HEADERS = "this run can't call the board with headers of its own";
|
|
35
|
+
const UNPAGED = "this board doesn't page threads back: its pages have no older";
|
|
35
36
|
/** The avatar the checks of who writes give their profile. */
|
|
36
37
|
const AVATAR = "https://example.com/conformance.png";
|
|
37
38
|
/** A post by `poster`, which sends `header`, read back as the run sees it: it lands, and is deleted when the run ends. */
|
|
@@ -79,12 +80,13 @@ function isRef(value, what) {
|
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* The groups a board may keep none of, saying so with a 501: a board without a scheduler answers
|
|
82
|
-
* `no_scheduler`, and without a blob store `no_files`;
|
|
83
|
-
*
|
|
84
|
-
* and fails.
|
|
83
|
+
* `no_scheduler`, and without a blob store `no_files`; one that keeps no tasks answers `no_tasks`,
|
|
84
|
+
* a backend of one's own that keeps no grants `no_grants`, and one that keeps no schemas
|
|
85
|
+
* `no_schemas`. A board that's meant to keep something and doesn't yet answers otherwise, and fails.
|
|
85
86
|
*/
|
|
86
87
|
const OPTIONAL = /* @__PURE__ */ new Set([
|
|
87
88
|
"schedules",
|
|
89
|
+
"tasks",
|
|
88
90
|
"grants",
|
|
89
91
|
"schemas",
|
|
90
92
|
"attachments"
|
|
@@ -305,6 +307,70 @@ async function reply(ctx, re, text, extra = {}) {
|
|
|
305
307
|
ctx.posted.push(message.id);
|
|
306
308
|
return message;
|
|
307
309
|
}
|
|
310
|
+
/** A task of this run's, in a thread of its own that stays on the board: the run deletes its root at the end, which cancels it. */
|
|
311
|
+
async function task(ctx, text, options = {}) {
|
|
312
|
+
const { labels, ...rest } = options;
|
|
313
|
+
const made = await ctx.board.tasks.create(ctx.channel, {
|
|
314
|
+
text,
|
|
315
|
+
labels: {
|
|
316
|
+
...ctx.labels,
|
|
317
|
+
...labels
|
|
318
|
+
},
|
|
319
|
+
noSync: true,
|
|
320
|
+
...rest
|
|
321
|
+
});
|
|
322
|
+
ctx.posted.push(made.task.id);
|
|
323
|
+
return made;
|
|
324
|
+
}
|
|
325
|
+
/** Several tasks of this run's, made in one write: the run deletes their roots at the end, as it does a task's. */
|
|
326
|
+
async function taskBatch(ctx, tasks, opts = {}) {
|
|
327
|
+
const made = await ctx.board.tasks.createMany(ctx.channel, tasks.map((one) => ({
|
|
328
|
+
...one,
|
|
329
|
+
labels: ctx.labels,
|
|
330
|
+
noSync: true
|
|
331
|
+
})), opts);
|
|
332
|
+
ctx.posted.push(...made.map((root) => root.id));
|
|
333
|
+
return made;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The second channel the tasks checks make tasks in, `conformance/tasks`: the same for every run, so
|
|
337
|
+
* a run leaves no channel behind.
|
|
338
|
+
*/
|
|
339
|
+
const besideOf = (ctx) => `${ctx.channel}/tasks`;
|
|
340
|
+
/** A task of this run's in that channel, or null when the run may not post there. */
|
|
341
|
+
async function taskBeside(ctx, text, options = {}) {
|
|
342
|
+
try {
|
|
343
|
+
const made = await ctx.board.tasks.create(besideOf(ctx), {
|
|
344
|
+
text,
|
|
345
|
+
labels: ctx.labels,
|
|
346
|
+
noSync: true,
|
|
347
|
+
...options
|
|
348
|
+
});
|
|
349
|
+
ctx.posted.push(made.task.id);
|
|
350
|
+
return made;
|
|
351
|
+
} catch (error) {
|
|
352
|
+
if (error instanceof BoardError && error.status === 403) return null;
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/** A task's state, as its thread reads now. */
|
|
357
|
+
const taskState = async (ctx, id) => (await ctx.board.thread(id)).message.task?.state;
|
|
358
|
+
/** Waits up to a few seconds for what a board may derive a moment late, a task becoming ready, say. */
|
|
359
|
+
async function soon(found, what) {
|
|
360
|
+
for (const deadline = Date.now() + 1e4;;) {
|
|
361
|
+
if (await found()) return;
|
|
362
|
+
if (Date.now() >= deadline) throw new Mismatch(`${what}, within a few seconds`);
|
|
363
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/** That each claim that lost a race was told the task is claimed. */
|
|
367
|
+
function lostRace(racing) {
|
|
368
|
+
for (const result of racing) {
|
|
369
|
+
if (result.status === "fulfilled") continue;
|
|
370
|
+
const error = result.reason;
|
|
371
|
+
check(error instanceof BoardError && error.status === 409 && error.code === "task_claimed", `a claim that lost the race should be 409 task_claimed, got ${error instanceof BoardError ? `${error.status} ${error.code}` : String(error)}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
308
374
|
const CHECKS = [
|
|
309
375
|
{
|
|
310
376
|
group: "core",
|
|
@@ -516,6 +582,73 @@ const CHECKS = [
|
|
|
516
582
|
same(found.last?.id, reply.id, "its latest reply");
|
|
517
583
|
}
|
|
518
584
|
},
|
|
585
|
+
{
|
|
586
|
+
group: "paging",
|
|
587
|
+
name: "pages back through a channel's threads by their `older`, each thread once",
|
|
588
|
+
run: async (ctx) => {
|
|
589
|
+
const posted = [];
|
|
590
|
+
for (const n of [
|
|
591
|
+
1,
|
|
592
|
+
2,
|
|
593
|
+
3
|
|
594
|
+
]) posted.push((await post(ctx, `conformance: thread ${n} of 3 to page through`)).id);
|
|
595
|
+
const first = await ctx.board.threads({
|
|
596
|
+
channel: ctx.channel,
|
|
597
|
+
limit: 2
|
|
598
|
+
});
|
|
599
|
+
if (!("older" in first)) return UNPAGED;
|
|
600
|
+
check(typeof first.older === "string", `a first page of 2, with 3 threads or more, should have an older, got ${show(first.older)}`);
|
|
601
|
+
const seen = first.threads.map((t) => t.message.id);
|
|
602
|
+
for (let older = first.older; older !== null;) {
|
|
603
|
+
check(typeof older === "string", `every page should have an older, a string or null, got ${show(older)}`);
|
|
604
|
+
const page = await ctx.board.threads({
|
|
605
|
+
channel: ctx.channel,
|
|
606
|
+
before: older,
|
|
607
|
+
limit: 50
|
|
608
|
+
});
|
|
609
|
+
seen.unshift(...page.threads.map((t) => t.message.id));
|
|
610
|
+
older = page.older;
|
|
611
|
+
}
|
|
612
|
+
const twice = seen.filter((id, i) => seen.indexOf(id) !== i);
|
|
613
|
+
check(twice.length === 0, `paging back should list each thread once, got ${show([...new Set(twice)])} again`);
|
|
614
|
+
for (const id of posted) check(seen.includes(id), `paging back should reach ${id}, got ${show(seen)}`);
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
group: "paging",
|
|
619
|
+
name: "refuses to page threads back and forward at once",
|
|
620
|
+
run: async (ctx) => {
|
|
621
|
+
const first = await ctx.board.threads({
|
|
622
|
+
channel: ctx.channel,
|
|
623
|
+
limit: 1
|
|
624
|
+
});
|
|
625
|
+
if (!("older" in first)) return UNPAGED;
|
|
626
|
+
await rejects(ctx.board.threads({
|
|
627
|
+
channel: ctx.channel,
|
|
628
|
+
before: first.older ?? "x",
|
|
629
|
+
after: ctx.start
|
|
630
|
+
}), 400, "invalid_request", "threads with before and after");
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
group: "core",
|
|
635
|
+
name: "stores a handle one actor has as a mention of them, and keeps one no one has as typed",
|
|
636
|
+
run: async (ctx) => {
|
|
637
|
+
check(ctx.root, "posting failed, so there's no thread to reply in");
|
|
638
|
+
const { handle, actor } = ctx.me;
|
|
639
|
+
if (!/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?(?:\/[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?)?$/i.test(handle)) return `the caller's handle, ${handle}, isn't one a mention can type`;
|
|
640
|
+
const nobody = `conformance-nobody-${Date.now().toString(36)}`;
|
|
641
|
+
const sent = await reply(ctx, ctx.root.id, `conformance: over to @${handle} and @${nobody}`);
|
|
642
|
+
const settled = `conformance: over to @[${actor}] and @${nobody}`;
|
|
643
|
+
check(sent.text === settled, `a handle one actor has should be stored as @[actor-id], and one no one has as typed: expected ${show(settled)}, got ${show(sent.text)}`);
|
|
644
|
+
const [mine, none, ...more] = sent.mentions ?? [];
|
|
645
|
+
check(mine?.written === `@${handle}` && mine.actor?.id === actor, `the answer's mentions should say @${handle} mentions ${actor}, got ${show(mine)}`);
|
|
646
|
+
check(none?.written === `@${nobody}` && none.actor === null && none.candidates.length === 0, `the answer's mentions should say @${nobody} mentions no one, got ${show(none)}`);
|
|
647
|
+
check(more.length === 0, `the answer's mentions should have one entry a handle, got ${more.length + 2}`);
|
|
648
|
+
const kept = (await ctx.board.thread(ctx.root.id)).replies.find((message) => message.id === sent.id);
|
|
649
|
+
check(kept?.text === settled, `the message should read back as it was stored, got ${show(kept?.text)}`);
|
|
650
|
+
}
|
|
651
|
+
},
|
|
519
652
|
{
|
|
520
653
|
group: "core",
|
|
521
654
|
name: "matches text anywhere in a message's own, in any case, as it reads now",
|
|
@@ -828,6 +961,838 @@ const CHECKS = [
|
|
|
828
961
|
}
|
|
829
962
|
}
|
|
830
963
|
},
|
|
964
|
+
{
|
|
965
|
+
group: "tasks",
|
|
966
|
+
name: "starts a thread as a task, or makes one of a thread that was there: it reads as its thread, and board.task finds it",
|
|
967
|
+
run: async (ctx) => {
|
|
968
|
+
const { task: root } = await task(ctx, "conformance: a task");
|
|
969
|
+
isRef(root.id, "a task's id");
|
|
970
|
+
same(root.task?.state, "ready", "a new task's state");
|
|
971
|
+
same(root.task?.owner, ctx.me.principal, "a new task's owner");
|
|
972
|
+
same(root.task?.by, ctx.me.actor, "the actor a new task was made as");
|
|
973
|
+
same(root.labels["board.task"], "ready", "its root's board.task");
|
|
974
|
+
const answer = await reply(ctx, root.id, "conformance: working on it");
|
|
975
|
+
const thread = await ctx.board.thread(root.id);
|
|
976
|
+
same(thread.message.task?.state, "ready", "the task, read as its thread");
|
|
977
|
+
check(thread.replies.some((m) => m.id === answer.id), "a reply should land in the task's thread");
|
|
978
|
+
const { messages } = await ctx.board.messages({
|
|
979
|
+
channel: ctx.channel,
|
|
980
|
+
label: {
|
|
981
|
+
...ctx.labels,
|
|
982
|
+
"board.task": "ready"
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
check(messages.some((m) => m.id === root.id), "board.task=ready should find the task");
|
|
986
|
+
const listed = (await ctx.board.tasks.list({
|
|
987
|
+
channel: ctx.channel,
|
|
988
|
+
label: ctx.labels
|
|
989
|
+
})).tasks.find((t) => t.message.id === root.id);
|
|
990
|
+
check(listed, `the tasks should include ${root.id}`);
|
|
991
|
+
same(listed.replies, 1, "the listed task's reply count");
|
|
992
|
+
same(listed.last?.id, answer.id, "the listed task's latest reply");
|
|
993
|
+
const plain = await post(ctx, "conformance: a thread to make a task");
|
|
994
|
+
await rejects(ctx.board.tasks.claim(plain.id), 404, "not_a_task", "claiming a thread that isn't a task");
|
|
995
|
+
const adopted = await ctx.board.tasks.create({ re: plain.id });
|
|
996
|
+
same(adopted.task.id, plain.id, "the task's id, its root's");
|
|
997
|
+
same(adopted.task.text, "conformance: a thread to make a task", "the task's text, its root's");
|
|
998
|
+
same((await ctx.board.thread(plain.id)).message.labels["board.task"], "ready", "the thread's board.task, once it's a task");
|
|
999
|
+
await rejects(ctx.board.tasks.create({ re: plain.id }), 409, "already_a_task", "making a task of a thread that is one");
|
|
1000
|
+
}
|
|
1001
|
+
},
|
|
1002
|
+
{
|
|
1003
|
+
group: "tasks",
|
|
1004
|
+
name: "makes a task once for a client ID, and none under an ID a reply or a plain thread landed with",
|
|
1005
|
+
run: async (ctx) => {
|
|
1006
|
+
const id = `conformance-task-${ctx.labels.conformance}`;
|
|
1007
|
+
const under = (landed, text) => ctx.board.tasks.create(ctx.channel, {
|
|
1008
|
+
text,
|
|
1009
|
+
labels: ctx.labels,
|
|
1010
|
+
noSync: true,
|
|
1011
|
+
id: landed
|
|
1012
|
+
}).then((made) => {
|
|
1013
|
+
ctx.posted.push(made.task.id);
|
|
1014
|
+
return made;
|
|
1015
|
+
});
|
|
1016
|
+
const { task: first } = await under(id, "conformance: a task with an ID");
|
|
1017
|
+
same((await under(id, "conformance: a task with an ID")).task.id, first.id, "the second task with the same client ID");
|
|
1018
|
+
await reply(ctx, first.id, "conformance: a reply with an ID", { id: `${id}-reply` });
|
|
1019
|
+
const plain = await post(ctx, "conformance: a thread with an ID", { id: `${id}-thread` });
|
|
1020
|
+
await rejects(under(`${id}-reply`, "conformance: a task under a reply's ID"), 409, "duplicate_id", "a task under an ID a reply landed with");
|
|
1021
|
+
await rejects(under(`${id}-thread`, "conformance: a task under a thread's ID"), 409, "duplicate_id", "a task under an ID a thread that is no task landed with");
|
|
1022
|
+
same((await ctx.board.thread(plain.id)).message.task, void 0, "the thread, after a task was asked for under its ID");
|
|
1023
|
+
same((await ctx.board.tasks.list({
|
|
1024
|
+
channel: ctx.channel,
|
|
1025
|
+
label: ctx.labels,
|
|
1026
|
+
state: "all"
|
|
1027
|
+
})).tasks.filter((listed) => listed.message.text.includes("with an ID") || listed.message.text.includes("'s ID")).length, 1, "the tasks made under those IDs");
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
group: "tasks",
|
|
1032
|
+
name: "gives a task to one of the claims that race for it, and takes its result",
|
|
1033
|
+
run: async (ctx) => {
|
|
1034
|
+
const { task: root } = await task(ctx, "conformance: a task to race for");
|
|
1035
|
+
const racing = await Promise.allSettled([
|
|
1036
|
+
1,
|
|
1037
|
+
2,
|
|
1038
|
+
3
|
|
1039
|
+
].map(() => ctx.board.tasks.claim(root.id, { lease: 60 })));
|
|
1040
|
+
const landed = racing.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
|
|
1041
|
+
same(landed.length, 1, "the claims that landed of three racing for one task");
|
|
1042
|
+
lostRace(racing);
|
|
1043
|
+
const claim = landed[0];
|
|
1044
|
+
same(claim.task.task?.state, "claimed", "the task, once claimed");
|
|
1045
|
+
same(claim.task.labels["board.task"], "claimed", "its root's board.task, once claimed");
|
|
1046
|
+
same(claim.task.task?.claim?.actor, ctx.me.actor, "who holds it");
|
|
1047
|
+
check(typeof claim.token === "string" && claim.token.length > 0, `a claim's token should be a string, got ${show(claim.token)}`);
|
|
1048
|
+
check(!show(await ctx.board.thread(root.id)).includes(claim.token), "a task's thread shouldn't show its claim's token");
|
|
1049
|
+
const done = await claim.complete("conformance: done");
|
|
1050
|
+
same(done.task?.state, "completed", "the task, once completed");
|
|
1051
|
+
same(done.task?.result, "conformance: done", "the completed task's result");
|
|
1052
|
+
await rejects(ctx.board.tasks.claim(root.id), 409, "task_finished", "claiming a completed task");
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
{
|
|
1056
|
+
group: "tasks",
|
|
1057
|
+
name: "gives a claim the lease it asks for, up to 5 minutes, and says when it ends",
|
|
1058
|
+
run: async (ctx) => {
|
|
1059
|
+
const { task: root } = await task(ctx, "conformance: a task to hold");
|
|
1060
|
+
const asked = Date.now();
|
|
1061
|
+
const claim = await ctx.board.tasks.claim(root.id, { lease: 300 });
|
|
1062
|
+
const lease = Date.parse(claim.until) - asked;
|
|
1063
|
+
check(lease >= 295e3 && lease <= 305e3 + (Date.now() - asked), `a claim that asks for 300 seconds should end in 300, got ${claim.until}`);
|
|
1064
|
+
same(claim.task.task?.claim?.until, claim.until, "the task's own word for when its claim ends");
|
|
1065
|
+
const again = Date.now();
|
|
1066
|
+
const renewed = await claim.renew(60);
|
|
1067
|
+
const left = Date.parse(renewed.until) - again;
|
|
1068
|
+
check(left >= 55e3 && left <= 65e3 + (Date.now() - again), `a claim renewed for 60 seconds should end in 60, got ${renewed.until}`);
|
|
1069
|
+
await renewed.release();
|
|
1070
|
+
const fallback = Date.now();
|
|
1071
|
+
const unasked = await ctx.board.tasks.claim(root.id);
|
|
1072
|
+
check(Date.parse(unasked.until) - fallback >= 295e3, `a claim that asks for no lease should get at least 5 minutes, got ${unasked.until}`);
|
|
1073
|
+
await unasked.release();
|
|
1074
|
+
await rejects(ctx.board.tasks.claim(root.id, { lease: 5 }), 400, "invalid_request", "a lease under 30 seconds");
|
|
1075
|
+
}
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
group: "tasks",
|
|
1079
|
+
name: "fences what a claim does: once it's over, its writes are lost and change nothing",
|
|
1080
|
+
run: async (ctx) => {
|
|
1081
|
+
const { task: root } = await task(ctx, "conformance: a task to take over");
|
|
1082
|
+
const first = await ctx.board.tasks.claim(root.id, { lease: 60 });
|
|
1083
|
+
await rejects(ctx.board.tasks.held(root.id, {
|
|
1084
|
+
epoch: first.epoch,
|
|
1085
|
+
token: `${first.token}x`
|
|
1086
|
+
}).complete("conformance: not mine"), 409, "claim_lost", "a complete with a token that isn't the claim's");
|
|
1087
|
+
same(await taskState(ctx, root.id), "claimed", "the task, after a write with the wrong token");
|
|
1088
|
+
same((await first.release()).task?.state, "ready", "the task, once released");
|
|
1089
|
+
await rejects(first.renew(), 409, "claim_lost", "renewing a claim that was released");
|
|
1090
|
+
const second = await ctx.board.tasks.claim(root.id, { lease: 60 });
|
|
1091
|
+
same(second.epoch, first.epoch + 1, "the epoch of the claim after it");
|
|
1092
|
+
await rejects(first.complete("conformance: too late"), 409, "claim_lost", "the first claim's complete, once another holds the task");
|
|
1093
|
+
await rejects(first.fail("conformance: too late"), 409, "claim_lost", "the first claim's fail, once another holds the task");
|
|
1094
|
+
const held = (await ctx.board.thread(root.id)).message.task;
|
|
1095
|
+
check(held?.state === "claimed" && held.epoch === second.epoch && held.result === null, `lost writes should leave the task with the claim that holds it, got ${show(held)}`);
|
|
1096
|
+
const failed = await second.fail("conformance: could not");
|
|
1097
|
+
same(failed.task?.state, "failed", "the task, once failed");
|
|
1098
|
+
same(failed.task?.reason, "conformance: could not", "the failed task's reason");
|
|
1099
|
+
same((await ctx.board.tasks.reopen(root.id)).task?.state, "ready", "a failed task, reopened");
|
|
1100
|
+
}
|
|
1101
|
+
},
|
|
1102
|
+
{
|
|
1103
|
+
group: "tasks",
|
|
1104
|
+
name: "holds a task until the tasks it needs complete, which a failed or canceled one never does",
|
|
1105
|
+
run: async (ctx) => {
|
|
1106
|
+
const { task: first } = await task(ctx, "conformance: a prerequisite");
|
|
1107
|
+
const { task: second } = await task(ctx, "conformance: a task that waits for it", { needs: [first.id] });
|
|
1108
|
+
same(second.task?.state, "waiting", "a task that needs one that has not completed");
|
|
1109
|
+
same(second.labels["board.task"], "waiting", "its root's board.task");
|
|
1110
|
+
alike(second.task?.needs, [first.id], "what it needs");
|
|
1111
|
+
await rejects(ctx.board.tasks.claim(second.id), 409, "task_waiting", "claiming a task that waits");
|
|
1112
|
+
await (await ctx.board.tasks.claim(first.id, { lease: 60 })).fail("conformance: not this time");
|
|
1113
|
+
same(await taskState(ctx, second.id), "waiting", "the task, once what it needs failed");
|
|
1114
|
+
await ctx.board.tasks.reopen(first.id);
|
|
1115
|
+
await (await ctx.board.tasks.claim(first.id, { lease: 60 })).complete();
|
|
1116
|
+
await soon(async () => await taskState(ctx, second.id) === "ready", "the task should be ready once what it needs completed");
|
|
1117
|
+
const { task: dropped } = await task(ctx, "conformance: a prerequisite to cancel");
|
|
1118
|
+
const { task: stuck } = await task(ctx, "conformance: a task that waits for that", { needs: [dropped.id] });
|
|
1119
|
+
const canceled = await ctx.board.tasks.cancel(dropped.id, "conformance: not wanted");
|
|
1120
|
+
same(canceled.task?.state, "canceled", "a canceled task");
|
|
1121
|
+
same(canceled.task?.reason, "conformance: not wanted", "the canceled task's reason");
|
|
1122
|
+
same(await taskState(ctx, stuck.id), "waiting", "the task, once what it needs was canceled");
|
|
1123
|
+
const plain = await post(ctx, "conformance: not a task");
|
|
1124
|
+
await rejects(ctx.board.tasks.create(ctx.channel, {
|
|
1125
|
+
text: "conformance: needs a thread",
|
|
1126
|
+
labels: ctx.labels,
|
|
1127
|
+
noSync: true,
|
|
1128
|
+
needs: [plain.id]
|
|
1129
|
+
}).then((made) => {
|
|
1130
|
+
ctx.posted.push(made.task.id);
|
|
1131
|
+
return made;
|
|
1132
|
+
}), 400, "invalid_needs", "a task that needs a thread that isn't a task");
|
|
1133
|
+
await rejects(ctx.board.tasks.create({ re: plain.id }, { needs: [plain.id] }), 400, "invalid_needs", "a task that needs itself");
|
|
1134
|
+
}
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
group: "tasks",
|
|
1138
|
+
name: "refuses a prerequisite that was canceled, which can never complete, and takes one that failed",
|
|
1139
|
+
run: async (ctx) => {
|
|
1140
|
+
const { task: dropped } = await task(ctx, "conformance: a prerequisite that was canceled");
|
|
1141
|
+
await ctx.board.tasks.cancel(dropped.id, "conformance: not wanted");
|
|
1142
|
+
await rejects(ctx.board.tasks.create(ctx.channel, {
|
|
1143
|
+
text: "conformance: needs a canceled task",
|
|
1144
|
+
labels: ctx.labels,
|
|
1145
|
+
noSync: true,
|
|
1146
|
+
needs: [dropped.id]
|
|
1147
|
+
}).then((made) => {
|
|
1148
|
+
ctx.posted.push(made.task.id);
|
|
1149
|
+
return made;
|
|
1150
|
+
}), 400, "invalid_needs", "a task that needs a canceled one");
|
|
1151
|
+
const plain = await post(ctx, "conformance: a thread that would need a canceled task");
|
|
1152
|
+
await rejects(ctx.board.tasks.create({ re: plain.id }, { needs: [dropped.id] }), 400, "invalid_needs", "making a thread a task that needs a canceled one");
|
|
1153
|
+
same((await ctx.board.thread(plain.id)).message.task, void 0, "the thread, after it was refused as a task");
|
|
1154
|
+
const { task: failed } = await task(ctx, "conformance: a prerequisite that failed");
|
|
1155
|
+
await (await ctx.board.tasks.claim(failed.id, { lease: 60 })).fail("conformance: not this time");
|
|
1156
|
+
const { task: after } = await task(ctx, "conformance: a task that waits for a failed one", { needs: [failed.id] });
|
|
1157
|
+
same(after.task?.state, "waiting", "a task that needs one that failed");
|
|
1158
|
+
alike(after.task?.needs, [failed.id], "what it needs");
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
{
|
|
1162
|
+
group: "tasks",
|
|
1163
|
+
name: "lists the tasks that wait for one in the channel a list names, or its subtree, and no other",
|
|
1164
|
+
run: async (ctx) => {
|
|
1165
|
+
const beside = besideOf(ctx);
|
|
1166
|
+
const { task: first } = await task(ctx, "conformance: a prerequisite two channels wait for");
|
|
1167
|
+
const { task: here } = await task(ctx, "conformance: a task that waits for it, in the channel", { needs: [first.id] });
|
|
1168
|
+
alike(here.task?.needs, [first.id], "what the task in the channel needs");
|
|
1169
|
+
const made = await taskBeside(ctx, "conformance: a task that waits for it, in another channel", { needs: [first.id] });
|
|
1170
|
+
if (!made) return `this token can't post in ${beside}`;
|
|
1171
|
+
const there = made.task;
|
|
1172
|
+
const waiting = async (channel) => (await ctx.board.tasks.list({
|
|
1173
|
+
needs: first.id,
|
|
1174
|
+
...channel !== void 0 ? { channel } : {}
|
|
1175
|
+
})).tasks.map((listed) => listed.message.id);
|
|
1176
|
+
await soon(async () => show(await waiting()) === show([here.id, there.id]), "the tasks that wait for one, on the whole board, should be the two that do");
|
|
1177
|
+
alike(await waiting(ctx.channel), [here.id], `the tasks that wait for one, in ${ctx.channel}`);
|
|
1178
|
+
alike(await waiting(beside), [there.id], `the tasks that wait for one, in ${beside}`);
|
|
1179
|
+
alike(await waiting(`${beside}/`), [there.id], `the tasks that wait for one, under ${beside}/`);
|
|
1180
|
+
alike(await waiting(`${ctx.channel}/`), [here.id, there.id], `the tasks that wait for one, under ${ctx.channel}/`);
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
{
|
|
1184
|
+
group: "tasks",
|
|
1185
|
+
name: "says task.ready each time a task that needs others becomes ready: right after it is made or unblocked, once they have completed",
|
|
1186
|
+
run: async (ctx) => {
|
|
1187
|
+
const { task: first } = await task(ctx, "conformance: a prerequisite that completes first");
|
|
1188
|
+
await (await ctx.board.tasks.claim(first.id, { lease: 60 })).complete();
|
|
1189
|
+
const label = [`conformance=${ctx.labels.conformance}`];
|
|
1190
|
+
let { cursor } = await ctx.board.poll({
|
|
1191
|
+
channel: ctx.channel,
|
|
1192
|
+
label
|
|
1193
|
+
});
|
|
1194
|
+
const made = await task(ctx, "conformance: a task made once what it needs completed", {
|
|
1195
|
+
needs: [first.id],
|
|
1196
|
+
claim: true,
|
|
1197
|
+
lease: 60
|
|
1198
|
+
});
|
|
1199
|
+
const { id } = made.task;
|
|
1200
|
+
same(made.task.task?.state, "claimed", "a task made with a claim, once what it needs completed");
|
|
1201
|
+
check(made.claim, "a task made with a claim should answer the claim");
|
|
1202
|
+
await ctx.board.tasks.held(id, made.claim).block("conformance: approve?");
|
|
1203
|
+
const { task: alone } = await task(ctx, "conformance: a task that needs none");
|
|
1204
|
+
await ctx.board.tasks.block(alone.id, "conformance: approve?");
|
|
1205
|
+
same((await ctx.board.tasks.unblock(alone.id)).task?.state, "ready", "a task that needs none, unblocked");
|
|
1206
|
+
same((await ctx.board.tasks.unblock(id)).task?.state, "ready", "the task, unblocked once what it needs completed");
|
|
1207
|
+
const seen = [];
|
|
1208
|
+
const changes = (of) => seen.filter((event) => event.type.startsWith("task.") && event.message?.id === of).map((event) => [event.type, event.message?.task?.state]);
|
|
1209
|
+
for (const deadline = Date.now() + 1e4; changes(id).filter(([type]) => type === "task.ready").length < 2 && Date.now() < deadline;) {
|
|
1210
|
+
const page = await ctx.board.poll({
|
|
1211
|
+
channel: ctx.channel,
|
|
1212
|
+
label,
|
|
1213
|
+
after: cursor,
|
|
1214
|
+
wait: 2
|
|
1215
|
+
});
|
|
1216
|
+
seen.push(...page.events);
|
|
1217
|
+
cursor = page.cursor;
|
|
1218
|
+
}
|
|
1219
|
+
alike(changes(id), [
|
|
1220
|
+
["task.created", "waiting"],
|
|
1221
|
+
["task.ready", "ready"],
|
|
1222
|
+
["task.claimed", "claimed"],
|
|
1223
|
+
["task.blocked", "blocked"],
|
|
1224
|
+
["task.unblocked", "waiting"],
|
|
1225
|
+
["task.ready", "ready"]
|
|
1226
|
+
], "the changes of a task made and unblocked once what it needs completed, with its state after each");
|
|
1227
|
+
alike(changes(alone.id), [
|
|
1228
|
+
["task.created", "ready"],
|
|
1229
|
+
["task.blocked", "blocked"],
|
|
1230
|
+
["task.unblocked", "ready"]
|
|
1231
|
+
], "the changes of a task that needs none, with its state after each");
|
|
1232
|
+
}
|
|
1233
|
+
},
|
|
1234
|
+
{
|
|
1235
|
+
group: "tasks",
|
|
1236
|
+
name: "changes what a task needs: it waits for the new ones, is ready once they have completed, and at once with none",
|
|
1237
|
+
run: async (ctx) => {
|
|
1238
|
+
const { task: done } = await task(ctx, "conformance: a prerequisite that has completed");
|
|
1239
|
+
await (await ctx.board.tasks.claim(done.id, { lease: 60 })).complete();
|
|
1240
|
+
const { task: open } = await task(ctx, "conformance: a prerequisite that has not");
|
|
1241
|
+
const { task: root } = await task(ctx, "conformance: a task whose needs change");
|
|
1242
|
+
const label = [`conformance=${ctx.labels.conformance}`];
|
|
1243
|
+
let { cursor } = await ctx.board.poll({
|
|
1244
|
+
channel: ctx.channel,
|
|
1245
|
+
label
|
|
1246
|
+
});
|
|
1247
|
+
const waiting = await ctx.board.tasks.needs(root.id, [open.id]);
|
|
1248
|
+
same(waiting.task?.state, "waiting", "a ready task, once it needs one that has not completed");
|
|
1249
|
+
same(waiting.labels["board.task"], "waiting", "its root's board.task");
|
|
1250
|
+
alike(waiting.task?.needs, [open.id], "what it needs now");
|
|
1251
|
+
await rejects(ctx.board.tasks.claim(root.id), 409, "task_waiting", "claiming a task that came to wait");
|
|
1252
|
+
const ready = await ctx.board.tasks.needs(root.id, [done.id]);
|
|
1253
|
+
same(ready.task?.state, "ready", "the task, once it needs only what has completed");
|
|
1254
|
+
alike(ready.task?.needs, [done.id], "what it needs now");
|
|
1255
|
+
same((await ctx.board.tasks.needs(root.id, [done.id, done.id])).task?.state, "ready", "the task, after the same needs again");
|
|
1256
|
+
await ctx.board.tasks.needs(root.id, [open.id]);
|
|
1257
|
+
const none = await ctx.board.tasks.needs(root.id, []);
|
|
1258
|
+
same(none.task?.state, "ready", "the task, once it needs nothing");
|
|
1259
|
+
alike(none.task?.needs, [], "what it needs now");
|
|
1260
|
+
await ctx.board.tasks.block(root.id, "conformance: approve?");
|
|
1261
|
+
same((await ctx.board.tasks.needs(root.id, [done.id])).task?.state, "blocked", "a held task, once what it needs changed");
|
|
1262
|
+
same((await ctx.board.tasks.unblock(root.id)).task?.state, "ready", "the task, unblocked, once what it needs now has completed");
|
|
1263
|
+
const seen = [];
|
|
1264
|
+
const changes = () => seen.filter((event) => event.type.startsWith("task.") && event.message?.id === root.id).map((event) => [event.type, event.message?.task?.state]);
|
|
1265
|
+
for (const deadline = Date.now() + 1e4; changes().filter(([type]) => type === "task.ready").length < 2 && Date.now() < deadline;) {
|
|
1266
|
+
const page = await ctx.board.poll({
|
|
1267
|
+
channel: ctx.channel,
|
|
1268
|
+
label,
|
|
1269
|
+
after: cursor,
|
|
1270
|
+
wait: 2
|
|
1271
|
+
});
|
|
1272
|
+
seen.push(...page.events);
|
|
1273
|
+
cursor = page.cursor;
|
|
1274
|
+
}
|
|
1275
|
+
alike(changes(), [
|
|
1276
|
+
["task.needs_changed", "waiting"],
|
|
1277
|
+
["task.needs_changed", "waiting"],
|
|
1278
|
+
["task.ready", "ready"],
|
|
1279
|
+
["task.needs_changed", "waiting"],
|
|
1280
|
+
["task.needs_changed", "ready"],
|
|
1281
|
+
["task.blocked", "blocked"],
|
|
1282
|
+
["task.needs_changed", "blocked"],
|
|
1283
|
+
["task.unblocked", "waiting"],
|
|
1284
|
+
["task.ready", "ready"]
|
|
1285
|
+
], "the changes of a task whose needs changed, with its state after each");
|
|
1286
|
+
}
|
|
1287
|
+
},
|
|
1288
|
+
{
|
|
1289
|
+
group: "tasks",
|
|
1290
|
+
name: "refuses a change of needs that would make a task wait for itself, straight back or through others",
|
|
1291
|
+
run: async (ctx) => {
|
|
1292
|
+
const { task: first } = await task(ctx, "conformance: the first of a line");
|
|
1293
|
+
const { task: second } = await task(ctx, "conformance: waits for the first", { needs: [first.id] });
|
|
1294
|
+
const { task: third } = await task(ctx, "conformance: waits for the second", { needs: [second.id] });
|
|
1295
|
+
await rejects(ctx.board.tasks.needs(first.id, [first.id]), 400, "invalid_needs", "a task that would need itself");
|
|
1296
|
+
await rejects(ctx.board.tasks.needs(first.id, [second.id]), 400, "invalid_needs", "a task that would need one that waits for it");
|
|
1297
|
+
await rejects(ctx.board.tasks.needs(first.id, [third.id]), 400, "invalid_needs", "a task that would need one that waits for it through another");
|
|
1298
|
+
const { task: dropped } = await task(ctx, "conformance: a prerequisite that was canceled, for a change");
|
|
1299
|
+
await ctx.board.tasks.cancel(dropped.id, "conformance: not wanted");
|
|
1300
|
+
const plain = await post(ctx, "conformance: not a task, for a change");
|
|
1301
|
+
await rejects(ctx.board.tasks.needs(first.id, [dropped.id]), 400, "invalid_needs", "a task that would need a canceled one");
|
|
1302
|
+
await rejects(ctx.board.tasks.needs(first.id, [plain.id]), 400, "invalid_needs", "a task that would need a thread that isn't a task");
|
|
1303
|
+
const left = (await ctx.board.thread(first.id)).message.task;
|
|
1304
|
+
same(left?.state, "ready", "the task, after the refused changes");
|
|
1305
|
+
alike(left?.needs, [], "what it needs, after the refused changes");
|
|
1306
|
+
await ctx.board.tasks.needs(second.id, []);
|
|
1307
|
+
const moved = await ctx.board.tasks.needs(first.id, [third.id]);
|
|
1308
|
+
same(moved.task?.state, "waiting", "the task, once it needs one that no longer waits for it");
|
|
1309
|
+
alike(moved.task?.needs, [third.id], "what it needs now");
|
|
1310
|
+
}
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
group: "tasks",
|
|
1314
|
+
name: "changes what a task needs only while no one holds it and it has not finished",
|
|
1315
|
+
run: async (ctx) => {
|
|
1316
|
+
const { task: other } = await task(ctx, "conformance: something to wait for");
|
|
1317
|
+
const { task: root } = await task(ctx, "conformance: a task someone holds, whose needs stay");
|
|
1318
|
+
const claim = await ctx.board.tasks.claim(root.id, { lease: 60 });
|
|
1319
|
+
await rejects(ctx.board.tasks.needs(root.id, [other.id]), 409, "task_claimed", "changing what a claimed task needs");
|
|
1320
|
+
const held = (await ctx.board.thread(root.id)).message.task;
|
|
1321
|
+
same(held?.state, "claimed", "the task, after the refused change");
|
|
1322
|
+
alike(held?.needs, [], "what it needs, after the refused change");
|
|
1323
|
+
await claim.release();
|
|
1324
|
+
same((await ctx.board.tasks.needs(root.id, [other.id])).task?.state, "waiting", "the task, once released and waiting for another");
|
|
1325
|
+
await ctx.board.tasks.needs(root.id, []);
|
|
1326
|
+
await (await ctx.board.tasks.claim(root.id, { lease: 60 })).complete();
|
|
1327
|
+
await rejects(ctx.board.tasks.needs(root.id, [other.id]), 409, "task_finished", "changing what a completed task needs");
|
|
1328
|
+
const { task: failed } = await task(ctx, "conformance: a task that fails, whose needs stay");
|
|
1329
|
+
await (await ctx.board.tasks.claim(failed.id, { lease: 60 })).fail("conformance: not this time");
|
|
1330
|
+
await rejects(ctx.board.tasks.needs(failed.id, [other.id]), 409, "task_finished", "changing what a failed task needs");
|
|
1331
|
+
const { task: dropped } = await task(ctx, "conformance: a task that is canceled, whose needs stay");
|
|
1332
|
+
await ctx.board.tasks.cancel(dropped.id, "conformance: not wanted");
|
|
1333
|
+
await rejects(ctx.board.tasks.needs(dropped.id, [other.id]), 409, "task_finished", "changing what a canceled task needs");
|
|
1334
|
+
}
|
|
1335
|
+
},
|
|
1336
|
+
{
|
|
1337
|
+
group: "tasks",
|
|
1338
|
+
name: "makes several tasks in one write, in the order given: each waits for the ones it names, of the batch or there already, and an id makes them once",
|
|
1339
|
+
run: async (ctx) => {
|
|
1340
|
+
const { task: done } = await task(ctx, "conformance: a prerequisite that has completed");
|
|
1341
|
+
await (await ctx.board.tasks.claim(done.id, { lease: 60 })).complete();
|
|
1342
|
+
const { task: open } = await task(ctx, "conformance: a prerequisite that has not");
|
|
1343
|
+
const id = `conformance-batch-${ctx.labels.conformance}`;
|
|
1344
|
+
const plan = [
|
|
1345
|
+
{
|
|
1346
|
+
key: "review",
|
|
1347
|
+
text: "conformance: batched, waits for the one after it",
|
|
1348
|
+
needs: [{ key: "fix" }]
|
|
1349
|
+
},
|
|
1350
|
+
{
|
|
1351
|
+
key: "fix",
|
|
1352
|
+
text: "conformance: batched, waits for nothing"
|
|
1353
|
+
},
|
|
1354
|
+
{
|
|
1355
|
+
text: "conformance: batched, waits for one that has completed",
|
|
1356
|
+
needs: [done.id]
|
|
1357
|
+
},
|
|
1358
|
+
{
|
|
1359
|
+
text: "conformance: batched, waits for one that has not, and for one of the batch",
|
|
1360
|
+
needs: [open.id, { key: "fix" }]
|
|
1361
|
+
}
|
|
1362
|
+
];
|
|
1363
|
+
const made = await taskBatch(ctx, plan, { id });
|
|
1364
|
+
alike(made.map((root) => root.text), plan.map((one) => one.text), "a batch's tasks, in the order it gave them");
|
|
1365
|
+
const [review, fix, after, both] = made;
|
|
1366
|
+
for (const root of made) isRef(root.id, "a batched task's id");
|
|
1367
|
+
same(new Set(made.map((root) => root.id)).size, made.length, "the batch's different IDs");
|
|
1368
|
+
same(fix.task?.state, "ready", "a batched task that needs nothing");
|
|
1369
|
+
same(fix.task?.owner, ctx.me.principal, "a batched task's owner");
|
|
1370
|
+
same(fix.labels["board.task"], "ready", "its root's board.task");
|
|
1371
|
+
same(review.task?.state, "waiting", "a batched task that needs a later one of the batch");
|
|
1372
|
+
alike(review.task?.needs, [fix.id], "what it needs, by the ID the batch gave that task");
|
|
1373
|
+
same(after.task?.state, "ready", "a batched task whose needs were all there and have completed");
|
|
1374
|
+
alike(after.task?.needs, [done.id], "what it needs");
|
|
1375
|
+
same(both.task?.state, "waiting", "a batched task that needs one of the batch and one that has not completed");
|
|
1376
|
+
alike(both.task?.needs?.slice().sort(), [open.id, fix.id].sort(), "what it needs");
|
|
1377
|
+
same((await ctx.board.thread(review.id)).message.task?.state, "waiting", "a batched task, read as its thread");
|
|
1378
|
+
const mine = async () => (await ctx.board.tasks.list({
|
|
1379
|
+
channel: ctx.channel,
|
|
1380
|
+
label: ctx.labels,
|
|
1381
|
+
state: "all",
|
|
1382
|
+
limit: 500
|
|
1383
|
+
})).tasks.map((listed) => listed.message).filter((root) => root.text.startsWith("conformance: batched,"));
|
|
1384
|
+
alike((await mine()).map((root) => root.id), made.map((root) => root.id), "the batch, listed");
|
|
1385
|
+
alike((await ctx.board.tasks.createMany(ctx.channel, plan.map((one) => ({
|
|
1386
|
+
...one,
|
|
1387
|
+
labels: ctx.labels,
|
|
1388
|
+
noSync: true
|
|
1389
|
+
})), { id })).map((root) => root.id), made.map((root) => root.id), "the tasks a retry with the same id answers");
|
|
1390
|
+
await rejects(taskBatch(ctx, [...plan, { text: "conformance: batched, one more under the same id" }], { id }), 409, "duplicate_id", "another batch under the same id");
|
|
1391
|
+
await rejects(taskBatch(ctx, plan.map((one, at) => at === 1 ? {
|
|
1392
|
+
...one,
|
|
1393
|
+
text: "conformance: batched, another plan of the same size under the same id"
|
|
1394
|
+
} : one), { id }), 409, "duplicate_id", "another plan of the same size under the same id");
|
|
1395
|
+
same((await mine()).length, made.length, "the tasks made under that id");
|
|
1396
|
+
await (await ctx.board.tasks.claim(fix.id, { lease: 60 })).complete();
|
|
1397
|
+
await soon(async () => await taskState(ctx, review.id) === "ready", "a batched task should be ready once the one it waited for completed");
|
|
1398
|
+
same(await taskState(ctx, both.id), "waiting", "the batched task that still waits for one that has not completed");
|
|
1399
|
+
}
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
group: "tasks",
|
|
1403
|
+
name: "makes none of a batch when one of its tasks can not be made, wherever it comes in it",
|
|
1404
|
+
run: async (ctx) => {
|
|
1405
|
+
const { task: gone } = await task(ctx, "conformance: a prerequisite that was canceled");
|
|
1406
|
+
await ctx.board.tasks.cancel(gone.id, "conformance: not wanted");
|
|
1407
|
+
const fine = [{
|
|
1408
|
+
key: "a",
|
|
1409
|
+
text: "conformance: never made, first of a refused batch"
|
|
1410
|
+
}, {
|
|
1411
|
+
text: "conformance: never made, second of a refused batch",
|
|
1412
|
+
needs: [{ key: "a" }]
|
|
1413
|
+
}];
|
|
1414
|
+
const refused = (last, what) => rejects(taskBatch(ctx, [...fine, ...last]), 400, "invalid_needs", what);
|
|
1415
|
+
await refused([{
|
|
1416
|
+
text: "conformance: never made, waits for no one",
|
|
1417
|
+
needs: [{ key: "nobody" }]
|
|
1418
|
+
}], "a batch with a task that needs a key no task of it has");
|
|
1419
|
+
await refused([{
|
|
1420
|
+
key: "a",
|
|
1421
|
+
text: "conformance: never made, a second a"
|
|
1422
|
+
}], "a batch with a key two of its tasks have");
|
|
1423
|
+
await refused([{
|
|
1424
|
+
key: "itself",
|
|
1425
|
+
text: "conformance: never made, waits for itself",
|
|
1426
|
+
needs: [{ key: "itself" }]
|
|
1427
|
+
}], "a batch with a task that needs itself");
|
|
1428
|
+
await refused([{
|
|
1429
|
+
key: "x",
|
|
1430
|
+
text: "conformance: never made, waits for y",
|
|
1431
|
+
needs: [{ key: "y" }]
|
|
1432
|
+
}, {
|
|
1433
|
+
key: "y",
|
|
1434
|
+
text: "conformance: never made, waits for x",
|
|
1435
|
+
needs: [{ key: "x" }]
|
|
1436
|
+
}], "a batch with tasks that wait for each other");
|
|
1437
|
+
await refused([{
|
|
1438
|
+
text: "conformance: never made, waits for a canceled one",
|
|
1439
|
+
needs: [gone.id]
|
|
1440
|
+
}], "a batch whose last task needs one that was canceled");
|
|
1441
|
+
const { tasks } = await ctx.board.tasks.list({
|
|
1442
|
+
channel: ctx.channel,
|
|
1443
|
+
label: ctx.labels,
|
|
1444
|
+
state: "all",
|
|
1445
|
+
limit: 500
|
|
1446
|
+
});
|
|
1447
|
+
const left = tasks.filter((listed) => listed.message.text.startsWith("conformance: never made"));
|
|
1448
|
+
check(left.length === 0, `a refused batch should make none of its tasks, and these are there: ${show(left.map((listed) => listed.message.text))}`);
|
|
1449
|
+
}
|
|
1450
|
+
},
|
|
1451
|
+
{
|
|
1452
|
+
group: "tasks",
|
|
1453
|
+
name: "holds a task for a person, by its owner or its claim, and gives it back when unblocked",
|
|
1454
|
+
run: async (ctx) => {
|
|
1455
|
+
const { task: root } = await task(ctx, "conformance: a task to hold for a person");
|
|
1456
|
+
const blocked = await ctx.board.tasks.block(root.id, "conformance: approve?", { kind: "awaiting_approval" });
|
|
1457
|
+
same(blocked.task?.state, "blocked", "a held task");
|
|
1458
|
+
alike(blocked.task?.blocked, {
|
|
1459
|
+
kind: "awaiting_approval",
|
|
1460
|
+
reason: "conformance: approve?"
|
|
1461
|
+
}, "what it is held for");
|
|
1462
|
+
await rejects(ctx.board.tasks.claim(root.id), 409, "task_blocked", "claiming a held task");
|
|
1463
|
+
same((await ctx.board.tasks.unblock(root.id)).task?.state, "ready", "the task, unblocked");
|
|
1464
|
+
const claim = await ctx.board.tasks.claim(root.id, { lease: 60 });
|
|
1465
|
+
await rejects(ctx.board.tasks.block(root.id, "conformance: without the claim"), 409, "task_claimed", "holding a claimed task without its claim");
|
|
1466
|
+
same((await claim.block("conformance: which one?", { kind: "needs_input" })).task?.state, "blocked", "a claimed task, held by its claim");
|
|
1467
|
+
await rejects(claim.complete(), 409, "claim_lost", "completing with a claim that held the task");
|
|
1468
|
+
await ctx.board.tasks.unblock(root.id);
|
|
1469
|
+
await ctx.board.tasks.cancel(root.id, "conformance: done checking");
|
|
1470
|
+
await rejects(ctx.board.tasks.claim(root.id), 409, "task_finished", "claiming a canceled task");
|
|
1471
|
+
await rejects(ctx.board.tasks.cancel(root.id, "conformance: again"), 409, "task_finished", "canceling a canceled task");
|
|
1472
|
+
}
|
|
1473
|
+
},
|
|
1474
|
+
{
|
|
1475
|
+
group: "tasks",
|
|
1476
|
+
name: "keeps a task assigned to a profile for that actor alone",
|
|
1477
|
+
run: async (ctx) => {
|
|
1478
|
+
const fixer = ctx.board.as("conformance");
|
|
1479
|
+
const assignee = await fixer.me();
|
|
1480
|
+
if (assignee.principal !== ctx.me.principal) return "this handle's profiles are principals of their own, so none is its principal's actor";
|
|
1481
|
+
if (assignee.actor === ctx.me.actor) return "this credential writes as one actor only, so no other actor of its principal can try";
|
|
1482
|
+
const { task: root } = await task(ctx, "conformance: a task for one profile", { for: assignee.actor });
|
|
1483
|
+
same(root.task?.for, assignee.actor, "who the task is for");
|
|
1484
|
+
await rejects(ctx.board.tasks.claim(root.id), 409, "task_assigned", "claiming a task assigned to another actor");
|
|
1485
|
+
const claim = await fixer.tasks.claim(root.id, { lease: 60 });
|
|
1486
|
+
same(claim.task.task?.claim?.actor, assignee.actor, "who holds it");
|
|
1487
|
+
await claim.release();
|
|
1488
|
+
same((await ctx.board.tasks.assign(root.id, null)).task?.for, null, "who the task is for, back in the pool");
|
|
1489
|
+
await (await ctx.board.tasks.claim(root.id, { lease: 60 })).release();
|
|
1490
|
+
await rejects(ctx.board.tasks.assign(root.id, "conformance:not-an-actor-of-its-owner"), 400, "invalid_request", "assigning a task to an actor that isn't its owner's");
|
|
1491
|
+
}
|
|
1492
|
+
},
|
|
1493
|
+
{
|
|
1494
|
+
group: "tasks",
|
|
1495
|
+
name: "lets a profile change only the tasks it made, and its principal all of them",
|
|
1496
|
+
run: async (ctx) => {
|
|
1497
|
+
const { task: principals } = await task(ctx, "conformance: its principal's task");
|
|
1498
|
+
if (!ctx.withHeaders) return NO_HEADERS;
|
|
1499
|
+
if (ctx.me.actor !== ctx.me.principal) return "this run writes as a profile, so it can't change tasks as its principal";
|
|
1500
|
+
const can = `${ctx.channel}=read,post,react,label`;
|
|
1501
|
+
const as = (name) => ctx.withHeaders({
|
|
1502
|
+
"x-board-profile": `conformance-${name}-${ctx.labels.conformance}`,
|
|
1503
|
+
"x-board-can": can
|
|
1504
|
+
});
|
|
1505
|
+
const principal = ctx.withHeaders({ "x-board-can": can });
|
|
1506
|
+
const profile = as("own");
|
|
1507
|
+
const sibling = as("other");
|
|
1508
|
+
const [actor, other] = await Promise.all([profile.me(), sibling.me()]);
|
|
1509
|
+
if (actor.principal !== ctx.me.principal) return "this handle's profiles are principals of their own, so none is its principal's actor";
|
|
1510
|
+
await rejects(profile.tasks.assign(principals.id, actor.actor), 403, "task_not_owned", "assigning its principal's task to itself, by a profile");
|
|
1511
|
+
await rejects(profile.tasks.block(principals.id, "conformance: not its own"), 403, "task_not_owned", "holding its principal's task, by a profile");
|
|
1512
|
+
await rejects(profile.tasks.cancel(principals.id, "conformance: not its own"), 403, "task_not_owned", "canceling its principal's task, by a profile");
|
|
1513
|
+
await rejects(profile.tasks.needs(principals.id, []), 403, "task_not_owned", "changing what its principal's task needs, by a profile");
|
|
1514
|
+
const { task: own } = await profile.tasks.create(ctx.channel, {
|
|
1515
|
+
text: "conformance: a profile's own task",
|
|
1516
|
+
labels: ctx.labels,
|
|
1517
|
+
noSync: true
|
|
1518
|
+
});
|
|
1519
|
+
ctx.posted.push(own.id);
|
|
1520
|
+
same(own.task?.owner, ctx.me.principal, "who owns a profile's task: its principal");
|
|
1521
|
+
same(own.task?.by, actor.actor, "the actor a profile's task was made as");
|
|
1522
|
+
same((await ctx.board.thread(own.id)).message.task?.by, actor.actor, "the actor a profile's task was made as, read as its thread");
|
|
1523
|
+
same(principals.task?.by, ctx.me.principal, "the actor its principal's task was made as");
|
|
1524
|
+
same((await profile.tasks.assign(own.id, actor.actor)).task?.for, actor.actor, "who a profile's own task is for, once it assigns it");
|
|
1525
|
+
await rejects(sibling.tasks.assign(own.id, other.actor), 403, "task_not_owned", "assigning a profile's task to itself, by another profile of its principal");
|
|
1526
|
+
await rejects(sibling.tasks.cancel(own.id, "conformance: not its own"), 403, "task_not_owned", "canceling a profile's task, by another profile of its principal");
|
|
1527
|
+
same((await ctx.board.thread(own.id)).message.task?.for, actor.actor, "who a profile's task is for, after another profile's refused changes");
|
|
1528
|
+
same((await principal.tasks.assign(own.id, null)).task?.for, null, "who a profile's task is for, once its principal gives it back to the pool");
|
|
1529
|
+
same((await principal.tasks.cancel(own.id, "conformance: done checking")).task?.state, "canceled", "a profile's task, once its principal cancels it");
|
|
1530
|
+
same((await principal.tasks.assign(principals.id, actor.actor)).task?.for, actor.actor, "who its principal's task is for, once its principal assigns it");
|
|
1531
|
+
const thread = await profile.post(ctx.channel, {
|
|
1532
|
+
text: "conformance: a profile's thread, made a task by its principal",
|
|
1533
|
+
labels: ctx.labels,
|
|
1534
|
+
noSync: true
|
|
1535
|
+
});
|
|
1536
|
+
ctx.posted.push(thread.id);
|
|
1537
|
+
await principal.tasks.create({ re: thread.id });
|
|
1538
|
+
await profile.edit(thread.id, "conformance: a profile's thread, edited by it");
|
|
1539
|
+
const edited = (await ctx.board.thread(thread.id)).message;
|
|
1540
|
+
same(edited.task?.state, "blocked", "its principal's task, once the profile that wrote its root edited it");
|
|
1541
|
+
same(edited.task?.blocked?.kind, "edited", "what it is held for");
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
{
|
|
1545
|
+
group: "tasks",
|
|
1546
|
+
name: "takes label in its channel to claim a task: a caller narrowed to reading and posting claims none",
|
|
1547
|
+
run: async (ctx) => {
|
|
1548
|
+
const { task: root } = await task(ctx, "conformance: a task to claim without label");
|
|
1549
|
+
if (!ctx.withCan) return NO_CAN;
|
|
1550
|
+
const narrowed = ctx.withCan(`${ctx.channel}=read,post`);
|
|
1551
|
+
same((await narrowed.thread(root.id)).message.task?.state, "ready", "the task, as a caller narrowed to reading and posting reads it");
|
|
1552
|
+
await rejects(narrowed.tasks.claim(root.id), 403, "forbidden", "a claim by a caller without label in its channel");
|
|
1553
|
+
await rejects(narrowed.tasks.claim({
|
|
1554
|
+
channel: ctx.channel,
|
|
1555
|
+
label: ctx.labels
|
|
1556
|
+
}), 403, "forbidden", "a claim of the next ready task by a caller without label in that channel");
|
|
1557
|
+
same(await taskState(ctx, root.id), "ready", "the task, after the refused claims");
|
|
1558
|
+
}
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
group: "tasks",
|
|
1562
|
+
name: "takes read in a prerequisite's channel to wait for it: a caller narrowed out of it makes no task that needs it",
|
|
1563
|
+
run: async (ctx) => {
|
|
1564
|
+
const beside = besideOf(ctx);
|
|
1565
|
+
const made = await taskBeside(ctx, "conformance: a prerequisite its caller can't read");
|
|
1566
|
+
if (!ctx.withCan) return NO_CAN;
|
|
1567
|
+
if (!made) return `this token can't post in ${beside}`;
|
|
1568
|
+
const unread = made.task;
|
|
1569
|
+
const { task: read } = await task(ctx, "conformance: a prerequisite its caller reads");
|
|
1570
|
+
const narrowed = ctx.withCan(`*=post;${ctx.channel}=read,post,label`);
|
|
1571
|
+
await rejects(narrowed.tasks.create(ctx.channel, {
|
|
1572
|
+
text: "conformance: needs a task its caller can't read",
|
|
1573
|
+
labels: ctx.labels,
|
|
1574
|
+
noSync: true,
|
|
1575
|
+
needs: [unread.id]
|
|
1576
|
+
}).then((started) => {
|
|
1577
|
+
ctx.posted.push(started.task.id);
|
|
1578
|
+
return started;
|
|
1579
|
+
}), 400, "invalid_needs", "a task that needs one its caller can't read");
|
|
1580
|
+
const plain = await narrowed.post(ctx.channel, {
|
|
1581
|
+
text: "conformance: a thread that would need a task its caller can't read",
|
|
1582
|
+
labels: ctx.labels,
|
|
1583
|
+
noSync: true
|
|
1584
|
+
});
|
|
1585
|
+
ctx.posted.push(plain.id);
|
|
1586
|
+
await rejects(narrowed.tasks.create({ re: plain.id }, { needs: [unread.id] }), 400, "invalid_needs", "making a thread a task that needs one its caller can't read");
|
|
1587
|
+
same((await ctx.board.thread(plain.id)).message.task, void 0, "the thread, after it was refused as a task");
|
|
1588
|
+
alike((await ctx.board.tasks.list({ needs: unread.id })).tasks.map((listed) => listed.message.id), [], "the tasks that wait for the one its caller can't read");
|
|
1589
|
+
const waits = await narrowed.tasks.create(ctx.channel, {
|
|
1590
|
+
text: "conformance: needs a task its caller reads",
|
|
1591
|
+
labels: ctx.labels,
|
|
1592
|
+
noSync: true,
|
|
1593
|
+
needs: [read.id]
|
|
1594
|
+
});
|
|
1595
|
+
ctx.posted.push(waits.task.id);
|
|
1596
|
+
same(waits.task.task?.state, "waiting", "a task that needs one its caller reads");
|
|
1597
|
+
}
|
|
1598
|
+
},
|
|
1599
|
+
{
|
|
1600
|
+
group: "tasks",
|
|
1601
|
+
name: "claims the oldest ready task in a channel or its subtree that has the labels asked for, and waits for one",
|
|
1602
|
+
run: async (ctx) => {
|
|
1603
|
+
const queue = {
|
|
1604
|
+
...ctx.labels,
|
|
1605
|
+
queue: `q${ctx.labels.conformance}`
|
|
1606
|
+
};
|
|
1607
|
+
const { task: older } = await task(ctx, "conformance: the older of two", { labels: queue });
|
|
1608
|
+
const { task: newer } = await task(ctx, "conformance: the newer of two", { labels: queue });
|
|
1609
|
+
same(await ctx.board.tasks.claim({
|
|
1610
|
+
channel: ctx.channel,
|
|
1611
|
+
label: {
|
|
1612
|
+
...queue,
|
|
1613
|
+
queue: "no-such-queue"
|
|
1614
|
+
}
|
|
1615
|
+
}), null, "a claim for labels no ready task has");
|
|
1616
|
+
const first = await ctx.board.tasks.claim({
|
|
1617
|
+
channel: `${ctx.channel}/`,
|
|
1618
|
+
label: queue,
|
|
1619
|
+
lease: 60
|
|
1620
|
+
});
|
|
1621
|
+
same(first?.task.id, older.id, "the task claimed first, in the subtree");
|
|
1622
|
+
const second = await ctx.board.tasks.claim({
|
|
1623
|
+
channel: ctx.channel,
|
|
1624
|
+
label: queue,
|
|
1625
|
+
lease: 60
|
|
1626
|
+
});
|
|
1627
|
+
same(second?.task.id, newer.id, "the task claimed next, in the channel");
|
|
1628
|
+
same(await ctx.board.tasks.claim({
|
|
1629
|
+
channel: ctx.channel,
|
|
1630
|
+
label: queue
|
|
1631
|
+
}), null, "a claim once both are held");
|
|
1632
|
+
const waiting = ctx.board.tasks.claim({
|
|
1633
|
+
channel: ctx.channel,
|
|
1634
|
+
label: queue,
|
|
1635
|
+
wait: 10,
|
|
1636
|
+
lease: 60
|
|
1637
|
+
});
|
|
1638
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1639
|
+
await first.release();
|
|
1640
|
+
const got = await waiting;
|
|
1641
|
+
same(got?.task.id, older.id, "the task a waiting claim got");
|
|
1642
|
+
await got.release();
|
|
1643
|
+
await second.release();
|
|
1644
|
+
}
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
group: "tasks",
|
|
1648
|
+
name: "shows a feed that filters on board.task=ready a task becoming ready and being claimed, and never a token",
|
|
1649
|
+
run: async (ctx) => {
|
|
1650
|
+
const { task: first } = await task(ctx, "conformance: a prerequisite to watch");
|
|
1651
|
+
const { task: second } = await task(ctx, "conformance: a task to watch become ready", { needs: [first.id] });
|
|
1652
|
+
const label = [`conformance=${ctx.labels.conformance}`, "board.task=ready"];
|
|
1653
|
+
let { cursor } = await ctx.board.poll({
|
|
1654
|
+
channel: ctx.channel,
|
|
1655
|
+
label
|
|
1656
|
+
});
|
|
1657
|
+
const seen = [];
|
|
1658
|
+
const until = async (found, what) => {
|
|
1659
|
+
for (const deadline = Date.now() + 1e4; !found();) {
|
|
1660
|
+
if (Date.now() >= deadline) throw new Mismatch(`${what}, within a few seconds`);
|
|
1661
|
+
const page = await ctx.board.poll({
|
|
1662
|
+
channel: ctx.channel,
|
|
1663
|
+
label,
|
|
1664
|
+
after: cursor,
|
|
1665
|
+
wait: 2
|
|
1666
|
+
});
|
|
1667
|
+
seen.push(...page.events);
|
|
1668
|
+
cursor = page.cursor;
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
await (await ctx.board.tasks.claim(first.id, { lease: 60 })).complete();
|
|
1672
|
+
await until(() => seen.some((event) => event.type === "task.ready" && event.message?.id === second.id), "the feed should show the task become ready");
|
|
1673
|
+
const claim = await ctx.board.tasks.claim(second.id, { lease: 60 });
|
|
1674
|
+
await until(() => seen.some((event) => event.type === "task.claimed" && event.message?.id === second.id), "the feed should show the task being claimed");
|
|
1675
|
+
const claimed = seen.find((event) => event.type === "task.claimed" && event.message?.id === second.id);
|
|
1676
|
+
same(claimed.message?.task?.state, "claimed", "the task in its claim's event");
|
|
1677
|
+
check(!("token" in claimed.payload) && !show(seen).includes(claim.token), "the feed shouldn't show a claim's token");
|
|
1678
|
+
await claim.release();
|
|
1679
|
+
}
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
group: "tasks",
|
|
1683
|
+
name: "keeps labels under board. its own: a label write or a post that sets one is refused",
|
|
1684
|
+
run: async (ctx) => {
|
|
1685
|
+
const { task: root } = await task(ctx, "conformance: a task whose label is the board's");
|
|
1686
|
+
await rejects(ctx.board.label(root.id, { set: { "board.task": "completed" } }), 400, "reserved_label", "a label write that sets board.task");
|
|
1687
|
+
await rejects(ctx.board.label(root.id, { unset: ["board.task"] }), 400, "reserved_label", "a label write that unsets board.task");
|
|
1688
|
+
await rejects(ctx.board.post(ctx.channel, {
|
|
1689
|
+
text: "conformance: a post that names itself ready",
|
|
1690
|
+
labels: {
|
|
1691
|
+
...ctx.labels,
|
|
1692
|
+
"board.task": "ready"
|
|
1693
|
+
},
|
|
1694
|
+
noSync: true
|
|
1695
|
+
}).then((message) => {
|
|
1696
|
+
ctx.posted.push(message.id);
|
|
1697
|
+
return message;
|
|
1698
|
+
}), 400, "reserved_label", "a post whose labels set board.task");
|
|
1699
|
+
same(await taskState(ctx, root.id), "ready", "the task, after the refused writes");
|
|
1700
|
+
await ctx.board.label(root.id, {
|
|
1701
|
+
set: { seen: "yes" },
|
|
1702
|
+
if: { "board.task": "ready" }
|
|
1703
|
+
});
|
|
1704
|
+
same((await ctx.board.thread(root.id)).message.labels.seen, "yes", "a label set while board.task is what the write's `if` says");
|
|
1705
|
+
await rejects(ctx.board.label(root.id, {
|
|
1706
|
+
set: { seen: "no" },
|
|
1707
|
+
if: { "board.task": null }
|
|
1708
|
+
}), 409, "label_conflict", "a label write that holds on there being no task, on a task");
|
|
1709
|
+
await rejects(ctx.board.label(root.id, {
|
|
1710
|
+
set: { seen: "no" },
|
|
1711
|
+
if: { "board.task": "claimed" }
|
|
1712
|
+
}), 409, "label_conflict", "a label write that holds on a state the task isn't in");
|
|
1713
|
+
same((await ctx.board.thread(root.id)).message.labels.seen, "yes", "the label, after the writes its `if` refused");
|
|
1714
|
+
}
|
|
1715
|
+
},
|
|
1716
|
+
{
|
|
1717
|
+
group: "tasks",
|
|
1718
|
+
name: "holds a task when anyone but its owner edits its root, which ends its claim",
|
|
1719
|
+
run: async (ctx) => {
|
|
1720
|
+
await ctx.board.tasks.list({
|
|
1721
|
+
channel: ctx.channel,
|
|
1722
|
+
limit: 1
|
|
1723
|
+
});
|
|
1724
|
+
const key = SYNC_KEY;
|
|
1725
|
+
const thread = `${key}:${ctx.labels.conformance}:task`;
|
|
1726
|
+
const author = {
|
|
1727
|
+
id: `${key}:user:${ctx.labels.conformance}`,
|
|
1728
|
+
handle: "conformance",
|
|
1729
|
+
name: "Conformance",
|
|
1730
|
+
avatar: null,
|
|
1731
|
+
isBot: false
|
|
1732
|
+
};
|
|
1733
|
+
const origin = {
|
|
1734
|
+
thread,
|
|
1735
|
+
message: "1"
|
|
1736
|
+
};
|
|
1737
|
+
const registered = await registerSync(ctx);
|
|
1738
|
+
if ("skip" in registered) return registered.skip;
|
|
1739
|
+
let id;
|
|
1740
|
+
try {
|
|
1741
|
+
({message: id} = await ctx.board.syncImport({
|
|
1742
|
+
op: "post",
|
|
1743
|
+
author,
|
|
1744
|
+
from: key,
|
|
1745
|
+
channel: ctx.channel,
|
|
1746
|
+
text: "conformance: from a platform, to make a task",
|
|
1747
|
+
labels: ctx.labels,
|
|
1748
|
+
noSync: true,
|
|
1749
|
+
origin: {
|
|
1750
|
+
channel: `${key}:${ctx.labels.conformance}`,
|
|
1751
|
+
thread,
|
|
1752
|
+
subthread: null,
|
|
1753
|
+
message: "1",
|
|
1754
|
+
context: null
|
|
1755
|
+
}
|
|
1756
|
+
}));
|
|
1757
|
+
} catch (error) {
|
|
1758
|
+
await ctx.board.register({
|
|
1759
|
+
...registered.where,
|
|
1760
|
+
watch: {}
|
|
1761
|
+
}).catch(() => {});
|
|
1762
|
+
if (error instanceof BoardError && error.status === 403) return `this token can't sync in ${ctx.channel}`;
|
|
1763
|
+
throw error;
|
|
1764
|
+
}
|
|
1765
|
+
try {
|
|
1766
|
+
isRef(id, "an import's message");
|
|
1767
|
+
await ctx.board.tasks.create({ re: id });
|
|
1768
|
+
const claim = await ctx.board.tasks.claim(id, { lease: 60 });
|
|
1769
|
+
await ctx.board.syncImport({
|
|
1770
|
+
op: "edit",
|
|
1771
|
+
author,
|
|
1772
|
+
from: key,
|
|
1773
|
+
origin,
|
|
1774
|
+
text: "conformance: edited on the platform"
|
|
1775
|
+
});
|
|
1776
|
+
const edited = (await ctx.board.thread(id)).message;
|
|
1777
|
+
same(edited.text, "conformance: edited on the platform", "the root's text, once edited");
|
|
1778
|
+
same(edited.task?.state, "blocked", "the task, once its root was edited by someone else");
|
|
1779
|
+
same(edited.task?.blocked?.kind, "edited", "what it is held for");
|
|
1780
|
+
await rejects(claim.complete(), 409, "claim_lost", "the claim's complete, once the edit held the task");
|
|
1781
|
+
same((await ctx.board.tasks.unblock(id)).task?.state, "ready", "the task, once its owner unblocked it");
|
|
1782
|
+
} finally {
|
|
1783
|
+
await ctx.board.syncImport({
|
|
1784
|
+
op: "delete",
|
|
1785
|
+
author,
|
|
1786
|
+
from: key,
|
|
1787
|
+
origin
|
|
1788
|
+
}).catch(() => {});
|
|
1789
|
+
await ctx.board.register({
|
|
1790
|
+
...registered.where,
|
|
1791
|
+
watch: {}
|
|
1792
|
+
}).catch(() => {});
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
831
1796
|
{
|
|
832
1797
|
group: "grants",
|
|
833
1798
|
name: "grants a principal, lists it, and revokes it",
|
|
@@ -1316,6 +2281,26 @@ const CHECKS = [
|
|
|
1316
2281
|
same(new TextDecoder().decode(await response.arrayBuffer()), new TextDecoder().decode(bytes), "the file's bytes");
|
|
1317
2282
|
}
|
|
1318
2283
|
},
|
|
2284
|
+
{
|
|
2285
|
+
group: "attachments",
|
|
2286
|
+
name: "starts a task with a file, which its root carries",
|
|
2287
|
+
run: async (ctx) => {
|
|
2288
|
+
await ctx.board.tasks.list({
|
|
2289
|
+
channel: ctx.channel,
|
|
2290
|
+
limit: 1
|
|
2291
|
+
});
|
|
2292
|
+
const bytes = new TextEncoder().encode(`conformance ${ctx.labels.conformance}: a task's file\n`);
|
|
2293
|
+
const attachment = await ctx.board.upload({
|
|
2294
|
+
data: bytes,
|
|
2295
|
+
name: "conformance-task.txt",
|
|
2296
|
+
type: "text/plain"
|
|
2297
|
+
});
|
|
2298
|
+
const { task: root } = await task(ctx, "conformance: a task with a file", { attachments: [attachment.id] });
|
|
2299
|
+
check(root.attachments.some((a) => a.id === attachment.id), "the task's root should carry the file");
|
|
2300
|
+
same(root.task?.state, "ready", "the task's state");
|
|
2301
|
+
check((await ctx.board.thread(root.id)).message.attachments.some((a) => a.id === attachment.id), "the task, read as its thread, should carry the file");
|
|
2302
|
+
}
|
|
2303
|
+
},
|
|
1319
2304
|
{
|
|
1320
2305
|
group: "watchers",
|
|
1321
2306
|
name: "matches a registered tail, hands the match to a pull, and takes its ack",
|
|
@@ -1522,6 +2507,78 @@ const CHECKS = [
|
|
|
1522
2507
|
}
|
|
1523
2508
|
}
|
|
1524
2509
|
},
|
|
2510
|
+
{
|
|
2511
|
+
group: "sync",
|
|
2512
|
+
name: "meets a platform user an import's text mentions: an actor as one who wrote would be, whom the text names by that actor's ID",
|
|
2513
|
+
run: async (ctx) => {
|
|
2514
|
+
const key = SYNC_KEY;
|
|
2515
|
+
const thread = `${key}:${ctx.labels.conformance}:mentioned`;
|
|
2516
|
+
const author = {
|
|
2517
|
+
id: `${key}:user:${ctx.labels.conformance}`,
|
|
2518
|
+
handle: "conformance",
|
|
2519
|
+
name: "Conformance",
|
|
2520
|
+
avatar: null,
|
|
2521
|
+
isBot: false
|
|
2522
|
+
};
|
|
2523
|
+
const cc = {
|
|
2524
|
+
id: `${key}:user:${ctx.labels.conformance}-cc`,
|
|
2525
|
+
handle: "conformance-cc",
|
|
2526
|
+
name: "Conformance Cc",
|
|
2527
|
+
avatar: null,
|
|
2528
|
+
isBot: false
|
|
2529
|
+
};
|
|
2530
|
+
const origin = {
|
|
2531
|
+
thread,
|
|
2532
|
+
message: "1"
|
|
2533
|
+
};
|
|
2534
|
+
const registered = await registerSync(ctx);
|
|
2535
|
+
if ("skip" in registered) return registered.skip;
|
|
2536
|
+
const { where } = registered;
|
|
2537
|
+
try {
|
|
2538
|
+
let imported;
|
|
2539
|
+
try {
|
|
2540
|
+
imported = await ctx.board.syncImport({
|
|
2541
|
+
op: "post",
|
|
2542
|
+
author,
|
|
2543
|
+
from: key,
|
|
2544
|
+
channel: ctx.channel,
|
|
2545
|
+
text: `conformance: cc @[${cc.id}]`,
|
|
2546
|
+
mentioned: [cc],
|
|
2547
|
+
labels: ctx.labels,
|
|
2548
|
+
noSync: true,
|
|
2549
|
+
origin: {
|
|
2550
|
+
channel: `${key}:${ctx.labels.conformance}`,
|
|
2551
|
+
thread,
|
|
2552
|
+
subthread: null,
|
|
2553
|
+
message: "1",
|
|
2554
|
+
context: null
|
|
2555
|
+
},
|
|
2556
|
+
id: `conformance-mentioned-${ctx.labels.conformance}`
|
|
2557
|
+
});
|
|
2558
|
+
} catch (error) {
|
|
2559
|
+
if (error instanceof BoardError && error.status === 403) return `this token can't sync in ${ctx.channel}`;
|
|
2560
|
+
throw error;
|
|
2561
|
+
}
|
|
2562
|
+
isRef(imported.message, "an import's message");
|
|
2563
|
+
const actor = `${ctx.me.principal}+${cc.id}`;
|
|
2564
|
+
same((await ctx.board.thread(imported.message)).message.text, `conformance: cc @[${actor}]`, "the import's text, its mention by the actor's ID");
|
|
2565
|
+
const met = (await ctx.board.actors()).find((known) => known.id === actor);
|
|
2566
|
+
check(met !== void 0, `the board should know the user the import mentioned as ${actor}`);
|
|
2567
|
+
same(met?.name, cc.name, "the mentioned user's name");
|
|
2568
|
+
} finally {
|
|
2569
|
+
await ctx.board.syncImport({
|
|
2570
|
+
op: "delete",
|
|
2571
|
+
author,
|
|
2572
|
+
from: key,
|
|
2573
|
+
origin
|
|
2574
|
+
}).catch(() => {});
|
|
2575
|
+
await ctx.board.register({
|
|
2576
|
+
...where,
|
|
2577
|
+
watch: {}
|
|
2578
|
+
}).catch(() => {});
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
},
|
|
1525
2582
|
{
|
|
1526
2583
|
group: "sync",
|
|
1527
2584
|
name: "queues a platform thread's events in its sync's inbox once, and leases each after the one before is acked",
|