|
1 | 1 | import path from "node:path"; |
2 | 2 | import { Lang, parse } from "@ast-grep/napi"; |
3 | 3 | import { describe, expect, it } from "vitest"; |
| 4 | +import type { TemplatePluginsManifest } from "../manifest-types"; |
4 | 5 | import { |
| 6 | + computeResolution, |
| 7 | + enrichPluginsWithResolution, |
5 | 8 | isWithinDirectory, |
6 | 9 | parseImports, |
7 | 10 | parsePluginUsages, |
@@ -182,4 +185,121 @@ describe("plugin sync", () => { |
182 | 185 | expect(shouldAllowJsManifestForPackage("@acme/plugin")).toBe(false); |
183 | 186 | }); |
184 | 187 | }); |
| 188 | + |
| 189 | + describe("computeResolution", () => { |
| 190 | + it('returns "platform-injected" when localOnly is true', () => { |
| 191 | + expect(computeResolution({ localOnly: true })).toBe("platform-injected"); |
| 192 | + }); |
| 193 | + |
| 194 | + it('returns "platform-injected" when localOnly is true even with value and resolve', () => { |
| 195 | + expect( |
| 196 | + computeResolution({ |
| 197 | + localOnly: true, |
| 198 | + value: "5432", |
| 199 | + resolve: "postgres:host", |
| 200 | + }), |
| 201 | + ).toBe("platform-injected"); |
| 202 | + }); |
| 203 | + |
| 204 | + it('returns "static" when value is set', () => { |
| 205 | + expect(computeResolution({ value: "5432" })).toBe("static"); |
| 206 | + }); |
| 207 | + |
| 208 | + it('returns "static" for non-empty value without localOnly', () => { |
| 209 | + expect(computeResolution({ value: "require" })).toBe("static"); |
| 210 | + }); |
| 211 | + |
| 212 | + it('returns "cli-resolved" when resolve is set', () => { |
| 213 | + expect(computeResolution({ resolve: "postgres:host" })).toBe( |
| 214 | + "cli-resolved", |
| 215 | + ); |
| 216 | + }); |
| 217 | + |
| 218 | + it('returns "user-provided" when no localOnly, value, or resolve', () => { |
| 219 | + expect(computeResolution({})).toBe("user-provided"); |
| 220 | + expect( |
| 221 | + computeResolution({ env: "MY_VAR", description: "Some field" }), |
| 222 | + ).toBe("user-provided"); |
| 223 | + }); |
| 224 | + |
| 225 | + it('returns "user-provided" for empty value string', () => { |
| 226 | + expect(computeResolution({ value: "" })).toBe("user-provided"); |
| 227 | + }); |
| 228 | + }); |
| 229 | + |
| 230 | + describe("enrichPluginsWithResolution", () => { |
| 231 | + it("injects resolution on every resource field", () => { |
| 232 | + const plugins: TemplatePluginsManifest["plugins"] = { |
| 233 | + analytics: { |
| 234 | + name: "analytics", |
| 235 | + displayName: "Analytics", |
| 236 | + description: "Test", |
| 237 | + package: "@databricks/appkit", |
| 238 | + resources: { |
| 239 | + required: [ |
| 240 | + { |
| 241 | + type: "sql_warehouse", |
| 242 | + alias: "SQL Warehouse", |
| 243 | + resourceKey: "sql-warehouse", |
| 244 | + description: "test", |
| 245 | + permission: "CAN_USE", |
| 246 | + fields: { |
| 247 | + id: { env: "WAREHOUSE_ID", description: "Warehouse ID" }, |
| 248 | + }, |
| 249 | + }, |
| 250 | + ], |
| 251 | + optional: [], |
| 252 | + }, |
| 253 | + }, |
| 254 | + lakebase: { |
| 255 | + name: "lakebase", |
| 256 | + displayName: "Lakebase", |
| 257 | + description: "Test", |
| 258 | + package: "@databricks/appkit", |
| 259 | + resources: { |
| 260 | + required: [ |
| 261 | + { |
| 262 | + type: "postgres", |
| 263 | + alias: "Postgres", |
| 264 | + resourceKey: "postgres", |
| 265 | + description: "test", |
| 266 | + permission: "CAN_CONNECT_AND_CREATE", |
| 267 | + fields: { |
| 268 | + branch: { description: "Branch" }, |
| 269 | + host: { |
| 270 | + env: "PGHOST", |
| 271 | + localOnly: true, |
| 272 | + resolve: "postgres:host", |
| 273 | + }, |
| 274 | + port: { env: "PGPORT", localOnly: true, value: "5432" }, |
| 275 | + endpoint: { resolve: "postgres:endpointPath" }, |
| 276 | + }, |
| 277 | + }, |
| 278 | + ], |
| 279 | + optional: [], |
| 280 | + }, |
| 281 | + }, |
| 282 | + }; |
| 283 | + |
| 284 | + enrichPluginsWithResolution(plugins); |
| 285 | + |
| 286 | + const analyticsId = plugins.analytics.resources.required[0].fields |
| 287 | + .id as Record<string, unknown>; |
| 288 | + expect(analyticsId.resolution).toBe("user-provided"); |
| 289 | + |
| 290 | + const lakebaseFields = plugins.lakebase.resources.required[0].fields; |
| 291 | + expect( |
| 292 | + (lakebaseFields.branch as Record<string, unknown>).resolution, |
| 293 | + ).toBe("user-provided"); |
| 294 | + expect((lakebaseFields.host as Record<string, unknown>).resolution).toBe( |
| 295 | + "platform-injected", |
| 296 | + ); |
| 297 | + expect((lakebaseFields.port as Record<string, unknown>).resolution).toBe( |
| 298 | + "platform-injected", |
| 299 | + ); |
| 300 | + expect( |
| 301 | + (lakebaseFields.endpoint as Record<string, unknown>).resolution, |
| 302 | + ).toBe("cli-resolved"); |
| 303 | + }); |
| 304 | + }); |
185 | 305 | }); |
0 commit comments