salvage: uncommitted work from dewey-r180 (disk cleanup #824, 2026-11-06)

This commit is contained in:
mos committed 2026-11-06 10:00:33 -06:00
1 parent 7f519242e1
commit 80558dfacd
5 files changed
+161 -10

No files matched your search

+102
View File
@@ -1095,3 +1095,105 @@ test('T42 tester-port pm-on preserves pointer Console flags',async(t)=>{
r=await run(e,'pm-on','acme');assert.equal(r.code,0,r.out+r.err);
assert.deepEqual(pointer(e).console,testerFlags(e));assert.match(consoleText(e),/--tester-port 7333(?:\n|$)/);
});
// Row 180 item 1 (P19 391): a date stand-in prints one second for every call that names a time,
// so each run below starts in that second, as two runs within one real second do. Calls for
// +%s (the gate's start mark) pass through, so each gate still reads only its own start.
function pinClock(e){
const dir=join(e.root,'clock'),second=Math.floor(Date.now()/1000);mkdirSync(dir);
writeFileSync(join(dir,'date'),`#!/bin/sh\ncase "$*" in *%s*) exec /usr/bin/date "$@" ;; esac\nexec /usr/bin/date -d @${second} "$@"\n`,{mode:0o755});
e.env={...e.env,PATH:`${dir}:${e.env.PATH}`};
return execFileSync(join(dir,'date'),['-u','+%Y%m%dT%H%M%SZ'],{env:e.env,encoding:'utf8'}).trim();
}
const rollbackSets=(e)=>readdirSync(join(e.state,'stack-rollback')).sort();
test('T43 row 180 item 1: runs in one second get distinct activation ids, rollback sets and post-attempt stores',async(t)=>{
await t.test('activate then pm-on on the same copy',async(t)=>{
const e=await mk(t);await seed(e,{pm:true});const sec=pinClock(e),id=`${sec}-${C1.slice(0,12)}`;
let r=await run(e,'activate',C1,'acme','--pm-after-harness');assert.equal(r.code,0,r.out+r.err);
assert.equal(pointer(e).activation,id);
biz(e,HARNESS);
r=await run(e,'pm-on','acme');assert.equal(r.code,0,r.out+r.err);
assert.equal(pointer(e).activation,`${id}-1`);
assert.deepEqual(logLines(e).slice(-4).map((l)=>[l.op,l.result,l.activation]),[['activate','started',id],['activate','ok',id],['pm-on','started',`${id}-1`],['pm-on','ok',`${id}-1`]]);
assert.deepEqual(rollbackSets(e),[id,`${id}-1`]);
for(const a of [id,`${id}-1`])assert.ok(existsSync(join(e.state,'stack-rollback',a,'SHA256SUMS')),a);
});
await t.test('two restores: an old-form id and a suffixed one, each with its own post-attempt store',async(t)=>{
const e=await mk(t);await seed(e);const sec=pinClock(e),c=`${sec}-${C.slice(0,12)}`,b=`${sec}-${B.slice(0,12)}`;
for(const [act,restore] of [[c,b],[`${c}-1`,`${b}-1`]]){
let r=await run(e,'activate',C,'acme','--migrate');assert.equal(r.code,0,r.out+r.err);assert.equal(pointer(e).activation,act);
assert.ok(existsSync(join(e.data,'backups','stack',act,'SHA256SUMS')),act);
r=await run(e,'rollback','acme','--restore',act);assert.equal(r.code,0,r.out+r.err);
const post=join(e.data,`bus.post-attempt-${sec}${restore.slice(b.length)}`);
assert.ok(r.out.startsWith(`restore: ${join(e.data,'backups','stack',act)}; the store now in place moves to ${post} and is kept; 0 event(s) were written after the backup\n`),r.out);
assert.deepEqual([pointer(e).copy,pointer(e).activation,pointer(e).schema],[B,restore,'3g']);
assert.equal(logLines(e).at(-1).backup,act);
}
assert.deepEqual(posts(e).sort(),[`bus.post-attempt-${sec}`,`bus.post-attempt-${sec}-1`]);
assert.deepEqual(readdirSync(join(e.data,'backups','stack')).sort(),[c,`${c}-1`]);
assert.deepEqual(rollbackSets(e),[c,`${c}-1`,b,`${b}-1`].sort());
});
await t.test('adopt takes the next free id too',async(t)=>{
const e=await mk(t);await seed(e,{pointer:'none'});const id=`${pinClock(e)}-${B.slice(0,12)}`;
mkdirSync(join(e.state,'stack-rollback',id),{recursive:true});
const r=await run(e,'adopt','acme');assert.equal(r.code,0,r.out+r.err);
assert.equal(pointer(e).activation,`${id}-1`);
assert.deepEqual(logLines(e).map((l)=>[l.op,l.result,l.activation]),[['adopt','ok',`${id}-1`]]);
});
await t.test('all ten names taken: capture-failed before anything stops, and the log line names no activation',async(t)=>{
const e=await mk(t);await seed(e);const sec=pinClock(e),id=`${sec}-${C1.slice(0,12)}`;
// A rollback set, a backup or a post-attempt store each takes a name.
for(const s of ['','-1','-2','-3','-4','-5','-6','-7'])mkdirSync(join(e.state,'stack-rollback',`${id}${s}`),{recursive:true});
mkdirSync(join(e.data,'backups','stack',`${id}-8`),{recursive:true});writeFileSync(join(e.data,`bus.post-attempt-${sec}-9`),'');
await refused(e,['activate',C1,'acme'],'capture-failed',`every activation id for ${id} is taken; nothing was stopped`);
assert.equal(logLines(e).at(-1).activation,null);
});
await t.test('--restore takes an id with or without -1 to -9 and nothing else',async(t)=>{
const e=await mk(t);await seed(e);const id=`20261020T013708Z-${B.slice(0,12)}`;
for(const bad of [`${id}-0`,`${id}-10`,`${id}-a`,`${id}-`,`${id}1`]){
const r=await run(e,'rollback','acme','--restore',bad,'--plan');assert.equal(r.code,4,bad);
}
for(const good of [id,`${id}-1`,`${id}-9`]){
const r=await run(e,'rollback','acme','--restore',good,'--plan');assert.notEqual(r.code,4,`${good}: ${r.err}`);
}
});
});
test('T44 row 180 item 2: --plan lists tester-port-invalid and tester-port-target with its other refusals',async(t)=>{
const usageText=async(e)=>(await run(e,'--help')).err;
await t.test('a bad tester port',async(t)=>{
const e=await mk(t);await seed(e,{pm:true});biz(e,HARNESS);
const before=fp(e),n=calls(e).length,logs=logLines(e).length,p0=readFileSync(e.pointer,'utf8');
const rule=(port,main)=>`--tester-port ${port} is not a whole port from 1024 to 65535 other than 7332${main?` and the Console's --port ${main}`:''}`;
// The fixture's Console has --port e.port; a pointer without --port has the default 7332, which
// the reason names once. --plan reads the pointer's flags and not the units, so only it changes.
const noPort=()=>{const q=JSON.parse(p0);q.console=q.console.filter((f,i,a)=>f!=='--port'&&a[i-1]!=='--port');writeFileSync(e.pointer,JSON.stringify(q)+'\n')};
for(const [port,reason,edit] of [['80',rule('80',e.port)],[e.port,rule(e.port,e.port)],['80',rule('80'),noPort],['7332',rule('7332'),noPort]]){
if(edit)edit();
const r=await run(e,'activate',C1,'acme','--pm-after-harness','--plan','--tester-port',port);
assert.equal(r.code,3,r.out+r.err);assert.equal(r.err,'');
assert.deepEqual(r.out.split('\n').filter((l)=>l.startsWith('refuses ')),[`refuses tester-port-invalid: ${reason}`,'refuses pm-after-harness-set: the business file already sets harness ["claude-code"]; use --pm']);
const u=await run(e,'activate',C1,'acme','--pm-after-harness','--tester-port',port);
assert.equal(u.code,4,u.out+u.err);assert.equal(u.out,'');assert.equal(u.err,await usageText(e));
writeFileSync(e.pointer,p0);
}
assert.deepEqual(fp(e),before);assert.deepEqual(startsStops(e,n),[]);assert.equal(logLines(e).length,logs);
});
await t.test('without --plan a bad port is usage before any pointer read',async(t)=>{
// parse_opts checks it, so a host with no pointer gets usage and not no-pointer (exit 3, a log line).
const e=await mk(t);await seed(e,{pointer:'none'});
const n=calls(e).length,u=await run(e,'activate',C1,'acme','--tester-port','80');
assert.equal(u.code,4,u.out+u.err);assert.equal(u.out,'');assert.equal(u.err,await usageText(e));
assert.deepEqual(logLines(e),[]);assert.deepEqual(startsStops(e,n),[]);
});
await t.test('a target Console without --tester-port',async(t)=>{
const e=await mk(t);await seed(e);biz(e,HARNESS);
const before=fp(e),n=calls(e).length,logs=logLines(e).length;
const r=await run(e,'activate',A,'acme','--tester-port','7333','--plan');
assert.equal(r.code,3,r.out+r.err);assert.equal(r.err,'');
assert.deepEqual(r.out.split('\n').filter((l)=>l.startsWith('refuses ')),[`refuses tester-port-target: ${A}'s Console does not support --tester-port`,`refuses unknown-kind-for-target: the business file names plug-in kind(s) harness, which ${A} does not know`]);
assert.deepEqual(fp(e),before);assert.deepEqual(startsStops(e,n),[]);assert.equal(logLines(e).length,logs);
await refused(e,['activate',A,'acme','--tester-port','7333'],'tester-port-target',`${A}'s Console does not support --tester-port`);
});
});