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
5 changes: 1 addition & 4 deletions pkgs/id/e2e/tests/world-surface.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ test.describe("World surface", () => {
// a role=img grid with a "columns by rows" label, not guest HTML text.
const screen = view.locator(".id-world-screen");
await expect(screen).toBeVisible({ timeout: 15_000 });
await expect(view.locator('[role="img"]')).toHaveAttribute(
"aria-label",
/World screen, \d+ columns by \d+ rows/,
);
await expect(view.locator('[role="img"]')).toHaveAttribute("aria-label", /World screen, \d+ columns by \d+ rows/);
await expect(view).not.toContainText("Waiting for a world view");
// The roc-screen fixture renders its counter through Screen cells.
await expect(view).toContainText(/count=\d+/);
Expand Down
22 changes: 14 additions & 8 deletions pkgs/id/scripts/just-recipes-check-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ script="$(cd "$(dirname "$0")" && pwd)/just-recipes-check.sh"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
mkdir "$tmp/bin" "$tmp/work"
printf '#!%s\n' "$(command -v bash)" > "$tmp/bin/just"
cat >> "$tmp/bin/just" <<'EOF'
printf '#!%s\n' "$(command -v bash)" >"$tmp/bin/just"
cat >>"$tmp/bin/just" <<'EOF'
cat "$FRESH"
EOF
chmod +x "$tmp/bin/just"
export PATH="$tmp/bin:$PATH" FRESH="$tmp/fresh.json"
cd "$tmp/work"
cat > just-recipes.json <<'EOF'
cat >just-recipes.json <<'EOF'
{"source":"old", "recipes":{"run":{"doc":"run", "private":false, "parameters":[{"name":"arg", "kind":"singular", "default":null, "export":false, "flag":false}], "dependencies":[{"recipe":"dep", "arguments":[["string", "a"]], "star":null}], "body":[["old"]]}}, "aliases":{"r":{"target":"run"}}}
EOF
cp just-recipes.json "$FRESH"
check_pass() { if ! bash "$script" > "$tmp/output" 2>&1; then cat "$tmp/output"; exit 1; fi; }
check_fail() { if bash "$script" > "$tmp/output" 2>&1; then echo "unexpected success: $1" >&2; exit 1; fi; }
change() { jq "$1" just-recipes.json > "$FRESH"; }
check_pass() { if ! bash "$script" >"$tmp/output" 2>&1; then
cat "$tmp/output"
exit 1
fi; }
check_fail() { if bash "$script" >"$tmp/output" 2>&1; then
echo "unexpected success: $1" >&2
exit 1
fi; }
change() { jq "$1" just-recipes.json >"$FRESH"; }

check_pass
change '.source = "new" | .recipes.run.body = [["new"]]'
Expand All @@ -33,9 +39,9 @@ change '.recipes.run.dependencies[0].star = true'
check_fail 'dependency star'
change '.aliases.r.target = "dep"'
check_fail 'alias target'
printf '{' > "$FRESH"
printf '{' >"$FRESH"
check_fail 'invalid fresh JSON'
cp just-recipes.json "$FRESH"
printf '{' > just-recipes.json
printf '{' >just-recipes.json
check_fail 'invalid committed JSON'
echo 'just-recipes-check tests passed'
12 changes: 6 additions & 6 deletions pkgs/id/scripts/just-recipes-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
just --dump --dump-format json > "$tmp/fresh.json"
just --dump --dump-format json >"$tmp/fresh.json"
# Compare semantic fields only: recipe presence, doc, parameters,
# dependencies and the private flag, plus alias targets. The top-level
# `source` is an absolute path from the generating machine and recipe
# bodies serialise differently between just versions (the `bench`
# nesting, #2729), so both are projected out — a byte diff would
# false-positive forever.
project() {
jq -S '{recipes: (.recipes | to_entries | map({key, value: {doc: .value.doc, parameters: .value.parameters, dependencies: .value.dependencies, private: (.value.private // false)}}) | from_entries), aliases: ((.aliases // {}) | to_entries | map({key, value: .value.target}) | from_entries)}' "$1"
jq -S '{recipes: (.recipes | to_entries | map({key, value: {doc: .value.doc, parameters: .value.parameters, dependencies: .value.dependencies, private: (.value.private // false)}}) | from_entries), aliases: ((.aliases // {}) | to_entries | map({key, value: .value.target}) | from_entries)}' "$1"
}
# Project separately: failures inside process substitutions are otherwise hidden
# by diff's exit status and can incorrectly report a match.
project just-recipes.json > "$tmp/committed.json"
project "$tmp/fresh.json" > "$tmp/projected.json"
project just-recipes.json >"$tmp/committed.json"
project "$tmp/fresh.json" >"$tmp/projected.json"
if ! diff "$tmp/committed.json" "$tmp/projected.json"; then
echo "error: just-recipes.json has drifted from the justfile — run 'just lockfiles' and commit the result" >&2
exit 1
echo "error: just-recipes.json has drifted from the justfile — run 'just lockfiles' and commit the result" >&2
exit 1
fi
echo "✓ just-recipes.json matches the justfile"
10 changes: 6 additions & 4 deletions pkgs/id/src/world_ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ use std::{
use futures_lite::StreamExt;
use russh::{
Channel, ChannelId, ChannelOpenFailure, MethodKind, MethodSet, Pty,
keys::{Algorithm, PrivateKey, PublicKey, ssh_key::HashAlg, ssh_key::LineEnding},
server::{Auth, ChannelOpenHandle, Config, Handle, Handler, Msg, Server, Session},
keys::{Algorithm, PrivateKey, ssh_key::HashAlg, ssh_key::LineEnding},
server::{
Auth, ChannelOpenHandle, Config, Handle, Handler, Msg, Server, Session, VerifiedPublicKey,
},
};
use serde_json::json;
use tokio::{
Expand Down Expand Up @@ -305,12 +307,12 @@ impl Handler for SshClient {
async fn auth_publickey(
&mut self,
user: &str,
public_key: &PublicKey,
public_key: VerifiedPublicKey<'_>,
) -> Result<Auth, russh::Error> {
let Some(world) = user.strip_prefix(EXPLORE_PREFIX) else {
return Ok(Auth::reject());
};
let Some(ed25519) = public_key.key_data().ed25519() else {
let Some(ed25519) = public_key.public_key.key_data().ed25519() else {
return Ok(Auth::reject());
};
if self.permit.is_none() {
Expand Down
66 changes: 21 additions & 45 deletions pkgs/id/web/src/collab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ class FakeWebSocket {

deliver(msg: unknown): void {
const packed = packr.pack(msg);
const buf = packed.buffer.slice(
packed.byteOffset,
packed.byteOffset + packed.byteLength,
) as ArrayBuffer;
const buf = packed.buffer.slice(packed.byteOffset, packed.byteOffset + packed.byteLength) as ArrayBuffer;
this.onmessage?.({ data: buf });
}

Expand Down Expand Up @@ -84,16 +81,18 @@ function track<T extends { disconnect: () => void }>(conn: T): T {
}

function openCollab(onEditorReady = vi.fn()) {
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
null,
undefined,
undefined,
onEditorReady,
));
const conn = track(
initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
null,
undefined,
undefined,
onEditorReady,
),
);
const socket = FakeWebSocket.instances.at(-1)!;
socket.open();
return { conn, socket, onEditorReady };
Expand All @@ -119,14 +118,9 @@ describe("initCollab protocol handling (#1463, #2824)", () => {

it("reconnect AUTH sends the AUTH_OK refreshed token, not the init token", () => {
const onTokenRefresh = vi.fn();
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
"OLD_TOKEN_A",
onTokenRefresh,
));
const conn = track(
initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", "OLD_TOKEN_A", onTokenRefresh),
);

const first = FakeWebSocket.instances[0];
first.open();
Expand All @@ -149,14 +143,9 @@ describe("initCollab protocol handling (#1463, #2824)", () => {
});

it("reconnect without any refresh re-sends the init token", () => {
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
"ONLY_TOKEN",
undefined,
));
const conn = track(
initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", "ONLY_TOKEN", undefined),
);

const first = FakeWebSocket.instances[0];
first.open();
Expand All @@ -172,14 +161,7 @@ describe("initCollab protocol handling (#1463, #2824)", () => {
});

it("anonymous connect sends no AUTH frame, before or after reconnect", () => {
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
null,
undefined,
));
const conn = track(initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", null, undefined));

const first = FakeWebSocket.instances[0];
first.open();
Expand Down Expand Up @@ -313,13 +295,7 @@ describe("buildCollabWsUrl (#2830)", () => {
FakeWebSocket.instances = [];
vi.stubGlobal("WebSocket", FakeWebSocket);
const conn = track(
initCollab(
buildCollabWsUrl("ws:", "example.test", "a#b.md"),
makeContainer(),
"a#b.md",
"a#b.md",
null,
),
initCollab(buildCollabWsUrl("ws:", "example.test", "a#b.md"), makeContainer(), "a#b.md", "a#b.md", null),
);
const socket = FakeWebSocket.instances.at(-1)!;
const url = new URL(socket.url);
Expand Down
13 changes: 2 additions & 11 deletions pkgs/id/web/src/collab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,7 @@ export function initCollab(
);
return;
}
console.log(
"[collab] Sending",
batch.length,
"of",
sendable.steps.length,
"steps, version:",
sendable.version,
);
console.log("[collab] Sending", batch.length, "of", sendable.steps.length, "steps, version:", sendable.version);
send(MSG.STEPS, sendable.version, batch, sendable.clientID);
}
};
Expand Down Expand Up @@ -326,9 +319,7 @@ export function initCollab(
const version = msg[1];
const doc = msg[2];
const docRecord =
doc !== null && typeof doc === "object" && !Array.isArray(doc)
? (doc as Record<string, unknown>)
: null;
doc !== null && typeof doc === "object" && !Array.isArray(doc) ? (doc as Record<string, unknown>) : null;
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0) {
console.error("[collab] Dropping malformed Init message: invalid version");
return;
Expand Down
6 changes: 4 additions & 2 deletions pkgs/id/web/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ export const richSchema = new Schema({
// reflection admits fractional/negative/hex starts the u64
// markdown codec cannot represent).
const el = dom as HTMLOListElement;
if (el.classList.contains("contains-task-list")) return { order: parseOrderedListStart(el.getAttribute("start")) };
if (el.classList.contains("contains-task-list"))
return { order: parseOrderedListStart(el.getAttribute("start")) };
const firstLi = el.querySelector("li");
if (firstLi?.querySelector('input[type="checkbox"]')) return { order: parseOrderedListStart(el.getAttribute("start")) };
if (firstLi?.querySelector('input[type="checkbox"]'))
return { order: parseOrderedListStart(el.getAttribute("start")) };
return false;
},
},
Expand Down
Loading