@terreno/ai 57.20.0 → 58.0.0-beta.1
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.
- package/AGENTS.md +20 -18
- package/CHANGELOG.md +93 -0
- package/biome.jsonc +3 -2
- package/dist/aiApp.d.ts +5 -2
- package/dist/aiApp.js +3 -2
- package/dist/harness/agentLoop.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -2
- package/dist/migrations/gptHistoryStringIds.d.ts +41 -0
- package/dist/migrations/gptHistoryStringIds.js +94 -0
- package/dist/models/aiDataset.js +2 -2
- package/dist/models/gptHistory.js +11 -0
- package/dist/observability/local/experimentRunner.d.ts +2 -5
- package/dist/routes/files.d.ts +7 -1
- package/dist/routes/files.js +62 -13
- package/dist/routes/gptActions.js +0 -7
- package/dist/routes/gptHistories.js +8 -2
- package/dist/service/aiDatasets.js +2 -1
- package/dist/service/chatTurn.js +4 -0
- package/dist/service/vertex.d.ts +5 -2
- package/dist/types/harness.d.ts +5 -2
- package/dist/types/index.d.ts +5 -2
- package/e2e/smoke.ts +227 -0
- package/package.json +19 -16
- package/src/aiApp.test.ts +43 -18
- package/src/aiApp.ts +6 -3
- package/src/harness/agentLoop.test.ts +1 -1
- package/src/harness/agentLoop.ts +2 -1
- package/src/harness/agentRecovery.test.ts +31 -28
- package/src/harness/approvals.test.ts +11 -9
- package/src/harness/events.test.ts +10 -6
- package/src/harness/extensions.test.ts +7 -6
- package/src/harness/ownership.test.ts +20 -9
- package/src/harness/retries.test.ts +6 -3
- package/src/harness/routes/conversations.test.ts +2 -2
- package/src/harness/routes/tasks.test.ts +2 -2
- package/src/harness/runners/jobsRunner.test.ts +1 -1
- package/src/harness/subagent.test.ts +3 -2
- package/src/harness/waits.test.ts +6 -4
- package/src/index.test.ts +3 -3
- package/src/index.ts +7 -1
- package/src/isolated/gptStream.isolated.ts +35 -30
- package/src/isolated/langfuseClient.isolated.ts +9 -3
- package/src/isolated/lazyProjectModel.isolated.ts +2 -2
- package/src/langfuseApp.test.ts +4 -20
- package/src/langfuseRoutes.test.ts +20 -15
- package/src/langfuseTracing.test.ts +6 -2
- package/src/langfuseVercelAi.test.ts +12 -9
- package/src/migrations/gptHistoryStringIds.test.ts +231 -0
- package/src/migrations/gptHistoryStringIds.ts +150 -0
- package/src/models/aiDataset.test.ts +1 -1
- package/src/models/aiDataset.ts +2 -2
- package/src/models/gptHistory.test.ts +22 -11
- package/src/models/gptHistory.ts +19 -1
- package/src/observability/evaluate.test.ts +12 -10
- package/src/observability/local/experimentRunner.test.ts +9 -12
- package/src/observability/local/experimentRunner.ts +2 -2
- package/src/observability/local/promptStore.test.ts +4 -3
- package/src/observability/routes/datasets.test.ts +2 -2
- package/src/observability/routes/evaluators.test.ts +2 -2
- package/src/observability/routes/experiments.test.ts +2 -2
- package/src/observability/routes/prompts.test.ts +3 -3
- package/src/observability/routes/review.test.ts +2 -2
- package/src/observability/routes/status.test.ts +4 -4
- package/src/observability/routes/testMultiStage.test.ts +6 -6
- package/src/observability/routes/traces.test.ts +2 -2
- package/src/routes/files.test.ts +126 -3
- package/src/routes/files.ts +90 -15
- package/src/routes/gpt.test.ts +23 -16
- package/src/routes/gptActions.test.ts +15 -15
- package/src/routes/gptActions.ts +1 -4
- package/src/routes/gptApprovals.test.ts +1 -1
- package/src/routes/gptDatasets.test.ts +1 -1
- package/src/routes/gptFiles.test.ts +2 -2
- package/src/routes/gptHistories.test.ts +17 -11
- package/src/routes/gptHistories.ts +59 -55
- package/src/routes/gptHistoriesSync.test.ts +141 -0
- package/src/routes/mcp.test.ts +3 -3
- package/src/routes/projects.test.ts +5 -3
- package/src/routes/routes.test.ts +64 -47
- package/src/service/aiDatasets.ts +2 -1
- package/src/service/aiService.test.ts +1 -1
- package/src/service/asks.test.ts +14 -6
- package/src/service/chatTurn.ts +4 -0
- package/src/service/fileStorage.test.ts +5 -2
- package/src/service/getMCPTools.test.ts +9 -5
- package/src/service/mcpService.test.ts +6 -3
- package/src/service/vertex.test.ts +1 -1
- package/src/service/vertex.ts +7 -4
- package/src/tests/bunSetup.ts +1 -1
- package/src/tests/chatHarness.ts +4 -4
- package/src/tests/fakeJudge.ts +8 -0
- package/src/tests/fakeLangfusePrompt.ts +10 -0
- package/src/tests/helpers.ts +26 -4
- package/src/types/harness.ts +6 -2
- package/src/types/index.ts +5 -2
- package/tsconfig.typecheck.json +18 -0
|
@@ -181,7 +181,7 @@ describe("/gpt/prompt files asks", () => {
|
|
|
181
181
|
afterEach(async () => {
|
|
182
182
|
await AIRequest.deleteMany({});
|
|
183
183
|
await FileAttachment.deleteMany({});
|
|
184
|
-
await GptHistory.deleteMany({});
|
|
184
|
+
await GptHistory.collection.deleteMany({});
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
describe("with data URLs", () => {
|
|
@@ -279,7 +279,7 @@ describe("/gpt/prompt files asks", () => {
|
|
|
279
279
|
},
|
|
280
280
|
]);
|
|
281
281
|
|
|
282
|
-
const output = receiptResultOf(model, 1) as {value: {text?: string}[]};
|
|
282
|
+
const output = receiptResultOf(model, 1) as {value: {text?: string; type?: string}[]};
|
|
283
283
|
expect(output.value.slice(1)).toEqual([
|
|
284
284
|
{text: "File 1 of 1: ledger.csv (text/csv, 100051 bytes)", type: "text"},
|
|
285
285
|
{text: "a".repeat(99_999), type: "text"},
|
|
@@ -38,7 +38,13 @@ import {
|
|
|
38
38
|
toolNamesOf,
|
|
39
39
|
USER_PROMPT,
|
|
40
40
|
} from "../tests/chatHarness";
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
authAsUser,
|
|
43
|
+
authAsUserWithCredentials,
|
|
44
|
+
ensureTestUsers,
|
|
45
|
+
historyRouterOptions,
|
|
46
|
+
terrenoUserModel,
|
|
47
|
+
} from "../tests/helpers";
|
|
42
48
|
import type {GptHistoryDocument} from "../types";
|
|
43
49
|
import {addGptHistoryRoutes} from "./gptHistories";
|
|
44
50
|
|
|
@@ -97,12 +103,12 @@ describe("/gpt/histories headless turns", () => {
|
|
|
97
103
|
beforeAll(async () => {
|
|
98
104
|
await ensureTestUsers();
|
|
99
105
|
await ensureTestUsers([OTHER_USER]);
|
|
100
|
-
await GptHistory.deleteMany({});
|
|
106
|
+
await GptHistory.collection.deleteMany({});
|
|
101
107
|
});
|
|
102
108
|
|
|
103
109
|
afterEach(async () => {
|
|
104
110
|
await AIRequest.deleteMany({});
|
|
105
|
-
await GptHistory.deleteMany({});
|
|
111
|
+
await GptHistory.collection.deleteMany({});
|
|
106
112
|
});
|
|
107
113
|
|
|
108
114
|
describe("POST /gpt/histories/:id/turn", () => {
|
|
@@ -799,10 +805,10 @@ describe("/gpt/histories headless turns", () => {
|
|
|
799
805
|
const historyApp = (validation?: ModelRouterOptions<GptHistoryDocument>["validation"]) =>
|
|
800
806
|
new TerrenoApp({
|
|
801
807
|
configureApp: (router, options) => {
|
|
802
|
-
addGptHistoryRoutes(router, {...options, validation});
|
|
808
|
+
addGptHistoryRoutes(router, {...historyRouterOptions(options), validation});
|
|
803
809
|
},
|
|
804
810
|
skipListen: true,
|
|
805
|
-
userModel:
|
|
811
|
+
userModel: terrenoUserModel,
|
|
806
812
|
}).build();
|
|
807
813
|
|
|
808
814
|
afterEach(() => {
|
|
@@ -845,10 +851,10 @@ describe("/gpt/histories headless turns", () => {
|
|
|
845
851
|
it("adds no headless actions without chat options", async () => {
|
|
846
852
|
const app = new TerrenoApp({
|
|
847
853
|
configureApp: (router, options) => {
|
|
848
|
-
addGptHistoryRoutes(router, options);
|
|
854
|
+
addGptHistoryRoutes(router, historyRouterOptions(options));
|
|
849
855
|
},
|
|
850
856
|
skipListen: true,
|
|
851
|
-
userModel:
|
|
857
|
+
userModel: terrenoUserModel,
|
|
852
858
|
}).build();
|
|
853
859
|
const agent = await authAsUser(app, "notAdmin");
|
|
854
860
|
|
|
@@ -865,12 +871,12 @@ describe("/gpt/histories headless turns", () => {
|
|
|
865
871
|
const app = new TerrenoApp({
|
|
866
872
|
configureApp: (router, options) => {
|
|
867
873
|
addGptHistoryRoutes(router, {
|
|
868
|
-
...options,
|
|
874
|
+
...historyRouterOptions(options),
|
|
869
875
|
chat: {aiService: new AIService({model: model as unknown as LanguageModel})},
|
|
870
876
|
});
|
|
871
877
|
},
|
|
872
878
|
skipListen: true,
|
|
873
|
-
userModel:
|
|
879
|
+
userModel: terrenoUserModel,
|
|
874
880
|
}).build();
|
|
875
881
|
const agent = await authAsUser(app, "notAdmin");
|
|
876
882
|
const historyId = await createHistory(agent);
|
|
@@ -892,7 +898,7 @@ describe("/gpt/histories headless turns", () => {
|
|
|
892
898
|
const app = new TerrenoApp({
|
|
893
899
|
configureApp: (router, options) => {
|
|
894
900
|
addGptHistoryRoutes(router, {
|
|
895
|
-
...options,
|
|
901
|
+
...historyRouterOptions(options),
|
|
896
902
|
chat: {
|
|
897
903
|
aiService: new AIService({model: model as unknown as LanguageModel}),
|
|
898
904
|
asks: true,
|
|
@@ -914,7 +920,7 @@ describe("/gpt/histories headless turns", () => {
|
|
|
914
920
|
});
|
|
915
921
|
},
|
|
916
922
|
skipListen: true,
|
|
917
|
-
userModel:
|
|
923
|
+
userModel: terrenoUserModel,
|
|
918
924
|
}).build();
|
|
919
925
|
const agent = await authAsUser(app, "notAdmin");
|
|
920
926
|
const historyId = await createHistory(agent);
|
|
@@ -27,6 +27,9 @@ import type {GptHistoryDocument, GptHistoryRouteOptions, GptRouteOptions} from "
|
|
|
27
27
|
|
|
28
28
|
type HistoryRouterOptions = Partial<ModelRouterOptions<GptHistoryDocument>>;
|
|
29
29
|
|
|
30
|
+
/** Route path of the history CRUD; the sync collection tag is this path without the slash. */
|
|
31
|
+
const GPT_HISTORIES_PATH = "/gpt/histories";
|
|
32
|
+
|
|
30
33
|
/**
|
|
31
34
|
* Only the chat turn writes `pendingAsk`: it holds messages replayed verbatim to the model, so a
|
|
32
35
|
* client must not be able to plant or edit one, including through dotted paths.
|
|
@@ -332,59 +335,60 @@ export const addGptHistoryRoutes = (
|
|
|
332
335
|
if (headlessChat) {
|
|
333
336
|
assertNoReservedToolNames(headlessChat.tools);
|
|
334
337
|
}
|
|
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
|
-
);
|
|
338
|
+
// The three-argument form registers the collection, so SyncApp serves it to @terreno/syncdb
|
|
339
|
+
// clients as the `gpt/histories` collection on the caller's owner stream.
|
|
340
|
+
const registration = modelRouter(GPT_HISTORIES_PATH, GptHistory, {
|
|
341
|
+
...openApiOptions,
|
|
342
|
+
...routerOptions,
|
|
343
|
+
...(headlessChat ? headlessActions({chat: headlessChat, routerOptions}) : {}),
|
|
344
|
+
openApiExtraModelProperties: {
|
|
345
|
+
...routerOptions.openApiExtraModelProperties,
|
|
346
|
+
pendingAsk: clientPendingAskSchema(),
|
|
347
|
+
},
|
|
348
|
+
openApiOverwrite: {
|
|
349
|
+
...routerOptions.openApiOverwrite,
|
|
350
|
+
create: mergeFragments(READ_ONLY_PENDING_ASK, routerOptions.openApiOverwrite?.create),
|
|
351
|
+
update: mergeFragments(READ_ONLY_PENDING_ASK, routerOptions.openApiOverwrite?.update),
|
|
352
|
+
},
|
|
353
|
+
permissions: {
|
|
354
|
+
create: [Permissions.IsAuthenticated],
|
|
355
|
+
delete: [Permissions.IsOwner],
|
|
356
|
+
list: [Permissions.IsAuthenticated],
|
|
357
|
+
read: [Permissions.IsOwner],
|
|
358
|
+
update: [Permissions.IsOwner],
|
|
359
|
+
},
|
|
360
|
+
preCreate: async (body, req): Promise<GptHistoryDocument> => {
|
|
361
|
+
return {
|
|
362
|
+
...(await withoutClientGcsKeys(withoutPendingAsk(body))),
|
|
363
|
+
userId: (req.user as {_id: unknown})?._id,
|
|
364
|
+
} as GptHistoryDocument;
|
|
365
|
+
},
|
|
366
|
+
preUpdate: async (body, req): Promise<GptHistoryDocument> => {
|
|
367
|
+
const update = await withoutClientGcsKeys(withoutPendingAsk(body), req.params.id);
|
|
368
|
+
// A host hook that returns null still refuses the update; modelRouter checks the value.
|
|
369
|
+
return (
|
|
370
|
+
routerOptions.preUpdate ? await routerOptions.preUpdate(update, req) : update
|
|
371
|
+
) as GptHistoryDocument;
|
|
372
|
+
},
|
|
373
|
+
queryFields: ["userId", "projectId"],
|
|
374
|
+
queryFilter: (user) => ({userId: user?.id}),
|
|
375
|
+
responseHandler: async (value, method, req, handlerOptions) => {
|
|
376
|
+
const hostHandler = routerOptions.responseHandler ?? defaultResponseHandler;
|
|
377
|
+
const serialized = await hostHandler(
|
|
378
|
+
value,
|
|
379
|
+
method as Parameters<typeof defaultResponseHandler>[1],
|
|
380
|
+
req,
|
|
381
|
+
handlerOptions
|
|
382
|
+
);
|
|
383
|
+
return (
|
|
384
|
+
Array.isArray(serialized)
|
|
385
|
+
? serialized.map(withClientPendingAsk)
|
|
386
|
+
: withClientPendingAsk(serialized)
|
|
387
|
+
) as JSONValue;
|
|
388
|
+
},
|
|
389
|
+
sort: "-updated",
|
|
390
|
+
sync: {scope: {field: "userId", type: "owner"}},
|
|
391
|
+
validation: withCallerUserId(routerOptions.validation),
|
|
392
|
+
});
|
|
393
|
+
router.use(registration.path, registration.router);
|
|
390
394
|
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {afterEach, beforeAll, describe, expect, it} from "bun:test";
|
|
2
|
+
import {SyncApp, TerrenoApp} from "@terreno/api";
|
|
3
|
+
import type express from "express";
|
|
4
|
+
import type mongoose from "mongoose";
|
|
5
|
+
|
|
6
|
+
import {GptHistory} from "../models/gptHistory";
|
|
7
|
+
import {
|
|
8
|
+
type AiTestUserDoc,
|
|
9
|
+
authAsUser,
|
|
10
|
+
authAsUserWithCredentials,
|
|
11
|
+
ensureTestUsers,
|
|
12
|
+
historyRouterOptions,
|
|
13
|
+
terrenoUserModel,
|
|
14
|
+
UserModel,
|
|
15
|
+
} from "../tests/helpers";
|
|
16
|
+
import {addGptHistoryRoutes} from "./gptHistories";
|
|
17
|
+
|
|
18
|
+
const OTHER_USER = {
|
|
19
|
+
admin: false,
|
|
20
|
+
email: "sync-other@example.com",
|
|
21
|
+
name: "Other",
|
|
22
|
+
password: "password",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
26
|
+
|
|
27
|
+
interface SnapshotEntity {
|
|
28
|
+
data: Record<string, unknown>;
|
|
29
|
+
deleted: boolean;
|
|
30
|
+
id: string;
|
|
31
|
+
seq: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ownerStream = (userId: string): string => `gpt/histories|owner:${userId}`;
|
|
35
|
+
|
|
36
|
+
const snapshotPath = (userId: string): string =>
|
|
37
|
+
`/sync/snapshot?stream=${encodeURIComponent(ownerStream(userId))}`;
|
|
38
|
+
|
|
39
|
+
const idOf = (user: AiTestUserDoc): string =>
|
|
40
|
+
String((user as AiTestUserDoc & {_id: mongoose.Types.ObjectId})._id);
|
|
41
|
+
|
|
42
|
+
const buildSyncApp = (): express.Application =>
|
|
43
|
+
new TerrenoApp({
|
|
44
|
+
configureApp: (router, options) => {
|
|
45
|
+
addGptHistoryRoutes(router, historyRouterOptions(options));
|
|
46
|
+
},
|
|
47
|
+
skipListen: true,
|
|
48
|
+
userModel: terrenoUserModel,
|
|
49
|
+
})
|
|
50
|
+
.register(new SyncApp())
|
|
51
|
+
.build();
|
|
52
|
+
|
|
53
|
+
describe("/gpt/histories over sync", () => {
|
|
54
|
+
let notAdminId: string;
|
|
55
|
+
let otherId: string;
|
|
56
|
+
|
|
57
|
+
beforeAll(async () => {
|
|
58
|
+
const [, notAdmin] = await ensureTestUsers();
|
|
59
|
+
const [other] = await ensureTestUsers([OTHER_USER]);
|
|
60
|
+
notAdminId = idOf(notAdmin);
|
|
61
|
+
otherId = idOf(other);
|
|
62
|
+
await GptHistory.collection.deleteMany({});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(async () => {
|
|
66
|
+
await GptHistory.collection.deleteMany({});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("gives new histories a UUID String id", async () => {
|
|
70
|
+
const agent = await authAsUser(buildSyncApp(), "notAdmin");
|
|
71
|
+
|
|
72
|
+
const res = await agent.post("/gpt/histories").send({title: "Fresh"}).expect(201);
|
|
73
|
+
|
|
74
|
+
expect(res.body.data._id).toMatch(UUID_PATTERN);
|
|
75
|
+
const history = await GptHistory.findById(res.body.data._id);
|
|
76
|
+
expect(history?.title).toBe("Fresh");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns only the owner's histories in the snapshot of their stream", async () => {
|
|
80
|
+
const app = buildSyncApp();
|
|
81
|
+
const agent = await authAsUser(app, "notAdmin");
|
|
82
|
+
const otherAgent = await authAsUserWithCredentials(app, OTHER_USER);
|
|
83
|
+
const mine = await agent.post("/gpt/histories").send({title: "Mine"}).expect(201);
|
|
84
|
+
await otherAgent.post("/gpt/histories").send({title: "Theirs"}).expect(201);
|
|
85
|
+
await GptHistory.create({prompts: [], title: "Also theirs", userId: otherId});
|
|
86
|
+
|
|
87
|
+
const streams = await agent.get("/sync/streams").expect(200);
|
|
88
|
+
const res = await agent.get(snapshotPath(notAdminId)).expect(200);
|
|
89
|
+
|
|
90
|
+
expect(JSON.stringify(streams.body)).toContain(ownerStream(notAdminId));
|
|
91
|
+
const entities = res.body.entities as SnapshotEntity[];
|
|
92
|
+
expect(entities.map((entity) => entity.id)).toEqual([mine.body.data._id]);
|
|
93
|
+
expect(entities[0].data.title).toBe("Mine");
|
|
94
|
+
expect(entities[0].deleted).toBe(false);
|
|
95
|
+
expect(entities[0].seq).toBeGreaterThan(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("refuses another user's stream", async () => {
|
|
99
|
+
const agent = await authAsUser(buildSyncApp(), "notAdmin");
|
|
100
|
+
|
|
101
|
+
await agent.get(snapshotPath(otherId)).expect(403);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("leaves the paused turn's server-only fields out of synced pending asks", async () => {
|
|
105
|
+
const agent = await authAsUser(buildSyncApp(), "notAdmin");
|
|
106
|
+
const history = await GptHistory.create({
|
|
107
|
+
pendingAsk: {
|
|
108
|
+
created: new Date("2026-01-05T09:00:00.000Z"),
|
|
109
|
+
input: {question: "Continue?"},
|
|
110
|
+
kind: "confirm",
|
|
111
|
+
promptIndex: 1,
|
|
112
|
+
responseMessages: [{content: "secret", role: "assistant"}],
|
|
113
|
+
simple: {buttons: [], question: "Continue?"},
|
|
114
|
+
toolCallId: "call_confirm",
|
|
115
|
+
},
|
|
116
|
+
prompts: [{text: "Hello", type: "user"}],
|
|
117
|
+
userId: notAdminId,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const res = await agent.get(snapshotPath(notAdminId)).expect(200);
|
|
121
|
+
|
|
122
|
+
const entity = (res.body.entities as SnapshotEntity[]).find((item) => item.id === history._id);
|
|
123
|
+
const pendingAsk = entity?.data.pendingAsk as Record<string, unknown>;
|
|
124
|
+
expect(pendingAsk.toolCallId).toBe("call_confirm");
|
|
125
|
+
expect(pendingAsk).not.toHaveProperty("promptIndex");
|
|
126
|
+
expect(pendingAsk).not.toHaveProperty("responseMessages");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("tombstones a deleted history in the owner's snapshot", async () => {
|
|
130
|
+
const agent = await authAsUser(buildSyncApp(), "notAdmin");
|
|
131
|
+
const created = await agent.post("/gpt/histories").send({title: "Gone"}).expect(201);
|
|
132
|
+
|
|
133
|
+
await agent.delete(`/gpt/histories/${created.body.data._id}`).expect(204);
|
|
134
|
+
const res = await agent.get(snapshotPath(notAdminId)).expect(200);
|
|
135
|
+
|
|
136
|
+
const entity = (res.body.entities as SnapshotEntity[]).find(
|
|
137
|
+
(item) => item.id === created.body.data._id
|
|
138
|
+
);
|
|
139
|
+
expect(entity?.deleted).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
});
|
package/src/routes/mcp.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type express from "express";
|
|
|
4
4
|
import supertest from "supertest";
|
|
5
5
|
|
|
6
6
|
import type {MCPService} from "../service/mcpService";
|
|
7
|
-
import {authAsUser, ensureTestUsers,
|
|
7
|
+
import {authAsUser, ensureTestUsers, terrenoUserModel} from "../tests/helpers";
|
|
8
8
|
import {addMcpRoutes} from "./mcp";
|
|
9
9
|
|
|
10
10
|
type MockMcpService = Pick<MCPService, "getServerStatus" | "getTools" | "reconnectServer">;
|
|
@@ -30,7 +30,7 @@ describe("MCP Routes", () => {
|
|
|
30
30
|
addMcpRoutes(router, {mcpService: mcpService as MCPService, openApiOptions: options});
|
|
31
31
|
},
|
|
32
32
|
skipListen: true,
|
|
33
|
-
userModel:
|
|
33
|
+
userModel: terrenoUserModel,
|
|
34
34
|
}).build();
|
|
35
35
|
});
|
|
36
36
|
|
|
@@ -89,7 +89,7 @@ describe("MCP Routes", () => {
|
|
|
89
89
|
addMcpRoutes(router, {mcpService: mcpService as MCPService, openApiOptions: options});
|
|
90
90
|
},
|
|
91
91
|
skipListen: true,
|
|
92
|
-
userModel:
|
|
92
|
+
userModel: terrenoUserModel,
|
|
93
93
|
}).build();
|
|
94
94
|
const agent = await authAsUser(customApp, "admin");
|
|
95
95
|
const res = await agent.post("/mcp/servers/unknown/reconnect");
|
|
@@ -4,7 +4,7 @@ import type express from "express";
|
|
|
4
4
|
import mongoose from "mongoose";
|
|
5
5
|
|
|
6
6
|
import {Project} from "../models/project";
|
|
7
|
-
import {authAsUser, ensureTestUsers, UserModel} from "../tests/helpers";
|
|
7
|
+
import {authAsUser, ensureTestUsers, terrenoUserModel, UserModel} from "../tests/helpers";
|
|
8
8
|
import {addProjectRoutes} from "./projects";
|
|
9
9
|
|
|
10
10
|
describe("Project Routes", () => {
|
|
@@ -24,7 +24,7 @@ describe("Project Routes", () => {
|
|
|
24
24
|
addProjectRoutes(router, {openApiOptions: options});
|
|
25
25
|
},
|
|
26
26
|
skipListen: true,
|
|
27
|
-
userModel:
|
|
27
|
+
userModel: terrenoUserModel,
|
|
28
28
|
}).build();
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -77,7 +77,9 @@ describe("Project Routes", () => {
|
|
|
77
77
|
|
|
78
78
|
it("exposes ownerId virtual aliased to userId", async () => {
|
|
79
79
|
const project = await Project.create({name: "With Owner", userId: notAdminId});
|
|
80
|
-
expect(
|
|
80
|
+
expect(
|
|
81
|
+
project.toObject<{ownerId: mongoose.Types.ObjectId}>({virtuals: true}).ownerId.toString()
|
|
82
|
+
).toBe(notAdminId.toString());
|
|
81
83
|
});
|
|
82
84
|
});
|
|
83
85
|
|