Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Follows [Keep a Changelog](https://keepachangelog.com/); versioning is [SemVer](

- sl-viewer menu id taxonomy property surface (WBS-6.2 #457): `crates/sl-viewer/tests/properties_viewer_menu.rs` adds 5 proptest properties — every documented menu id (9 of them: `ID_APP_ABOUT`, `ID_APP_SETTINGS`, `ID_FILE_RELOAD_DISCOVERY`, `ID_FILE_SETTINGS`, `ID_EDIT_FIND`, `ID_VIEW_RELOAD`, `ID_VIEW_TOGGLE_THEME`, `ID_VIEW_COMMAND_PALETTE`, `ID_HELP_TOGGLE`) is non-empty, kebab-case ASCII, carries the `sl-viewer.` prefix, and is unique across the set so a muda event resolves to one DOM action. The menu taxonomy has exactly 9 documented ids so the operator documentation can be re-aligned if it drifts.

- sl-viewer async_states SkeletonLayout property surface (WBS-6.2 #458): `crates/sl-viewer/tests/properties_viewer_async_states.rs` adds 7 proptest properties — `SkeletonLayout::default()` is `Bundles`, exposes exactly three variants (`Bundles`, `ListDetail`, `StreamFeed`), and every variant's `Debug` label is non-empty, single-line, and matches one of the documented names. `list_rows.clamp(3, 6)` lands in `[3, 6]` for every input, is monotonic non-decreasing, and has the documented fixed points (`0` / `2` → `3`, `6` / `usize::MAX` → `6`).

- session-ledger OKF document validator property surface (WBS-6.2 #459): `crates/sl-viewer/tests/properties_session_ledger_okf.rs` adds 12 proptest properties pinning `session_ledger::OkfDocument::new` and `validate_okf_document` (the OKF v1 graph validator that backs the export / wiki / search pipeline). `new(b, c)` always produces `okf = "1.0"`, propagates `bundle.source_id` into `source_id` and `provenance.source_id`, propagates `c` into `provenance.corpus`, and starts with empty entities/relations/tags. `validate_okf_document` reports exactly one `unsupported_version` error per non-`"1.0"` `okf` (with the offending version in the message), exactly one `source_id_mismatch` error per provenance/source mismatch, exactly one `duplicate_entity_id` error per duplicate entity occurrence, `dangling_relation_source`/`dangling_relation_target` errors with field paths, and every `OkfValidationError` carries non-empty `field`/`code`/`message`.

- session-ledger worklog projector property surface (WBS-6.2 #460): `crates/sl-viewer/tests/properties_session_ledger_worklog.rs` adds 11 proptest properties pinning the crash-recovery / lost-work projector. Empty sessions project `None`; final user turns project as `AwaitingAssistantResponse`; final tool/subagent turns project as `InterruptedExecution`; final assistant turns with one of the 9 documented completion markers (`complete`, `completed`, `done`, `[completed]`, `<completed>`, `status: complete`, `status: completed`, `task complete`, `task completed`) project as `None`; final assistant turns without any marker project as `MissingCompletionMarker`; the summary never exceeds 241 characters, is single-line, and carries the originating session id, corpus, and message count. `project_unfinished_work` returns one item per unfinished session in input order and is deterministic. `WorklogProjection::from_session` carries `message_count` and matches `detect_unfinished` exactly.

- Commit signing header scan (C04 L34): `commit-signing-check.ps1` reads bounded commit headers via line-scanner (no unbounded `git cat-file` buffers or `(?ms)` regex); `-SelfCheck` + `tests/commit_signing_check.rs`.

- Loom permutation CI timeout (P0 stability): split blocking `loom-permutation.yml` into core + per-daemon `loom_model` jobs with `LOOM_MAX_PREEMPTIONS` on broadcast/pipeline/shutdown; mirror in soft `loom-smoke.yml` so Wave-40 tokio-shaped daemon graph tests no longer exceed single-job ceilings.
Expand Down
268 changes: 268 additions & 0 deletions crates/sl-viewer/tests/properties_session_ledger_okf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
//! Property evidence for `session_ledger::validate_okf_document` and

Check failure on line 1 in crates/sl-viewer/tests/properties_session_ledger_okf.rs

View workflow job for this annotation

GitHub Actions / Trunk Check

rustfmt

Incorrect formatting, autoformat by running 'trunk fmt'
//! `session_ledger::OkfDocument::new` (OKF v1 graph validation).
//!
//! The OKF validator is the single source of truth for whether an exported
//! document is well-formed before it is published to downstream consumers
//! (search index, wiki, replay). Any drift between the validator and the
//! exporter surfaces as a `Vec<OkfValidationError>` whose shape is pinned
//! here.
//!
//! `OkfDocument::new` invariants:
//! * `okf` is always `"1.0"`.
//! * `source_id` matches the input `bundle.source_id`.
//! * `provenance.corpus` matches the corpus arg.
//! * `provenance.source_id` matches the bundle `source_id`.
//! * `entities`, `relations`, `tags` start empty.
//!
//! `validate_okf_document` invariants:
//! * A freshly-constructed `OkfDocument::new(b, c)` is valid (zero errors).
//! * Bumping `okf` to anything other than `"1.0"` produces exactly one
//! `unsupported_version` error with field `"okf"`.
//! * `provenance.source_id != source_id` produces exactly one
//! `source_id_mismatch` error with field `"provenance.source_id"`.
//! * Duplicated entity ids each surface a `duplicate_entity_id` error.
//! * Dangling relation source/target each surface their respective error.
//! * Each error has non-empty `field` / `code` / `message`.

use proptest::prelude::*;
use session_ledger::{
validate_okf_document, OkfDocument, OkfEntity, OkfProvenance, OkfRelation,
OkfValidationError, ContinuationBundle,
};

// ── Strategies ─────────────────────────────────────────────────────────────

const CORPORA: &[&str] = &["forge", "codex", "claude-code", "cursor"];

// ── OkfDocument::new ───────────────────────────────────────────────────────

proptest! {
/// `OkfDocument::new(b, c)` always carries `okf = "1.0"`.
#[test]
fn new_document_okf_version_is_one_zero(
source_id in "[a-zA-Z0-9_-]{1,16}",
corpus_idx in 0..CORPORA.len(),
) {
let corpus = CORPORA[corpus_idx];
let bundle = ContinuationBundle::new(&source_id);
let document = OkfDocument::new(&bundle, corpus);
prop_assert_eq!(document.okf, "1.0");
}

/// `OkfDocument::new(b, c)` propagates `bundle.source_id`.
#[test]
fn new_document_source_id_matches_bundle(
source_id in "[a-zA-Z0-9_-]{1,16}",
corpus_idx in 0..CORPORA.len(),
) {
let corpus = CORPORA[corpus_idx];
let bundle = ContinuationBundle::new(&source_id);
let document = OkfDocument::new(&bundle, corpus);
prop_assert_eq!(document.source_id, bundle.source_id);
}

/// `OkfDocument::new(b, c)` propagates `c` into `provenance.corpus`.
#[test]
fn new_document_provenance_corpus_matches_arg(
source_id in "[a-zA-Z0-9_-]{1,16}",
corpus_idx in 0..CORPORA.len(),
) {
let corpus = CORPORA[corpus_idx];
let bundle = ContinuationBundle::new(&source_id);
let document = OkfDocument::new(&bundle, corpus);
prop_assert_eq!(document.provenance.corpus, corpus);
}

/// `OkfDocument::new(b, c)` propagates `bundle.source_id` into
/// `provenance.source_id`.
#[test]
fn new_document_provenance_source_id_matches_bundle(
source_id in "[a-zA-Z0-9_-]{1,16}",
corpus_idx in 0..CORPORA.len(),
) {
let corpus = CORPORA[corpus_idx];
let bundle = ContinuationBundle::new(&source_id);
let document = OkfDocument::new(&bundle, corpus);
prop_assert_eq!(document.provenance.source_id, bundle.source_id);
}

/// `OkfDocument::new(b, c)` starts with empty entities, relations, tags.
#[test]
fn new_document_collections_start_empty(
source_id in "[a-zA-Z0-9_-]{1,16}",
corpus_idx in 0..CORPORA.len(),
) {
let corpus = CORPORA[corpus_idx];
let bundle = ContinuationBundle::new(&source_id);
let document = OkfDocument::new(&bundle, corpus);
prop_assert!(document.entities.is_empty());
prop_assert!(document.relations.is_empty());
prop_assert!(document.tags.is_empty());
}
}

// ── validate_okf_document ──────────────────────────────────────────────────

proptest! {
/// A freshly-constructed OKF document validates with zero errors.
#[test]
fn fresh_document_validates_clean(
source_id in "[a-zA-Z0-9_-]{1,16}",
corpus_idx in 0..CORPORA.len(),
) {
let corpus = CORPORA[corpus_idx];
let bundle = ContinuationBundle::new(&source_id);
let document = OkfDocument::new(&bundle, corpus);
let errors = validate_okf_document(&document);
prop_assert!(errors.is_empty(), "expected no errors, got {errors:?}");
}

/// Bumping `okf` to anything other than `"1.0"` produces exactly one
/// `unsupported_version` error with field `"okf"`.
#[test]
fn wrong_okf_version_produces_one_unsupported_version_error(
source_id in "[a-zA-Z0-9_-]{1,16}",
bad_version in "[0-9A-Za-z.]{1,8}",
) {
let bundle = ContinuationBundle::new(&source_id);
let mut document = OkfDocument::new(&bundle, "forge");
// Filter out the trivial case where the random string happens to
// equal "1.0" — we want a strictly-non-"1.0" version.
prop_assume!(bad_version != "1.0");
document.okf = bad_version.clone();
let errors = validate_okf_document(&document);
let matching: Vec<&OkfValidationError> = errors
.iter()
.filter(|e| e.code == "unsupported_version" && e.field == "okf")
.collect();
prop_assert_eq!(matching.len(), 1);
// The message must mention the offending version.
prop_assert!(matching[0].message.contains(&bad_version));
}

/// `provenance.source_id != source_id` produces exactly one
/// `source_id_mismatch` error.
#[test]
fn provenance_source_mismatch_produces_one_error(
source_id in "[a-zA-Z0-9_-]{1,16}",
other_id in "[a-zA-Z0-9_-]{1,16}",
) {
prop_assume!(source_id != other_id);
let bundle = ContinuationBundle::new(&source_id);
let mut document = OkfDocument::new(&bundle, "forge");
document.provenance = OkfProvenance {
corpus: "forge".into(),
source_id: other_id.clone(),
};
let errors = validate_okf_document(&document);
let matching: Vec<&OkfValidationError> = errors
.iter()
.filter(|e| e.code == "source_id_mismatch" && e.field == "provenance.source_id")
.collect();
prop_assert_eq!(matching.len(), 1);
}

/// Duplicate entity ids surface a `duplicate_entity_id` error per
/// offending id (one per duplicate occurrence).
#[test]
fn duplicate_entity_ids_surface_errors(
n in 2_usize..6,
) {
let bundle = ContinuationBundle::new("dup-session");
let mut document = OkfDocument::new(&bundle, "forge");
let entity = OkfEntity {
id: "dup-entity".into(),
r#type: "intent".into(),
label: "shared".into(),
properties: serde_json::Value::Null,
};
document.entities = (0..n).map(|_| entity.clone()).collect();
let errors = validate_okf_document(&document);
let dups: Vec<&OkfValidationError> = errors
.iter()
.filter(|e| e.code == "duplicate_entity_id")
.collect();
// The validator reports the *second* (and subsequent) occurrences.
prop_assert_eq!(dups.len(), n - 1);
}

/// Dangling relation source surfaces a `dangling_relation_source` error.
#[test]
fn dangling_relation_source_surfaces_error(
source_id in "[a-zA-Z0-9_-]{1,16}",
) {
let bundle = ContinuationBundle::new(&source_id);
let mut document = OkfDocument::new(&bundle, "forge");
document.entities = vec![OkfEntity {
id: "present".into(),
r#type: "intent".into(),
label: "p".into(),
properties: serde_json::Value::Null,
}];
document.relations = vec![OkfRelation {
source: "missing-source".into(),
target: "present".into(),
r#type: "grounds".into(),
provenance: document.provenance.clone(),
}];
let errors = validate_okf_document(&document);
prop_assert!(errors.iter().any(|e| e.code == "dangling_relation_source"
&& e.field == "relations[0].source"));
}

/// Dangling relation target surfaces a `dangling_relation_target` error.
#[test]
fn dangling_relation_target_surfaces_error(
source_id in "[a-zA-Z0-9_-]{1,16}",
) {
let bundle = ContinuationBundle::new(&source_id);
let mut document = OkfDocument::new(&bundle, "forge");
document.entities = vec![OkfEntity {
id: "present".into(),
r#type: "intent".into(),
label: "p".into(),
properties: serde_json::Value::Null,
}];
document.relations = vec![OkfRelation {
source: "present".into(),
target: "missing-target".into(),
r#type: "grounds".into(),
provenance: document.provenance.clone(),
}];
let errors = validate_okf_document(&document);
prop_assert!(errors.iter().any(|e| e.code == "dangling_relation_target"
&& e.field == "relations[0].target"));
}

/// Every `OkfValidationError` carries non-empty `field`, `code`,
/// `message` so callers can render an actionable diagnostic.
#[test]
fn every_error_has_nonempty_components(_seed in any::<u32>()) {
let bundle = ContinuationBundle::new("err-shape");
let mut document = OkfDocument::new(&bundle, "forge");
// Force every error class at once.
document.okf = "2.0".into();
document.provenance.source_id = "other".into();
document.entities = vec![
OkfEntity {
id: "x".into(),
r#type: "intent".into(),
label: "x".into(),
properties: serde_json::Value::Null,
},
OkfEntity {
id: "x".into(),
r#type: "intent".into(),
label: "x".into(),
properties: serde_json::Value::Null,
},
];
let errors = validate_okf_document(&document);
Comment on lines +240 to +260

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add dangling relations to the all-error-shape fixture.

The fixture only produces unsupported_version, source_id_mismatch, and duplicate_entity_id. It does not produce dangling_relation_source or dangling_relation_target, despite Line 243 claiming that it forces every error class.

Add a relation whose source and target are absent from document.entities. This makes the non-empty component check cover all validator error classes.

Proposed fix
         document.entities = vec![
             OkfEntity {
                 id: "x".into(),
@@
                 properties: serde_json::Value::Null,
             },
         ];
+        document.relations = vec![OkfRelation {
+            source: "missing-source".into(),
+            target: "missing-target".into(),
+            r#type: "grounds".into(),
+            provenance: document.provenance.clone(),
+        }];
         let errors = validate_okf_document(&document);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn every_error_has_nonempty_components(_seed in any::<u32>()) {
let bundle = ContinuationBundle::new("err-shape");
let mut document = OkfDocument::new(&bundle, "forge");
// Force every error class at once.
document.okf = "2.0".into();
document.provenance.source_id = "other".into();
document.entities = vec![
OkfEntity {
id: "x".into(),
r#type: "intent".into(),
label: "x".into(),
properties: serde_json::Value::Null,
},
OkfEntity {
id: "x".into(),
r#type: "intent".into(),
label: "x".into(),
properties: serde_json::Value::Null,
},
];
let errors = validate_okf_document(&document);
fn every_error_has_nonempty_components(_seed in any::<u32>()) {
let bundle = ContinuationBundle::new("err-shape");
let mut document = OkfDocument::new(&bundle, "forge");
// Force every error class at once.
document.okf = "2.0".into();
document.provenance.source_id = "other".into();
document.entities = vec![
OkfEntity {
id: "x".into(),
r#type: "intent".into(),
label: "x".into(),
properties: serde_json::Value::Null,
},
OkfEntity {
id: "x".into(),
r#type: "intent".into(),
label: "x".into(),
properties: serde_json::Value::Null,
},
];
document.relations = vec![OkfRelation {
source: "missing-source".into(),
target: "missing-target".into(),
r#type: "grounds".into(),
provenance: document.provenance.clone(),
}];
let errors = validate_okf_document(&document);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/sl-viewer/tests/properties_session_ledger_okf.rs` around lines 240 -
260, Update every_error_has_nonempty_components to add a relation whose source
and target IDs are absent from document.entities, ensuring validation produces
both dangling_relation_source and dangling_relation_target alongside the
existing error classes. Keep the fixture’s all-error-shape intent and existing
entity setup unchanged.

prop_assert!(!errors.is_empty());
for err in &errors {
prop_assert!(!err.field.is_empty(), "error has empty field");
prop_assert!(!err.code.is_empty(), "error has empty code");
prop_assert!(!err.message.is_empty(), "error has empty message");
}
}
}
Loading
Loading