Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

fix(connectors): stop reporting a never-written connectors.json as removed

Alan Buscaglia1275f27681f0
diff --git a/packages/daemon/src/connectors.ts b/packages/daemon/src/connectors.ts
index 5318e5f..a5499a7 100644
--- a/packages/daemon/src/connectors.ts
+++ b/packages/daemon/src/connectors.ts
@@ -840,6 +840,11 @@ export class ConnectorStore {
this.log("connectors.json was signed before and is missing; starting with no connectors");
this.onSetAside(MISSING_NOTICE);
}
+ // The empty record is signed in its place: the next start verifies it instead of reporting a
+ // file that never existed (a fresh install) or one already reported.
+ this.edited = true;
+ mkdirSync(this.options.dataDir, { recursive: true, mode: 0o700 });
+ writePrivateFile(this.file, this.recordText());
return;
}
const record = this.loaded.record;
diff --git a/packages/daemon/test/computer.test.ts b/packages/daemon/test/computer.test.ts
index 4727270..10d476f 100644
--- a/packages/daemon/test/computer.test.ts
+++ b/packages/daemon/test/computer.test.ts
@@ -140,7 +140,8 @@ describe("computer control registration (S24.7)", () => {
await new Promise((resolve) => setTimeout(resolve, 1300));
expect(logs.filter((line) => line.includes("put back"))).toEqual([]);
expect(messages.filter((m) => m.type === "toast")).toEqual([]);
- expect(existsSync(join(dataDir, "connectors.json"))).toBe(false);
+ // The first integrity check writes an empty signed connectors.json; it still holds no connector.
+ expect(JSON.parse(readFileSync(join(dataDir, "connectors.json"), "utf8")).connectors).toEqual({});
});
it("renders the helper as a built-in direct server with the key in its header, and the key goes nowhere else", async () => {
diff --git a/packages/daemon/test/connector-integrity.test.ts b/packages/daemon/test/connector-integrity.test.ts
index 0348ec0..0cccf9b 100644
--- a/packages/daemon/test/connector-integrity.test.ts
+++ b/packages/daemon/test/connector-integrity.test.ts
@@ -287,6 +287,34 @@ describe("when the check itself cannot run (A1, A3, L120)", () => {
const { store, notices } = await started(dataDir, source);
expect(notices).toEqual([MISSING_NOTICE]);
expect(store.state().connectors).toEqual({});
+ // The empty record is signed in its place, so the next start verifies it and stays quiet.
+ expect(validlySigned(dataDir, source.values)).toBe(true);
+ expect(statSync(join(dataDir, "connectors.json")).mode & 0o777).toBe(0o600);
+ store.close();
+ const { store: next, notices: nextNotices } = await started(dataDir, source);
+ expect(nextNotices).toEqual([]);
+ expect(next.state().connectors).toEqual({});
+ });
+
+ it("a fresh install with no connectors.json is never reported as missing", async () => {
+ const dataDir = tempDir();
+ const source = new MemorySecretSource();
+ const first = await started(dataDir, source);
+ expect(first.notices).toEqual([]);
+ expect(first.store.state().connectors).toEqual({});
+ // The first start signs an empty record, so later starts have a file to verify.
+ expect(existsSync(join(dataDir, "connectors.json"))).toBe(true);
+ expect(validlySigned(dataDir, source.values)).toBe(true);
+ expect(readRecord(dataDir).connectors).toEqual({});
+ expect(statSync(join(dataDir, "connectors.json")).mode & 0o777).toBe(0o600);
+ first.store.close();
+ for (let start = 0; start < 2; start++) {
+ const { store, notices } = await started(dataDir, source);
+ expect(notices).toEqual([]);
+ expect(store.state().connectors).toEqual({});
+ expect(rejectedFiles(dataDir)).toEqual([]);
+ store.close();
+ }
});
});