Cut 3 Soul fixes: replaces counts only from the same sender; tests for the loop guard and the cover
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 6m20s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 6m20s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
796bc161a9
commit
5835e565cd
5 changed files with 36 additions and 6 deletions
|
|
@ -82,7 +82,7 @@ What it buys: one identity, one audience, one audit trail, immutable files, exis
|
|||
- **When it posts.** Handoff documents are edited in place, so mirroring every save would spam the room with drafts. The rule (Eureka's lean, adopted): **post once, when the document is marked final**; a later final version posts again with a `replaces` relation to the earlier event. "Final" is a sibling `NAME.final` holding the document's sha256 (answered Q-E2); the client must not know.
|
||||
- **Allowlist.** Lives on the publisher: a list of source roots and patterns, read by the publisher only. `handoff-private` is not on it and the publisher never lists, reads or posts from it. The client holds no path to anything on disk.
|
||||
- **The event.** A file event in the thread of the folder's album, built the way `getMsgContent` builds them (`msgtype`, `body`, `filename`, `url` from the media repo, `info.mimetype|size|sha256`), plus one extra key `org.gamecult.publish`: `{ source, sha256, replaces? }` where `source` is a path relative to the allowlisted root, never absolute, and `replaces` is the event id of the version it supersedes.
|
||||
- **`replaces`, not `m.replace`.** `m.replace` is the stock edit relation, but Ratatoskr's `buildAlbums` deliberately never treats an edit as a file, several clients do not render an edited file, and an edit hides the earlier version. A custom key keeps both events as files; the view shows the latest of a chain and a "N earlier versions" row under it, and other Matrix clients see two ordinary file posts. A chain is read from the events themselves (each carries its `replaces`), not from a table.
|
||||
- **`replaces`, not `m.replace`.** `m.replace` is the stock edit relation, but Ratatoskr's `buildAlbums` deliberately never treats an edit as a file, several clients do not render an edited file, and an edit hides the earlier version. A custom key keeps both events as files; the view shows the latest of a chain and a "N earlier versions" row under it, and other Matrix clients see two ordinary file posts. A chain is read from the events themselves (each carries its `replaces`), not from a table, and a `replaces` counts only when its event has the same sender as the event it names, so nobody else in the thread can fold a file away.
|
||||
- **Idempotence.** The publisher's own state (a typed CultCache document of `source`, `sha256`, `event_id`) says what it posted; if that is lost, it rebuilds by reading its own events back from the room (`org.gamecult.publish.source` plus `sha256`) rather than guessing. The same `sha256` never posts twice.
|
||||
- **Receipts and fetch** work unchanged: the event is an ordinary file event in a file-zone room, so a Mind's mouth can fetch it by room id and event id (5 MiB cap there) and tick `fetched for`.
|
||||
|
||||
|
|
|
|||
|
|
@ -229,6 +229,16 @@ describe('versions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('versions: cover and sender', () => {
|
||||
it('the cover comes from the shown version, not a folded image', () => {
|
||||
const img = (id: string, ts: number, type: string, replaces?: string) =>
|
||||
reply(id, ts, type, id, replaces ? { 'org.gamecult.publish': { replaces } } : {});
|
||||
const a = one(root('$r', 1), [img('$v1', 10, 'm.image'), img('$v2', 20, 'm.file', '$v1')]);
|
||||
expect(a.files.map((f) => f.id)).toEqual(['$v2']);
|
||||
expect(a.cover).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mind receipts', () => {
|
||||
const HASH = 'a'.repeat(64);
|
||||
const file = (id: string, sha?: string) =>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export type AlbumFile = {
|
|||
id: string;
|
||||
kind: FileKind;
|
||||
name: string;
|
||||
sender: string;
|
||||
ts: number;
|
||||
/** The event content, as RenderMessageContent reads it. */
|
||||
content: Record<string, unknown>;
|
||||
|
|
@ -75,6 +76,7 @@ const toFile = (e: ZoneEvent): AlbumFile | undefined => {
|
|||
id: e.event_id,
|
||||
kind,
|
||||
name: asString(e.content.filename) || asString(e.content.body),
|
||||
sender: e.sender ?? '',
|
||||
ts: tsOf(e.origin_server_ts),
|
||||
content: e.content,
|
||||
readBy: [],
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { PUBLISH_KEY, foldVersions, replacesOf } from './versions';
|
||||
|
||||
type F = { id: string; content: Record<string, unknown>; earlier: F[] };
|
||||
const f = (id: string, replaces?: string): F => ({
|
||||
type F = { id: string; sender: string; content: Record<string, unknown>; earlier: F[] };
|
||||
const f = (id: string, replaces?: string, sender = '@m:x'): F => ({
|
||||
id,
|
||||
sender,
|
||||
content: replaces ? { [PUBLISH_KEY]: { replaces } } : {},
|
||||
earlier: [],
|
||||
});
|
||||
|
|
@ -59,6 +60,19 @@ describe('foldVersions', () => {
|
|||
expect(out.map((x) => x.id)).toEqual(['$s']);
|
||||
});
|
||||
|
||||
it('a loop reached from a head is walked once and ends', () => {
|
||||
const out = foldVersions([f('$a', '$b'), f('$b', '$a'), f('$h', '$a')]);
|
||||
expect(shape(out)).toEqual([['$h', ['$a', '$b']]]);
|
||||
});
|
||||
|
||||
it('a replacement by another sender folds nothing', () => {
|
||||
const out = foldVersions([f('$victim', undefined, '@m:x'), f('$evil', '$victim', '@e:x')]);
|
||||
expect(shape(out)).toEqual([
|
||||
['$victim', []],
|
||||
['$evil', []],
|
||||
]);
|
||||
});
|
||||
|
||||
it('an empty list is empty', () => {
|
||||
expect(foldVersions([])).toEqual([]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,16 +17,20 @@ type Versioned<F> = F & { earlier: F[] };
|
|||
/**
|
||||
* Files not replaced by another file in the list, oldest first as given, each carrying the files it
|
||||
* supersedes (nearest first) in `earlier`. A replacement whose target is missing from the list (a
|
||||
* redacted event, another thread) replaces nothing and stands as a head. A file two others claim to
|
||||
* redacted event, another thread) replaces nothing and stands as a head. A replacement by another sender is ignored. A file two others claim to
|
||||
* replace sits under both. The walk refuses to revisit a file, so a malformed chain cannot loop (an event id hashes its content, so a real one cannot cycle).
|
||||
*/
|
||||
export const foldVersions = <F extends { id: string; content: Record<string, unknown> }>(
|
||||
export const foldVersions = <
|
||||
F extends { id: string; sender: string; content: Record<string, unknown> }
|
||||
>(
|
||||
files: Versioned<F>[]
|
||||
): Versioned<F>[] => {
|
||||
const byId = new Map(files.map((f) => [f.id, f]));
|
||||
const target = (f: F): F | undefined => {
|
||||
const id = replacesOf(f.content);
|
||||
return id && id !== f.id ? byId.get(id) : undefined;
|
||||
const t = id && id !== f.id ? byId.get(id) : undefined;
|
||||
// Only the sender of a file can supersede it, so no one else in the thread can fold it away.
|
||||
return t && t.sender === f.sender ? t : undefined;
|
||||
};
|
||||
const replaced = new Set<string>();
|
||||
files.forEach((f) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue