Skip to content

Commit 3dd2c1a

Browse files
committed
test: guard plugin diagnostic assertions
1 parent eafdbe8 commit 3dd2c1a

7 files changed

Lines changed: 20 additions & 10 deletions

src/plugins/contracts/host-hooks.contract.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ function diagnosticSummaries(diagnostics: readonly unknown[]) {
7676
}
7777

7878
function expectRecordFields(record: unknown, expected: Record<string, unknown>) {
79-
expect(record).toBeDefined();
79+
if (!record || typeof record !== "object") {
80+
throw new Error("Expected record");
81+
}
8082
const actual = record as Record<string, unknown>;
8183
for (const [key, value] of Object.entries(expected)) {
8284
expect(actual[key]).toEqual(value);

src/plugins/contracts/scheduled-turns.contract.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ function mockCronAdd(response: CronJob) {
131131

132132
function getCronAddBody() {
133133
const addCall = workflowMocks.cronAdd.mock.calls[0];
134-
expect(addCall).toBeDefined();
135-
return addCall?.[0] as CronJobCreate;
134+
if (!addCall) {
135+
throw new Error("Expected cron add call");
136+
}
137+
return addCall[0] as CronJobCreate;
136138
}
137139

138140
function expectSessionTurnHandle(

src/plugins/discovery.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ function expectCandidateFields(
343343
| undefined,
344344
expected: Record<string, unknown>,
345345
) {
346-
expect(candidate).toBeDefined();
347346
if (!candidate) {
348347
throw new Error("Expected plugin candidate");
349348
}
@@ -1869,7 +1868,9 @@ describe("discoverOpenClawPlugins", () => {
18691868
(entry.source ?? "").endsWith("alias-dir") &&
18701869
entry.message.includes("blocked plugin candidate: world-writable path"),
18711870
);
1872-
expect(diagnostic).toBeDefined();
1871+
if (!diagnostic) {
1872+
throw new Error("Expected world-writable plugin candidate diagnostic");
1873+
}
18731874
} finally {
18741875
fs.chmodSync(pluginDir, 0o755);
18751876
}

src/plugins/manifest-registry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ function expectDiagnosticFields(
175175
}
176176
return true;
177177
});
178-
expect(diagnostic, `diagnostic ${expected.messageIncludes ?? ""}`).toBeDefined();
178+
if (!diagnostic) {
179+
throw new Error(`Expected diagnostic ${expected.messageIncludes ?? ""}`);
180+
}
179181
}
180182

181183
function prepareLinkedManifestFixture(params: { id: string; mode: "symlink" | "hardlink" }): {

src/plugins/plugin-registry-snapshot.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ function requirePluginRecord(
9696
pluginId: string,
9797
): InstalledPluginIndex["plugins"][number] {
9898
const plugin = plugins.find((candidate) => candidate.pluginId === pluginId);
99-
expect(plugin, `plugin ${pluginId}`).toBeDefined();
10099
if (!plugin) {
101100
throw new Error(`expected plugin ${pluginId}`);
102101
}

src/plugins/uninstall.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ async function expectPathAccessState(pathToCheck: string, expected: "exists" | "
246246

247247
function expectNpmUninstallCommand(params: { packageName: string; npmRoot: string }) {
248248
const command = runCommandWithTimeoutMock.mock.calls[0];
249-
expect(command).toBeDefined();
250-
expect(command?.[0]).toEqual([
249+
if (!command) {
250+
throw new Error("Expected npm uninstall command");
251+
}
252+
expect(command[0]).toEqual([
251253
"npm",
252254
"uninstall",
253255
"--loglevel=error",

src/plugins/update.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ describe("updateNpmInstalledPlugins", () => {
766766
"dist.shasum",
767767
"--json",
768768
]);
769-
expect(npmViewCall()?.[1]).toBeDefined();
769+
if (npmViewCall()?.[1] === undefined) {
770+
throw new Error("Expected npm view command options");
771+
}
770772
expect(installPluginFromNpmSpecMock).not.toHaveBeenCalled();
771773
expect(result.changed).toBe(false);
772774
expect(result.config).toBe(config);

0 commit comments

Comments
 (0)