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. 提示词导演
JavaScript ai-artai-videochrome-extensionclaude-codecodexhiggsfieldjimenglocal-firstmcpmidjourneymoodboardprompt-engineeringprompt-libraryprompt-managerreference-libraryseedancevisual-bookmarksweb-clipper
import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
test("the collector live-refreshes on draft storage changes", async () => {
const source = await readFile(new URL("../extension/collector.js", import.meta.url), "utf8");
assert.match(source, /libraryStorage\.subscribe/);
assert.match(source, /changes\.captureDraft/);
});
test("opening the capture workspace never starts synchronization", async () => {
const source = await readFile(new URL("../extension/background.js", import.meta.url), "utf8");
const start = source.indexOf('case "GET_CAPTURE_WORKSPACE"');
const end = source.indexOf('case "GET_DATA_SAFETY_STATUS"', start);
const branch = source.slice(start, end);
assert.match(branch, /return captureWorkspace\(\)/);
assert.doesNotMatch(branch, /scheduleAutomaticSync|scheduleIdleSync|synchronizeNow|manualSyncController|SYNC_NOW/);
});
test("reading library state never starts synchronization", async () => {
const source = await readFile(new URL("../extension/background.js", import.meta.url), "utf8");
const start = source.indexOf('case "GET_STATE"');
const end = source.indexOf('case "GET_CAPTURE_WORKSPACE"', start);
const branch = source.slice(start, end);
assert.match(branch, /return enqueue\(async \(\) => \(\{ ok: true,/);
assert.doesNotMatch(branch, /scheduleAutomaticSync|scheduleIdleSync|synchronizeNow|manualSyncController|SYNC_NOW/);
assert.doesNotMatch(source, /function scheduleAutomaticSync|function scheduleIdleSync/);
});
test("draft edits and save share one lightweight queue so the last capture cannot miss the commit", async () => {
const source = await readFile(new URL("../extension/background.js", import.meta.url), "utf8");
for (const messageType of [
"UPDATE_CAPTURE_DRAFT", "UPDATE_CAPTURE_DRAFT_METADATA", "UPDATE_CAPTURE_FRAGMENT", "REMOVE_CAPTURE_FRAGMENT",
"REMOVE_CAPTURE_VISUAL", "CANCEL_CAPTURE_DRAFT", "COMMIT_CAPTURE_DRAFT"
]) {
const start = source.indexOf(`case "${messageType}"`);
assert.notEqual(start, -1, `${messageType} handler is missing`);
const branch = source.slice(start, source.indexOf("case ", start + 6));
const transaction = branch.includes('captureSaveTasks.run')
? source.slice(source.indexOf('async function runCaptureSave'), source.indexOf('async function commitPageCapture')) : branch;
assert.match(transaction, /enqueueCapture/, `${messageType} must stay ordered with capture writes`);
if (messageType === 'COMMIT_CAPTURE_DRAFT') assert.match(transaction, /enqueue\(/);
}
});
test("creative result capture and metadata commit cross both queues as one transaction", async () => {
const source = await readFile(new URL("../extension/background.js", import.meta.url), "utf8");
const start = source.indexOf("async function captureAndCommitCreativeOutputs");
const end = source.indexOf("function dispatchCaptureMessage", start);
const transaction = source.slice(start, end);
assert.match(transaction, /enqueueCapture/);
assert.match(transaction, /await enqueue\(\(\) => commitCreativeOutputsTransaction\(\)\)/);
assert.ok(transaction.indexOf("dispatchCaptureMessage") < transaction.indexOf("commitCreativeOutputsTransaction"));
});
test("captured posts retain real media facts when suggesting a case category", async () => {
const source = await readFile(new URL("../extension/background.js", import.meta.url), "utf8");
const start = source.indexOf("async function commitPageCapture");
const end = source.indexOf("async function", start + 20);
const save = source.slice(start, end);
assert.match(save, /classifyCapturedContent\(\{ \.\.\.base, sourceFacts: candidate\.sourceFacts, mediaAssets, mediaPrompts \}/);
assert.doesNotMatch(save, /classificationMediaAssets/);
});
test("restoring an overwritten screenshot marks that existing media id dirty", async () => {
const source = await readFile(new URL("../extension/background.js", import.meta.url), "utf8");
const start = source.indexOf("async function undoLastSave()");
const end = source.indexOf("async function deleteEntry", start);
const undo = source.slice(start, end);
assert.match(undo, /dirtyAssetIds:\s*\[current\.id\]/);
});
test("a recovered page-capture save preview is not replaced by an older assistant batch", async () => {
const assistant = await readFile(new URL("../extension/collector-capture-assistant.js", import.meta.url), "utf8");
const collector = await readFile(new URL("../extension/collector.js", import.meta.url), "utf8");
// The assistant must not re-apply a batch that belongs to the durable save task,
// and must leave a recovered preview alone while that task still exists.
assert.match(assistant, /preserveBatch = \(\) => false/);
assert.match(assistant, /function assistantPendingBatch\(value\)/);
assert.match(assistant, /value && value\.status !== 'saving' \? value : null/);
assert.match(assistant, /if \(!preserveBatch\(\)\) \{/);
assert.match(assistant, /state\.pendingBatch = assistantPendingBatch\(baseBatch\)/);
assert.match(collector, /preserveBatch: \(\) => Boolean\(pageCaptureBatch && captureSaveTask\?\.input\?\.type === 'COMMIT_PAGE_CAPTURE'\)/);
});