Public: anyone can read this; the crew can change it.
Talk on a phone, still wrong after #16552 landed: conversation history loads… #16768
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16560-talk-on-a-phone-still-wrong-after-16552 → main 0 commits fork 3 threads · 3 unresolved
1 file
changed +66
−0
test/talk-history-order.test.ts added +66
| @@ -0,0 +1,66 @@ | ||
| 1 | /** | |
| 2 | * A long Talk history reads oldest to newest (#16560), without a browser: the latest page is the | |
| 3 | * last fifty turns in order, Earlier is the fifty before them in order. The script is covered by | |
| 4 | * talk-phone.test.ts. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | import { promote } from "./helpers/members.ts"; | |
| 17 | ||
| 18 | quietLogs(); | |
| 19 | let dir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | let token: string; | |
| 23 | let userId: string; | |
| 24 | let id: string; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dir = await mkdtemp(join(tmpdir(), "forge-talk-order-")); | |
| 28 | app = createApp({ dataDir: dir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 31 | if (!made.ok) throw new Error(made.error); | |
| 32 | promote(app.db, made.value); | |
| 33 | userId = made.value.id; | |
| 34 | token = createSession(app.db, userId).token; | |
| 35 | const c = createConversation(app.db, userId); | |
| 36 | if (!c.ok) throw new Error(c.error); | |
| 37 | id = c.value.id; | |
| 38 | for (let i = 0; i < 120; i++) appendTurn(app.db, userId, id, { role: i % 2 === 0 ? "person" : "agent", text: `message ${i}` }); | |
| 39 | }, 30_000); | |
| 40 | afterAll(async () => { | |
| 41 | servers.stop(); | |
| 42 | app.close(); | |
| 43 | await rm(dir, { recursive: true, force: true }); | |
| 44 | }); | |
| 45 | ||
| 46 | const get = async (path: string): Promise<string> => (await fetch(`${servers.url}${path}`, { headers: { cookie: `forge_session=${token}` } })).text(); | |
| 47 | const earlierId = (page: string): string => new RegExp(`href="/talk/${id}\\?before=([^"]+)" data-earlier`).exec(page)?.[1] ?? ""; | |
| 48 | const logOf = (page: string): number[] => [...page.slice(page.indexOf('class="talk-log"')).matchAll(/message (\d+)/g)].map((m) => Number(m[1])); | |
| 49 | ||
| 50 | test("the latest page is 70..119 in order, and its Earlier link names the first of them", async () => { | |
| 51 | const page = await get(`/talk/${id}`); | |
| 52 | const nums = logOf(page); | |
| 53 | expect(nums[0]).toBe(70); | |
| 54 | expect(nums.at(-1)).toBe(119); | |
| 55 | expect(nums).toEqual([...nums].sort((a, b) => a - b)); | |
| 56 | expect(earlierId(page)).not.toBe(""); | |
| 57 | }); | |
| 58 | ||
| 59 | test("Earlier is 20..69 in order, and a page of its own still opens without the script", async () => { | |
| 60 | const first = earlierId(await get(`/talk/${id}`)); | |
| 61 | expect(first).not.toBe(""); | |
| 62 | const nums = logOf(await get(`/talk/${id}?before=${first}`)); | |
| 63 | expect(nums[0]).toBe(20); | |
| 64 | expect(nums.at(-1)).toBe(69); | |
| 65 | expect(nums).toEqual([...nums].sort((a, b) => a - b)); | |
| 66 | }); |
new above
offline
Duplicates a lookup the served page already gives. Take the id from the Earlier link in the page instead.