Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/gittensory-miner-extension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ function parseRankedCandidatesJson(text) {
return parsed;
}

async function removeLegacyDiscoveryIndexUrl() {
await chrome.storage.sync.remove("discoveryIndexUrl");
}

if (globalThis.__GITTENSORY_MINER_EXTENSION_TEST__) {
globalThis.__gittensoryMinerOptionsInternals = {
parseWatchedRepos,
parseRankedCandidatesJson,
removeLegacyDiscoveryIndexUrl,
};
}

Expand All @@ -38,6 +43,7 @@ form.addEventListener("submit", async (event) => {
const repos = parseWatchedRepos(watchedRepos.value);
const rankedCandidates = parseRankedCandidatesJson(rankedCandidatesJson.value);
await chrome.storage.sync.set({ watchedRepos: repos });
await removeLegacyDiscoveryIndexUrl();
await chrome.storage.local.set({ rankedCandidates });
await refreshSettings();
showStatus(
Expand All @@ -53,6 +59,7 @@ form.addEventListener("submit", async (event) => {

async function refreshSettings() {
const stored = await chrome.storage.sync.get({ watchedRepos: [] });
await removeLegacyDiscoveryIndexUrl();
const local = await chrome.storage.local.get({ rankedCandidates: [] });
const repos = Array.isArray(stored.watchedRepos) ? stored.watchedRepos : [];
watchedRepos.value = repos.join("\n");
Expand Down
25 changes: 21 additions & 4 deletions test/unit/miner-extension-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,18 @@ describe("miner extension opportunity badge", () => {
expect(() => internals.parseRankedCandidatesJson('{"not":"array"}')).toThrow();
});

it("REGRESSION (dead-field removal): no discoveryIndexUrl config field remains anywhere in the extension", () => {
it("REGRESSION (dead-field removal): no discoveryIndexUrl config field remains in UI or background reads", () => {
expect(optionsHtml).not.toMatch(/discoveryIndexUrl/);
expect(optionsScript).not.toMatch(/discoveryIndexUrl/);
expect(backgroundScript).not.toMatch(/discoveryIndexUrl/);
});

it("saves and restores settings without ever writing or reading discoveryIndexUrl", async () => {
const synced: Record<string, unknown> = { watchedRepos: [] };
it("removes stale discoveryIndexUrl values from synced options storage", async () => {
const synced: Record<string, unknown> = {
watchedRepos: [],
discoveryIndexUrl: "https://private.example.test/index.json",
};
const setCalls: Array<Record<string, unknown>> = [];
const removeCalls: string[] = [];
const elements = {
"#settings": createFormMock(),
"#status": { textContent: "" },
Expand All @@ -174,6 +177,10 @@ describe("miner extension opportunity badge", () => {
setCalls.push(value);
Object.assign(synced, value);
},
remove: async (key: string) => {
removeCalls.push(key);
delete synced[key];
},
},
local: { get: async () => ({ rankedCandidates: [] }), set: async () => {} },
},
Expand All @@ -184,11 +191,17 @@ describe("miner extension opportunity badge", () => {
const vmContext = createContext(context);
new Script(optionsScript).runInContext(vmContext);

await flushPromises();
expect(removeCalls).toEqual(["discoveryIndexUrl"]);
expect("discoveryIndexUrl" in synced).toBe(false);

synced.discoveryIndexUrl = "https://private.example.test/index.json";
elements["#watchedRepos"].value = "JSONbored/gittensory";
await elements["#settings"].dispatchSubmit();

expect(setCalls).toHaveLength(1);
expect(setCalls[0]).toEqual({ watchedRepos: ["JSONbored/gittensory"] });
expect(removeCalls).toEqual(["discoveryIndexUrl", "discoveryIndexUrl", "discoveryIndexUrl"]);
expect("discoveryIndexUrl" in synced).toBe(false);
});
});
Expand All @@ -205,6 +218,10 @@ function createFormMock() {
};
}

function flushPromises() {
return new Promise((resolve) => setTimeout(resolve, 0));
}

function createMockContainer() {
const container = {
hidden: false,
Expand Down