Fix Threads post text extraction

This commit is contained in:
Jordan Wages 2026-08-25 01:02:35 -05:00
commit ece11a8352
4 changed files with 52 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
import { readFileSync } from "node:fs";
import { DefinitionEngine, matchesUrlPattern, selectDefinition } from "../src/content/definition-engine";
import { BUILTIN_DEFINITIONS } from "../src/content/definitions";
import type { SiteDefinition } from "../src/shared/types";
@ -59,4 +60,21 @@ describe("DefinitionEngine", () => {
stop();
expect(observed).toContain("content warning revealed text");
});
it("discovers Threads posts from stable semantic/data selectors and permalink IDs", () => {
document.body.innerHTML = readFileSync("tests/fixtures/threads-feed.html", "utf8");
const threads = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "threads")!;
const posts = new DefinitionEngine(threads).discover(document);
expect(posts.map((post) => post.id)).toEqual(["threads:http://localhost:3000/@alice/post/ABC123", "threads:http://localhost:3000/@bob/post/DEF456"]);
expect(posts.map((post) => post.text)).toEqual(["first threads post with visible text", "a reply in the conversation"]);
});
it("selects Threads on current and legacy domains", () => {
const threads = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "threads")!;
document.body.innerHTML = '<div data-pressable-container="true"></div>';
for (const url of ["https://threads.com/home", "https://www.threads.com/@alice/post/ABC123", "https://threads.net/home", "https://www.threads.net/@alice/post/ABC123"]) {
expect(selectDefinition([threads], url)).toBe(threads);
}
expect(selectDefinition([threads], "https://example.com/home")).toBeUndefined();
});
});