Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

3.4 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

const [html, source, background] = await Promise.all([
  readFile(new URL("../extension/library.html", import.meta.url), "utf8"),
  readFile(new URL("../extension/library.js", import.meta.url), "utf8"),
  readFile(new URL("../extension/background.js", import.meta.url), "utf8")
]);

test("local index maintenance keeps its controls and uses real job counters in the shared progress bar", () => {
  const card = html.slice(html.indexOf('<div class="batch-card local-index-card">'), html.indexOf('id="legacy-candidates"'));
  assert.match(card, /资料索引自动补全/);
  assert.match(card, /class="task-heading"><div class="task-copy"><h3[^>]*>资料索引自动补全<\/h3><div id="reanalyze-preview"/);
  assert.match(card, /id="preview-reanalyze"[^>]*>检查缺失项/);
  assert.match(card, /id="apply-reanalyze"[^>]*hidden[^>]*>开始补全/);
  assert.match(card, /<progress id="maintenance-progress-bar" class="ui-task-progress"[^>]*hidden/);
  assert.match(source, /setTaskProgress\(elements\.maintenanceProgressBar, \{ completed: maintenanceJob\?\.processed, total: maintenanceJob\?\.total/);
  assert.doesNotMatch(card, /task-stage|task-details-panel/);
});

test("local index maintenance exposes checked, running, complete, and failed text states", () => {
  const manager = source.slice(source.indexOf("function renderBatchManager"), source.indexOf("function renderAnalysisSettings"));
  const status = source.slice(source.indexOf("function renderReanalysisPreview"), source.indexOf("function updateLibrarySettingsSaveState"));
  assert.match(manager, /t\(reanalysisPreview \|\| maintenanceJob \? "重新检查" : "检查缺失项"\)/);
  assert.match(manager, /elements\.applyReanalyze\.hidden = maintenanceActive \|\| !maintenanceMissing/);
  assert.match(status, /资料索引已完整/);
  assert.match(status, /t\("需要更新索引:\{types\} 条内容类型,\{palettes\} 张图片色卡。"/);
  assert.doesNotMatch(status, /待补全/);
  assert.match(status, /t\("\{status\} · 已处理 \{processed\}\/\{total\} · 成功 \{succeeded\} · 失败 \{failed\}"/);
  assert.match(status, /processed: maintenanceJob\.processed/);
  assert.match(status, /succeeded: maintenanceJob\.succeeded/);
});

test("every material import queues local index completion without coupling it to AI", () => {
  const localImport = background.slice(background.indexOf("async function importStagedItem"), background.indexOf("function importedEntryFromStagedAsset"));
  const packageImport = background.slice(background.indexOf("async function applyLibraryImport"), background.indexOf("function previewCuratedImport"));
  const curatedImport = background.slice(background.indexOf("async function applyCuratedImport"), background.indexOf("function curatedImportResponse"));
  const automaticCompletion = background.slice(background.indexOf("async function enqueueAutomaticLibraryMaintenance"), background.indexOf("async function libraryMaintenanceStatus"));

  assert.match(localImport, /enqueueAutomaticLibraryMaintenance\(imported\)/);
  assert.match(packageImport, /enqueueAutomaticLibraryMaintenance/);
  assert.match(curatedImport, /enqueueAutomaticLibraryMaintenance/);
  assert.match(automaticCompletion, /libraryMaintenanceTargets/);
  assert.doesNotMatch(automaticCompletion, /Vision|AI|queueAutomaticVisionAnalysis/);
});