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. 提示词导演

隔离启动期状态整理写入

MigenAI2af5dfee9d63
diff --git a/background.js b/background.js
index 24d4207..e16ed00 100644
--- a/background.js
+++ b/background.js
@@ -2914,16 +2914,18 @@ async function readState() {
}
await chrome.storage.local.remove(STORAGE_KEYS.legacyAnalysisBatchJob);
}
- if (JSON.stringify(stored[STORAGE_KEYS.creativeRuns] ?? []) !== JSON.stringify(creativeRuns) ||
- JSON.stringify(stored[STORAGE_KEYS.creativeJobs] ?? {}) !== JSON.stringify(creativeJobs) ||
- JSON.stringify(stored[STORAGE_KEYS.creativeExperimentSettings] ?? {}) !== JSON.stringify(creativeExperimentSettings) ||
- JSON.stringify(stored[STORAGE_KEYS.activeCreativeResult] ?? null) !== JSON.stringify(activeCreativeResult)) {
- await commitLocalChanges({
- [STORAGE_KEYS.creativeRuns]: creativeRuns,
- [STORAGE_KEYS.creativeJobs]: creativeJobs,
- [STORAGE_KEYS.creativeExperimentSettings]: creativeExperimentSettings,
- [STORAGE_KEYS.activeCreativeResult]: activeCreativeResult
- }, { markSyncDirty: false });
+ const normalizedCreativeStorage = {
+ [STORAGE_KEYS.creativeRuns]: creativeRuns,
+ [STORAGE_KEYS.creativeJobs]: creativeJobs,
+ [STORAGE_KEYS.creativeExperimentSettings]: creativeExperimentSettings,
+ [STORAGE_KEYS.activeCreativeResult]: activeCreativeResult
+ };
+ const creativeNormalizationUpdate = Object.fromEntries(
+ Object.entries(normalizedCreativeStorage)
+ .filter(([key, value]) => JSON.stringify(stored[key]) !== JSON.stringify(value))
+ );
+ if (Object.keys(creativeNormalizationUpdate).length) {
+ await commitLocalChanges(creativeNormalizationUpdate, { markSyncDirty: false });
}
const storedBatchJob = normalizeAnalysisBatchJob(stored[STORAGE_KEYS.batchJob]);
const textBatchSummary = storedBatchJob?.kind === "text_tags"
diff --git a/test/creative-jobs.test.js b/test/creative-jobs.test.js
index ec2dca0..6a5e757 100644
--- a/test/creative-jobs.test.js
+++ b/test/creative-jobs.test.js
@@ -1,5 +1,6 @@
import test from "node:test";
import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
import {
createCreativeJob,
@@ -9,6 +10,8 @@ import {
updateCreativeJob
} from "../creative-jobs.js";
+const background = await readFile(new URL("../background.js", import.meta.url), "utf8");
+
function request(overrides = {}) {
return {
session: {
@@ -75,6 +78,17 @@ test("startup marks stale active jobs interrupted without automatically retrying
assert.equal(recovered.items.length, 1);
});
+test("startup normalization never rewrites an unchanged creative job from a stale sibling snapshot", () => {
+ const start = background.indexOf("const creativeRuns = normalizeCreativeRuns");
+ const end = background.indexOf("const storedBatchJob = normalizeAnalysisBatchJob", start);
+ const normalization = background.slice(start, end);
+
+ assert.match(normalization, /const creativeNormalizationUpdate = Object\.fromEntries/);
+ assert.match(normalization, /Object\.entries\(normalizedCreativeStorage\)/);
+ assert.match(normalization, /filter\(\(\[key, value\]\) => JSON\.stringify\(stored\[key\]\) !== JSON\.stringify\(value\)\)/);
+ assert.match(normalization, /commitLocalChanges\(creativeNormalizationUpdate/);
+});
+
test("an interrupted local edit can be retried explicitly with its retained mask reference", () => {
const created = createCreativeJob(undefined, request({
imageEdit: {