Files
memind/scripts/run-context-runtime-offline.mjs
T
john 478c33376c
Memind CI / Test, build, and release guards (push) Has been cancelled
feat(context): add offline shadow profile and local dev gate
Provide context-runtime-profile simulation for gateway shadow events,
run-context-runtime-offline.mjs for zero-LLM verification, and a local
dev guide for user-led shadow self-tests later.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-09 22:18:47 +08:00

126 lines
3.8 KiB
JavaScript

#!/usr/bin/env node
/**
* Context Runtime offline gate: unit tests + local probes, no LLM.
*/
import { spawnSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import {
CONTEXT_RUNTIME_SHADOW_ENV,
describeContextRuntimeProfile,
simulateContextRuntimeShadowEvents,
validateContextRuntimeShadowEvents,
} from '../context-runtime-profile.mjs';
import { prepareGooseV149CheckEnv } from './goose-v149-canary.mjs';
import { checkPassed, classifyCheckResult } from './goose-v149-check-result.mjs';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const checkEnv = prepareGooseV149CheckEnv({ ...process.env }, root);
const unitChecks = [
{
name: 'context-runtime-profile',
command: [process.execPath, '--test', 'context-runtime-profile.test.mjs'],
},
{
name: 'context-runtime-modules',
command: [
process.execPath,
'--test',
'memind-headroom-policy.test.mjs',
'context-budget.test.mjs',
'recall-fusion.test.mjs',
'mcp-result-compactor.test.mjs',
'memind-zvec-workspace.test.mjs',
],
},
];
const scriptChecks = [
{ name: 'mcp-compactor-local', script: 'check-mcp-compactor-local.mjs' },
{ name: 'headroom-proxy-local', script: 'check-headroom-proxy-local.mjs', optional: true },
{ name: 'zvec-workspace-local', script: 'check-zvec-workspace-local.mjs', optional: true },
];
function runCommand(command) {
const [bin, ...args] = command;
const result = spawnSync(bin, args, {
cwd: root,
env: checkEnv,
encoding: 'utf8',
});
return {
ok: checkPassed(result),
outcome: classifyCheckResult(result),
stdout: result.stdout?.trim() ?? '',
stderr: result.stderr?.trim() ?? '',
};
}
function runScript(script) {
const result = spawnSync(process.execPath, [path.join(root, 'scripts', script)], {
cwd: root,
env: checkEnv,
encoding: 'utf8',
});
return {
ok: checkPassed(result),
outcome: classifyCheckResult(result),
stdout: result.stdout?.trim() ?? '',
stderr: result.stderr?.trim() ?? '',
};
}
function main() {
console.log('CONTEXT_RUNTIME_OFFLINE:');
console.log(` profile=${JSON.stringify(describeContextRuntimeProfile(checkEnv))}`);
console.log(` recommended_shadow=${JSON.stringify(CONTEXT_RUNTIME_SHADOW_ENV)}`);
const simulation = simulateContextRuntimeShadowEvents({ env: { ...CONTEXT_RUNTIME_SHADOW_ENV } });
const validation = validateContextRuntimeShadowEvents(simulation);
console.log(` shadow_simulation=${validation.ok ? 'OK' : 'FAIL'}`);
if (!validation.ok) {
console.error(validation.issues.join('\n'));
process.exit(1);
}
console.log(` sample_events=${Object.keys(simulation.events).join(',')}`);
const failures = [];
for (const check of unitChecks) {
const result = runCommand(check.command);
console.log(`[context-runtime-offline] ${result.outcome} ${check.name}`);
if (!result.ok) {
failures.push(check.name);
if (result.stderr) console.error(result.stderr);
}
}
for (const check of scriptChecks) {
const result = runScript(check.script);
const skipped = /SKIP:/.test(result.stdout);
if (skipped && check.optional) {
console.log(`[context-runtime-offline] SKIP ${check.name}`);
continue;
}
console.log(`[context-runtime-offline] ${result.outcome} ${check.name}`);
if (!result.ok && !check.optional) {
failures.push(check.name);
if (result.stderr) console.error(result.stderr);
} else if (!result.ok && check.optional) {
console.log(`[context-runtime-offline] WARN ${check.name} (optional probe failed)`);
}
}
if (failures.length) {
console.error(`CONTEXT_RUNTIME_OFFLINE_FAIL: ${failures.join(', ')}`);
process.exit(1);
}
console.log('CONTEXT_RUNTIME_OFFLINE_OK');
console.log(' self-test: docs/context-runtime-local-dev.md');
}
main();