Replaces the transitional OpenAPI 3.0 + `x-mizan-*` extensions
substrate with the canonical Mizan IR as KDL, per docs/AFI_ARCHITECTURE.md:
"KDL is the contract; everything else (REST envelopes, OpenAPI
documents, framework idioms) is sediment around it."
End-to-end cutover. No transitional path left on main.
Forward direction:
cores/mizan-python/src/mizan_core/ir.py
build_ir() walks mizan_core.registry, introspects Pydantic
models directly (no JSON-Schema indirection), and emits the
Mizan IR document. The KDL grammar is locked in this file's
module docstring.
Backends emit KDL:
backends/mizan-fastapi/src/mizan_fastapi/ir.py
`python -m mizan_fastapi.ir <module>` — CLI entry point.
backends/mizan-django/.../management/commands/export_mizan_ir.py
`manage.py export_mizan_ir` — Django mgmt command.
Codegen consumes KDL:
protocol/mizan-codegen/Cargo.toml: + kdl = "6"
protocol/mizan-codegen/src/ir.rs: NamedType { Struct/List/Enum/Alias }
+ TypeShape { Primitive/Ref/List/Optional/Enum/Union } sum types,
replacing the JsonSchema sprawl. KDL parser walks the
`kdl::KdlDocument` tree into typed Rust structs.
protocol/mizan-codegen/src/fetch.rs: subprocess command switches
to the new IR-export entry points.
All emit modules (stage1 / react / python / rust / vue / svelte /
channels) port their type-walkers from JsonSchema to the new
sum types — case analysis collapses substantially.
Substrate-honesty wins beyond the moat closure:
- `int | bool` multi-arm unions land as `TypeShape::Union` (was
silently coerced to "string" before).
- `<CamelName>Output = list[T]` returns emit as named alias
types instead of struct-shaped wrappers, so consumer code
`.map()` works directly on the type.
- Pydantic field defaults flow through to `default` properties
in KDL, then back to non-optional shape in every target.
Deleted:
- backends/mizan-fastapi/src/mizan_fastapi/{cli,schema}.py
- backends/mizan-django/.../export_mizan_schema.py
- openapi-bearing half of mizan/export/__init__.py (edge
manifest generator preserved — separate concern).
- tests/afi/schema_normalizer.py
- tests/fixtures/{afi_schema.json, channels_schema.json}
- tests/fixtures/js_* baseline directories.
Verification:
- 20 mizan-codegen unit tests green (IR deserialization,
byte-equivalence parity across stage1/rust/python/react/vue/svelte
against fresh KDL-driven baselines, channels structural).
- tests/rust/run_wire_parity.py: 12/12 probes green driving
the binary end-to-end through KDL.
- Blazr studio-ui typechecks against the regenerated React client.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
81 lines
2.9 KiB
Rust
81 lines
2.9 KiB
Rust
//! Smoke test for the channels target against a synthetic fixture.
|
|
//! The JS channels.mjs runs types through `openapi-typescript` which the
|
|
//! Rust codegen replaces with direct interface emission; byte-equivalence
|
|
//! against the JS baseline is intentionally not the gate. Instead this
|
|
//! test checks structural properties of the emitted output.
|
|
|
|
use std::collections::BTreeMap;
|
|
use std::path::PathBuf;
|
|
|
|
use mizan_codegen::config::{Config, SourceConfig};
|
|
use mizan_codegen::emit::CodegenTarget;
|
|
use mizan_codegen::emit::channels::ChannelsTarget;
|
|
use mizan_codegen::fetch::parse_ir_from_str;
|
|
|
|
|
|
fn fixture_config() -> Config {
|
|
Config {
|
|
project_id: None,
|
|
output: PathBuf::from("/tmp"),
|
|
targets: vec!["channels".to_string()],
|
|
source: SourceConfig { fastapi: None, django: None },
|
|
rust_kernel: None,
|
|
rust_crate_name: None,
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
fn channels_target_emits_expected_files() {
|
|
let raw = std::fs::read_to_string(
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/channels_ir.kdl"),
|
|
).unwrap();
|
|
let ir = parse_ir_from_str(&raw).unwrap();
|
|
|
|
let files = ChannelsTarget.emit(&ir, &fixture_config());
|
|
assert_eq!(files.len(), 2, "channels target emits 2 files when channels present");
|
|
|
|
let by_path: BTreeMap<PathBuf, &str> =
|
|
files.iter().map(|f| (f.rel_path.clone(), f.content.as_str())).collect();
|
|
|
|
let ts = by_path.get(&PathBuf::from("channels.ts"))
|
|
.expect("channels.ts emitted");
|
|
for expected in [
|
|
"export interface ChatChannelParams",
|
|
"export interface ChatReactMessage",
|
|
"export interface ChatDjangoMessage",
|
|
"export interface NotificationsDjangoMessage",
|
|
"export const CHANNELS = {",
|
|
"chat: {",
|
|
"notifications: {",
|
|
"hasParams: true",
|
|
"hasParams: false",
|
|
] {
|
|
assert!(ts.contains(expected), "channels.ts must contain {expected:?}");
|
|
}
|
|
|
|
let hooks = by_path.get(&PathBuf::from("channels.hooks.tsx"))
|
|
.expect("channels.hooks.tsx emitted");
|
|
for expected in [
|
|
"import { useChannel, type ChannelSubscription } from 'mizan/channels'",
|
|
"export function useChatChannel(params: ChatChannelParams)",
|
|
"export function useNotificationsChannel()",
|
|
"ChannelSubscription<ChatChannelParams, ChatDjangoMessage, ChatReactMessage>",
|
|
"ChannelSubscription<Record<string, never>, NotificationsDjangoMessage, never>",
|
|
] {
|
|
assert!(hooks.contains(expected), "channels.hooks.tsx must contain {expected:?}");
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
fn channels_target_emits_nothing_when_empty() {
|
|
// AFI fixture has no channels — target should produce zero files.
|
|
let raw = std::fs::read_to_string(
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/afi_ir.kdl"),
|
|
).unwrap();
|
|
let ir = parse_ir_from_str(&raw).unwrap();
|
|
let files = ChannelsTarget.emit(&ir, &fixture_config());
|
|
assert!(files.is_empty(), "no channels → no files");
|
|
}
|