Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.
JavaScript agent-skillsai-agentsbrowser-agentbrowser-automationdecision-modeldeep-researchinstagramjevlinkedinlocal-firstopen-sourceosintresearch-agentsocaisocial-listeningsocial-mediasocial-media-researchsocmintsystem-onetiktok
fix: give evidence-card actions contextual accessible names (#88)
Misbah Nazir090eeb4b2eac
diff --git a/public/app.js b/public/app.jsindex d56f5e2..7a92377 100644--- a/public/app.js+++ b/public/app.js@@ -501,6 +501,32 @@ function evidenceKey(item, index) {return String(item.shortcode || item.video_id || item.id || item.url || item.web_url || item.share_url || `item-${index}`);}+function accessibleEvidenceContext(item, index) {+ const raw = firstString(item, ["title", "caption", "description", "text", "name"])+ || authorName(item)+ || `Result ${index + 1}`;+ const normalized = String(raw).replace(/\s+/gu, " ").trim();+ const containsUnsafeLocation = /https?:\/\/|file:\/\/|(?:^|\s)(?:~?[\\/]|[a-z]:[\\/]|\\\\)/iu.test(normalized);+ return containsUnsafeLocation ? `Result ${index + 1}` : normalized || `Result ${index + 1}`;+}++function truncateAccessibleText(value, maxLength) {+ const text = String(value);+ if (text.length <= maxLength) return text;+ const segments = new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(text);+ let output = "";+ for (const { segment } of segments) {+ if (output.length + segment.length > maxLength - 1) break;+ output += segment;+ }+ return `${output}…`;+}++function accessibleEvidenceAction(action, item, index) {+ const prefix = `${action} for evidence ${index + 1}: `;+ return prefix + truncateAccessibleText(accessibleEvidenceContext(item, index), 80 - prefix.length);+}+function renderCard(item, index) {const card = element("article", "card");const title = firstString(item, ["title", "caption", "description", "text", "name"]) || `Result ${index + 1}`;@@ -517,6 +543,7 @@ function renderCard(item, index) {const actions = element("div", "card-actions");const inspect = element("button", "", "View details");inspect.type = "button";+ inspect.setAttribute("aria-label", accessibleEvidenceAction("View details", item, index));inspect.addEventListener("click", () => showDetail(item, title));actions.append(inspect);const sourceUrl = firstString(item, ["url", "web_url", "share_url", "canonical_url"]);@@ -525,6 +552,7 @@ function renderCard(item, index) {link.href = sourceUrl;link.target = "_blank";link.rel = "noreferrer";+ link.setAttribute("aria-label", accessibleEvidenceAction("Open source ↗", item, index));actions.append(link);}body.append(actions);diff --git a/test/card-action-name.test.js b/test/card-action-name.test.jsnew file mode 100644index 0000000..d2f0b82--- /dev/null+++ b/test/card-action-name.test.js@@ -0,0 +1,107 @@+import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";+import test from "node:test";+import vm from "node:vm";++const appSource = await readFile(new URL("../public/app.js", import.meta.url), "utf8");++function productionFunction(name, nextName) {+ const start = appSource.indexOf(`function ${name}(`);+ const end = appSource.indexOf(`\nfunction ${nextName}(`, start);+ assert.notEqual(start, -1, `expected production function ${name}`);+ assert.notEqual(end, -1, `expected production function ${nextName} after ${name}`);+ return appSource.slice(start, end).trim();+}++function element(tagName, className = "", text = "") {+ return {+ tagName,+ className,+ text,+ attributes: {},+ children: [],+ append(...children) {+ this.children.push(...children);+ },+ addEventListener() {},+ setAttribute(name, value) {+ this.attributes[name] = String(value);+ },+ };+}++function descendants(node) {+ return [node, ...(node.children || []).flatMap(descendants)];+}++function makeRenderer() {+ return vm.runInNewContext(+ `(() => {+ ${productionFunction("accessibleEvidenceContext", "renderCard")}+ ${productionFunction("renderCard", "renderMediaPreview")}+ return renderCard;+ })()`,+ {+ element,+ renderMediaPreview() {},+ renderStats: () => null,+ showDetail() {},+ firstString(item, keys) {+ return keys.map((key) => item[key]).find((value) => typeof value === "string" && value.trim()) || "";+ },+ authorName: (item) => item.author || "",+ isHttpUrl: (value) => /^https:\/\//u.test(value || ""),+ Array,+ Intl,+ String,+ },+ );+}++function actions(card) {+ const nodes = descendants(card);+ return {+ button: nodes.find((node) => node.tagName === "button"),+ link: nodes.find((node) => node.tagName === "a"),+ };+}++test("renderCard gives repeated actions bounded, record-specific accessible names", () => {+ const renderCard = makeRenderer();+ const first = actions(renderCard({ title: "Duplicate title", url: "https://example.com/one" }, 0));+ const second = actions(renderCard({ title: "Duplicate title", url: "https://example.com/two" }, 1));++ assert.equal(first.button.text, "View details");+ assert.equal(first.link.text, "Open source ↗");+ assert.equal(first.button.attributes["aria-label"], "View details for evidence 1: Duplicate title");+ assert.equal(first.link.attributes["aria-label"], "Open source ↗ for evidence 1: Duplicate title");+ assert.notEqual(first.button.attributes["aria-label"], second.button.attributes["aria-label"]);+ assert.notEqual(first.link.attributes["aria-label"], second.link.attributes["aria-label"]);++ const missingTitle = actions(renderCard({ author: "@maker", url: "https://example.com/three" }, 2));+ assert.equal(missingTitle.button.attributes["aria-label"], "View details for evidence 3: @maker");++ const longTitle = actions(renderCard({ title: "x".repeat(200), url: "https://example.com/four" }, 3));+ assert.match(longTitle.button.attributes["aria-label"], /…$/u);+ assert.ok(longTitle.button.attributes["aria-label"].length <= 80);++ const sensitiveTitle = actions(renderCard({+ title: "https://private.example/post /Users/alice/run.json",+ url: "https://example.com/five",+ }, 4));+ assert.equal(sensitiveTitle.button.attributes["aria-label"], "View details for evidence 5: Result 5");+ assert.doesNotMatch(sensitiveTitle.link.attributes["aria-label"], /private\.example|\/Users\//u);++ const spacedPath = actions(renderCard({+ title: "Saved at C:\\Users\\Alice Smith\\private\\run.json",+ url: "https://example.com/six",+ }, 5));+ assert.equal(spacedPath.button.attributes["aria-label"], "View details for evidence 6: Result 6");+ assert.doesNotMatch(spacedPath.link.attributes["aria-label"], /Alice|private|run\.json/u);++ const emojiTitle = actions(renderCard({ title: "👩💻".repeat(40), url: "https://example.com/seven" }, 6));+ const emojiLabel = emojiTitle.link.attributes["aria-label"];+ const emojiContext = emojiLabel.replace(/^Open source ↗ for evidence 7: /u, "");+ assert.ok(emojiLabel.length <= 80);+ assert.match(emojiContext, /^(?:👩💻)*…$/u, "truncation must preserve complete grapheme clusters");+});