Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
"""Execute the actual shared-file transaction with injected disk failures.
|
||||
Engine JSON/migration/menu checks are recorded separately in native evidence.
|
||||
"""
|
||||
from policy_harness import ROOT, body, run
|
||||
p = ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_ProfileConfig.c'
|
||||
method = body(p, 'static bool Commit(')
|
||||
for before, after in [
|
||||
('map<string, string>', 'Map'), ('FileHandle file', 'FileHandle* file'),
|
||||
('file.', 'file->'), ('FileIO.', 'FileIO::'), ('FileMode.', 'FileMode::'),
|
||||
('Replication.', 'Replication::')]:
|
||||
method = method.replace(before, after)
|
||||
run(r'''
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <string>
|
||||
using string=std::string;
|
||||
using Map=std::map<string,string>;
|
||||
const string PATH="Escapists.json";
|
||||
std::map<string,string> files;
|
||||
std::map<string,Map> documents;
|
||||
int fault=0,serial=0;
|
||||
namespace Replication {bool server=true;bool IsServer(){return server;}}
|
||||
namespace FileMode {int WRITE=1;}
|
||||
struct FileHandle {
|
||||
string path;
|
||||
void Write(string data){files[path]=fault==2?"CORRUPT":data;}
|
||||
void Close(){}
|
||||
};
|
||||
namespace FileIO {
|
||||
FileHandle* OpenFile(string path,int){static FileHandle h;h.path=path;return fault==1?nullptr:&h;}
|
||||
bool FileExists(string path){return files.count(path);}
|
||||
bool DeleteFile(string path){return files.erase(path);}
|
||||
bool CopyFile(string from,string to){
|
||||
if(!files.count(from))return false;
|
||||
if(to==PATH+".bak"&&fault==3)return false;
|
||||
files[to]=files[from];
|
||||
if(to==PATH+".bak"&&fault==4)files[to]="CORRUPT";
|
||||
if(from==PATH+".tmp"){
|
||||
if(fault==5){files[to]="PARTIAL";return false;}
|
||||
if(fault==6)files[to]="CORRUPT";
|
||||
if(fault==7){files[to]="WRONG";documents["WRONG"]={{"mission","wrong"}};}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
struct Store {
|
||||
static string Encode(Map values){string id="doc"+std::to_string(++serial);documents[id]=values;return id;}
|
||||
static bool Document(string path,Map& values){
|
||||
if(!files.count(path)||!documents.count(files[path]))return false;
|
||||
values=documents[files[path]];return true;
|
||||
}
|
||||
static bool Same(Map a,Map b){return a==b;}
|
||||
''' + method + r'''
|
||||
};
|
||||
int main(){
|
||||
Map old={{"mission","old"},{"items","presets"},{"voice","url"}}, next=old,read;
|
||||
next["mission"]="new";
|
||||
for(int injected:{1,2,5,6,7}){
|
||||
files.clear();fault=injected;
|
||||
assert(!Store::Commit(next)&&!files.count(PATH)); // failed first save stays absent
|
||||
}
|
||||
for(int injected=1;injected<=7;injected++){
|
||||
files.clear();fault=0;assert(Store::Commit(old));
|
||||
fault=injected;assert(!Store::Commit(next));
|
||||
assert(Store::Document(PATH,read)&&read==old); // current valid config remains
|
||||
fault=0;assert(Store::Commit(next));
|
||||
assert(Store::Document(PATH,read)&&read==next);
|
||||
}
|
||||
for(int injected:{1,2,5,6,7}){
|
||||
files.clear();files[PATH]="CORRUPT";files[PATH+".bak"]=Store::Encode(old);
|
||||
fault=injected;assert(!Store::Commit(next));
|
||||
assert(Store::Document(PATH+".bak",read)&&read==old); // only good backup not replaced
|
||||
fault=0;assert(Store::Commit(next));
|
||||
assert(Store::Document(PATH,read)&&read==next);
|
||||
}
|
||||
files.clear();fault=0;assert(Store::Commit(old));assert(Store::Commit(next));
|
||||
assert(Store::Document(PATH+".bak",read)&&read==old);
|
||||
assert(!files.count(PATH+".tmp"));
|
||||
Replication::server=false;assert(!Store::Commit(old));
|
||||
assert(Store::Document(PATH,read)&&read==next);
|
||||
}
|
||||
''')
|
||||
print('PASS: shared config transaction rejects client writes, preserves first-save/prior/fallback state across open, write, backup, partial-copy, readback and mismatch failures')
|
||||
Reference in New Issue
Block a user