fix(notifications): start a pasted Apprise URL from defaults, not stale values (#5217)

* fix(notifications): drop stale fields from an earlier pasted URL

A URL read half-typed (ntfy://romm) sets mode=cloud. The full URL then
omits mode as the default, so the stale cloud mode stayed and Apprise
ignored the host. Remember what the last read filled in and drop it on
the next read unless it was changed by hand.

* refactor(notifications): apply code-review fixes to stale URL field handling

Reset the last-read memory with the form values instead of a clearPaste
flag, compare with lodash isEqual, and fix the test import order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(notifications): simplify the stale URL field tests

Fold the three drop cases into it.each, bind the paste label once, and
drive the URL debounce with fake timers instead of real sleeps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(notifications): let a pasted URL replace every option it decides

The parse response now lists every key the URL decides, defaults included,
so the dialog drops a stale value (ntfy's mode: cloud) whether it came from
an earlier read or from the channel being edited. This replaces the
frontend's memory of the last read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(notifications): keep typed values only beside a service's own URL

An Apprise URL carries every option, so a pasted one starts from defaults
and a stale ntfy mode: cloud (from an earlier read or the channel being
edited) is dropped. Only an https URL, a service's own, keeps what was
typed beside it. This replaces the parse endpoint's decided list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ellis Nieuwpoort
2026-10-28 09:17:47 +08:00
committed by GitHub
parent 2216f122c1
commit 9b705d9602
2 changed files with 123 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
import { flushPromises, mount } from "@vue/test-utils";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { defineComponent, nextTick } from "vue";
import type { NotificationChannelSchema } from "@/__generated__";
import { RCheckbox, RComboboxField, RSelect } from "@/lib";
@@ -94,8 +94,11 @@ async function save(wrapper: Wrapper) {
describe("NotificationChannelDialog", () => {
beforeEach(() => {
vi.resetAllMocks();
// Only the timers, so flushPromises still settles.
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
api.getAppriseServices.mockResolvedValue({ data: [makeAppriseService()] });
});
afterEach(() => vi.useRealTimers());
it("creates a webhook that forwards every topic", async () => {
api.create.mockResolvedValue({ data: channel() });
@@ -233,10 +236,14 @@ describe("NotificationChannelDialog", () => {
stored_secrets: ["token"],
has_secret: false,
});
async function paste(wrapper: Wrapper, url: string) {
await textField(wrapper, "notifications.channel-paste-url")?.setValue(url);
async function paste(
wrapper: Wrapper,
url: string,
label = "notifications.channel-paste-url",
) {
await textField(wrapper, label)?.setValue(url);
// Past the field's debounce.
await new Promise((resolve) => setTimeout(resolve, 450));
await vi.advanceTimersByTimeAsync(450);
await flushPromises();
}
@@ -271,6 +278,112 @@ describe("NotificationChannelDialog", () => {
wrapper.unmount();
});
describe("an Apprise URL read over values already in the form", () => {
const label = "notifications.channel-service-url";
const cloud = {
service: "ntfy",
fields: { targets: ["romm"], mode: "cloud" },
};
const privateServer = {
service: "ntfy",
fields: { schema: "ntfy", host: "10.0.0.5", targets: ["romm"] },
};
async function openNtfy(editing?: NotificationChannelSchema) {
const base = makeAppriseService();
const field = base.fields[0]!;
api.getAppriseServices.mockResolvedValue({
data: [
makeAppriseService({
url_fields: ["schema", "host", "port", "targets"],
fields: [
...base.fields,
{
...field,
key: "mode",
label: "Mode",
required: false,
advanced: true,
default: "private",
values: ["private", "cloud"],
},
],
}),
],
});
api.create.mockResolvedValue({ data: channel({ type: "apprise" }) });
api.update.mockResolvedValue({ data: channel({ type: "apprise" }) });
const wrapper = await open(editing ?? null, { admin: true });
if (editing) return wrapper;
await pick(wrapper, "apprise:ntfy");
await wrapper.findAll("input.r-text-field__input")[0]!.setValue("Phone");
return wrapper;
}
const pasteUrl = (wrapper: Wrapper, url: string) =>
paste(wrapper, url, label);
const saved = () => api.create.mock.calls[0]![0].fields;
it("drops what an earlier URL set and the new one leaves out", async () => {
api.parseAppriseUrl
.mockResolvedValueOnce({ data: cloud })
.mockResolvedValueOnce({ data: privateServer });
const wrapper = await openNtfy();
await pasteUrl(wrapper, "ntfy://romm");
await pasteUrl(wrapper, "ntfy://10.0.0.5/romm");
await save(wrapper);
expect(saved()).toMatchObject({ host: "10.0.0.5", mode: "private" });
wrapper.unmount();
});
it("drops a stored value the URL leaves out when editing", async () => {
api.parseAppriseUrl.mockResolvedValueOnce({ data: privateServer });
const wrapper = await openNtfy(
channel({
type: "apprise",
service: "ntfy",
service_name: "ntfy",
fields: { host: "10.0.0.5", targets: ["romm"], mode: "cloud" },
}),
);
await pasteUrl(wrapper, "ntfy://user:pass@10.0.0.5/romm");
await save(wrapper);
expect(api.update.mock.calls[0]![1].fields).toMatchObject({
host: "10.0.0.5",
mode: "private",
});
wrapper.unmount();
});
it("ignores a read that answers after a newer one", async () => {
let answerOlder: (value: unknown) => void = () => {};
api.parseAppriseUrl
.mockResolvedValueOnce({ data: cloud })
.mockReturnValueOnce(new Promise((resolve) => (answerOlder = resolve)))
.mockResolvedValueOnce({ data: privateServer });
const wrapper = await openNtfy();
await pasteUrl(wrapper, "ntfy://romm");
await pasteUrl(wrapper, "ntfy://user:pass@10.0.0.5/romm");
await pasteUrl(wrapper, "ntfy://10.0.0.5/romm");
answerOlder({
data: {
...privateServer,
fields: { ...privateServer.fields, host: "older.example.com" },
},
});
await flushPromises();
await save(wrapper);
expect(saved()).toMatchObject({ host: "10.0.0.5", mode: "private" });
wrapper.unmount();
});
});
it("says why it can't read a pasted URL", async () => {
api.parseAppriseUrl.mockRejectedValue({
isAxiosError: true,
@@ -408,7 +521,7 @@ describe("NotificationChannelDialog", () => {
);
await save(wrapper);
// The field's own read comes due while the save waits on its read.
await new Promise((resolve) => setTimeout(resolve, 450));
await vi.advanceTimersByTimeAsync(450);
answer({
data: {
service: "discord",

View File

@@ -167,6 +167,8 @@ let pasteRequest = 0;
let reading: { url: string; done: Promise<void> } | null = null;
const parsedUrl = ref("");
const URL_LIKE = /^[a-z][\w+.-]*:\/\/\S+$/i;
// Apprise's own URLs never use http(s), so these are a service's own.
const NATIVE_URL = /^https?:\/\//i;
function clearPaste() {
pasteRequest++;
@@ -263,9 +265,10 @@ async function readUrl(url: string) {
});
return;
}
// What's typed beside a service's own URL (a Discord bot name) stays.
// What's typed beside a service's own URL (a Discord bot name) stays; an
// Apprise URL carries every option, so the defaults it omits (ntfy's mode) win.
const typed =
found.id === service.value?.id && found.url_fields.length > 0
found.id === service.value?.id && NATIVE_URL.test(url)
? Object.fromEntries(
Object.entries(appriseValues.value).filter(
([key]) => !found.url_fields.includes(key),