Public: anyone can read this; the crew can change it.
Game door: plain questions go to Talk at once, and continue until /forge clear #18055
Merged 14h 40m ago, live in production
sold/forge-talk → main 0 commits 2 threads · 2 unresolved
5 files
changed +220
−23
docs/features/games.md +1 −1
| @@ -92,7 +92,7 @@ A linked name that holds operator on the server it types on can also say: | ||
| 92 | 92 | |
| 93 | 93 | - `!forge give me a new void world with FAWE and bedwars`: planned like `create_server` (see New servers), and the plan's lines and memory math come back in chat, then "type !forge yes within 5 minutes". `!forge yes` commits that plan as the linked account, or says "The box changed since the preview; preview it again." when the repository moved; `!forge no` drops it. A plan answers only the same name on the same server. It changes the whole network, so it takes operator of the box, asked at the plan, at the yes and again right before the commit; operator of one server is refused. |
| 94 | 94 | - `!forge help`. |
| 95 | - `!forge <anything else>`: a new Talk conversation of the linked account. The crew's first answer comes back in chat (its first lines, then a link to the conversation): nothing the account could not read on the forge itself. | |
| 95 | - `!forge <anything else>`: a Talk conversation of the linked account. The crew's first answer comes back in chat (its first lines, then a link to the conversation): nothing the account could not read on the forge itself. Through the proxy's `/forge` the words go to Talk at once, with no confirmation first. The door has exactly the authority Talk has on the web, no more: a linked player is that account (the proxy checks the Minecraft account, and the link binds its UUID), and the crew's turn is the forge's own agent for that account, so the forge's one policy applies. Every `games` action but `list` (restart, start, settings, console, mods, servers), every admin-scope tool and every irreversible or outward action (release, archive, delete, secrets, tokens) is held as a confirm that nothing runs until the account says yes in Talk with its own session; the reply's last lines say "Held for your yes: <what it would do> [](<Talk link>)". The rest of what the account may do (close, assign, edit, merge) runs at once with a receipt and an Undo in Talk; the reply says "Done: <what> [](<link>)". The proxy's own confirmation (the player's code) stays for what the door itself does: linking, dropping a plan, building a new server. The player's next words continue the same conversation on that box, and the answer's last line is the link ("Open in Talk"). `/forge clear` ends it: the next words start a new one. Any role on the server may clear: it removes only that account's own pointer on that box, never a conversation or another account's. If the kept conversation is gone (archived or deleted), the next words start a new one and say so. | |
| 96 | 96 | |
| 97 | 97 | Through the proxy's `/forge` a linked account, with a role on the box or without, can also say `/forge status` (the version that runs and what the crew does, read as that account by the MCP tools `now` and `releases`) and `/forge servers` (the servers it has a role on: state, players, memory). They are not answered in chat yet. Tested on Paper 1.21.6 and Fabric 1.21.6, offline servers with no plugin that logs commands: a `tellraw` over RCON reached only its player, and neither stdout nor latest.log kept it. With the questions asked through `/forge`, they have their own limit: 30 a minute and 600 an hour an account, 60 a minute a box. A question asked through the proxy before the release that added `game_chat.door` stays in the 5 and 30 for its hour. A question in chat stays one of the 5 and 30. `status` and `servers` do not wait behind a plan; a question does. |
| 98 | 98 |
src/core/migration-pins/20261203100000-game-talk.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | ca8da090a6ae8570f85afa64ccd4555cb830fddedb31df3c48e564d31c3b8388 |
src/core/migrations/20261203100000-game-talk.ts added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | // The Talk conversation a linked player's plain words continue through the proxy's door (#18028), | |
| 2 | // one per box and account, until `/forge clear` or the conversation goes. Replaced by the next | |
| 3 | // conversation, so it cannot grow by repeats. | |
| 4 | export default ` | |
| 5 | CREATE TABLE game_talk ( | |
| 6 | box_id TEXT NOT NULL, | |
| 7 | user_id TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE, | |
| 8 | conversation TEXT NOT NULL, | |
| 9 | created_at TEXT NOT NULL, | |
| 10 | PRIMARY KEY (box_id, user_id) | |
| 11 | ) WITHOUT ROWID; | |
| 12 | `; |
src/games/chat.ts +67 −10
| @@ -25,8 +25,10 @@ | ||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | import type { App } from "../app.ts"; |
| 28 | import { waitingConfirms } from "../actions/conversation_confirms.ts"; | |
| 28 | 29 | import { talk } from "../actions/talk.ts"; |
| 29 | 30 | import { createConversation, listTurns } from "../core/conversations.ts"; |
| 31 | import { readReceipt } from "../crew/receipt.ts"; | |
| 30 | 32 | import { publicOrigin } from "../core/public_origin.ts"; |
| 31 | 33 | import { getUserById, isActive, type User } from "../core/users.ts"; |
| 32 | 34 | import { blockedBy, blockedText } from "../kernel/blocked.ts"; |
| @@ -224,7 +226,7 @@ const UNLINKED_HELP = [ | ||
| 224 | 226 | ]; |
| 225 | 227 | const OPERATOR_HELP = [ |
| 226 | 228 | "!forge give me a new void world with FAWE and bedwars: plans it, then !forge yes builds it.", |
| 227 | "!forge <anything else>: asks the crew; the answer comes here.", | |
| 229 | "!forge <anything else>: asks the crew; the answer comes here. !forge clear: ends that conversation.", | |
| 228 | 230 | "!forge no: drops a plan. !forge link <code>: links this name (a code from your forge settings).", |
| 229 | 231 | ]; |
| 230 | 232 | |
| @@ -437,7 +439,7 @@ function one( | ||
| 437 | 439 | } |
| 438 | 440 | // A question only reads (`ask.ts`), so a viewer may ask; the rest takes an operator. |
| 439 | 441 | const question = questionOf(words, service, serversSeen(app, user, box, compose)); |
| 440 | if (question === undefined && read === undefined && !help && !mayDo(role, "operator")) return refuse(user.id, "not an operator", `${user.username} is not an operator of ${service}.`); | |
| 442 | if (question === undefined && read === undefined && !help && lower !== "clear" && !mayDo(role, "operator")) return refuse(user.id, "not an operator", `${user.username} is not an operator of ${service}.`); | |
| 441 | 443 | const reads = read !== undefined || (door !== undefined && question !== undefined); |
| 442 | 444 | // The commands that ran (not the refusals) in the last minute and hour; full means wait until the |
| 443 | 445 | // oldest of them leaves the window. |
| @@ -461,7 +463,6 @@ function one( | ||
| 461 | 463 | } |
| 462 | 464 | // Kept with its audit row, whose outcome the job writes when it is done. |
| 463 | 465 | const later = (kind: "ask" | "read" | "plan" | "yes" | "talk", said: string, sha = ""): void => { |
| 464 | if (kind === "talk" && door !== undefined && confirmed === undefined) return askFirst(user.id, `Ask the crew: "${said}"?`, { action: "words", words: said }); | |
| 465 | 466 | audit(app, box, at, user.id, kind, said, "waiting", now); |
| 466 | 467 | db.query( |
| 467 | 468 | "INSERT INTO game_chat_job (box_id, service, player, user_id, kind, words, sha, origin, audit_id, created_at, ask_id) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, last_insert_rowid(), ?9, ?10)", |
| @@ -483,6 +484,11 @@ function one( | ||
| 483 | 484 | user.id, |
| 484 | 485 | ); |
| 485 | 486 | } |
| 487 | if (lower === "clear") { | |
| 488 | db.query("DELETE FROM game_talk WHERE box_id = ?1 AND user_id = ?2").run(box.id, user.id); | |
| 489 | audit(app, box, at, user.id, "clear", words, "cleared", now); | |
| 490 | return say(db, box, at, ["Cleared: your next words start a new conversation."], user.id); | |
| 491 | } | |
| 486 | 492 | if (lower === "no") { |
| 487 | 493 | if (door !== undefined && confirmed === undefined) return askFirst(user.id, "Drop the plan that is waiting?", { action: "words", words }); |
| 488 | 494 | db.query("DELETE FROM game_chat_pending WHERE box_id = ?1 AND player = ?2").run(box.id, player); |
| @@ -681,15 +687,30 @@ async function runJob(app: App, box: GameBox, job: Job): Promise<void> { | ||
| 681 | 687 | function ask(app: App, box: GameBox, job: Job, user: User): void { |
| 682 | 688 | const db = app.db; |
| 683 | 689 | db.transaction(() => { |
| 684 | const conversation = createConversation(db, user.id); | |
| 685 | if (!conversation.ok) | |
| 686 | return finish(app, box, job, "too many conversations", ["You hold the most conversations the forge keeps: archive one on /talk first."], "red"); | |
| 687 | const sent = talk(app, user, job.words, [], "inject", conversation.value.id); | |
| 690 | // Through the proxy the player's words continue their conversation for this box until they clear it. | |
| 691 | const door = job.ask_id !== ""; | |
| 692 | const kept = door | |
| 693 | ? db.query<{ conversation: string }, [string, string]>("SELECT conversation FROM game_talk WHERE box_id = ?1 AND user_id = ?2").get(box.id, user.id)?.conversation | |
| 694 | : undefined; | |
| 695 | const into = (id: string) => talk(app, user, job.words, [], "inject", id); | |
| 696 | let id = kept; | |
| 697 | let sent = kept === undefined ? undefined : into(kept); | |
| 698 | const gone = sent !== undefined && !sent.ok && sent.error === "not_found"; | |
| 699 | if (gone) sent = undefined; | |
| 700 | if (sent === undefined) { | |
| 701 | const conversation = createConversation(db, user.id); | |
| 702 | if (!conversation.ok) | |
| 703 | return finish(app, box, job, "too many conversations", ["You hold the most conversations the forge keeps: archive one on /talk first."], "red"); | |
| 704 | id = conversation.value.id; | |
| 705 | sent = into(id); | |
| 706 | } | |
| 688 | 707 | if (!sent.ok) return finish(app, box, job, sent.error, [`The crew could not take it: ${sent.error}.`], "red"); |
| 689 | const waiting: Job = { ...job, kind: "reply", conversation: conversation.value.id }; | |
| 708 | if (door) | |
| 709 | db.query("INSERT OR REPLACE INTO game_talk (box_id, user_id, conversation, created_at) VALUES (?1, ?2, ?3, ?4)").run(box.id, user.id, id!, new Date().toISOString()); | |
| 710 | const waiting: Job = { ...job, kind: "reply", conversation: id! }; | |
| 690 | 711 | db.query("UPDATE game_chat_job SET kind = 'reply', conversation = ?2 WHERE id = ?1").run(job.id, waiting.conversation); |
| 691 | 712 | db.query("UPDATE game_chat SET outcome = ?2 WHERE id = ?1").run(job.audit_id, sent.value.how); |
| 692 | say(app.db, box, { service: job.service, player: job.player, ask: job.ask_id }, [`Asked the crew: the answer comes here and at ${job.origin}/talk/${waiting.conversation}`], user.id); | |
| 713 | say(app.db, box, { service: job.service, player: job.player, ask: job.ask_id }, [`${gone ? "Your earlier conversation is gone, so this is a new one. " : ""}Asked the crew: the answer comes here and at ${job.origin}/talk/${waiting.conversation}`], user.id); | |
| 693 | 714 | const { live } = workersOf(app); |
| 694 | 715 | if (sent.value.done === undefined) return; |
| 695 | 716 | live.add(job.id); |
| @@ -705,6 +726,37 @@ function ask(app: App, box: GameBox, job: Job, user: User): void { | ||
| 705 | 726 | })(); |
| 706 | 727 | } |
| 707 | 728 | |
| 729 | /** | |
| 730 | * What the crew's turn left that the player must know, one line each: the first confirm still | |
| 731 | * waiting for their yes (the forge holds games, admin and irreversible actions, and says so here), | |
| 732 | * and the first reversible change it did at once, with its receipt (its Undo is in Talk). | |
| 733 | */ | |
| 734 | function closing(app: App, job: Job, link: string): string[] { | |
| 735 | const user = getUserById(app.db, job.user_id); | |
| 736 | if (user === undefined) return []; | |
| 737 | const out: string[] = []; | |
| 738 | const turns = listTurns(app.db, job.user_id, job.conversation); | |
| 739 | if (turns.ok) { | |
| 740 | const last = turns.value.map((t) => t.role).lastIndexOf("person"); | |
| 741 | for (const t of turns.value.slice(last + 1)) { | |
| 742 | if (t.role !== "tool" || t.replaced) continue; | |
| 743 | try { | |
| 744 | const made = JSON.parse(t.text) as { direct?: unknown; receipt?: unknown }; | |
| 745 | const r = made.direct === true ? readReceipt(made.receipt) : undefined; | |
| 746 | if (r !== undefined) { | |
| 747 | out.push(`Done: ${r.verb} ${r.object}.${r.undo === undefined ? "" : ` [Undo](${link})`}`); | |
| 748 | break; | |
| 749 | } | |
| 750 | } catch { | |
| 751 | // A tool turn that is not JSON has no receipt. | |
| 752 | } | |
| 753 | } | |
| 754 | } | |
| 755 | const held = waitingConfirms({ app }, user)[0]; | |
| 756 | if (held !== undefined) out.push(`Held for your yes: ${held.does} [Answer it](${link})`); | |
| 757 | return out; | |
| 758 | } | |
| 759 | ||
| 708 | 760 | /** The crew's answer in game: its first lines, then the link. Without one, the link alone. */ |
| 709 | 761 | function answer(app: App, box: GameBox, job: Job): void { |
| 710 | 762 | const link = `${job.origin}/talk/${job.conversation}`; |
| @@ -712,6 +764,11 @@ function answer(app: App, box: GameBox, job: Job): void { | ||
| 712 | 764 | .split("\n") |
| 713 | 765 | .map((l) => l.trim()) |
| 714 | 766 | .filter(Boolean); |
| 715 | if (text.length === 0) return finish(app, box, job, "", [`No answer came: see ${link}`]); | |
| 767 | const more = job.ask_id === "" ? [] : closing(app, job, link); | |
| 768 | if (text.length === 0) return finish(app, box, job, "", [...more, `No answer came: see ${link}`]); | |
| 769 | // Through the proxy the link is always the last line. | |
| 770 | if (job.ask_id !== "") { | |
| 771 | return finish(app, box, job, "", [...text.slice(0, LINES_OUT - 1 - more.length), ...more, `[Open in Talk](${link})`], "white"); | |
| 772 | } | |
| 716 | 773 | finish(app, box, job, "", [...text.slice(0, LINES_OUT - 1), ...(text.length > LINES_OUT - 1 ? [`More at ${link}`] : [])], "white"); |
| 717 | 774 | } |
test/game-door.test.ts +139 −12
| @@ -9,14 +9,17 @@ import { tmpdir } from "node:os"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import { appendTurn } from "../src/core/conversations.ts"; | |
| 13 | import { hold, waitingFor } from "../src/core/fence.ts"; | |
| 12 | 14 | import { createSession } from "../src/core/sessions.ts"; |
| 15 | import { mintViaToken } from "../src/core/via_token.ts"; | |
| 13 | 16 | import { createUser, type User } from "../src/core/users.ts"; |
| 14 | 17 | import { chatLog, gameAsk, gameChat, linksOf, newLinkCode, runChat, typedAs } from "../src/games/chat.ts"; |
| 15 | 18 | import doorMigration from "../src/core/migrations/20261203042200-game-chat-door.ts"; |
| 16 | 19 | import { readCompose } from "../src/games/compose.ts"; |
| 17 | 20 | import { CONFIRM_MS, toldTo } from "../src/games/door.ts"; |
| 18 | import { boxNamed, createGameBox, type GameBox } from "../src/games/store.ts"; | |
| 19 | import { forgeHttp } from "../src/http/server.ts"; | |
| 21 | import { boxNamed, createGameBox, grant, type GameBox } from "../src/games/store.ts"; | |
| 22 | import { forgeHttp, serve } from "../src/http/server.ts"; | |
| 20 | 23 | import { chatAged } from "./helpers/game-chat-clock.ts"; |
| 21 | 24 | import { quietLogs } from "./helpers/globals.ts"; |
| 22 | 25 | import { pollUntil } from "./helpers/poll.ts"; |
| @@ -92,6 +95,11 @@ beforeAll(async () => { | ||
| 92 | 95 | .run(box.id, JSON.stringify([{ name: "ada", uuid: ADA }])); |
| 93 | 96 | }, 30_000); |
| 94 | 97 | beforeEach(() => { |
| 98 | // The crew's turns are not run here: nothing of one is left for the next test. | |
| 99 | app.db.query("DELETE FROM game_chat_job").run(); | |
| 100 | app.db.query("DELETE FROM game_talk").run(); | |
| 101 | app.db.query("DELETE FROM conversation_held").run(); | |
| 102 | app.db.query("DELETE FROM game_command").run(); | |
| 95 | 103 | now = Date.now(); |
| 96 | 104 | // Past what the test before spent of the account's hour. |
| 97 | 105 | anHourOn(); |
| @@ -146,8 +154,8 @@ test("status is the forge's own read, as the linked account; servers names those | ||
| 146 | 154 | const [servers] = await send([request("Servers")]); |
| 147 | 155 | expect(servers!.text).toBe("hub: running, 1 player"); |
| 148 | 156 | expect(kinds(2)).toEqual(["read", "read"]); |
| 149 | // Anything more than the one word is still a question or the crew's. | |
| 150 | expect((await send([request("status of the hub")]))[0]).toMatchObject({ confirm: true }); | |
| 157 | // Anything more than the one word is the crew's, and goes to Talk at once. | |
| 158 | expect((await send([request("status of the hub")]))[0]).toMatchObject({ confirm: false }); | |
| 151 | 159 | // Never in chat: a server's log may keep what it is told to show. |
| 152 | 160 | gameChat(app, box, { hub: ["[12:00:01] [Async Chat Thread - #3/INFO]: <ada> !forge status"] }, COMPOSE, "http://forge.test", now); |
| 153 | 161 | expect(kinds(1)).toEqual(["talk"]); |
| @@ -248,32 +256,151 @@ test("every request in a sync is answered, a repeated refusal too", async () => | ||
| 248 | 256 | }); |
| 249 | 257 | |
| 250 | 258 | test("crew work starts only on the same player's confirmation, on the same box, once, in time", async () => { |
| 251 | const before = request("when does the hub restart?"); | |
| 252 | expect(await send([before])).toEqual([{ n: expect.any(Number), id: before.id, uuid: ADA, text: 'Ask the crew: "when does the hub restart?"?', confirm: true }]); | |
| 259 | // The plan's own drop asks first: the same confirmation as any other the proxy asks for. | |
| 260 | const before = request("no"); | |
| 261 | expect(await send([before])).toEqual([{ n: expect.any(Number), id: before.id, uuid: ADA, text: "Drop the plan that is waiting?", confirm: true }]); | |
| 253 | 262 | const refused = "That is no longer waiting for your yes: ask again."; |
| 254 | 263 | const confirm = (more: Record<string, unknown> = {}) => request("yes", { confirms: before.id, ...more }); |
| 255 | 264 | expect((await send([confirm({ uuid: EVE, name: "eve" })]))[0]!.text).toBe(refused); |
| 256 | 265 | expect((await send([confirm()], other))[0]!.text).toBe(refused); |
| 257 | 266 | expect((await send([confirm({ confirms: crypto.randomUUID() })]))[0]!.text).toBe(refused); |
| 258 | 267 | expect(kinds(1)).toEqual(["asked"]); |
| 259 | // In time: queued without running the crew. | |
| 260 | gameAsk(app, box, [confirm()], COMPOSE, "http://forge.test", now); | |
| 261 | expect(jobs()).toBe(1); | |
| 262 | expect(kinds(1)).toEqual(["talk"]); | |
| 263 | app.db.query("DELETE FROM game_chat_job").run(); | |
| 268 | // In time: done once. | |
| 269 | expect((await send([confirm()]))[0]!.text).toBe("Dropped."); | |
| 270 | expect(kinds(1)).toEqual(["no"]); | |
| 264 | 271 | expect((await send([confirm()]))[0]!.text).toBe(refused); |
| 265 | 272 | // The confirmed request sent again by the box starts nothing over. |
| 266 | 273 | expect(await send([before])).toEqual([]); |
| 267 | 274 | expect((await send([confirm()]))[0]!.text).toBe(refused); |
| 268 | 275 | |
| 269 | 276 | anHourOn(); |
| 270 | const late = request("when does the hub restart?"); | |
| 277 | const late = request("no"); | |
| 271 | 278 | await send([late]); |
| 272 | 279 | app.db.query("UPDATE game_ask SET shown_at = ?2 WHERE id = ?1").run(late.id, new Date(now - CONFIRM_MS - 1).toISOString()); |
| 273 | 280 | expect((await send([request("yes", { confirms: late.id })]))[0]!.text).toBe(refused); |
| 274 | 281 | expect(jobs()).toBe(0); |
| 275 | 282 | }); |
| 276 | 283 | |
| 284 | /** What the player is told for `words`, all lines. */ | |
| 285 | const toldFor = async (words: string): Promise<string[]> => (await send([request(words)])).map((t) => t.text); | |
| 286 | const conversation = (user = ada): string | undefined => app.db.query<{ conversation: string }, [string]>("SELECT conversation FROM game_talk WHERE user_id = ?1").get(user.id)?.conversation; | |
| 287 | const commands = (): number => app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM game_command").get()!.n; | |
| 288 | ||
| 289 | test("plain words reach Talk at once, the next words continue that conversation, and /forge clear ends it", async () => { | |
| 290 | expect(conversation()).toBeUndefined(); | |
| 291 | const first = await send([request("why is the hub slow?")]); | |
| 292 | expect(first.map((t) => t.confirm)).not.toContain(true); | |
| 293 | expect(first[0]!.text).toStartWith("Asked the crew"); | |
| 294 | const one = conversation(); | |
| 295 | expect(one).toBeDefined(); | |
| 296 | anHourOn(); | |
| 297 | expect((await toldFor("and what about survival?"))[0]).toStartWith("Asked the crew"); | |
| 298 | expect(conversation()).toBe(one); | |
| 299 | anHourOn(); | |
| 300 | expect((await toldFor("clear"))[0]).toStartWith("Cleared"); | |
| 301 | expect(conversation()).toBeUndefined(); | |
| 302 | anHourOn(); | |
| 303 | await toldFor("is it still slow?"); | |
| 304 | expect(conversation()).not.toBe(one); | |
| 305 | expect(kinds(8)).toContain("clear"); | |
| 306 | }, 30_000); | |
| 307 | ||
| 308 | test("a change in any phrasing goes to Talk as words, and the door itself changes nothing: no game command is queued", async () => { | |
| 309 | for (const words of ["can you restart the hub", "I want survival wiped", "gamemode creative"]) { | |
| 310 | anHourOn(); | |
| 311 | const told = await send([request(words)]); | |
| 312 | expect(told.map((t) => t.confirm), words).not.toContain(true); | |
| 313 | expect(told[0]!.text, words).toStartWith("Asked the crew"); | |
| 314 | expect(commands(), words).toBe(0); | |
| 315 | } | |
| 316 | }); | |
| 317 | ||
| 318 | test("what a crew turn does for a game player: the games tool and an admin write are held, never run (the forge's one policy, as in Talk)", async () => { | |
| 319 | await toldFor("restart the hub"); | |
| 320 | const id = conversation()!; | |
| 321 | const via = `conversation:${id}`; | |
| 322 | const minted = mintViaToken(app.db, ada.id, via, "", new Date(Date.now() + 10 * 60_000).toISOString()); | |
| 323 | if (!minted.ok) throw new Error(minted.error); | |
| 324 | const servers = await serve(app); | |
| 325 | const tool = async (name: string, args: Record<string, unknown>) => { | |
| 326 | const res = await fetch(`${servers.url}/mcp`, { | |
| 327 | method: "POST", | |
| 328 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${minted.value.token}` }, | |
| 329 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }), | |
| 330 | }); | |
| 331 | const body = (await res.json()) as { result?: { content?: { text?: string }[]; isError?: boolean } }; | |
| 332 | return JSON.parse(body.result?.content?.[0]?.text ?? "{}") as Record<string, unknown>; | |
| 333 | }; | |
| 334 | try { | |
| 335 | const waiting = () => waitingFor(app.db, ada.id).length; | |
| 336 | for (const args of [ | |
| 337 | { action: "power", box: "mc", service: "hub", kind: "restart" }, | |
| 338 | { action: "power", box: "mc", service: "hub", kind: "start" }, | |
| 339 | { action: "env", box: "mc", service: "hub", key: "MEMORY", value: "1G" }, | |
| 340 | { action: "console", box: "mc", service: "hub", text: "gamemode creative ada" }, | |
| 341 | ]) { | |
| 342 | const before = waiting(); | |
| 343 | const said = await tool("games", args); | |
| 344 | expect(said["needs_confirm"], JSON.stringify(args)).toEqual(expect.any(String)); | |
| 345 | expect(waiting()).toBe(before + 1); | |
| 346 | } | |
| 347 | expect(commands()).toBe(0); | |
| 348 | // An admin-scope write. | |
| 349 | const before = waiting(); | |
| 350 | expect((await tool("release_now", {}))["needs_confirm"]).toEqual(expect.any(String)); | |
| 351 | expect(waiting()).toBe(before + 1); | |
| 352 | expect(commands()).toBe(0); | |
| 353 | // A read is not held. | |
| 354 | expect((await tool("games", { action: "list" }))["needs_confirm"]).toBeUndefined(); | |
| 355 | } finally { | |
| 356 | servers.stop(); | |
| 357 | } | |
| 358 | }, 30_000); | |
| 359 | ||
| 360 | test("the reply ends with a held action and a reversible change it made, each said, and the link last", async () => { | |
| 361 | await toldFor("close the first issue and archive the repo"); | |
| 362 | const id = conversation()!; | |
| 363 | appendTurn(app.db, ada.id, id, { role: "agent", text: "I closed it and asked about archiving." }); | |
| 364 | appendTurn(app.db, ada.id, id, { role: "tool", text: JSON.stringify({ direct: true, tool: "close", done: true, says: "closed", receipt: { verb: "Closed", object: "ada/net#1", href: "/ada/net/issues/1", undo: { label: "Undo", tool: "close", args: {}, expect: {} } } }) }); | |
| 365 | hold(app.db, `conversation:${id}`, ada.id, "archive", { repo: "ada/net", archived: true, dryRun: false }); | |
| 366 | const all = (await send([])).map((t) => t.text); | |
| 367 | expect(all.join("\n")).toContain("Done: Closed ada/net#1. [Undo](http://forge.test/talk/"); | |
| 368 | expect(all.join("\n")).toContain("Held for your yes: Archive ada/net. [Answer it](http://forge.test/talk/"); | |
| 369 | expect(all.join("\n")).toEndWith(`[Open in Talk](http://forge.test/talk/${id})`); | |
| 370 | }, 30_000); | |
| 371 | ||
| 372 | test("clear touches only the account's own conversation: a viewer's and a no-role account's cannot reach another's", async () => { | |
| 373 | const person = async (username: string, uuid: string, role: "viewer" | "none") => { | |
| 374 | const made = await createUser(app.db, { username, email: `${username}@f.test`, password: "a-good-passphrase", origin: "seed", trusted: true }); | |
| 375 | if (!made.ok) throw new Error(made.error); | |
| 376 | app.db.query("INSERT INTO game_link (box_id, player, user_id, uuid, created_at) VALUES (?1, ?2, ?3, ?4, '')").run(box.id, `${username}_mc`, made.value.id, uuid); | |
| 377 | if (role !== "none") grant(app.db, box.id, made.value.id, role); | |
| 378 | return { user: made.value, kit: { uuid, name: `${username}_mc` } }; | |
| 379 | }; | |
| 380 | const viewer = await person("vi", "00000000-0000-4000-8000-0000000000a1", "viewer"); | |
| 381 | const nobody = await person("nr", "00000000-0000-4000-8000-0000000000a2", "none"); | |
| 382 | const mine = (user: User, id: string) => app.db.query("INSERT INTO game_talk (box_id, user_id, conversation, created_at) VALUES (?1, ?2, ?3, '')").run(box.id, user.id, id); | |
| 383 | mine(ada, "conv-ada"); | |
| 384 | mine(viewer.user, "conv-viewer"); | |
| 385 | mine(nobody.user, "conv-nobody"); | |
| 386 | // The no-role account is refused, and nothing of anyone's goes. | |
| 387 | expect((await send([request("clear", nobody.kit)]))[0]!.text).toContain("has no role"); | |
| 388 | expect(conversation(nobody.user)).toBe("conv-nobody"); | |
| 389 | // A viewer's clear ends the viewer's own pointer and no other. | |
| 390 | expect((await send([request("clear", viewer.kit)]))[0]!.text).toStartWith("Cleared"); | |
| 391 | expect(conversation(viewer.user)).toBeUndefined(); | |
| 392 | expect(conversation(ada)).toBe("conv-ada"); | |
| 393 | expect(conversation(nobody.user)).toBe("conv-nobody"); | |
| 394 | }); | |
| 395 | ||
| 396 | test("when the kept conversation is gone, the next words start a new one and say so", async () => { | |
| 397 | app.db.query("INSERT INTO game_talk (box_id, user_id, conversation, created_at) VALUES (?1, ?2, 'gone-conversation', '')").run(box.id, ada.id); | |
| 398 | const told = (await toldFor("why is the hub slow?"))[0]!; | |
| 399 | expect(told).toStartWith("Your earlier conversation is gone, so this is a new one. Asked the crew"); | |
| 400 | expect(conversation()).toBeDefined(); | |
| 401 | expect(conversation()).not.toBe("gone-conversation"); | |
| 402 | }); | |
| 403 | ||
| 277 | 404 | test("a typed yes builds nothing; the plan's own confirmation does, and chat's yes is not it", async () => { |
| 278 | 405 | const plan = request("give me a flat world called build"); |
| 279 | 406 | const [shown] = await send([plan]); |
new above
offline
This says 'archived or deleted' starts a new conversation.
ask()handles onlynot_found, so an archived one is continued silently. Make the code match (preferred, with a test that archives the kept conversation) or change the words.