- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/test/news-written.test.ts --version 292 --json
- JSON
- /christopher/abso-core/blame/worker/project/test/news-written.test.ts?version=292&format=json
56 linesreadspeed 100%Last change readspeed in version 292,
56 lines from 1 change in 1 version.
readspeed292Project tells a host each write's news (newsWritten), and reads an agent's waiting news without taking it (peekNews)
A host that wakes a listener the moment news lands, such as a WebSocket per agent, needs two things from the engine: which agents a write just gave news, and a way to show what's waiting without using it up.
- ProjectOptions.newsWritten(items): after each write that appended "news" entries, it's called once with one item per text: {agent, text, at, seq}, where seq is the entry's place in the log. It runs inside the write, which can still roll back, so the host collects the items and acts only once the call has returned. Taking news (heard) and writes with no news call nothing, so a listener's own reads wake no one. It works on both the in-memory store and openWriter's.
- peekNews(agent): the agent's waiting news, read only. Nothing is taken, heard or written, and an agent the project hasn't got reads as none, with none made. A listener can catch up on connect while the news stays for the agent's own next read, so a listener that dies loses nothing.
- hasAgent(agent): whether the project has it, read only.
Tests: worker/project/test/news-written.test.ts (3): one call per write, with each item's agent, text and place in the log; no call for writes without news or for taking news; peekNews takes and writes nothing, and the take still finds the news. All engine tests pass (362).Compare1// A host learns each write's news as the write appends it (newsWritten), and can read an agent's waiting news without
2// taking it (peekNews), so a listener can be woken for exactly the agents that got news and caught up on connect.
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { MemoryStore, type NewsWritten, Project } from "../project.ts";
8function setup() {
9 const store = new MemoryStore();
10 const written: NewsWritten[][] = [];
11 const project = new Project(store, { newsWritten: (items) => written.push([...items]) });
12 project.init({ "a.txt": "a\n" }, 0);
13 for (const a of ["builder1", "builder2", "builder3"]) project.sync(a);
14 written.length = 0;
15 return { project, store, written };
16}
18test("a write's news is told once, per item, with its agent, text and place in the log", () => {
19 const { project, store, written } = setup();
20 project.announce("builder1", "Ship it", ["builder2", "builder3"], 1);
21 assert.equal(written.length, 1, "one call for the write");
22 const items = written[0]!;
23 assert.deepEqual(
24 items.map((i) => i.agent),
25 ["builder2", "builder3"],
26 );
27 for (const item of items) {
28 assert.match(item.text, /Announcement from builder1.*Ship it/);
29 assert.equal(store.entries[item.seq]?.type, "news", "seq is the entry's place in the log");
30 }
31 assert.ok(items[1]!.seq > items[0]!.seq);
32});
34test("writes with no news, and taking news (heard), tell nothing", () => {
35 const { project, written } = setup();
36 project.announce("builder1", "Ship it", ["builder2"], 1);
37 written.length = 0;
38 project.news("builder2");
39 project.sync("builder3");
40 assert.deepEqual(written, []);
41});
43test("peekNews reads waiting news and takes nothing; hasAgent reads only", () => {
44 const { project, store } = setup();
45 project.announce("builder1", "Ship it", ["builder2"], 1);
46 const length = store.entries.length;
47 const peeked = project.peekNews("builder2");
48 assert.equal(peeked.length, 1);
49 assert.match(peeked[0]!.text, /Ship it/);
50 assert.deepEqual(project.peekNews("builder2"), peeked, "still there");
51 assert.deepEqual(project.peekNews("nobody"), [], "no agent: none, and none made");
52 assert.equal(project.hasAgent("builder2"), true);
53 assert.equal(project.hasAgent("nobody"), false);
54 assert.equal(store.entries.length, length, "nothing written");
55 assert.equal(project.news("builder2").news.length, 1, "the take still finds it");
56});