flagtldr / scripts /e2e /release-check.mjs
botezx's picture
Grok Bot
FlagTLDR 0.5.0 (snapshot of local f98bb37)
043267b
Raw History Blame Contribute Delete
7.37 kB
// Release check (0.5.0): (1) the built zip loads in Chrome (manifest valid, version, icons, SW + options page start);
// (2) upgrade from 0.4.3 ("X Addons") – what survives in chrome.storage.local (settings, country cache "xaGeo"):
// a) new files unpacked into the SAME folder (same unpacked-extension ID) -> kept;
// b) loaded from a DIFFERENT folder (new ID) -> empty (storage is per extension ID);
// c) old entry removed ("Usuń") and the same folder loaded again -> empty (removal deletes the extension's storage).
// node release-check.mjs <chrome> [zip] (no mock needed; temp profile, nothing touches a real profile)
import puppeteer from "puppeteer-core";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { execFileSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { setTimeout as sleep } from "node:timers/promises";
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const CHROME = process.argv[2];
const ver = JSON.parse(fs.readFileSync(path.join(ROOT, "extension/manifest.json"), "utf8")).version;
const ZIP = process.argv[3] || path.join(ROOT, "dist", `flagtldr-${ver}-chrome.zip`);
const OLD = path.join(ROOT, "dist", "x-addons-0.4.3-chrome");
const T = fs.mkdtempSync(path.join(os.tmpdir(), "flagtldr-release-"));
const PROFILE = path.join(T, "profile"), A = path.join(T, "folderA"), B = path.join(T, "folderB");
const log = (...a) => console.log("[release-check]", ...a);
const fail = (m) => { throw new Error(m); };
const unzip = (dst) => { fs.rmSync(dst, { recursive: true, force: true }); fs.mkdirSync(dst, { recursive: true });
execFileSync("python3", ["-c", "import sys,zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])", ZIP, dst]); };
async function run(dir, fn) {
const b = await puppeteer.launch({ executablePath: CHROME, headless: true, userDataDir: PROFILE,
args: [`--disable-extensions-except=${dir}`, `--load-extension=${dir}`, "--no-sandbox", "--no-first-run"] });
try {
const sw = await b.waitForTarget((t) => t.type() === "service_worker" && t.url().startsWith("chrome-extension://"), { timeout: 15000 });
const id = new URL(sw.url()).host;
const opt = await b.newPage(); const errs = [];
opt.on("pageerror", (e) => errs.push(String(e)));
await opt.goto(`chrome-extension://${id}/src/options/options.html`); await sleep(700);
const info = await opt.evaluate(async () => ({ version: chrome.runtime.getManifest().version, name: chrome.runtime.getManifest().name,
header: document.querySelector("h1")?.textContent.trim(), storage: await chrome.storage.local.get(null) }));
return { id, errs, ...info, ...(fn ? await fn(opt, id) : {}) };
} finally { await b.close(); }
}
try {
// 1) zip loads
const names = execFileSync("python3", ["-c", "import sys,zipfile; print('\\n'.join(zipfile.ZipFile(sys.argv[1]).namelist()))", ZIP]).toString().split("\n");
const man = JSON.parse(execFileSync("python3", ["-c", "import sys,zipfile; sys.stdout.write(zipfile.ZipFile(sys.argv[1]).read('manifest.json').decode())", ZIP]).toString());
if (man.version !== ver) fail("zip version " + man.version);
for (const f of new Set([...Object.values(man.icons), ...Object.values(man.action.default_icon)])) if (!names.includes(f)) fail("missing " + f);
if (man.browser_specific_settings || man.background.scripts) fail("Firefox-only keys left in the Chrome zip");
unzip(B);
const fresh = await run(B, async (opt, id) => {
const icons = {};
for (const s of [16, 32, 48, 128]) icons[s] = await opt.evaluate(async (u) => { const i = new Image(); i.src = u; await i.decode(); return i.naturalWidth; }, `chrome-extension://${id}/icons/icon${s}.png`);
return { icons };
});
if (fresh.version !== ver || fresh.errs.length) fail("fresh load: " + JSON.stringify(fresh));
for (const s of [16, 32, 48, 128]) if (fresh.icons[s] !== s) fail("icon " + s);
log(`zip OK: ${path.relative(ROOT, ZIP)} (${fs.statSync(ZIP).size} B, ${names.filter(Boolean).length} files) – Chrome loaded "${fresh.name}" v${fresh.version}, header "${fresh.header}", icons 16/32/48/128 OK, no page errors`);
fs.rmSync(PROFILE, { recursive: true, force: true });
// 2a) 0.4.3 in folder A: save a changed setting + a country-cache entry
if (!fs.existsSync(OLD)) fail("old build missing: " + OLD);
fs.cpSync(OLD, A, { recursive: true });
const old = await run(A, async (opt) => {
await opt.$eval("#geoCacheDays", (e) => { e.value = "21"; }); await opt.click("#save"); await sleep(500);
await opt.evaluate(() => chrome.storage.local.get("xaGeo").then(({ xaGeo }) => chrome.storage.local.set({ xaGeo: { ...(xaGeo || {}),
testkonto: { t: Date.now(), src: "about", found: true, basedIn: "Poland", accurate: true, source: null, usernameChanges: null } } })));
return { after: await opt.evaluate(() => chrome.storage.local.get(null)) };
});
log(`0.4.3 in folder A: id ${old.id}, v${old.version} "${old.name}", saved geoCacheDays=${old.after.settings?.geoCacheDays}, xaGeo keys ${Object.keys(old.after.xaGeo || {})}`);
// 2b) same folder, new files
unzip(A);
const same = await run(A, async (opt) => ({ field: await opt.$eval("#geoCacheDays", (e) => e.value), geoEnabledBox: await opt.$eval("#geoEnabled", (e) => e.checked).catch(() => null) }));
const keptSame = same.id === old.id && same.storage.settings?.geoCacheDays === 21 && !!same.storage.xaGeo?.testkonto;
log(`0.5.0 unpacked into the SAME folder: id ${same.id} (${same.id === old.id ? "same" : "DIFFERENT"}), v${same.version} "${same.name}", geoCacheDays field ${same.field}, xaGeo.testkonto ${same.storage.xaGeo?.testkonto ? "kept" : "LOST"}, geoEnabled checkbox ${same.geoEnabledBox} -> ${keptSame ? "settings + country cache KEPT" : "NOT kept"}`);
if (!keptSame) fail("same-folder upgrade lost data");
// 2c) different folder
const other = await run(B);
log(`0.5.0 from a DIFFERENT folder: id ${other.id} (${other.id === old.id ? "same" : "different"}), stored keys: [${Object.keys(other.storage)}] -> ${other.storage.xaGeo?.testkonto ? "cache visible" : "fresh start (defaults, no country cache)"}`);
if (other.id === old.id || other.storage.xaGeo?.testkonto) fail("expected a separate extension");
// 2d) remove the extension, load the same folder again
const b = await puppeteer.launch({ executablePath: CHROME, headless: true, userDataDir: PROFILE,
args: [`--disable-extensions-except=${A}`, `--load-extension=${A}`, "--no-sandbox", "--no-first-run"] });
try {
const sw = await b.waitForTarget((t) => t.type() === "service_worker" && t.url().startsWith("chrome-extension://"));
const p = await b.newPage(); await p.goto(`chrome-extension://${new URL(sw.url()).host}/src/options/options.html`);
await p.evaluate(() => chrome.management.uninstallSelf({ showConfirmDialog: false })).catch(() => {}); await sleep(800);
} finally { await b.close(); }
const re = await run(A);
log(`removed, then the same folder loaded again: id ${re.id} (${re.id === old.id ? "same" : "different"}), stored keys: [${Object.keys(re.storage)}] -> ${re.storage.xaGeo?.testkonto || re.storage.settings?.geoCacheDays === 21 ? "data still there" : "settings + country cache GONE"}`);
log("OK");
} finally { fs.rmSync(T, { recursive: true, force: true }); }