feat(assessment): watermark the task text of real attempts
This commit is contained in:
1 parent
24b64d698a
commit
c975a0d506
57 files changed
+2429
-92
No files matched your search
@@ -44,17 +44,26 @@ export type MockedAttempt = {
|
||||
acknowledgements: unknown[];
|
||||
};
|
||||
|
||||
export const watermarkCode = "7K3QD-9XM2T";
|
||||
/** The notice text version the page knows; the mock server requires the same one. */
|
||||
export const noticeVersion = 3;
|
||||
|
||||
type Options = {
|
||||
content: MockItemContent;
|
||||
/** The candidate already acknowledged the notice, so the start asks nothing. */
|
||||
noticeAcknowledged?: boolean;
|
||||
/** The task text the server sends, with its invisible mark when it has one. */
|
||||
prompt?: string;
|
||||
/** The visible code of the attempt, or null for an attempt without one. */
|
||||
watermark?: string | null;
|
||||
};
|
||||
|
||||
function isoSeconds(ms: number): string {
|
||||
return `${new Date(ms).toISOString().slice(0, 19)}Z`;
|
||||
}
|
||||
|
||||
function attemptBody(version: number, content: MockItemContent) {
|
||||
function attemptBody(version: number, options: Options) {
|
||||
const { content, prompt = taskPrompt, watermark = watermarkCode } = options;
|
||||
return {
|
||||
id: attemptId,
|
||||
version,
|
||||
@@ -76,8 +85,9 @@ function attemptBody(version: number, content: MockItemContent) {
|
||||
sessions: { used: 1, max: 2, idle_timeout_seconds: 1800 },
|
||||
finished_at: null,
|
||||
progress: { answered_items: 0, max_items: 5 },
|
||||
current_item: { id: itemId, sequence: 1, prompt: taskPrompt, content },
|
||||
current_item: { id: itemId, sequence: 1, prompt, content },
|
||||
practices: [],
|
||||
...(watermark ? { watermark: { code: watermark } } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -118,16 +128,16 @@ export async function mockAttemptApi(page: Page, options: Options): Promise<Mock
|
||||
recorded.acknowledgements.push(JSON.parse(request.postData() ?? "{}"));
|
||||
}
|
||||
return reply({
|
||||
notice_version: 2,
|
||||
notice_version: noticeVersion,
|
||||
acknowledged,
|
||||
acknowledged_at: acknowledged ? "2026-10-10T10:00:00Z" : null,
|
||||
});
|
||||
}
|
||||
if (path === base && method === "GET") return reply(attemptBody(1, options.content));
|
||||
if (path === `${base}/sessions`) return reply(attemptBody(2, options.content));
|
||||
if (path === base && method === "GET") return reply(attemptBody(1, options));
|
||||
if (path === `${base}/sessions`) return reply(attemptBody(2, options));
|
||||
if (path === `${base}/answers`) {
|
||||
recorded.answers.push(JSON.parse(request.postData() ?? "{}"));
|
||||
return reply(attemptBody(3, options.content));
|
||||
return reply(attemptBody(3, options));
|
||||
}
|
||||
if (path === `${base}/signals`) {
|
||||
const body = JSON.parse(request.postData() ?? "{}") as { events: SignalEvent[] };
|
||||
|
||||
Reference in new issue
Block a user