@cartanova/qgrid-cli 2.15.1 → 2.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/bundle/dist/application/qgrid/qgrid.frame.js +3 -2
  2. package/bundle/dist/application/request-log/request-log-cost.js +59 -0
  3. package/bundle/dist/application/request-log/request-log.model.js +55 -85
  4. package/bundle/src/application/request-log/request-log-cost.test.ts +40 -0
  5. package/bundle/src/application/request-log/request-log-cost.ts +103 -0
  6. package/bundle/src/application/request-log/request-log.model.test.ts +121 -123
  7. package/bundle/src/application/request-log/request-log.model.ts +70 -167
  8. package/bundle/web-dist/client/assets/{index-JkBenvsH.js → index-BakMhnHZ.js} +3 -3
  9. package/bundle/web-dist/client/assets/logs-Dw-GrMuH.js +1 -0
  10. package/bundle/web-dist/client/assets/{monit-CQ6cVvzc.js → monit-BaFFiVKs.js} +1 -1
  11. package/bundle/web-dist/client/assets/{routes-BkeaYiBN.js → routes-R1xBZYVT.js} +1 -1
  12. package/bundle/web-dist/client/assets/{settings-DJdBEFoL.js → settings-Bw_NXAx8.js} +1 -1
  13. package/bundle/web-dist/client/assets/{show-CcKkiy8Y.js → show-BH7nfFtF.js} +1 -1
  14. package/bundle/web-dist/client/assets/{tokens-DuLrdLMa.js → tokens-BPmRr7mD.js} +1 -1
  15. package/bundle/web-dist/client/assets/{use-oauth-login-flow-CFJY-N99.js → use-oauth-login-flow-B_MGbC3a.js} +1 -1
  16. package/bundle/web-dist/client/assets/{use-update-token-mutation-CrEi7wJa.js → use-update-token-mutation-Dcq7Yv2R.js} +1 -1
  17. package/bundle/web-dist/client/index.html +1 -1
  18. package/bundle/web-dist/server/assets/{logs-C0md5rmp.js → logs-6289J29J.js} +17 -4
  19. package/bundle/web-dist/server/assets/{routes-CCdBJqP_.js → routes-DVWRvqn0.js} +1 -1
  20. package/bundle/web-dist/server/assets/{tokens-C4D67FBX.js → tokens-Di1vDwm5.js} +1 -1
  21. package/bundle/web-dist/server/assets/{use-oauth-login-flow-CFzShQtp.js → use-oauth-login-flow-BUAcW_pK.js} +3 -3
  22. package/bundle/web-dist/server/entry-server.generated.js +21 -21
  23. package/dist/cli.js +9 -38
  24. package/package.json +2 -2
  25. package/bundle/web-dist/client/assets/logs-UozX8VD5.js +0 -1
@@ -0,0 +1,40 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { pricingTableCostMicroUsd, resolvePricingCost } from "./request-log-cost";
4
+
5
+ const usage = {
6
+ token_name: "anthropic/test",
7
+ model_name: "claude-sonnet-4-6",
8
+ input_tokens: 1_000,
9
+ output_tokens: 1_000,
10
+ cache_read_tokens: 0,
11
+ cache_creation_tokens: 0,
12
+ };
13
+
14
+ describe("resolvePricingCost", () => {
15
+ it("prices source-less rows, including a caller cost without a source", () => {
16
+ expect(resolvePricingCost({ ...usage, cost_usd: 1 })).toEqual({ cost_usd: 18_000, cost_source: "pricing_table" });
17
+ });
18
+
19
+ it("keeps sourced rows, unknown models, and zero-cost rows without a stored cost", () => {
20
+ expect(resolvePricingCost({ ...usage, cost_source: "provider" })).toBeUndefined();
21
+ expect(resolvePricingCost({ ...usage, model_name: null })).toBeUndefined();
22
+ expect(resolvePricingCost({ ...usage, input_tokens: 0, output_tokens: 0, cost_usd: null })).toBeUndefined();
23
+ });
24
+ });
25
+
26
+ describe("pricingTableCostMicroUsd", () => {
27
+ it("prices 5m and 1h cache writes at their own TTL rates", () => {
28
+ // Sonnet 4.6: 100K input × $3 + 30K 5m write × $3.75 + 50K 1h write × $6 = $0.4725.
29
+ expect(
30
+ pricingTableCostMicroUsd({
31
+ ...usage,
32
+ input_tokens: 100_000,
33
+ output_tokens: 0,
34
+ cache_creation_tokens: 80_000,
35
+ cache_creation_5m_tokens: 30_000,
36
+ cache_creation_1h_tokens: 50_000,
37
+ }),
38
+ ).toBe(472_500);
39
+ });
40
+ });
@@ -0,0 +1,103 @@
1
+ /**
2
+ * request log 비용 계산 규칙. Sonamu 에 의존하지 않아 모델과 운영 백필 스크립트가 같이 쓴다.
3
+ */
4
+ import { calculateCostUsd } from "../../utils/providers/common/model-cost";
5
+
6
+ // cost_usd는 정수 micro-USD로 저장. 실제 USD = cost_usd / MICRO_USD.
7
+ export const MICRO_USD = 1_000_000;
8
+
9
+ export type RequestLogUsageRow = {
10
+ token_name?: string | null;
11
+ model_name?: string | null;
12
+ input_tokens: number;
13
+ output_tokens: number;
14
+ cache_read_tokens: number;
15
+ cache_creation_tokens: number;
16
+ cache_creation_5m_tokens?: number | null;
17
+ cache_creation_1h_tokens?: number | null;
18
+ cost_usd?: number | null;
19
+ cost_source?: string | null;
20
+ };
21
+
22
+ function isAnthropicUsageRow(row: Pick<RequestLogUsageRow, "token_name" | "model_name">): boolean {
23
+ return (
24
+ row.token_name?.startsWith("anthropic/") === true ||
25
+ row.model_name?.startsWith("claude-") === true ||
26
+ row.model_name?.startsWith("anthropic/claude-") === true
27
+ );
28
+ }
29
+
30
+ export function canonicalModelName(modelName: string): string {
31
+ return modelName.includes("/") ? modelName.split("/").pop()! : modelName;
32
+ }
33
+
34
+ interface UsageForCost {
35
+ model: string | null;
36
+ inputTokens: number;
37
+ outputTokens: number;
38
+ cachedInputTokens: number;
39
+ cacheCreationInputTokens: number;
40
+ cacheCreationInputTokens5m?: number;
41
+ cacheCreationInputTokens1h?: number;
42
+ }
43
+
44
+ export function normalizedUsageForCost(row: RequestLogUsageRow): UsageForCost {
45
+ const cacheRead = row.cache_read_tokens;
46
+ const cacheCreation = row.cache_creation_tokens;
47
+ const storedInput = row.input_tokens;
48
+
49
+ const legacyAnthropicSplitInput =
50
+ isAnthropicUsageRow(row) && storedInput < cacheRead + cacheCreation;
51
+
52
+ const usage: UsageForCost = {
53
+ model: row.model_name ? canonicalModelName(row.model_name) : null,
54
+ inputTokens: legacyAnthropicSplitInput ? storedInput + cacheRead + cacheCreation : storedInput,
55
+ outputTokens: row.output_tokens,
56
+ cachedInputTokens: cacheRead,
57
+ cacheCreationInputTokens: cacheCreation,
58
+ };
59
+
60
+ if (row.cache_creation_5m_tokens !== null && row.cache_creation_5m_tokens !== undefined) {
61
+ usage.cacheCreationInputTokens5m = row.cache_creation_5m_tokens;
62
+ }
63
+
64
+ if (row.cache_creation_1h_tokens !== null && row.cache_creation_1h_tokens !== undefined) {
65
+ usage.cacheCreationInputTokens1h = row.cache_creation_1h_tokens;
66
+ }
67
+
68
+ return usage;
69
+ }
70
+
71
+ /** 현재 가격표로 계산한 driver 비용(micro-USD). 모델을 모르면 undefined. */
72
+ export function pricingTableCostMicroUsd(row: RequestLogUsageRow): number | undefined {
73
+ const usage = normalizedUsageForCost(row);
74
+
75
+ if (!usage.model) return undefined;
76
+
77
+ return Math.round(
78
+ calculateCostUsd(usage.model, {
79
+ inputTokens: usage.inputTokens,
80
+ outputTokens: usage.outputTokens,
81
+ cachedInputTokens: usage.cachedInputTokens,
82
+ cacheCreationInputTokens: usage.cacheCreationInputTokens,
83
+ cacheCreationInputTokens5m: usage.cacheCreationInputTokens5m,
84
+ cacheCreationInputTokens1h: usage.cacheCreationInputTokens1h,
85
+ }) * MICRO_USD,
86
+ );
87
+ }
88
+
89
+ /**
90
+ * 출처 없는 비용을 쓰기 시점에 가격표로 확정한다. 읽기 경로는 저장값만 더하므로, 이 규칙을
91
+ * 거친 row 는 재계산 보정이 0 이다. 출처가 있으면 그대로 두고, 모델을 모르거나 저장값이 없는데
92
+ * 계산값도 0 이면(미확정 media 등) 바꾸지 않는다.
93
+ */
94
+ export function resolvePricingCost(
95
+ row: RequestLogUsageRow,
96
+ ): { cost_usd: number; cost_source: "pricing_table" } | undefined {
97
+ if (row.cost_source) return undefined;
98
+ const cost = pricingTableCostMicroUsd(row);
99
+
100
+ if (cost === undefined || (cost === 0 && (row.cost_usd ?? null) === null)) return undefined;
101
+
102
+ return { cost_usd: cost, cost_source: "pricing_table" };
103
+ }
@@ -596,17 +596,11 @@ describe("RequestLogModel cost provenance", () => {
596
596
  });
597
597
 
598
598
  /**
599
- * totalCost 는 확정 비용(SQL SUM)과 legacy 재계산(JS) 두 쿼리로 나뉜다.
599
+ * totalCost 는 저장된 비용을 SQL SUM 한 번으로 합산한다.
600
600
  * @param confirmedTotal SUM 쿼리가 돌려줄 micro-USD 합계
601
- * @param legacyRows 재계산 대상 row 들
602
601
  */
603
- function mockTotalCostQueries(
604
- confirmedTotal: number,
605
- legacyRows: unknown[],
606
- unknownImageCostCount = 0,
607
- unknownCostCount = 0,
608
- ) {
609
- // subset qb 는 SELECT 를 비우고(clear) 집계/축소된 컬럼만 다시 얹는다 — 구현과 같은 체인.
602
+ function mockTotalCostQuery(confirmedTotal: number, unknownImageCostCount = 0, unknownCostCount = 0) {
603
+ // subset qb 는 SELECT 를 비우고(clear) 집계 컬럼만 다시 얹는다 — 구현과 같은 체인.
610
604
  const sumChain = {
611
605
  where: vi.fn(),
612
606
  whereIn: vi.fn(),
@@ -621,31 +615,16 @@ describe("RequestLogModel cost provenance", () => {
621
615
  sumChain.clear.mockReturnValue(sumChain);
622
616
  sumChain.select.mockReturnValue(sumChain);
623
617
 
624
- const legacyChain = {
625
- where: vi.fn(),
626
- whereIn: vi.fn(),
627
- whereRaw: vi.fn(),
628
- clear: vi.fn(),
629
- select: vi.fn(async () => legacyRows),
630
- };
631
- legacyChain.where.mockReturnValue(legacyChain);
632
- legacyChain.whereIn.mockReturnValue(legacyChain);
633
- legacyChain.whereRaw.mockReturnValue(legacyChain);
634
- legacyChain.clear.mockReturnValue(legacyChain);
635
-
636
- const getSubsetQueries = vi
637
- .fn()
638
- .mockReturnValueOnce({ qb: sumChain })
639
- .mockReturnValueOnce({ qb: legacyChain });
618
+ const getSubsetQueries = vi.fn().mockReturnValue({ qb: sumChain });
640
619
  vi.spyOn(
641
620
  RequestLogModel as unknown as { getSubsetQueries: typeof getSubsetQueries },
642
621
  "getSubsetQueries",
643
622
  ).mockImplementation(getSubsetQueries);
644
- return { sumChain, legacyChain };
623
+ return { sumChain, getSubsetQueries };
645
624
  }
646
625
 
647
626
  it("uses exact stored cost for rows with a cost source", async () => {
648
- mockTotalCostQueries(3_000, []);
627
+ mockTotalCostQuery(3_000);
649
628
 
650
629
  await expect(RequestLogModel.totalCost()).resolves.toEqual({
651
630
  usd: 0.003,
@@ -655,7 +634,7 @@ describe("RequestLogModel cost provenance", () => {
655
634
  });
656
635
 
657
636
  it("counts unpriced non-token media rows separately from unknown image costs", async () => {
658
- const { sumChain } = mockTotalCostQueries(3_000, [], 2, 3);
637
+ const { sumChain } = mockTotalCostQuery(3_000, 2, 3);
659
638
 
660
639
  await expect(RequestLogModel.totalCost()).resolves.toEqual({
661
640
  usd: 0.003,
@@ -679,77 +658,18 @@ describe("RequestLogModel cost provenance", () => {
679
658
  }
680
659
  });
681
660
 
682
- it("sums every row in SQL without a cost_source predicate", async () => {
683
- const { sumChain, legacyChain } = mockTotalCostQueries(3_000, []);
661
+ it("sums stored costs in one SQL query without re-pricing source-less rows", async () => {
662
+ const { sumChain, getSubsetQueries } = mockTotalCostQuery(3_000);
684
663
 
685
664
  await RequestLogModel.totalCost();
686
665
 
666
+ expect(getSubsetQueries).toHaveBeenCalledTimes(1);
687
667
  expect(sumChain.select).toHaveBeenCalledTimes(1);
688
- // source 없는 행도 저장된 이미지 비용을 포함하고 driver 차액만 별도로 보정한다.
689
668
  expect(sumChain.whereRaw).not.toHaveBeenCalled();
690
- expect(legacyChain.whereRaw).toHaveBeenCalledWith(
691
- "request_logs.cost_source IS NULL OR request_logs.cost_usd IS NULL",
692
- );
693
669
  });
694
670
 
695
- it("keeps TTL-aware price-table recomputation for legacy rows", async () => {
696
- mockTotalCostQueries(0, [
697
- {
698
- model_name: "claude-sonnet-4-6",
699
- input_tokens: 100_000,
700
- output_tokens: 0,
701
- cache_read_tokens: 0,
702
- cache_creation_tokens: 80_000,
703
- cache_creation_5m_tokens: 30_000,
704
- cache_creation_1h_tokens: 50_000,
705
- cost_usd: null,
706
- cost_source: null,
707
- },
708
- ]);
709
-
710
- await expect(RequestLogModel.totalCost().then((result) => result.usd)).resolves.toBeCloseTo(0.4725, 10);
711
- });
712
-
713
- it("adds only the delta for legacy rows already counted in the SQL sum", async () => {
714
- // 전체 SUM 이 저장값 0.2 를 이미 포함하므로, 재계산값 0.4725 와의 차액만 더해야 한다.
715
- mockTotalCostQueries(200_000, [
716
- {
717
- model_name: "claude-sonnet-4-6",
718
- input_tokens: 100_000,
719
- output_tokens: 0,
720
- cache_read_tokens: 0,
721
- cache_creation_tokens: 80_000,
722
- cache_creation_5m_tokens: 30_000,
723
- cache_creation_1h_tokens: 50_000,
724
- cost_usd: 200_000,
725
- cost_source: null,
726
- },
727
- ]);
728
-
729
- await expect(RequestLogModel.totalCost().then((result) => result.usd)).resolves.toBeCloseTo(0.4725, 10);
730
- });
731
-
732
- it("leaves the stored value untouched for legacy rows without a model name", async () => {
733
- // 모델을 모르면 재계산할 수 없다. 저장값이 SUM 에 이미 들어갔으므로 보정하지 않는다.
734
- mockTotalCostQueries(5_000, [
735
- {
736
- model_name: null,
737
- input_tokens: 100,
738
- output_tokens: 100,
739
- cache_read_tokens: 0,
740
- cache_creation_tokens: 0,
741
- cache_creation_5m_tokens: null,
742
- cache_creation_1h_tokens: null,
743
- cost_usd: 5_000,
744
- cost_source: null,
745
- },
746
- ]);
747
-
748
- await expect(RequestLogModel.totalCost().then((result) => result.usd)).resolves.toBeCloseTo(0.005, 10);
749
- });
750
-
751
- it("applies list filters to both cost queries so totals match the filtered list", async () => {
752
- const { sumChain, legacyChain } = mockTotalCostQueries(0, []);
671
+ it("applies list filters so totals match the filtered list", async () => {
672
+ const { sumChain } = mockTotalCostQuery(0);
753
673
 
754
674
  await RequestLogModel.totalCost({
755
675
  num: 0,
@@ -759,39 +679,17 @@ describe("RequestLogModel cost provenance", () => {
759
679
  model_name: "openai/gpt-5.5",
760
680
  });
761
681
 
762
- for (const chain of [sumChain, legacyChain]) {
763
- expect(chain.where).toHaveBeenCalledWith("request_logs.project_name", "deti");
764
- expect(chain.where).toHaveBeenCalledWith("request_logs.token_name", "openai/yds");
765
- expect(chain.where).toHaveBeenCalledWith("request_logs.model_name", "openai/gpt-5.5");
766
- }
682
+ expect(sumChain.where).toHaveBeenCalledWith("request_logs.project_name", "deti");
683
+ expect(sumChain.where).toHaveBeenCalledWith("request_logs.token_name", "openai/yds");
684
+ expect(sumChain.where).toHaveBeenCalledWith("request_logs.model_name", "openai/gpt-5.5");
767
685
  });
768
686
 
769
- it("applies the unassigned-project filter to both cost queries", async () => {
770
- const { sumChain, legacyChain } = mockTotalCostQueries(0, []);
687
+ it("applies the unassigned-project filter", async () => {
688
+ const { sumChain } = mockTotalCostQuery(0);
771
689
 
772
690
  await RequestLogModel.totalCost({ num: 0, page: 1, project_name_is_null: true });
773
691
 
774
- for (const chain of [sumChain, legacyChain]) {
775
- expect(chain.where).toHaveBeenCalledWith("request_logs.project_name", null);
776
- }
777
- });
778
-
779
- it("combines the SQL-summed total with the legacy recomputation delta", async () => {
780
- mockTotalCostQueries(3_000, [
781
- {
782
- model_name: "claude-sonnet-4-6",
783
- input_tokens: 100_000,
784
- output_tokens: 0,
785
- cache_read_tokens: 0,
786
- cache_creation_tokens: 80_000,
787
- cache_creation_5m_tokens: 30_000,
788
- cache_creation_1h_tokens: 50_000,
789
- cost_usd: null,
790
- cost_source: null,
791
- },
792
- ]);
793
-
794
- await expect(RequestLogModel.totalCost().then((result) => result.usd)).resolves.toBeCloseTo(0.4755, 10);
692
+ expect(sumChain.where).toHaveBeenCalledWith("request_logs.project_name", null);
795
693
  });
796
694
  });
797
695
 
@@ -800,7 +698,7 @@ describe("RequestLogModel PostgreSQL", () => {
800
698
  await Sonamu.initForTesting();
801
699
  });
802
700
 
803
- it("includes image costs once and filters both stored totals and legacy adjustments", async () => {
701
+ it("includes image costs once and filters stored totals", async () => {
804
702
  const projectName = `cost-${randomUUID()}`;
805
703
  const ids: number[] = [];
806
704
  try {
@@ -829,9 +727,9 @@ describe("RequestLogModel PostgreSQL", () => {
829
727
  const { rows } = await RequestLogModel.findMany("C", params);
830
728
  expect(rows.map((row) => row.id)).toEqual(expect.arrayContaining([ids[0], ids[1], ids[3], ids[4]]));
831
729
  expect(rows).toHaveLength(4);
832
- // .038 known images + .001 hosted driver + .002 text; other project excluded.
730
+ // .03 known images + .005/.001 stored drivers + .001 hosted driver + .002 text; other project excluded.
833
731
  const total = await RequestLogModel.totalCost(params);
834
- expect(total.usd).toBeCloseTo(0.041, 10);
732
+ expect(total.usd).toBeCloseTo(0.039, 10);
835
733
  expect(total.unknownImageCostCount).toBe(1);
836
734
  } finally {
837
735
  await RequestLogModel.del(ids);
@@ -875,6 +773,106 @@ describe("RequestLogModel PostgreSQL", () => {
875
773
  }
876
774
  });
877
775
 
776
+ it("prices unsourced finishRun and save costs at write time but keeps unknown media unpriced", async () => {
777
+ const projectName = `write-cost-${randomUUID()}`;
778
+ const ids: number[] = [];
779
+ const read = (id: number) =>
780
+ RequestLogModel.getPuri("r")
781
+ .from("request_logs")
782
+ .select({ cost_usd: "cost_usd", cost_source: "cost_source" })
783
+ .where("id", id)
784
+ .first();
785
+ try {
786
+ const priced = await RequestLogModel.createRun({ user_prompt: "priced", project_name: projectName });
787
+ const media = await RequestLogModel.createRun({ user_prompt: "media", project_name: projectName });
788
+ ids.push(priced, media);
789
+ // Sonnet 4.6: 1K input × $3 + 1K output × $15 = $0.018; a source-less caller cost is re-priced.
790
+ await RequestLogModel.finishRun(priced, {
791
+ status: "succeeded",
792
+ token_name: "anthropic/test",
793
+ model_name: "claude-sonnet-4-6",
794
+ input_tokens: 1_000,
795
+ output_tokens: 1_000,
796
+ cost_usd: 1,
797
+ });
798
+ await RequestLogModel.finishRun(media, {
799
+ status: "succeeded",
800
+ token_name: "grok/test",
801
+ model_name: "grok/tts",
802
+ input_tokens: 0,
803
+ output_tokens: 0,
804
+ cost_usd: null,
805
+ cost_source: null,
806
+ });
807
+ expect(await read(priced)).toEqual({ cost_usd: 18_000, cost_source: "pricing_table" });
808
+ expect(await read(media)).toEqual({ cost_usd: null, cost_source: null });
809
+
810
+ const saved = (
811
+ await RequestLogModel.save([
812
+ {
813
+ user_prompt: "saved",
814
+ project_name: projectName,
815
+ token_name: "anthropic/test",
816
+ model_name: "claude-sonnet-4-6",
817
+ input_tokens: 1_000,
818
+ output_tokens: 1_000,
819
+ cache_read_tokens: 0,
820
+ cache_creation_tokens: 0,
821
+ cost_usd: null,
822
+ cost_source: null,
823
+ } as Parameters<typeof RequestLogModel.save>[0][number],
824
+ ])
825
+ )[0]!;
826
+ ids.push(saved);
827
+ expect(await read(saved)).toEqual({ cost_usd: 18_000, cost_source: "pricing_table" });
828
+ } finally {
829
+ await RequestLogModel.del(ids);
830
+ }
831
+ });
832
+
833
+ it("prices an expired run whose generate steps carried no cost source", async () => {
834
+ const id = await RequestLogModel.createRun({ user_prompt: "stale external run" });
835
+ try {
836
+ await RequestLogModel.recordRunProgress(id, { token_name: "anthropic/test", model_name: "claude-sonnet-4-6" });
837
+ await RequestLogModel.appendStep(id, { step_index: 0, type: "generate", input_tokens: 1_000, output_tokens: 1_000 });
838
+ await RequestLogModel.appendStep(id, { step_index: 1, type: "tool_call", tool_call_id: "call-1", tool_name: "t" });
839
+
840
+ await expect(
841
+ RequestLogModel.tryExpireStaleToolWaitingRun(id, new Date(Date.now() + 60_000), "stale"),
842
+ ).resolves.toBe(true);
843
+ const row = await RequestLogModel.getPuri("r")
844
+ .from("request_logs")
845
+ .select({ cost_usd: "cost_usd", cost_source: "cost_source" })
846
+ .where("id", id)
847
+ .first();
848
+ expect(row).toEqual({ cost_usd: 18_000, cost_source: "pricing_table" });
849
+ } finally {
850
+ await RequestLogModel.del([id]);
851
+ }
852
+ });
853
+
854
+ it("lists distinct project and model names in ascending order without NULL", async () => {
855
+ const prefix = `distinct-${randomUUID()}`;
856
+ const ids: number[] = [];
857
+ try {
858
+ for (const project of [`${prefix}-b`, `${prefix}-a`, `${prefix}-b`, null]) {
859
+ const id = await RequestLogModel.createRun({ user_prompt: "distinct", project_name: project ?? undefined });
860
+ ids.push(id);
861
+ await RequestLogModel.recordRunProgress(id, { model_name: `${prefix}-model` });
862
+ }
863
+
864
+ const projects = (await RequestLogModel.distinctProjectNames()).filter((name) => name.startsWith(prefix));
865
+ expect(projects).toEqual([`${prefix}-a`, `${prefix}-b`]);
866
+ expect((await RequestLogModel.distinctModelNames()).filter((name) => name.startsWith(prefix))).toEqual([
867
+ `${prefix}-model`,
868
+ ]);
869
+ const all = await RequestLogModel.distinctProjectNames();
870
+ expect(all).toEqual([...all].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)));
871
+ } finally {
872
+ await RequestLogModel.del(ids);
873
+ }
874
+ });
875
+
878
876
  it("does not expire a run while another connection holds its follow-up lock", async () => {
879
877
  const wdb = RequestLogModel.getPuri("w");
880
878
  const client = new Client(wdb.knex.client.config.connection as ClientConfig);