fix(replay): serve admitted AI overlays without revalidation
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
|
||||
import { createServer } from "vite";
|
||||
|
||||
let server;
|
||||
let fetchPerceptionPreparationStatus;
|
||||
let perceptionPreparationMessage;
|
||||
|
||||
before(async () => {
|
||||
server = await createServer({
|
||||
appType: "custom",
|
||||
logLevel: "silent",
|
||||
server: { middlewareMode: true },
|
||||
});
|
||||
({
|
||||
fetchPerceptionPreparationStatus,
|
||||
perceptionPreparationMessage,
|
||||
} = await server.ssrLoadModule(
|
||||
"/src/core/observation/perceptionPreparation.ts",
|
||||
));
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server?.close();
|
||||
});
|
||||
|
||||
test("perception preparation status is same-origin, typed and phase-specific", async () => {
|
||||
let requested;
|
||||
const status = await fetchPerceptionPreparationStatus(
|
||||
"/api/v1/observation-sessions/session-1/perception.rrd",
|
||||
"recording-001",
|
||||
{
|
||||
origin: "http://127.0.0.1:8000",
|
||||
fetcher: async (input, init) => {
|
||||
requested = { url: String(input), method: init.method };
|
||||
return Response.json({
|
||||
state: "preparing",
|
||||
phase: "artifact-validation",
|
||||
elapsed_seconds: 2.5,
|
||||
byte_length: null,
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(requested, {
|
||||
url: "http://127.0.0.1:8000/api/v1/observation-sessions/session-1/perception/status?recording_id=recording-001",
|
||||
method: "GET",
|
||||
});
|
||||
assert.deepEqual(status, {
|
||||
state: "preparing",
|
||||
phase: "artifact-validation",
|
||||
elapsedSeconds: 2.5,
|
||||
byteLength: null,
|
||||
});
|
||||
assert.equal(
|
||||
perceptionPreparationMessage(status.phase),
|
||||
"Проверяем опубликованный AI-результат.",
|
||||
);
|
||||
});
|
||||
|
||||
test("perception preparation status rejects cross-origin endpoints", async () => {
|
||||
await assert.rejects(
|
||||
fetchPerceptionPreparationStatus(
|
||||
"https://example.com/api/v1/observation-sessions/session-1/perception.rrd",
|
||||
"recording-001",
|
||||
{
|
||||
origin: "http://127.0.0.1:8000",
|
||||
fetcher: async () => {
|
||||
throw new Error("must not fetch");
|
||||
},
|
||||
},
|
||||
),
|
||||
/Unsafe perception preparation status request/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user