Skip to content
Merged
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
5 changes: 2 additions & 3 deletions apps/gittensory-miner-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ available for the current issue.
## Local ranked cache

Laptop-mode installs can paste JSON from a miner `discover` run into the options page. The extension stores that list in
`chrome.storage.local.rankedCandidates` and looks up the current issue there. A discovery-index URL can be saved for a
future hosted client path; it is not read yet, so when only unranked hosted metadata would be available the badge
degrades gracefully by staying hidden.
`chrome.storage.local.rankedCandidates` and looks up the current issue there. When no ranked signal is cached for the
current issue, the badge degrades gracefully by staying hidden.
6 changes: 2 additions & 4 deletions apps/gittensory-miner-extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ async function loadIssueOpportunityContext(message) {
}

async function loadMinerExtensionSettings() {
const stored = await chrome.storage.sync.get({ watchedRepos: [], discoveryIndexUrl: "" });
const stored = await chrome.storage.sync.get({ watchedRepos: [] });
const watchedRepos = Array.isArray(stored.watchedRepos)
? stored.watchedRepos.map((value) => String(value).trim()).filter(Boolean)
: [];
const discoveryIndexUrl =
typeof stored.discoveryIndexUrl === "string" ? stored.discoveryIndexUrl.trim() : "";
return { watchedRepos, discoveryIndexUrl };
return { watchedRepos };
}

async function loadRankedCandidates() {
Expand Down
4 changes: 0 additions & 4 deletions apps/gittensory-miner-extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ <h1>Gittensory miner extension</h1>
Watched repositories
<textarea id="watchedRepos" name="watchedRepos" placeholder="owner/repo, one per line"></textarea>
</label>
<label>
Discovery index URL (optional)
<input id="discoveryIndexUrl" name="discoveryIndexUrl" placeholder="https://example.com/discovery-index" />
</label>
<label>
Ranked candidates JSON (local cache)
<textarea
Expand Down
11 changes: 3 additions & 8 deletions apps/gittensory-miner-extension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ if (globalThis.__GITTENSORY_MINER_EXTENSION_TEST__) {
const form = document.querySelector("#settings");
const status = document.querySelector("#status");
const watchedRepos = document.querySelector("#watchedRepos");
const discoveryIndexUrl = document.querySelector("#discoveryIndexUrl");
const rankedCandidatesJson = document.querySelector("#rankedCandidatesJson");

if (!form || !status || !watchedRepos || !discoveryIndexUrl || !rankedCandidatesJson) {
if (!form || !status || !watchedRepos || !rankedCandidatesJson) {
// options.html is not mounted (unit-test harness or partial load).
} else {
void refreshSettings();
Expand All @@ -38,10 +37,7 @@ form.addEventListener("submit", async (event) => {
try {
const repos = parseWatchedRepos(watchedRepos.value);
const rankedCandidates = parseRankedCandidatesJson(rankedCandidatesJson.value);
await chrome.storage.sync.set({
watchedRepos: repos,
discoveryIndexUrl: discoveryIndexUrl.value.trim(),
});
await chrome.storage.sync.set({ watchedRepos: repos });
await chrome.storage.local.set({ rankedCandidates });
await refreshSettings();
showStatus(
Expand All @@ -56,11 +52,10 @@ form.addEventListener("submit", async (event) => {
}

async function refreshSettings() {
const stored = await chrome.storage.sync.get({ watchedRepos: [], discoveryIndexUrl: "" });
const stored = await chrome.storage.sync.get({ watchedRepos: [] });
const local = await chrome.storage.local.get({ rankedCandidates: [] });
const repos = Array.isArray(stored.watchedRepos) ? stored.watchedRepos : [];
watchedRepos.value = repos.join("\n");
discoveryIndexUrl.value = typeof stored.discoveryIndexUrl === "string" ? stored.discoveryIndexUrl : "";
const rankedCandidates = Array.isArray(local.rankedCandidates) ? local.rankedCandidates : [];
rankedCandidatesJson.value =
rankedCandidates.length > 0 ? JSON.stringify(rankedCandidates, null, 2) : "";
Expand Down
61 changes: 59 additions & 2 deletions test/unit/miner-extension-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const contentScript = readFileSync("apps/gittensory-miner-extension/content.js",
const backgroundScript = readFileSync("apps/gittensory-miner-extension/background.js", "utf8");
const badgeScript = readFileSync("apps/gittensory-miner-extension/opportunity-badge.js", "utf8");
const optionsScript = readFileSync("apps/gittensory-miner-extension/options.js", "utf8");
const optionsHtml = readFileSync("apps/gittensory-miner-extension/options.html", "utf8");
const manifest = JSON.parse(readFileSync("apps/gittensory-miner-extension/manifest.json", "utf8"));

const NOW = Date.parse("2026-07-03T12:00:00.000Z");
Expand Down Expand Up @@ -146,8 +147,64 @@ describe("miner extension opportunity badge", () => {
expect(() => internals.parseRankedCandidatesJson("{")).toThrow();
expect(() => internals.parseRankedCandidatesJson('{"not":"array"}')).toThrow();
});

it("REGRESSION (dead-field removal): no discoveryIndexUrl config field remains anywhere in the extension", () => {
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: [] };
const setCalls: Array<Record<string, unknown>> = [];
const elements = {
"#settings": createFormMock(),
"#status": { textContent: "" },
"#watchedRepos": { value: "" },
"#rankedCandidatesJson": { value: "" },
};
const context: Record<string, unknown> = {
__GITTENSORY_MINER_EXTENSION_TEST__: true,
document: { querySelector: (selector: string) => elements[selector as keyof typeof elements] ?? null },
chrome: {
storage: {
sync: {
get: async (defaults: Record<string, unknown>) => ({ ...defaults, ...synced }),
set: async (value: Record<string, unknown>) => {
setCalls.push(value);
Object.assign(synced, value);
},
},
local: { get: async () => ({ rankedCandidates: [] }), set: async () => {} },
},
},
window: { setTimeout: () => 0 },
};
context.globalThis = context;
const vmContext = createContext(context);
new Script(optionsScript).runInContext(vmContext);

elements["#watchedRepos"].value = "JSONbored/gittensory";
await elements["#settings"].dispatchSubmit();

expect(setCalls).toHaveLength(1);
expect(setCalls[0]).toEqual({ watchedRepos: ["JSONbored/gittensory"] });
expect("discoveryIndexUrl" in synced).toBe(false);
});
});

function createFormMock() {
let submitHandler: ((event: { preventDefault: () => void }) => unknown) | null = null;
return {
addEventListener: (type: string, handler: typeof submitHandler) => {
if (type === "submit") submitHandler = handler;
},
dispatchSubmit: async () => {
await submitHandler?.({ preventDefault: () => {} });
},
};
}

function createMockContainer() {
const container = {
hidden: false,
Expand Down Expand Up @@ -207,7 +264,7 @@ function loadBackgroundInternals({
chrome: {
storage: {
sync: {
get: async () => ({ watchedRepos, discoveryIndexUrl: "" }),
get: async () => ({ watchedRepos }),
},
local: {
get: async () => ({ rankedCandidates }),
Expand Down Expand Up @@ -239,7 +296,7 @@ function loadOptionsInternals() {
document: { querySelector: () => null },
chrome: {
storage: {
sync: { get: async () => ({ watchedRepos: [], discoveryIndexUrl: "" }), set: async () => {} },
sync: { get: async () => ({ watchedRepos: [] }), set: async () => {} },
local: { get: async () => ({ rankedCandidates: [] }), set: async () => {} },
},
},
Expand Down