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-public-site/tests/repo_pages.rs

//! ★ **GUN-GUEST (owner 2026-10-30): the site draws no repository page of its own.**
//! `/{ns}/{name}[/…]` is the console's address: every such path passes on to the console
//! (which hands everybody its own document, with the page's content pre-rendered into it),
//! for a visitor and a signed-in person alike. What the site builds is its files only:
//! robots.txt, the sitemap, llms.txt, llms-full.txt and each public repository's readme.md,
//! tree.txt and issues.md, and the console's landing at `/`.

mod common;
use common::*;

use http::{header, StatusCode};

fn repo(leaf: &str) -> String {
    format!("/{NS}/{PUBLIC}{leaf}")
}

#[tokio::test]
async fn every_repository_address_passes_on_to_the_console() {
    let (site, _) = site().await;
    let app = app(site);
    for leaf in ["", "/tree", "/tree/src", "/blob/README.md", "/blob/src/main.rs", "/commits", "/issues", "/issues/1", "/issues?q=boot"] {
        for cookie in [None, Some(SESSION)] {
            let a = get_as(&app, &repo(leaf), cookie, None, Some("c")).await;
            assert_eq!((a.status, a.body.as_str()), (StatusCode::SEE_OTHER, TODAY), "{leaf}: the site answered a console address");
        }
    }
}

#[tokio::test]
async fn the_site_builds_only_its_files_and_the_landing() {
    let (site, _) = site().await;
    let built = site.built();
    for (path, page) in &built.pages {
        let file = ["/robots.txt", "/sitemap.xml", "/llms.txt", "/llms-full.txt"].contains(&path.as_str())
            || ["/readme.md", "/tree.txt", "/issues.md"].iter().any(|leaf| path.ends_with(leaf));
        assert!(path == "/" || file, "{path} is a page of the site's own");
        if path != "/" {
            assert!(!page.content_type.starts_with("text/html"), "{path} is HTML");
        }
    }
}

#[tokio::test]
async fn the_sitemap_names_the_consoles_addresses_and_the_docs_at_any_depth() {
    let mut fake = Fake::new();
    fake.more_files = vec![("docs/v2/README.md".into(), "# Docs\n".into()), ("crates/a/src/lib.rs".into(), "fn a() {}\n".into())];
    let (site, _) = site_with(fake, config()).await;
    let map = get(&app(site), "/sitemap.xml").await;
    assert_eq!(map.status, StatusCode::OK);
    assert!(map.headers[header::CONTENT_TYPE].to_str().unwrap().starts_with("application/xml"));
    for want in [format!("<loc>https://gunnar.example/{NS}/{PUBLIC}</loc>"), format!("<loc>https://gunnar.example/{NS}/{PUBLIC}/blob/docs/v2/README.md</loc>"), format!("<loc>https://gunnar.example/{NS}/{PUBLIC}/issues</loc>")] {
        assert!(map.body.contains(&want), "{want}: {}", map.body);
    }
    assert!(!map.body.contains("lib.rs"), "only documentation is listed: {}", map.body);
    assert!(!map.body.contains("/repo/") && !map.body.contains(PRIVATE), "{}", map.body);
}

#[tokio::test]
async fn a_namespace_that_is_a_console_path_is_never_published() {
    let mut fake = Fake::new();
    fake.extra = vec![gunnar_public_site::RepoRef { namespace: "admin".into(), name: "storage".into(), description: String::new(), public: true }];
    let (site, _) = site_with(fake, config()).await;
    for (path, body) in every_page(&site) {
        assert!(!body.contains("/admin/storage") && !path.starts_with("/admin/"), "{path}");
    }
}