gander: preserve row 196 human boundary build for rebase

This commit is contained in:
jason.woltje committed 2026-10-21 13:48:20 -05:00
1 parent a365237133
commit 64539c96bb
97 files changed
+10407 -182

No files matched your search

+9
View File
@@ -1069,3 +1069,12 @@ provider/model, provider and account groups, with input/output/cacheWrite/
cacheRead and unknown turns beside every total. JSON retains the full view.
Account is unassigned today. Unknown turns can have used tokens: known sums
are a best reading of session-editable transcripts, not proof or a limit check.
### Private tester HTTP (row 196)
`node packages/cli/src/tester-http.mjs GET /api/config` selects the instance's
console/tester.sock from its dataRoot. POST reads one bounded JSON body from stdin.
The helper supplies the fixed logical origin, reports status/text/body as JSON,
and never retries an uncertain write. It cannot navigate a browser or upgrade the
tester to an owner. `mosaic ... --tester` continues using broker.sock directly.
See docs/TOOLS.md for explicit activation conversion and rollback behavior.
+39
View File
@@ -0,0 +1,39 @@
import { request } from 'node:http';
import { fileURLToPath } from 'node:url';
import { readFileSync } from 'node:fs';
import { testerSocketPath, TESTER_ORIGIN } from '../../webui/src/tester-socket.mjs';
export function testerRequest({ dataRoot, path = '/healthz', method = 'GET', body, headers = {}, timeout = 30000 }) {
if (typeof path !== 'string' || !/^\/(?!\/)/.test(path) || /[\r\n\0]/.test(path)) return Promise.reject(Error('tester-http-path'));
const data = body === undefined ? undefined : JSON.stringify(body);
if (data && Buffer.byteLength(data) > 16384) return Promise.reject(Error('tester-http-size'));
return new Promise((resolve, reject) => {
const req = request({ socketPath: testerSocketPath(dataRoot), path, method,
headers: { host: new URL(TESTER_ORIGIN).host, origin: TESTER_ORIGIN, 'sec-fetch-site': 'same-origin',
...(data ? { 'content-type': 'application/json' } : {}), ...headers } }, res => {
const chunks = []; let size = 0;
res.on('data', b => { size += b.length; if (size > 8 * 1024 * 1024) req.destroy(Error('tester-http-size')); else chunks.push(b); });
res.on('error', reject);
res.on('end', () => {
const text = Buffer.concat(chunks).toString('utf8');
try { resolve({ status: res.statusCode, text, body: res.headers['content-type']?.includes('json') ? JSON.parse(text) : null }); }
catch { reject(Error('tester-http-response')); }
});
});
req.setTimeout(timeout, () => req.destroy(Error('tester-http-timeout')));
req.on('error', reject);
req.end(data);
});
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
try {
const { loadSystem } = await import('./config.mjs');
const [method = 'GET', path = '/healthz'] = process.argv.slice(2);
if (!['GET', 'HEAD', 'POST'].includes(method) || process.argv.length > 4) throw Error('tester-http-usage');
const body = method === 'POST' ? JSON.parse(readFileSync(0, 'utf8')) : undefined;
const result = await testerRequest({ dataRoot: loadSystem().dataRoot, path, method, body });
process.stdout.write(JSON.stringify(result) + '\n');
if (result.status >= 400) process.exitCode = 2;
} catch { process.stderr.write('tester-http-refused\n'); process.exitCode = 2; }
}
+2 -2
View File
@@ -357,9 +357,9 @@ export function biz(e,plugins){
writeFileSync(f,JSON.stringify(b,null,2)+'\n',{mode:0o600});chmodSync(f,0o600);
}
export async function mk(t){
export async function mk(t,dataName='data'){
const root=realpathSync(mkdtempSync(join(tmpdir(),'sr-')));
const e={root,data:join(root,'data'),bin:join(root,'bin'),sd:join(root,'sd'),units:join(root,'xcfg','systemd','user'),cfg:join(root,'cfg','config.json'),claude:join(root,'claude-bin','claude')};
const e={root,data:join(root,dataName),bin:join(root,'bin'),sd:join(root,'sd'),units:join(root,'xcfg','systemd','user'),cfg:join(root,'cfg','config.json'),claude:join(root,'claude-bin','claude')};
// The default instance's names; named() sets NAME's (row 190).
Object.assign(e,{flags:[],bus:BUS,tmpl:'[email protected]',con:CON,wrapper:'mosaic'});
Object.assign(e,{state:join(e.data,'state'),pointer:join(e.data,'state','stack-active.json'),log:join(e.data,'state','stack-activation-log.jsonl'),store:join(e.data,'bus','bus.sqlite'),lock:join(e.data,'state','stack-release.lock')});
+27
View File
@@ -2273,3 +2273,30 @@ test('T56 row 190: named instances side by side on one unit directory, $BIN and
const r=await run(a,'activate',C1,'acme');assert.equal(r.code,0,r.out+r.err);
});
});
test('row196 explicit socket conversion refuses inherited TCP before stop and rollback disables socket',async t=>{
const e=await mk(t),base=await seedPreview(e,{copy:A}),proof=await proofFile(e);
let r=await run(e,'activate',B,'acme','--tester-port','7333');assert.equal(r.code,0,r.out+r.err);
const file=join(COPIES,C1,'packages/webui/src/cli.mjs'),original=readFileSync(file,'utf8');
chmodSync(file,0o644);writeFileSync(file,'// MOSAIC_TESTER_SOCKET_V1\n// --tester-socket\n// --proof-header\n');chmodSync(file,0o444);
t.after(()=>{chmodSync(file,0o644);writeFileSync(file,original);chmodSync(file,0o444);});
const module=join(COPIES,C1,'packages/bus/src/interpreter.mjs');
chmodSync(dirname(module),0o755);
writeFileSync(module,'export const inspectInterpreter=()=>({path:"/usr/bin/python3",sha256:"fixture"});export const verifyInterpreterReceipt=()=>true;\n');chmodSync(module,0o444);chmodSync(dirname(module),0o555);
t.after(()=>{chmodSync(dirname(module),0o755);rmSync(module);chmodSync(dirname(module),0o555);});
const n=calls(e).length;
r=await run(e,'activate',C1,'acme');assert.equal(r.code,3,r.out+r.err);assert.match(r.err,/tester-transport-migration/);assert.deepEqual(startsStops(e,n),[]);
r=await run(e,'activate',C1,'acme','--tester-socket','--plan');assert.equal(r.code,0,r.out+r.err);assert.match(r.out,/--tester-socket/);assert.match(r.out,/drop.*--tester-port 7333/);
r=await run(e,'activate',C1,'acme','--tester-socket',...pair(proof));assert.equal(r.code,0,r.out+r.err);
assert.deepEqual(pointer(e).console,[...base,...pair(proof),'--tester-socket']);assert.match(consoleText(e),/--tester-socket/);assert.doesNotMatch(consoleText(e),/--tester-port/);
r=await run(e,'rollback','acme');assert.equal(r.code,0,r.out+r.err);assert.doesNotMatch(consoleText(e),/--tester-(socket|port)/);assert.match(r.out,/drop.*--tester-socket/);
await noLeak(e);
mkdirSync(join(e.data,'console'),{mode:0o755});
const unsafeBefore=calls(e).length;
r=await run(e,'activate',C1,'acme','--tester-socket');
assert.equal(r.code,3,r.out+r.err);assert.match(r.err,/tester-socket-path/);assert.deepEqual(startsStops(e,unsafeBefore),[]);
const long=await mk(t,'data-'+ 'a'.repeat(100));await seed(long,{copy:B});
const before=calls(long).length;
r=await run(long,'activate',C1,'acme','--tester-socket');
assert.equal(r.code,3,r.out+r.err);assert.match(r.err,/tester-socket-path/);assert.deepEqual(startsStops(long,before),[]);
});
+24
View File
@@ -0,0 +1,24 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { mkdtempSync,rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { bindTesterSocket, testerSocketPath, TESTER_ORIGIN } from '../../webui/src/tester-socket.mjs';
import { testerRequest } from '../src/tester-http.mjs';
test('tester HTTP helper uses instance socket, logical origin and JSON without retrying',async t=>{
const root=mkdtempSync(join(tmpdir(),'g196-h-'));let hits=0;
const server=await bindTesterSocket(createServer((q,r)=>{hits++;assert.equal(q.headers.host,new URL(TESTER_ORIGIN).host);assert.equal(q.headers.origin,TESTER_ORIGIN);r.setHeader('content-type','application/json');r.end('{"ok":true}');}),testerSocketPath(root));
t.after(async()=>{await new Promise(r=>server.close(r));rmSync(root,{recursive:true,force:true});});
assert.equal((await testerRequest({dataRoot:root,path:'/fixture',method:'POST',body:{x:1}})).body.ok,true);
assert.equal(hits,1);
for(const path of ['//remote','bad','/a\n'])await assert.rejects(testerRequest({dataRoot:root,path}),/tester-http-path/);
await assert.rejects(testerRequest({dataRoot:root,body:{x:'x'.repeat(16385)}}),/tester-http-size/);
});
test('tester HTTP timeout closes the socket and does not retry',async t=>{
const root=mkdtempSync(join(tmpdir(),'g196-h-'));let hits=0;
const server=await bindTesterSocket(createServer(()=>{hits++;}),testerSocketPath(root));
t.after(async()=>{server.closeAllConnections();await new Promise(r=>server.close(r));rmSync(root,{recursive:true,force:true});});
await assert.rejects(testerRequest({dataRoot:root,timeout:20}),/tester-http-timeout/);
assert.equal(hits,1);
});