Skip to content

Commit b8dc30a

Browse files
committed
test: avoid cold startup migration timeout
1 parent c7714f4 commit b8dc30a

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/infra/state-migrations.restart-sentinel.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import {
2121
writeRestartSentinel,
2222
type RestartSentinelPayload,
2323
} from "./restart-sentinel.js";
24-
import {
25-
autoMigrateLegacyState,
26-
resetAutoMigrateLegacyStateForTest,
27-
} from "./state-migrations.doctor.js";
2824
import {
2925
detectLegacyRestartSentinel,
3026
migrateLegacyRestartSentinel,
@@ -38,7 +34,6 @@ type MigrationDatabase = Pick<
3834
describe("legacy restart sentinel migration", () => {
3935
const tempDirs = useAutoCleanupTempDirTracker((cleanup) => {
4036
afterEach(() => {
41-
resetAutoMigrateLegacyStateForTest();
4237
closeOpenClawStateDatabaseForTest();
4338
cleanup();
4439
});
@@ -176,21 +171,6 @@ describe("legacy restart sentinel migration", () => {
176171
});
177172
});
178173

179-
it("runs the same migration owner during automatic startup preflight", async () => {
180-
const { env, stateDir } = useStateDir();
181-
const expected = payload(321);
182-
const sourcePath = await writeLegacy(stateDir, { version: 1, payload: expected });
183-
184-
const result = await autoMigrateLegacyState({ cfg: {}, env });
185-
186-
expect(result.warnings).toEqual([]);
187-
expect(result.changes).toContain(
188-
"Imported the legacy restart sentinel into shared SQLite state.",
189-
);
190-
await expect(readRestartSentinel(env)).resolves.toMatchObject({ payload: expected });
191-
expect(fs.existsSync(sourcePath)).toBe(false);
192-
});
193-
194174
it("preserves a valid canonical row when legacy JSON conflicts", async () => {
195175
const { env, stateDir } = useStateDir();
196176
const canonical = payload(999);

src/infra/state-migrations.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
listWebPushSubscriptions,
2929
readPersistedVapidKeyPair,
3030
} from "./push-web-store.js";
31+
import { readRestartSentinel } from "./restart-sentinel.js";
3132
import {
3233
autoMigrateLegacyState,
3334
autoMigrateLegacyPluginDoctorState,
@@ -1729,7 +1730,7 @@ describe("state migrations", () => {
17291730
await expect(fs.readFile(`${routingPath}.migrated`, "utf8")).resolves.toContain("robot wake");
17301731
});
17311732

1732-
it("auto-migrates standalone legacy voice wake JSON settings", async () => {
1733+
it("auto-migrates standalone legacy JSON settings", async () => {
17331734
const root = await createTempDir();
17341735
const stateDir = path.join(root, ".openclaw");
17351736
const env = createEnv(stateDir);
@@ -1741,14 +1742,31 @@ describe("state migrations", () => {
17411742
JSON.stringify({ triggers: ["wake"] }),
17421743
"utf8",
17431744
);
1745+
const expectedSentinel = {
1746+
kind: "update" as const,
1747+
status: "ok" as const,
1748+
ts: 321,
1749+
message: "Update completed",
1750+
};
1751+
const restartSentinelPath = path.join(stateDir, "restart-sentinel.json");
1752+
await fs.writeFile(
1753+
restartSentinelPath,
1754+
`${JSON.stringify({ version: 1, payload: expectedSentinel })}\n`,
1755+
"utf8",
1756+
);
17441757

17451758
const result = await autoMigrateLegacyState({ cfg, env, homedir: () => root });
17461759

17471760
expect(result.skipped).toBe(false);
17481761
expect(result.migrated).toBe(true);
17491762
expect(result.warnings).toStrictEqual([]);
1763+
expect(result.changes).toContain(
1764+
"Imported the legacy restart sentinel into shared SQLite state.",
1765+
);
17501766
await expect(loadVoiceWakeConfig(stateDir)).resolves.toMatchObject({ triggers: ["wake"] });
1767+
await expect(readRestartSentinel(env)).resolves.toMatchObject({ payload: expectedSentinel });
17511768
await expectMissingPath(path.join(settingsDir, "voicewake.json"));
1769+
await expectMissingPath(restartSentinelPath);
17521770
});
17531771

17541772
it("runs plugin doctor migrations after repairing shared state schema", async () => {

0 commit comments

Comments
 (0)