Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Always-on home: pin main's wiring and lending's test, stop a first-start retry once ready

milind-soniba564d780eea
diff --git a/electron/always-on-login.node-test.mjs b/electron/always-on-login.node-test.mjs
index 6740b8514f..66b043d4db 100644
--- a/electron/always-on-login.node-test.mjs
+++ b/electron/always-on-login.node-test.mjs
@@ -63,8 +63,8 @@ test("Windows: the person's earlier Off is put back when the switch goes off", t
w.home.set(true);
assert.deepEqual(w.names(), [CHOSEN]);
assert.equal(w.declined(), false);
- w.home.set(false);
- assert.equal(w.declined(), true);
+ w.make().set(false);
+ assert.equal(w.declined(), true, "what it saved is still known after a restart");
w.lend(true);
assert.deepEqual(w.names(), [], "lending still adds nothing, as before the switch");
});
diff --git a/electron/server-supervisor.mjs b/electron/server-supervisor.mjs
index 0ce52ae6be..f6182958fa 100644
--- a/electron/server-supervisor.mjs
+++ b/electron/server-supervisor.mjs
@@ -85,11 +85,11 @@ export function createServerSupervisor({
/** A first start that never got ready (every port taken after a power cut, say), on an always-on home: `start()`, true
* once it is ready, again after each long wait while `keepTrying()`; not while an earlier child is still owned. */
function startLater(start) {
- if (stopped || paused || timer || !keepTrying()) return false;
+ if (stopped || paused || timer || readySince !== null || !keepTrying()) return false;
log(`server start: always-on home, trying again in ${longRetryMs}ms`);
timer = setTimeout(async () => {
timer = null;
- if (stopped || paused) return;
+ if (stopped || paused || readySince !== null) return;
if (current === null) {
let started = false;
try { started = await start(); } catch (error) { log(`server start failed: ${error?.message ?? error}`); }
diff --git a/electron/server-supervisor.node-test.mjs b/electron/server-supervisor.node-test.mjs
index cb4c21c2a0..d118fc32a0 100644
--- a/electron/server-supervisor.node-test.mjs
+++ b/electron/server-supervisor.node-test.mjs
@@ -154,6 +154,26 @@ test("an always-on home whose first start never got ready tries again after the
assert.equal(f.supervisor.startLater(start), false, "not an always-on home: nothing waits");
});
+test("a first start's retry ends once a server got ready some other way", async (t) => {
+ let starts = 0;
+ const f = fixture(t, { keepTrying: () => true, longRetryMs: 500 });
+ f.supervisor.startLater(async () => { starts++; return false; });
+ f.supervisor.ready(f.spawn());
+ await f.tick(500);
+ await settle();
+ await f.tick(5000);
+ await settle();
+ assert.equal(starts, 0);
+ assert.equal(f.supervisor.startLater(async () => true), false, "nothing to start");
+});
+
+test("main wires the always-on home: lending's own test, the first start's retry and the error page's line", () => {
+ assert.match(MAIN_SOURCE, /installAlwaysOnHome\(\{[^}]*lending: \(\) => computerSharing\?\.lendingSomewhere\(\) === true/);
+ assert.match(MAIN_SOURCE, /keepTrying: \(\) => alwaysOnHome\.on\(\)/);
+ assert.match(MAIN_SOURCE, /if \(!serverReady && !desktopShutdownStarted\) serverSupervisor\.startLater\(startServerPackaged\);/);
+ assert.match(MAIN_SOURCE, /buildErrorPage\(\{ allPortsOccupied: serverStartConflictOnly, logDir: LOG_DIR, keepTrying: alwaysOnHome\.on\(\) \}/);
+});
+
test("only a stable ready uptime resets the recovery budget", async (t) => {
const f = fixture(t);
f.supervisor.ready(f.spawn());
diff --git a/electron/sharing-persistence.node-test.mjs b/electron/sharing-persistence.node-test.mjs
index 825d8a1f02..eb86432f11 100644
--- a/electron/sharing-persistence.node-test.mjs
+++ b/electron/sharing-persistence.node-test.mjs
@@ -64,6 +64,22 @@ test("a failed Pause save stops active sharing and reports that the pause is not
assert.match(f.summaries.at(-1).pauseError, /not saved/i);
});
+test("lendingSomewhere: anything lent, running or not, to a Cloud or a server of the person's own; nothing while paused", t => {
+ const f = fixture(t), sharing = f.make();
+ assert.equal(sharing.lendingToCloud(), false, "not running");
+ assert.equal(sharing.lendingSomewhere(), true, "still lent, so its login item stays");
+ sharing.pause();
+ assert.equal(sharing.lendingSomewhere(), false);
+ sharing.close();
+ const saved = f.saved();
+ const [id] = Object.keys(saved.records);
+ const { cloud: _cloud, ...grant } = saved.records[id];
+ fs.writeFileSync(f.file, JSON.stringify({ ...saved, records: { [id]: { ...grant, own: true } }, automatic: { paused: false } }));
+ assert.equal(f.make().lendingSomewhere(), true, "a server of the person's own");
+ fs.writeFileSync(f.file, JSON.stringify({ ...saved, records: {}, automatic: { paused: false } }));
+ assert.equal(f.make().lendingSomewhere(), false, "nothing lent");
+});
+
test("Pause retries a failed save while sharing stays paused", async t => {
const f = fixture(t), sharing = f.make();
f.block();