fix(config): keep unsupported source sections editable

Ignore empty form projections when checking raw edits, so include directives remain writable without enabling edits to represented settings. Exercise unsupported source content in editor tests and wait for router initialization before history traversal.
This commit is contained in:
Zakk committed 2026-10-02 08:49:36 +10:00
1 parent 69078c7df0
commit e144aebb00
4 files changed
+15 -11

No files matched your search

+9 -10
View File
@@ -74,8 +74,8 @@ test('switching sources discards the draft after confirmation', async ({page}) =
await expect(editor).toHaveAttribute('contenteditable', 'true');
await editor.click();
await page.keyboard.press('ControlOrMeta+End');
await page.keyboard.type('domain(example.org) -> proxy');
await expect(editor).toContainText('domain(example.org) -> proxy');
await page.keyboard.type('# unsaved source note');
await expect(editor).toContainText('# unsaved source note');
const picker = page.getByRole('button', {name: /Config file/});
await picker.click();
await page.getByRole('option', {name: /\/etc\/honk\/config\.dae/}).click();
@@ -95,26 +95,25 @@ test('editing validates, shows diagnostics on errors, and saves through a reload
await expect(editor).toHaveAttribute('contenteditable', 'true');
await editor.click();
await page.keyboard.press('ControlOrMeta+End');
await page.keyboard.type('domain(geosite: netflix) -> nowhere');
await page.keyboard.type('unknown_section {}');
await page.keyboard.press('Enter');
await page.getByRole('button', {name: 'Validate', exact: true}).click();
const diagnostics = page.getByRole('list', {name: 'Diagnostics'});
await expect(diagnostics.getByRole('listitem')).toHaveCount(1);
await expect(diagnostics).toContainText('No group named "nowhere"');
await expect(diagnostics).toContainText('Unknown section "unknown_section"');
await expect(page.locator('.rp-toast.negative')).toContainText('Validation found 1 error');
await editor.click();
await page.keyboard.press('ControlOrMeta+End');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('End');
for (let i = 0; i < 'nowhere'.length; i++) await page.keyboard.press('Backspace');
await page.keyboard.type('proxy');
await page.keyboard.press('Home');
await page.keyboard.type('# ');
await expect(page.locator('.rp-badge', {hasText: 'Not applied'})).toBeVisible();
await expect(page.locator('.rp-card').first()).toContainText('Reloading or closing the page loses the changes');
await page.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(page.locator('.rp-toast.positive', {hasText: 'written'})).toContainText('configuration reloaded');
await expect(page.locator('.rp-badge', {hasText: 'Not applied'})).toHaveCount(0);
await expect(page.getByRole('button', {name: 'Apply', exact: true})).toHaveCount(0);
await expect(page.locator('.cm-content[aria-label="/etc/honk/rules.dae"]')).toContainText('domain(geosite: netflix) -> proxy');
await expect(page.locator('.cm-content[aria-label="/etc/honk/rules.dae"]')).toContainText('# unknown_section {}');
await expect(page.locator('.rp-toolbar').first()).toContainText('41');
await expect(page.locator('.rp-toolbar').nth(1)).toContainText('3 lines,');
});
@@ -749,10 +748,10 @@ test('a new file in the include directory is created empty and opens in the sour
const editor = page.locator('.cm-content[aria-label="/etc/honk/config.d/work.dae"]');
await expect(editor).toHaveAttribute('contenteditable', 'true');
await editor.click();
await page.keyboard.type('domain(geosite: netflix) -> proxy');
await page.keyboard.type('# include file notes');
await page.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(page.locator('.rp-toast.positive', {hasText: 'written'})).toContainText('configuration reloaded');
await expect(editor).toContainText('domain(geosite: netflix) -> proxy');
await expect(editor).toContainText('# include file notes');
// The backend's refusal of an existing name stays in the dialog.
await page.getByRole('button', {name: 'New file', exact: true}).click();
await name.fill('work');
+3
View File
@@ -74,10 +74,13 @@ test('discard resets a source draft even when the destination selects the same e
test('cancelled Back and Forward restore the cursor without replacing history entries', async ({page}) => {
await page.goto('/#/settings');
await expect(page.getByRole('region', {name: 'Backend', exact: true})).toBeVisible();
await page.evaluate(() => {
location.hash = '#/config?tab=source';
});
await expect(page.locator('.cm-content')).toBeVisible();
await page.locator('.rp-nav[href="#/connections"]').click();
await expect(page).toHaveURL(/#\/connections$/);
await page.goBack();
await appendDraft(page, 'keep until discarded');
const dialog = page.getByRole('alertdialog');
+1
View File
@@ -12,6 +12,7 @@ it('routes located globals to their sole form and protects them from raw changes
expect(sameFormValues(before, before.replace('keep', 'other'), 'include', engine)).toBe(true);
expect(sameFormValues(before, before.replace(':53', ':54'), 'include', engine)).toBe(true);
expect(sameFormValues(before, before + '\n# comment', 'include', engine)).toBe(true);
expect(sameFormValues(before, before + '\nrouting { include rules.dae }', 'include', engine)).toBe(true);
expect(sameFormValues(before, before + '\nglobal { mptcp: true }', 'include', engine)).toBe(false);
});
+2 -1
View File
@@ -85,7 +85,8 @@ export function sameFormValues(before: string, after: string, source: string, en
return scanConfig(value)
.tokens.filter(token => token.kind !== 'comment')
.map(token => value.slice(token.from, token.to));
});
})
.filter(value => value.length > 0);
const includedTargets = (text: string) => {
const {blocks} = scanConfig(text);
let outside = text;