Skip to content

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

Remember which licence a finished write left on disk

Sebastien Tardifca422763d7b1
diff --git a/connector/src/licence.ts b/connector/src/licence.ts
index aa66ec28b9..ad929b4c34 100644
--- a/connector/src/licence.ts
+++ b/connector/src/licence.ts
@@ -122,7 +122,10 @@ export class LicenceDelivery {
try { this.options.record({ event: "licence", what: "failed", by: "admin", fingerprint }); } catch { /* the log said why already */ }
return this.failed(licence, errorText(error));
}
- if (this.wanted !== licence) return;
+ if (this.wanted !== licence) {
+ if (state === "written" || state === "same") this.settled = { licence, at: this.now() };
+ return;
+ }
if (this.settle(licence, state) && state === "written") this.options.log(`saved the licence MausBot sent (${fingerprint}) to the server's data folder`);
}
}
diff --git a/connector/test/customer-run.test.ts b/connector/test/customer-run.test.ts
index efea52badd..0db2d8ee5d 100644
--- a/connector/test/customer-run.test.ts
+++ b/connector/test/customer-run.test.ts
@@ -483,6 +483,31 @@ describe("a customer-run server: its licence", () => {
expect(written).toEqual([RENEWED]);
});
+ it("writes the wanted licence back when an older write lands after it was asked for again", async () => {
+ let clock = 1_800_000_000_000;
+ let finishRenewed: (() => void) | null = null;
+ const written: string[] = [];
+ const home = {
+ licenceProof: null as string | null,
+ licenceFile(mode: "check" | "write", licence: string): Promise<LicenceFileState> {
+ if (mode === "check") return Promise.resolve(licence === LICENCE && !written.includes(RENEWED) ? "same" : "differs");
+ if (licence === RENEWED) return new Promise((resolve) => { finishRenewed = () => { written.push(RENEWED); resolve("written"); }; });
+ written.push(licence);
+ return Promise.resolve("written");
+ },
+ };
+ const delivery = new LicenceDelivery({ home, log: () => {}, record: () => {}, now: () => clock, recheckMs: 60 * 60_000 });
+ await delivery.offer(LICENCE);
+ const renewing = delivery.offer(RENEWED);
+ for (let i = 0; i < 8 && !finishRenewed; i++) await Promise.resolve();
+ const again = delivery.offer(LICENCE);
+ finishRenewed!();
+ await renewing;
+ await again;
+ await delivery.tick();
+ expect(written).toEqual([RENEWED, LICENCE]);
+ });
+
it("saves it while remote management is paused: a licence is not a job on the server's bots", async () => {
const fixture = await delivering({ paused: true });
expect(fixture.state.paused()).toBe(true);