hayden4608 on Discord syncs two computers through GitHub, both with
Codex, and wants each one's Codex default model kept apart. Until now
the agents part carried every agent field ("codex.model", effort,
provider...) as one set: A's pick went up, B's sync brought it over B's,
B's pick went up again and A's next sync took it back. The two
computers fought, and the only way out was turning "agents' models"
off for every agent.
Now a sync that brings an agent field over this computer's value
records what it brought (Brought) and what it wrote over (Replaced,
only when that was picked here, not itself brought). If the user then
sets the field back to the value the sync replaced, the field is this
computer's own (Own): it leaves the hashes, a sync no longer brings it,
and a push keeps the server's value, so the other computer is not
changed either. Every other new pick is an ordinary pick and still goes
both ways, so a computer that changes the model for everyone (and
TestSyncAgentDefaults' reset) still reaches the rest. Nothing to set
up: the user's own act on this computer decides it, and a synced value
never overrides it again.
Settings > Sync lists the kept fields in one row ("Kept on this
computer: Codex model ...") with a "Follow the others" button
(davsync/follow), which brings the server's values on the next sync and
ends the keeping. Restore brings everything and ends it too. The row is
drawn only while sync and agents' models are on and something is kept;
plain row and button, no new layout. app.js grew 623 bytes; the budgets
are raised by that with a note.
Tests:
- internal/davsync/own_model_test.go TestOwnModelStaysOnEachComputer:
two sandbox HOMEs (CODEX_HOME per computer) on the GitHub fixture.
A picks a1, B joins and gets it, B picks b1 (goes up), A gets b1, A
sets a1 back (own; the server keeps b1), B picks b2 + effort +
provider (A gets effort and provider, keeps a1), A picks a2 and a
Claude model (both go up, B gets them), A follows (gets b2), B's b3
reaches A. TestNewPicksStillGoBothWays: alternating new picks always
reach the other computer.
- internal/gui/tests/sync-own-fields.test.cjs: the row in en, zh,
zh-TW, ja, de at 420px, no overflow, Follow posts once and the row
goes, no scroll; no row without own fields or with agents off.
Broken by hand, each red: noticeOwn off (own_model_test:122); any pick
after a sync counts as own (TestSyncAgentDefaults and own test:106);
keepServersOwn off (:166); the bring ignoring Own (:146); withoutOwn
off in the hashes (:143, a notice); Follow off (:182).
Run at this head (rebased on 47173f593) on mote:
gofmt -l internal/davsync internal/gui clean; go vet ./..., GOOS=linux
go vet -tags nogui ./..., GOOS=windows go vet ./... ok; go test
./internal/davsync ok, ./internal/backup ok, ./internal/gui ok but
TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red on main) and the
eleven real-window AppKit tests (dock, panel, tray, corners), which
time out on mote at origin/main 47173f593 too (#4125, #2645);
-run 'Budget|Sync|Backup|Settings' passes TestCoreScriptBudget.
GUI (node --test): sync-own-fields, sync-note-show, github-sync,
s3-sync, sync-other-kind, sync-not-backup, sync-auto-restore,
sync-usage-error, i18n-keys. Chromium on mote: all pass but
sync-not-backup and sync-usage-error, whose chromium.launch({channel:
"chromium"}) segfaults on mote at origin/main 47173f593 too; on the
WSL box (magpie-desktop) they pass, 25 of 25 with sync-own-fields.
WebKit on mote hangs on launch for every file, untouched ones too; on
WSL all nine files ran: 49 of 52, the reds being i18n-keys' "a
plugin's words are its own" (#4524, red on main) and the first
page.goto of sync-own-fields and sync-note-show at 5s under nine
files at once, which pass run alone (9 of 9).
Red on main and not from this change: TestSettingsSaveKeepsWhatItDoesNotSend
(#4514), i18n-keys "Unmarked" (#4524).
Not tried: a real GitHub repo and a real Codex on two computers; the
CLI has no follow command (only the GUI and Restore end the keeping);
Undo after a Restore doesn't bring Own back.
112 lines
6.2 KiB
JavaScript
112 lines
6.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// An agent's field set back on a computer after a sync changed it stays that
|
|
// computer's (hayden4608 on Discord: two computers on one GitHub sync, each
|
|
// wanting its own Codex model). Settings → Sync names the fields kept here,
|
|
// in the page's language, and Follow the others gives them back to sync:
|
|
// it asks the server once, and the row goes with the fields. A sync with no
|
|
// such fields, or with agents' models off, shows no row. In every language,
|
|
// Chromium and WebKit, at a narrow width with nothing wider than the page.
|
|
// The API is faked; nothing is synced.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
const { openPart } = require("./reader.cjs");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
|
|
function serve(lang, sync, posts) {
|
|
const settings = {
|
|
theme: "light", lang, tray: "panel", version: "test", dir: "/tmp/magpie",
|
|
gateway: "http://127.0.0.1:3425", visionModels: [], imageGenModels: [],
|
|
fx: { rate: 7.2, stale: false },
|
|
};
|
|
return async (route) => {
|
|
const request = route.request();
|
|
const pathname = new URL(request.url()).pathname;
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
|
if (pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (pathname === "/api/state") return json({ agents: [], profiles: [], settings });
|
|
if (pathname === "/api/settings") return json(settings);
|
|
if (pathname === "/api/usage/quotas") return json([]);
|
|
if (pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (pathname === "/api/davsync") return json(sync);
|
|
if (pathname === "/api/davsync/follow") {
|
|
posts.push("follow");
|
|
const { own, ...rest } = sync;
|
|
return json(rest);
|
|
}
|
|
if (pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, pathname === "/" ? "index.html" : pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
return route.fulfill({ body: await fs.readFile(file), contentType });
|
|
};
|
|
}
|
|
|
|
const words = {
|
|
en: { title: "Kept on this computer", follow: "Follow the others", field: "Codex model" },
|
|
zh: { title: "仅本机保留", follow: "跟随其他电脑", field: "Codex 模型" },
|
|
"zh-TW": { title: "僅本機保留", follow: "跟隨其他電腦", field: "Codex 模型" },
|
|
ja: { title: "このコンピュータだけで保持", follow: "ほかのコンピュータに合わせる", field: "Codex のモデル" },
|
|
de: { title: "Nur auf diesem Computer", follow: "Den anderen folgen", field: "Codex: Modell" },
|
|
};
|
|
|
|
const base = () => ({ on: true, kind: "github", url: "github://alice/private/team", passwordSet: true, passphraseSet: true,
|
|
keys: true, agents: true, library: true, auto: 3, last: new Date().toISOString() });
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
const open = async (t, lang, sync, posts, width = 900) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage();
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, sync, posts));
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-sync-own-fields.png`), fullPage: true });
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(5000);
|
|
await page.goto("http://magpie.test/");
|
|
await page.locator("#prefs").click();
|
|
await openPart(page, "sync");
|
|
await page.locator("#syncList .row").first().waitFor({ state: "visible" });
|
|
return { page, errors };
|
|
};
|
|
|
|
for (const lang of Object.keys(words)) {
|
|
const w = words[lang];
|
|
test(`${engine} ${lang}: the fields kept on this computer are named, and follow the others on a click`, async (t) => {
|
|
const posts = [];
|
|
const sync = { ...base(), own: [{ agent: "Codex", field: "model" }] };
|
|
const { page, errors } = await open(t, lang, sync, posts, 420);
|
|
const row = page.locator("#syncList .row", { has: page.locator(".sync-own") });
|
|
await row.waitFor({ state: "visible" });
|
|
assert.equal((await row.locator(".name").textContent()).trim(), w.title);
|
|
assert.ok((await row.locator(".sync-own").textContent()).includes(w.field), `names ${w.field}`);
|
|
const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
|
assert.ok(over <= 0, `nothing wider than the page (${over}px over)`);
|
|
const y = await page.evaluate(() => document.scrollingElement.scrollTop);
|
|
await row.getByRole("button", { name: w.follow, exact: true }).click();
|
|
await row.waitFor({ state: "detached" });
|
|
assert.deepEqual(posts, ["follow"], "asked the server once");
|
|
assert.equal(await page.evaluate(() => document.scrollingElement.scrollTop), y, "the click moved nothing");
|
|
assert.deepEqual(errors, [], "nothing threw");
|
|
});
|
|
}
|
|
|
|
for (const [name, sync] of [["no fields kept", base()], ["agents' models off", { ...base(), agents: false, own: [{ agent: "Codex", field: "model" }] }]]) {
|
|
test(`${engine}: ${name} shows no row for them`, async (t) => {
|
|
const { page, errors } = await open(t, "en", sync, []);
|
|
assert.equal(await page.locator("#syncList .sync-own").count(), 0);
|
|
assert.equal(await page.getByText("Kept on this computer").count(), 0);
|
|
assert.deepEqual(errors, [], "nothing threw");
|
|
});
|
|
}
|
|
}
|