Files
marqdo-view/tests/cli_surface.rs
T
marqdo-view dev 8ba20a5c67 feat(PR-01): single Rust package, Tool Protocol v1 bundle and PublicCoreClient
- src/lib.rs module layout + thin main.rs dispatcher; CLI owns browse/export/verify
- core_client: MARQDO_BIN only, explicit argv (no shell), 0700 scratch dirs,
  wall-clock timeout killing the whole process group, version/protocol negotiation
- project/source_map: canonical path boundary, SafeRelativePath, exact UTF-8
  byte <-> line/column <-> UTF-16 mapping, SHA-256 of exact bytes
- stable view.* error codes with 0/1/2 exit classes; BindDenied for non-loopback
- verify use case: Analysis v2 schema/profile/root_id/source_digest binding, no execution
- tool.json + tools/package.sh + tools/install-smoke.sh; frozen-CLI install smoke PASS
- contract tests with a real fake-core executable + architectural coupling gates
- COMPATIBILITY/CHANGELOG/STATUS updated
2026-11-22 10:33:14 +08:00

90 lines
3.2 KiB
Rust

//! CLI surface tests: this program owns its own help/subcommands and refuses
//! unsafe defaults. Exit codes follow RFC-VIEW-0001 §10.2.
mod common;
use common::run_view;
fn clean_env() -> Vec<(&'static str, Option<&'static str>)> {
vec![
("MARQDO_BIN", None),
("MARQDO_TOOL_PROTOCOL", None),
("MARQDO_PROTOCOL_ANALYSIS", None),
("MARQDO_PROTOCOL_TRACE", None),
]
}
#[test]
fn help_comes_from_view_not_core() {
let cwd = std::env::current_dir().unwrap();
let output = run_view(&["--help"], &cwd, &clean_env());
assert_eq!(output.status.code(), Some(0));
let stdout = String::from_utf8_lossy(&output.stdout);
for needle in ["marqdo-view", "export", "verify", "PATH", "--marqdo-bin"] {
assert!(
stdout.contains(needle),
"missing {needle} in help:\n{stdout}"
);
}
// The Core's own help wording must not leak here.
assert!(!stdout.contains("Statically check a document"));
}
#[test]
fn version_is_the_tool_version() {
let cwd = std::env::current_dir().unwrap();
let output = run_view(&["--version"], &cwd, &clean_env());
assert_eq!(output.status.code(), Some(0));
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("marqdo-view 0.1.0"), "{stdout}");
}
#[test]
fn export_requires_an_output_directory() {
let cwd = std::env::current_dir().unwrap();
let output = run_view(&["export", "example.mq.md"], &cwd, &clean_env());
assert_eq!(output.status.code(), Some(2));
}
#[test]
fn non_loopback_bind_is_refused_by_default() {
let cwd = std::env::current_dir().unwrap();
let output = run_view(&["--host", "0.0.0.0"], &cwd, &clean_env());
assert_eq!(output.status.code(), Some(2));
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("view.bind_denied"), "{stderr}");
assert!(stderr.contains("--unsafe-expose"), "{stderr}");
}
#[test]
fn browse_without_core_reports_core_missing() {
// Browse is not implemented yet, but the reader must still fail with a
// stable View code and exit class rather than pretending to work.
let cwd = std::env::current_dir().unwrap();
let output = run_view(&[], &cwd, &clean_env());
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(output.status.code(), Some(2), "stderr: {stderr}");
assert!(
stderr.contains("view.unsupported") || stderr.contains("view.core_missing"),
"unexpected diagnostic: {stderr}"
);
}
#[test]
fn verify_without_core_is_an_argument_error() {
let project = common::TempProject::new("cli-verify-no-core");
project.marqdo_project("# @knowledge fixture\n");
let output = run_view(&["verify", "index.mq.md"], &project.dir, &clean_env());
assert_eq!(output.status.code(), Some(2));
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("view.core_missing"), "{stderr}");
}
#[test]
fn missing_document_is_an_io_error() {
let project = common::TempProject::new("cli-missing-doc");
let output = run_view(&["verify", "missing.mq.md"], &project.dir, &clean_env());
assert_eq!(output.status.code(), Some(1));
assert!(String::from_utf8_lossy(&output.stderr).contains("view.io"));
}