fix(release): validate non-console config keys with target loader
This commit is contained in:
1 parent
b23783f395
commit
3b17c75508
3 files changed
+86
-14
No files matched your search
@@ -2598,3 +2598,60 @@ test('row196 rehearsal selects socket only for marked copies and uses scratch da
|
||||
assert.equal(untouched(e),before);
|
||||
});
|
||||
});
|
||||
|
||||
// #1797: validate every config with the target loader, even without console.
|
||||
function anyConfigLoader(file,text){
|
||||
const old=existsSync(file)?readFileSync(file):null;
|
||||
if(old!==null)chmodSync(file,0o644);
|
||||
mkdirSync(dirname(file),{recursive:true});writeFileSync(file,text);
|
||||
return ()=>{if(old===null)rmSync(file);else{writeFileSync(file,old);chmodSync(file,0o444);}};
|
||||
}
|
||||
const ANY_CONFIG_MSG=(e,to,op,why)=>`${e.cfg} is refused by ${to}'s loader (${why}); remove the refused key first (restore the config.json backup from the window's step 1), then run the ${op} again`;
|
||||
test('config-any-key: a non-console target refusal stops activate and rollback before any stop',async t=>{
|
||||
const e=await mk(t);await seed(e);
|
||||
let r=await run(e,'activate',C1,'acme');assert.equal(r.code,0,r.out+r.err);
|
||||
const why='mosaic-config: unsupported configuration key: "execution"';
|
||||
const undo=anyConfigLoader(join(COPIES,B,'scripts/mosaic-config.mjs'),`console.error(${JSON.stringify(why)});process.exitCode=2;\n`);
|
||||
try{
|
||||
assert.equal(Object.hasOwn(JSON.parse(readFileSync(e.cfg,'utf8')),'console'),false);
|
||||
for(const op of ['activate','rollback']){
|
||||
const args=op==='activate'?['activate',B,'acme']:['rollback','acme'];
|
||||
await refused(e,args,'config-console-key',ANY_CONFIG_MSG(e,B,op,why));
|
||||
}
|
||||
const out=await planOnly(e,3,'rollback','acme');
|
||||
assert.deepEqual(out.filter(l=>l.startsWith('refuses ')),[`refuses config-console-key: ${ANY_CONFIG_MSG(e,B,'rollback',why)}`]);
|
||||
}finally{undo();}
|
||||
});
|
||||
test('config-any-key: accepting loaders run validate with the selected config on activate and rollback',async t=>{
|
||||
const e=await mk(t);await seed(e);const witness=join(e.root,'loader-calls.jsonl'),canary='resolved-config-must-not-leak';
|
||||
const undos=[B,C1].map(id=>anyConfigLoader(join(COPIES,id,'scripts/mosaic-config.mjs'),`import fs from 'node:fs';fs.appendFileSync(${JSON.stringify(witness)},JSON.stringify({copy:${JSON.stringify(id)},args:process.argv.slice(2),config:process.env.MOSAIC_CONFIG})+'\\n');console.log(${JSON.stringify(canary)});\n`));
|
||||
try{
|
||||
for(const args of [['activate',C1,'acme'],['rollback','acme']]){
|
||||
const r=await run(e,...args);assert.equal(r.code,0,r.out+r.err);assert.equal((r.out+r.err).includes(canary),false);
|
||||
}
|
||||
assert.deepEqual(lines(witness).map(JSON.parse),[
|
||||
{copy:C1,args:['validate'],config:e.cfg},{copy:B,args:['validate'],config:e.cfg},
|
||||
]);
|
||||
}finally{for(const undo of undos)undo();}
|
||||
});
|
||||
function isolatedConfigChecks(e){
|
||||
const source=readFileSync(SR,'utf8'),body=source.split('config_checks() {')[1]?.split('\n}\n')[0];assert.ok(body,'config_checks exists');
|
||||
return spawnSync('bash',['-c','config_checks() {'+body+'\n}\ncheck_refuse(){ printf "%s: %s\\n" "$1" "$2" >&2; exit 3; }; config_checks'],{
|
||||
encoding:'utf8',env:{...e.env,COPIES:join(e.root,'target-copies'),TO:'old',OP:'activate'},
|
||||
});
|
||||
}
|
||||
test('config-any-key: missing-loader copies accept only the four oldest keys',async t=>{
|
||||
const e=await mk(t);let r=isolatedConfigChecks(e);assert.equal(r.status,0,r.stderr);
|
||||
const original=JSON.parse(readFileSync(e.cfg,'utf8'));
|
||||
for(const [key,value] of [['compactionReadBytes',1048576],['compactionStreams',['messages']]]){
|
||||
writeFileSync(e.cfg,JSON.stringify({...original,[key]:value}));r=isolatedConfigChecks(e);
|
||||
assert.equal(r.status,3,r.stderr);assert.match(r.stderr,new RegExp(`configuration key: "${key}"`));
|
||||
assert.ok(r.stderr.includes('restore the config.json backup from the window\'s step 1'));
|
||||
}
|
||||
});
|
||||
test('config-any-key: missing config passes but malformed JSON refuses without calling the loader',async t=>{
|
||||
const e=await mk(t),file=join(e.root,'target-copies/old/scripts/mosaic-config.mjs'),witness=join(e.root,'validate-called');
|
||||
mkdirSync(dirname(file),{recursive:true});writeFileSync(file,`import fs from 'node:fs';fs.writeFileSync(${JSON.stringify(witness)},'called');\n`);
|
||||
rmSync(e.cfg);let r=isolatedConfigChecks(e);assert.equal(r.status,0,r.stderr);assert.equal(existsSync(witness),false);
|
||||
writeFileSync(e.cfg,'{');r=isolatedConfigChecks(e);assert.equal(r.status,3,r.stderr);assert.match(r.stderr,/cannot be read as JSON/);assert.equal(existsSync(witness),false);
|
||||
});
|
||||
Reference in new issue
Block a user