Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/gunnar-ui

crates/gunnar-ui-server/tests/console_signup_contract.rs

//! **The console's signup vendor against monetize's contract for it.**
//!
//! `auth::signup` names ONE vendor on every `Signup.*` call (`VENDOR`): none (monetize A32-15,
//! the payment core is no vendor's shape; the shared relay monetize-site-buy sends none either),
//! and never an instance (`stripe/gunnar-test2`): which site's account takes the money is
//! monetize's routing (`[estates.<e>] vendor`), and a console that named an instance would bill
//! through whichever site it was built for. monetize, for its part, must answer with the calling
//! site's own instance — on `Start`, on the welcome page's `Status` poll and on `Rename` (i54a
//! run30/31, 2026-10-12: test2's console sent `stripe`, the ONE box routed `stripe/gunnar-test2`,
//! and the signup page said "An account is not sold here right now.").
//!
//! Two halves, as `vendored_monetize_protos.rs`:
//!
//! * WEAK, never skips: the console's `VENDOR` names no vendor.
//! * STRONG, with a monetize checkout beside this one (or `MONETIZE_CHECKOUT`): it equals
//!   monetize's `CONSOLE_VENDOR` in `crates/monetize-server/tests/console_signup_contract.rs`,
//!   the file that replays this console's calls against the real server with per-site
//!   instances. Read as text so the check runs in the open build too (`auth::signup` is
//!   compiled only under `metered`).

use std::path::{Path, PathBuf};

/// The string literal of `const <name>: &str = "…";` in `src`.
fn const_str(src: &str, name: &str) -> Option<String> {
    src.lines().find_map(|l| {
        let l = l.trim_start();
        let rest = l.strip_prefix("pub ").unwrap_or(l).strip_prefix(&format!("const {name}: &str = \""))?;
        Some(rest.split('"').next()?.to_owned())
    })
}

fn console_vendor() -> String {
    let p = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/auth/signup.rs");
    let src = std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("{}: {e}", p.display()));
    const_str(&src, "VENDOR").unwrap_or_else(|| panic!("{} declares no `const VENDOR: &str`", p.display()))
}

/// Where monetize's half of the contract is, if a checkout is anywhere on this box.
fn monetize_contract() -> Option<PathBuf> {
    const REL: &str = "crates/monetize-server/tests/console_signup_contract.rs";
    if let Some(named) = std::env::var_os("MONETIZE_CHECKOUT") {
        let f = PathBuf::from(named).join(REL);
        assert!(f.is_file(), "MONETIZE_CHECKOUT does not hold {}: a named checkout that is not there is a failed comparison", f.display());
        return Some(f);
    }
    let sibling = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../monetize").join(REL);
    sibling.is_file().then_some(sibling)
}

#[test]
fn the_console_names_no_vendor_never_an_instance() {
    let v = console_vendor();
    assert!(v.is_empty(), "auth::signup VENDOR = {v:?}: a console names no vendor (A32-15); the site's instance is monetize's routing");
}

#[test]
fn the_console_vendor_is_monetizes_contract() {
    let Some(theirs) = monetize_contract() else {
        eprintln!("no monetize checkout beside this one and MONETIZE_CHECKOUT is unset: the strong half stepped aside (the weak half still ran)");
        return;
    };
    let src = std::fs::read_to_string(&theirs).unwrap_or_else(|e| panic!("{}: {e}", theirs.display()));
    let contract = const_str(&src, "CONSOLE_VENDOR").unwrap_or_else(|| panic!("{} declares no CONSOLE_VENDOR", theirs.display()));
    assert_eq!(console_vendor(), contract, "the console's VENDOR is not the one monetize's contract test replays ({})", theirs.display());
}