Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@profullstack/readm3",
"version": "0.26.0",
"version": "0.26.1",
"description": "Markdown editing and sharing for people and teams. Web/PWA, CLI, API and MCP with version history, view/edit links, and a terminal reader.",
"type": "module",
"license": "MIT",
Expand Down
11 changes: 8 additions & 3 deletions site/cloud-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export async function record(changes: Change[], key: SyncKey, device: string): P
const sealed = async (source: Pick<WorkspaceDocument, "source" | "language">, when: string, ifEmpty?: boolean) => ({
tag, ifEmpty, sealed: JSON.stringify(await seal({ path: doc.path, source: source.source, language: source.language, device, at: when } satisfies Sealed, key)),
});
if (before && !before.blob && before.source !== doc.source) versions.push(await sealed(before, "", true));
// The text before is dated just ahead of the save, so the save stays the newest version.
if (before && !before.blob && before.source !== doc.source) versions.push(await sealed(before, new Date(Date.parse(at) - 1).toISOString(), true));
versions.push(await sealed(doc, at));
}
for (let i = 0; i < versions.length; i += 50) await request("file-history", "POST", { versions: versions.slice(i, i + 50) });
Expand All @@ -50,9 +51,13 @@ export async function list(path: string, limit = 25): Promise<CloudVersion[]> {
const version = await open<Sealed>(JSON.parse(sealed) as Envelope, key);
// A version sealed for another path under the same tag cannot happen, but is never shown.
if (version.path !== path) return null;
return { id, at: version.at || createdAt, device: version.device, source: version.source, ...(version.language ? { language: version.language } : {}) };
return { id, at: version.at, createdAt, device: version.device, source: version.source, ...(version.language ? { language: version.language } : {}) };
} catch { return null; }
}));
return opened.filter((version): version is CloudVersion => !!version);
const found = opened.filter((version) => !!version);
// Before 0.26.1 the text before a file's first synced save was sealed undated and took the
// server's later clock, so it sorted above that save; it is the oldest version, so it goes last.
const oldest = Math.min(...found.filter((version) => version.at).map((version) => Date.parse(version.at)));
return found.map(({ createdAt, ...version }) => ({ ...version, at: version.at || (Number.isFinite(oldest) ? new Date(oldest - 1).toISOString() : createdAt) }));
} catch { return []; }
}
14 changes: 13 additions & 1 deletion site/test/sync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect, type Page, type BrowserContext } from "@playwright/test";
import { test, expect, type Page, type BrowserContext, type Route } from "@playwright/test";
import { stat } from "node:fs/promises";
import { editorInput } from "./editor.ts";

Expand Down Expand Up @@ -77,9 +77,14 @@ test("two devices sync files and settings automatically through the encrypted co
await setPassphrase(page);
await page.locator("#theme").selectOption("nord");
await page.locator("#flavor").selectOption("reddit");
// The file reaches the account with no history yet (as files synced before history did), so the
// first edit files the text before it too, and that older text must not sort above the edit.
const noHistory = (route: Route) => route.request().method() === "POST" ? route.fulfill({ json: { saved: 0 } }) : route.continue();
await page.route("**/api/v1/file-history", noHistory);
await page.locator("#files-input").setInputFiles({ name: "Synced.md", mimeType: "text/markdown", buffer: Buffer.from("# Across devices\n\nHello 😺\n") });
await expect.poll(() => sealedSnapshot(page), { timeout: 20_000 }).not.toBeNull();
await expect(page.locator("#sync-note")).toContainText("Synced", { timeout: 20_000 });
await page.unroute("**/api/v1/file-history", noHistory);

const second = await browser.newContext();
try {
Expand All @@ -99,6 +104,13 @@ test("two devices sync files and settings automatically through the encrypted co
await editorInput(other).fill("# Edited on second device\n");
// "Synced" is already on screen from the first pass; wait for the edit to reach the account.
await expect.poll(async () => (await sealedSnapshot(page))?.revision, { timeout: 20_000 }).toBeGreaterThan(before);
// On the device that saved it, the save is the newest version: the text before it is listed below.
await other.locator("#history").click();
const mine = other.locator("#file-history-dialog .history-item");
await expect(mine.locator(".history-reason", { hasText: "synced from browser" }).first()).toBeVisible({ timeout: 20_000 });
await expect(mine.filter({ hasText: "Across devices" }).first()).toBeVisible({ timeout: 20_000 });
await expect(mine.first().locator(".history-snippet .added").first()).toContainText("Edited on second device");
await other.locator("#file-history-dialog").getByRole("button", { name: "Close history" }).click();

await page.evaluate(() => window.dispatchEvent(new Event("focus")));
await page.locator('.file-row[data-path="Synced.md"]').click();
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { run, type ViewerOptions } from "./viewer.ts";
import { isCloudCommand, cloudMain, CLOUD_USAGE } from "./cloud-cli.ts";
import { isDesktopCommand, desktopMain, installedDesktop, prefersDesktop, DESKTOP_USAGE } from "./desktop-cli.ts";

export const VERSION = "0.26.0";
export const VERSION = "0.26.1";

/** The help text, exported so a test can hold it to the flags it documents. */
export const USAGE = `readm3 — a plain text editor for Markdown and code
Expand Down
Loading