Project Course swipe gateway events

This commit is contained in:
-Puter
2026-07-13 20:13:53 +05:30
parent 4fa4a8bbd1
commit a3c4a91cbe
2 changed files with 8 additions and 5 deletions
+7 -4
View File
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import { serviceRoutes } from "../src/routes/services.js";
import { buildCourseGatewayEvent } from "../src/services/course-events.js";
import { extractQscoreSignals } from "../src/events/projectors/qscore-projector.js";
const originalFetch = globalThis.fetch;
const calls: Array<{ url: string; body: Record<string, unknown> }> = [];
globalThis.fetch = (async (input, init) => {
@@ -28,13 +29,15 @@ try {
assert.equal(courseParams.curatorTaskId, "task-1");
assert.equal(recorded.length, 1);
assert.equal((recorded[0].mission as Record<string, unknown>).missionId, "mission-1");
const progress = buildCourseGatewayEvent({ userId: "user_test", action: "record_swipe", body: { params: { video_id: "video-1" } }, result: { status: "completed", messages: [{ type: "agent_data", data: { video_id: "video-1", watch_pct: 0.8 } }] } });
assert.equal(progress.type, "course.task_finished");
assert.ok(!/(progress_recorded|completed|started|watch)/.test(String(progress.type)));
assert.equal(progress.payload.courseId, undefined);
const progress = buildCourseGatewayEvent({ userId: "user_test", action: "record_swipe", body: { params: { video_id: "video-1", anchor_id: "anchor-1", curatorTaskId: "task-3", missionId: "mission-3" } }, result: { status: "completed", messages: [{ type: "agent_data", data: { watch_pct: 0.8 } }] } });
assert.equal(progress.type, "course.progress_recorded");
const projected = extractQscoreSignals({ type: progress.type, payload: progress.payload, id: "evt-course", userId: "user_test", source: progress.source, category: "service", mission: progress.mission ?? null, subject: progress.subject ?? null, correlation: progress.correlation ?? null } as never);
assert.ok(projected.some((signal) => signal.signalId === "courses.completion_rate"), "record_swipe must project course progress");
assert.equal(progress.payload.courseId, "anchor-1");
assert.equal(progress.payload.lessonId, "video-1");
const nonProgress = buildCourseGatewayEvent({ userId: "user_test", action: "get_feed", body: { params: {} }, result: { status: "completed", messages: [] } });
assert.equal(nonProgress.type, "course.task_finished");
assert.equal(extractQscoreSignals({ type: nonProgress.type, payload: nonProgress.payload, id: "evt-feed", userId: "user_test", source: nonProgress.source, category: "service", mission: null, subject: null, correlation: null } as never).length, 0);
recorded.length = 0;
calls.length = 0;
+1 -1
View File
@@ -24,7 +24,7 @@ export function buildCourseGatewayEvent(input: { userId: string; action: string;
return {
userId: input.userId,
source: "course-a2a-gateway",
type: input.result.status === "error" ? "course.request.failed" : "course.task_finished",
type: input.result.status === "error" ? "course.request.failed" : progressAction ? "course.progress_recorded" : "course.task_finished",
payload,
correlation,
mission: missionId || missionInstanceId || stageId ? { missionId, instanceId: missionInstanceId, stageId, source: pick(params.source) ?? "curator-v1" } : undefined,