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: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ wasm/ comline-playground-wasm — the editor's Rust crate, wasm-bindgen surf
encode_describe / check_description — the Describe call first,
checked as the CLI checks it (protocol,
IR format, language and version)
describe_project(files) -> the schema shape the sim runs on
describe_project(files) -> the schema shape the sim runs on,
with wire numbers and the comline@2 Hello
The package takes core's defaults (datagram@3, comline@2) and
has the fixed id 706c617967726f756e64000000000000; its facts are
a first version's (comline_core::compat::facts_of_context), so
wire numbers and lines are provisional.
semantic_tokens / hover / completions — the LSP handlers verbatim
deps: comline-core, comline-codegen, comline-codegen-rust,
comline-codegen-typescript, comline-language-server (git rev)
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@codemirror/view": "^6.34.0",
"@lezer/highlight": "^1.2.3",
"comline-examples": "git+https://github.com/ComlineProject/examples.git#f63894988ea2cc5db98ff97cc0fbdfceb5af6bb7",
"comline-simulator": "git+https://github.com/ComlineProject/simulator.git#1eab1f84f1ae7760135ca4a7a519c78091001a44"
"comline-simulator": "git+https://github.com/ComlineProject/simulator.git#564851a8fa00709cd94db8ce8ab1c4325a691fc4"
},
"devDependencies": {
"@types/node": "^20.19.43",
Expand Down
26 changes: 24 additions & 2 deletions app/src/sim/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

export interface ProjectShape {
schemas: SchemaShape[];
/** The package's connection, when its protocols run on one. */
connection?: ConnectionShape;
}

/** The package connection: what every protocol on it shares. */
export interface ConnectionShape {
/** Canonical: `datagram@3` (core's default), `datagram@2`, ... */
framing: string;
/** Canonical: `comline@2` (core's default), `comline@1` or `none`. */
handshake: string;
/** `comline@2`'s four parameters, each as written or its default. */
params?: Record<string, string>;
/**
* Under `comline@2`: the encoded `Hello` each end sends, hex. A playground
* package has no history, so its numbers and lines are a first version's:
* provisional, as a first build's are until `comline release`.
*/
hello?: string;
}

export interface SchemaShape {
Expand All @@ -19,14 +37,18 @@ export interface SchemaShape {

export interface ProtocolShape {
name: string;
framing: "datagram" | "datagram@2" | "jsonrpc";
framing: "datagram" | "datagram@2" | "datagram@3" | "jsonrpc";
/** The number its frames carry on the connection (its wire number under `datagram@3`). */
number?: number;
functions: FnShape[];
}

export interface FnShape {
name: string;
/** 0-based position in the protocol — the `Call` id `resolveKind` matches. */
/** 0-based position in the protocol. */
index: number;
/** What its call carries on the wire: its wire number under `datagram@3`, else its position. */
call?: number;
/** No return at all — a fire-and-forget `notify`. */
oneway: boolean;
args: ArgShape[];
Expand Down
12 changes: 9 additions & 3 deletions app/src/sim/sim-wasm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ test("the sim wasm instantiates and round-trips a call", () => {
assert.equal(result.status, "ok");
assert.deepEqual(result.value, { body: "", seq: 0 }); // default seeded reply = zero value

// Core's defaults: `datagram@3` and `comline@2`, whose `offer` exchange is
// three messages (hello, answer, verdict).
const frames = JSON.parse(sim.frames(conn));
assert.equal(frames.length, 4, "two handshake frames, then request + response");
assert.equal(frames[2].kind, "request");
assert.equal(frames[3].kind, "response");
assert.equal(frames.length, 5, "three comline@2 handshake frames, then request + response");
assert.deepEqual(
frames.slice(0, 3).map((f: { kind: string }) => f.kind),
["handshake", "handshake", "handshake"],
);
assert.equal(frames[3].kind, "request");
assert.equal(frames[4].kind, "response");
});

test("a behaviour swap and a shareable link work through the facade", () => {
Expand Down
3 changes: 3 additions & 0 deletions app/src/sim/ui/framelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface FrameDetail {
/** Why it faulted, when the simulator knows. */
note?: string;
handshake?: { irHash: string; wireFormat: string; framing: string; caps: number };
/** A `comline@2` message, as the runtime decodes it. */
comline2?: { type: "hello" | "answer" | "verdict"; message: unknown };
}

export interface LogSource {
Expand Down Expand Up @@ -338,6 +340,7 @@ export function frameLog(): FrameLog {
kv("framing_name", detail.handshake.framing),
);
}
if (detail.comline2) body.append(json(`comline@2 ${detail.comline2.type}`, detail.comline2.message));
if (detail.requestId !== undefined) body.append(kv("request_id", detail.requestId));
if ("params" in detail) body.append(json("params", detail.params));
if ("ok" in detail) body.append(json("ok", detail.ok));
Expand Down
20 changes: 18 additions & 2 deletions app/src/sim/ui/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface ModelConn {
clientId: string;
serverId: string;
faults: Faults;
framing: "auto" | "datagram" | "datagram@2" | "jsonrpc";
framing: "auto" | "datagram" | "datagram@2" | "datagram@3" | "jsonrpc";
wireFormat: "packed" | "json" | "msgpack";
}
interface Model {
Expand Down Expand Up @@ -842,6 +842,7 @@ export function createSim(opts: SimOpts = {}): SimView {
["protocol", sel.protocol],
["role", sel.role],
["framing", found.protocol.framing],
...(shape?.connection ? [["handshake", handshakeLabel(shape.connection)] as [string, string]] : []),
]),
);
const hash = document.createElement("button");
Expand Down Expand Up @@ -1100,7 +1101,7 @@ export function createSim(opts: SimOpts = {}): SimView {
inspectorEl.append(section("transport"));
const framingSel = document.createElement("select");
framingSel.title = "auto follows the protocol's declared framing";
for (const v of ["auto", "datagram@2", "datagram", "jsonrpc"] as const) {
for (const v of ["auto", "datagram@3", "datagram@2", "datagram", "jsonrpc"] as const) {
framingSel.append(opt(v, v, v === conn.framing));
}
const wireSel = document.createElement("select");
Expand Down Expand Up @@ -1128,6 +1129,11 @@ export function createSim(opts: SimOpts = {}): SimView {
if (conn.framing === "auto") {
inspectorEl.append(muted(`auto → ${resolvedFraming} for this protocol`));
}
const handshake = shape?.connection;
if (handshake) {
inspectorEl.append(facts([["handshake", handshakeLabel(handshake)]]));
if (handshake.hello) inspectorEl.append(muted(PROVISIONAL));
}

inspectorEl.append(section("faults"));
inspectorEl.append(faultControls(conn));
Expand Down Expand Up @@ -1699,3 +1705,13 @@ function opt(value: string, text: string, selected = false): HTMLOptionElement {
if (selected) o.selected = true;
return o;
}

/** A playground package has no history: its wire numbers and lines are a first version's. */
const PROVISIONAL =
"wire numbers and lines are a first version's — provisional, as a first build's are until `comline release`";

/** `comline@2 (exchange = offer, ...)`, or the handshake's name alone. */
function handshakeLabel(c: { handshake: string; params?: Record<string, string> }): string {
const params = Object.entries(c.params ?? {});
return params.length ? `${c.handshake} (${params.map(([k, v]) => `${k} = ${v}`).join(", ")})` : c.handshake;
}
17 changes: 14 additions & 3 deletions app/src/sim/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ test("1d — place, connect, call, and see the reply and frames", async () => {
(reqRow as HTMLDetailsElement).open = true;
fire(reqRow, "toggle");
assert.match(reqRow.querySelector(".frame-body")!.textContent!, /"text": "hello"/);
assert.match(reqRow.querySelector(".frame-body")!.textContent!, /datagram@2/);
// Core's default framing, addressing the call by its wire number.
assert.match(reqRow.querySelector(".frame-body")!.textContent!, /datagram@3/);

sim.destroy();
});
Expand Down Expand Up @@ -844,13 +845,16 @@ test("2g — `compare` runs the call over every framing/codec combo", async () =
"datagram@2/json",
"datagram@2/msgpack",
"datagram@2/packed",
"datagram@3/json",
"datagram@3/msgpack",
"datagram@3/packed",
"jsonrpc/json",
],
"every combo Chat's framing supports",
);
assert.match(
blk.querySelector(".compare-note")!.textContent!,
/same reply on all 7 framing\/codec combinations/,
/same reply on all 10 framing\/codec combinations/,
"the decoded reply is identical across encodings",
);
assert.equal(blk.querySelectorAll(".compare-table tr.mismatch").length, 0);
Expand All @@ -872,7 +876,14 @@ test("2g — the connection inspector edits framing / wire format", async () =>
const wireSel = () => selects().find((s) => [...s.options].some((o) => o.value === "msgpack"))!;

assert.equal(framingSel().value, "auto", "starts on auto");
assert.match(sim.el.querySelector(".sim-inspector")!.textContent!, /auto → datagram@2/);
assert.match(sim.el.querySelector(".sim-inspector")!.textContent!, /auto → datagram@3/);
// Core's default handshake, with its parameters, and the numbers labelled
// provisional: a playground package has no history.
assert.match(
sim.el.querySelector(".sim-inspector")!.textContent!,
/comline@2 \(scope = protocol, newer_consumer = degrade, same_version_differs = refuse, exchange = offer\)/,
);
assert.match(sim.el.querySelector(".sim-inspector")!.textContent!, /provisional/);
assert.deepEqual(
[...wireSel().options].map((o) => o.value),
["packed", "json", "msgpack"],
Expand Down
8 changes: 4 additions & 4 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -787,18 +787,18 @@ __metadata:
"@lezer/highlight": "npm:^1.2.3"
"@types/node": "npm:^20.19.43"
comline-examples: "git+https://github.com/ComlineProject/examples.git#f63894988ea2cc5db98ff97cc0fbdfceb5af6bb7"
comline-simulator: "git+https://github.com/ComlineProject/simulator.git#1eab1f84f1ae7760135ca4a7a519c78091001a44"
comline-simulator: "git+https://github.com/ComlineProject/simulator.git#564851a8fa00709cd94db8ce8ab1c4325a691fc4"
linkedom: "npm:^0.18.13"
tsx: "npm:^4.23.13"
typescript: "npm:^5.6.0"
vite: "npm:^5.4.0"
languageName: unknown
linkType: soft

"comline-simulator@git+https://github.com/ComlineProject/simulator.git#1eab1f84f1ae7760135ca4a7a519c78091001a44":
"comline-simulator@git+https://github.com/ComlineProject/simulator.git#564851a8fa00709cd94db8ce8ab1c4325a691fc4":
version: 0.0.0
resolution: "comline-simulator@https://github.com/ComlineProject/simulator.git#commit=1eab1f84f1ae7760135ca4a7a519c78091001a44"
checksum: 10c0/1c06f13064ca40fbf183d154d6849c429b6f89b91664fe6ca5afdb304637069a6443a9a1f925662c6308ed80d7c3c6eb500616d9593c5cc5cf8227a393b2274c
resolution: "comline-simulator@https://github.com/ComlineProject/simulator.git#commit=564851a8fa00709cd94db8ce8ab1c4325a691fc4"
checksum: 10c0/0238c841ab44ef23e1224473c61631b0424ab9d470474921d43fdb7a5d9f4792c0902374964773298f28fcd91913c6447edb57a9643a5f2cee1052ffc0dbb396
languageName: node
linkType: hard

Expand Down
15 changes: 8 additions & 7 deletions wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ crate-type = ["cdylib", "rlib"]
# The same crates the CLI and the language server compose — by git rev, so the
# playground runs *that* code, not a re-implementation. Keep the `comline-core`
# rev identical across all of them (one `comline-core` in the tree).
comline-core = { git = "https://github.com/ComlineProject/core", rev = "8f5dc91f1c1c91e192585c3e4b80128621047499" }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "c303722c447ded28d50d7cf32b3164916fa76e5f" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "2d50fbff670d883c92c363793e888158bb15b7a0" }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "ea9b9e2c70bbd87d99cc028543f73c8ee7749e1c" }
comline-core = { git = "https://github.com/ComlineProject/core", rev = "1dc294ae97cc3649311e9f78c7eeac8c6f969c31" }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "83162eac46c3689a4d4a681e3e4dc1be8bdbd856" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "addca268903503f997a8f099e30261c2fff0c720" }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "40cab74beb727e293d1445cd3e9afa98e1ec380b" }
# The LSP's analysis layer (diagnostics / hover / completion / semantic tokens),
# without its `tower-lsp` server — builds for wasm32.
comline-language-server = { git = "https://github.com/ComlineProject/language-server", rev = "91189530cdcb72dacb96eff6e2a67c3f14da8282", default-features = false }
comline-language-server = { git = "https://github.com/ComlineProject/language-server", rev = "0764367be56f18a6715cf7c385259debdbd9b6d2", default-features = false }
lsp-types = "0.94"
rust-sitter = "0.4.5" # parse-error types

wasm-bindgen = "0.2"
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.6"
console_error_panic_hook = "0.1"

[dev-dependencies]
# `comline_core::compat::PackageFacts` into the generator protocol's mirror,
# as the CLI converts it.
serde_json = "1"


[profile.release]
opt-level = "s"
lto = true
Loading
Loading