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
7 changes: 5 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ permissions:
on:
pull_request:
branches: ["main"]
types: [opened, synchronize, reopened, ready_for_review]
# Converting to a draft or closing cancels the in-flight run through the concurrency group.
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft, closed]

# Cancel a superseded run so a newer push to the PR frees its runner.
concurrency:
Expand All @@ -16,8 +17,10 @@ concurrency:
jobs:
check:
name: Check
if: ${{ !github.event.pull_request.draft }}
if: ${{ github.event.action != 'closed' && !github.event.pull_request.draft }}
runs-on: ubuntu-latest
# Backstop a hang instead of holding the runner for the 6-hour default.
timeout-minutes: 30

steps:
- name: Checkout
Expand Down
18 changes: 18 additions & 0 deletions REVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Repository-specific review rules for Hang (extends Quest's shared review rules, read from the base branch).

# Checks

- **Approach first**: judge whether the change belongs here and takes the simplest route before reading its lines. Generic media, protocol, auth, and room logic belongs upstream in `moq-dev/moq`; flag a local copy of what a `@moq/*` package provides, or a workaround for its bug, and recommend the upstream fix.
- **Boundaries**: the app reaches the API through `@hang/api` types and the browser-safe `@hang/api/client`; it never imports Worker internals, and Worker code never imports browser modules.
- **Mixed versions**: `just deploy` ships the API before the app, and open tabs keep the old app. A request or response shape, stored setting, or D1 migration must work with the previous app build.
- **Grants**: a relay token lets a participant publish only under its own identity and subscribe only within its room. Flag any grant that widens either.

# Tests

Flag unit tests that wait on the real clock; room logic reads time through `@moq/clock`, so install `Manual` from `@moq/clock/test`. Only `app/test/media.browser.ts`, which drives a real browser, codecs, and relay, may use real time; flag a wait there that media from an earlier capture or stage could satisfy.

# Not findings

- Missing tests for SolidJS markup, CSS, or WebGL shaders, which are checked on the running app.
- Behavior a `@moq/*` package owns; report it upstream instead.
- A shim for an API shape no deployed app build uses.
7 changes: 7 additions & 0 deletions api/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The Hono API on Cloudflare Workers (`@hang/api`): accounts, OAuth, avatars in R2, favorites in D1, and relay tokens.

- Each module (`account.ts`, `oauth.ts`, `room.ts`, ...) owns its routes and its `Context`; `context.ts` builds them per request. Drizzle tables live beside their routes, except the account tables in `tables.ts`, which reference each other.
- `client.ts` is the browser-safe entry the app imports at runtime; keep Worker-only imports out of it.
- A schema change is a new SQL file under `migrations/`, applied by `just api dev` and `just api deploy`. Keep it additive: the previous app build keeps calling the API during a deploy.
- Room tokens are signed with `@moq/auth`. `RELAY_PREFIX` scopes every token; a participant publishes only under its own identity.
- Test with `bun run --cwd api test`; `test/harness.ts` runs routes against in-memory SQLite and R2 fakes.
4 changes: 1 addition & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
},
"devDependencies": {
"@types/uuid": "^11.0.0",
"typescript": "^6.0.0",
"@biomejs/biome": "^2.4.3",
"madge": "^8.0.0",
"typescript": "7.0.2",
"@types/bun": "^1.4.4"
},
"packageManager": "bun@1.4.2"
Expand Down
26 changes: 9 additions & 17 deletions api/src/account.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { and, eq } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { bodyLimit } from "hono/body-limit";
import { HTTPException } from "hono/http-exception";
import * as Uuid from "uuid";
import { z } from "zod";
import * as Auth from "./auth";
import * as Avatar from "./avatar";
import { AccountId, accountIdSchema, nameSchema } from "./client";
import * as Database from "./database";
import * as OAuth from "./oauth";
import { type AccountId, accountIdSchema, nameSchema } from "./client";
import type * as Database from "./database";
import type * as OAuth from "./oauth";
import * as rpc from "./rpc";
import * as Storage from "./storage";
import type * as Storage from "./storage";
import * as Tables from "./tables";

export type Id = AccountId;
export const idSchema = accountIdSchema;
Expand All @@ -31,15 +31,7 @@ export interface Create {
avatar?: Avatar.Upload;
}

export const table = sqliteTable("accounts", {
id: text("id").primaryKey(),
email: text("email").notNull().unique(),
name: text("name").notNull(),
avatar: text("avatar").notNull(),
avatarType: text("avatar_type").notNull(),
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
});
const table = Tables.accounts;

export type Row = typeof table.$inferSelect;
export type NewRow = typeof table.$inferInsert;
Expand Down Expand Up @@ -107,8 +99,8 @@ export class Context {
const result = await this.db
.select()
.from(table)
.innerJoin(OAuth.table, eq(table.id, OAuth.table.accountId))
.where(and(eq(OAuth.table.providerId, provider), eq(OAuth.table.providerUser, providerUser)))
.innerJoin(Tables.linked, eq(table.id, Tables.linked.accountId))
.where(and(eq(Tables.linked.providerId, provider), eq(Tables.linked.providerUser, providerUser)))
.limit(1);

return this.#rowToInfo(result.at(0)?.accounts);
Expand Down Expand Up @@ -264,7 +256,7 @@ export class Context {
}

// Delete OAuth entries
await this.db.delete(OAuth.table).where(eq(OAuth.table.accountId, id));
await this.db.delete(Tables.linked).where(eq(Tables.linked.accountId, id));

// Delete account
await this.db.delete(table).where(eq(table.id, id));
Expand Down
4 changes: 2 additions & 2 deletions api/src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createMiddleware } from "hono/factory";
import * as JWT from "jose";
import { z } from "zod";
import { Account } from ".";
import type { Account } from ".";
import { accountIdSchema, oauthChallenge } from "./client";
import RootContext from "./context";
import type RootContext from "./context";

// Use ZOD to validate the payload
const tokenSchema = z.object({
Expand Down
12 changes: 12 additions & 0 deletions api/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createMiddleware } from "hono/factory";
import * as Account from "./account";
import * as Auth from "./auth";
import * as Database from "./database";
Expand All @@ -24,3 +25,14 @@ export default class Context {
this.room = new Room.Context(env);
}
}

// Wraps env in a context object for each request.
export const withContext = createMiddleware<{
Bindings: Env;
Variables: {
ctx: Context;
};
}>(async (c, next) => {
c.set("ctx", new Context(c.env));
return await next();
});
7 changes: 5 additions & 2 deletions api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Hono } from "hono";
import * as Account from "./account";
import * as Avatar from "./avatar";
import { withContext } from "./context";
import * as Fave from "./fave";
import * as Health from "./health";
import * as OAuth from "./oauth";
Expand All @@ -9,8 +11,9 @@ import * as Storage from "./storage";

export { Account, Avatar, Fave, Health, OAuth, Room };

const app = rpc
.app()
const app = new Hono<{ Bindings: Env }>()
.use(withContext)
.use(rpc.withCors)
.route("/auth", OAuth.router)
.route("/account", Account.router)
.route("/fave", Fave.router)
Expand Down
29 changes: 8 additions & 21 deletions api/src/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { and, eq } from "drizzle-orm";
import { integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { HTTPException } from "hono/http-exception";
import * as jose from "jose";
import { z } from "zod";
import * as Account from "./account";
import type * as Account from "./account";
import * as Avatar from "./avatar";
import { OauthState, oauthStateSchema, oauthTokenSchema, oauthProviders as providers } from "./client";
import * as Database from "./database";
import { type OauthState, oauthStateSchema, oauthTokenSchema, oauthProviders as providers } from "./client";
import type * as Database from "./database";
import * as rpc from "./rpc";
import * as Tables from "./tables";
import { unreachable } from "./util";

export type ProviderId = (typeof providers)[number];
Expand Down Expand Up @@ -306,9 +306,9 @@ export class Provider {
// The link vouches for the account only when the provider verified the account's own address.
const owner = (
await this.db
.select({ email: Account.table.email })
.from(Account.table)
.where(eq(Account.table.id, account))
.select({ email: Tables.accounts.email })
.from(Tables.accounts)
.where(eq(Tables.accounts.id, account))
.limit(1)
).at(0);
const emailVerified = user.emailVerified && user.email !== undefined && user.email === owner?.email;
Expand Down Expand Up @@ -458,20 +458,7 @@ export interface User {
avatar?: string;
}

export const table = sqliteTable(
"accounts_linked",
{
accountId: text("account_id")
.notNull()
.references(() => Account.table.id, { onDelete: "cascade" }),
providerId: text("provider_id").notNull(),
providerUser: text("provider_user").notNull(),
emailVerified: integer("email_verified", { mode: "boolean" }).notNull().default(false),
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
},
(table) => [primaryKey({ columns: [table.accountId, table.providerId] })],
);
const table = Tables.linked;

export type Row = typeof table.$inferSelect;
export type NewRow = typeof table.$inferInsert;
Expand Down
24 changes: 2 additions & 22 deletions api/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { createMiddleware } from "hono/factory";
import { z } from "zod";
import Context from "./context";

export function app() {
return new Hono<{
Bindings: Env;
}>()
.use(withContext)
.use(withCors);
}
import type { z } from "zod";
import type Context from "./context";

export function router() {
return new Hono<{
Expand All @@ -24,18 +16,6 @@ export function router() {
}>();
}

// Instead of exposing env directly, we wrap it in a context object for easier access
export const withContext = createMiddleware<{
Bindings: Env;
Variables: {
ctx: Context;
};
}>(async (c, next) => {
const ctx = new Context(c.env);
c.set("ctx", ctx);
return await next();
});

export const withCors = createMiddleware<{
Bindings: Env;
}>(async (c, next) => {
Expand Down
28 changes: 28 additions & 0 deletions api/src/tables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// The account tables, apart from the routes, since each references the other.

import { integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";

export const accounts = sqliteTable("accounts", {
id: text("id").primaryKey(),
email: text("email").notNull().unique(),
name: text("name").notNull(),
avatar: text("avatar").notNull(),
avatarType: text("avatar_type").notNull(),
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
});

export const linked = sqliteTable(
"accounts_linked",
{
accountId: text("account_id")
.notNull()
.references(() => accounts.id, { onDelete: "cascade" }),
providerId: text("provider_id").notNull(),
providerUser: text("provider_user").notNull(),
emailVerified: integer("email_verified", { mode: "boolean" }).notNull().default(false),
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
},
(table) => [primaryKey({ columns: [table.accountId, table.providerId] })],
);
6 changes: 6 additions & 0 deletions app/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The SolidJS frontend (`@hang/live`), built with Vite and served from Cloudflare Workers.

- `src/room/` is the spatial room: `@moq/room` publishing and watching, WebGL rendering under `gl/`, physics, chat, and TTS. Its logic reads time through `@moq/clock` (Biome enforces it), so tests drive it with `Manual` from `@moq/clock/test`.
- Reactive room state uses `@moq/signals`; read `moq/js/AGENTS.md` before touching it. SolidJS components bridge signals through `src/util/solid.ts`.
- Make API requests through `src/api.ts`. At runtime the app imports only the browser-safe `@hang/api/client` (schemas and helpers, usable directly); `@hang/api` itself is types only.
- `bun run --cwd app test` runs unit tests under happy-dom; `bun run --cwd app test:media` drives Chromium with fake devices against a local relay to check capture, encoding, and decoding end to end.
4 changes: 1 addition & 3 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"devDependencies": {
"@babel/core": "7.29.7",
"@babel/preset-typescript": "^7.29.0",
"@biomejs/biome": "^2.4.3",
"@happy-dom/global-registrator": "21.0.4",
"@iconify-json/material-symbols": "^1.2.33",
"@iconify-json/mdi": "^1.2.3",
Expand All @@ -55,12 +54,11 @@
"babel-preset-solid": "1.9.15",
"globals": "^17.4.0",
"jsdom": "^31.0.1",
"madge": "^8.0.0",
"playwright": "1.64.1",
"rolldown": "^1.2.15",
"ts-expect": "^1.3.0",
"tsx": "^4.20.5",
"typescript": "^6.0.0",
"typescript": "7.0.2",
"vite": "^8.0.3",
"vite-plugin-glsl": "^1.5.4",
"vite-plugin-solid": "^2.11.8",
Expand Down
5 changes: 3 additions & 2 deletions app/src/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function AccountLoad(): JSX.Element {
}
};

onMount(async () => {
const loadInfo = async () => {
try {
const info = await Api.client.routes.account.info.$get();
if (info.ok) {
Expand All @@ -60,7 +60,8 @@ function AccountLoad(): JSX.Element {
} catch (e) {
setError(`Failed to load account info: ${e}`);
}
});
};
onMount(() => void loadInfo());

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Client {
Settings.oauth.token.set(token);
}

async logout(): Promise<void> {
logout(): void {
Settings.logout();
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/another-one.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Accessor, createEffect, createSignal, onCleanup, Show } from "solid-js";
import { type Accessor, createEffect, createSignal, onCleanup, Show } from "solid-js";

export default function AnotherOne(props: { clicks: Accessor<number> }) {
// Duration breakpoints for the meme video (in seconds)
Expand Down
5 changes: 2 additions & 3 deletions app/src/components/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as Clock from "@moq/clock";
import { Effect } from "@moq/signals";
import { createSignal, JSX, onCleanup, Show } from "solid-js";
import { createSignal, type JSX, onCleanup, Show } from "solid-js";
import * as Api from "../api";
import { Camera, Microphone } from "../controls";
import { Canvas } from "../room/canvas";
import type { HangLocalSource } from "../room/local";
import { Local } from "../room/local";
import type { HangLocalSource, Local } from "../room/local";
import { Sound } from "../room/sound";
import { Space } from "../room/space";
import Settings from "../settings";
Expand Down
5 changes: 2 additions & 3 deletions app/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import Tooltip from "./components/tooltip";
import { Tutorial } from "./components/tutorial";
import type { Room } from "./room";
import type { Canvas } from "./room/canvas";
import type { HangLocalSource } from "./room/local";
import { Local } from "./room/local";
import { Sound } from "./room/sound";
import type { HangLocalSource, Local } from "./room/local";
import type { Sound } from "./room/sound";
import Settings, { Modal } from "./settings";
import * as Speaker from "./speaker";
import { isMobile } from "./util/mobile";
Expand Down
9 changes: 3 additions & 6 deletions app/src/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,9 @@ function IconCanvas(props: { variant: IconVariant }) {
return URL.createObjectURL(blob);
};

onMount(async () => {
const svgDataUrl = renderIconToSvg();
setSvgDataUrl(svgDataUrl);

const pngDataUrl = await renderIconToPng();
setIconDataUrl(pngDataUrl);
onMount(() => {
setSvgDataUrl(renderIconToSvg());
void renderIconToPng().then(setIconDataUrl);
});

const downloadPNG = async (size?: number) => {
Expand Down
Loading