Skip to content

Commit eda8ff2

Browse files
committed
refactor(appkit): let the framework own ai-search missing-resource policy
setup()'s indexName-presence check duplicated the framework's resource validation, which already warns-in-dev / throws-in-prod for a missing DATABRICKS_VS_INDEX_NAME and runs before setup(). The inline NODE_ENV gate was therefore redundant, its prod-throw branch was unreachable in the real createApp flow, and it silently ignored APPKIT_STRICT_VALIDATION (which the registry honors). Drop it and keep only the pagination -> endpointName check, a config logic error the registry can't see. Unresolved aliases still 404 on the routes and throw in query(). Removes the two now-obsolete setup() tests. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
1 parent e13f60a commit eda8ff2

2 files changed

Lines changed: 4 additions & 37 deletions

File tree

packages/appkit/src/plugins/ai-search/ai-search.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,11 @@ export class AiSearchPlugin extends Plugin<IAiSearchConfig> {
4444
}
4545

4646
async setup(): Promise<void> {
47-
const isDev = process.env.NODE_ENV === "development";
47+
// A missing indexName is a missing-resource condition owned by the
48+
// framework's resource validation (warn in dev, throw in prod). Only the
49+
// pagination -> endpointName dependency is a config logic error the
50+
// framework can't see, so it's the sole check here.
4851
for (const [alias, idx] of Object.entries(this.config.indexes ?? {})) {
49-
// A missing indexName is a missing-resource condition, which the
50-
// framework's resource validation already reports (warn in dev, throw
51-
// in prod). Mirror that policy here instead of hard-crashing dev.
52-
if (!this._resolveIndex(alias)) {
53-
const message = `Index "${alias}" has no indexName (set it in config or via DATABRICKS_VS_INDEX_NAME)`;
54-
if (isDev) {
55-
logger.warn(message);
56-
continue;
57-
}
58-
throw new Error(message);
59-
}
60-
// A config logic error, not a missing resource — always fail fast.
6152
if (idx.pagination && !idx.endpointName) {
6253
throw new Error(
6354
`Index "${alias}" has pagination enabled but is missing "endpointName"`,

packages/appkit/src/plugins/ai-search/tests/ai-search.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,12 @@ describe("AiSearchPlugin", () => {
111111

112112
describe("setup()", () => {
113113
const originalIndexEnv = process.env.DATABRICKS_VS_INDEX_NAME;
114-
const originalNodeEnv = process.env.NODE_ENV;
115114
afterEach(() => {
116115
if (originalIndexEnv === undefined) {
117116
delete process.env.DATABRICKS_VS_INDEX_NAME;
118117
} else {
119118
process.env.DATABRICKS_VS_INDEX_NAME = originalIndexEnv;
120119
}
121-
process.env.NODE_ENV = originalNodeEnv;
122-
});
123-
124-
it("throws outside dev if indexName is unset in both config and env", async () => {
125-
delete process.env.DATABRICKS_VS_INDEX_NAME;
126-
process.env.NODE_ENV = "production";
127-
const plugin = new AiSearchPlugin({
128-
indexes: {
129-
test: { columns: ["id"] },
130-
},
131-
});
132-
await expect(plugin.setup()).rejects.toThrow("indexName");
133-
});
134-
135-
it("only warns (does not throw) for a missing indexName in dev", async () => {
136-
delete process.env.DATABRICKS_VS_INDEX_NAME;
137-
process.env.NODE_ENV = "development";
138-
const plugin = new AiSearchPlugin({
139-
indexes: {
140-
test: { columns: ["id"] },
141-
},
142-
});
143-
await expect(plugin.setup()).resolves.not.toThrow();
144120
});
145121

146122
it("defaults indexName from DATABRICKS_VS_INDEX_NAME when omitted", async () => {

0 commit comments

Comments
 (0)