Skip to content

Commit 30f5b17

Browse files
committed
fix: make clearAuth async and fix unawaited asyncProperty tests
Make clearAuth() properly async so clearResponseCache() is awaited rather than fire-and-forget. This ensures the filesystem cache is fully removed before the process exits. Fix pre-existing bug in model-based tests: fcAssert(asyncProperty(...)) returns a Promise that was never awaited. When all commands were synchronous this was invisible, but with the async clearAuth() the yield point caused createIsolatedDbContext() cleanups to interleave with subsequent iterations, corrupting the SENTRY_CONFIG_DIR env var. Changes: - src/lib/db/auth.ts: clearAuth() → async, try/await/catch for clearResponseCache() (was .catch() fire-and-forget) - test/lib/db/model-based.test.ts: add async/await to all test functions using asyncProperty; await clearAuth() calls - test/lib/db/pagination.model-based.test.ts: same async/await fix - test/commands/project/list.test.ts: await clearAuth() calls, add required fresh:false to ListFlags objects
1 parent bc16ea7 commit 30f5b17

File tree

4 files changed

+60
-31
lines changed

4 files changed

+60
-31
lines changed

src/lib/db/auth.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function setAuthToken(
154154
});
155155
}
156156

157-
export function clearAuth(): void {
157+
export async function clearAuth(): Promise<void> {
158158
withDbSpan("clearAuth", () => {
159159
const db = getDatabase();
160160
db.query("DELETE FROM auth WHERE id = 1").run();
@@ -164,10 +164,13 @@ export function clearAuth(): void {
164164
db.query("DELETE FROM pagination_cursors").run();
165165
});
166166

167-
// Clear cached API responses — they are tied to the current user's permissions
168-
clearResponseCache().catch(() => {
167+
// Clear cached API responses — they are tied to the current user's permissions.
168+
// Awaited so cache is fully removed before the process exits.
169+
try {
170+
await clearResponseCache();
171+
} catch {
169172
// Non-fatal: cache directory may not exist yet
170-
});
173+
}
171174
}
172175

173176
export async function isAuthenticated(): Promise<boolean> {

test/commands/project/list.test.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ describe("handleExplicit", () => {
426426
await handleExplicit(writer, "test-org", "frontend", {
427427
limit: 30,
428428
json: false,
429+
fresh: false,
429430
});
430431

431432
const text = output();
@@ -440,6 +441,7 @@ describe("handleExplicit", () => {
440441
await handleExplicit(writer, "test-org", "frontend", {
441442
limit: 30,
442443
json: true,
444+
fresh: false,
443445
});
444446

445447
const parsed = JSON.parse(output());
@@ -454,6 +456,7 @@ describe("handleExplicit", () => {
454456
await handleExplicit(writer, "test-org", "nonexistent", {
455457
limit: 30,
456458
json: false,
459+
fresh: false,
457460
});
458461

459462
const text = output();
@@ -469,6 +472,7 @@ describe("handleExplicit", () => {
469472
await handleExplicit(writer, "test-org", "nonexistent", {
470473
limit: 30,
471474
json: true,
475+
fresh: false,
472476
});
473477

474478
const parsed = JSON.parse(output());
@@ -483,6 +487,7 @@ describe("handleExplicit", () => {
483487
limit: 30,
484488
json: false,
485489
platform: "ruby",
490+
fresh: false,
486491
});
487492

488493
const text = output();
@@ -498,6 +503,7 @@ describe("handleExplicit", () => {
498503
limit: 30,
499504
json: false,
500505
platform: "javascript",
506+
fresh: false,
501507
});
502508

503509
const text = output();
@@ -524,7 +530,7 @@ describe("handleOrgAll", () => {
524530
await handleOrgAll({
525531
stdout: writer,
526532
org: "test-org",
527-
flags: { limit: 30, json: false },
533+
flags: { limit: 30, json: false, fresh: false },
528534
contextKey: "type:org:test-org",
529535
cursor: undefined,
530536
});
@@ -546,7 +552,7 @@ describe("handleOrgAll", () => {
546552
await handleOrgAll({
547553
stdout: writer,
548554
org: "test-org",
549-
flags: { limit: 30, json: true },
555+
flags: { limit: 30, json: true, fresh: false },
550556
contextKey: "type:org:test-org",
551557
cursor: undefined,
552558
});
@@ -564,7 +570,7 @@ describe("handleOrgAll", () => {
564570
await handleOrgAll({
565571
stdout: writer,
566572
org: "test-org",
567-
flags: { limit: 30, json: true },
573+
flags: { limit: 30, json: true, fresh: false },
568574
contextKey: "type:org:test-org",
569575
cursor: undefined,
570576
});
@@ -584,7 +590,7 @@ describe("handleOrgAll", () => {
584590
await handleOrgAll({
585591
stdout: writer,
586592
org: "test-org",
587-
flags: { limit: 30, json: false },
593+
flags: { limit: 30, json: false, fresh: false },
588594
contextKey: "type:org:test-org",
589595
cursor: undefined,
590596
});
@@ -607,7 +613,7 @@ describe("handleOrgAll", () => {
607613
await handleOrgAll({
608614
stdout: writer,
609615
org: "test-org",
610-
flags: { limit: 30, json: false },
616+
flags: { limit: 30, json: false, fresh: false },
611617
contextKey: "type:org:test-org",
612618
cursor: undefined,
613619
});
@@ -626,7 +632,7 @@ describe("handleOrgAll", () => {
626632
await handleOrgAll({
627633
stdout: writer,
628634
org: "test-org",
629-
flags: { limit: 30, json: false, platform: "rust" },
635+
flags: { limit: 30, json: false, platform: "rust", fresh: false },
630636
contextKey: "type:org:test-org",
631637
cursor: undefined,
632638
});
@@ -644,7 +650,7 @@ describe("handleOrgAll", () => {
644650
await handleOrgAll({
645651
stdout: writer,
646652
org: "test-org",
647-
flags: { limit: 30, json: false },
653+
flags: { limit: 30, json: false, fresh: false },
648654
contextKey: "type:org:test-org",
649655
cursor: undefined,
650656
});
@@ -660,7 +666,7 @@ describe("handleOrgAll", () => {
660666
await handleOrgAll({
661667
stdout: writer,
662668
org: "test-org",
663-
flags: { limit: 30, json: false, platform: "rust" },
669+
flags: { limit: 30, json: false, platform: "rust", fresh: false },
664670
contextKey: "type:org:test-org",
665671
cursor: undefined,
666672
});
@@ -680,7 +686,7 @@ describe("handleOrgAll", () => {
680686
await handleOrgAll({
681687
stdout: writer,
682688
org: "test-org",
683-
flags: { limit: 30, json: false },
689+
flags: { limit: 30, json: false, fresh: false },
684690
contextKey: "type:org:test-org",
685691
cursor: undefined,
686692
});
@@ -701,7 +707,7 @@ describe("handleOrgAll", () => {
701707
await handleOrgAll({
702708
stdout: writer,
703709
org: "test-org",
704-
flags: { limit: 30, json: false, platform: "python" },
710+
flags: { limit: 30, json: false, platform: "python", fresh: false },
705711
contextKey: "type:org:test-org:platform:python",
706712
cursor: undefined,
707713
});
@@ -730,6 +736,7 @@ describe("handleProjectSearch", () => {
730736
await handleProjectSearch(writer, "frontend", {
731737
limit: 30,
732738
json: false,
739+
fresh: false,
733740
});
734741

735742
const text = output();
@@ -743,6 +750,7 @@ describe("handleProjectSearch", () => {
743750
await handleProjectSearch(writer, "frontend", {
744751
limit: 30,
745752
json: true,
753+
fresh: false,
746754
});
747755

748756
const parsed = JSON.parse(output());
@@ -779,6 +787,7 @@ describe("handleProjectSearch", () => {
779787
handleProjectSearch(writer, "nonexistent", {
780788
limit: 30,
781789
json: false,
790+
fresh: false,
782791
})
783792
).rejects.toThrow(ContextError);
784793
});
@@ -811,6 +820,7 @@ describe("handleProjectSearch", () => {
811820
await handleProjectSearch(writer, "nonexistent", {
812821
limit: 30,
813822
json: true,
823+
fresh: false,
814824
});
815825

816826
const parsed = JSON.parse(output());
@@ -824,6 +834,7 @@ describe("handleProjectSearch", () => {
824834
await handleProjectSearch(writer, "frontend", {
825835
limit: 30,
826836
json: false,
837+
fresh: false,
827838
});
828839

829840
const text = output();
@@ -838,6 +849,7 @@ describe("handleProjectSearch", () => {
838849
limit: 30,
839850
json: false,
840851
platform: "rust",
852+
fresh: false,
841853
});
842854

843855
const text = output();
@@ -894,6 +906,7 @@ describe("handleProjectSearch", () => {
894906
await handleProjectSearch(writer, "frontend", {
895907
limit: 1,
896908
json: false,
909+
fresh: false,
897910
});
898911

899912
const text = output();
@@ -950,6 +963,7 @@ describe("handleProjectSearch", () => {
950963
await handleProjectSearch(writer, "frontend", {
951964
limit: 1,
952965
json: true,
966+
fresh: false,
953967
});
954968

955969
const parsed = JSON.parse(output());
@@ -1163,6 +1177,7 @@ describe("handleAutoDetect", () => {
11631177
await handleAutoDetect(writer, "/tmp/test-project", {
11641178
limit: 30,
11651179
json: false,
1180+
fresh: false,
11661181
});
11671182

11681183
const text = output();
@@ -1179,6 +1194,7 @@ describe("handleAutoDetect", () => {
11791194
await handleAutoDetect(writer, "/tmp/test-project", {
11801195
limit: 30,
11811196
json: true,
1197+
fresh: false,
11821198
});
11831199

11841200
const parsed = JSON.parse(output());
@@ -1194,6 +1210,7 @@ describe("handleAutoDetect", () => {
11941210
await handleAutoDetect(writer, "/tmp/test-project", {
11951211
limit: 30,
11961212
json: false,
1213+
fresh: false,
11971214
});
11981215

11991216
expect(output()).toContain("No projects found");
@@ -1209,6 +1226,7 @@ describe("handleAutoDetect", () => {
12091226
await handleAutoDetect(writer, "/tmp/test-project", {
12101227
limit: 2,
12111228
json: true,
1229+
fresh: false,
12121230
});
12131231

12141232
const parsed = JSON.parse(output());
@@ -1225,6 +1243,7 @@ describe("handleAutoDetect", () => {
12251243
limit: 30,
12261244
json: true,
12271245
platform: "python",
1246+
fresh: false,
12281247
});
12291248

12301249
const parsed = JSON.parse(output());
@@ -1243,6 +1262,7 @@ describe("handleAutoDetect", () => {
12431262
await handleAutoDetect(writer, "/tmp/test-project", {
12441263
limit: 2,
12451264
json: false,
1265+
fresh: false,
12461266
});
12471267

12481268
const text = output();
@@ -1259,6 +1279,7 @@ describe("handleAutoDetect", () => {
12591279
await handleAutoDetect(writer, "/tmp/test-project", {
12601280
limit: 30,
12611281
json: true,
1282+
fresh: false,
12621283
});
12631284

12641285
const parsed = JSON.parse(output());
@@ -1279,6 +1300,7 @@ describe("handleAutoDetect", () => {
12791300
await handleAutoDetect(writer, "/tmp/test-project", {
12801301
limit: 30,
12811302
json: false,
1303+
fresh: false,
12821304
});
12831305

12841306
const text = output();
@@ -1298,6 +1320,7 @@ describe("handleAutoDetect", () => {
12981320
await handleAutoDetect(writer, "/tmp/test-project", {
12991321
limit: 30,
13001322
json: true,
1323+
fresh: false,
13011324
});
13021325

13031326
const parsed = JSON.parse(output());
@@ -1325,6 +1348,7 @@ describe("handleAutoDetect", () => {
13251348
await handleAutoDetect(writer, "/tmp/test-project", {
13261349
limit: 30,
13271350
json: true,
1351+
fresh: false,
13281352
});
13291353

13301354
const parsed = JSON.parse(output());
@@ -1342,6 +1366,7 @@ describe("handleAutoDetect", () => {
13421366
handleAutoDetect(writer, "/tmp/test-project", {
13431367
limit: 30,
13441368
json: true,
1369+
fresh: false,
13451370
})
13461371
).rejects.toThrow(AuthError);
13471372
});
@@ -1356,6 +1381,7 @@ describe("handleAutoDetect", () => {
13561381
limit: 30,
13571382
json: true,
13581383
platform: "python",
1384+
fresh: false,
13591385
});
13601386

13611387
const parsed = JSON.parse(output());

0 commit comments

Comments
 (0)