mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-21 18:17:05 +00:00
Refactor startup lifecycle into service features
This commit is contained in:
@@ -4,8 +4,41 @@ import {
|
||||
inspectObsidianServiceContextContract,
|
||||
} from "../runner/liveSyncWorkflow.ts";
|
||||
import { startObsidianLiveSyncSession, type ObsidianLiveSyncSession } from "../runner/session.ts";
|
||||
import { withObsidianPage } from "../runner/ui.ts";
|
||||
import { createTemporaryVault } from "../runner/vault.ts";
|
||||
|
||||
const BASIC_COMMAND_IDS = [
|
||||
"livesync-replicate",
|
||||
"livesync-dump",
|
||||
"livesync-toggle",
|
||||
"livesync-suspendall",
|
||||
"livesync-scan-files",
|
||||
"livesync-runbatch",
|
||||
"livesync-abortsync",
|
||||
] as const;
|
||||
|
||||
type ObsidianCommandHost = typeof globalThis & {
|
||||
app?: { commands?: { commands?: Record<string, unknown> } };
|
||||
};
|
||||
|
||||
async function assertMenuFeaturesAreComposed(remoteDebuggingPort: number): Promise<void> {
|
||||
await withObsidianPage(remoteDebuggingPort, async (page) => {
|
||||
const registered = await page.evaluate((commandIds) => {
|
||||
const commands = (globalThis as ObsidianCommandHost).app?.commands?.commands ?? {};
|
||||
return commandIds.filter((id) => commands[`obsidian-livesync:${id}`] !== undefined);
|
||||
}, BASIC_COMMAND_IDS);
|
||||
if (registered.length !== BASIC_COMMAND_IDS.length) {
|
||||
const missing = BASIC_COMMAND_IDS.filter((id) => !registered.includes(id));
|
||||
throw new Error(`Extracted basic commands were not composed: ${missing.join(", ")}`);
|
||||
}
|
||||
|
||||
const ribbonCount = await page.locator(".livesync-ribbon-replicate").count();
|
||||
if (ribbonCount !== 1) {
|
||||
throw new Error(`Expected one extracted replication ribbon action, found ${ribbonCount}.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const binary = requireObsidianBinary();
|
||||
const cli = discoverObsidianCli();
|
||||
@@ -34,6 +67,8 @@ async function main(): Promise<void> {
|
||||
console.log(
|
||||
`Obsidian service Context contract passed: ${contextContract.contextType}, ${contextContract.serviceContextMismatches.length} mismatches.`
|
||||
);
|
||||
await assertMenuFeaturesAreComposed(session.remoteDebuggingPort);
|
||||
console.log("Extracted basic commands and replication ribbon were composed exactly once.");
|
||||
await new Promise((resolve) => setTimeout(resolve, Number(process.env.E2E_OBSIDIAN_SMOKE_TIMEOUT_MS ?? 1000)));
|
||||
console.log("Obsidian stayed alive after the plug-in readiness check.");
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user