fix: correct Memos links and author identities

This commit is contained in:
2026-07-19 18:51:16 +08:00
parent d512443d00
commit 08059e2a9d
11 changed files with 41 additions and 21 deletions
+10 -4
View File
@@ -1,15 +1,21 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { postAuthorLabel } from "../lib/display";
import { memoUrl } from "../lib/memos";
test("formats Memos authors as name at source hostname", () => {
assert.equal(postAuthorLabel({ origin: "memos", username: "hub-user", name: "codex", remote_display_name: "codex", source_base_url: "https://memos.fishking.studio/path" }), "@codex@memos.fishking.studio");
test("formats Memos authors as remote user at source hostname", () => {
assert.equal(postAuthorLabel({ origin: "memos", username: "hub-user", name: "唐宋打油", remote_user: "users/tangsong", remote_display_name: "唐宋打油", source_base_url: "https://memos.fishking.studio/path" }), "@tangsong@memos.fishking.studio");
});
test("formats Hub posts linked to Memos with the same source identity", () => {
assert.equal(postAuthorLabel({ origin: "hub", username: "codex", name: "codex", remote_display_name: "codex", source_base_url: "https://memos.fishking.studio" }), "@codex@memos.fishking.studio");
assert.equal(postAuthorLabel({ origin: "hub", username: "codex", name: "唐宋打油", remote_user: "users/tangsong", remote_display_name: "唐宋打油", source_base_url: "https://memos.fishking.studio" }), "@tangsong@memos.fishking.studio");
});
test("keeps the existing label for non-Memos posts", () => {
assert.equal(postAuthorLabel({ origin: "hub", username: "codex", name: "Hub", source_base_url: null }), "@Hub · Hub");
assert.equal(postAuthorLabel({ origin: "hub", username: "codex", name: "Hub", source_base_url: null }), "@codex");
});
test("uses current Memos UID links while preserving legacy numeric links", () => {
assert.equal(memoUrl("https://memos.example.com/", "memos/VA54SvJG7yBparf3SiH3Ey"), "https://memos.example.com/memos/VA54SvJG7yBparf3SiH3Ey");
assert.equal(memoUrl("https://memos.example.com", "memos/15"), "https://memos.example.com/m/15");
});
+1 -1
View File
@@ -16,7 +16,7 @@ test("applies tracked migrations and deduplicates active pull jobs", async () =>
const { queuePull } = await import("../lib/sync");
const { notify } = await import("../lib/notifications");
const migrations = db.prepare("SELECT version FROM schema_migrations ORDER BY version").all() as { version: number }[];
assert.deepEqual(migrations.map((item) => item.version), Array.from({ length: 41 }, (_, index) => index + 1));
assert.deepEqual(migrations.map((item) => item.version), Array.from({ length: 42 }, (_, index) => index + 1));
const userId = Number(db.prepare("INSERT INTO users(username,password_hash) VALUES('sync-test','hash')").run().lastInsertRowid);
const sourceId = Number(db.prepare("INSERT INTO sources(user_id,name,base_url,token_encrypted,is_enabled) VALUES(?,?,?,?,1)").run(userId, "Test", "https://example.test", "encrypted").lastInsertRowid);
assert.equal(queuePull(sourceId, "manual"), true);