Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions pkgs/id/crates/id-web/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2765,11 +2765,7 @@ mod upload_router_tests {
// the invite through the mount-scoped API URL — the session
// round-trip (refused anonymously, served with the secret)
// behaves exactly as it does on the program surface itself.
let res = app
.clone()
.oneshot(invite(Some("s3cret")))
.await
.unwrap();
let res = app.clone().oneshot(invite(Some("s3cret"))).await.unwrap();
assert_eq!(res.status(), StatusCode::OK);
let body = to_bytes(res.into_body(), usize::MAX).await.unwrap();
assert!(!body.is_empty());
Expand All @@ -2779,8 +2775,7 @@ mod upload_router_tests {
async fn publication_mounts_isolate_sibling_worlds_at_the_router() {
let (_, mut state, _dir, _endpoint, _docs) = router_with_state().await;
let opener = id_worlds::world_hub::testing::MemoryOpener::new(false);
let dyn_opener: std::sync::Arc<dyn id_worlds::world_hub::WorldOpener> =
opener.clone();
let dyn_opener: std::sync::Arc<dyn id_worlds::world_hub::WorldOpener> = opener.clone();
let hub = id_worlds::world_hub::WorldHub::new(
dyn_opener,
Some("admin".to_owned()),
Expand Down Expand Up @@ -2831,7 +2826,11 @@ mod upload_router_tests {
.oneshot(invite("/prog/api/world/invite", "vault"))
.await
.unwrap();
assert_eq!(res.status(), StatusCode::NOT_FOUND, "invite vault via /prog");
assert_eq!(
res.status(),
StatusCode::NOT_FOUND,
"invite vault via /prog"
);
let res = app
.clone()
.oneshot(invite("/vault/api/world/invite", "vault"))
Expand Down
22 changes: 11 additions & 11 deletions pkgs/id/hosted-worker/test/front-door.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ function front(path: string, init: RequestInit = {}): Request {
function countingBody(chunks: Uint8Array[]) {
const seen = { bytes: 0 };
let i = 0;
const body = new ReadableStream<Uint8Array>({
pull(c) {
if (i >= chunks.length) return c.close();
const chunk = chunks[i++];
seen.bytes += chunk.byteLength;
c.enqueue(chunk);
const body = new ReadableStream<Uint8Array>(
{
pull(c) {
if (i >= chunks.length) return c.close();
const chunk = chunks[i++];
seen.bytes += chunk.byteLength;
c.enqueue(chunk);
},
},
}, { highWaterMark: 0 });
{ highWaterMark: 0 },
);
return { body, seen };
}

test("a declared oversized body is refused at the front door without being read", async () => {
const { env, calls } = makeEnv({ USER_CEILING_BYTES: "10" });
const { body, seen } = countingBody([new Uint8Array(64)]);
const r = await worker.fetch(
front("/v1/blobs", { method: "PUT", body, headers: { "content-length": "64" } }),
env,
);
const r = await worker.fetch(front("/v1/blobs", { method: "PUT", body, headers: { "content-length": "64" } }), env);
assert.equal(r.status, 413);
assert.equal(((await r.json()) as { error: string }).error, "body_too_large");
assert.equal(seen.bytes, 0, "the body was never read");
Expand Down
6 changes: 5 additions & 1 deletion pkgs/id/hosted-worker/test/usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ test("kv usage and the ceiling count UTF-8 bytes, not characters (#11349)", asyn
// Overwriting a 20-byte value with 2 ASCII bytes frees 18 bytes of headroom.
assert.equal((await doA.fetch(routed("/v1/kv/k0", { method: "PUT", body: "ab" }))).status, 200);
assert.equal((await getUsage(doA)).kv_bytes, 82);
assert.equal((await doA.fetch(routed("/v1/kv/k1", { method: "PUT", body: "\u00e9".repeat(19) }))).status, 200, "38 bytes fits 18 freed + 20 prior");
assert.equal(
(await doA.fetch(routed("/v1/kv/k1", { method: "PUT", body: "\u00e9".repeat(19) }))).status,
200,
"38 bytes fits 18 freed + 20 prior",
);
assert.equal((await getUsage(doA)).kv_bytes, 100);
});

Expand Down
8 changes: 6 additions & 2 deletions pkgs/id/src/structured_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,13 @@ mod tests {
std::fs::create_dir_all(&dir).expect("create temp dir");

let mut writer = SharedFileWriter::open(&path).expect("open log file");
writer.write_all(b"before delete\n").expect("write before delete");
writer
.write_all(b"before delete\n")
.expect("write before delete");
std::fs::remove_file(&path).expect("delete log");
writer.write_all(b"after delete\n").expect("write after delete");
writer
.write_all(b"after delete\n")
.expect("write after delete");
writer.write_all(b"no newline").expect("write partial tail");
drop(writer);

Expand Down
59 changes: 38 additions & 21 deletions pkgs/id/web/src/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,17 @@ describe("ordered_list start parsing (#2005)", () => {
expect(parseOrderedListStart(raw)).toBe(expected);
});

it.each(["abc", "2.5", "0x10", "1e3", "", "-3", "9007199254740993"])(
"falls back to 1 for invalid start=%s",
(raw) => {
expect(parseOrderedListStart(raw)).toBe(1);
},
);
it.each([
"abc",
"2.5",
"0x10",
"1e3",
"",
"-3",
"9007199254740993",
])("falls back to 1 for invalid start=%s", (raw) => {
expect(parseOrderedListStart(raw)).toBe(1);
});

it("falls back to 1 when the start attribute is absent", () => {
expect(parseOrderedListStart(null)).toBe(1);
Expand Down Expand Up @@ -384,15 +389,20 @@ describe("task_list start parsing (#4100)", () => {
expect(olGetAttrs()(el)).toEqual({ order: expected });
});

it.each(["abc", "2.5", "0x10", "1e3", "", "-3", "9007199254740993"])(
"falls back to 1 for invalid start=%s",
(raw) => {
const el = document.createElement("ol");
el.classList.add("contains-task-list");
el.setAttribute("start", raw);
expect(olGetAttrs()(el)).toEqual({ order: 1 });
},
);
it.each([
"abc",
"2.5",
"0x10",
"1e3",
"",
"-3",
"9007199254740993",
])("falls back to 1 for invalid start=%s", (raw) => {
const el = document.createElement("ol");
el.classList.add("contains-task-list");
el.setAttribute("start", raw);
expect(olGetAttrs()(el)).toEqual({ order: 1 });
});

it("defaults order to 1 without a start attribute", () => {
const el = document.createElement("ol");
Expand Down Expand Up @@ -770,12 +780,19 @@ describe("image dimension parsing (#2010)", () => {
expect(parseImageDimension(raw)).toBe(expected);
});

it.each(["200px", "50%", "2.5", "-5", "abc", "0x10", "1e3", "", "9007199254740993"])(
"drops invalid dimension=%s to null",
(raw) => {
expect(parseImageDimension(raw)).toBeNull();
},
);
it.each([
"200px",
"50%",
"2.5",
"-5",
"abc",
"0x10",
"1e3",
"",
"9007199254740993",
])("drops invalid dimension=%s to null", (raw) => {
expect(parseImageDimension(raw)).toBeNull();
});

it("drops an absent dimension to null", () => {
expect(parseImageDimension(null)).toBeNull();
Expand Down
13 changes: 12 additions & 1 deletion pkgs/id/web/src/shell-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ type Field = {
/** The result of checking one frame. */
export type Check = { ok: true; type: string } | { ok: false; error: string };

const FIELD_TYPES = new Set<string>(["string", "hex", "bool", "u16", "u32", "u64", "i64", "string[]", "array", "object"]);
const FIELD_TYPES = new Set<string>([
"string",
"hex",
"bool",
"u16",
"u32",
"u64",
"i64",
"string[]",
"array",
"object",
]);
const PHASES = new Set<string>(["opening", "query", "install", "joined", "closed"]);
const FRAME_CLASSES = new Set<string>([
"event",
Expand Down