Rename existing Endoleap proxy and configuration in place [skip ci]
This commit is contained in:
+32
-32
@@ -132,7 +132,7 @@ const app = spawn(
|
||||
],
|
||||
{
|
||||
cwd: fileURLToPath(new URL("../", import.meta.url)),
|
||||
env: { ...process.env, FOUNDRY_API_ORIGIN: "http://127.0.0.1:" + port },
|
||||
env: { ...process.env, BEDROCK_API_ORIGIN: "http://127.0.0.1:" + port },
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
},
|
||||
);
|
||||
@@ -188,7 +188,7 @@ try {
|
||||
}
|
||||
assert.equal((await fetch(host + "/missing-page")).status, 404);
|
||||
// 登录代理必须去掉响应体 token,改设 HttpOnly/SameSite cookie,并报告上游计时。
|
||||
const res = await fetch(host + "/api/foundry/auth/login", {
|
||||
const res = await fetch(host + "/api/bedrock/auth/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Origin: host },
|
||||
body: "{}",
|
||||
@@ -207,7 +207,7 @@ try {
|
||||
// 2500ms 的 Promise.race 只限制 fetch 返回响应头,后面的 reader.read 不在该 deadline 内,不能据此声称首块也受同一计时约束。
|
||||
let streamTimer;
|
||||
try {
|
||||
const streamed = await Promise.race([fetch(host + "/api/foundry/workspaces/space/materials/stream-board/canvas", { headers: { Cookie: session } }), new Promise((_, reject) => { streamTimer = setTimeout(() => reject(new Error("Snapshot proxy buffered the body")), 2500); })]);
|
||||
const streamed = await Promise.race([fetch(host + "/api/bedrock/workspaces/space/materials/stream-board/canvas", { headers: { Cookie: session } }), new Promise((_, reject) => { streamTimer = setTimeout(() => reject(new Error("Snapshot proxy buffered the body")), 2500); })]);
|
||||
assert.equal(streamed.headers.get("etag"), '\"1\"'); assert.equal(streamed.headers.get("x-canvas-schema-version"), "2");
|
||||
assert.match(streamed.headers.get("server-timing"), /upstream;dur=.*proxy_headers;dur=/);
|
||||
assert.ok(streamed.headers.get("set-cookie")?.includes("HttpOnly"));
|
||||
@@ -217,27 +217,27 @@ try {
|
||||
assert.equal(JSON.parse(raw).document.schema_version, 2);
|
||||
} finally { clearTimeout(streamTimer); releaseStream(); }
|
||||
// 子命令循环只检查头透传;随后检查资源 variant、目录分页与 AI 查询参数白名单。
|
||||
const v2Base = host + "/api/foundry/workspaces/space/materials/foundry-generated-id/canvas";
|
||||
const v2Base = host + "/api/bedrock/workspaces/space/materials/foundry-generated-id/canvas";
|
||||
const idem = "11111111-1111-4111-8111-111111111111";
|
||||
for (const path of ["connections", "subgraphs", "subgraphs/migrate", "subgraphs/frame-1/members", "subgraphs/frame-1/dissolve", "transactions/tx-1/undo", "ai/runs", "ai/runs/run-1/cancel", "ai/runs/run-1/apply"]) {
|
||||
const response = await fetch(v2Base + "/" + path, { method: "POST", headers: { Cookie: session, Origin: host, "Content-Type": "application/json", "Idempotency-Key": idem, "If-Match": '\"7\"' }, body: "{}" });
|
||||
assert.equal(response.status, 200, path); const echo = await response.json(); assert.equal(echo.key, idem); assert.equal(echo.version, '\"7\"'); assert.equal(echo.accept, "application/vnd.foundry.canvas+json;version=2");
|
||||
}
|
||||
const preview = await fetch(host + "/api/foundry/workspaces/space/assets/image?variant=preview", { headers: { Cookie: session } });assert.equal(preview.status,200);assert.equal(preview.headers.get("x-asset-variant"),"preview");await preview.arrayBuffer();
|
||||
const directoryResponse = await (await fetch(host + "/api/foundry/workspaces/space/materials?kind=board&sort=modified&include_subgraphs=true&limit=100&offset=100", { headers: { Cookie: session } })).json();
|
||||
const preview = await fetch(host + "/api/bedrock/workspaces/space/assets/image?variant=preview", { headers: { Cookie: session } });assert.equal(preview.status,200);assert.equal(preview.headers.get("x-asset-variant"),"preview");await preview.arrayBuffer();
|
||||
const directoryResponse = await (await fetch(host + "/api/bedrock/workspaces/space/materials?kind=board&sort=modified&include_subgraphs=true&limit=100&offset=100", { headers: { Cookie: session } })).json();
|
||||
const directoryQuery = new URL(directoryResponse.url, "http://mock").searchParams;
|
||||
assert.equal(directoryQuery.get("include_subgraphs"), "true"); assert.equal(directoryQuery.get("offset"), "100");
|
||||
const events = await (await fetch(v2Base + "/ai/runs/run-1?after_seq=12&limit=100&status=active&include_descendants=true&cursor=cursor&secret=drop", { headers: { Cookie: session } })).json();
|
||||
const query = new URL(events.url, "http://mock").searchParams; assert.equal(query.get("after_seq"), "12"); assert.equal(query.get("include_descendants"), "true"); assert.equal(query.get("cursor"), "cursor"); assert.equal(query.get("secret"), null);
|
||||
// 验证慢 body 完整读取和 trace 标识,再检查资源认证、MIME 拒绝、nosniff 与 multipart 转发。
|
||||
const slowSnapshot = await fetch(host + "/api/foundry/workspaces/space/materials/slow-body-board/canvas", { headers: { Cookie: session } });
|
||||
const slowSnapshot = await fetch(host + "/api/bedrock/workspaces/space/materials/slow-body-board/canvas", { headers: { Cookie: session } });
|
||||
assert.ok(slowSnapshot.headers.get("x-canvas-trace-id")); assert.equal((await slowSnapshot.json()).version, 210, "A valid body can finish after the old 15-second total deadline");
|
||||
const asset = await fetch(host + "/api/foundry/workspaces/space/assets/image-1", { headers: { Cookie: session } });
|
||||
const asset = await fetch(host + "/api/bedrock/workspaces/space/assets/image-1", { headers: { Cookie: session } });
|
||||
assert.equal(asset.status, 200); assert.equal(asset.headers.get("content-type"), "image/png"); assert.equal(asset.headers.get("x-content-type-options"), "nosniff"); assert.ok(asset.headers.get("set-cookie")?.includes("HttpOnly")); assert.equal((await asset.arrayBuffer()).byteLength, 8);
|
||||
assert.equal((await fetch(host + "/api/foundry/workspaces/space/assets/image-1")).status, 401);
|
||||
assert.equal((await fetch(host + "/api/foundry/workspaces/space/assets/bad", { headers: { Cookie: session } })).status, 502);
|
||||
assert.equal((await fetch(host + "/api/bedrock/workspaces/space/assets/image-1")).status, 401);
|
||||
assert.equal((await fetch(host + "/api/bedrock/workspaces/space/assets/bad", { headers: { Cookie: session } })).status, 502);
|
||||
const form = new FormData(); form.set("image", new Blob([new Uint8Array([137,80,78,71])], { type: "image/png" }), "test.png");
|
||||
const upload = await (await fetch(host + "/api/foundry/workspaces/space/assets", { method: "POST", headers: { Cookie: session, Origin: host, "Idempotency-Key": idem }, body: form })).json();
|
||||
const upload = await (await fetch(host + "/api/bedrock/workspaces/space/assets", { method: "POST", headers: { Cookie: session, Origin: host, "Idempotency-Key": idem }, body: form })).json();
|
||||
// 这里只核对 multipart Content-Type、image 字段标记及幂等键;未解析 multipart,也未逐字节比较上传文件内容。
|
||||
assert.match(upload.type, /^multipart\/form-data; boundary=/); assert.equal(upload.key, idem); assert.ok(upload.multipart);
|
||||
// 有效会话首页重定向且不缓存私有结果;dashboard 初始 HTML 不应包含画布或 landing。
|
||||
@@ -264,29 +264,29 @@ try {
|
||||
|
||||
assert.equal(
|
||||
(
|
||||
await fetch(host + "/api/foundry/profile", {
|
||||
await fetch(host + "/api/bedrock/profile", {
|
||||
headers: { Cookie: session },
|
||||
})
|
||||
).status,
|
||||
200,
|
||||
);
|
||||
assert.equal((await fetch(host + "/api/foundry/profile")).status, 401);
|
||||
assert.equal((await fetch(host + "/api/bedrock/profile")).status, 401);
|
||||
// 续期只接受有效剩余秒数;非法上游值和无效会话不应产生新的 Set-Cookie。
|
||||
mockSessionSeconds = "3600";
|
||||
const renewed = await fetch(host + "/api/foundry/profile", { headers: { Cookie: session } });
|
||||
const renewed = await fetch(host + "/api/bedrock/profile", { headers: { Cookie: session } });
|
||||
assert.equal(renewed.status, 200); assert.match(renewed.headers.get("set-cookie") || "", /Max-Age=3600/);
|
||||
assert.match(renewed.headers.get("set-cookie") || "", /HttpOnly/);
|
||||
mockSessionSeconds = "garbage";
|
||||
const malformedRenewal = await fetch(host + "/api/foundry/profile", { headers: { Cookie: session } });
|
||||
const malformedRenewal = await fetch(host + "/api/bedrock/profile", { headers: { Cookie: session } });
|
||||
assert.equal(malformedRenewal.headers.get("set-cookie"), null);
|
||||
mockSessionSeconds = "2592000";
|
||||
const expiredSession = await fetch(host + "/api/foundry/profile", { headers: { Cookie: "foundry_session=expired" } });
|
||||
const expiredSession = await fetch(host + "/api/bedrock/profile", { headers: { Cookie: "foundry_session=expired" } });
|
||||
assert.equal(expiredSession.status, 401); assert.equal(expiredSession.headers.get("set-cookie"), null);
|
||||
|
||||
// 读取头像再修改公开资料,确认未涉及的头像字段保持。
|
||||
const profile = await (await fetch(host + "/api/foundry/profile", { headers: { Cookie: session } })).json();
|
||||
const profile = await (await fetch(host + "/api/bedrock/profile", { headers: { Cookie: session } })).json();
|
||||
assert.equal(profile.avatar_url, "https://lh3.googleusercontent.com/test-avatar=s96-c");
|
||||
const updated = await fetch(host + "/api/foundry/profile", {
|
||||
const updated = await fetch(host + "/api/bedrock/profile", {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json", Cookie: session, Origin: host },
|
||||
body: JSON.stringify({ username: "test", display_name: "Updated name" }),
|
||||
@@ -297,7 +297,7 @@ try {
|
||||
assert.equal(updatedProfile.avatar_url, profile.avatar_url);
|
||||
|
||||
// 经真实代理创建、读取和重命名内存图谱,检查服务分配身份、内容保留和元信息版本递增。
|
||||
const create = await fetch(host + "/api/foundry/workspaces/space/materials", {
|
||||
const create = await fetch(host + "/api/bedrock/workspaces/space/materials", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Cookie: session, Origin: host },
|
||||
body: JSON.stringify({ kind: "board", title: "未命名图谱", content: { schema_version: 1 } }),
|
||||
@@ -305,18 +305,18 @@ try {
|
||||
assert.equal(create.status, 201);
|
||||
const graph = await create.json();
|
||||
assert.deepEqual(graph, { id: "foundry-generated-id", workspace_id: "space", kind: "board", version: 1 });
|
||||
const opened = await fetch(host + `/api/foundry/workspaces/${graph.workspace_id}/materials/${graph.id}`, { headers: { Cookie: session } });
|
||||
const opened = await fetch(host + `/api/bedrock/workspaces/${graph.workspace_id}/materials/${graph.id}`, { headers: { Cookie: session } });
|
||||
assert.equal(opened.status, 200);
|
||||
const stored = await opened.json();
|
||||
assert.equal(stored.title, "未命名图谱");
|
||||
assert.equal(stored.workspace_id, "space");
|
||||
assert.equal(stored.content.schema_version, 1);
|
||||
const rename = await fetch(host + `/api/foundry/workspaces/${graph.workspace_id}/materials/${graph.id}`, {
|
||||
const rename = await fetch(host + `/api/bedrock/workspaces/${graph.workspace_id}/materials/${graph.id}`, {
|
||||
method: "PATCH", headers: { "Content-Type": "application/json", Cookie: session, Origin: host, "If-Match": '"1"' },
|
||||
body: JSON.stringify({ title: "改名后的图谱", description: "", content: stored.content }),
|
||||
});
|
||||
assert.equal(rename.status, 204);
|
||||
const renamed = await (await fetch(host + `/api/foundry/workspaces/${graph.workspace_id}/materials/${graph.id}`, { headers: { Cookie: session } })).json();
|
||||
const renamed = await (await fetch(host + `/api/bedrock/workspaces/${graph.workspace_id}/materials/${graph.id}`, { headers: { Cookie: session } })).json();
|
||||
assert.equal(renamed.title, "改名后的图谱");
|
||||
assert.equal(renamed.version, 2);
|
||||
assert.deepEqual(renamed.content, stored.content);
|
||||
@@ -324,14 +324,14 @@ try {
|
||||
// workspace/board 各自使用 ID 或 slug 的四种组合都应定位同一图谱和独立画布版本。
|
||||
// 替身通过 canonical 字符串替换提供该映射;此处验证代理接受四种路径,不验证真实 Foundry 的 slug 解析实现。
|
||||
for (const workspace of ["space", "creative-space"]) for (const board of ["foundry-generated-id", "my-board"]) {
|
||||
const path = `/api/foundry/workspaces/${workspace}/materials/${board}`;
|
||||
const path = `/api/bedrock/workspaces/${workspace}/materials/${board}`;
|
||||
const material = await (await fetch(host + path, { headers: { Cookie: session } })).json();
|
||||
assert.equal(material.id, "foundry-generated-id"); assert.equal(material.slug, "my-board");
|
||||
const snapshot = await fetch(host + path + "/canvas", { headers: { Cookie: session } });
|
||||
assert.equal(snapshot.status, 200); assert.equal(snapshot.headers.get("etag"), '"1"');
|
||||
assert.equal((await snapshot.json()).version, 1);
|
||||
}
|
||||
const canvasPath = "/api/foundry/workspaces/creative-space/materials/my-board/canvas";
|
||||
const canvasPath = "/api/bedrock/workspaces/creative-space/materials/my-board/canvas";
|
||||
// 生成超过 1 MiB 的完整快照经代理保存/恢复,再用旧版本重发检查 412;不是增量或大文件性能测试。
|
||||
const largeDocument = { schema_version: 1, nodes: Array.from({ length: 15 }, (_, index) => ({ id: "text-" + index, type: "material", position: { x: index * 300, y: 100 }, width: 260, height: 200, data: { kind: "text", title: "保存测试", text: "x".repeat(90000), fontSize: 24, rotation: 30, textStyle: { bold: true, color: "#123456" } } })), edges: [], viewport: { x: 20, y: 40, zoom: 0.75 } };
|
||||
const savedCanvas = await fetch(host + canvasPath, { method: "PATCH", headers: { Cookie: session, Origin: host, "Content-Type": "application/json", "If-Match": '"1"' }, body: JSON.stringify({ document: largeDocument }) });
|
||||
@@ -354,7 +354,7 @@ try {
|
||||
assert.equal(restored.document.nodes[1].data.frameId, "frame-1");
|
||||
}
|
||||
assert.equal((await fetch(host + canvasPath)).status, 401);
|
||||
assert.equal((await fetch(host + "/api/foundry/workspaces/space/search/my-board/canvas")).status, 404);
|
||||
assert.equal((await fetch(host + "/api/bedrock/workspaces/space/search/my-board/canvas")).status, 404);
|
||||
// 超过画布 body 上限的请求必须返回 413,不能转成成功保存。
|
||||
const oversizedCanvas = await fetch(host + canvasPath, { method: "PATCH", headers: { Cookie: session, "Content-Type": "application/json" }, body: JSON.stringify({ document: "x".repeat(5 * 1024 * 1024) }) });
|
||||
assert.equal(oversizedCanvas.status, 413);
|
||||
@@ -364,7 +364,7 @@ try {
|
||||
for (const origin of ["https://example.com", "null"])
|
||||
assert.equal(
|
||||
(
|
||||
await fetch(host + "/api/foundry/auth/login", {
|
||||
await fetch(host + "/api/bedrock/auth/login", {
|
||||
method: "POST",
|
||||
headers: { Origin: origin, "Content-Type": "application/json" },
|
||||
body: "{}",
|
||||
@@ -372,27 +372,27 @@ try {
|
||||
).status,
|
||||
403,
|
||||
);
|
||||
assert.equal((await fetch(host + "/api/foundry/unlisted")).status, 404);
|
||||
assert.equal((await fetch(host + "/api/bedrock/unlisted")).status, 404);
|
||||
assert.equal(
|
||||
(await fetch(host + "/api/oauth/slack?challenge=bad")).status,
|
||||
400,
|
||||
);
|
||||
assert.equal(res.headers.get("cache-control"), "no-store");
|
||||
const secure = await fetch(host + "/api/foundry/auth/login", {
|
||||
const secure = await fetch(host + "/api/bedrock/auth/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "X-Forwarded-Proto": "https" },
|
||||
body: "{}",
|
||||
});
|
||||
assert.match(secure.headers.get("set-cookie"), /; Secure/);
|
||||
for (const [body, status] of [["{", 400], [JSON.stringify({ text: "x".repeat(1024 * 1024) }), 413]]) {
|
||||
const invalid = await fetch(host + "/api/foundry/auth/login", {
|
||||
const invalid = await fetch(host + "/api/bedrock/auth/login", {
|
||||
method: "POST", headers: { "Content-Type": "application/json" }, body,
|
||||
});
|
||||
assert.equal(invalid.status, status);
|
||||
}
|
||||
assert.equal((await fetch(host + "/api/foundry/profile", { method: "PUT" })).status, 405);
|
||||
assert.equal((await fetch(host + "/api/bedrock/profile", { method: "PUT" })).status, 405);
|
||||
// 查询保留 kind/limit 而删除未许可 secret;此处使用替身回显观察最终上游路径。
|
||||
const materials = await fetch(host + "/api/foundry/workspaces/space/materials?kind=board&limit=100&secret=drop", {
|
||||
const materials = await fetch(host + "/api/bedrock/workspaces/space/materials?kind=board&limit=100&secret=drop", {
|
||||
method: "PATCH", headers: { "Content-Type": "application/json" }, body: "{}",
|
||||
});
|
||||
assert.deepEqual(await materials.json(), {
|
||||
@@ -405,7 +405,7 @@ try {
|
||||
assert.equal(redirect.headers.get("location"), `http://127.0.0.1:${port}/projects/endoleap/auth/${provider}?challenge=${"a".repeat(43)}`);
|
||||
}
|
||||
// 登出保持 204 空体并清除 cookie;下方 PASS 长文是摘要,实际覆盖以逐项断言为准。
|
||||
const logout = await fetch(host + "/api/foundry/auth/logout", {
|
||||
const logout = await fetch(host + "/api/bedrock/auth/logout", {
|
||||
method: "POST", headers: { "Content-Type": "application/json", Cookie: session }, body: "{}",
|
||||
});
|
||||
assert.equal(logout.status, 204);
|
||||
|
||||
Reference in New Issue
Block a user