-
Notifications
You must be signed in to change notification settings - Fork 1
Extension-index completeness gate + fix stale extension table — P2.5 #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0c96409
Extension-index completeness gate + fix stale extension table — P2.5
LayerDynamics 125f45b
Merge remote-tracking branch 'origin/main' into docs-pipeline-p25-ext…
LayerDynamics 573c1a6
Merge remote-tracking branch 'origin/main' into docs-pipeline-p25-ext…
LayerDynamics File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| //! Rule `ext-index`: every `crates/ext_*` extension is listed in the | ||
| //! `architecture.md` "Extension Crates" overview table. | ||
| //! | ||
| //! This is the index/module-list guard (Phase 2.5). It is a **completeness | ||
| //! check**, not a generator: the table's `Purpose` column is hand-authored prose | ||
| //! and only 13/37 crates carry a `Cargo.toml` description, so generating that | ||
| //! column would either fabricate text or replace good labels with inconsistent | ||
| //! doc-first-lines. Instead the rule ensures the authored table can never go | ||
| //! silently incomplete — which it had (it listed 27 of 37 extensions, missing | ||
| //! `console`, `dock`, `encoding`, `image_tools`, `svelte`, `web_inspector`, | ||
| //! `codesign`, …). Adding a new extension now requires adding its row, the same | ||
| //! way `crate-page` requires its dedicated page. | ||
|
|
||
| use crate::checks::read_optional; | ||
| use crate::discovery::Workspace; | ||
| use crate::Finding; | ||
|
|
||
| /// The overview page whose extension table must list every extension crate. | ||
| const INDEX_PAGE: &str = "architecture.md"; | ||
|
|
||
| pub fn check(ws: &Workspace) -> Vec<Finding> { | ||
| let page = match read_optional(&ws.docs_dir().join(INDEX_PAGE)) { | ||
| Some(p) => p, | ||
| None => return Vec::new(), | ||
| }; | ||
| let mut findings = Vec::new(); | ||
| for krate in ws.extension_crates() { | ||
| // The table references each extension by its crate name in a code span, | ||
| // e.g. `| `ext_console` | … |`. Require that exact token to be present. | ||
| let needle = format!("`{}`", krate.dir_name); | ||
| if !page.contains(&needle) { | ||
| findings.push(Finding::new( | ||
| "ext-index", | ||
| format!( | ||
| "extension crate `{}` is not listed in {}'s extension overview table", | ||
| krate.dir_name, INDEX_PAGE | ||
| ), | ||
| )); | ||
| } | ||
| } | ||
| findings | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use std::fs; | ||
|
|
||
| fn ws_with(arch: &str, ext_crates: &[&str]) -> (tempfile::TempDir, Workspace) { | ||
| let tmp = tempfile::tempdir().unwrap(); | ||
| let root = tmp.path(); | ||
| fs::create_dir_all(root.join("sdk")).unwrap(); | ||
| fs::create_dir_all(root.join("site/src/content/docs")).unwrap(); | ||
| fs::write(root.join("site/src/content/docs/architecture.md"), arch).unwrap(); | ||
| let mut members = String::new(); | ||
| for c in ext_crates { | ||
| let dir = root.join("crates").join(c); | ||
| fs::create_dir_all(&dir).unwrap(); | ||
| fs::write( | ||
| dir.join("Cargo.toml"), | ||
| format!("[package]\nname = \"{c}\"\nversion = \"0.1.0\"\nedition = \"2021\"\n"), | ||
| ) | ||
| .unwrap(); | ||
| members.push_str(&format!(" \"crates/{c}\",\n")); | ||
| } | ||
| fs::write( | ||
| root.join("Cargo.toml"), | ||
| format!("[workspace]\nmembers = [\n{members}]\nresolver = \"2\"\n"), | ||
| ) | ||
| .unwrap(); | ||
| let ws = Workspace::discover_at(root).unwrap(); | ||
| (tmp, ws) | ||
| } | ||
|
|
||
| #[test] | ||
| fn flags_extension_missing_from_table() { | ||
| let arch = "| `ext_fs` | runtime:fs | files |\n"; | ||
| let (_t, ws) = ws_with(arch, &["ext_fs", "ext_console"]); | ||
| let findings = check(&ws); | ||
| assert!( | ||
| findings.iter().any(|f| f.message.contains("ext_console")), | ||
| "missing ext_console must be flagged: {:?}", | ||
| findings.iter().map(|f| &f.message).collect::<Vec<_>>() | ||
| ); | ||
| assert!(!findings.iter().any(|f| f.message.contains("ext_fs"))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn passes_when_all_listed() { | ||
| let arch = "| `ext_fs` | x |\n| `ext_console` | y |\n"; | ||
| let (_t, ws) = ws_with(arch, &["ext_fs", "ext_console"]); | ||
| assert!(check(&ws).is_empty()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current check only verifies if the backticked crate name (e.g.,
`ext_window`) is present anywhere in the document. However, some extension crates are also mentioned in prose (for example,ext_windowis mentioned on line 60 ofarchitecture.md). If such an extension were accidentally removed from the overview table, this check would still pass (a false negative).To make this check robust, we should verify that the crate name is actually listed within a markdown table row (i.e., a line starting with
|).