- 1
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - 2
- 3
//! The desktop client strips inline runtime hints and context blocks from text - 4
//! it renders. It cannot import the Rust vocabulary, so this fails the build - 5
//! if its two lists differ from `vak_intent::control` — the drift that, with - 6
//! a marker added on one side only, once displaced every later chat turn. - 7
//! Exact set equality, not "contains": a stale extra entry is drift too. - 8
- 9
use std::collections::BTreeSet; - 10
use std::path::PathBuf; - 11
- 12
fn client_source(file: &str) -> String { - 13
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - 14
.join("../vak-client-ui/src") - 15
.join(file); - 16
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())) - 17
} - 18
- 19
/// The string literals of `export const NAME = [ ... ]` in the client source. - 20
fn ts_string_list(source: &str, name: &str) -> BTreeSet<String> { - 21
let start = source - 22
.find(&format!("export const {name} = [")) - 23
.unwrap_or_else(|| panic!("structured.ts must declare `export const {name} = [...]`")); - 24
let body = &source[start..]; - 25
let open = body.find('[').unwrap() + 1; - 26
// Not the first `]`: the marker literals themselves contain brackets. - 27
let close = body[open..].find("] as const").unwrap() + open; - 28
body[open..close] - 29
.split(',') - 30
.filter_map(|item| { - 31
let item = item.trim(); - 32
item.strip_prefix('"') - 33
.and_then(|rest| rest.strip_suffix('"')) - 34
.map(str::to_string) - 35
}) - 36
.collect() - 37
} - 38
- 39
#[test] - 40
fn the_clients_inline_hint_list_is_exactly_the_runtimes() { - 41
let client = ts_string_list(&client_source("structured.ts"), "INLINE_HINT_MARKERS"); - 42
let runtime: BTreeSet<String> = vak_intent::control::inline_markers() - 43
.into_iter() - 44
.map(str::to_string) - 45
.collect(); - 46
assert_eq!( - 47
client, runtime, - 48
"structured.ts INLINE_HINT_MARKERS differs from vak_intent::control::inline_markers()" - 49
); - 50
} - 51
- 52
#[test] - 53
fn the_clients_context_block_tags_are_exactly_the_runtimes() { - 54
let client = ts_string_list(&client_source("structured.ts"), "CONTEXT_BLOCK_TAGS"); - 55
let runtime: BTreeSet<String> = vak_intent::control::CONTEXT_BLOCK_TAGS - 56
.into_iter() - 57
.map(str::to_string) - 58
.collect(); - 59
assert_eq!( - 60
client, runtime, - 61
"structured.ts CONTEXT_BLOCK_TAGS differs from vak_intent::control::CONTEXT_BLOCK_TAGS" - 62
); - 63
} - 64
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.