Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

test: assert storage validation errors (#10798)

Shahmir Varqha4b6bd21f47ac
diff --git a/frontend/.oxlintrc.json b/frontend/.oxlintrc.json
index 32d367b6ad..41430a85e8 100644
--- a/frontend/.oxlintrc.json
+++ b/frontend/.oxlintrc.json
@@ -78,7 +78,6 @@
{ "additionalTestBlockFunctions": ["beforeEach"] }
],
"vitest/prefer-snapshot-hint": "off",
- "vitest/require-to-throw-message": "off",
"vitest/valid-expect": "off",
// === Core rules ===
diff --git a/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts b/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts
index 08b85359a7..ed8ed63822 100644
--- a/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts
+++ b/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts
@@ -757,19 +757,23 @@ describe("generateDatabaseCode", () => {
() =>
// @ts-expect-error - Testing invalid input
generateDatabaseCode(basePostgres, "polars"),
+ "Unsupported library: polars",
],
[
"throws for invalid port",
() => generateDatabaseCode({ ...basePostgres, port: -1 }, "sqlmodel"),
+ /port/i,
],
[
"throws for invalid host",
() => generateDatabaseCode({ ...basePostgres, host: "" }, "sqlmodel"),
+ /host/i,
],
[
"throws for port out of range",
() =>
generateDatabaseCode({ ...basePostgres, port: 65_536 }, "sqlmodel"),
+ /port/i,
],
[
"throws for invalid snowflake account",
@@ -778,6 +782,7 @@ describe("generateDatabaseCode", () => {
{ ...snowflakeConnection, account: "" },
"sqlmodel",
),
+ /account/i,
],
[
"throws for invalid bigquery project",
@@ -786,9 +791,10 @@ describe("generateDatabaseCode", () => {
{ ...bigqueryConnection, project: "" },
"sqlmodel",
),
+ /project/i,
],
- ])("%s", (_name, fn) => {
- expect(fn).toThrow();
+ ])("%s", (_name, fn, error) => {
+ expect(fn).toThrow(error);
});
});
});
diff --git a/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts b/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts
index 4d515fb94c..9f9fd1e0c7 100644
--- a/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts
+++ b/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts
@@ -412,7 +412,7 @@ describe("generateStorageCode", () => {
generateStorageCode({ type: "s3", bucket: "" } as StorageConnection, {
library: "obstore",
}),
- ).toThrow();
+ ).toThrow(/bucket/);
});
it("throws for empty GCS bucket", () => {
@@ -420,7 +420,7 @@ describe("generateStorageCode", () => {
generateStorageCode({ type: "gcs", bucket: "" } as StorageConnection, {
library: "obstore",
}),
- ).toThrow();
+ ).toThrow(/bucket/);
});
it("throws for empty Azure container", () => {
@@ -433,7 +433,7 @@ describe("generateStorageCode", () => {
} as StorageConnection,
{ library: "obstore" },
),
- ).toThrow();
+ ).toThrow(/container/);
});
it("throws for empty Azure account name", () => {
@@ -446,7 +446,7 @@ describe("generateStorageCode", () => {
} as StorageConnection,
{ library: "obstore" },
),
- ).toThrow();
+ ).toThrow(/account_name/);
});
it("throws for empty CoreWeave bucket", () => {
@@ -459,7 +459,7 @@ describe("generateStorageCode", () => {
} as StorageConnection,
{ library: "obstore" },
),
- ).toThrow();
+ ).toThrow(/bucket/);
});
it("throws for empty CoreWeave region", () => {
@@ -472,7 +472,7 @@ describe("generateStorageCode", () => {
} as StorageConnection,
{ library: "obstore" },
),
- ).toThrow();
+ ).toThrow(/region/);
});
it("throws for empty GitHub org", () => {
@@ -481,7 +481,7 @@ describe("generateStorageCode", () => {
{ type: "github", org: "", repo: "marimo" } as StorageConnection,
{ library: "fsspec" },
),
- ).toThrow();
+ ).toThrow(/org/);
});
it("throws for empty GitHub repo", () => {
@@ -494,7 +494,7 @@ describe("generateStorageCode", () => {
} as StorageConnection,
{ library: "fsspec" },
),
- ).toThrow();
+ ).toThrow(/repo/);
});
it("throws when GitHub username is set without token", () => {
@@ -508,7 +508,7 @@ describe("generateStorageCode", () => {
},
{ library: "fsspec" },
),
- ).toThrow();
+ ).toThrow(/token/);
});
it("throws when GitHub token is set without username", () => {
@@ -522,7 +522,7 @@ describe("generateStorageCode", () => {
},
{ library: "fsspec" },
),
- ).toThrow();
+ ).toThrow("Username and access token are required together");
});
});
});
diff --git a/frontend/src/core/ai/__tests__/staged-cells.test.ts b/frontend/src/core/ai/__tests__/staged-cells.test.ts
index 623ac3d110..2b2301efcd 100644
--- a/frontend/src/core/ai/__tests__/staged-cells.test.ts
+++ b/frontend/src/core/ai/__tests__/staged-cells.test.ts
@@ -592,7 +592,7 @@ describe("staged cell generation", () => {
type: "data-notebook-cells-completion",
data: { cells },
}),
- ).toThrow();
+ ).toThrow(/cells/i);
});
it("should create cells from a validated completion", () => {
diff --git a/frontend/src/core/ai/__tests__/stream-completion-text.test.ts b/frontend/src/core/ai/__tests__/stream-completion-text.test.ts
index a2d64c4d09..40b08e649a 100644
--- a/frontend/src/core/ai/__tests__/stream-completion-text.test.ts
+++ b/frontend/src/core/ai/__tests__/stream-completion-text.test.ts
@@ -44,7 +44,7 @@ describe("streamCompletionText", () => {
data: { code: 42 },
});
- await expect(streamCompletionText(response)).rejects.toThrow();
+ await expect(streamCompletionText(response)).rejects.toThrow(/code/);
});
it("rejects a partial completion without successful final validation", async () => {
diff --git a/frontend/src/core/runtime/__tests__/runtime.test.ts b/frontend/src/core/runtime/__tests__/runtime.test.ts
index 7710178c8e..f2b2eb09c2 100644
--- a/frontend/src/core/runtime/__tests__/runtime.test.ts
+++ b/frontend/src/core/runtime/__tests__/runtime.test.ts
@@ -698,7 +698,7 @@ describe("RuntimeManager", () => {
it("should throw for invalid URLs", () => {
expect(() => {
new RuntimeManager({ url: "not-a-url", lazy: true });
- }).toThrow();
+ }).toThrow("Invalid runtime URL");
});
it("should handle http to ws conversion correctly", () => {
diff --git a/frontend/src/core/static/__tests__/files.test.ts b/frontend/src/core/static/__tests__/files.test.ts
index a63296616b..9c06f76f1c 100644
--- a/frontend/src/core/static/__tests__/files.test.ts
+++ b/frontend/src/core/static/__tests__/files.test.ts
@@ -177,7 +177,7 @@ describe("patchFetch", () => {
.mockImplementation(Functions.NOOP);
// This should fallback to original fetch and potentially fail
- await expect(window.fetch("invalid://url")).rejects.toThrow();
+ await expect(window.fetch("invalid://url")).rejects.toThrow(/fetch|url/i);
unpatch();
loggerSpy.mockRestore();
@@ -276,7 +276,9 @@ describe("patchVegaLoader - loader.load", () => {
it("should handle missing virtual files gracefully in loader.load", async () => {
const loader = createLoader();
const unpatch = patchVegaLoader(loader, {});
- await expect(loader.load("/non-existent-file.json")).rejects.toThrow();
+ await expect(loader.load("/non-existent-file.json")).rejects.toThrow(
+ /fetch|file|load/i,
+ );
unpatch();
});
@@ -592,9 +594,9 @@ describe("maybeGetVirtualFile utility function", () => {
const unpatch = patchFetch(virtualFiles);
// This file:// URL doesn't contain @file/, so it should fallback to original fetch
- await expect(
- window.fetch("file:///simple/path/test.txt"),
- ).rejects.toThrow();
+ await expect(window.fetch("file:///simple/path/test.txt")).rejects.toThrow(
+ /fetch|file/i,
+ );
unpatch();
});
diff --git a/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts b/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts
index 8007998d2f..f9047d7ea2 100644
--- a/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts
+++ b/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts
@@ -99,7 +99,9 @@ describe("WidgetRegistry models", () => {
const model = new Model<ModelState>({ count: 0 }, createMockComm());
registry.setModel(testId, model);
registry.delete(testId);
- await expect(registry.getModel(testId)).rejects.toThrow();
+ await expect(registry.getModel(testId)).rejects.toThrow(
+ `Model not found for key: ${testId}`,
+ );
});
it("should handle widget messages", async () => {
@@ -148,7 +150,9 @@ describe("WidgetRegistry models", () => {
model_id: testId,
message: { method: "close" },
});
- await expect(registry.getModel(testId)).rejects.toThrow();
+ await expect(registry.getModel(testId)).rejects.toThrow(
+ `Model not found for key: ${testId}`,
+ );
});
describe("static mode", () => {
diff --git a/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts b/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts
index a5119c450c..186e05256e 100644
--- a/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts
+++ b/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts
@@ -116,7 +116,7 @@ describe("WidgetDefRegistry", () => {
it("should remove from cache on import failure so retry creates new promise", async () => {
const promise1 = getModule(registry, "http://localhost/a.js", "fail-hash");
// The URL is rejected by the trusted-URL validator.
- await expect(promise1).rejects.toThrow();
+ await expect(promise1).rejects.toThrow(/untrusted/i);
// After failure, cache should be cleared, so next call creates a new promise
const promise2 = getModule(registry, "http://localhost/a.js", "fail-hash");
expect(promise1).not.toBe(promise2);
diff --git a/frontend/src/utils/__tests__/arrays.test.ts b/frontend/src/utils/__tests__/arrays.test.ts
index e50783ee94..d0da77e195 100644
--- a/frontend/src/utils/__tests__/arrays.test.ts
+++ b/frontend/src/utils/__tests__/arrays.test.ts
@@ -106,7 +106,7 @@ describe("arrays", () => {
});
it("should throw for arrays of different lengths", () => {
- expect(() => Arrays.zip([1, 2], ["a"])).toThrow();
+ expect(() => Arrays.zip([1, 2], ["a"])).toThrow(/same length/i);
});
it("should handle empty arrays", () => {
diff --git a/frontend/src/utils/__tests__/id-tree.test.ts b/frontend/src/utils/__tests__/id-tree.test.ts
index 9186ca987d..7c4f2b9c14 100644
--- a/frontend/src/utils/__tests__/id-tree.test.ts
+++ b/frontend/src/utils/__tests__/id-tree.test.ts
@@ -558,7 +558,9 @@ describe("CollapsibleTree", () => {
expect(collapsed.after("four")).toBeUndefined();
// Should throw for collapsed children that aren't top-level
- expect(() => collapsed.after("three")).toThrow();
+ expect(() => collapsed.after("three")).toThrow(
+ "Node three not found in tree. Valid ids: one,two,four",
+ );
});
it("handles before correctly", () => {
@@ -585,7 +587,9 @@ describe("CollapsibleTree", () => {
expect(collapsed.before("one")).toBeUndefined();
// Should throw for collapsed children that aren't top-level
- expect(() => collapsed.before("three")).toThrow();
+ expect(() => collapsed.before("three")).toThrow(
+ "Node three not found in tree. Valid ids: one,two,four",
+ );
});
it("handles slice on empty tree", () => {
@@ -704,8 +708,8 @@ describe("CollapsibleTree edge cases", () => {
expect(tree.first()).toBe("A");
expect(tree.last()).toBe("D");
tree = CollapsibleTree.from([]);
- expect(() => tree.first()).toThrow();
- expect(() => tree.last()).toThrow();
+ expect(() => tree.first()).toThrow("Node at index 0 not found in tree");
+ expect(() => tree.last()).toThrow("Node at index -1 not found in tree");
});
it("handles inOrderIds with nested structure", () => {
@@ -1045,7 +1049,9 @@ describe("MultiColumn", () => {
"Cell Z1 not found in any column",
);
expect(multiColumn.colLength).toBeGreaterThan(2);
- expect(() => multiColumn.delete("123" as CellColumnId)).toThrow();
+ expect(() => multiColumn.delete("123" as CellColumnId)).toThrow(
+ /Column 123 not found/,
+ );
});
it("checks if it's empty", () => {
@@ -1070,7 +1076,7 @@ describe("MultiColumn", () => {
expect(multiColumn.at(1)?.topLevelIds).toEqual(["B1", "B2"]);
expect(multiColumn.atOrThrow(1).topLevelIds).toEqual(["B1", "B2"]);
expect(multiColumn.at(5)).toBeUndefined();
- expect(() => multiColumn.atOrThrow(5)).toThrow();
+ expect(() => multiColumn.atOrThrow(5)).toThrow("Column 5 not found");
});
it("handles moving the last item in a column", () => {
diff --git a/frontend/src/utils/__tests__/semaphore.test.ts b/frontend/src/utils/__tests__/semaphore.test.ts
index c0e4ef2d22..7761852dd9 100644
--- a/frontend/src/utils/__tests__/semaphore.test.ts
+++ b/frontend/src/utils/__tests__/semaphore.test.ts
@@ -5,9 +5,15 @@ import { mapWithConcurrency, Semaphore } from "../semaphore";
describe("Semaphore", () => {
it("rejects invalid permit counts", () => {
- expect(() => new Semaphore(0)).toThrow();
- expect(() => new Semaphore(-1)).toThrow();
- expect(() => new Semaphore(1.5)).toThrow();
+ expect(() => new Semaphore(0)).toThrow(
+ "Semaphore permits must be a positive integer, got 0",
+ );
+ expect(() => new Semaphore(-1)).toThrow(
+ "Semaphore permits must be a positive integer, got -1",
+ );
+ expect(() => new Semaphore(1.5)).toThrow(
+ "Semaphore permits must be a positive integer, got 1.5",
+ );
});
it("resolves run() with the function's value", async () => {
@@ -203,8 +209,12 @@ describe("mapWithConcurrency", () => {
});
it("throws on invalid concurrency, even for empty input", () => {
- expect(() => mapWithConcurrency([1, 2, 3], 0, async (n) => n)).toThrow();
- expect(() => mapWithConcurrency([], 0, async (n: number) => n)).toThrow();
+ expect(() => mapWithConcurrency([1, 2, 3], 0, async (n) => n)).toThrow(
+ "Semaphore permits must be a positive integer, got 0",
+ );
+ expect(() => mapWithConcurrency([], 0, async (n: number) => n)).toThrow(
+ "Semaphore permits must be a positive integer, got 0",
+ );
});
it("passes the index to fn", async () => {
diff --git a/frontend/src/utils/__tests__/strings.test.ts b/frontend/src/utils/__tests__/strings.test.ts
index 1948cc3926..80bc249df5 100644
--- a/frontend/src/utils/__tests__/strings.test.ts
+++ b/frontend/src/utils/__tests__/strings.test.ts
@@ -20,7 +20,9 @@ describe("Strings", () => {
});
it("throws for non-string input", () => {
- expect(() => Strings.startCase(123 as unknown as string)).toThrow();
+ expect(() => Strings.startCase(123 as unknown as string)).toThrow(
+ /string/i,
+ );
});
});