Skip to content

Commit 40f59a1

Browse files
authored
bug(host): a trimmed room log makes read_group_chat report the wrong total (#2839)
Fixes #2838 Owner: Dev-1 Reviewer: Birfy Written-by: Dev-1 Bot: Dev-1 Claim-Id: 63eb2d9dca664fab94de573fdd70b3e0 Risk tier: T2 Base: e16c1d3 ## What happened `read_group_chat` (`core/src/host/groups.js`) built its `Latest in …` header from `kept.length`, which is only what the room log still holds. The store trims at `ROOM_LOG_MAX` (60 here, 200 in `room-membership.js`) while `room.seq` keeps counting every line ever appended, so a room that had said 500 lines read `Latest in "Ops" (newest 30 of 60, oldest first):` and the 440 lines the trim threw away disappeared from the count — the lines a reader asking "didn't we decide X?" is looking for. The same arithmetic ignored the reader's floor: a reader joining at line 300 of that room was told `newest 30 of 60` when 201 lines were said since its floor (`500 − 299`), so the header under-reported on both axes at once. ## Expected, and what the tip does - `dropped = max(0, room.seq − room.log.length)`; `total = kept.length + max(0, dropped − max(0, from − 1))`; `older = total − lines.length`. A floorless reader of a 500-line room reads `newest 30 of 500`; a reader at floor 300 reads `newest 30 of 201`. - `ROOM_LOG_MAX` stays **60** and `room-membership.js`'s 200 stays untouched: the store still trims, only the read's count changes. - The header still prints only when something is left out; an at-cap room (`newest 30 of 60`) and an under-cap room read byte-identically, and a legacy log without `seq` is normalised by `ensureRoomLog` (`seq = log.length`) so it counts exactly as today. ## Red first On `e16c1d3c`, `groups.js` untouched, only `core/test/room-read-trimmed-count.test.js` added; two runs, identical apart from temp paths: ``` # tests 5 / # pass 3 / # fail 2 not ok - the total counts what the log still holds, not what the room said: Latest in "Ops" (newest 30 of 60, oldest first): not ok - the total ignores the reader's floor: Latest in "Ops" (newest 30 of 60, oldest first): ``` The three guards (late joiner at floor 480 → 21 lines, no header; room exactly at the cap → `newest 30 of 60`; room under the cap → byte-identical) were green at the base and stay green. After the fix the same file is `5/5`. ## What I ran at this tip - `core/test/room-read-trimmed-count.test.js`: `5/5` green. - Neighbourhood — 29 `room-*` / `group*` / `remote-room` / `link-room-title` / `face-room-hidden` / `mock-group-roster` / `details-group-*` suites: `360/360`. - Full core suite: `3091/3091`. - `TZ=UTC npm run verify` at the tip: exit 0 — core 3091/3091, social 619, tree 149, timeline 172, workflow 528, project 147, scripts+policy 673, interop 37, live-e2e 34, core lint 88 warnings / 0 errors, `arch-docs: OK (6 changed file(s))`, `10 patches apply cleanly in order`, canonical no-op. - `ARCH_DOCS_BASE=e16c1d3c npm run arch-docs` on the committed tree: `OK (6 changed file(s))`. Not run: `build-client` (no `core/src/client/` file changes, so `0008` and `core/client.js` are untouched), the smoke test (no `index.js` / host boot change), and the merge-queue checks (CI runs them). ## Generated artifacts `node scripts/ds-bot-patches.mjs generate` rewrites exactly two files on this base: - `patches/ds-bot/0012-room-membership.patch` — **+10/−3** (181,726 → 182,325 bytes), carrying the `groups.js` hunk. - `patches/ds-bot/files/test/room-read-trimmed-count.test.js` — new mirror, 97 lines / 5,710 bytes. The other nine patches are byte-identical to `e16c1d3c`. `check` says `ok 10 patches apply cleanly in order` / `ok core/ equals ds-bot/ + patches/ds-bot/`, and `canonical` says `ok patches/ds-bot/ is what generate writes (generate is a no-op)`. ## Scope 6 files, +215/−6: | file | +/− | | --- | --- | | `core/src/host/groups.js` | +9/−2 | | `core/test/room-read-trimmed-count.test.js` | +97/−0 (new) | | `patches/ds-bot/0012-room-membership.patch` | +10/−3 (generated) | | `patches/ds-bot/files/test/room-read-trimmed-count.test.js` | +97/−0 (generated) | | `docs/subsystems/core-host.md` | +1/−1 (the `#2780` sentence now names the trimmed case and the new test) | | `changelog.d/2838-room-read-trimmed-count.fixed.md` | +1/−0 | Tier basis: `risk-tier: T2; basis: core/src/host/groups.js=T2, changelog.d/2838-room-read-trimmed-count.fixed.md=T1, core/test/room-read-trimmed-count.test.js=T1, patches/ds-bot/0012-room-membership.patch=T1, patches/ds-bot/files/test/room-read-trimmed-count.test.js=T1, docs/subsystems/core-host.md=T0` (111 changed lines in the 4 non-generated files; 2 generated files not counted). T2, so it needs a Verdict PASS at this tip. ## Known boundary The fix is the read's count only: the store keeps trimming at 60 / 200 (raising them would change what is stored and shipped), and the lines themselves are still gone from the transcript. A legacy room with no `seq` is normalised on read, so its count cannot recover lines trimmed before this change. No retry, caching or backfill is added. Verified commit: 11a84e958b89d2adeb2adce8aef9d7cdcecca5e0 (tree 65c2478); the pushed head below is that tree rebuilt on live main. ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 2839, "claim": "Dev-1", "issue": 2838, "summary": "The group read's header counted only the lines the log still holds, so a room that had said 500 lines read `newest 30 of 60`; it now counts the dropped lines from the reader's floor, and a reader at line 300 reads `newest 30 of 201`. `ROOM_LOG_MAX` (60) and the membership store's 200 are unchanged, and a room that never trimmed reads byte-identically. The new test fails 2 of 5 on the old code and passes at this tip, the room/group neighbourhood is 360/360 and `verify` is green.", "files": [ "core/src/host/groups.js", "core/test/room-read-trimmed-count.test.js", "patches/ds-bot/0012-room-membership.patch", "patches/ds-bot/files/test/room-read-trimmed-count.test.js", "docs/subsystems/core-host.md", "changelog.d/2838-room-read-trimmed-count.fixed.md" ], "checks": { "ran": "TZ=UTC npm run verify", "result": "green", "at": "f67e2b07f67d26079b61e2be7aaafbd70ccf4a8c" }, "next": "none — ready for a Verdict PASS at this tip" } ``` <!-- /flybot:checkpoint -->
1 parent 9b1433f commit 40f59a1

6 files changed

Lines changed: 215 additions & 6 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`read_group_chat` now counts the lines the room said, not only the lines its log still holds: a room that said 500 lines and keeps the newest 60 reads `Latest in "Ops" (newest 30 of 500, oldest first):` instead of `newest 30 of 60`, and a reader at floor line 300 reads `newest 30 of 201`. A room that never trimmed reads byte-identically, and the caps (`ROOM_READ_MAX` 30, `ROOM_LOG_MAX` 60, the membership store's 200) are unchanged. See [#2838](https://github.com/ThinkFlowLab/FlyBot/issues/2838).

‎core/src/host/groups.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,15 @@ export function install(rt) {
10491049
const lines = kept.slice(-ROOM_READ_MAX)
10501050
if (lines.length === 0) return `"${room.name}" has no messages yet.`
10511051
// A cut read says how much it left out, so a missing message does not read as never said (#2780).
1052-
const older = kept.length - lines.length
1053-
return `Latest in "${room.name}" (${older > 0 ? `newest ${lines.length} of ${kept.length}, ` : ''}oldest first):\n${transcript(lines)}`
1052+
// `kept.length` is only what the log still holds: the store is capped (60 here, 200 in
1053+
// room-membership.js) while `room.seq` counts every line ever appended, so a room that had
1054+
// said 500 lines read as "newest 30 of 60" with 440 of them silently gone (#2838). The
1055+
// dropped lines sit below the oldest retained one, so they count from the reader's floor to
1056+
// that point, never the lines before the reader joined.
1057+
const dropped = Math.max(0, (room.seq ?? 0) - (room.log ?? []).length)
1058+
const total = kept.length + Math.max(0, dropped - Math.max(0, from - 1))
1059+
const older = total - lines.length
1060+
return `Latest in "${room.name}" (${older > 0 ? `newest ${lines.length} of ${total}, ` : ''}oldest first):\n${transcript(lines)}`
10541061
},
10551062
}))
10561063

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// P-684: a busy room's read counts what the disk still holds, not what the room said. `room.log` is
2+
// capped at ROOM_LOG_MAX (60; 200 from room-membership.js) while `room.seq` keeps counting every line
3+
// ever appended, so `kept.length` is a window — yet the header printed it as the total, telling a Bot
4+
// `newest 30 of 60` for a room that had said 500 lines.
5+
import assert from 'node:assert/strict'
6+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
7+
import { tmpdir } from 'node:os'
8+
import { join } from 'node:path'
9+
import { test } from 'node:test'
10+
import { createRuntime, provideFlyBot } from '../index.js'
11+
import { fakeContext } from './fake-ctx.js'
12+
13+
const T0 = 1_760_000_000_000
14+
const line = (seq, who, text) => ({ seq, who, text, time: T0 + seq * 1000 })
15+
const lines = (count, from = 1) => Array.from({ length: count }, (_, i) => line(from + i, (from + i) % 2 === 0 ? 'Chief' : 'Writer', `message ${from + i}: the merge queue slipped again`))
16+
const shownLines = out => out.split('\n').filter(l => /^(Chief|Writer): /.test(l))
17+
const seat = (id, joinedSeq) => ({ kind: 'bot', id, role: id === 'a' ? 'admin' : 'member', displayName: id === 'a' ? 'Chief' : 'Writer', joinedSeq, joinedAt: T0 })
18+
19+
async function start(t, log, room = {}) {
20+
const home = mkdtempSync(join(tmpdir(), 'ds-bot-p684-'))
21+
const seed = {
22+
version: 1,
23+
mainBotIds: ['a'],
24+
bots: {
25+
a: { id: 'a', name: 'Chief', role: 'Boss', sessionId: 'a', createdAt: 1 },
26+
b: { id: 'b', name: 'Writer', role: 'Write', sessionId: 'b', createdAt: 2 },
27+
},
28+
rooms: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b'], mode: 'admin', admin: 'a', named: true, sessions: { a: 'ga', b: 'gb' }, log, seq: (log.at(-1)?.seq ?? 0), seen: {}, ...room } },
29+
agents: {},
30+
exchanges: [],
31+
exchangeTurns: {},
32+
questions: {},
33+
prefs: {},
34+
revision: 0,
35+
}
36+
writeFileSync(join(home, 'state.json'), JSON.stringify(seed))
37+
const ctx = fakeContext()
38+
const agentOf = id => ({ session: { id, seq: 0, deriveMessages: () => [] }, calls: [], inbox: { nextStep: [], nextTurn: [], remove: () => false }, followup: () => {}, steer: () => {}, cancel() {} })
39+
Object.assign(ctx, {
40+
llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },
41+
workspaceRegistry: { get: () => undefined, resolveByPath: async () => undefined, create: async path => ({ id: 'w1', path }), archiveSession: async () => {} },
42+
sessionController: { create: async () => ({ sessionId: 's1' }), resolveAgent: async id => ({ agent: agentOf(id) }), selectModel: async () => {}, page: async () => ({ records: [], hasMore: false }) },
43+
sessionTitle: { rename: async () => {} },
44+
sessions: { flush: async () => {} },
45+
})
46+
const rt = createRuntime(ctx, { home })
47+
provideFlyBot(ctx, rt.flybot)
48+
t.after(async () => {
49+
await ctx.dispose()
50+
rmSync(home, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 })
51+
})
52+
const tool = (name, args, sessionId) => ctx.registeredTools.get(name).execute(args, { agent: { id: sessionId } })
53+
await tool('list_bots', {}, 'a')
54+
return { rt, tool }
55+
}
56+
57+
// RED today: 500 lines were said, the cap kept the newest 60, and the read calls the kept 60 the total.
58+
test('P-684: a trimmed room read reports the lines the room said, not the lines it kept', async (t) => {
59+
const host = await start(t, lines(60, 441), { seq: 500 })
60+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
61+
assert.equal(shownLines(out).length, 30)
62+
assert.match(out, /^Latest in "Ops" \(newest 30 of 500, oldest first\):$/m, `the total counts what the log still holds, not what the room said: ${out.split('\n')[0]}`)
63+
assert.match(out, /^(Chief|Writer): message 500: /m, 'the newest line is still shown')
64+
})
65+
66+
// RED today: the hidden lines between the reader's floor and the oldest retained line are part of the
67+
// total, but the lines the reader joined after are not.
68+
test('P-684: the total is counted from the reader\'s floor, not from the start of the room', async (t) => {
69+
const host = await start(t, lines(60, 441), { seq: 500, participants: [seat('a', 0), seat('b', 300)] })
70+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
71+
assert.equal(shownLines(out).length, 30)
72+
assert.match(out, /^Latest in "Ops" \(newest 30 of 201, oldest first\):$/m, `the total ignores the reader's floor: ${out.split('\n')[0]}`)
73+
})
74+
75+
// GREEN today, must stay: a reader whose floor is above every dropped line sees all of its window, so
76+
// there is nothing to report as left out.
77+
test('P-684 guard: a late joiner in a trimmed room is not told about lines it joined after', async (t) => {
78+
const host = await start(t, lines(60, 441), { seq: 500, participants: [seat('a', 0), seat('b', 480)] })
79+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
80+
assert.equal(shownLines(out).length, 21)
81+
assert.doesNotMatch(out, /newest \d+ of \d+/)
82+
})
83+
84+
// GREEN today, must stay: a log that reached the cap without dropping a line still counts its own 60.
85+
test('P-684 guard: a room at exactly the cap is unchanged', async (t) => {
86+
const host = await start(t, lines(60))
87+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
88+
assert.match(out, /^Latest in "Ops" \(newest 30 of 60, oldest first\):$/m)
89+
})
90+
91+
// GREEN today, must stay: a room under the cap reads exactly as the uncut room it is.
92+
test('P-684 guard: a room under the cap is byte-identical', async (t) => {
93+
const said = lines(20)
94+
const host = await start(t, said)
95+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
96+
assert.equal(out, `Latest in "Ops" (oldest first):\n${said.map(l => `${l.who}: ${l.text}`).join('\n')}`)
97+
})

‎docs/subsystems/core-host.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ has lines (#2790, `core/test/room-read-floor-clamp.test.js`).
433433

434434
### Group reads say what a cap left out (#2780)
435435

436-
- `read_group_chat` shows at most `ROOM_READ_MAX` (30) of the room lines visible to the caller, the newest ones, and the cut used to be silent: `Latest in "<room>" (oldest first):` printed as if those 30 were the whole log, so a Bot asked "didn't we decide X?" read a truncated log as the whole log — the same failure #1906 fixed for the own-chat read. The header now names the cut, `Latest in "<room>" (newest 30 of 45, oldest first):`, and a read that fits the cap stays byte-identical; lines before the member's `joinedSeq` are not counted as left out. Covered by `core/test/room-read-honest-count.test.js` and `core/test/group-work.test.js`.
436+
- `read_group_chat` shows at most `ROOM_READ_MAX` (30) of the room lines visible to the caller, the newest ones, and the cut used to be silent: `Latest in "<room>" (oldest first):` printed as if those 30 were the whole log, so a Bot asked "didn't we decide X?" read a truncated log as the whole log — the same failure #1906 fixed for the own-chat read. The header now names the cut, `Latest in "<room>" (newest 30 of 45, oldest first):`, and a read that fits the cap stays byte-identical; lines before the member's `joinedSeq` are not counted as left out, and a room whose log was trimmed counts the lines it dropped (the store keeps only the newest `ROOM_LOG_MAX` lines, 60 here and 200 in `room-membership.js`, while `room.seq` keeps counting every line, so 500 lines said and 60 kept read `newest 30 of 500`). Covered by `core/test/room-read-honest-count.test.js`, `core/test/room-read-trimmed-count.test.js` and `core/test/group-work.test.js`.
437437

438438
### Chat anchors name their part (#2710)
439439

‎patches/ds-bot/0012-room-membership.patch‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ diff --git a/src/host/groups.js b/src/host/groups.js
21182118
},
21192119
}))
21202120

2121-
@@ -539,8 +539,16 @@ export function install(rt) {
2121+
@@ -539,8 +539,23 @@ export function install(rt) {
21222122
const { room, error } = rt.pickRoom(args.group, self)
21232123
if (error) return error
21242124
ensureRoomLog(room)
@@ -2132,8 +2132,15 @@ diff --git a/src/host/groups.js b/src/host/groups.js
21322132
+ const lines = kept.slice(-ROOM_READ_MAX)
21332133
+ if (lines.length === 0) return `"${room.name}" has no messages yet.`
21342134
+ // A cut read says how much it left out, so a missing message does not read as never said (#2780).
2135-
+ const older = kept.length - lines.length
2136-
+ return `Latest in "${room.name}" (${older > 0 ? `newest ${lines.length} of ${kept.length}, ` : ''}oldest first):\n${transcript(lines)}`
2135+
+ // `kept.length` is only what the log still holds: the store is capped (60 here, 200 in
2136+
+ // room-membership.js) while `room.seq` counts every line ever appended, so a room that had
2137+
+ // said 500 lines read as "newest 30 of 60" with 440 of them silently gone (#2838). The
2138+
+ // dropped lines sit below the oldest retained one, so they count from the reader's floor to
2139+
+ // that point, never the lines before the reader joined.
2140+
+ const dropped = Math.max(0, (room.seq ?? 0) - (room.log ?? []).length)
2141+
+ const total = kept.length + Math.max(0, dropped - Math.max(0, from - 1))
2142+
+ const older = total - lines.length
2143+
+ return `Latest in "${room.name}" (${older > 0 ? `newest ${lines.length} of ${total}, ` : ''}oldest first):\n${transcript(lines)}`
21372144
},
21382145
}))
21392146

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// P-684: a busy room's read counts what the disk still holds, not what the room said. `room.log` is
2+
// capped at ROOM_LOG_MAX (60; 200 from room-membership.js) while `room.seq` keeps counting every line
3+
// ever appended, so `kept.length` is a window — yet the header printed it as the total, telling a Bot
4+
// `newest 30 of 60` for a room that had said 500 lines.
5+
import assert from 'node:assert/strict'
6+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
7+
import { tmpdir } from 'node:os'
8+
import { join } from 'node:path'
9+
import { test } from 'node:test'
10+
import { createRuntime, provideFlyBot } from '../index.js'
11+
import { fakeContext } from './fake-ctx.js'
12+
13+
const T0 = 1_760_000_000_000
14+
const line = (seq, who, text) => ({ seq, who, text, time: T0 + seq * 1000 })
15+
const lines = (count, from = 1) => Array.from({ length: count }, (_, i) => line(from + i, (from + i) % 2 === 0 ? 'Chief' : 'Writer', `message ${from + i}: the merge queue slipped again`))
16+
const shownLines = out => out.split('\n').filter(l => /^(Chief|Writer): /.test(l))
17+
const seat = (id, joinedSeq) => ({ kind: 'bot', id, role: id === 'a' ? 'admin' : 'member', displayName: id === 'a' ? 'Chief' : 'Writer', joinedSeq, joinedAt: T0 })
18+
19+
async function start(t, log, room = {}) {
20+
const home = mkdtempSync(join(tmpdir(), 'ds-bot-p684-'))
21+
const seed = {
22+
version: 1,
23+
mainBotIds: ['a'],
24+
bots: {
25+
a: { id: 'a', name: 'Chief', role: 'Boss', sessionId: 'a', createdAt: 1 },
26+
b: { id: 'b', name: 'Writer', role: 'Write', sessionId: 'b', createdAt: 2 },
27+
},
28+
rooms: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b'], mode: 'admin', admin: 'a', named: true, sessions: { a: 'ga', b: 'gb' }, log, seq: (log.at(-1)?.seq ?? 0), seen: {}, ...room } },
29+
agents: {},
30+
exchanges: [],
31+
exchangeTurns: {},
32+
questions: {},
33+
prefs: {},
34+
revision: 0,
35+
}
36+
writeFileSync(join(home, 'state.json'), JSON.stringify(seed))
37+
const ctx = fakeContext()
38+
const agentOf = id => ({ session: { id, seq: 0, deriveMessages: () => [] }, calls: [], inbox: { nextStep: [], nextTurn: [], remove: () => false }, followup: () => {}, steer: () => {}, cancel() {} })
39+
Object.assign(ctx, {
40+
llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },
41+
workspaceRegistry: { get: () => undefined, resolveByPath: async () => undefined, create: async path => ({ id: 'w1', path }), archiveSession: async () => {} },
42+
sessionController: { create: async () => ({ sessionId: 's1' }), resolveAgent: async id => ({ agent: agentOf(id) }), selectModel: async () => {}, page: async () => ({ records: [], hasMore: false }) },
43+
sessionTitle: { rename: async () => {} },
44+
sessions: { flush: async () => {} },
45+
})
46+
const rt = createRuntime(ctx, { home })
47+
provideFlyBot(ctx, rt.flybot)
48+
t.after(async () => {
49+
await ctx.dispose()
50+
rmSync(home, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 })
51+
})
52+
const tool = (name, args, sessionId) => ctx.registeredTools.get(name).execute(args, { agent: { id: sessionId } })
53+
await tool('list_bots', {}, 'a')
54+
return { rt, tool }
55+
}
56+
57+
// RED today: 500 lines were said, the cap kept the newest 60, and the read calls the kept 60 the total.
58+
test('P-684: a trimmed room read reports the lines the room said, not the lines it kept', async (t) => {
59+
const host = await start(t, lines(60, 441), { seq: 500 })
60+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
61+
assert.equal(shownLines(out).length, 30)
62+
assert.match(out, /^Latest in "Ops" \(newest 30 of 500, oldest first\):$/m, `the total counts what the log still holds, not what the room said: ${out.split('\n')[0]}`)
63+
assert.match(out, /^(Chief|Writer): message 500: /m, 'the newest line is still shown')
64+
})
65+
66+
// RED today: the hidden lines between the reader's floor and the oldest retained line are part of the
67+
// total, but the lines the reader joined after are not.
68+
test('P-684: the total is counted from the reader\'s floor, not from the start of the room', async (t) => {
69+
const host = await start(t, lines(60, 441), { seq: 500, participants: [seat('a', 0), seat('b', 300)] })
70+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
71+
assert.equal(shownLines(out).length, 30)
72+
assert.match(out, /^Latest in "Ops" \(newest 30 of 201, oldest first\):$/m, `the total ignores the reader's floor: ${out.split('\n')[0]}`)
73+
})
74+
75+
// GREEN today, must stay: a reader whose floor is above every dropped line sees all of its window, so
76+
// there is nothing to report as left out.
77+
test('P-684 guard: a late joiner in a trimmed room is not told about lines it joined after', async (t) => {
78+
const host = await start(t, lines(60, 441), { seq: 500, participants: [seat('a', 0), seat('b', 480)] })
79+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
80+
assert.equal(shownLines(out).length, 21)
81+
assert.doesNotMatch(out, /newest \d+ of \d+/)
82+
})
83+
84+
// GREEN today, must stay: a log that reached the cap without dropping a line still counts its own 60.
85+
test('P-684 guard: a room at exactly the cap is unchanged', async (t) => {
86+
const host = await start(t, lines(60))
87+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
88+
assert.match(out, /^Latest in "Ops" \(newest 30 of 60, oldest first\):$/m)
89+
})
90+
91+
// GREEN today, must stay: a room under the cap reads exactly as the uncut room it is.
92+
test('P-684 guard: a room under the cap is byte-identical', async (t) => {
93+
const said = lines(20)
94+
const host = await start(t, said)
95+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
96+
assert.equal(out, `Latest in "Ops" (oldest first):\n${said.map(l => `${l.who}: ${l.text}`).join('\n')}`)
97+
})

0 commit comments

Comments
 (0)