Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Thumbs.db
node_modules/
dist/
target/
.cargo-target/
*.log

# Entornos y secretos
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion crates/archmaker-core/fixtures/embedded-catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"options": [
{
"id": "archmaker.kernel.linux",
"title": "Linux"
"title": "Linux",
"provides": ["fs.ext4"]
}
]
}
Expand All @@ -50,5 +51,28 @@
}
]
}
],
"rules": [
{
"id": "RULE-COMP-001"
},
{
"id": "RULE-DM-001"
},
{
"id": "RULE-KERNEL-001"
},
{
"id": "RULE-BROWSER-001"
},
{
"id": "RULE-PKG-001"
},
{
"id": "RULE-KERNEL-002"
},
{
"id": "RULE-DUP-001"
}
]
}
117 changes: 100 additions & 17 deletions crates/archmaker-core/fixtures/local-catalog-mvp1.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@
"title": "Kernel",
"cardinality": "one",
"options": [
{ "id": "archmaker.kernel.linux", "title": "Linux" },
{ "id": "archmaker.kernel.zen", "title": "Linux Zen" }
{
"id": "archmaker.kernel.linux",
"title": "Linux",
"provides": ["fs.ext4", "fs.btrfs"]
},
{
"id": "archmaker.kernel.zen",
"title": "Linux Zen",
"provides": ["fs.ext4", "fs.btrfs"]
}
]
}
]
Expand All @@ -40,8 +48,16 @@
"title": "Filesystem",
"cardinality": "one",
"options": [
{ "id": "archmaker.filesystem.btrfs", "title": "Btrfs" },
{ "id": "archmaker.filesystem.ext4", "title": "Ext4" }
{
"id": "archmaker.filesystem.btrfs",
"title": "Btrfs",
"provides": ["fs.btrfs"]
},
{
"id": "archmaker.filesystem.ext4",
"title": "Ext4",
"provides": ["fs.ext4"]
}
]
}
]
Expand All @@ -56,8 +72,14 @@
"title": "Bootloader",
"cardinality": "one",
"options": [
{ "id": "archmaker.boot.systemd-boot", "title": "systemd-boot" },
{ "id": "archmaker.boot.grub", "title": "GRUB" }
{
"id": "archmaker.boot.systemd-boot",
"title": "systemd-boot"
},
{
"id": "archmaker.boot.grub",
"title": "GRUB"
}
]
}
]
Expand All @@ -72,7 +94,10 @@
"title": "Base devel",
"cardinality": "one",
"options": [
{ "id": "archmaker.pkg.base-devel", "title": "base-devel" }
{
"id": "archmaker.pkg.base-devel",
"title": "base-devel"
}
]
}
]
Expand All @@ -87,9 +112,18 @@
"title": "Compositor",
"cardinality": "one",
"options": [
{ "id": "archmaker.compositor.gnome", "title": "GNOME" },
{ "id": "archmaker.compositor.hyprland", "title": "Hyprland" },
{ "id": "archmaker.compositor.sway", "title": "Sway" }
{
"id": "archmaker.compositor.gnome",
"title": "GNOME"
},
{
"id": "archmaker.compositor.hyprland",
"title": "Hyprland"
},
{
"id": "archmaker.compositor.sway",
"title": "Sway"
}
]
}
]
Expand All @@ -104,8 +138,14 @@
"title": "Display manager",
"cardinality": "one",
"options": [
{ "id": "archmaker.dm.gdm", "title": "GDM" },
{ "id": "archmaker.dm.sddm", "title": "SDDM" }
{
"id": "archmaker.dm.gdm",
"title": "GDM"
},
{
"id": "archmaker.dm.sddm",
"title": "SDDM"
}
]
}
]
Expand All @@ -120,8 +160,16 @@
"title": "Browser",
"cardinality": "one",
"options": [
{ "id": "archmaker.browser.firefox", "title": "Firefox" },
{ "id": "archmaker.browser.vivaldi", "title": "Vivaldi" }
{
"id": "archmaker.browser.firefox",
"title": "Firefox",
"provides": ["pkg.firefox"]
},
{
"id": "archmaker.browser.vivaldi",
"title": "Vivaldi",
"provides": ["pkg.vivaldi"]
}
]
}
]
Expand All @@ -136,12 +184,47 @@
"title": "Apps",
"cardinality": "many",
"options": [
{ "id": "archmaker.app.steam", "title": "Steam" },
{ "id": "archmaker.app.vlc", "title": "VLC" },
{ "id": "archmaker.app.gimp", "title": "GIMP" }
{
"id": "archmaker.app.steam",
"title": "Steam",
"provides": ["pkg.steam"]
},
{
"id": "archmaker.app.vlc",
"title": "VLC",
"provides": ["pkg.vlc"]
},
{
"id": "archmaker.app.gimp",
"title": "GIMP",
"provides": ["pkg.gimp"]
}
]
}
]
}
],
"rules": [
{
"id": "RULE-COMP-001"
},
{
"id": "RULE-DM-001"
},
{
"id": "RULE-KERNEL-001"
},
{
"id": "RULE-BROWSER-001"
},
{
"id": "RULE-PKG-001"
},
{
"id": "RULE-KERNEL-002"
},
{
"id": "RULE-DUP-001"
}
]
}
53 changes: 41 additions & 12 deletions crates/archmaker-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use archmaker_domain::{
Selection, SelectionOrigin, SelectionValue, TargetRef, MANIFEST_DOMAIN_LABEL,
};
use archmaker_resolution::{Catalog as ResolutionCatalog, CatalogOption};
use archmaker_rules::{canonical_rules, evaluate_all, Diagnostic, Draft as RulesDraft};
use archmaker_rules::{
load_rules_by_ids, Diagnostic, Draft as RulesDraft, Rule, CANONICAL_RULES_PACK_JSON,
};

use crate::error::{CoreError, Result};
use crate::inputs::{
Expand Down Expand Up @@ -80,14 +82,31 @@ static UUID_COUNTER: AtomicU64 = AtomicU64::new(0);

pub struct RealCore {
pub catalog_embedded: Catalog,
/// Reglas activas cargadas desde fichas del catálogo (nunca inventadas en silencio).
pub active_rules: Vec<Rule>,
store_dir: Option<PathBuf>,
drafts: RefCell<HashMap<String, Draft>>,
}

fn rules_from_catalog(catalog: &Catalog) -> Result<Vec<Rule>> {
let source = CoreOp::LoadCatalog.source();
let Some(refs) = catalog.rules.as_ref() else {
return Ok(Vec::new());
};
if refs.is_empty() {
return Ok(Vec::new());
}
let ids: Vec<&str> = refs.iter().map(|rule_ref| rule_ref.id.as_str()).collect();
load_rules_by_ids(CANONICAL_RULES_PACK_JSON, &ids)
.map_err(|_| CoreError::schema_invalid(source))
}

impl RealCore {
pub fn new(catalog_embedded: Catalog) -> Self {
let active_rules = rules_from_catalog(&catalog_embedded).unwrap_or_default();
Self {
catalog_embedded,
active_rules,
store_dir: None,
drafts: RefCell::new(HashMap::new()),
}
Expand All @@ -99,7 +118,13 @@ impl RealCore {
.map_err(|_| CoreError::schema_invalid(source))?;
let catalog: Catalog =
serde_json::from_value(value).map_err(|_| CoreError::schema_invalid(source))?;
Ok(Self::new(catalog))
let active_rules = rules_from_catalog(&catalog)?;
Ok(Self {
catalog_embedded: catalog,
active_rules,
store_dir: None,
drafts: RefCell::new(HashMap::new()),
})
}

pub fn with_store_dir(mut self, dir: PathBuf) -> Self {
Expand Down Expand Up @@ -613,13 +638,20 @@ fn resolve_internal(
}
let (provided, _) = provided_required(&view, &catalog);
view.provided = provided.into_iter().collect();
let resolved = archmaker_resolution::resolve(&view, &catalog);
let digest = resolution_content_digest(
let resolved = archmaker_resolution::resolve(&view, &catalog, &core.active_rules);
let digest = ContentDigest {
algorithm: DigestAlgorithm::Sha256,
value: resolved.resolution_digest.clone(),
kind: Some(ContentKind::Content),
};
// Parity check: core digest helper must match resolution crate (NFR-DET-001).
let expected = resolution_content_digest(
&resolved.effective_selections,
&resolved.provided_capabilities,
&resolved.required_capabilities,
&resolved.diagnostics,
);
debug_assert_eq!(digest.value, expected.value);
let input_pairs: BTreeSet<(String, String)> = draft
.selections
.iter()
Expand Down Expand Up @@ -890,18 +922,15 @@ impl CorePort for RealCore {

fn validate_draft(&self, input: ValidateDraftInput) -> Result<ValidationResult> {
let source = CoreOp::ValidateDraft.source();
self.ensure_catalog_match(&input.catalog_ref, source)?;
ensure_draft_shape(&input.draft, source)?;
if let Some(target) = &input.target_ref {
ensure_target(target, &union_targets(), source)?;
}
let catalog = resolution_catalog(&self.catalog_embedded);
let mut view = rules_view(&input.draft);
let (provided, _) = provided_required(&view, &catalog);
view.provided = provided.into_iter().collect();
let mut diagnostics = evaluate_all(&canonical_rules(), &view);
// Same pipeline as resolve/buildManifest (stages 6–9): integrity, rules, resolution.
let internal = resolve_internal(self, &input.draft, &input.catalog_ref, source)?;
let mut diagnostics = internal.diagnostics;
sort_diagnostics(&mut diagnostics);
let blocking = diagnostics.iter().any(|diagnostic| diagnostic.blocking);
let blocking = !internal.conflicts.is_empty()
|| diagnostics.iter().any(|diagnostic| diagnostic.blocking);
Ok(ValidationResult {
diagnostics,
blocking,
Expand Down
2 changes: 2 additions & 0 deletions crates/archmaker-resolution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ license.workspace = true

[dependencies]
archmaker-rules = { path = "../archmaker-rules" }
archmaker-canonicalization = { path = "../archmaker-canonicalization" }
serde_json = "1"
Loading
Loading