@langwatch/server 3.1.0-beta.21 → 3.1.0-beta.23
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/langevals/evaluators/topic_clustering/langevals_topic_clustering/__init__.py +36 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/_logger.py +165 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/batch_clustering.py +153 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/build_response.py +77 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/constants.py +7 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/incremental_clustering.py +325 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/topic_naming.py +432 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/types.py +42 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/utils.py +191 -0
- package/langevals/evaluators/topic_clustering/pyproject.toml +52 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_clustering.py +239 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_clustering_integration.py +97 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_naming.py +72 -0
- package/langevals/langevals/pytest_plugins/pass_rate_plugin.py +7 -1
- package/langevals/langevals/server.py +28 -0
- package/langevals/pyproject.toml +3 -0
- package/langevals/uv.lock +119 -20
- package/langwatch/dist/client/assets/{AnnotationsTable-BDAkYaz6.js → AnnotationsTable-uS_9SQ-g.js} +2 -2
- package/langwatch/dist/client/assets/{BatchEvaluationSummary-DMaQM_VB.js → BatchEvaluationSummary-DtFd8yKJ.js} +2 -2
- package/langwatch/dist/client/assets/{BudgetEditDrawer-CHaqmdIl.js → BudgetEditDrawer-CHEPz0hH.js} +2 -2
- package/langwatch/dist/client/assets/{ChartCard-D14PUg_d.js → ChartCard-s5fMPo7b.js} +2 -2
- package/langwatch/dist/client/assets/{ChatWindow-CRDnlP-Q.js → ChatWindow-C0XSteVJ.js} +2 -2
- package/langwatch/dist/client/assets/ChatWindow-DFEmNXQL.js +1 -0
- package/langwatch/dist/client/assets/{ConfirmDialog-CXIhncvW.js → ConfirmDialog-M94yLNvP.js} +2 -2
- package/langwatch/dist/client/assets/{ContactSalesBlock-CijLBwRC.js → ContactSalesBlock-CnnuZ8iI.js} +2 -2
- package/langwatch/dist/client/assets/{DSPyExperiment-B1YOL2m8.js → DSPyExperiment-CMA6lrlx.js} +2 -2
- package/langwatch/dist/client/assets/{FilterDisplay-BB0xWrLn.js → FilterDisplay-0S3NqCkq.js} +2 -2
- package/langwatch/dist/client/assets/{FormatMoney-w9vr_h0X.js → FormatMoney-CCygtAHg.js} +2 -2
- package/langwatch/dist/client/assets/{FoundryDrawer-CdJDXtpz.js → FoundryDrawer-B35xZ26C.js} +2 -2
- package/langwatch/dist/client/assets/{GatewayErrorPanel-DvE9U2dS.js → GatewayErrorPanel-BsaYQEie.js} +2 -2
- package/langwatch/dist/client/assets/{GatewayLayout-lv1p_6B5.js → GatewayLayout-LvwwrwMf.js} +2 -2
- package/langwatch/dist/client/assets/{GraphsLayout-BJ68J9e-.js → GraphsLayout-DJ-HI9N1.js} +2 -2
- package/langwatch/dist/client/assets/{GroupBindingInputRow-DebZBCnD.js → GroupBindingInputRow-CV-fBkX9.js} +2 -2
- package/langwatch/dist/client/assets/{MessagesTable-B6lYde-x.js → MessagesTable-9taaKCOZ.js} +2 -2
- package/langwatch/dist/client/assets/{NavigationFooter-CiOVzDUh.js → NavigationFooter-Dzvauw3l.js} +2 -2
- package/langwatch/dist/client/assets/{NoDataInfoBlock-quSW_MRm.js → NoDataInfoBlock-CLKl_wlX.js} +2 -2
- package/langwatch/dist/client/assets/{OpsPageShell-DJ1WlI6-.js → OpsPageShell-C_mTziRS.js} +2 -2
- package/langwatch/dist/client/assets/{OptimizationStudio-BlozXjcN.js → OptimizationStudio-D2zpsmJj.js} +8 -12
- package/langwatch/dist/client/assets/{PreconditionsField-BOfcWvmZ.js → PreconditionsField-WXB8kcTK.js} +2 -2
- package/langwatch/dist/client/assets/{SettingsLayout-CLCGxMAe.js → SettingsLayout--1gdEuhv.js} +2 -2
- package/langwatch/dist/client/assets/{SubscriptionPage-J8b2Zaj6.js → SubscriptionPage-B0ox_4kM.js} +2 -2
- package/langwatch/dist/client/assets/{VirtualKeySecretReveal-DR1VDLy7.js → VirtualKeySecretReveal-CRbI1dKQ.js} +2 -2
- package/langwatch/dist/client/assets/{WithPermissionGuard-DD8uo3UK.js → WithPermissionGuard-B4Jo8E5-.js} +2 -2
- package/langwatch/dist/client/assets/{__...path__-BZVaIayJ.js → __...path__-BF2zkD84.js} +2 -2
- package/langwatch/dist/client/assets/{_experiment_-B1aT-wS3.js → _experiment_-D02aoVQk.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-oI_eq-I_.js → _id_-Ch8YmTiM.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-DAqPuO73.js → _id_-D6ZvwHpH.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-DUngklVb.js → _id_-DOC1ZkBm.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-jFDAfbob.js → _id_-DfWwW6_N.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-BKBrWGG0.js → _id_-DxUo4W7J.js} +2 -2
- package/langwatch/dist/client/assets/_not-found-COI3ShsR.js +1 -0
- package/langwatch/dist/client/assets/{_project_-Bt1tayHB.js → _project_-_UUt5Ar9.js} +2 -2
- package/langwatch/dist/client/assets/{_runId_-CfvnDt5H.js → _runId_-Dimwzp48.js} +2 -2
- package/langwatch/dist/client/assets/_slug_-BMvKBwS_.js +2 -0
- package/langwatch/dist/client/assets/{_slug_-DZAdl0QS.js → _slug_-CE6VoDSC.js} +2 -2
- package/langwatch/dist/client/assets/{_slug_-DmoWXjKT.js → _slug_-OiOLG1Mv.js} +2 -2
- package/langwatch/dist/client/assets/{_team_-DL_wKSWK.js → _team_-DKvmwO_5.js} +2 -2
- package/langwatch/dist/client/assets/{_workflow_-DcMXLPUe.js → _workflow_-FkilKiB-.js} +3 -3
- package/langwatch/dist/client/assets/{_workflow_-NI9bac7d.js → _workflow_-gJZppg3h.js} +2 -2
- package/langwatch/dist/client/assets/{access-audit-CFwNwusI.js → access-audit-xcUVYMMT.js} +2 -2
- package/langwatch/dist/client/assets/{agents-Di4XRwcn.js → agents-D32g91cu.js} +2 -2
- package/langwatch/dist/client/assets/{all-C273mlDB.js → all-vnREzDZj.js} +2 -2
- package/langwatch/dist/client/assets/{analytics-CEAcSf6B.js → analytics-DP6Y4Feh.js} +2 -2
- package/langwatch/dist/client/assets/{annotation-scores-CHfn4LQp.js → annotation-scores-CjD4CEB6.js} +2 -2
- package/langwatch/dist/client/assets/{annotations-CHZQrha6.js → annotations-1rVXiDRQ.js} +2 -2
- package/langwatch/dist/client/assets/{api-keys-BT7HExHM.js → api-keys-BJpKyuaz.js} +2 -2
- package/langwatch/dist/client/assets/{audit-log-BGk-51Dt.js → audit-log-BdUdZjxp.js} +2 -2
- package/langwatch/dist/client/assets/{authentication-DvwXfkp-.js → authentication-8mQB00CC.js} +2 -2
- package/langwatch/dist/client/assets/{authorize-tXpHrWyw.js → authorize-BpUueMNW.js} +2 -2
- package/langwatch/dist/client/assets/{authorize-CRu9xlpU.js → authorize-CbNBtmxW.js} +2 -2
- package/langwatch/dist/client/assets/{automations-CjDvz9Ak.js → automations-34KMkRxd.js} +2 -2
- package/langwatch/dist/client/assets/{billing-plans-FUqEPN62.js → billing-plans-BUQp08MI.js} +2 -2
- package/langwatch/dist/client/assets/{budgets-BV6_RHrs.js → budgets-CdelE8Hv.js} +2 -2
- package/langwatch/dist/client/assets/{cache-rules-CtYA79E_.js → cache-rules-D2m1QlNJ.js} +2 -2
- package/langwatch/dist/client/assets/choose-C0LdeUiH.js +2 -0
- package/langwatch/dist/client/assets/{command-bar-CaJygoez.js → command-bar-DUK45yin.js} +7 -9
- package/langwatch/dist/client/assets/custom-hBq2K4FJ.js +1 -0
- package/langwatch/dist/client/assets/{datasets-vLWpH84_.js → datasets-ErNNhmjg.js} +2 -2
- package/langwatch/dist/client/assets/{dejaview-DwVR3RGg.js → dejaview-BaD4_v90.js} +2 -2
- package/langwatch/dist/client/assets/{dist-SwV3YZv3.js → dist-Cds4Mqhj.js} +4 -6
- package/langwatch/dist/client/assets/{edit-CyxsmQmW.js → edit-DpT8ejBV.js} +2 -2
- package/langwatch/dist/client/assets/{evaluations-BfgeZMph.js → evaluations-BdQ2Dm2r.js} +2 -2
- package/langwatch/dist/client/assets/{evaluations-HSQIMvbX.js → evaluations-C90I4VAr.js} +2 -2
- package/langwatch/dist/client/assets/{evaluators-DLHVvnrh.js → evaluators-ig_ugRLt.js} +2 -2
- package/langwatch/dist/client/assets/{foundry-Ckq0WjPU.js → foundry-B-X_80pD.js} +2 -2
- package/langwatch/dist/client/assets/{gateway-CDSYPZ6w.js → gateway-CS_mtJx-.js} +2 -2
- package/langwatch/dist/client/assets/{groups-CCCRUqPj.js → groups-Bp90ChP3.js} +2 -2
- package/langwatch/dist/client/assets/{index-Bm6z2fM9.js → index-BEjGS0kI.js} +5 -5
- package/langwatch/dist/client/assets/{license-CHOarGWr.js → license-CgnlvyuI.js} +2 -2
- package/langwatch/dist/client/assets/{me-CBya_vXs.js → me-DEqhm_KC.js} +2 -2
- package/langwatch/dist/client/assets/{members-lIFLh-rh.js → members-CUJANDtH.js} +2 -2
- package/langwatch/dist/client/assets/{messages-CG9j8Dz8.js → messages-fQBfCjvp.js} +2 -2
- package/langwatch/dist/client/assets/{metrics-C9pzeaI6.js → metrics-DeIxebpD.js} +2 -2
- package/langwatch/dist/client/assets/{model-costs-Bc5uqjkl.js → model-costs-C1RbgK--.js} +2 -2
- package/langwatch/dist/client/assets/{model-providers-B5UjRgS_.js → model-providers-Pv3ML_-t.js} +2 -2
- package/langwatch/dist/client/assets/{my-queue-BkEfiWyR.js → my-queue-BLre2NMr.js} +2 -2
- package/langwatch/dist/client/assets/{ops-Cc-g-CMn.js → ops-CCw-FJaT.js} +2 -2
- package/langwatch/dist/client/assets/{organization-features-CoIKKHkQ.js → organization-features-rqg-75mI.js} +2 -2
- package/langwatch/dist/client/assets/{organizations-DWcQUTzi.js → organizations-DjCzIHVx.js} +2 -2
- package/langwatch/dist/client/assets/{persistence-CTQ44vGL.js → persistence-BPvHS0F6.js} +2 -2
- package/langwatch/dist/client/assets/{plans-Dq3eFg5K.js → plans-Ch2Ol-Fd.js} +2 -2
- package/langwatch/dist/client/assets/{projections-CTNj1QBM.js → projections-it4FOVjm.js} +2 -2
- package/langwatch/dist/client/assets/{projects-BxM7C87h.js → projects-CjWZFLfn.js} +2 -2
- package/langwatch/dist/client/assets/{prompts-DhXnJT6e.js → prompts-DilmFH_s.js} +2 -2
- package/langwatch/dist/client/assets/{providers-DW7VWdqq.js → providers-tlLT_lTF.js} +2 -2
- package/langwatch/dist/client/assets/{reports-D3QFKhNP.js → reports-vlrcTrLs.js} +2 -2
- package/langwatch/dist/client/assets/{roles-B_0t5DWA.js → roles-DNgi-NQ9.js} +2 -2
- package/langwatch/dist/client/assets/{scenarios-BX3XslU0.js → scenarios-BmG_wDkR.js} +2 -2
- package/langwatch/dist/client/assets/{scim-DDsLO39r.js → scim-BKr1_FHt.js} +2 -2
- package/langwatch/dist/client/assets/{secrets-BvEGwDCy.js → secrets-CU8ocTGv.js} +2 -2
- package/langwatch/dist/client/assets/{settings-9giNiAQQ.js → settings-CDzdoYVK.js} +2 -2
- package/langwatch/dist/client/assets/{setup-HxXKoVKG.js → setup-nEvn2rjN.js} +2 -2
- package/langwatch/dist/client/assets/{subscription-DhyswDze.js → subscription-BPNl_6jF.js} +3 -3
- package/langwatch/dist/client/assets/{subscriptions-Dyyau22a.js → subscriptions-D0G-OE5C.js} +2 -2
- package/langwatch/dist/client/assets/{teams-DRmeAxzf.js → teams-DThgDQvB.js} +2 -2
- package/langwatch/dist/client/assets/{textOverflowHeuristic-JibhpzDV.js → textOverflowHeuristic-DTC8-Ffx.js} +2 -2
- package/langwatch/dist/client/assets/{topic-clustering-Bllfw5rZ.js → topic-clustering-BR2Mbpao.js} +2 -2
- package/langwatch/dist/client/assets/{topics-CpiGYxqb.js → topics-CI8GoNqp.js} +2 -2
- package/langwatch/dist/client/assets/{traceExecutor-CiHXJB0V.js → traceExecutor-CDUGyUaw.js} +2 -2
- package/langwatch/dist/client/assets/{usage-BnsstwBY.js → usage-B4mR7ut_.js} +2 -2
- package/langwatch/dist/client/assets/{usage-CoyGtJoI.js → usage-C8fbffYi.js} +2 -2
- package/langwatch/dist/client/assets/{useAdminResource-SPC5iBHM.js → useAdminResource-SmnnHro6.js} +2 -2
- package/langwatch/dist/client/assets/{useAnnotationQueues-2DKZTC7r.js → useAnnotationQueues-CA6Vk--V.js} +2 -2
- package/langwatch/dist/client/assets/{useAvailableEvaluators-HndTl2LV.js → useAvailableEvaluators-hmbmcRQr.js} +2 -2
- package/langwatch/dist/client/assets/{useDeleteDatasetConfirmation-BgWN6Qqb.js → useDeleteDatasetConfirmation-BCK_zUUe.js} +2 -2
- package/langwatch/dist/client/assets/{useWorkflowStore-e1wFCvo2.js → useWorkflowStore-QUJ3J8X9.js} +2 -2
- package/langwatch/dist/client/assets/{users-C6wjliCC.js → users-CfhanCfR.js} +2 -2
- package/langwatch/dist/client/assets/{users-tF6ZKeV1.js → users-HjuN3o6k.js} +2 -2
- package/langwatch/dist/client/assets/{virtual-keys-BL-65S0B.js → virtual-keys-Bj-MhW66.js} +2 -2
- package/langwatch/dist/client/assets/{wizard-faGkpZDT.js → wizard-dRWCVVx6.js} +2 -2
- package/langwatch/dist/client/assets/{workbench-Oj0s_YR-.js → workbench-CuixH3G1.js} +2 -2
- package/langwatch/dist/client/assets/{workflows-Cu9k-Twu.js → workflows-BT6m4Yu9.js} +2 -2
- package/langwatch/dist/client/index.html +3 -3
- package/langwatch/dist/scenario-child-process.js +20 -10
- package/langwatch/package.json +2 -2
- package/langwatch/pnpm-lock.yaml +329 -328
- package/langwatch/scripts/seed-dogfood-password.ts +163 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-evaluator.integration.test.ts +458 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-routing.test.ts +188 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event.integration.test.ts +274 -0
- package/langwatch/src/app/api/workflows/post_event/post-event.ts +29 -1
- package/langwatch/src/components/agents/AgentCodeEditorDrawer.tsx +4 -5
- package/langwatch/src/components/agents/__tests__/AgentCodeEditorDrawer.integration.test.tsx +40 -0
- package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/__tests__/code-execution-node.factory.unit.test.ts +47 -0
- package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/code-execution-node.factory.ts +2 -4
- package/langwatch/src/components/experiments/BatchEvaluationV2/BatchEvaluationV2EvaluationResults.tsx +6 -1
- package/langwatch/src/hooks/usePostHog.ts +11 -0
- package/langwatch/src/optimization_studio/__tests__/registry.test.ts +29 -1
- package/langwatch/src/optimization_studio/components/Optimize.tsx +17 -3
- package/langwatch/src/optimization_studio/components/properties/AgentPropertiesPanel.tsx +4 -5
- package/langwatch/src/optimization_studio/hooks/workflowStoreCore.ts +17 -6
- package/langwatch/src/optimization_studio/hooks/workflowStoreCore.unit.test.ts +42 -0
- package/langwatch/src/optimization_studio/registry.ts +2 -4
- package/langwatch/src/optimization_studio/server/lambda/index.ts +12 -2
- package/langwatch/src/server/api/routers/workflows.ts +18 -0
- package/langwatch/src/server/evaluations-v3/execution/workflowBuilder.ts +3 -2
- package/langwatch/src/server/evaluations-v3/services/__tests__/experiment-run.service.getRun-null.unit.test.ts +71 -0
- package/langwatch/src/server/evaluations-v3/services/experiment-run.service.ts +18 -9
- package/langwatch/src/server/modelProviders/utils.ts +11 -1
- package/langwatch/src/server/nlpgo/__tests__/nlpgoFetch.integration.test.ts +248 -0
- package/langwatch/src/server/nlpgo/nlpgoFetch.ts +155 -0
- package/langwatch/src/server/routes/__tests__/playground-proxy.integration.test.ts +242 -0
- package/langwatch/src/server/routes/playground.ts +11 -1
- package/langwatch/src/server/routes/workflows.ts +17 -0
- package/langwatch/src/server/topicClustering/topicClustering.ts +33 -8
- package/langwatch/src/server/workflows/runWorkflow.ts +10 -13
- package/langwatch_nlp/langwatch_nlp/studio/execute/execute_component.py +25 -1
- package/langwatch_nlp/langwatch_nlp/studio/parser.py +121 -16
- package/langwatch_nlp/langwatch_nlp/topic_clustering/topic_naming.py +39 -32
- package/langwatch_nlp/scripts/entrypoint.sh +67 -0
- package/langwatch_nlp/tests/studio/test_parse.py +198 -0
- package/mcp-server/pnpm-lock.yaml +15 -21
- package/package.json +1 -1
- package/packages/server/dist/cli.cjs +78 -94
- package/langwatch/dist/client/assets/ChatWindow-DzB-tNlQ.js +0 -1
- package/langwatch/dist/client/assets/_not-found-PEUaWdF3.js +0 -1
- package/langwatch/dist/client/assets/_slug_-C-8AjsjC.js +0 -2
- package/langwatch/dist/client/assets/choose--PBky27o.js +0 -2
- package/langwatch/dist/client/assets/custom-CSiS1liN.js +0 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seeds a credential-auth dev user that mirrors a real account's
|
|
3
|
+
* org/team membership. Used by browser-QA dogfood: pnpm dev runs with
|
|
4
|
+
* NEXTAUTH_PROVIDER=email, this user signs in with email+password,
|
|
5
|
+
* inherits another user's project access without sharing credentials.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* DOGFOOD_OWNER_EMAIL=you@example.com npx tsx scripts/seed-dogfood-password.ts
|
|
9
|
+
*
|
|
10
|
+
* Env (all optional):
|
|
11
|
+
* DOGFOOD_OWNER_EMAIL — copy this user's org+team membership (default: required, no fallback)
|
|
12
|
+
* DOGFOOD_USER_EMAIL — login email (default: dogfood@langwatch.local)
|
|
13
|
+
* DOGFOOD_PASSWORD — login password (default: DogfoodPassword!2026)
|
|
14
|
+
* DOGFOOD_USER_NAME — display name (default: Dogfood)
|
|
15
|
+
*/
|
|
16
|
+
import { RoleBindingScopeType, TeamUserRole } from "@prisma/client";
|
|
17
|
+
import { hash } from "bcrypt";
|
|
18
|
+
import { prisma } from "../src/server/db";
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
const ownerEmail = process.env.DOGFOOD_OWNER_EMAIL;
|
|
22
|
+
if (!ownerEmail) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"DOGFOOD_OWNER_EMAIL is required — set it to a user whose org/team membership the dogfood user should mirror.",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const email = process.env.DOGFOOD_USER_EMAIL ?? "dogfood@langwatch.local";
|
|
28
|
+
const password = process.env.DOGFOOD_PASSWORD ?? "DogfoodPassword!2026";
|
|
29
|
+
const name = process.env.DOGFOOD_USER_NAME ?? "Dogfood";
|
|
30
|
+
const hashed = await hash(password, 10);
|
|
31
|
+
|
|
32
|
+
let user = await prisma.user.findUnique({ where: { email } });
|
|
33
|
+
if (!user) {
|
|
34
|
+
user = await prisma.user.create({
|
|
35
|
+
data: {
|
|
36
|
+
email,
|
|
37
|
+
name,
|
|
38
|
+
emailVerified: true,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
console.log("Created user", user.id);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const acct = await prisma.account.findFirst({
|
|
45
|
+
where: { userId: user.id, provider: "credential" },
|
|
46
|
+
});
|
|
47
|
+
if (acct) {
|
|
48
|
+
await prisma.account.update({
|
|
49
|
+
where: { id: acct.id },
|
|
50
|
+
data: { password: hashed },
|
|
51
|
+
});
|
|
52
|
+
console.log("Updated credential account password");
|
|
53
|
+
} else {
|
|
54
|
+
await prisma.account.create({
|
|
55
|
+
data: {
|
|
56
|
+
userId: user.id,
|
|
57
|
+
provider: "credential",
|
|
58
|
+
providerAccountId: user.id,
|
|
59
|
+
type: "credentials",
|
|
60
|
+
password: hashed,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
console.log("Created credential account");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Mirror ALL of the owner's orgs + teams so we have access to every
|
|
67
|
+
// project they can see. Iterate the full graph: project URLs may redirect
|
|
68
|
+
// across teams (e.g. landing on a project in team A while we'd only
|
|
69
|
+
// joined team B → tRPC 401s with "You do not have permission to access
|
|
70
|
+
// this project resource").
|
|
71
|
+
//
|
|
72
|
+
// Three tables to keep in lockstep, matching the canonical paths in
|
|
73
|
+
// organization.prisma.repository.ts (org bootstrap) and team.ts (member
|
|
74
|
+
// add):
|
|
75
|
+
// 1. OrganizationUser → controls org-membership listing
|
|
76
|
+
// 2. TeamUser → legacy team-membership listing
|
|
77
|
+
// 3. RoleBinding → drives RBAC checks like
|
|
78
|
+
// getUserProtectionsForProject (api/utils.ts:119) which gates
|
|
79
|
+
// canSeeCapturedOutput. Without ORG + TEAM scoped role bindings,
|
|
80
|
+
// Studio shows '🔒 Redacted' on every node output, even with the
|
|
81
|
+
// project's capturedOutputVisibility=VISIBLE_TO_ALL.
|
|
82
|
+
const owner = await prisma.user.findUnique({
|
|
83
|
+
where: { email: ownerEmail },
|
|
84
|
+
include: { orgMemberships: true, teamMemberships: true },
|
|
85
|
+
});
|
|
86
|
+
if (!owner) {
|
|
87
|
+
throw new Error(`Owner user not found: ${ownerEmail}`);
|
|
88
|
+
}
|
|
89
|
+
for (const m of owner.orgMemberships) {
|
|
90
|
+
await prisma.organizationUser.upsert({
|
|
91
|
+
where: {
|
|
92
|
+
userId_organizationId: {
|
|
93
|
+
userId: user.id,
|
|
94
|
+
organizationId: m.organizationId,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
create: {
|
|
98
|
+
userId: user.id,
|
|
99
|
+
organizationId: m.organizationId,
|
|
100
|
+
role: "ADMIN",
|
|
101
|
+
},
|
|
102
|
+
update: {},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
console.log(`Joined ${owner.orgMemberships.length} org(s)`);
|
|
106
|
+
for (const m of owner.teamMemberships) {
|
|
107
|
+
await prisma.teamUser.upsert({
|
|
108
|
+
where: { userId_teamId: { userId: user.id, teamId: m.teamId } },
|
|
109
|
+
create: {
|
|
110
|
+
userId: user.id,
|
|
111
|
+
teamId: m.teamId,
|
|
112
|
+
role: "ADMIN",
|
|
113
|
+
},
|
|
114
|
+
update: {},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
console.log(`Joined ${owner.teamMemberships.length} team(s)`);
|
|
118
|
+
|
|
119
|
+
// Seed RoleBinding rows. RoleBinding has no natural unique key Prisma
|
|
120
|
+
// knows about (uniqueness is enforced via partial indexes in
|
|
121
|
+
// migrations), so we deleteMany + create to stay idempotent.
|
|
122
|
+
const teams = await prisma.team.findMany({
|
|
123
|
+
where: { id: { in: owner.teamMemberships.map((m) => m.teamId) } },
|
|
124
|
+
select: { id: true, organizationId: true },
|
|
125
|
+
});
|
|
126
|
+
await prisma.roleBinding.deleteMany({ where: { userId: user.id } });
|
|
127
|
+
for (const m of owner.orgMemberships) {
|
|
128
|
+
await prisma.roleBinding.create({
|
|
129
|
+
data: {
|
|
130
|
+
organizationId: m.organizationId,
|
|
131
|
+
userId: user.id,
|
|
132
|
+
role: TeamUserRole.ADMIN,
|
|
133
|
+
scopeType: RoleBindingScopeType.ORGANIZATION,
|
|
134
|
+
scopeId: m.organizationId,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
for (const t of teams) {
|
|
139
|
+
await prisma.roleBinding.create({
|
|
140
|
+
data: {
|
|
141
|
+
organizationId: t.organizationId,
|
|
142
|
+
userId: user.id,
|
|
143
|
+
role: TeamUserRole.ADMIN,
|
|
144
|
+
scopeType: RoleBindingScopeType.TEAM,
|
|
145
|
+
scopeId: t.id,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
console.log(
|
|
150
|
+
`Seeded ${owner.orgMemberships.length} org + ${teams.length} team RoleBinding(s)`,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
console.log("\nSign in with:");
|
|
154
|
+
console.log(" email: ", email);
|
|
155
|
+
console.log(" password: ", password);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
main()
|
|
159
|
+
.catch((e) => {
|
|
160
|
+
console.error(e);
|
|
161
|
+
process.exit(1);
|
|
162
|
+
})
|
|
163
|
+
.finally(() => process.exit(0));
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment node
|
|
3
|
+
*
|
|
4
|
+
* Mandatory evaluator-with-real-provider e2e through Studio's
|
|
5
|
+
* `studioBackendPostEvent` SSE surface. Per owner: this is the
|
|
6
|
+
* headline test the migration must produce — proves cost / score /
|
|
7
|
+
* passed / details propagate from a Go-engine evaluator node all the
|
|
8
|
+
* way back through the Studio SSE stream that the TS reducer consumes.
|
|
9
|
+
*
|
|
10
|
+
* Topology:
|
|
11
|
+
*
|
|
12
|
+
* Studio post_event (TS app)
|
|
13
|
+
* └─ studioBackendPostEvent FF-routed
|
|
14
|
+
* └─ POST /go/studio/execute (nlpgo subprocess)
|
|
15
|
+
* ├─ entry → real-OpenAI signature → fake-LangWatch evaluator → end
|
|
16
|
+
* └─ engine.runEvaluator hits ${LANGWATCH_BASE_URL}/api/evaluations/<slug>/evaluate
|
|
17
|
+
* └─ canned response: {status, score, passed, details, cost}
|
|
18
|
+
*
|
|
19
|
+
* Skipped (not failed) when:
|
|
20
|
+
* - OPENAI_API_KEY not set (signature node needs it)
|
|
21
|
+
* - go binary not on PATH
|
|
22
|
+
*
|
|
23
|
+
* Run cost: ~5-8s + ~3s subprocess startup.
|
|
24
|
+
*/
|
|
25
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
26
|
+
import http from "node:http";
|
|
27
|
+
import type { AddressInfo } from "node:net";
|
|
28
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
|
|
31
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
32
|
+
|
|
33
|
+
import type { StudioServerEvent } from "../../../../../optimization_studio/types/events";
|
|
34
|
+
|
|
35
|
+
vi.mock("../../../../../server/featureFlag/featureFlag.service", () => ({
|
|
36
|
+
featureFlagService: {
|
|
37
|
+
isEnabled: vi.fn().mockResolvedValue(true),
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
vi.mock("../../../../../optimization_studio/server/addEnvs", async () => {
|
|
42
|
+
const actual = await vi.importActual<
|
|
43
|
+
typeof import("../../../../../optimization_studio/server/addEnvs")
|
|
44
|
+
>("../../../../../optimization_studio/server/addEnvs");
|
|
45
|
+
return {
|
|
46
|
+
...actual,
|
|
47
|
+
getS3CacheKey: () => undefined,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Per-owner port scheme: 5561X / 5562X range (production port + extra
|
|
52
|
+
// trailing digit, makes the dev↔test connection obvious to readers).
|
|
53
|
+
// Each live integration test that spawns its own nlpgo subprocess
|
|
54
|
+
// claims a unique port:
|
|
55
|
+
// 55620 — playground proxy live OpenAI
|
|
56
|
+
// 55610 — post_event SSE FF gating
|
|
57
|
+
// 55611 — this test (post_event evaluator with real provider e2e)
|
|
58
|
+
const NLPGO_PORT = 55611;
|
|
59
|
+
const REPO_ROOT = path.resolve(__dirname, "../../../../../../..");
|
|
60
|
+
|
|
61
|
+
let nlpgoProcess: ChildProcess | null = null;
|
|
62
|
+
let langwatchSrv: http.Server | null = null;
|
|
63
|
+
let langwatchURL = "";
|
|
64
|
+
|
|
65
|
+
interface CapturedEvalCall {
|
|
66
|
+
path: string;
|
|
67
|
+
method: string;
|
|
68
|
+
authToken: string;
|
|
69
|
+
traceId: string;
|
|
70
|
+
origin: string;
|
|
71
|
+
body: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
const capturedEvalCalls: CapturedEvalCall[] = [];
|
|
74
|
+
|
|
75
|
+
async function waitForHealth(timeoutMs = 30_000): Promise<void> {
|
|
76
|
+
const deadline = Date.now() + timeoutMs;
|
|
77
|
+
while (Date.now() < deadline) {
|
|
78
|
+
try {
|
|
79
|
+
const r = await fetch(`http://127.0.0.1:${NLPGO_PORT}/healthz`);
|
|
80
|
+
if (r.status === 200 || r.status === 503) return;
|
|
81
|
+
} catch {
|
|
82
|
+
// not ready yet
|
|
83
|
+
}
|
|
84
|
+
await sleep(250);
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`nlpgo did not become healthy within ${timeoutMs}ms`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
beforeAll(async () => {
|
|
90
|
+
if (!process.env.OPENAI_API_KEY) return;
|
|
91
|
+
|
|
92
|
+
// Spin up a fake LangWatch evaluator endpoint that records every
|
|
93
|
+
// request and returns a canned processed result.
|
|
94
|
+
langwatchSrv = http.createServer((req, res) => {
|
|
95
|
+
const chunks: Buffer[] = [];
|
|
96
|
+
req.on("data", (c: Buffer) => chunks.push(c));
|
|
97
|
+
req.on("end", () => {
|
|
98
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
99
|
+
let parsed: Record<string, unknown> = {};
|
|
100
|
+
try {
|
|
101
|
+
parsed = JSON.parse(raw) as Record<string, unknown>;
|
|
102
|
+
} catch {
|
|
103
|
+
// leave parsed empty
|
|
104
|
+
}
|
|
105
|
+
capturedEvalCalls.push({
|
|
106
|
+
path: req.url ?? "",
|
|
107
|
+
method: req.method ?? "",
|
|
108
|
+
authToken: (req.headers["x-auth-token"] as string) ?? "",
|
|
109
|
+
traceId: (req.headers["x-langwatch-trace-id"] as string) ?? "",
|
|
110
|
+
origin: (req.headers["x-langwatch-origin"] as string) ?? "",
|
|
111
|
+
body: parsed,
|
|
112
|
+
});
|
|
113
|
+
res.setHeader("Content-Type", "application/json");
|
|
114
|
+
res.end(
|
|
115
|
+
JSON.stringify({
|
|
116
|
+
status: "processed",
|
|
117
|
+
score: 0.91,
|
|
118
|
+
passed: true,
|
|
119
|
+
details: "fake evaluator: looks good",
|
|
120
|
+
cost: { currency: "USD", amount: 0.000123 },
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
await new Promise<void>((resolve) =>
|
|
126
|
+
langwatchSrv!.listen(0, "127.0.0.1", () => resolve()),
|
|
127
|
+
);
|
|
128
|
+
const addr = langwatchSrv.address() as AddressInfo;
|
|
129
|
+
langwatchURL = `http://127.0.0.1:${addr.port}`;
|
|
130
|
+
|
|
131
|
+
process.env.LANGWATCH_NLP_SERVICE = `http://127.0.0.1:${NLPGO_PORT}`;
|
|
132
|
+
delete process.env.LANGWATCH_NLP_LAMBDA_CONFIG;
|
|
133
|
+
|
|
134
|
+
// detached:true so afterAll's process.kill(-pid) reaches the
|
|
135
|
+
// compiled child of `go run`, not just the toolchain wrapper.
|
|
136
|
+
// See post-event.integration.test.ts for the full rationale.
|
|
137
|
+
nlpgoProcess = spawn("go", ["run", "./cmd/service", "nlpgo"], {
|
|
138
|
+
cwd: REPO_ROOT,
|
|
139
|
+
env: {
|
|
140
|
+
...process.env,
|
|
141
|
+
NLPGO_CHILD_BYPASS: "true",
|
|
142
|
+
SERVER_ADDR: `:${NLPGO_PORT}`,
|
|
143
|
+
NLPGO_ENGINE_LANGWATCH_BASE_URL: langwatchURL,
|
|
144
|
+
},
|
|
145
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
146
|
+
detached: true,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
nlpgoProcess.stderr?.on("data", (chunk: Buffer) => {
|
|
150
|
+
if (process.env.NLPGO_TEST_LOG === "1") {
|
|
151
|
+
process.stderr.write(`[nlpgo] ${chunk.toString()}`);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
nlpgoProcess.on("exit", (code, signal) => {
|
|
155
|
+
if (code !== 0 && code !== null) {
|
|
156
|
+
console.error(`nlpgo exited unexpectedly: code=${code} signal=${signal}`);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
await waitForHealth();
|
|
161
|
+
}, 90_000);
|
|
162
|
+
|
|
163
|
+
afterAll(async () => {
|
|
164
|
+
if (nlpgoProcess?.pid) {
|
|
165
|
+
const pgid = -nlpgoProcess.pid;
|
|
166
|
+
try {
|
|
167
|
+
process.kill(pgid, "SIGTERM");
|
|
168
|
+
} catch {
|
|
169
|
+
// group already gone
|
|
170
|
+
}
|
|
171
|
+
const exited = await Promise.race([
|
|
172
|
+
new Promise<boolean>((resolve) =>
|
|
173
|
+
nlpgoProcess!.once("exit", () => resolve(true)),
|
|
174
|
+
),
|
|
175
|
+
sleep(2000).then(() => false),
|
|
176
|
+
]);
|
|
177
|
+
if (!exited) {
|
|
178
|
+
try {
|
|
179
|
+
process.kill(pgid, "SIGKILL");
|
|
180
|
+
} catch {
|
|
181
|
+
// best-effort
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (langwatchSrv) {
|
|
186
|
+
await new Promise<void>((resolve) => langwatchSrv!.close(() => resolve()));
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const liveOpenAI = process.env.OPENAI_API_KEY ? it : it.skip;
|
|
191
|
+
|
|
192
|
+
describe("Studio post_event SSE: signature → evaluator e2e (real OpenAI + fake LangWatch)", () => {
|
|
193
|
+
liveOpenAI(
|
|
194
|
+
"evaluator's score / passed / details / cost propagate through the SSE stream end-to-end",
|
|
195
|
+
async () => {
|
|
196
|
+
capturedEvalCalls.length = 0;
|
|
197
|
+
|
|
198
|
+
const { studioBackendPostEvent } = await import("../post-event");
|
|
199
|
+
|
|
200
|
+
// entry → signature(real OpenAI) → evaluator(fake LangWatch) → end
|
|
201
|
+
const workflow = {
|
|
202
|
+
workflow_id: "ts-eval-e2e",
|
|
203
|
+
api_key: "sk-test-project-abc",
|
|
204
|
+
spec_version: "1.3",
|
|
205
|
+
name: "Eval E2E",
|
|
206
|
+
icon: "🧪",
|
|
207
|
+
description: "evaluator e2e",
|
|
208
|
+
version: "1.3",
|
|
209
|
+
template_adapter: "default",
|
|
210
|
+
nodes: [
|
|
211
|
+
{
|
|
212
|
+
id: "entry",
|
|
213
|
+
type: "entry",
|
|
214
|
+
data: {
|
|
215
|
+
outputs: [
|
|
216
|
+
{ identifier: "question", type: "str" },
|
|
217
|
+
{ identifier: "expected_output", type: "str" },
|
|
218
|
+
],
|
|
219
|
+
dataset: {
|
|
220
|
+
inline: {
|
|
221
|
+
records: {
|
|
222
|
+
question: ["Reply with just the digit 9."],
|
|
223
|
+
expected_output: ["9"],
|
|
224
|
+
},
|
|
225
|
+
count: 1,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
entry_selection: 0,
|
|
229
|
+
train_size: 1.0,
|
|
230
|
+
test_size: 0.0,
|
|
231
|
+
seed: 1,
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: "answer",
|
|
236
|
+
type: "signature",
|
|
237
|
+
data: {
|
|
238
|
+
name: "Answer",
|
|
239
|
+
parameters: [
|
|
240
|
+
{
|
|
241
|
+
identifier: "llm",
|
|
242
|
+
type: "llm",
|
|
243
|
+
value: {
|
|
244
|
+
model: "openai/gpt-5-mini",
|
|
245
|
+
litellm_params: { api_key: process.env.OPENAI_API_KEY },
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
inputs: [{ identifier: "question", type: "str" }],
|
|
250
|
+
outputs: [{ identifier: "answer", type: "str" }],
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: "eval",
|
|
255
|
+
type: "evaluator",
|
|
256
|
+
data: {
|
|
257
|
+
parameters: [
|
|
258
|
+
{
|
|
259
|
+
identifier: "evaluator",
|
|
260
|
+
type: "str",
|
|
261
|
+
value: "langevals/exact_match",
|
|
262
|
+
},
|
|
263
|
+
{ identifier: "name", type: "str", value: "strict-match" },
|
|
264
|
+
{
|
|
265
|
+
identifier: "settings",
|
|
266
|
+
type: "dict",
|
|
267
|
+
value: { mode: "exact" },
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
outputs: [
|
|
271
|
+
{ identifier: "score", type: "float" },
|
|
272
|
+
{ identifier: "passed", type: "bool" },
|
|
273
|
+
{ identifier: "details", type: "str" },
|
|
274
|
+
{ identifier: "cost", type: "dict" },
|
|
275
|
+
],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
id: "end",
|
|
280
|
+
type: "end",
|
|
281
|
+
data: {
|
|
282
|
+
inputs: [
|
|
283
|
+
{ identifier: "score", type: "float" },
|
|
284
|
+
{ identifier: "passed", type: "bool" },
|
|
285
|
+
{ identifier: "details", type: "str" },
|
|
286
|
+
{ identifier: "cost", type: "dict" },
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
edges: [
|
|
292
|
+
{
|
|
293
|
+
id: "e1",
|
|
294
|
+
source: "entry",
|
|
295
|
+
sourceHandle: "outputs.question",
|
|
296
|
+
target: "answer",
|
|
297
|
+
targetHandle: "inputs.question",
|
|
298
|
+
type: "default",
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
id: "e2",
|
|
302
|
+
source: "answer",
|
|
303
|
+
sourceHandle: "outputs.answer",
|
|
304
|
+
target: "eval",
|
|
305
|
+
targetHandle: "output",
|
|
306
|
+
type: "default",
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
id: "e3",
|
|
310
|
+
source: "entry",
|
|
311
|
+
sourceHandle: "outputs.expected_output",
|
|
312
|
+
target: "eval",
|
|
313
|
+
targetHandle: "expected_output",
|
|
314
|
+
type: "default",
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
id: "e4",
|
|
318
|
+
source: "entry",
|
|
319
|
+
sourceHandle: "outputs.question",
|
|
320
|
+
target: "eval",
|
|
321
|
+
targetHandle: "input",
|
|
322
|
+
type: "default",
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
id: "e5",
|
|
326
|
+
source: "eval",
|
|
327
|
+
sourceHandle: "score",
|
|
328
|
+
target: "end",
|
|
329
|
+
targetHandle: "score",
|
|
330
|
+
type: "default",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: "e6",
|
|
334
|
+
source: "eval",
|
|
335
|
+
sourceHandle: "passed",
|
|
336
|
+
target: "end",
|
|
337
|
+
targetHandle: "passed",
|
|
338
|
+
type: "default",
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
id: "e7",
|
|
342
|
+
source: "eval",
|
|
343
|
+
sourceHandle: "details",
|
|
344
|
+
target: "end",
|
|
345
|
+
targetHandle: "details",
|
|
346
|
+
type: "default",
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
id: "e8",
|
|
350
|
+
source: "eval",
|
|
351
|
+
sourceHandle: "cost",
|
|
352
|
+
target: "end",
|
|
353
|
+
targetHandle: "cost",
|
|
354
|
+
type: "default",
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
state: {},
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const message = {
|
|
361
|
+
type: "execute_flow" as const,
|
|
362
|
+
payload: {
|
|
363
|
+
trace_id: "ts-eval-e2e-trace",
|
|
364
|
+
workflow,
|
|
365
|
+
inputs: [{}],
|
|
366
|
+
origin: "workflow",
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const events: StudioServerEvent[] = [];
|
|
371
|
+
await studioBackendPostEvent({
|
|
372
|
+
projectId: "test-project",
|
|
373
|
+
message: message as any,
|
|
374
|
+
onEvent: (ev) => events.push(ev),
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Stream must terminate cleanly.
|
|
378
|
+
const errorEvent = events.find((e) => e.type === "error");
|
|
379
|
+
expect(
|
|
380
|
+
errorEvent,
|
|
381
|
+
errorEvent && "payload" in errorEvent
|
|
382
|
+
? JSON.stringify(errorEvent.payload)
|
|
383
|
+
: "no error",
|
|
384
|
+
).toBeUndefined();
|
|
385
|
+
expect(events.find((e) => e.type === "done")).toBeDefined();
|
|
386
|
+
|
|
387
|
+
// Evaluator node must surface a final state-change carrying the
|
|
388
|
+
// canned score / passed / details / cost. Cost is the tricky one
|
|
389
|
+
// owner explicitly called out as load-bearing — engine projects
|
|
390
|
+
// upstream's {currency, amount} dict onto the per-node outputs
|
|
391
|
+
// when the workflow declares `cost` as an output, AND surfaces
|
|
392
|
+
// the amount on `execution_state.cost` for the workflow-level
|
|
393
|
+
// total accumulator.
|
|
394
|
+
const componentChanges = events.filter(
|
|
395
|
+
(e): e is Extract<StudioServerEvent, { type: "component_state_change" }> =>
|
|
396
|
+
e.type === "component_state_change",
|
|
397
|
+
);
|
|
398
|
+
const finalEvalChange = [...componentChanges]
|
|
399
|
+
.reverse()
|
|
400
|
+
.find(
|
|
401
|
+
(e) =>
|
|
402
|
+
e.payload.component_id === "eval" &&
|
|
403
|
+
(e.payload.execution_state as any)?.status === "success",
|
|
404
|
+
);
|
|
405
|
+
expect(
|
|
406
|
+
finalEvalChange,
|
|
407
|
+
`expected a final success component_state_change for 'eval'; events=${JSON.stringify(componentChanges)}`,
|
|
408
|
+
).toBeDefined();
|
|
409
|
+
const evalOutputs = (finalEvalChange?.payload.execution_state as any)
|
|
410
|
+
?.outputs;
|
|
411
|
+
expect(evalOutputs).toBeDefined();
|
|
412
|
+
expect(evalOutputs.score).toBeCloseTo(0.91, 5);
|
|
413
|
+
expect(evalOutputs.passed).toBe(true);
|
|
414
|
+
expect(evalOutputs.details).toContain("looks good");
|
|
415
|
+
expect(evalOutputs.cost).toEqual({ currency: "USD", amount: 0.000123 });
|
|
416
|
+
// The workflow-level cost field on execution_state surfaces the
|
|
417
|
+
// numeric amount so trace + billing aggregators don't have to
|
|
418
|
+
// unpack the {currency, amount} dict.
|
|
419
|
+
expect(
|
|
420
|
+
(finalEvalChange?.payload.execution_state as any)?.cost,
|
|
421
|
+
).toBeCloseTo(0.000123, 9);
|
|
422
|
+
|
|
423
|
+
// End node must produce the same score/passed/details/cost as
|
|
424
|
+
// outputs (proves the edge wiring of all four evaluator → end
|
|
425
|
+
// edges works end-to-end).
|
|
426
|
+
const finalEndChange = [...componentChanges]
|
|
427
|
+
.reverse()
|
|
428
|
+
.find((e) => e.payload.component_id === "end");
|
|
429
|
+
expect(finalEndChange).toBeDefined();
|
|
430
|
+
const endOutputs = (finalEndChange?.payload.execution_state as any)
|
|
431
|
+
?.outputs;
|
|
432
|
+
expect(endOutputs.score).toBeCloseTo(0.91, 5);
|
|
433
|
+
expect(endOutputs.passed).toBe(true);
|
|
434
|
+
expect(endOutputs.cost).toEqual({ currency: "USD", amount: 0.000123 });
|
|
435
|
+
|
|
436
|
+
// Wire validation: exactly one evaluator HTTP call landed at the
|
|
437
|
+
// fake LangWatch with the right URL, project apiKey on
|
|
438
|
+
// X-Auth-Token, trace_id propagated, and body carrying name +
|
|
439
|
+
// settings + data.
|
|
440
|
+
expect(capturedEvalCalls).toHaveLength(1);
|
|
441
|
+
const call = capturedEvalCalls[0]!;
|
|
442
|
+
expect(call.method).toBe("POST");
|
|
443
|
+
expect(call.path).toBe("/api/evaluations/langevals/exact_match/evaluate");
|
|
444
|
+
expect(call.authToken).toBe("sk-test-project-abc");
|
|
445
|
+
expect(call.traceId).toBe("ts-eval-e2e-trace");
|
|
446
|
+
expect(call.origin).toBe("workflow");
|
|
447
|
+
expect(call.body.name).toBe("strict-match");
|
|
448
|
+
expect((call.body.settings as Record<string, unknown>).mode).toBe(
|
|
449
|
+
"exact",
|
|
450
|
+
);
|
|
451
|
+
const data = call.body.data as Record<string, unknown>;
|
|
452
|
+
expect(data.expected_output).toBe("9");
|
|
453
|
+
// The signature's answer ought to mention the digit 9.
|
|
454
|
+
expect(String(data.output)).toContain("9");
|
|
455
|
+
},
|
|
456
|
+
90_000,
|
|
457
|
+
);
|
|
458
|
+
});
|