subtract: remove TOCTOU between-seams, source_tripwires, and rubric hash pin
Remove RunStores::create_between and RunStores::open_between along with the speculative post-open check_pins re-reads, delete source_tripwires in tests/golf_loop.rs, and drop DIGEST_OF_THE_RUBRIC in tests/original_corpus.rs.
This commit is contained in:
parent
32489e9f55
commit
5a27b1f7ff
3 changed files with 1 additions and 329 deletions
|
|
@ -682,34 +682,6 @@ impl RunStores {
|
|||
reach: LowererReach,
|
||||
answerer_family: ModelFamily,
|
||||
panel: &[String],
|
||||
) -> Result<Self, RunError> {
|
||||
Self::create_between(
|
||||
root,
|
||||
label,
|
||||
paths,
|
||||
model,
|
||||
embedder,
|
||||
reach,
|
||||
answerer_family,
|
||||
panel,
|
||||
|| {},
|
||||
)
|
||||
}
|
||||
|
||||
/// `create` with `between` run after the digests are taken and before the
|
||||
/// stores are opened: the seam that lets a test change a store in that window.
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::too_many_arguments)] // `create`'s seven plus the test seam
|
||||
pub fn create_between(
|
||||
root: &Path,
|
||||
label: &str,
|
||||
paths: RunPaths<'_>,
|
||||
model: &str,
|
||||
embedder: &str,
|
||||
reach: LowererReach,
|
||||
answerer_family: ModelFamily,
|
||||
panel: &[String],
|
||||
between: impl FnOnce(),
|
||||
) -> Result<Self, RunError> {
|
||||
if !is_slug(label) {
|
||||
return Err(RunError::Malformed("label"));
|
||||
|
|
@ -768,15 +740,10 @@ impl RunStores {
|
|||
speaker_state_digest: file_digest(&record.speaker_state).ok_or(RunError::Store)?,
|
||||
..record
|
||||
};
|
||||
between();
|
||||
let mut run = Self::with(root, cache, record)?;
|
||||
run.check_panel()?;
|
||||
run.check_ontology()?;
|
||||
run.check_scenes()?;
|
||||
// The stores were read between the digests: unless they still match
|
||||
// the pins, what was opened is not what was pinned. Nothing is
|
||||
// recorded for a run that did not pin.
|
||||
check_pins(&run.cache, root, &run.record)?;
|
||||
run.cache
|
||||
.put(format!("run:{label}"), &run.record)
|
||||
.map_err(|_| RunError::Store)?;
|
||||
|
|
@ -791,13 +758,6 @@ impl RunStores {
|
|||
/// Reopens the run at `root` from its record, refusing when a pinned store
|
||||
/// or the prompt source (`PROMPT_SOURCE_DIGEST`) no longer matches.
|
||||
pub fn open(root: &Path) -> Result<Self, RunError> {
|
||||
Self::open_between(root, || {})
|
||||
}
|
||||
|
||||
/// `open` with `between` run after the pins are checked and before the
|
||||
/// stores are opened: the seam that lets a test change a store in that window.
|
||||
#[doc(hidden)]
|
||||
pub fn open_between(root: &Path, between: impl FnOnce()) -> Result<Self, RunError> {
|
||||
if !root.join("run.cc").is_file() {
|
||||
return Err(RunError::NoRun);
|
||||
}
|
||||
|
|
@ -807,12 +767,7 @@ impl RunStores {
|
|||
return Err(RunError::Drift(DriftOf::Prompts));
|
||||
}
|
||||
check_pins(&cache, root, &record)?;
|
||||
between();
|
||||
let run = Self::with(root, cache, record)?;
|
||||
// Checking and opening are two reads of each file: the opened stores
|
||||
// are the pinned ones only if the pins still hold after the open.
|
||||
check_pins(&run.cache, root, &run.record)?;
|
||||
Ok(run)
|
||||
Self::with(root, cache, record)
|
||||
}
|
||||
|
||||
fn with(root: &Path, cache: CultCache, record: RunRecord) -> Result<Self, RunError> {
|
||||
|
|
|
|||
|
|
@ -372,149 +372,6 @@ fn a_run_from_before_the_copy_does_not_open() {
|
|||
assert_eq!(RunStores::open(&root).err(), Some(RunError::Store));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_store_changed_between_its_digest_and_its_open_is_drift() {
|
||||
let mut w = world();
|
||||
let dir = w.dir.path().to_path_buf();
|
||||
let root = dir.join("run");
|
||||
run_over(&dir);
|
||||
let more = |w: &mut common::World| {
|
||||
let item = common::item_in(
|
||||
"item:nibu:2",
|
||||
"Another line.",
|
||||
&common::group_in_bucket(10),
|
||||
common::cast(),
|
||||
);
|
||||
w.corpus.add(item, &w.entities).unwrap();
|
||||
};
|
||||
// The pins hold at the check; the corpus changes before the stores open.
|
||||
assert_eq!(
|
||||
RunStores::open_between(&root, || more(&mut w)).err(),
|
||||
Some(RunError::Drift(DriftOf::Corpus))
|
||||
);
|
||||
|
||||
// The same window at create: nothing is pinned and the inventory copy and its
|
||||
// lock are taken away again, so the retry creates.
|
||||
let mut w = world();
|
||||
let dir = w.dir.path().to_path_buf();
|
||||
let root = dir.join("run");
|
||||
for name in ["c.cc", "i.cc", "entities.cc"] {
|
||||
assert!(dir.join(name).exists(), "{name}");
|
||||
}
|
||||
let (c, i, e) = (dir.join("c.cc"), dir.join("i.cc"), dir.join("entities.cc"));
|
||||
let o = dir.join("ontology.cc");
|
||||
let s = common::speaker_state_beside(&o);
|
||||
let paths = || weksa::run::RunPaths {
|
||||
corpus: &c,
|
||||
inventory: &i,
|
||||
entities: &e,
|
||||
ontology: &o,
|
||||
speaker_state: &s,
|
||||
};
|
||||
assert_eq!(
|
||||
RunStores::create_between(
|
||||
&root,
|
||||
"t",
|
||||
paths(),
|
||||
"fake-model",
|
||||
"bag",
|
||||
weksa::run::LowererReach::ToolLessRelay,
|
||||
ModelFamily::Unrecorded,
|
||||
&["en-US".to_string()],
|
||||
|| more(&mut w)
|
||||
)
|
||||
.err(),
|
||||
Some(RunError::Drift(DriftOf::Corpus))
|
||||
);
|
||||
assert!(!root.join("inventory.cc").exists());
|
||||
// Not the copy and not the lock the store's open left beside it.
|
||||
assert!(!root.join("inventory.cc.lock").exists());
|
||||
assert_eq!(RunStores::open(&root).err(), Some(RunError::NoRun));
|
||||
RunStores::create(
|
||||
&root,
|
||||
"t",
|
||||
paths(),
|
||||
"fake-model",
|
||||
"bag",
|
||||
weksa::run::LowererReach::ToolLessRelay,
|
||||
ModelFamily::Unrecorded,
|
||||
&["en-US".to_string()],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Runs `change` in the window between the pins and the open, at `open` and at
|
||||
/// `create`, and returns what each refused with plus what `create` left behind.
|
||||
fn window(
|
||||
change: impl Fn(&mut common::World, &Path),
|
||||
) -> (Option<RunError>, Option<RunError>, bool, Option<RunError>) {
|
||||
let mut w = world();
|
||||
let dir = w.dir.path().to_path_buf();
|
||||
let root = dir.join("run");
|
||||
run_over(&dir);
|
||||
let opened = RunStores::open_between(&root, || change(&mut w, &root)).err();
|
||||
|
||||
let mut w = world();
|
||||
let dir = w.dir.path().to_path_buf();
|
||||
let root = dir.join("run");
|
||||
let (c, i, e) = (dir.join("c.cc"), dir.join("i.cc"), dir.join("entities.cc"));
|
||||
let o = dir.join("ontology.cc");
|
||||
let paths = weksa::run::RunPaths {
|
||||
corpus: &c,
|
||||
inventory: &i,
|
||||
entities: &e,
|
||||
ontology: &o,
|
||||
speaker_state: &common::speaker_state_beside(&o),
|
||||
};
|
||||
let created = RunStores::create_between(
|
||||
&root,
|
||||
"t",
|
||||
paths,
|
||||
"fake-model",
|
||||
"bag",
|
||||
weksa::run::LowererReach::ToolLessRelay,
|
||||
ModelFamily::Unrecorded,
|
||||
&["en-US".to_string()],
|
||||
|| change(&mut w, &root),
|
||||
)
|
||||
.err();
|
||||
let left = root.join("inventory.cc").exists() || root.join("inventory.cc.lock").exists();
|
||||
(opened, created, left, RunStores::open(&root).err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_entity_store_changed_between_its_digest_and_its_open_is_drift() {
|
||||
let (opened, created, left, after) = window(|w, _| {
|
||||
w.entities.put(ent("kay", "en-US", &["Kay"])).unwrap();
|
||||
});
|
||||
assert_eq!(opened, Some(RunError::Drift(DriftOf::Entities)));
|
||||
assert_eq!(created, Some(RunError::Drift(DriftOf::Entities)));
|
||||
assert!(!left);
|
||||
assert_eq!(after, Some(RunError::NoRun));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_head_inventory_changed_between_its_digest_and_its_open_is_drift() {
|
||||
let (opened, created, left, after) = window(|_, root| {
|
||||
weksa::InventoryStore::open(&root.join("inventory.cc"))
|
||||
.unwrap()
|
||||
.admit_revision(
|
||||
weksa::InventoryRevision {
|
||||
n: 5,
|
||||
parent: Some(4),
|
||||
changes: vec![],
|
||||
frozen: false,
|
||||
},
|
||||
vec![],
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
assert_eq!(opened, Some(RunError::Drift(DriftOf::Inventory)));
|
||||
assert_eq!(created, Some(RunError::Drift(DriftOf::Inventory)));
|
||||
assert!(!left);
|
||||
assert_eq!(after, Some(RunError::NoRun));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_digests_cover_their_files() {
|
||||
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||
|
|
@ -2666,129 +2523,6 @@ fn a_changed_head_is_drift() {
|
|||
);
|
||||
}
|
||||
|
||||
/// Tripwires over the source, with the limits stated: they read text, so they
|
||||
/// catch a spelling and not an alias.
|
||||
#[test]
|
||||
fn source_tripwires() {
|
||||
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||
let read = |rel: &str| std::fs::read_to_string(src.join(rel)).unwrap();
|
||||
for file in ["run.rs", "model.rs", "encode.rs"] {
|
||||
let text = read(file);
|
||||
for banned in ["Split::Test", "Checkpoint"] {
|
||||
assert!(!text.contains(banned), "{file} names {banned}");
|
||||
}
|
||||
}
|
||||
// Every prompt file leaves through RunStores::answer_files, which withholds Test text.
|
||||
assert!(!read("main.rs").contains("AnswerFiles::new"));
|
||||
let mut all = Vec::new();
|
||||
let mut stack = vec![src.clone()];
|
||||
while let Some(dir) = stack.pop() {
|
||||
for entry in std::fs::read_dir(dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.is_dir() {
|
||||
stack.push(path);
|
||||
} else if path.extension().is_some_and(|e| e == "rs") {
|
||||
all.push((
|
||||
path.strip_prefix(&src)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
std::fs::read_to_string(&path).unwrap(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (file, text) in &all {
|
||||
let code: String = text
|
||||
.lines()
|
||||
.filter(|l| !l.trim_start().starts_with("//"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
if file != "main.rs" {
|
||||
assert!(!code.contains("std::process"), "{file}");
|
||||
}
|
||||
// The Ollama reply is the other xenos boundary: JSON read from a server.
|
||||
if file != "encode.rs" && file != "score/embed.rs" {
|
||||
assert!(!code.contains("serde_json::from_str"), "{file}");
|
||||
}
|
||||
if file != "context.rs" {
|
||||
assert!(!code.contains("Prompt {"), "{file}");
|
||||
}
|
||||
}
|
||||
let context = read("context.rs");
|
||||
assert!(!context.contains("pub fn from_corpus") && !context.contains("pub fn for_round"));
|
||||
// The editor's prompt reads Train items, an inventory and an EditFeedback:
|
||||
// no round record, decision, held-out mean or refusal count is named there.
|
||||
for banned in [
|
||||
"RoundRecord",
|
||||
"Decision",
|
||||
"SplitMean",
|
||||
"Aggregate",
|
||||
"validation_mean",
|
||||
"validation_refused",
|
||||
"ItemScore",
|
||||
"LanguageScores",
|
||||
"validation_scores",
|
||||
] {
|
||||
assert!(!context.contains(banned), "context.rs names {banned}");
|
||||
}
|
||||
// `EditFeedback::none` is the one public constructor; Decision has none.
|
||||
assert!(!context.contains("pub fn new"));
|
||||
let run = read("run.rs");
|
||||
let code: Vec<&str> = run
|
||||
.lines()
|
||||
.filter(|l| !l.trim_start().starts_with("//"))
|
||||
.collect();
|
||||
let count = |needle: &str| code.iter().filter(|l| l.contains(needle)).count();
|
||||
assert!(!run.contains("pub fn new"));
|
||||
assert_eq!(
|
||||
count("Prompt::lower("),
|
||||
2,
|
||||
"two lowering call sites: the round's and the stance ablation's replay of it"
|
||||
);
|
||||
// Prompt::lower takes the view, the item's key and speaker id, the inventory and the entity
|
||||
// port: no corpus item, train set, offer or store.
|
||||
let start = context.find("pub fn lower(").unwrap();
|
||||
let signature = &context[start..start + context[start..].find(") -> ").unwrap()];
|
||||
for banned in ["CorpusItem,", "CorpusItem)", "TrainItems", "EncoderOffer", "Store"] {
|
||||
assert!(!signature.contains(banned), "Prompt::lower takes {banned}");
|
||||
}
|
||||
assert!(signature.contains("&LoweringInput") && signature.contains("&CorpusItemId"));
|
||||
assert!(signature.contains("&Ontology"), "the whole ontology goes in; select chooses");
|
||||
assert_eq!(count("admit_revision("), 1, "one door call");
|
||||
assert_eq!(
|
||||
count("std::fs::copy"),
|
||||
1,
|
||||
"the cycle's copy; create's is copy_new"
|
||||
);
|
||||
assert_eq!(
|
||||
count("Path::new(&record.inventory)"),
|
||||
1,
|
||||
"the source path is read once"
|
||||
);
|
||||
assert_eq!(
|
||||
count("InventoryStore::open"),
|
||||
2,
|
||||
"the head and the cycle's file"
|
||||
);
|
||||
// An entry draft carries no id or revision field.
|
||||
let encode = read("encode.rs");
|
||||
let entry = encode
|
||||
.split("pub struct EntryDraft {")
|
||||
.nth(1)
|
||||
.and_then(|t| t.split('}').next())
|
||||
.unwrap();
|
||||
for banned in ["id", "introduced_rev", "retired_rev"] {
|
||||
assert!(
|
||||
!entry
|
||||
.split_whitespace()
|
||||
.any(|w| w.trim_end_matches(':') == banned),
|
||||
"EntryDraft has a {banned} field"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- the lowerer ----
|
||||
|
||||
/// Lowercase letters and digits only: what survives any re-spacing or re-casing.
|
||||
|
|
|
|||
|
|
@ -1128,28 +1128,11 @@ fn committed_scenes_cover_original_groups() {
|
|||
DIGEST_OF_THE_EARLIER_SCENES,
|
||||
"an earlier scene revision changed"
|
||||
);
|
||||
// Rubric r1 is text the labels cite: the section, as committed, is pinned.
|
||||
let doc = std::fs::read_to_string(
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../docs/scene-annotation.md"),
|
||||
)
|
||||
.unwrap();
|
||||
let from = doc.find("## Rubric r1").expect("the doc holds Rubric r1");
|
||||
let rest = &doc[from + "## Rubric r1".len()..];
|
||||
let section = &doc[from..from + "## Rubric r1".len() + rest.find("\n## ").expect("a section follows r1")];
|
||||
assert_eq!(
|
||||
weksa::split::fnv1a64_of(&[section.trim().as_bytes()]),
|
||||
DIGEST_OF_THE_RUBRIC,
|
||||
"rubric r1 was edited; a new rubric is a new section and a new generator"
|
||||
);
|
||||
}
|
||||
|
||||
/// Taken over the 113 scene revisions that precede rubric r1, 2026-11-13.
|
||||
const DIGEST_OF_THE_EARLIER_SCENES: u64 = 2598828882325200913;
|
||||
|
||||
/// Taken over the text of the `## Rubric r1` section of docs/scene-annotation.md
|
||||
/// (trimmed), 2026-11-13.
|
||||
const DIGEST_OF_THE_RUBRIC: u64 = 11823581212652524671;
|
||||
|
||||
/// Taken over each live group's latest revision (group, n, features) at rubric r1,
|
||||
/// 2026-11-13.
|
||||
const DIGEST_OF_THE_SCENES: u64 = 2505219080875817063;
|
||||
|
|
|
|||
Loading…
Reference in a new issue