Add ALD Transition Console preview and Astra lab build workflow

This commit is contained in:
scandalist-trash committed 2026-10-27 10:50:43 -04:00
1 parent f330a3c00a
commit e5c6a2fc0e
199 files changed
+9866

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
#include "core/Rules.h"
#include <algorithm>
#include <iostream>
#include <random>
#include <set>
#include <stdexcept>
using namespace ald::rules;
static int checks=0;
#define CHECK(x) do { ++checks; if(!(x)) throw std::runtime_error("check failed at line " + std::to_string(__LINE__) + ": " #x); } while(false)
template<typename F> void throws(F f){bool did=false;try{f();}catch(const std::invalid_argument&){did=true;}CHECK(did);}
int main(){try {
for(int exitCode:{0,1,127,255})for(bool normal:{false,true})for(Result post:{Result::Pass,Result::Fail,Result::NotChecked,Result::Error,Result::Unknown}) {
const auto r=reconcile(exitCode,normal,post,false,true);
CHECK((r==Result::Pass)==(exitCode==0&&normal&&post==Result::Pass));
CHECK(reconcile(exitCode,normal,post,true,true)==Result::Unknown);
}
GateInput gate;gate.sourceDomain=gate.targetDomain="corp.local";
gate.inventoryComplete=gate.recoveryRehearsed=gate.windowAuthorized=true;
for(const auto *id:{"same_name_transition","credentials","windows_profiles","computer_trust","identity_permissions","applications","policy_outcomes","ad_independence"})gate.requirements.push_back({id,CapabilityState::Verified,Result::Pass,true});
CHECK(blockers(gate).empty());
gate.requirements.front().support=CapabilityState::DocumentedNotTested;
CHECK(!blockers(gate).empty());
gate.requirements.front().evidence=Result::Pass; // Human checkbox cannot change support.
CHECK(!blockers(gate).empty());
gate.requirements.front().support=CapabilityState::Verified;
gate.current.mappingDigest="changed";CHECK(!blockers(gate).empty());gate.current=gate.accepted;
gate.current.inventoryDigest="changed";CHECK(!blockers(gate).empty());gate.current=gate.accepted;
gate.current.policyDigest="changed";CHECK(!blockers(gate).empty());gate.current=gate.accepted;
gate.current.revision++;CHECK(!blockers(gate).empty());gate.current=gate.accepted;
gate.requirements.clear();CHECK(!blockers(gate).empty());
gate.sourceDomain="CORP.LOCAL";gate.targetDomain="corp.local";
const auto mixedCase=blockers(gate);
CHECK(std::find(mixedCase.begin(),mixedCase.end(),"SAME_NAME_TRANSITION_UNVERIFIED")!=mixedCase.end());
RoleFacts clean;clean.astra=clean.packageQueryComplete=true;
CHECK(classify(clean)==NodeRole::PartialOrUnknown);
clean.configurationObserved=true;CHECK(classify(clean)==NodeRole::CleanAstra);
RoleFacts f;f.astra=f.packageQueryComplete=f.aldPackages=f.ipaConfig=f.serverConfig=f.servicesObserved=true;
CHECK(classify(f)==NodeRole::DcDegraded);CHECK(!canInitialize(classify(f)));
f.servicesHealthy=true;CHECK(classify(f)==NodeRole::PartialOrUnknown);
f.healthVerified=true;CHECK(classify(f)==NodeRole::DcHealthy);CHECK(!canInitialize(classify(f)));
for(bool reachable:{false,true})for(const auto &cur:{"old","applied","external"})CHECK(restoration(false,reachable,cur,"applied",false)==RestoreDecision::Preserve);
CHECK(restoration(true,true,"changed","applied",false)==RestoreDecision::Conflict);
CHECK(restoration(true,false,"applied","applied",false)==RestoreDecision::Pending);
CHECK(restoration(true,true,"applied","applied",true)==RestoreDecision::ManualVerification);
CHECK(identityKey("source","ABC","S-1-2")==identityKey("source","abc","S-1-2"));
CHECK(identityKey("source","abc","S-1-2")!=identityKey("source","def","S-1-2"));
CHECK(identityKey("source","abc","S-1-2")!=identityKey("other","abc","S-1-2"));
throws([]{identityKey("source","","sid");});
CHECK(!transitionAllowed(RunState::Running,RunState::Completed));
CHECK(!transitionAllowed(RunState::RecoveryRequired,RunState::Running));
CHECK(transitionAllowed(RunState::Running,RunState::StopRequested));
CHECK(!dependenciesPassed({"two","host",{"one"},true},{{"one",Result::Fail}}));
CHECK(!dependenciesPassed({"two","host",{"one"},true},{}));
CHECK(afterResult(Result::Fail,ErrorPolicy::Independent)==BatchDecision::Continue);
CHECK(afterResult(Result::Unknown,ErrorPolicy::Stop)==BatchDecision::Stop);
CHECK(afterResult(Result::Error,ErrorPolicy::Pause)==BatchDecision::Pause);
throws([]{topological({{"a","x",{"b"},false},{"b","y",{"a"},false}});});
throws([]{topological({{"a","x",{"missing"},false}});});
throws([]{topological({{"a","x",{},false},{"a","y",{},false}});});
for(const auto *bad:{"--help","host;id","a\nwhoami","$(id)","a..b","a.-b","a_.b","a.'b","a/b","a:22","a\\b"})CHECK(!safeHost(bad));
CHECK(safeHost("ald.corp.local"));CHECK(safeHost("192.0.2.10"));
for(const auto *bad:{"--help","x;id","a b","$x","a\n","a'"})CHECK(!safeUser(bad));
CHECK(safeUser("CORP\\admin"));CHECK(safeUser("ald.alice"));
for(const auto *bad:{"/abs","../x","x/../y","x//y","C:\\x","x/./y"}) { CHECK(!safeRelativePath(bad)); }
CHECK(safeRelativePath("tasks/check.ps1"));
const std::vector<std::string> secrets={"password-123","пароль123","abc","bcd"};
const std::string input="before password-123 and пароль123 and abcd after";
for(std::size_t split=0;split<=input.size();++split){SecretStream s(secrets);auto output=s.feed(input.substr(0,split));output+=s.feed(input.substr(split),true);for(const auto &secret:secrets)CHECK(output.find(secret)==std::string::npos);CHECK(output.find("before")!=std::string::npos);CHECK(output.find("after")!=std::string::npos);}
SecretStream overflow({"aaa"});std::string suppressed;
for(int i=0;i<10;++i)suppressed+=overflow.feed(std::string(1000,'a'));
suppressed+=overflow.feed("aaa after",true);
CHECK(suppressed.find("aaa")==std::string::npos);
CHECK(suppressed.find("oversized sensitive output")!=std::string::npos);
// Reproducible generative properties: chunk partition independence and DAG order.
std::mt19937 random(0xA1D310);
SecretStream whole(secrets);const auto expected=whole.feed(input,true);
for(int trial=0;trial<1000;++trial){SecretStream s(secrets);std::string output;for(std::size_t pos=0;pos<input.size();){auto n=1+random()%9;output+=s.feed(input.substr(pos,n));pos+=n;}output+=s.feed("",true);CHECK(output==expected);
std::vector<Step> steps;for(int i=0;i<20;++i){Step step{std::to_string(i),"host",{},false};for(int j=0;j<i;++j)if(random()%5==0)step.dependencies.push_back(std::to_string(j));steps.push_back(step);}std::shuffle(steps.begin(),steps.end(),random);auto order=topological(steps);CHECK(order.size()==steps.size());for(const auto &step:steps)for(const auto &dep:step.dependencies)CHECK(std::find(order.begin(),order.end(),dep)<std::find(order.begin(),order.end(),step.id));
}
std::cout<<"PASS: "<<checks<<" assertions, including 1000 seeded chunk/DAG trials\n";return 0;
}catch(const std::exception &e){std::cerr<<e.what()<<'\n';return 1;}}