-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathdatamate.test.ts
More file actions
591 lines (512 loc) · 22.5 KB
/
datamate.test.ts
File metadata and controls
591 lines (512 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
import { describe, expect, test, beforeEach, afterEach } from "bun:test"
import path from "path"
import os from "os"
import fsp from "fs/promises"
import { AltimateApi } from "../../src/altimate/api/client"
import { slugify } from "../../src/altimate/tools/datamate"
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
const tmpRoot = path.join(os.tmpdir(), "datamate-test-" + process.pid + "-" + Math.random().toString(36).slice(2))
// ---------------------------------------------------------------------------
// buildMcpConfig
// ---------------------------------------------------------------------------
describe("buildMcpConfig", () => {
const creds = {
altimateUrl: "https://api.getaltimate.com",
altimateInstanceName: "megatenant",
altimateApiKey: "test-api-key-123",
}
test("returns correct shape with 4 headers", () => {
const config = AltimateApi.buildMcpConfig(creds, "42")
expect(config.type).toBe("remote")
expect(config.headers).toBeDefined()
expect(Object.keys(config.headers)).toHaveLength(4)
expect(config.headers["Authorization"]).toBe("Bearer test-api-key-123")
expect(config.headers["x-datamate-id"]).toBe("42")
expect(config.headers["x-tenant"]).toBe("megatenant")
expect(config.headers["x-altimate-url"]).toBe("https://api.getaltimate.com")
})
test("uses default MCP URL when mcpServerUrl not set", () => {
const config = AltimateApi.buildMcpConfig(creds, "1")
expect(config.url).toBe("https://mcpserver.getaltimate.com/sse")
})
test("uses override MCP URL when mcpServerUrl set", () => {
const credsWithUrl = { ...creds, mcpServerUrl: "https://custom.example.com/sse" }
const config = AltimateApi.buildMcpConfig(credsWithUrl, "1")
expect(config.url).toBe("https://custom.example.com/sse")
})
test("sets oauth to false", () => {
const config = AltimateApi.buildMcpConfig(creds, "1")
expect(config.oauth).toBe(false)
})
test("coerces datamate ID to string", () => {
const config = AltimateApi.buildMcpConfig(creds, "123")
expect(config.headers["x-datamate-id"]).toBe("123")
expect(typeof config.headers["x-datamate-id"]).toBe("string")
})
})
// ---------------------------------------------------------------------------
// credentialsPath
// ---------------------------------------------------------------------------
describe("credentialsPath", () => {
test("returns path under home directory", () => {
const p = AltimateApi.credentialsPath()
expect(p).toContain(".altimate")
expect(p).toContain("altimate.json")
expect(p.endsWith(path.join(".altimate", "altimate.json"))).toBe(true)
})
})
// ---------------------------------------------------------------------------
// getCredentials
// ---------------------------------------------------------------------------
describe("getCredentials", () => {
const testHome = path.join(tmpRoot, "creds-test")
beforeEach(async () => {
process.env.OPENCODE_TEST_HOME = testHome
await fsp.mkdir(testHome, { recursive: true })
})
afterEach(async () => {
delete process.env.OPENCODE_TEST_HOME
await fsp.rm(testHome, { recursive: true, force: true }).catch(() => {})
})
test("throws when file missing", async () => {
await expect(AltimateApi.getCredentials()).rejects.toThrow("credentials not found")
})
test("parses valid file", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "https://api.test.com",
altimateInstanceName: "testco",
altimateApiKey: "key123",
}),
)
const creds = await AltimateApi.getCredentials()
expect(creds.altimateUrl).toBe("https://api.test.com")
expect(creds.altimateInstanceName).toBe("testco")
expect(creds.altimateApiKey).toBe("key123")
})
test("throws on malformed JSON", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(path.join(altDir, "altimate.json"), "not json")
await expect(AltimateApi.getCredentials()).rejects.toThrow()
})
test("throws on missing required fields", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({ altimateUrl: "https://api.test.com" }),
)
await expect(AltimateApi.getCredentials()).rejects.toThrow()
})
test("resolves ${env:VAR} substitution in all fields", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "${env:TEST_ALT_URL}",
altimateInstanceName: "${env:TEST_ALT_INSTANCE}",
altimateApiKey: "${env:TEST_ALT_KEY}",
}),
)
process.env.TEST_ALT_URL = "https://api.envtest.com"
process.env.TEST_ALT_INSTANCE = "envtenant"
process.env.TEST_ALT_KEY = "envkey456"
try {
const creds = await AltimateApi.getCredentials()
expect(creds.altimateUrl).toBe("https://api.envtest.com")
expect(creds.altimateInstanceName).toBe("envtenant")
expect(creds.altimateApiKey).toBe("envkey456")
} finally {
delete process.env.TEST_ALT_URL
delete process.env.TEST_ALT_INSTANCE
delete process.env.TEST_ALT_KEY
}
})
test("resolves ${env:VAR} mixed with literal text", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "https://api.myaltimate.com",
altimateInstanceName: "${env:TEST_ALT_INSTANCE_MIX}",
altimateApiKey: "prefix-${env:TEST_ALT_KEY_MIX}-suffix",
}),
)
process.env.TEST_ALT_INSTANCE_MIX = "mixedtenant"
process.env.TEST_ALT_KEY_MIX = "secret"
try {
const creds = await AltimateApi.getCredentials()
expect(creds.altimateInstanceName).toBe("mixedtenant")
expect(creds.altimateApiKey).toBe("prefix-secret-suffix")
} finally {
delete process.env.TEST_ALT_INSTANCE_MIX
delete process.env.TEST_ALT_KEY_MIX
}
})
test("throws when referenced env var is not set", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "https://api.myaltimate.com",
altimateInstanceName: "tenant",
altimateApiKey: "${env:THIS_VAR_DOES_NOT_EXIST_12345}",
}),
)
delete process.env.THIS_VAR_DOES_NOT_EXIST_12345
await expect(AltimateApi.getCredentials()).rejects.toThrow(
"Environment variable THIS_VAR_DOES_NOT_EXIST_12345 not found",
)
})
test("resolves empty-string env var without throwing", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "https://api.myaltimate.com",
altimateInstanceName: "${env:TEST_EMPTY_VAR}",
altimateApiKey: "key",
}),
)
process.env.TEST_EMPTY_VAR = ""
try {
const creds = await AltimateApi.getCredentials()
expect(creds.altimateInstanceName).toBe("")
} finally {
delete process.env.TEST_EMPTY_VAR
}
})
test("leaves literal values unchanged when no substitution syntax present", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "https://api.myaltimate.com",
altimateInstanceName: "plaintenant",
altimateApiKey: "plain-key-no-substitution",
}),
)
const creds = await AltimateApi.getCredentials()
expect(creds.altimateApiKey).toBe("plain-key-no-substitution")
})
test("resolves optional mcpServerUrl field via env var", async () => {
const altDir = path.join(testHome, ".altimate")
await fsp.mkdir(altDir, { recursive: true })
await fsp.writeFile(
path.join(altDir, "altimate.json"),
JSON.stringify({
altimateUrl: "https://api.myaltimate.com",
altimateInstanceName: "tenant",
altimateApiKey: "key",
mcpServerUrl: "${env:TEST_MCP_URL}",
}),
)
process.env.TEST_MCP_URL = "https://custom.mcp.example.com/sse"
try {
const creds = await AltimateApi.getCredentials()
expect(creds.mcpServerUrl).toBe("https://custom.mcp.example.com/sse")
} finally {
delete process.env.TEST_MCP_URL
}
})
})
// ---------------------------------------------------------------------------
// parseAltimateKey
// ---------------------------------------------------------------------------
describe("parseAltimateKey", () => {
test("parses valid 3-part input", () => {
const r = AltimateApi.parseAltimateKey("https://api.getaltimate.com::mycompany::abc123")
expect(r).toEqual({ altimateUrl: "https://api.getaltimate.com", altimateInstanceName: "mycompany", altimateApiKey: "abc123" })
})
test("trims whitespace", () => {
const r = AltimateApi.parseAltimateKey(" https://api.getaltimate.com :: mycompany :: abc123 ")
expect(r?.altimateUrl).toBe("https://api.getaltimate.com")
expect(r?.altimateInstanceName).toBe("mycompany")
expect(r?.altimateApiKey).toBe("abc123")
})
test("allows :: in the api key (joins remaining parts)", () => {
const r = AltimateApi.parseAltimateKey("https://api.getaltimate.com::mycompany::key::extra")
expect(r?.altimateApiKey).toBe("key::extra")
})
test("returns null for a single part (no separator)", () => {
expect(AltimateApi.parseAltimateKey("justonevalue")).toBeNull()
})
// altimate_change start — default URL for 2-part input
test("parses 2-part input with default URL (https://api.myaltimate.com)", () => {
const r = AltimateApi.parseAltimateKey("mycompany::abc123")
expect(r).toEqual({
altimateUrl: "https://api.myaltimate.com",
altimateInstanceName: "mycompany",
altimateApiKey: "abc123",
})
})
test("trims whitespace for 2-part input", () => {
const r = AltimateApi.parseAltimateKey(" mycompany :: abc123 ")
expect(r?.altimateUrl).toBe("https://api.myaltimate.com")
expect(r?.altimateInstanceName).toBe("mycompany")
expect(r?.altimateApiKey).toBe("abc123")
})
test("returns null for empty instance name in 2-part input", () => {
expect(AltimateApi.parseAltimateKey("::abc123")).toBeNull()
})
test("returns null for empty api key in 2-part input", () => {
expect(AltimateApi.parseAltimateKey("mycompany::")).toBeNull()
})
test("3+ parts always treat first segment as URL — non-http rejected", () => {
// `mycompany::key::extra` → 3 parts → url=mycompany (fails http(s) check)
expect(AltimateApi.parseAltimateKey("mycompany::key::extra")).toBeNull()
})
// altimate_change end
test("returns null for empty url", () => {
expect(AltimateApi.parseAltimateKey("::mycompany::key")).toBeNull()
})
test("returns null for empty instance", () => {
expect(AltimateApi.parseAltimateKey("https://api.getaltimate.com::::key")).toBeNull()
})
test("returns null for non-http url", () => {
expect(AltimateApi.parseAltimateKey("ftp://api.getaltimate.com::mycompany::key")).toBeNull()
})
test("returns null for empty string", () => {
expect(AltimateApi.parseAltimateKey("")).toBeNull()
})
test("supports http:// for local dev", () => {
const r = AltimateApi.parseAltimateKey("http://localhost:8000::dev::localkey")
expect(r?.altimateUrl).toBe("http://localhost:8000")
expect(r?.altimateInstanceName).toBe("dev")
expect(r?.altimateApiKey).toBe("localkey")
})
})
// ---------------------------------------------------------------------------
// saveCredentials
// ---------------------------------------------------------------------------
describe("saveCredentials", () => {
const testHome = path.join(tmpRoot, "save-test")
beforeEach(async () => {
process.env.OPENCODE_TEST_HOME = testHome
await fsp.mkdir(testHome, { recursive: true })
})
afterEach(async () => {
delete process.env.OPENCODE_TEST_HOME
await fsp.rm(testHome, { recursive: true, force: true }).catch(() => {})
})
test("writes all fields to altimate.json", async () => {
await AltimateApi.saveCredentials({
altimateUrl: "https://api.save-test.com",
altimateInstanceName: "savetenant",
altimateApiKey: "savekey",
})
const written = JSON.parse(await fsp.readFile(AltimateApi.credentialsPath(), "utf-8"))
expect(written.altimateUrl).toBe("https://api.save-test.com")
expect(written.altimateInstanceName).toBe("savetenant")
expect(written.altimateApiKey).toBe("savekey")
})
test("creates parent directory if missing", async () => {
const dirPath = path.join(testHome, ".altimate")
await fsp.rm(dirPath, { recursive: true, force: true }).catch(() => {})
await AltimateApi.saveCredentials({
altimateUrl: "https://api.save-test.com",
altimateInstanceName: "savetenant",
altimateApiKey: "savekey",
})
expect(await fsp.access(AltimateApi.credentialsPath()).then(() => true).catch(() => false)).toBe(true)
})
test("sets file permissions to 0o600", async () => {
await AltimateApi.saveCredentials({
altimateUrl: "https://api.save-test.com",
altimateInstanceName: "savetenant",
altimateApiKey: "savekey",
})
const stat = await fsp.stat(AltimateApi.credentialsPath())
expect(stat.mode & 0o777).toBe(0o600)
})
test("writes optional mcpServerUrl when provided", async () => {
await AltimateApi.saveCredentials({
altimateUrl: "https://api.save-test.com",
altimateInstanceName: "savetenant",
altimateApiKey: "savekey",
mcpServerUrl: "https://custom.mcp.example.com/sse",
})
const written = JSON.parse(await fsp.readFile(AltimateApi.credentialsPath(), "utf-8"))
expect(written.mcpServerUrl).toBe("https://custom.mcp.example.com/sse")
})
test("omits mcpServerUrl field when not provided", async () => {
await AltimateApi.saveCredentials({
altimateUrl: "https://api.save-test.com",
altimateInstanceName: "savetenant",
altimateApiKey: "savekey",
})
const written = JSON.parse(await fsp.readFile(AltimateApi.credentialsPath(), "utf-8"))
expect(written.mcpServerUrl).toBeUndefined()
})
})
// ---------------------------------------------------------------------------
// TUI credential round-trip: parseAltimateKey → saveCredentials → getCredentials
// ---------------------------------------------------------------------------
describe("TUI credential round-trip", () => {
const testHome = path.join(tmpRoot, "roundtrip-test")
beforeEach(async () => {
process.env.OPENCODE_TEST_HOME = testHome
await fsp.mkdir(testHome, { recursive: true })
})
afterEach(async () => {
delete process.env.OPENCODE_TEST_HOME
await fsp.rm(testHome, { recursive: true, force: true }).catch(() => {})
})
test("parse → save → getCredentials returns same values", async () => {
const parsed = AltimateApi.parseAltimateKey(
"https://api.getaltimate.com::megatenant::e7ad942d0e64c873074f762f409989a4",
)
expect(parsed).not.toBeNull()
await AltimateApi.saveCredentials(parsed!)
const creds = await AltimateApi.getCredentials()
expect(creds.altimateUrl).toBe("https://api.getaltimate.com")
expect(creds.altimateInstanceName).toBe("megatenant")
expect(creds.altimateApiKey).toBe("e7ad942d0e64c873074f762f409989a4")
})
test("trailing slash in url is stripped through round-trip", async () => {
const parsed = AltimateApi.parseAltimateKey("https://api.getaltimate.com/::tenant::key")
expect(parsed).not.toBeNull()
await AltimateApi.saveCredentials(parsed!)
const creds = await AltimateApi.getCredentials()
expect(creds.altimateUrl).toBe("https://api.getaltimate.com")
})
test("api key containing :: survives round-trip", async () => {
const parsed = AltimateApi.parseAltimateKey("https://api.getaltimate.com::tenant::part1::part2")
expect(parsed).not.toBeNull()
await AltimateApi.saveCredentials(parsed!)
const creds = await AltimateApi.getCredentials()
expect(creds.altimateApiKey).toBe("part1::part2")
})
})
// ---------------------------------------------------------------------------
// validateCredentials — mirrors AltimateSettingsHelper.validateSettings
// ---------------------------------------------------------------------------
describe("validateCredentials", () => {
const validCreds = {
altimateUrl: "https://api.getaltimate.com",
altimateInstanceName: "mycompany",
altimateApiKey: "abc123",
}
const originalFetch = globalThis.fetch
afterEach(() => {
globalThis.fetch = originalFetch
})
test("returns ok:true on 200 response", async () => {
globalThis.fetch = (async () =>
new Response(JSON.stringify({ ok: true }), { status: 200 })) as unknown as typeof fetch
const result = await AltimateApi.validateCredentials(validCreds)
expect(result).toEqual({ ok: true })
})
test("returns ok:false with 'Invalid API key' message on 401", async () => {
globalThis.fetch = (async () =>
new Response(JSON.stringify({ detail: "Invalid API key" }), {
status: 401,
statusText: "Unauthorized",
})) as unknown as typeof fetch
const result = await AltimateApi.validateCredentials(validCreds)
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("Invalid API key")
})
test("returns ok:false with 'Invalid instance name' message on 403", async () => {
globalThis.fetch = (async () =>
new Response(JSON.stringify({ detail: "Invalid instance name" }), {
status: 403,
statusText: "Forbidden",
})) as unknown as typeof fetch
const result = await AltimateApi.validateCredentials(validCreds)
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("Invalid instance name")
})
test("returns ok:false with status code on other HTTP errors", async () => {
globalThis.fetch = (async () =>
new Response("{}", { status: 500, statusText: "Internal Server Error" })) as unknown as typeof fetch
const result = await AltimateApi.validateCredentials(validCreds)
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("500")
})
test("returns ok:false when network fetch throws", async () => {
globalThis.fetch = (async () => { throw new Error("Network error") }) as unknown as typeof fetch
const result = await AltimateApi.validateCredentials(validCreds)
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("Could not reach Altimate API")
})
test("returns ok:false for instance name with uppercase letters", async () => {
const result = await AltimateApi.validateCredentials({ ...validCreds, altimateInstanceName: "MyCompany" })
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("Invalid instance name")
})
test("returns ok:false for instance name starting with a number", async () => {
const result = await AltimateApi.validateCredentials({ ...validCreds, altimateInstanceName: "1company" })
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("Invalid instance name")
})
test("returns ok:false for instance name with spaces", async () => {
const result = await AltimateApi.validateCredentials({ ...validCreds, altimateInstanceName: "my company" })
expect(result.ok).toBe(false)
expect((result as { ok: false; error: string }).error).toContain("Invalid instance name")
})
test("accepts valid instance names with hyphens and underscores", async () => {
globalThis.fetch = (async () =>
new Response(JSON.stringify({ ok: true }), { status: 200 })) as unknown as typeof fetch
for (const name of ["test-instance", "test_instance", "_test", "a", "test123_name-here"]) {
const result = await AltimateApi.validateCredentials({ ...validCreds, altimateInstanceName: name })
expect(result.ok).toBe(true)
}
})
test("calls the correct endpoint URL with correct headers", async () => {
let capturedUrl = ""
let capturedHeaders: Record<string, string> = {}
globalThis.fetch = (async (url: RequestInfo | URL, init?: RequestInit) => {
capturedUrl = String(url)
capturedHeaders = Object.fromEntries(new Headers(init?.headers as HeadersInit).entries())
return new Response(JSON.stringify({ ok: true }), { status: 200 })
}) as unknown as typeof fetch
await AltimateApi.validateCredentials(validCreds)
expect(capturedUrl).toBe("https://api.getaltimate.com/dbt/v3/validate-credentials")
expect(capturedHeaders["x-tenant"]).toBe("mycompany")
expect(capturedHeaders["authorization"]).toBe("Bearer abc123")
})
test("strips trailing slash from url before calling endpoint", async () => {
let capturedUrl = ""
globalThis.fetch = (async (url: RequestInfo | URL) => {
capturedUrl = String(url)
return new Response(JSON.stringify({ ok: true }), { status: 200 })
}) as unknown as typeof fetch
await AltimateApi.validateCredentials({ ...validCreds, altimateUrl: "https://api.getaltimate.com/" })
expect(capturedUrl).toBe("https://api.getaltimate.com/dbt/v3/validate-credentials")
})
})
// ---------------------------------------------------------------------------
// slugify
// ---------------------------------------------------------------------------
describe("slugify", () => {
test("converts spaces and special chars to hyphens", () => {
expect(slugify("My SQL Expert!")).toBe("my-sql-expert")
})
test("lowercases", () => {
expect(slugify("TestName")).toBe("testname")
})
test("strips leading/trailing hyphens", () => {
expect(slugify("--hello--")).toBe("hello")
})
test("collapses multiple special chars", () => {
expect(slugify("a b...c")).toBe("a-b-c")
})
})
// ---------------------------------------------------------------------------
// Cleanup
// ---------------------------------------------------------------------------
afterEach(async () => {
await fsp.rm(tmpRoot, { recursive: true, force: true }).catch(() => {})
})