fix(settings): preserve server editor drafts until save succeeds

This commit is contained in:
2026-10-24 10:52:01 +01:00
parent 6609b52b1c
commit 25437b3181
6 changed files with 414 additions and 27 deletions
+44
View File
@@ -0,0 +1,44 @@
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pipelines_app/core/servers/server_catalog.dart';
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
import 'package:pipelines_app/features/settings/saved_servers_section.dart';
import 'package:pipelines_app/features/settings/server_connections.dart';
// Isolated, in-memory browser fixture: first write fails, retry succeeds.
// No sockets, real storage, or production requests.
void main() {
final cupertino = Uri.base.queryParameters['host'] == 'cupertino';
final connections = ServerConnections(
store: _Store(),
onSelected: (_) async {},
);
final body = SafeArea(
child: SingleChildScrollView(
child: SavedServersSection(connections: connections),
),
);
runApp(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
}
class _Store extends MemoryServerCatalogStore {
var _attempts = 0;
@override
Future<bool> save(ServerCatalog catalog) async {
globalContext.setProperty(
'serverEditorSaveAttempts'.toJS,
(++_attempts).toJS,
);
await Future<void>.delayed(const Duration(seconds: 3));
if (_attempts == 1) return false;
return super.save(catalog);
}
}
+68
View File
@@ -0,0 +1,68 @@
// Build: flutter build web -t tool/server_editor_save_probe.dart -o build/server_editor_save_probe_web
// Run: node tool/server_editor_save_probe.mjs [evidence directory]
import assert from 'node:assert/strict';
import { once } from 'node:events';
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { startServer, launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
import { axNodes, enableSemantics, waitFor, capture, assertName, click, clickAt } from './pipelines_probe_cdp_input.mjs';
const output = resolve(process.argv[2] ?? 'build/server-editor-save-evidence');
await mkdir(output, { recursive: true });
const fixture = await startServer(resolve('build/server_editor_save_probe_web'));
const profile = await mkdtemp(join(tmpdir(), 'server-editor-save-'));
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
const log = { checks: [], captures: [] };
let c;
try {
c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl);
await c.send('Page.enable');
await c.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });
for (const host of ['material', 'cupertino']) {
await c.send('Page.navigate', { url: `${fixture.url}?host=${host}` });
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 12000));
await enableSemantics(c);
await click(c, 'Add server');
const type = async (index, text) => {
const field = (await axNodes(c)).filter(node => node.role?.value === 'textbox')[index];
assert.ok(field, `field ${index}`);
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: field.backendDOMNodeId });
const [x1, y1, , , x3, y3] = model.content;
await clickAt(c, (x1 + x3) / 2, (y1 + y3) / 2);
await c.send('Input.insertText', { text });
await sleep(200);
};
await type(0, 'Home draft');
await type(1, 'wss://home.test/connect');
await click(c, 'Save server');
await assertName(c, 'Saving server…', `${host}: pending state visible`, log);
await click(c, 'Saving server…');
assert.equal(await c.evaluate('globalThis.serverEditorSaveAttempts'), 1);
log.checks.push(`${host}: repeat click does not submit again`);
await capture(c, output, log, `${host}-saving`);
await assertName(c, 'could not be saved', `${host}: save refusal shown in editor`, log);
await assertName(c, 'Home draft', `${host}: name draft retained`, log);
await assertName(c, 'wss://home.test/connect', `${host}: address draft retained`, log);
await capture(c, output, log, `${host}-failure-draft`);
await click(c, 'Save server');
await assertName(c, 'Selected server', `${host}: retry succeeds`, log);
assert.equal(await c.evaluate('globalThis.serverEditorSaveAttempts'), 2);
assert.ok(!(await axNodes(c)).some(node => node.role?.value === 'textbox'));
await capture(c, output, log, `${host}-retry-saved`);
}
console.log(JSON.stringify(log, null, 2));
} catch (error) {
if (c) {
await capture(c, output, log, 'failure');
await writeFile(join(output, 'failure-ax.json'), JSON.stringify(await axNodes(c), null, 2));
}
throw error;
} finally {
await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2));
c?.close();
const exited = once(chrome, 'exit');
chrome.kill();
await exited;
await new Promise(done => fixture.server.close(done));
}